diff --git a/libs/ACSVM/include/CAPI/Array.cpp b/libs/ACSVM/include/CAPI/Array.cpp deleted file mode 100644 index dbf45cd97..000000000 --- a/libs/ACSVM/include/CAPI/Array.cpp +++ /dev/null @@ -1,126 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (C) 2015-2017 David Hill -// -// See COPYING for license information. -// -//----------------------------------------------------------------------------- -// -// Arrays. -// -//----------------------------------------------------------------------------- - -#include "Array.h" - -#include "Environment.h" - - -extern "C" -{ - -//----------------------------------------------------------------------------| -// Extern Functions | -// - -// -// ACSVM_AllocArray -// -ACSVM_Array *ACSVM_AllocArray(void) -{ - return reinterpret_cast(new(std::nothrow) ACSVM::Array); -} - -// -// ACSVM_FreeArray -// -void ACSVM_FreeArray(ACSVM_Array *arr) -{ - delete reinterpret_cast(arr); -} - -// -// ACSVM_Array_Clear -// -void ACSVM_Array_Clear(ACSVM_Array *arr) -{ - reinterpret_cast(arr)->clear(); -} - -// -// ACSVM_Array_Find -// -ACSVM_Word ACSVM_Array_Find(ACSVM_Array const *arr, ACSVM_Word idx) -{ - return reinterpret_cast(arr)->find(idx); -} - -// -// ACSVM_Array_Get -// -ACSVM_Word *ACSVM_Array_Get(ACSVM_Array *arr, ACSVM_Word idx) -{ - try - { - return &reinterpret_cast(*arr)[idx]; - } - catch(std::bad_alloc const &) - { - return nullptr; - } -} - -// -// ACSVM_Array_LoadState -// -bool ACSVM_Array_LoadState(ACSVM_Array *arr, ACSVM_Serial *in) -{ - try - { - reinterpret_cast(arr)->loadState( - *reinterpret_cast(in)); - - return true; - } - catch(std::bad_alloc const &) - { - return false; - } -} - -// -// ACSVM_Array_LockStrings -// -void ACSVM_Array_LockStrings(ACSVM_Array const *arr, ACSVM_Environment *env) -{ - reinterpret_cast(arr)->lockStrings(env); -} - -// -// ACSVM_Array_RefStrings -// -void ACSVM_Array_RefStrings(ACSVM_Array const *arr, ACSVM_Environment *env) -{ - reinterpret_cast(arr)->refStrings(env); -} - -// -// ACSVM_Array_SaveState -// -void ACSVM_Array_SaveState(ACSVM_Array const *arr, ACSVM_Serial *out) -{ - reinterpret_cast(arr)->saveState( - *reinterpret_cast(out)); -} - -// -// ACSVM_Array_UnlockStrings -// -void ACSVM_Array_UnlockStrings(ACSVM_Array const *arr, ACSVM_Environment *env) -{ - reinterpret_cast(arr)->unlockStrings(env); -} - -} - -// EOF - diff --git a/libs/ACSVM/include/CAPI/Array.h b/libs/ACSVM/include/CAPI/Array.h deleted file mode 100644 index c035c6350..000000000 --- a/libs/ACSVM/include/CAPI/Array.h +++ /dev/null @@ -1,55 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (C) 2015-2017 David Hill -// -// See COPYING for license information. -// -//----------------------------------------------------------------------------- -// -// Arrays. -// -//----------------------------------------------------------------------------- - -#ifndef ACSVM__CAPI__Array_H__ -#define ACSVM__CAPI__Array_H__ - -#include "Types.h" - -#ifdef __cplusplus -#include "../ACSVM/Array.hpp" -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - -//----------------------------------------------------------------------------| -// Extern Functions | -// - -ACSVM_Array *ACSVM_AllocArray(void); -void ACSVM_FreeArray(ACSVM_Array *arr); - -void ACSVM_Array_Clear(ACSVM_Array *arr); - -ACSVM_Word ACSVM_Array_Find(ACSVM_Array const *arr, ACSVM_Word idx); - -ACSVM_Word *ACSVM_Array_Get(ACSVM_Array *arr, ACSVM_Word idx); - -bool ACSVM_Array_LoadState(ACSVM_Array *arr, ACSVM_Serial *in); - -void ACSVM_Array_LockStrings(ACSVM_Array const *arr, ACSVM_Environment *env); - -void ACSVM_Array_RefStrings(ACSVM_Array const *arr, ACSVM_Environment *env); - -void ACSVM_Array_SaveState(ACSVM_Array const *arr, ACSVM_Serial *out); - -void ACSVM_Array_UnlockStrings(ACSVM_Array const *arr, ACSVM_Environment *env); - -#ifdef __cplusplus -} -#endif - -#endif//ACSVM__CAPI__Array_H__ - diff --git a/libs/ACSVM/include/CAPI/BinaryIO.cpp b/libs/ACSVM/include/CAPI/BinaryIO.cpp deleted file mode 100644 index 8bfd2047b..000000000 --- a/libs/ACSVM/include/CAPI/BinaryIO.cpp +++ /dev/null @@ -1,100 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (C) 2015 David Hill -// -// See COPYING for license information. -// -//----------------------------------------------------------------------------- -// -// Binary data reading/writing. -// -//----------------------------------------------------------------------------- - -#include "BinaryIO.h" - - -extern "C" -{ - -//----------------------------------------------------------------------------| -// Extern Functions | -// - -// -// ACSVM_Buffer constructor -// -ACSVM_Buffer::ACSVM_Buffer(FILE *stream_) : - stream{stream_} -{ -} - -// -// ACSVM_Buffer::overflow -// -int ACSVM_Buffer::overflow(int c) -{ - return std::fputc(c, stream); -} - -// -// ACSVM_Buffer::uflow -// -int ACSVM_Buffer::uflow() -{ - return std::fgetc(stream); -} - -// -// ACSVM_IStream constructor -// -ACSVM_IStream::ACSVM_IStream(FILE *stream) : - buf{stream} -{ -} - -// -// ACSVM_OStream constructor -// -ACSVM_OStream::ACSVM_OStream(FILE *stream) : - buf{stream} -{ -} - -// -// ACSVM_AllocIStream -// -ACSVM_IStream *ACSVM_AllocIStream_File(FILE *stream) -{ - return reinterpret_cast( - static_cast(new(std::nothrow) ACSVM_IStream(stream))); -} - -// -// ACSVM_AllocOStream -// -ACSVM_OStream *ACSVM_AllocOStream_File(FILE *stream) -{ - return reinterpret_cast( - static_cast(new(std::nothrow) ACSVM_OStream(stream))); -} - -// -// ACSVM_ReadVLN -// -uintmax_t ACSVM_ReadVLN(ACSVM_IStream *in) -{ - return ACSVM::ReadVLN(reinterpret_cast(*in)); -} - -// -// ACSVM_WriteVLN -// -void ACSVM_WriteVLN(ACSVM_OStream *out, uintmax_t in) -{ - ACSVM::WriteVLN(reinterpret_cast(*out), in); -} - -} - -// EOF - diff --git a/libs/ACSVM/include/CAPI/BinaryIO.h b/libs/ACSVM/include/CAPI/BinaryIO.h deleted file mode 100644 index 2d6efac22..000000000 --- a/libs/ACSVM/include/CAPI/BinaryIO.h +++ /dev/null @@ -1,96 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (C) 2015 David Hill -// -// See COPYING for license information. -// -//----------------------------------------------------------------------------- -// -// Binary data reading/writing. -// -//----------------------------------------------------------------------------- - -#ifndef ACSVM__CAPI__BinaryIO_H__ -#define ACSVM__CAPI__BinaryIO_H__ - -#include "Types.h" - -#include - -#ifdef __cplusplus -#include "../ACSVM/BinaryIO.hpp" - -#include -#include -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - -//----------------------------------------------------------------------------| -// Types | -// - -#ifdef __cplusplus -// -// ACSVM_Buffer -// -struct ACSVM_Buffer : std::streambuf -{ -public: - ACSVM_Buffer(FILE *stream); - - FILE *stream; - -protected: - virtual int overflow(int c); - - virtual int uflow(); -}; - -// -// ACSVM_IStream -// -struct ACSVM_IStream : std::istream -{ -public: - ACSVM_IStream(FILE *stream); - - ACSVM_Buffer buf; -}; - -// -// ACSVM_OStream -// -struct ACSVM_OStream : std::ostream -{ -public: - ACSVM_OStream(FILE *stream); - - ACSVM_Buffer buf; -}; -#endif - - -//----------------------------------------------------------------------------| -// Extern Functions | -// - -ACSVM_IStream *ACSVM_AllocIStream_File(FILE *stream); -void ACSVM_FreeIStream(ACSVM_IStream *stream); - -ACSVM_OStream *ACSVM_AllocOStream_File(FILE *stream); -void ACSVM_FreeOStream(ACSVM_OStream *stream); - -uintmax_t ACSVM_ReadVLN(ACSVM_IStream *in); - -void ACSVM_WriteVLN(ACSVM_OStream *out, uintmax_t in); - -#ifdef __cplusplus -} -#endif - -#endif//ACSVM__CAPI__BinaryIO_H__ - diff --git a/libs/ACSVM/include/CAPI/CMakeLists.txt b/libs/ACSVM/include/CAPI/CMakeLists.txt deleted file mode 100644 index c57af5088..000000000 --- a/libs/ACSVM/include/CAPI/CMakeLists.txt +++ /dev/null @@ -1,55 +0,0 @@ -##----------------------------------------------------------------------------- -## -## Copyright (C) 2015 David Hill -## -## See COPYING for license information. -## -##----------------------------------------------------------------------------- -## -## CMake file for acsvm-capi. -## -##----------------------------------------------------------------------------- - - -##----------------------------------------------------------------------------| -## Environment Configuration | -## - -include_directories(.) - - -##----------------------------------------------------------------------------| -## Targets | -## - -## -## acsvm-capi -## -add_library(acsvm-capi ${ACSVM_SHARED_DECL} - Array.cpp - Array.h - BinaryIO.cpp - BinaryIO.h - Environment.cpp - Environment.h - Floats.cpp - Floats.h - Module.cpp - Module.h - PrintBuf.cpp - PrintBuf.h - Scope.cpp - Scope.h - String.cpp - String.h - Thread.cpp - Thread.h - Types.h -) - -target_link_libraries(acsvm-capi acsvm-util) - -ACSVM_INSTALL_LIB(acsvm-capi) - -## EOF - diff --git a/libs/ACSVM/include/CAPI/Code.h b/libs/ACSVM/include/CAPI/Code.h deleted file mode 100644 index 4bac77b76..000000000 --- a/libs/ACSVM/include/CAPI/Code.h +++ /dev/null @@ -1,68 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (C) 2015 David Hill -// -// See COPYING for license information. -// -//----------------------------------------------------------------------------- -// -// Codes. -// -//----------------------------------------------------------------------------- - -#ifndef ACSVM__CAPI__Code_H__ -#define ACSVM__CAPI__Code_H__ - -#include "Types.h" - -#ifdef __cplusplus -#include "../ACSVM/Code.hpp" -#endif - - -//----------------------------------------------------------------------------| -// Types | -// - -// -// ACSVM_Code -// -// ACSVM::Code mirror. -// -typedef enum ACSVM_Code -{ - #define ACSVM_CodeList(name, ...) ACSVM_Code_##name, - #include "../ACSVM/CodeList.hpp" - - ACSVM_Code_None -} ACSVM_Code; - -// -// ACSVM_Func -// -// ACSVM::Func mirror. -// -typedef enum ACSVM_Func -{ - #define ACSVM_FuncList(name) ACSVM_Func_##name, - #include "../ACSVM/CodeList.hpp" - - ACSVM_Func_None -} ACSVM_Func; - -// -// ACSVM_KillType -// -// ACSVM::KillType mirror. -// -typedef enum ACSVM_KillType -{ - ACSVM_KillType_None, - ACSVM_KillType_OutOfBounds, - ACSVM_KillType_UnknownCode, - ACSVM_KillType_UnknownFunc, - ACSVM_KillType_BranchLimit, -} ACSVM_KillType; - -#endif//ACSVM__CAPI__Code_H__ - diff --git a/libs/ACSVM/include/CAPI/Environment.cpp b/libs/ACSVM/include/CAPI/Environment.cpp deleted file mode 100644 index a027be641..000000000 --- a/libs/ACSVM/include/CAPI/Environment.cpp +++ /dev/null @@ -1,484 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (C) 2015-2017 David Hill -// -// See COPYING for license information. -// -//----------------------------------------------------------------------------- -// -// Environment. -// -//----------------------------------------------------------------------------- - -#include "Environment.h" - -#include "Code.h" -#include "Module.h" -#include "Thread.h" - -#include "ACSVM/CodeData.hpp" -#include "ACSVM/Error.hpp" -#include "ACSVM/Serial.hpp" - - -extern "C" -{ - -//----------------------------------------------------------------------------| -// Extern Functions | -// - -// -// ACSVM_Environment constructor -// -ACSVM_Environment::ACSVM_Environment(ACSVM_EnvironmentFuncs const &funcs_, void *data_) : - funcs{funcs_}, data{data_} -{ - if(funcs.ctor) - funcs.ctor(this); -} - -// -// ACSVM_Environment destructor -// -ACSVM_Environment::~ACSVM_Environment() -{ - if(funcs.dtor) - funcs.dtor(this); -} - -// -// ACSVM_Environment::allocThread -// -ACSVM::Thread *ACSVM_Environment::allocThread() -{ - if(!funcs.allocThread) - return new ACSVM_Thread(this, {}, nullptr); - - if(ACSVM_Thread *thread = funcs.allocThread(this)) - return thread; - - throw std::bad_alloc(); -} - -// -// ACSVM_Environment::callFunc -// -bool ACSVM_Environment::callFunc(ACSVM::Thread *thread, ACSVM::Word func, - ACSVM::Word const *argV, ACSVM::Word argC) -{ - if(func <= static_cast(ACSVM::Func::None)) - return ACSVM::Environment::callFunc(thread, func, argV, argC); - - auto callFunc = callFuncV[func - static_cast(ACSVM::Func::None) - 1]; - return callFunc(static_cast(thread), argV, argC); -} - -// -// ACSVM_Environment::callSpecImpl -// -ACSVM::Word ACSVM_Environment::callSpecImpl(ACSVM::Thread *thread, - ACSVM::Word spec, ACSVM::Word const *argV, ACSVM::Word argC) -{ - if(!funcs.callSpecImpl) - return ACSVM::Environment::callSpecImpl(thread, spec, argV, argC); - - return funcs.callSpecImpl(this, static_cast(thread), spec, argV, argC); -} - -// -// ACSVM_Environment::checkLock -// -bool ACSVM_Environment::checkLock(ACSVM::Thread *thread, ACSVM::Word lock, bool door) -{ - if(!funcs.checkLock) - return ACSVM::Environment::checkLock(thread, lock, door); - - return funcs.checkLock(this, static_cast(thread), lock, door); -} - -// -// ACSVM_Environment::checkTag -// -bool ACSVM_Environment::checkTag(ACSVM::Word type, ACSVM::Word tag) -{ - if(!funcs.checkTag) - return ACSVM::Environment::checkTag(type, tag); - - return funcs.checkTag(this, type, tag); -} - -// -// ACSVM_Environment::getModuleName -// -ACSVM::ModuleName ACSVM_Environment::getModuleName(char const *str, std::size_t len) -{ - if(!funcs.getModuleName) - return ACSVM::Environment::getModuleName(str, len); - - auto name = funcs.getModuleName(this, str, len); - return {reinterpret_cast(name.s), name.p, name.i}; -} - -// -// ACSVM_Environment::loadModule -// -void ACSVM_Environment::loadModule(ACSVM::Module *module) -{ - if(!funcs.loadModule) - throw ACSVM::ReadError(); - - if(!funcs.loadModule(this, reinterpret_cast(module))) - throw ACSVM::ReadError(); -} - -// -// ACSVM_Environment::loadState -// -void ACSVM_Environment::loadState(ACSVM::Serial &in) -{ - ACSVM::Environment::loadState(in); - - if(funcs.loadState) - funcs.loadState(this, reinterpret_cast(&in)); -} - -// -// ACSVM_Environment::printArray -// -void ACSVM_Environment::printArray(ACSVM::PrintBuf &buf, ACSVM::Array const &array, - ACSVM::Word index, ACSVM::Word limit) -{ - if(!funcs.printArray) - return ACSVM::Environment::printArray(buf, array, index, limit); - - funcs.printArray(this, reinterpret_cast(&buf), - reinterpret_cast(&array), index, limit); -} - -// -// ACSVM_Environment::printKill -// -void ACSVM_Environment::printKill(ACSVM::Thread *thread, ACSVM::Word type, ACSVM::Word killData) -{ - if(!funcs.printKill) - return ACSVM::Environment::printKill(thread, type, killData); - - funcs.printKill(this, static_cast(thread), type, killData); -} - -// -// ACSVM_Environment::readModuleName -// -ACSVM::ModuleName ACSVM_Environment::readModuleName(ACSVM::Serial &in) const -{ - if(!funcs.readModuleName) - return ACSVM::Environment::readModuleName(in); - - auto name = funcs.readModuleName(this, reinterpret_cast(&in)); - return {reinterpret_cast(name.s), name.p, name.i}; -} - -// -// ACSVM_Environment::refStrings -// -void ACSVM_Environment::refStrings() -{ - ACSVM::Environment::refStrings(); - - if(funcs.refStrings) - funcs.refStrings(this); -} - -// -// ACSVM_Environment::resetStrings -// -void ACSVM_Environment::resetStrings() -{ - ACSVM::Environment::resetStrings(); - - if(funcs.resetStrings) - funcs.resetStrings(this); -} - -// -// ACSVM_Environment::saveState -// -void ACSVM_Environment::saveState(ACSVM::Serial &out) const -{ - ACSVM::Environment::saveState(out); - - if(funcs.saveState) - funcs.saveState(this, reinterpret_cast(&out)); -} - -// -// ACSVM_Environment::writeModuleName -// -void ACSVM_Environment::writeModuleName(ACSVM::Serial &out, ACSVM::ModuleName const &in) const -{ - if(!funcs.writeModuleName) - return ACSVM::Environment::writeModuleName(out, in); - - funcs.writeModuleName(this, reinterpret_cast(&out), - {reinterpret_cast(in.s), in.p, in.i}); -} - -// -// ACSVM_AllocEnvironment -// -ACSVM_Environment *ACSVM_AllocEnvironment(ACSVM_EnvironmentFuncs const *funcs, void *data) -{ - return new(std::nothrow) ACSVM_Environment(*funcs, data); -} - -// -// ACSVM_FreeEnvironment -// -void ACSVM_FreeEnvironment(ACSVM_Environment *env) -{ - delete env; -} - -// -// ACSVM_Environment_AddCallFunc -// -ACSVM_Word ACSVM_Environment_AddCallFunc(ACSVM_Environment *env, ACSVM_CallFunc func) -{ - env->callFuncV.push_back(func); - return env->callFuncV.size() + static_cast(ACSVM::Func::None); -} - -// -// ACSVM_Environment_AddCodeDataACS0 -// -void ACSVM_Environment_AddCodeDataACS0(ACSVM_Environment *env, ACSVM_Word code, - char const *args, ACSVM_Code transCode_, ACSVM_Word stackArgC, ACSVM_Word transFunc) -{ - try - { - auto transCode = static_cast(transCode_); - env->addCodeDataACS0(code, {args, transCode, stackArgC, transFunc}); - } - catch(std::bad_alloc const &e) - { - if(env->funcs.bad_alloc) - env->funcs.bad_alloc(env, e.what()); - } -} - -// -// ACSVM_Environment_AddFuncDataACS0 -// -void ACSVM_Environment_AddFuncDataACS0(ACSVM_Environment *env, ACSVM_Word func, - ACSVM_Word transFunc, ACSVM_Word const *transCodeArgCV, - ACSVM_Code const *transCodeV, size_t transCodeC) -{ - try - { - if(transCodeC) - { - std::unique_ptr transCodes - {new ACSVM::FuncDataACS0::TransCode[transCodeC]}; - - for(std::size_t i = 0; i != transCodeC; ++i) - transCodes[i] = {transCodeArgCV[i], static_cast(transCodeV[i])}; - - env->addFuncDataACS0(func, {transFunc, std::move(transCodes), transCodeC}); - } - else - env->addFuncDataACS0(func, transFunc); - } - catch(std::bad_alloc const &e) - { - if(env->funcs.bad_alloc) - env->funcs.bad_alloc(env, e.what()); - } -} - -// -// ACSVM_Environment_CollectStrings -// -void ACSVM_Environment_CollectStrings(ACSVM_Environment *env) -{ - env->collectStrings(); -} - -// -// ACSVM_Environment_Exec -// -void ACSVM_Environment_Exec(ACSVM_Environment *env) -{ - try - { - env->exec(); - } - catch(std::bad_alloc const &e) - { - if(env->funcs.bad_alloc) - env->funcs.bad_alloc(env, e.what()); - } -} - -// -// ACSVM_Environment_FreeGlobalScope -// -void ACSVM_Environment_FreeGlobalScope(ACSVM_Environment *env, ACSVM_GlobalScope *scope) -{ - env->freeGlobalScope(reinterpret_cast(scope)); -} - -// -// ACSVM_Environment_FreeModule -// -void ACSVM_Environment_FreeModule(ACSVM_Environment *env, ACSVM_Module *module) -{ - env->freeModule(reinterpret_cast(module)); -} - -// -// ACSVM_Environment_GetBranchLimit -// -ACSVM_Word ACSVM_Environment_GetBranchLimit(ACSVM_Environment const *env) -{ - return env->branchLimit; -} - -// -// ACSVM_Environment_GetData -// -void *ACSVM_Environment_GetData(ACSVM_Environment const *env) -{ - return env->data; -} - -// -// ACSVM_Environment_GetGlobalScope -// -ACSVM_GlobalScope *ACSVM_Environment_GetGlobalScope(ACSVM_Environment *env, ACSVM_Word id) -{ - try - { - return reinterpret_cast(env->getGlobalScope(id)); - } - catch(std::bad_alloc const &e) - { - if(env->funcs.bad_alloc) - env->funcs.bad_alloc(env, e.what()); - - return nullptr; - } -} - -// -// ACSVM_Environment_GetModule -// -ACSVM_Module *ACSVM_Environment_GetModule(ACSVM_Environment *env, ACSVM_ModuleName name) -{ - try - { - return reinterpret_cast(env->getModule( - {reinterpret_cast(name.s), name.p, name.i})); - } - catch(ACSVM::ReadError const &e) - { - if(env->funcs.readError) - env->funcs.readError(env, e.what()); - - return nullptr; - } - catch(std::bad_alloc const &e) - { - if(env->funcs.bad_alloc) - env->funcs.bad_alloc(env, e.what()); - - return nullptr; - } -} - -// -// ACSVM_Environment_GetScriptLocRegC -// -ACSVM_Word ACSVM_Environment_GetScriptLocRegC(ACSVM_Environment const *env) -{ - return env->scriptLocRegC; -} - -// -// ACSVM_Environment_GetStringTable -// -ACSVM_StringTable *ACSVM_Environment_GetStringTable(ACSVM_Environment *env) -{ - return reinterpret_cast(&env->stringTable); -} - -// -// ACSVM_Environment_HasActiveThread -// -bool ACSVM_Environment_HasActiveThread(ACSVM_Environment const *env) -{ - return env->hasActiveThread(); -} - -// -// ACSVM_Environment_LoadState -// -bool ACSVM_Environment_LoadState(ACSVM_Environment *env, ACSVM_Serial *in) -{ - try - { - env->loadState(*reinterpret_cast(in)); - return true; - } - catch(ACSVM::SerialError const &e) - { - if(env->funcs.serialError) - env->funcs.serialError(env, e.what()); - - return false; - } - catch(std::bad_alloc const &e) - { - if(env->funcs.bad_alloc) - env->funcs.bad_alloc(env, e.what()); - - return false; - } -} - -// -// ACSVM_Environment_SaveState -// -void ACSVM_Environment_SaveState(ACSVM_Environment *env, ACSVM_Serial *out) -{ - env->saveState(*reinterpret_cast(out)); -} - -// -// ACSVM_Environment_SetBranchLimit -// -void ACSVM_Environment_SetBranchLimit(ACSVM_Environment *env, ACSVM_Word branchLimit) -{ - env->branchLimit = branchLimit; -} - -// -// ACSVM_Environment_SetData -// -void ACSVM_Environment_SetData(ACSVM_Environment *env, void *data) -{ - env->data = data; -} - -// -// ACSVM_Environment_SetScriptLocRegC -// -void ACSVM_Environment_SetScriptLocReg(ACSVM_Environment *env, ACSVM_Word scriptLocRegC) -{ - env->scriptLocRegC = scriptLocRegC; -} - -} - -// EOF - diff --git a/libs/ACSVM/include/CAPI/Environment.h b/libs/ACSVM/include/CAPI/Environment.h deleted file mode 100644 index 32344c99b..000000000 --- a/libs/ACSVM/include/CAPI/Environment.h +++ /dev/null @@ -1,198 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (C) 2015-2017 David Hill -// -// See COPYING for license information. -// -//----------------------------------------------------------------------------- -// -// Environment. -// -//----------------------------------------------------------------------------- - -#ifndef ACSVM__CAPI__Environment_H__ -#define ACSVM__CAPI__Environment_H__ - -#include "Code.h" - -#ifdef __cplusplus -#include "../ACSVM/Environment.hpp" - -#include -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - -//----------------------------------------------------------------------------| -// Types | -// - -// -// ACSVM_EnvironmentFuncs -// -// Overridable virtual functions in ACSVM_Environment. If null, the base -// function is called. If the base function is pure virtual, then the function -// in this structure must not be null. -// -typedef struct ACSVM_EnvironmentFuncs -{ - // Called in the event of a memory allocation failure. This function may - // return normally, but the ACSVM_Environment object must not be used - // afterward, except to be passed to ACSVM_FreeEnvironment. - void (*bad_alloc)(ACSVM_Environment *env, char const *what); - - // Called if an ACSVM::ReadError is caught. This function may return - // normally. - void (*readError)(ACSVM_Environment *env, char const *what); - - // Called if an ACSVM::SerialError is caught. This function may return - // normally, but the VM state is indeterminate. - void (*serialError)(ACSVM_Environment *env, char const *what); - - // public - - void (*ctor)(ACSVM_Environment *env); - void (*dtor)(ACSVM_Environment *env); - - bool (*checkLock)(ACSVM_Environment const *env, ACSVM_Thread *thread, - ACSVM_Word lock, bool door); - - bool (*checkTag)(ACSVM_Environment const *env, ACSVM_Word type, ACSVM_Word tag); - - ACSVM_ModuleName (*getModuleName)(ACSVM_Environment *env, - char const *str, size_t len); - - // Called after base class's. - void (*loadState)(ACSVM_Environment *env, ACSVM_Serial *in); - - void (*printArray)(ACSVM_Environment const *env, ACSVM_PrintBuf *buf, - ACSVM_Array const *array, ACSVM_Word index, ACSVM_Word limit); - - void (*printKill)(ACSVM_Environment const *env, ACSVM_Thread *thread, - ACSVM_Word type, ACSVM_Word data); - - ACSVM_ModuleName (*readModuleName)(ACSVM_Environment const *env, ACSVM_Serial *in); - - // Called after base class's. - void (*refStrings)(ACSVM_Environment *env); - - // Called after base class's. - void (*resetStrings)(ACSVM_Environment *env); - - // Called after base class's. - void (*saveState)(ACSVM_Environment const *env, ACSVM_Serial *out); - - void (*writeModuleName)(ACSVM_Environment const *env, ACSVM_Serial *out, - ACSVM_ModuleName in); - - // protected - - ACSVM_Thread *(*allocThread)(ACSVM_Environment *env); - - ACSVM_Word (*callSpecImpl)(ACSVM_Environment *env, ACSVM_Thread *thread, - ACSVM_Word spec, ACSVM_Word const *argV, ACSVM_Word argC); - - // Return false if load fails. - bool (*loadModule)(ACSVM_Environment *env, ACSVM_Module *module); -} ACSVM_EnvironmentFuncs; - -#ifdef __cplusplus -// -// ACSVM_Environment -// -struct ACSVM_Environment : ACSVM::Environment -{ -public: - ACSVM_Environment(ACSVM_EnvironmentFuncs const &funcs, void *data); - virtual ~ACSVM_Environment(); - - virtual bool callFunc(ACSVM::Thread *thread, ACSVM::Word func, - ACSVM::Word const *argV, ACSVM::Word argC); - - virtual bool checkLock(ACSVM::Thread *thread, ACSVM::Word lock, bool door); - - virtual bool checkTag(ACSVM::Word type, ACSVM::Word tag); - - virtual ACSVM::ModuleName getModuleName(char const *str, size_t len); - - virtual void loadState(ACSVM::Serial &in); - - virtual void printArray(ACSVM::PrintBuf &buf, ACSVM::Array const &array, - ACSVM::Word index, ACSVM::Word limit); - - virtual void printKill(ACSVM::Thread *thread, ACSVM::Word type, ACSVM::Word data); - - virtual ACSVM::ModuleName readModuleName(ACSVM::Serial &in) const; - - virtual void refStrings(); - - virtual void resetStrings(); - - virtual void saveState(ACSVM::Serial &out) const; - - virtual void writeModuleName(ACSVM::Serial &out, ACSVM::ModuleName const &in) const; - - std::vector callFuncV; - ACSVM_EnvironmentFuncs funcs; - void *data; - -protected: - virtual ACSVM::Thread *allocThread(); - - virtual ACSVM::Word callSpecImpl(ACSVM::Thread *thread, ACSVM::Word spec, - ACSVM::Word const *argV, ACSVM::Word argC); - - virtual void loadModule(ACSVM::Module *module); -}; -#endif - - -//----------------------------------------------------------------------------| -// Extern Functions | -// - -ACSVM_Environment *ACSVM_AllocEnvironment(ACSVM_EnvironmentFuncs const *funcs, void *data); -void ACSVM_FreeEnvironment(ACSVM_Environment *env); - -ACSVM_Word ACSVM_Environment_AddCallFunc(ACSVM_Environment *env, ACSVM_CallFunc func); - -void ACSVM_Environment_AddCodeDataACS0(ACSVM_Environment *env, ACSVM_Word code, - char const *args, ACSVM_Code transCode, ACSVM_Word stackArgC, ACSVM_Word transFunc); - -void ACSVM_Environment_AddFuncDataACS0(ACSVM_Environment *env, ACSVM_Word func, - ACSVM_Word transFunc, ACSVM_Word const *transCodeArgCV, - ACSVM_Code const *transCodeV, size_t transCodeC); - -void ACSVM_Environment_CollectStrings(ACSVM_Environment *env); - -void ACSVM_Environment_Exec(ACSVM_Environment *env); - -void ACSVM_Environment_FreeGlobalScope(ACSVM_Environment *env, ACSVM_GlobalScope *scope); -void ACSVM_Environment_FreeModule(ACSVM_Environment *env, ACSVM_Module *module); - -ACSVM_Word ACSVM_Environment_GetBranchLimit(ACSVM_Environment const *env); -void *ACSVM_Environment_GetData(ACSVM_Environment const *env); -ACSVM_GlobalScope *ACSVM_Environment_GetGlobalScope(ACSVM_Environment *env, ACSVM_Word id); -ACSVM_Module *ACSVM_Environment_GetModule(ACSVM_Environment *env, ACSVM_ModuleName name); -ACSVM_Word ACSVM_Environment_GetScriptLocRegC(ACSVM_Environment const *env); -ACSVM_StringTable *ACSVM_Environment_GetStringTable(ACSVM_Environment *env); - -bool ACSVM_Environment_HasActiveThread(ACSVM_Environment const *env); - -bool ACSVM_Environment_LoadState(ACSVM_Environment *env, ACSVM_Serial *in); - -void ACSVM_Environment_SaveState(ACSVM_Environment *env, ACSVM_Serial *out); - -void ACSVM_Environment_SetBranchLimit(ACSVM_Environment *env, ACSVM_Word branchLimit); -void ACSVM_Environment_SetData(ACSVM_Environment *env, void *data); -void ACSVM_Environment_SetScriptLocRegC(ACSVM_Environment *env, ACSVM_Word scriptLocRegC); - -#ifdef __cplusplus -} -#endif - -#endif//ACSVM__CAPI__Environment_H__ - diff --git a/libs/ACSVM/include/CAPI/Floats.cpp b/libs/ACSVM/include/CAPI/Floats.cpp deleted file mode 100644 index 0a7880053..000000000 --- a/libs/ACSVM/include/CAPI/Floats.cpp +++ /dev/null @@ -1,88 +0,0 @@ -//---------------------------------------------------------------------------- -// -// Copyright (C) 2015 David Hill -// -// See COPYING for license information. -// -//---------------------------------------------------------------------------- -// -// Floating-point utilities. -// -//---------------------------------------------------------------------------- - -#include "Floats.h" - -#include "Thread.h" - - -extern "C" -{ - -//----------------------------------------------------------------------------| -// Extern Functions | -// - -// -// ACSVM_CF_* -// - -bool ACSVM_CF_AddF_W1(ACSVM_Thread *thread, ACSVM_Word const *argV, ACSVM_Word argC) - {return ACSVM::CF_AddF_W1(thread, argV, argC);} -bool ACSVM_CF_AddF_W2(ACSVM_Thread *thread, ACSVM_Word const *argV, ACSVM_Word argC) - {return ACSVM::CF_AddF_W2(thread, argV, argC);} -bool ACSVM_CF_DivF_W1(ACSVM_Thread *thread, ACSVM_Word const *argV, ACSVM_Word argC) - {return ACSVM::CF_DivF_W1(thread, argV, argC);} -bool ACSVM_CF_DivF_W2(ACSVM_Thread *thread, ACSVM_Word const *argV, ACSVM_Word argC) - {return ACSVM::CF_DivF_W2(thread, argV, argC);} -bool ACSVM_CF_MulF_W1(ACSVM_Thread *thread, ACSVM_Word const *argV, ACSVM_Word argC) - {return ACSVM::CF_MulF_W1(thread, argV, argC);} -bool ACSVM_CF_MulF_W2(ACSVM_Thread *thread, ACSVM_Word const *argV, ACSVM_Word argC) - {return ACSVM::CF_MulF_W2(thread, argV, argC);} -bool ACSVM_CF_SubF_W1(ACSVM_Thread *thread, ACSVM_Word const *argV, ACSVM_Word argC) - {return ACSVM::CF_SubF_W1(thread, argV, argC);} -bool ACSVM_CF_SubF_W2(ACSVM_Thread *thread, ACSVM_Word const *argV, ACSVM_Word argC) - {return ACSVM::CF_SubF_W2(thread, argV, argC);} - -bool ACSVM_CF_PrintDouble(ACSVM_Thread *thread, ACSVM_Word const *argV, ACSVM_Word argC) - {return ACSVM::CF_PrintDouble(thread, argV, argC);} -bool ACSVM_CF_PrintFloat(ACSVM_Thread *thread, ACSVM_Word const *argV, ACSVM_Word argC) - {return ACSVM::CF_PrintFloat(thread, argV, argC);} - -// -// ACSVM_DWordToDouble -// -double ACSVM_DWordToDouble(ACSVM_DWord w) -{ - return ACSVM::WordsToFloat( - {{static_cast(w), static_cast(w >> 32)}}); -} - -// -// ACSVM_DoubleToDWord -// -ACSVM_DWord ACSBM_DoubleToDWord(double f) -{ - auto w = ACSVM::FloatToWords<2>(f); - return (static_cast(w[1]) << 32) | w[0]; -} - -// -// ACSVM_FloatToWord -// -ACSVM_Word ACSVM_FloatToWord(float f) -{ - return ACSVM::FloatToWords<1>(f)[0]; -} - -// -// ACSVM_WordToFloat -// -float ACSVM_WordToFloat(ACSVM_Word w) -{ - return ACSVM::WordsToFloat({{w}}); -} - -} - -// EOF - diff --git a/libs/ACSVM/include/CAPI/Floats.h b/libs/ACSVM/include/CAPI/Floats.h deleted file mode 100644 index 7f02fba9d..000000000 --- a/libs/ACSVM/include/CAPI/Floats.h +++ /dev/null @@ -1,56 +0,0 @@ -//---------------------------------------------------------------------------- -// -// Copyright (C) 2015 David Hill -// -// See COPYING for license information. -// -//---------------------------------------------------------------------------- -// -// Floating-point utilities. -// -//---------------------------------------------------------------------------- - -#ifndef ACSVM__CAPI__Floats_H__ -#define ACSVM__CAPI__Floats_H__ - -#include "Types.h" - -#ifdef __cplusplus -#include "../Util/Floats.hpp" -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - -//----------------------------------------------------------------------------| -// Extern Functions | -// - -bool ACSVM_CF_AddF_W1(ACSVM_Thread *thread, ACSVM_Word const *argV, ACSVM_Word argC); -bool ACSVM_CF_AddF_W2(ACSVM_Thread *thread, ACSVM_Word const *argV, ACSVM_Word argC); -bool ACSVM_CF_DivF_W1(ACSVM_Thread *thread, ACSVM_Word const *argV, ACSVM_Word argC); -bool ACSVM_CF_DivF_W2(ACSVM_Thread *thread, ACSVM_Word const *argV, ACSVM_Word argC); -bool ACSVM_CF_MulF_W1(ACSVM_Thread *thread, ACSVM_Word const *argV, ACSVM_Word argC); -bool ACSVM_CF_MulF_W2(ACSVM_Thread *thread, ACSVM_Word const *argV, ACSVM_Word argC); -bool ACSVM_CF_SubF_W1(ACSVM_Thread *thread, ACSVM_Word const *argV, ACSVM_Word argC); -bool ACSVM_CF_SubF_W2(ACSVM_Thread *thread, ACSVM_Word const *argV, ACSVM_Word argC); - -bool ACSVM_CF_PrintDouble(ACSVM_Thread *thread, ACSVM_Word const *argV, ACSVM_Word argC); -bool ACSVM_CF_PrintFloat(ACSVM_Thread *thread, ACSVM_Word const *argV, ACSVM_Word argC); - -double ACSVM_DWordToDouble(ACSVM_DWord w); - -ACSVM_DWord ACSVM_DoubleToDWord(double f); - -ACSVM_Word ACSVM_FloatToWord(float f); - -float ACSVM_WordToFloat(ACSVM_Word w); - -#ifdef __cplusplus -} -#endif - -#endif//ACSVM__CAPI__Floats_H__ - diff --git a/libs/ACSVM/include/CAPI/Module.cpp b/libs/ACSVM/include/CAPI/Module.cpp deleted file mode 100644 index a270ec3ab..000000000 --- a/libs/ACSVM/include/CAPI/Module.cpp +++ /dev/null @@ -1,68 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (C) 2015 David Hill -// -// See COPYING for license information. -// -//----------------------------------------------------------------------------- -// -// Modules. -// -//----------------------------------------------------------------------------- - -#include "Module.h" - -#include "Environment.h" - -#include "ACSVM/Error.hpp" - - -extern "C" -{ - -//----------------------------------------------------------------------------| -// Extern Functions | -// - -// -// ACSVM_Module_GetName -// -ACSVM_ModuleName ACSVM_Module_GetName(ACSVM_Module const *module_) -{ - auto module = reinterpret_cast(module_); - - return {reinterpret_cast(module->name.s), module->name.p, module->name.i}; -} - -// -// ACSVM_Module_ReadBytecode -// -bool ACSVM_Module_ReadBytecode(ACSVM_Module *module_, ACSVM_Byte const *data, size_t size) -{ - auto module = reinterpret_cast(module_); - - try - { - module->readBytecode(data, size); - return true; - } - catch(ACSVM::ReadError const &e) - { - auto env = static_cast(module->env); - if(env->funcs.readError) - env->funcs.readError(env, e.what()); - return false; - } - catch(std::bad_alloc const &e) - { - auto env = static_cast(module->env); - if(env->funcs.bad_alloc) - env->funcs.bad_alloc(env, e.what()); - return false; - } -} - -} - -// EOF - diff --git a/libs/ACSVM/include/CAPI/Module.h b/libs/ACSVM/include/CAPI/Module.h deleted file mode 100644 index 618cd49bb..000000000 --- a/libs/ACSVM/include/CAPI/Module.h +++ /dev/null @@ -1,58 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (C) 2015 David Hill -// -// See COPYING for license information. -// -//----------------------------------------------------------------------------- -// -// Modules. -// -//----------------------------------------------------------------------------- - -#ifndef ACSVM__CAPI__Module_H__ -#define ACSVM__CAPI__Module_H__ - -#include "Types.h" - -#ifdef __cplusplus -#include "../ACSVM/Module.hpp" -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - -//----------------------------------------------------------------------------| -// Types | -// - -// -// ACSVM_ModuleName -// -// ACSVM::ModuleName mirror. -// -struct ACSVM_ModuleName -{ - ACSVM_String *s; - void *p; - size_t i; -}; - - -//----------------------------------------------------------------------------| -// Extern Functions | -// - -ACSVM_ModuleName ACSVM_Module_GetName(ACSVM_Module const *module); - -// Returns false if reading fails. -bool ACSVM_Module_ReadBytecode(ACSVM_Module *module, ACSVM_Byte const *data, size_t size); - -#ifdef __cplusplus -} -#endif - -#endif//ACSVM__CAPI__Module_H__ - diff --git a/libs/ACSVM/include/CAPI/PrintBuf.cpp b/libs/ACSVM/include/CAPI/PrintBuf.cpp deleted file mode 100644 index e3c4f5d77..000000000 --- a/libs/ACSVM/include/CAPI/PrintBuf.cpp +++ /dev/null @@ -1,159 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (C) 2015 David Hill -// -// See COPYING for license information. -// -//----------------------------------------------------------------------------- -// -// PrintBuf class. -// -//----------------------------------------------------------------------------- - -#include "PrintBuf.h" - -#include - - -extern "C" -{ - -//----------------------------------------------------------------------------| -// Extern Functions | -// - -// -// ACSVM_AllocPrintBuf -// -ACSVM_PrintBuf *ACSVM_AllocPrintBuf(void) -{ - return reinterpret_cast(new(std::nothrow) ACSVM::PrintBuf); -} - -// -// ACSVM_FreePrintBuf -// -void ACSVM_FreePrintBuf(ACSVM_PrintBuf *buf) -{ - delete reinterpret_cast(buf); -} - -// -// ACSVM_PrintBuf_Clear -// -void ACSVM_PrintBuf_Clear(ACSVM_PrintBuf *buf) -{ - reinterpret_cast(buf)->clear(); -} - -// -// ACSVM_PrintBuf_Drop -// -void ACSVM_PrintBuf_Drop(ACSVM_PrintBuf *buf) -{ - reinterpret_cast(buf)->drop(); -} - -// -// ACSVM_PrintBuf_Format -// -void ACSVM_PrintBuf_Format(ACSVM_PrintBuf *buf, char const *fmt, ...) -{ - va_list arg; - va_start(arg, fmt); - reinterpret_cast(buf)->formatv(fmt, arg); - va_end(arg); -} - -// -// ACSVM_PrintBuf_FormatV -// -void ACSVM_PrintBuf_FormatV(ACSVM_PrintBuf *buf, char const *fmt, va_list arg) -{ - reinterpret_cast(buf)->formatv(fmt, arg); -} - -// -// ACSVM_PrintBuf_GetBuf -// -char *ACSVM_PrintBuf_GetBuf(ACSVM_PrintBuf *buf, size_t count) -{ - return reinterpret_cast(buf)->getBuf(count); -} - -// -// ACSVM_PrintBuf_GetData -// -char const *ACSVM_PrintBuf_GetData(ACSVM_PrintBuf const *buf) -{ - return reinterpret_cast(buf)->data(); -} - -// -// ACSVM_PrintBuf_GetDataFull -// -char const *ACSVM_PrintBuf_GetDataFull(ACSVM_PrintBuf const *buf) -{ - return reinterpret_cast(buf)->dataFull(); -} - -// -// ACSVM_PrintBuf_GetLoadBuf -// -char *ACSVM_PrintBuf_GetLoadBuf(ACSVM_PrintBuf *buf, size_t countFull, size_t count) -{ - return reinterpret_cast(buf)->getLoadBuf(countFull, count); -} - -// -// ACSVM_PrintBuf_Push -// -void ACSVM_PrintBuf_Push(ACSVM_PrintBuf *buf) -{ - reinterpret_cast(buf)->push(); -} - -// -// ACSVM_PrintBuf_PutC -// -void ACSVM_PrintBuf_PutC(ACSVM_PrintBuf *buf, char c) -{ - reinterpret_cast(buf)->put(c); -} - -// -// ACSVM_PrintBuf_PutS -// -void ACSVM_PrintBuf_PutS(ACSVM_PrintBuf *buf, char const *s, size_t n) -{ - reinterpret_cast(buf)->put(s, n); -} - -// -// ACSVM_PrintBuf_Reserve -// -void ACSVM_PrintBuf_Reserve(ACSVM_PrintBuf *buf, size_t count) -{ - reinterpret_cast(buf)->reserve(count); -} - -// -// ACSVM_PrintBuf_Size -// -size_t ACSVM_PrintBuf_Size(ACSVM_PrintBuf const *buf) -{ - return reinterpret_cast(buf)->size(); -} - -// -// ACSVM_PrintBuf_SizeFull -// -size_t ACSVM_PrintBuf_SizeFull(ACSVM_PrintBuf const *buf) -{ - return reinterpret_cast(buf)->sizeFull(); -} - -} - -// EOF - diff --git a/libs/ACSVM/include/CAPI/PrintBuf.h b/libs/ACSVM/include/CAPI/PrintBuf.h deleted file mode 100644 index 5cca535d0..000000000 --- a/libs/ACSVM/include/CAPI/PrintBuf.h +++ /dev/null @@ -1,63 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (C) 2015 David Hill -// -// See COPYING for license information. -// -//----------------------------------------------------------------------------- -// -// PrintBuf class. -// -//----------------------------------------------------------------------------- - -#ifndef ACSVM__CAPI__PrintBuf_H__ -#define ACSVM__CAPI__PrintBuf_H__ - -#include "Types.h" - -#ifdef __cplusplus -#include "../ACSVM/PrintBuf.hpp" -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - -//----------------------------------------------------------------------------| -// Extern Functions | -// - -ACSVM_PrintBuf *ACSVM_AllocPrintBuf(void); -void ACSVM_FreePrintBuf(ACSVM_PrintBuf *buf); - -void ACSVM_PrintBuf_Clear(ACSVM_PrintBuf *buf); - -void ACSVM_PrintBuf_Drop(ACSVM_PrintBuf *buf); - -void ACSVM_PrintBuf_Format(ACSVM_PrintBuf *buf, char const *fmt, ...); -void ACSVM_PrintBuf_FormatV(ACSVM_PrintBuf *buf, char const *fmt, va_list arg); - -char *ACSVM_PrintBuf_GetBuf(ACSVM_PrintBuf *buf, size_t count); - -char const *ACSVM_PrintBuf_GetData(ACSVM_PrintBuf const *buf); -char const *ACSVM_PrintBuf_GetDataFull(ACSVM_PrintBuf const *buf); - -char *ACSVM_PrintBuf_GetLoadBuf(ACSVM_PrintBuf *buf, size_t countFull, size_t count); - -void ACSVM_PrintBuf_Push(ACSVM_PrintBuf *buf); - -void ACSVM_PrintBuf_PutC(ACSVM_PrintBuf *buf, char c); -void ACSVM_PrintBuf_PutS(ACSVM_PrintBuf *buf, char const *s, size_t n); - -void ACSVM_PrintBuf_Reserve(ACSVM_PrintBuf *buf, size_t count); - -size_t ACSVM_PrintBuf_Size(ACSVM_PrintBuf const *buf); -size_t ACSVM_PrintBuf_SizeFull(ACSVM_PrintBuf const *buf); - -#ifdef __cplusplus -} -#endif - -#endif//ACSVM__CAPI__PrintBuf_H__ - diff --git a/libs/ACSVM/include/CAPI/Scope.cpp b/libs/ACSVM/include/CAPI/Scope.cpp deleted file mode 100644 index f903704bd..000000000 --- a/libs/ACSVM/include/CAPI/Scope.cpp +++ /dev/null @@ -1,363 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (C) 2015-2017 David Hill -// -// See COPYING for license information. -// -//----------------------------------------------------------------------------- -// -// Scopes. -// -//----------------------------------------------------------------------------- - -#include "Scope.h" - -#include "Environment.h" -#include "Script.h" -#include "Thread.h" - -#include "ACSVM/Action.hpp" - - -extern "C" -{ - -//----------------------------------------------------------------------------| -// Extern Functions | -// - -// -// ACSVM_GlobalScope_FreeHubScope -// -void ACSVM_GlobalScope_FreeHubScope(ACSVM_GlobalScope *scope, ACSVM_HubScope *scopeHub) -{ - reinterpret_cast(scope) - ->freeHubScope(reinterpret_cast(scopeHub)); -} - -// -// ACSVM_GlobalScope_GetGblArr -// -ACSVM_Array *ACSVM_GlobalScope_GetGblArr(ACSVM_GlobalScope *scope, ACSVM_Word idx) -{ - return reinterpret_cast(&reinterpret_cast(scope)->arrV[idx]); -} - -// -// ACSVM_GlobalScope_GetGblArrC -// -ACSVM_Word ACSVM_GlobalScope_GetGblArrC(ACSVM_GlobalScope const *) -{ - return ACSVM::GlobalScope::ArrC; -} - -// -// ACSVM_GlobalScope_GetHubScope -// -ACSVM_HubScope *ACSVM_GlobalScope_GetHubScope(ACSVM_GlobalScope *scope_, ACSVM_Word id) -{ - auto scope = reinterpret_cast(scope_); - - try - { - return reinterpret_cast(scope->getHubScope(id)); - } - catch(std::bad_alloc const &e) - { - auto env = static_cast(scope->env); - if(env->funcs.bad_alloc) - env->funcs.bad_alloc(env, e.what()); - - return nullptr; - } -} - -// -// ACSVM_GlobalScope_GetGblReg -// -ACSVM_Word ACSVM_GlobalScope_GetGblReg(ACSVM_GlobalScope const *scope, ACSVM_Word idx) -{ - return reinterpret_cast(scope)->regV[idx]; -} - -// -// ACSVM_GlobalScope_GetGblRegC -// -ACSVM_Word ACSVM_GlobalScope_GetGblRegC(ACSVM_GlobalScope const *) -{ - return ACSVM::GlobalScope::RegC; -} - -// -// ACSVM_GlobalScope_SetActive -// -void ACSVM_GlobalScope_SetActive(ACSVM_GlobalScope *scope, bool active) -{ - reinterpret_cast(scope)->active = active; -} - -// -// ACSVM_GlobalScope_SetGblReg -// -void ACSVM_GlobalScope_SetGblReg(ACSVM_GlobalScope *scope, ACSVM_Word idx, ACSVM_Word reg) -{ - reinterpret_cast(scope)->regV[idx] = reg; -} - -// -// ACSVM_HubScope_FreeMapScope -// -void ACSVM_HubScope_FreeMapScope(ACSVM_HubScope *scope, ACSVM_MapScope *scopeMap) -{ - reinterpret_cast(scope) - ->freeMapScope(reinterpret_cast(scopeMap)); -} - -// -// ACSVM_HubScope_GetHubArr -// -ACSVM_Array *ACSVM_HubScope_GetHubArr(ACSVM_HubScope *scope, ACSVM_Word idx) -{ - return reinterpret_cast(&reinterpret_cast(scope)->arrV[idx]); -} - -// -// ACSVM_HubScope_GetHubArrC -// -ACSVM_Word ACSVM_HubScope_GetHubArrC(ACSVM_HubScope const *) -{ - return ACSVM::HubScope::ArrC; -} - -// -// ACSVM_HubScope_GetMapScope -// -ACSVM_MapScope *ACSVM_HubScope_GetMapScope(ACSVM_HubScope *scope_, ACSVM_Word id) -{ - auto scope = reinterpret_cast(scope_); - - try - { - return reinterpret_cast(scope->getMapScope(id)); - } - catch(std::bad_alloc const &e) - { - auto env = static_cast(scope->env); - if(env->funcs.bad_alloc) - env->funcs.bad_alloc(env, e.what()); - - return nullptr; - } -} - -// -// ACSVM_HubScope_GetHubReg -// -ACSVM_Word ACSVM_HubScope_GetHubReg(ACSVM_HubScope const *scope, ACSVM_Word idx) -{ - return reinterpret_cast(scope)->regV[idx]; -} - -// -// ACSVM_HubScope_GetHubRegC -// -ACSVM_Word ACSVM_HubScope_GetHubRegC(ACSVM_HubScope const *) -{ - return ACSVM::HubScope::RegC; -} - -// -// ACSVM_HubScope_SetActive -// -void ACSVM_HubScope_SetActive(ACSVM_HubScope *scope, bool active) -{ - reinterpret_cast(scope)->active = active; -} - -// -// ACSVM_HubScope_SetHubReg -// -void ACSVM_HubScope_SetHubReg(ACSVM_HubScope *scope, ACSVM_Word idx, ACSVM_Word reg) -{ - reinterpret_cast(scope)->regV[idx] = reg; -} - -// -// ACSVM_MapScope_AddModule -// -void ACSVM_MapScope_AddModules(ACSVM_MapScope *scope_, - ACSVM_Module *const *moduleV, size_t moduleC) -{ - auto scope = reinterpret_cast(scope_); - - try - { - scope->addModules(reinterpret_cast(moduleV), moduleC); - } - catch(std::bad_alloc const &e) - { - auto env = static_cast(scope->env); - if(env->funcs.bad_alloc) - env->funcs.bad_alloc(env, e.what()); - } -} - -// -// ACSVM_MapScope_GetModuleScope -// -ACSVM_ModuleScope *ACSVM_MapScope_GetModuleScope(ACSVM_MapScope *scope, ACSVM_Module *module) -{ - return reinterpret_cast( - reinterpret_cast(scope)->getModuleScope( - reinterpret_cast(module))); -} - -// -// ACSVM_MapScope_HasModules -// -bool ACSVM_MapScope_HasModules(ACSVM_MapScope const *scope) -{ - return reinterpret_cast(scope)->hasModules(); -} - -// -// ACSVM_MapScope_ScriptPause -// -bool ACSVM_MapScope_ScriptPause(ACSVM_MapScope *scope, - ACSVM_ScriptName name_, ACSVM_ScopeID id) -{ - ACSVM::ScriptName name{reinterpret_cast(name_.s), name_.i}; - return reinterpret_cast(scope) - ->scriptPause(name, {id.global, id.hub, id.map}); -} - -// -// ACSVM_MapScope_ScriptStart -// -bool ACSVM_MapScope_ScriptStart(ACSVM_MapScope *scope, - ACSVM_ScriptName name_, ACSVM_ScopeID id, ACSVM_Word const *argV, ACSVM_Word argC, - ACSVM_ThreadInfo const *info, void (*func)(void *thread)) -{ - ACSVM::ScriptName name{reinterpret_cast(name_.s), name_.i}; - return reinterpret_cast(scope) - ->scriptStart(name, {id.global, id.hub, id.map}, {argV, argC, info, func}); -} - -// -// ACSVM_MapScope_ScriptStartForced -// -bool ACSVM_MapScope_ScriptStartForced(ACSVM_MapScope *scope, - ACSVM_ScriptName name_, ACSVM_ScopeID id, ACSVM_Word const *argV, ACSVM_Word argC, - ACSVM_ThreadInfo const *info, void (*func)(void *thread)) -{ - ACSVM::ScriptName name{reinterpret_cast(name_.s), name_.i}; - return reinterpret_cast(scope) - ->scriptStartForced(name, {id.global, id.hub, id.map}, {argV, argC, info, func}); -} - -// -// ACSVM_MapScope_ScriptStartResult -// -ACSVM_Word ACSVM_MapScope_ScriptStartResult(ACSVM_MapScope *scope, - ACSVM_ScriptName name_, ACSVM_Word const *argV, ACSVM_Word argC, - ACSVM_ThreadInfo const *info, void (*func)(void *thread)) -{ - ACSVM::ScriptName name{reinterpret_cast(name_.s), name_.i}; - return reinterpret_cast(scope) - ->scriptStartResult(name, {argV, argC, info, func}); -} - -// -// ACSVM_MapScope_ScriptStartType -// -ACSVM_Word ACSVM_MapScope_ScriptStartType(ACSVM_MapScope *scope, - ACSVM_Word type, ACSVM_Word const *argV, ACSVM_Word argC, - ACSVM_ThreadInfo const *info, void (*func)(void *thread)) -{ - return reinterpret_cast(scope) - ->scriptStartType(type, {argV, argC, info, func}); -} - -// -// ACSVM_MapScope_ScriptStartTypeForced -// -ACSVM_Word ACSVM_MapScope_ScriptStartTypeForced(ACSVM_MapScope *scope, - ACSVM_Word type, ACSVM_Word const *argV, ACSVM_Word argC, - ACSVM_ThreadInfo const *info, void (*func)(void *thread)) -{ - return reinterpret_cast(scope) - ->scriptStartTypeForced(type, {argV, argC, info, func}); -} - -// -// ACSVM_MapScope_ScriptStop -// -bool ACSVM_MapScope_ScriptStop(ACSVM_MapScope *scope, - ACSVM_ScriptName name_, ACSVM_ScopeID id) -{ - ACSVM::ScriptName name{reinterpret_cast(name_.s), name_.i}; - return reinterpret_cast(scope) - ->scriptStop(name, {id.global, id.hub, id.map}); -} - -// -// ACSVM_MapScope_GetString -// -ACSVM_String *ACSVM_MapScope_GetString(ACSVM_MapScope *scope, ACSVM::Word idx) -{ - return reinterpret_cast( - reinterpret_cast(scope)->getString(idx)); -} - -// -// ACSVM_MapScope_SetActive -// -void ACSVM_MapScope_SetActive(ACSVM_MapScope *scope, bool active) -{ - reinterpret_cast(scope)->active = active; -} - -// -// ACSVM_ModuleScope_GetModArr -// -ACSVM_Array *ACSVM_ModuleScope_GetModArr(ACSVM_ModuleScope *scope, ACSVM_Word idx) -{ - return reinterpret_cast(reinterpret_cast(scope)->arrV[idx]); -} - -// -// ACSVM_ModuleScope_GetModArrC -// -ACSVM_Word ACSVM_ModuleScope_GetModArrC(ACSVM_ModuleScope const *) -{ - return ACSVM::ModuleScope::ArrC; -} - -// -// ACSVM_ModuleScope_SetModReg -// -void ACSVM_ModuleScope_SetModReg(ACSVM_ModuleScope *scope, ACSVM_Word idx, ACSVM_Word reg) -{ - *reinterpret_cast(scope)->regV[idx] = reg; -} - -// -// ACSVM_ModuleScope_GetModReg -// -ACSVM_Word ACSVM_ModuleScope_GetModReg(ACSVM_ModuleScope const *scope, ACSVM_Word idx) -{ - return *reinterpret_cast(scope)->regV[idx]; -} - -// -// ACSVM_ModuleScope_GetModRegC -// -ACSVM_Word ACSVM_ModuleScope_GetModRegC(ACSVM_ModuleScope const *) -{ - return ACSVM::ModuleScope::RegC; -} - -} - -// EOF - diff --git a/libs/ACSVM/include/CAPI/Scope.h b/libs/ACSVM/include/CAPI/Scope.h deleted file mode 100644 index 683f0388f..000000000 --- a/libs/ACSVM/include/CAPI/Scope.h +++ /dev/null @@ -1,117 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (C) 2015-2017 David Hill -// -// See COPYING for license information. -// -//----------------------------------------------------------------------------- -// -// Scopes. -// -//----------------------------------------------------------------------------- - -#ifndef ACSVM__CAPI__Scope_H__ -#define ACSVM__CAPI__Scope_H__ - -#include "Types.h" - -#ifdef __cplusplus -#include "../ACSVM/Scope.hpp" -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - -//----------------------------------------------------------------------------| -// Types | -// - -// -// ACSVM_ScopeID -// -struct ACSVM_ScopeID -{ - ACSVM_Word global; - ACSVM_Word hub; - ACSVM_Word map; -}; - - -//----------------------------------------------------------------------------| -// Extern Functions | -// - -void ACSVM_GlobalScope_FreeHubScope(ACSVM_GlobalScope *scope, ACSVM_HubScope *scopeHub); - -ACSVM_Array *ACSVM_GlobalScope_GetGblArr (ACSVM_GlobalScope *scope, ACSVM_Word idx); -ACSVM_Word ACSVM_GlobalScope_GetGblArrC (ACSVM_GlobalScope const *scope); -ACSVM_HubScope *ACSVM_GlobalScope_GetHubScope(ACSVM_GlobalScope *scope, ACSVM_Word id); -ACSVM_Word ACSVM_GlobalScope_GetGblReg (ACSVM_GlobalScope const *scope, ACSVM_Word idx); -ACSVM_Word ACSVM_GlobalScope_GetGblRegC (ACSVM_GlobalScope const *scope); - -void ACSVM_GlobalScope_SetActive(ACSVM_GlobalScope *scope, bool active); -void ACSVM_GlobalScope_SetGblReg(ACSVM_GlobalScope *scope, ACSVM_Word idx, ACSVM_Word reg); - -void ACSVM_HubScope_FreeMapScope(ACSVM_HubScope *scope, ACSVM_MapScope *scopeMap); - -ACSVM_Array *ACSVM_HubScope_GetHubArr (ACSVM_HubScope *scope, ACSVM_Word idx); -ACSVM_Word ACSVM_HubScope_GetHubArrC (ACSVM_HubScope const *scope); -ACSVM_MapScope *ACSVM_HubScope_GetMapScope(ACSVM_HubScope *scope, ACSVM_Word id); -ACSVM_Word ACSVM_HubScope_GetHubReg (ACSVM_HubScope const *scope, ACSVM_Word idx); -ACSVM_Word ACSVM_HubScope_GetHubRegC (ACSVM_HubScope const *scope); - -void ACSVM_HubScope_SetActive(ACSVM_HubScope *scope, bool active); -void ACSVM_HubScope_SetHubReg(ACSVM_HubScope *scope, ACSVM_Word idx, ACSVM_Word reg); - -void ACSVM_MapScope_AddModules(ACSVM_MapScope *scope, - ACSVM_Module *const *moduleV, size_t moduleC); - -ACSVM_ModuleScope *ACSVM_MapScope_GetModuleScope(ACSVM_MapScope *scope, ACSVM_Module *module); - -bool ACSVM_MapScope_HasModules(ACSVM_MapScope const *scope); - -bool ACSVM_MapScope_ScriptPause(ACSVM_MapScope *scope, - ACSVM_ScriptName name, ACSVM_ScopeID id); - -bool ACSVM_MapScope_ScriptStart(ACSVM_MapScope *scope, - ACSVM_ScriptName name, ACSVM_ScopeID id, ACSVM_Word const *argV, ACSVM_Word argC, - ACSVM_ThreadInfo const *info, void (*func)(void *thread)); - -bool ACSVM_MapScope_ScriptStartForced(ACSVM_MapScope *scope, - ACSVM_ScriptName name, ACSVM_ScopeID id, ACSVM_Word const *argV, ACSVM_Word argC, - ACSVM_ThreadInfo const *info, void (*func)(void *thread)); - -ACSVM_Word ACSVM_MapScope_ScriptStartResult(ACSVM_MapScope *scope, - ACSVM_ScriptName name, ACSVM_Word const *argV, ACSVM_Word argC, - ACSVM_ThreadInfo const *info, void (*func)(void *thread)); - -ACSVM_Word ACSVM_MapScope_ScriptStartType(ACSVM_MapScope *scope, - ACSVM_Word type, ACSVM_Word const *argV, ACSVM_Word argC, - ACSVM_ThreadInfo const *info, void (*func)(void *thread)); - -ACSVM_Word ACSVM_MapScope_ScriptStartTypeForced(ACSVM_MapScope *scope, - ACSVM_Word type, ACSVM_Word const *argV, ACSVM_Word argC, - ACSVM_ThreadInfo const *info, void (*func)(void *thread)); - -bool ACSVM_MapScope_ScriptStop(ACSVM_MapScope *scope, - ACSVM_ScriptName name, ACSVM_ScopeID id); - -ACSVM_String *ACSVM_MapScope_GetString(ACSVM_MapScope *scope, ACSVM_Word idx); - -void ACSVM_MapScope_SetActive(ACSVM_MapScope *scope, bool active); - -ACSVM_Array *ACSVM_ModuleScope_GetModArr (ACSVM_ModuleScope *scope, ACSVM_Word idx); -ACSVM_Word ACSVM_ModuleScope_GetModArrC(ACSVM_ModuleScope const *scope); -ACSVM_Word ACSVM_ModuleScope_GetModReg (ACSVM_ModuleScope const *scope, ACSVM_Word idx); -ACSVM_Word ACSVM_ModuleScope_GetModRegC(ACSVM_ModuleScope const *scope); - -void ACSVM_ModuleScope_SetModReg(ACSVM_ModuleScope *scope, ACSVM_Word idx, ACSVM_Word reg); - -#ifdef __cplusplus -} -#endif - -#endif//ACSVM__CAPI__Scope_H__ - diff --git a/libs/ACSVM/include/CAPI/Script.h b/libs/ACSVM/include/CAPI/Script.h deleted file mode 100644 index 6aa843c0e..000000000 --- a/libs/ACSVM/include/CAPI/Script.h +++ /dev/null @@ -1,52 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (C) 2015-2017 David Hill -// -// See COPYING for license information. -// -//----------------------------------------------------------------------------- -// -// Scripts. -// -//----------------------------------------------------------------------------- - -#ifndef ACSVM__CAPI__Script_H__ -#define ACSVM__CAPI__Script_H__ - -#include "Types.h" - -#ifdef __cplusplus -#include "ACSVM/Script.hpp" -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - -//----------------------------------------------------------------------------| -// Types | -// - -// -// ACSVM_ScriptName -// -// ACSVM::ScriptName mirror. -// -struct ACSVM_ScriptName -{ - ACSVM_String *s; - ACSVM_Word i; -}; - - -//----------------------------------------------------------------------------| -// Extern Functions | -// - -#ifdef __cplusplus -} -#endif - -#endif//ACSVM__CAPI__Script_H__ - diff --git a/libs/ACSVM/include/CAPI/String.cpp b/libs/ACSVM/include/CAPI/String.cpp deleted file mode 100644 index 471b3675c..000000000 --- a/libs/ACSVM/include/CAPI/String.cpp +++ /dev/null @@ -1,184 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (C) 2015 David Hill -// -// See COPYING for license information. -// -//----------------------------------------------------------------------------- -// -// Strings. -// -//----------------------------------------------------------------------------- - -#include "ACS_String.h" - - -extern "C" -{ - -//----------------------------------------------------------------------------| -// Extern Functions | -// - -// -// ACSVM_StrHash -// -size_t ACSVM_StrHash(char const *str, size_t len) -{ - return ACSVM::StrHash(str, len); -} - -// -// ACSVM_String_GetHash -// -size_t ACSVM_String_GetHash(ACSVM_String const *s) -{ - return reinterpret_cast(s)->hash; -} - -// -// ACSVM_String_GetIdx -// -ACSVM_Word ACSVM_String_GetIdx(ACSVM_String const *s) -{ - return reinterpret_cast(s)->idx; -} - -// -// ACSVM_String_GetLen -// -size_t ACSVM_String_GetLen(ACSVM_String const *s) -{ - return reinterpret_cast(s)->len; -} - -// -// ACSVM_String_GetLen0 -// -ACSVM_Word ACSVM_String_GetLen0(ACSVM_String const *s) -{ - return reinterpret_cast(s)->len0; -} - -// -// ACSVM_String_GetLock -// -size_t ACSVM_String_GetLock(ACSVM_String const *s) -{ - return reinterpret_cast(s)->lock; -} - -// -// ACSVM_String_GetStr -// -char const *ACSVM_String_GetStr(ACSVM_String const *s) -{ - return reinterpret_cast(s)->str; -} - -// -// ACSVM_String_SetLock -// -void ACSVM_String_SetLock(ACSVM_String *s, size_t lock) -{ - reinterpret_cast(s)->lock = lock; -} - -// -// ACSVM_String_SetRef -// -void ACSVM_String_SetRef(ACSVM_String *s) -{ - reinterpret_cast(s)->ref = true; -} - -// -// ACSVM_AllocStringTable -// -ACSVM_StringTable *ACSVM_AllocStringTable(void) -{ - return reinterpret_cast(new(std::nothrow) ACSVM::StringTable); -} - -// -// ACSVM_FreeStringTable -// -void ACSVM_FreeStringTable(ACSVM_StringTable *table) -{ - delete reinterpret_cast(table); -} - -// -// ACSVM_StringTable_Clear -// -void ACSVM_StringTable_Clear(ACSVM_StringTable *table) -{ - reinterpret_cast(table)->clear(); -} - -// -// ACSVM_StringTable_CollectBegin -// -void ACSVM_StringTable_CollectBegin(ACSVM_StringTable *table) -{ - reinterpret_cast(table)->collectBegin(); -} - -// -// ACSVM_StringTable_CollectEnd -// -void ACSVM_StringTable_CollectEnd(ACSVM_StringTable *table) -{ - reinterpret_cast(table)->collectEnd(); -} - -// -// ACSVM_StringTable_GetNone -// -ACSVM_String *ACSVM_StringTable_GetNone(ACSVM_StringTable *table) -{ - return reinterpret_cast( - &reinterpret_cast(table)->getNone()); -} - -// -// ACSVM_StringTable_GetStringByData -// -ACSVM_String *ACSVM_StringTable_GetStringByData(ACSVM_StringTable *table, - char const *str, size_t len, size_t hash) -{ - return reinterpret_cast( - &reinterpret_cast(*table)[{str, len, hash}]); -} - -// -// ACSVM_StringTable_GetStringByIdx -// -ACSVM_String *ACSVM_StringTable_GetStringByIdx(ACSVM_StringTable *table, ACSVM::Word idx) -{ - return reinterpret_cast( - &reinterpret_cast(*table)[idx]); -} - -// -// ACSVM_StringTable_LoadState -// -void ACSVM_StringTable_LoadState(ACSVM_StringTable *table, ACSVM_IStream *in) -{ - reinterpret_cast(table)->loadState( - reinterpret_cast(*in)); -} - -// -// ACSVM_StringTable_SaveState -// -void ACSVM_StringTable_SaveState(ACSVM_StringTable *table, ACSVM_OStream *out) -{ - reinterpret_cast(table)->saveState( - reinterpret_cast(*out)); -} - -} - -// EOF - diff --git a/libs/ACSVM/include/CAPI/String.h b/libs/ACSVM/include/CAPI/String.h deleted file mode 100644 index cbf4b7a6f..000000000 --- a/libs/ACSVM/include/CAPI/String.h +++ /dev/null @@ -1,65 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (C) 2015 David Hill -// -// See COPYING for license information. -// -//----------------------------------------------------------------------------- -// -// Strings. -// -//----------------------------------------------------------------------------- - -#ifndef ACSVM__CAPI__String_H__ -#define ACSVM__CAPI__String_H__ - -#include "Types.h" - -#ifdef __cplusplus -#include "../ACSVM/String.hpp" -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - -//----------------------------------------------------------------------------| -// Extern Functions | -// - -size_t ACSVM_StrHash(char const *str, size_t len); - -size_t ACSVM_String_GetHash(ACSVM_String const *s); -ACSVM_Word ACSVM_String_GetIdx (ACSVM_String const *s); -size_t ACSVM_String_GetLen (ACSVM_String const *s); -ACSVM_Word ACSVM_String_GetLen0(ACSVM_String const *s); -size_t ACSVM_String_GetLock(ACSVM_String const *s); -char const *ACSVM_String_GetStr (ACSVM_String const *s); - -void ACSVM_String_SetLock(ACSVM_String *s, size_t lock); -void ACSVM_String_SetRef (ACSVM_String *s); - -ACSVM_StringTable *ACSVM_AllocStringTable(void); -void ACSVM_FreeStringTable(ACSVM_StringTable *table); - -void ACSVM_StringTable_Clear(ACSVM_StringTable *table); - -void ACSVM_StringTable_CollectBegin(ACSVM_StringTable *table); -void ACSVM_StringTable_CollectEnd(ACSVM_StringTable *table); - -ACSVM_String *ACSVM_StringTable_GetNone(ACSVM_StringTable *table); -ACSVM_String *ACSVM_StringTable_GetStringByData(ACSVM_StringTable *table, - char const *str, size_t len, size_t hash); -ACSVM_String *ACSVM_StringTable_GetStringByIdx(ACSVM_StringTable *table, ACSVM_Word idx); - -void ACSVM_StringTable_LoadState(ACSVM_StringTable *table, ACSVM_IStream *in); - -void ACSVM_StringTable_SaveState(ACSVM_StringTable *table, ACSVM_OStream *out); - -#ifdef __cplusplus -} -#endif - -#endif//ACSVM__CAPI__String_H__ - diff --git a/libs/ACSVM/include/CAPI/Thread.cpp b/libs/ACSVM/include/CAPI/Thread.cpp deleted file mode 100644 index 7047128ac..000000000 --- a/libs/ACSVM/include/CAPI/Thread.cpp +++ /dev/null @@ -1,373 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (C) 2015-2017 David Hill -// -// See COPYING for license information. -// -//----------------------------------------------------------------------------- -// -// Threads. -// -//----------------------------------------------------------------------------- - -#include "Thread.h" - -#include "Array.h" -#include "Environment.h" - - -extern "C" -{ - -//----------------------------------------------------------------------------| -// Extern Functions | -// - -// -// ACSVM_ThreadInfo constructor -// -ACSVM_ThreadInfo::ACSVM_ThreadInfo(void *data_) : - data{data_} -{ -} - -// -// ACSVM_ThreadInfo destructor -// -ACSVM_ThreadInfo::~ACSVM_ThreadInfo() -{ -} - -// -// ACSVM_Thread constructor -// -ACSVM_Thread::ACSVM_Thread(ACSVM_Environment *env_, ACSVM_ThreadFuncs const &funcs_, void *data_) : - ACSVM::Thread{env_}, funcs{funcs_}, info{data_} -{ - if(funcs.ctor) - funcs.ctor(this); -} - -// -// ACSVM_Thread destructor -// -ACSVM_Thread::~ACSVM_Thread() -{ - if(funcs.dtor) - funcs.dtor(this); -} - -// -// ACSVM_Thread::getInfo -// -ACSVM::ThreadInfo const *ACSVM_Thread::getInfo() const -{ - return &info; -} - -// -// ACSVM_Thread::loadState -// -void ACSVM_Thread::loadState(ACSVM::Serial &in) -{ - ACSVM::Thread::loadState(in); - - if(funcs.loadState) - funcs.loadState(this, reinterpret_cast(&in)); -} - -// -// ACSVM_Thread::lockStrings -// -void ACSVM_Thread::lockStrings() const -{ - ACSVM::Thread::lockStrings(); - - if(funcs.lockStrings) - funcs.lockStrings(this); -} - -// -// ACSVM_Thread::refStrings -// -void ACSVM_Thread::refStrings() const -{ - ACSVM::Thread::refStrings(); - - if(funcs.refStrings) - funcs.refStrings(this); -} - -// -// ACSVM_Thread::saveState -// -void ACSVM_Thread::saveState(ACSVM::Serial &out) const -{ - ACSVM::Thread::saveState(out); - - if(funcs.saveState) - funcs.saveState(this, reinterpret_cast(&out)); -} - -// -// ACSVM_Thread::start -// -void ACSVM_Thread::start(ACSVM::Script *script, ACSVM::MapScope *map, - ACSVM::ThreadInfo const *infoPtr, ACSVM::Word const *argV, ACSVM::Word argC) -{ - ACSVM::Thread::start(script, map, infoPtr, argV, argC); - - if(funcs.start) - { - auto infoDer = dynamic_cast(infoPtr); - funcs.start(this, infoDer ? infoDer->data : nullptr); - } -} - -// -// ACSVM_Thread::stop -// -void ACSVM_Thread::stop() -{ - ACSVM::Thread::stop(); - - if(funcs.stop) - funcs.stop(this); -} - -// -// ACSVM_Thread::unlockStrings -// -void ACSVM_Thread::unlockStrings() const -{ - ACSVM::Thread::unlockStrings(); - - if(funcs.unlockStrings) - funcs.unlockStrings(this); -} - -// -// ACSVM_AllocThread -// -ACSVM_Thread *ACSVM_AllocThread(ACSVM_Environment *env, - ACSVM_ThreadFuncs const *funcs, void *data) -{ - return new(std::nothrow) ACSVM_Thread(env, *funcs, data); -} - -// -// ACSVM_AllocThreadInfo -// -ACSVM_ThreadInfo *ACSVM_AllocThreadInfo(void *data) -{ - return new(std::nothrow) ACSVM_ThreadInfo(data); -} - -// -// ACSVM_ThreadFromVoid -// -ACSVM_Thread *ACSVM_ThreadFromVoid(void *thread) -{ - return static_cast(static_cast(thread)); -} - -// -// ACSVM_Thread_Exec -// -void ACSVM_Thread_Exec(ACSVM_Thread *thread) -{ - try - { - thread->exec(); - } - catch(std::bad_alloc const &e) - { - auto env = static_cast(thread->env); - if(env->funcs.bad_alloc) - env->funcs.bad_alloc(env, e.what()); - } -} - -// -// ACSVM_Thread_GetCodePtr -// -ACSVM_Word const *ACSVM_Thread_GetCodePtr(ACSVM_Thread const *thread) -{ - return thread->codePtr; -} - -// -// ACSVM_Thread_GetDelay -// -ACSVM_Word ACSVM_Thread_GetDelay(ACSVM_Thread const *thread) -{ - return thread->delay; -} - -// -// ACSVM_Thread_GetEnv -// -ACSVM_Environment *ACSVM_Thread_GetEnv(ACSVM_Thread const *thread) -{ - return static_cast(thread->env); -} - -// -// ACSVM_Thread_GetInfo -// -void *ACSVM_Thread_GetInfo(ACSVM_Thread const *thread) -{ - return thread->info.data; -} - -// -// ACSVM_Thread_GetLocalArr -// -ACSVM_Array *ACSVM_Thread_GetLocalArr(ACSVM_Thread *thread, ACSVM_Word idx) -{ - if(idx < thread->localArr.size()) - return reinterpret_cast(&thread->localArr[idx]); - else - return nullptr; -} - -// -// ACSVM_Thread_GetLocalReg -// -ACSVM_Word *ACSVM_Thread_GetLocalReg(ACSVM_Thread *thread, ACSVM_Word idx) -{ - if(idx < thread->localReg.size()) - return &thread->localReg[idx]; - else - return nullptr; -} - -// -// ACSVM_Thread_GetModule -// -ACSVM_Module *ACSVM_Thread_GetModule(ACSVM_Thread const *thread) -{ - return reinterpret_cast(thread->module); -} - -// -// ACSVM_Thread_GetPrintBuf -// -ACSVM_PrintBuf *ACSVM_Thread_GetPrintBuf(ACSVM_Thread *thread) -{ - return reinterpret_cast(&thread->printBuf); -} - -// -// ACSVM_Thread_GetResult -// -ACSVM_Word ACSVM_Thread_GetResult(ACSVM_Thread const *thread) -{ - return thread->result; -} - -// -// ACSVM_Thread_GetScopeGbl -// -ACSVM_GlobalScope *ACSVM_Thread_GetScopeGbl(ACSVM_Thread const *thread) -{ - return reinterpret_cast(thread->scopeGbl); -} - -// -// ACSVM_Thread_GetScopeHub -// -ACSVM_HubScope *ACSVM_Thread_GetScopeHub(ACSVM_Thread const *thread) -{ - return reinterpret_cast(thread->scopeHub); -} - -// -// ACSVM_Thread_GetScopeMap -// -ACSVM_MapScope *ACSVM_Thread_GetScopeMap(ACSVM_Thread const *thread) -{ - return reinterpret_cast(thread->scopeMap); -} - -// -// ACSVM_Thread_GetScopeMod -// -ACSVM_ModuleScope *ACSVM_Thread_GetScopeMod(ACSVM_Thread const *thread) -{ - return reinterpret_cast(thread->scopeMod); -} - -// -// ACSVM_Thread_GetScript -// -ACSVM_Script *ACSVM_Thread_GetScript(ACSVM_Thread const *thread) -{ - return reinterpret_cast(thread->script); -} - -// -// ACSVM_Thread_GetState -// -ACSVM_ThreadState ACSVM_Thread_GetState(ACSVM_Thread const *thread) -{ - return - { - static_cast(thread->state.state), - thread->state.data, thread->state.type - }; -} - -// -// ACSVM_Thread_DatakStk_Push -// -void ACSVM_Thread_DataStk_Push(ACSVM_Thread *thread, ACSVM_Word data) -{ - thread->dataStk.push(data); -} - -// -// ACSVM_Thread_SetCodePtr -// -void ACSVM_Thread_SetCodePtr(ACSVM_Thread *thread, ACSVM_Word const *codePtr) -{ - thread->codePtr = codePtr; -} - -// -// ACSVM_Thread_SetDelay -// -void ACSVM_Thread_SetDelay(ACSVM_Thread *thread, ACSVM_Word delay) -{ - thread->delay = delay; -} - -// -// ACSVM_Thread_SetInfo -// -void ACSVM_Thread_SetInfo(ACSVM_Thread *thread, void *info) -{ - thread->info.data = info; -} - -// -// ACSVM_Thread_SetResult -// -void ACSVM_Thread_SetResult(ACSVM_Thread *thread, ACSVM_Word result) -{ - thread->result = result; -} - -// -// ACSVM_Thread_SetState -// -void ACSVM_Thread_SetState(ACSVM_Thread *thread, ACSVM_ThreadState state) -{ - thread->state = - {static_cast(state.state), state.data, state.type}; -} - -} - -// EOF - diff --git a/libs/ACSVM/include/CAPI/Thread.h b/libs/ACSVM/include/CAPI/Thread.h deleted file mode 100644 index 192aacc80..000000000 --- a/libs/ACSVM/include/CAPI/Thread.h +++ /dev/null @@ -1,171 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (C) 2015-2017 David Hill -// -// See COPYING for license information. -// -//----------------------------------------------------------------------------- -// -// Threads. -// -//----------------------------------------------------------------------------- - -#ifndef ACSVM__CAPI__Thread_H__ -#define ACSVM__CAPI__Thread_H__ - -#include "Types.h" - -#ifdef __cplusplus -#include "../ACSVM/Thread.hpp" -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - -//----------------------------------------------------------------------------| -// Types | -// - -// -// ACSVM_ThreadStateEnum -// -typedef enum ACSVM_ThreadStateEnum -{ - ACSVM_ThreadState_Inactive, // Inactive thread. - ACSVM_ThreadState_Running, // Running. - ACSVM_ThreadState_Stopped, // Will go inactive on next exec. - ACSVM_ThreadState_Paused, // Paused by instruction. - ACSVM_ThreadState_WaitScrI, // Waiting on a numbered script. - ACSVM_ThreadState_WaitScrS, // Waiting on a named script. - ACSVM_ThreadState_WaitTag, // Waiting on tagged object. -} ACSVM_ThreadStateEnum; - -// -// ACSVM_ThreadFuncs -// -// ACSVM_Thread functions. If non-null, these get called after the base class. -// -typedef struct ACSVM_ThreadFuncs -{ - // public - - void (*ctor)(ACSVM_Thread *env); - void (*dtor)(ACSVM_Thread *env); - - void (*loadState)(ACSVM_Thread *thread, ACSVM_Serial *in); - - void (*lockStrings)(ACSVM_Thread const *thread); - - void (*refStrings)(ACSVM_Thread const *thread); - - void (*saveState)(ACSVM_Thread const *thread, ACSVM_Serial *out); - - void (*start)(ACSVM_Thread *thread, void *data); - - void (*stop)(ACSVM_Thread *thread); - - void (*unlockStrings)(ACSVM_Thread const *thread); -} ACSVM_ThreadFuncs; - -// -// ACSVM_ThreadState -// -// ACSVM::ThreadState mirror. -// -struct ACSVM_ThreadState -{ - ACSVM_ThreadStateEnum state; - ACSVM_Word data; - ACSVM_Word type; -}; - -#ifdef __cplusplus -// -// ACSVM_ThreadInfo -// -struct ACSVM_ThreadInfo : ACSVM::ThreadInfo -{ -public: - explicit ACSVM_ThreadInfo(void *data); - virtual ~ACSVM_ThreadInfo(); - - void *data; -}; - -// -// ACSVM_Thread -// -struct ACSVM_Thread : ACSVM::Thread -{ -public: - ACSVM_Thread(ACSVM_Environment *env, ACSVM_ThreadFuncs const &funcs, void *data); - virtual ~ACSVM_Thread(); - - virtual ACSVM::ThreadInfo const *getInfo() const; - - virtual void loadState(ACSVM::Serial &in); - - virtual void lockStrings() const; - - virtual void refStrings() const; - - virtual void saveState(ACSVM::Serial &out) const; - - virtual void start(ACSVM::Script *script, ACSVM::MapScope *map, - ACSVM::ThreadInfo const *info, ACSVM::Word const *argV, ACSVM::Word argC); - - virtual void stop(); - - virtual void unlockStrings() const; - - ACSVM_ThreadFuncs funcs; - ACSVM_ThreadInfo info; -}; -#endif - - -//----------------------------------------------------------------------------| -// Extern Functions | -// - -ACSVM_Thread *ACSVM_AllocThread(ACSVM_Environment *env, - ACSVM_ThreadFuncs const *funcs, void *data); - -ACSVM_ThreadInfo *ACSVM_AllocThreadInfo(void *data); - -ACSVM_Thread *ACSVM_ThreadFromVoid(void *thread); - -void ACSVM_Thread_Exec(ACSVM_Thread *thread); - -ACSVM_Word const *ACSVM_Thread_GetCodePtr (ACSVM_Thread const *thread); -ACSVM_Word ACSVM_Thread_GetDelay (ACSVM_Thread const *thread); -ACSVM_Environment *ACSVM_Thread_GetEnv (ACSVM_Thread const *thread); -void *ACSVM_Thread_GetInfo (ACSVM_Thread const *thread); -ACSVM_Array *ACSVM_Thread_GetLocalArr(ACSVM_Thread *thread, ACSVM_Word idx); -ACSVM_Word *ACSVM_Thread_GetLocalReg(ACSVM_Thread *thread, ACSVM_Word idx); -ACSVM_Module *ACSVM_Thread_GetModule (ACSVM_Thread const *thread); -ACSVM_PrintBuf *ACSVM_Thread_GetPrintBuf(ACSVM_Thread *thread); -ACSVM_Word ACSVM_Thread_GetResult (ACSVM_Thread const *thread); -ACSVM_GlobalScope *ACSVM_Thread_GetScopeGbl(ACSVM_Thread const *thread); -ACSVM_HubScope *ACSVM_Thread_GetScopeHub(ACSVM_Thread const *thread); -ACSVM_MapScope *ACSVM_Thread_GetScopeMap(ACSVM_Thread const *thread); -ACSVM_ModuleScope *ACSVM_Thread_GetScopeMod(ACSVM_Thread const *thread); -ACSVM_Script *ACSVM_Thread_GetScript (ACSVM_Thread const *thread); -ACSVM_ThreadState ACSVM_Thread_GetState (ACSVM_Thread const *thread); - -void ACSVM_Thread_DataStk_Push(ACSVM_Thread *thread, ACSVM_Word data); - -void ACSVM_Thread_SetCodePtr(ACSVM_Thread *thread, ACSVM_Word const *codePtr); -void ACSVM_Thread_SetDelay (ACSVM_Thread *thread, ACSVM_Word delay); -void ACSVM_Thread_SetInfo (ACSVM_Thread *thread, void *info); -void ACSVM_Thread_SetResult (ACSVM_Thread *thread, ACSVM_Word result); -void ACSVM_Thread_SetState (ACSVM_Thread *thread, ACSVM_ThreadState state); - -#ifdef __cplusplus -} -#endif - -#endif//ACSVM__CAPI__Thread_H__ - diff --git a/libs/ACSVM/include/CAPI/Types.h b/libs/ACSVM/include/CAPI/Types.h deleted file mode 100644 index 86c5e9279..000000000 --- a/libs/ACSVM/include/CAPI/Types.h +++ /dev/null @@ -1,68 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright (C) 2015 David Hill -// -// See COPYING for license information. -// -//----------------------------------------------------------------------------- -// -// Common typedefs and struct declarations. -// -//----------------------------------------------------------------------------- - -#ifndef ACSVM__CAPI__Types_H__ -#define ACSVM__CAPI__Types_H__ - -#ifdef __cplusplus -#include "../ACSVM/Types.hpp" -#endif - -#include -#include -#include -#include - - -#ifdef __cplusplus -extern "C" { -#endif - -//----------------------------------------------------------------------------| -// Types | -// - -typedef unsigned char ACSVM_Byte; -typedef uint64_t ACSVM_DWord; -typedef int64_t ACSVM_SDWord; -typedef int32_t ACSVM_SWord; -typedef uint32_t ACSVM_Word; - -typedef struct ACSVM_Array ACSVM_Array; -typedef struct ACSVM_Environment ACSVM_Environment; -typedef struct ACSVM_GlobalScope ACSVM_GlobalScope; -typedef struct ACSVM_HubScope ACSVM_HubScope; -typedef struct ACSVM_IStream ACSVM_IStream; -typedef struct ACSVM_MapScope ACSVM_MapScope; -typedef struct ACSVM_Module ACSVM_Module; -typedef struct ACSVM_ModuleName ACSVM_ModuleName; -typedef struct ACSVM_ModuleScope ACSVM_ModuleScope; -typedef struct ACSVM_OStream ACSVM_OStream; -typedef struct ACSVM_PrintBuf ACSVM_PrintBuf; -typedef struct ACSVM_ScopeID ACSVM_ScopeID; -typedef struct ACSVM_Script ACSVM_Script; -typedef struct ACSVM_ScriptName ACSVM_ScriptName; -typedef struct ACSVM_Serial ACSVM_Serial; -typedef struct ACSVM_String ACSVM_String; -typedef struct ACSVM_StringTable ACSVM_StringTable; -typedef struct ACSVM_Thread ACSVM_Thread; -typedef struct ACSVM_ThreadInfo ACSVM_ThreadInfo; -typedef struct ACSVM_ThreadState ACSVM_ThreadState; - -typedef bool (*ACSVM_CallFunc)(ACSVM_Thread *, ACSVM_Word const *, ACSVM_Word); - -#ifdef __cplusplus -} -#endif - -#endif//ACSVM__CAPI__Types_H__ - diff --git a/libs/ACSVM/include/Exec/CMakeLists.txt b/libs/ACSVM/include/Exec/CMakeLists.txt deleted file mode 100644 index f0c929f61..000000000 --- a/libs/ACSVM/include/Exec/CMakeLists.txt +++ /dev/null @@ -1,48 +0,0 @@ -##----------------------------------------------------------------------------- -## -## Copyright (C) 2015 David Hill -## -## See COPYING for license information. -## -##----------------------------------------------------------------------------- -## -## CMake file for acsvm-exec. -## -##----------------------------------------------------------------------------- - - -##----------------------------------------------------------------------------| -## Environment Configuration | -## - -include_directories(.) - - -##----------------------------------------------------------------------------| -## Targets | -## - -## -## acsvm-exec -## -add_executable(acsvm-exec - main_exec.cpp -) - -target_link_libraries(acsvm-exec acsvm-util) - -## -## acsvm-execc -## -## Used to test the C API. -## -if(EXISTS "${CMAKE_SOURCE_DIR}/CAPI") - add_executable(acsvm-execc - main_execc.c - ) - - target_link_libraries(acsvm-execc acsvm-capi) -endif() - -## EOF - diff --git a/libs/ACSVM/include/Exec/main_exec.cpp b/libs/ACSVM/include/Exec/main_exec.cpp deleted file mode 100644 index 3e84140e7..000000000 --- a/libs/ACSVM/include/Exec/main_exec.cpp +++ /dev/null @@ -1,264 +0,0 @@ -//---------------------------------------------------------------------------- -// -// Copyright (C) 2015-2017 David Hill -// -// See COPYING for license information. -// -//---------------------------------------------------------------------------- -// -// Program entry point. -// -//---------------------------------------------------------------------------- - -#include "ACSVM/Code.hpp" -#include "ACSVM/CodeData.hpp" -#include "ACSVM/Environment.hpp" -#include "ACSVM/Error.hpp" -#include "ACSVM/Module.hpp" -#include "ACSVM/Scope.hpp" -#include "ACSVM/Script.hpp" -#include "ACSVM/Serial.hpp" -#include "ACSVM/Thread.hpp" - -#include "Util/Floats.hpp" - -#include -#include -#include -#include -#include -#include - - -//----------------------------------------------------------------------------| -// Types | -// - -// -// Environment -// -class Environment : public ACSVM::Environment -{ -public: - Environment(); - - virtual void exec() {++timer; ACSVM::Environment::exec();} - - ACSVM::Word timer; - -protected: - virtual void loadModule(ACSVM::Module *module); -}; - - -//----------------------------------------------------------------------------| -// Static Objects | -// - -static bool NeedExit = false; -static bool NeedTestSaveEnv = false; - - -//----------------------------------------------------------------------------| -// Static Functions | -// - -// -// CF_CollectStrings -// -static bool CF_CollectStrings(ACSVM::Thread *thread, ACSVM::Word const *, ACSVM::Word) -{ - std::size_t countOld = thread->env->stringTable.size(); - thread->env->collectStrings(); - std::size_t countNew = thread->env->stringTable.size(); - thread->dataStk.push(countOld - countNew); - return false; -} - -// -// CF_DumpLocals -// -static bool CF_DumpLocals(ACSVM::Thread *thread, ACSVM::Word const *, ACSVM::Word) -{ - // LocReg store info. - std::cout << "LocReg=" - << thread->localReg.begin() << '+' << thread->localReg.size() << " / " - << thread->localReg.beginFull() << '+' << thread->localReg.sizeFull() << "\n"; - - // LocReg values for current function. - for(std::size_t i = 0, e = thread->localReg.size(); i != e; ++i) - std::cout << " [" << i << "]=" << thread->localReg[i] << '\n'; - - return false; -} - -// -// CF_EndPrint -// -static bool CF_EndPrint(ACSVM::Thread *thread, ACSVM::Word const *, ACSVM::Word) -{ - std::cout << thread->printBuf.data() << '\n'; - thread->printBuf.drop(); - return false; -} - -// -// CF_Exit -// -static bool CF_Exit(ACSVM::Thread *thread, ACSVM::Word const *, ACSVM::Word) -{ - NeedExit = true; - thread->state = ACSVM::ThreadState::Stopped; - return true; -} - -// -// CF_TestSave -// -static bool CF_TestSave(ACSVM::Thread *, ACSVM::Word const *, ACSVM::Word) -{ - NeedTestSaveEnv = true; - return false; -} - -// -// CF_Timer -// -static bool CF_Timer(ACSVM::Thread *thread, ACSVM::Word const *, ACSVM::Word) -{ - thread->dataStk.push(static_cast(thread->env)->timer); - return false; -} - -// -// LoadModules -// -static void LoadModules(Environment &env, char const *const *argv, std::size_t argc) -{ - // Load modules. - std::vector modules; - for(std::size_t i = 1; i < argc; ++i) - modules.push_back(env.getModule(env.getModuleName(argv[i]))); - - // Create and activate scopes. - ACSVM::GlobalScope *global = env.getGlobalScope(0); global->active = true; - ACSVM::HubScope *hub = global->getHubScope(0); hub ->active = true; - ACSVM::MapScope *map = hub->getMapScope(0); map ->active = true; - - // Register modules with map scope. - map->addModules(modules.data(), modules.size()); - - // Start Open scripts. - map->scriptStartType(1, {}); -} - - -//----------------------------------------------------------------------------| -// Extern Functions | -// - -// -// Environment constructor -// -Environment::Environment() : - timer{0} -{ - ACSVM::Word funcCollectStrings = addCallFunc(CF_CollectStrings); - ACSVM::Word funcDumpLocals = addCallFunc(CF_DumpLocals); - ACSVM::Word funcEndPrint = addCallFunc(CF_EndPrint); - ACSVM::Word funcExit = addCallFunc(CF_Exit); - ACSVM::Word funcTestSave = addCallFunc(CF_TestSave); - ACSVM::Word funcTimer = addCallFunc(CF_Timer); - - addCodeDataACS0( 86, {"", 0, funcEndPrint}); - addCodeDataACS0( 93, {"", 0, funcTimer}); - addCodeDataACS0(270, {"", 0, funcEndPrint}); - - addFuncDataACS0(0x10000, funcTestSave); - addFuncDataACS0(0x10001, funcCollectStrings); - addFuncDataACS0(0x10002, funcDumpLocals); - addFuncDataACS0(0x10003, funcExit); - - addFuncDataACS0(0x10100, addCallFunc(ACSVM::CF_AddF_W1)); - addFuncDataACS0(0x10101, addCallFunc(ACSVM::CF_DivF_W1)); - addFuncDataACS0(0x10102, addCallFunc(ACSVM::CF_MulF_W1)); - addFuncDataACS0(0x10103, addCallFunc(ACSVM::CF_SubF_W1)); - addFuncDataACS0(0x10104, addCallFunc(ACSVM::CF_AddF_W2)); - addFuncDataACS0(0x10105, addCallFunc(ACSVM::CF_DivF_W2)); - addFuncDataACS0(0x10106, addCallFunc(ACSVM::CF_MulF_W2)); - addFuncDataACS0(0x10107, addCallFunc(ACSVM::CF_SubF_W2)); - addFuncDataACS0(0x10108, addCallFunc(ACSVM::CF_PrintFloat)); - addFuncDataACS0(0x10109, addCallFunc(ACSVM::CF_PrintDouble)); -} - -// -// Environment::loadModule -// -void Environment::loadModule(ACSVM::Module *module) -{ - std::ifstream in{module->name.s->str, std::ios_base::in | std::ios_base::binary}; - - if(!in) throw ACSVM::ReadError("file open failure"); - - std::vector data; - - for(int c; c = in.get(), in;) - data.push_back(c); - - module->readBytecode(data.data(), data.size()); -} - -// -// main -// -int main(int argc, char *argv[]) -{ - Environment env; - - // Load modules. - try - { - LoadModules(env, argv, argc); - } - catch(ACSVM::ReadError &e) - { - std::cerr << "Error loading modules: " << e.what() << std::endl; - return EXIT_FAILURE; - } - - // Execute until all threads terminate. - while(!NeedExit && env.hasActiveThread()) - { - std::chrono::duration rate{1.0 / 35}; - auto time = std::chrono::steady_clock::now() + rate; - - env.exec(); - - if(NeedTestSaveEnv) - { - std::stringstream buf; - - { - ACSVM::Serial out{static_cast(buf)}; - out.signs = true; - out.saveHead(); - env.saveState(out); - out.saveTail(); - } - - { - ACSVM::Serial in{static_cast(buf)}; - in.loadHead(); - env.loadState(in); - in.loadTail(); - } - - NeedTestSaveEnv = false; - } - - std::this_thread::sleep_until(time); - } -} - -// EOF - diff --git a/libs/ACSVM/include/Exec/main_execc.c b/libs/ACSVM/include/Exec/main_execc.c deleted file mode 100644 index ccd8c9533..000000000 --- a/libs/ACSVM/include/Exec/main_execc.c +++ /dev/null @@ -1,231 +0,0 @@ -//---------------------------------------------------------------------------- -// -// Copyright (C) 2015-2017 David Hill -// -// See COPYING for license information. -// -//---------------------------------------------------------------------------- -// -// Program entry point. -// -//---------------------------------------------------------------------------- - -#include "CAPI/BinaryIO.h" -#include "CAPI/Environment.h" -#include "CAPI/Module.h" -#include "CAPI/PrintBuf.h" -#include "CAPI/Scope.h" -#include "CAPI/ACS_String.h" -#include "CAPI/Thread.h" - -#include -#include -#include -#include - - -//----------------------------------------------------------------------------| -// Static Objects | -// - -static ACSVM_Word ExecTime = 0; - - -//----------------------------------------------------------------------------| -// Static Functions | -// - -// -// CF_EndPrint -// -static bool CF_EndPrint(ACSVM_Thread *thread, ACSVM_Word const *argV, ACSVM_Word argC) -{ - (void)argV; (void)argC; - - ACSVM_PrintBuf *buf = ACSVM_Thread_GetPrintBuf(thread); - - printf("%s\n", ACSVM_PrintBuf_GetData(buf)); - ACSVM_PrintBuf_Drop(buf); - - return false; -} - -// -// CF_Timer -// -static bool CF_Timer(ACSVM_Thread *thread, ACSVM_Word const *argV, ACSVM_Word argC) -{ - (void)argV; (void)argC; - - ACSVM_Thread_DataStk_Push(thread, ExecTime); - return false; -} - -// -// Environment_BadAlloc -// -static void Environment_BadAlloc(ACSVM_Environment *env, char const *what) -{ - (void)env; - - fprintf(stderr, "bad_alloc: %s\n", what); - exit(EXIT_FAILURE); -} - -// -// Environment_Construct -// -static void Environment_Construct(ACSVM_Environment *env) -{ - ACSVM_Word funcEndPrint = ACSVM_Environment_AddCallFunc(env, CF_EndPrint); - ACSVM_Word funcTimer = ACSVM_Environment_AddCallFunc(env, CF_Timer); - - ACSVM_Environment_AddCodeDataACS0(env, 86, "", ACSVM_Code_CallFunc, 0, funcEndPrint); - ACSVM_Environment_AddCodeDataACS0(env, 93, "", ACSVM_Code_CallFunc, 0, funcTimer); - ACSVM_Environment_AddCodeDataACS0(env, 270, "", ACSVM_Code_CallFunc, 0, funcEndPrint); -} - -// -// Environment_LoadModule -// -static bool Environment_LoadModule(ACSVM_Environment *env, ACSVM_Module *module) -{ - (void)env; - - ACSVM_ModuleName name = ACSVM_Module_GetName(module); - - FILE *stream = fopen(ACSVM_String_GetStr(name.s), "rb"); - if(!stream) - { - fprintf(stderr, "failed to fopen: %s\n", strerror(errno)); - exit(EXIT_FAILURE); - } - - ACSVM_Byte *data = NULL; - size_t size = 0; - size_t alloc = 0; - - for(int c; (c = fgetc(stream)) != EOF;) - { - if(size == alloc) - { - alloc = alloc + alloc / 2 + 256; - data = realloc(data, alloc); - if(!data) - { - fprintf(stderr, "failed to allocate %zu\n", alloc); - exit(EXIT_FAILURE); - } - } - - data[size++] = c; - } - - fclose(stream); - - bool res = ACSVM_Module_ReadBytecode(module, data, size); - - free(data); - - return res; -} - -// -// Environment_ReadError -// -static void Environment_ReadError(ACSVM_Environment *env, char const *what) -{ - (void)env; - - fprintf(stderr, "ReadError: %s\n", what); - exit(EXIT_FAILURE); -} - -// -// LoadModules -// -static void LoadModules(ACSVM_Environment *env, char **argv, int argc) -{ - ACSVM_StringTable *strTab = ACSVM_Environment_GetStringTable(env); - - // Create and activate scopes. - ACSVM_GlobalScope *global = ACSVM_Environment_GetGlobalScope(env, 0); - ACSVM_GlobalScope_SetActive(global, true); - ACSVM_HubScope *hub = ACSVM_GlobalScope_GetHubScope(global, 0); - ACSVM_HubScope_SetActive(hub, true); - ACSVM_MapScope *map = ACSVM_HubScope_GetMapScope(hub, 0); - ACSVM_MapScope_SetActive(map, true); - - // Load modules. - - size_t moduleC = argc - 1; - ACSVM_Module **moduleV = malloc(sizeof(ACSVM_Module *) * moduleC); - if(!moduleV) - { - fprintf(stderr, "failed to alloc moduleV[%zu]\n", moduleC); - exit(EXIT_FAILURE); - } - - for(int argi = 1; argi < argc; ++argi) - { - char const *arg = argv[argi]; - size_t len = strlen(arg); - size_t hash = ACSVM_StrHash(arg, len); - ACSVM_ModuleName name = - {ACSVM_StringTable_GetStringByData(strTab, arg, len, hash), NULL, 0}; - - moduleV[argi - 1] = ACSVM_Environment_GetModule(env, name); - } - - // Register modules with map scope. - ACSVM_MapScope_AddModules(map, moduleV, moduleC); - - // Start Open scripts. - ACSVM_MapScope_ScriptStartType(map, 1, NULL, 0, NULL, NULL); -} - - -//----------------------------------------------------------------------------| -// Extern Functions | -// - -// -// main -// -int main(int argc, char *argv[]) -{ - ACSVM_Environment *env = ACSVM_AllocEnvironment( - &(ACSVM_EnvironmentFuncs) - { - .bad_alloc = Environment_BadAlloc, - .readError = Environment_ReadError, - - .ctor = Environment_Construct, - - .loadModule = Environment_LoadModule, - }, - NULL); - - if(!env) - { - fprintf(stderr, "failed to allocate environment\n"); - return EXIT_FAILURE; - } - - LoadModules(env, argv, argc); - - while(ACSVM_Environment_HasActiveThread(env)) - { - ++ExecTime; - ACSVM_Environment_Exec(env); - - // TODO: Sleep. - } - - ACSVM_FreeEnvironment(env); - - return EXIT_SUCCESS; -} - -// EOF - diff --git a/libs/ACSVM/include/doc/ACSVM.txt b/libs/ACSVM/include/doc/ACSVM.txt deleted file mode 100644 index 17837859b..000000000 --- a/libs/ACSVM/include/doc/ACSVM.txt +++ /dev/null @@ -1,1212 +0,0 @@ -############################################################################### -ACSVM Library Specification -############################################################################### - -=============================================================================== -Types -=============================================================================== - -Synopsis: - using Byte = unsigned char; - - using DWord = std::uint64_t; - using SDWord = std::int64_t; - using SWord = std::int32_t; - using Word = std::uint32_t; - - using CallFunc = bool (*)(Thread *thread, Word const *argv, Word argc); - -=============================================================================== -Deferred Actions -=============================================================================== - -=========================================================== -ACSVM::ScopeID -=========================================================== - -Synopsis: - #include - class ScopeID - { - public: - ScopeID() = default; - ScopeID(Word global, Word hub, Word map); - - bool operator == (ScopeID const &id) const; - bool operator != (ScopeID const &id) const; - - Word global; - Word hub; - Word map; - }; - -=============================================================================== -Arrays -=============================================================================== - -=========================================================== -ACSVM::Array -=========================================================== - -Synopsis: - #include - class Array - { - public: - Array(); - Array(Array const &) = delete; - Array(Array &&array); - ~Array(); - - Word &operator [] (Word idx); - - void clear(); - - Word find(Word idx) const; - - void lockStrings(Environment *env) const; - - void unlockStrings(Environment *env) const; - }; - -=============================================================================== -Codes -=============================================================================== - -=========================================================== -ACSVM::Code -=========================================================== - -Synopsis: - #include - enum class Code - { - /* ... */ - None - }; - -=========================================================== -ACSVM::Func -=========================================================== - -Synopsis: - #include - enum class Func - { - /* ... */ - None - }; - -=========================================================== -ACSVM::KillType -=========================================================== - -Synopsis: - #include - enum class KillType - { - None, - OutOfBounds, - UnknownCode, - UnknownFunc, - BranchLimit, - }; - -=============================================================================== -Code Data -=============================================================================== - -=========================================================== -ACSVM::CodeDataACS0 -=========================================================== - -Synopsis: - #include - class CodeDataACS0 - { - public: - CodeDataACS0(char const *args, Code transCode, Word stackArgC, - Word transFunc = 0); - CodeDataACS0(char const *args, Word stackArgC, Word transFunc); - - char const *args; - std::size_t argc; - - Word stackArgC; - - Code transCode; - - Word transFunc; - }; - -=========================================================== -ACSVM::FuncDataACS0 -=========================================================== - -Synopsis: - #include - class FuncDataACS0 - { - public: - using TransCode = std::pair; - - - FuncDataACS0(FuncDataACS0 const &data); - FuncDataACS0(FuncDataACS0 &&data); - FuncDataACS0(Word transFunc); - FuncDataACS0(Word transFunc, std::initializer_list transCodes); - ~FuncDataACS0(); - - FuncDataACS0 &operator = (FuncDataACS0 const &) = delete; - FuncDataACS0 &operator = (FuncDataACS0 &&data); - - Word transFunc; - }; - -=============================================================================== -Environment -=============================================================================== - -=========================================================== -ACSVM::Environment -=========================================================== - -Synopsis: - #include - class Environment - { - public: - Environment(); - virtual ~Environment(); - - Word addCallFunc(CallFunc func); - - void addCodeDataACS0(Word code, CodeDataACS0 &&data); - - void addFuncDataACS0(Word func, FuncDataACS0 &&data); - - virtual bool checkLock(Thread *thread, Word lock, bool door); - - virtual bool checkTag(Word type, Word tag); - - void collectStrings(); - - virtual void exec(); - - void freeGlobalScope(GlobalScope *scope); - - void freeModule(Module *module); - - GlobalScope *getGlobalScope(Word id); - - Module *getModule(ModuleName const &name); - - ModuleName getModuleName(char const *str); - virtual ModuleName getModuleName(char const *str, std::size_t len); - - String *getString(Word idx); - String *getString(char const *first, char const *last); - String *getString(char const *str); - String *getString(char const *str, std::size_t len); - String *getString(StringData const *data); - - bool hasActiveThread() const; - - virtual void loadState(Serial &in); - - virtual void printArray(PrintBuf &buf, Array const &array, Word index, - Word limit); - - virtual void printKill(Thread *thread, Word type, Word data); - - virtual ModuleName readModuleName(Serial &in) const; - - String *readString(Serial &in) const; - - virtual void refStrings(); - - virtual void resetStrings(); - - virtual void saveState(Serial &out) const; - - virtual void writeModuleName(Serial &out, ModuleName const &name) const; - - void writeString(Serial &out, String const *in) const; - - StringTable stringTable; - - Word scriptLocRegC; - - - static void PrintArrayChar(PrintBuf &buf, Array const &array, Word index, - Word limit); - - static void PrintArrayUTF8(PrintBuf &buf, Array const &array, Word index, - Word limit); - - static constexpr Word ScriptLocRegCDefault; - - protected: - virtual Thread *allocThread(); - - virtual Word callSpecImpl(Thread *thread, Word spec, Word const *argV, - Word argC); - - virtual void loadModule(Module *module) = 0; - }; - -Description: - Represents an execution environment. - ------------------------------------------------------------ -ACSVM::Environment::Environment ------------------------------------------------------------ - -Synopsis: - Environment(); - -Description: - Constructs the Environment object. - ------------------------------------------------------------ -ACSVM::Environment::~Environment ------------------------------------------------------------ - -Synopsis: - ~Environment(); - -Description: - Destructs the Environment object. - ------------------------------------------------------------ -ACSVM::Environment::addCallFunc ------------------------------------------------------------ - -Synopsis: - Word addCallFunc(CallFunc func); - -Description: - Adds a function callback for scripts and returns its index. - -Returns: - Added function's index. - ------------------------------------------------------------ -ACSVM::Environment::addCodeDataACS0 ------------------------------------------------------------ - -Synopsis: - void addCodeDataACS0(Word code, CodeDataACS0 &&data); - -Description: - Adds a translation from instruction code for ACS0 and derived bytecode. - ------------------------------------------------------------ -ACSVM::Environment::addFuncDataACS0 ------------------------------------------------------------ - -Synopsis: - void addFuncDataACS0(Word func, FuncDataACS0 &&data); - -Description: - Adds a translation from callfunc func for ACS0 and derived bytecode. - ------------------------------------------------------------ -ACSVM::Environment::checkLock ------------------------------------------------------------ - -Synopsis: - virtual bool checkLock(Thread *thread, Word lock, bool door); - -Description: - Called to check if a given lock number can be used from a given thread. The - lock number has no internal semantics, and is passed from the user source - unaltered. - - The base implementation always return false. - -Returns: - True if the lock is open for that thread, false otherwise. - ------------------------------------------------------------ -ACSVM::Environment::checkTag ------------------------------------------------------------ - -Synopsis: - virtual bool checkTag(Word type, Word tag); - -Description: - Called to check if a given tag is inactive. The tag type and number both have - no internal semantics, and are passed from the user source unaltered. - - The base implementation always returns false. - -Returns: - True if the tag is inactive, false otherwise. - ------------------------------------------------------------ -ACSVM::Environment::collectStrings ------------------------------------------------------------ - -Synopsis: - void collectStrings(); - -Description: - Performs a full scan of the environment and frees strings that are no longer - in use. - ------------------------------------------------------------ -ACSVM::Environment::exec ------------------------------------------------------------ - -Synopsis: - virtual void exec(); - -Description: - Performs a single execution cycle. Deferred script actions will be applied, - and active threads will execute until they terminate or enter a wait state. - ------------------------------------------------------------ -ACSVM::Environment::freeGlobalScope ------------------------------------------------------------ - -Synopsis: - void freeGlobalScope(GlobalScope *scope); - -Description: - Destructs and deallocates a contained GlobalScope object. - ------------------------------------------------------------ -ACSVM::Environment::freeModule ------------------------------------------------------------ - -Synopsis: - void freeModule(Module *module); - -Description: - Destructs and deallocates a contained Module object. - - If any other modules reference the freed module, they must also be freed. - ------------------------------------------------------------ -ACSVM::Environment::getGlobalScope ------------------------------------------------------------ - -Synopsis: - GlobalScope *getGlobalScope(Word id); - -Description: - Retrieves a GlobalScope object by its identifier number. If it does not - exist, it will be created. - -Returns: - GlobalScope object with given id. - ------------------------------------------------------------ -ACSVM::Environment::getModule ------------------------------------------------------------ - -Synopsis: - Module *getModule(ModuleName const &name); - -Description: - Retrieves a Module object by name. If it does not exist or is not loaded, it - will be created and loaded as needed. - -Returns: - Module object with given name. - ------------------------------------------------------------ -ACSVM::Environment::getModuleName ------------------------------------------------------------ - -Synopsis: - ModuleName getModuleName(char const *str); - virtual ModuleName getModuleName(char const *str, std::size_t len); - -Description: - Generates a ModuleName from an input string. The first form calls the second, - using the null-terminated length of the input string. - - The base implementation converts the input string into a String object for - ModuleName::s, leaving the other ModuleName fields set to 0. - -Returns: - ModuleName object formed from input string. - ------------------------------------------------------------ -ACSVM::Environment::getScriptType ------------------------------------------------------------ - -Synopsis: - virtual std::pair getScriptTypeACS0(Word name); - virtual Word getScriptTypeACSE(Word type); - -Description: - Translates a bytecode script type into an internal type. - - First form takes the script number and must return the type and name. - - The base implementation of the first form translates by dividing by 1000. The - second form returns the type unaltered. - -Returns: - Translated script type or (type, name) pair. - ------------------------------------------------------------ -ACSVM::Environment::getString ------------------------------------------------------------ - -Synopsis: - String *getString(Word idx); - String *getString(char const *first, char const *last); - String *getString(char const *str); - String *getString(char const *str, std::size_t len); - String *getString(StringData const *data); - -Description: - First form returns a String object as if by calling (&stringTable[~idx]). - - Second, third, and fourth forms create a StringData from input to find or - create an entry in stringTable. - - Fifth form uses the supplied StringData object to find or create an entry in - stringTable. If data is null, null is returned. This is intended primarily - for resetting strings after deserialization. - -Returns: - First form returns the String object with the given index. All other forms - return a String object with the same data as the input. - - Fifth form will return null if input is null, and non-null otherwise. All - other forms never return null. - ------------------------------------------------------------ -ACSVM::Environment::hasActiveThread ------------------------------------------------------------ - -Synopsis: - bool hasActiveThread() const; - -Description: - Checks for any active threads. A thread is considered active if it has any - state other than ThreadState::Inactive. So this will include threads that are - delayed, waiting for a condition (script or tag), or set to stop during the - next execution cycle. - -Returns: - True if there are any active threads, false otherwise. - ------------------------------------------------------------ -ACSVM::Environment::loadState ------------------------------------------------------------ - -Synopsis: - virtual void loadState(Serial &in); - -Description: - Restores the environment state from a previously serialized instance. If in - does not contain a byte stream generated by a previous call to saveState, the - behavior is undefined. - ------------------------------------------------------------ -ACSVM::Environment::printArray ------------------------------------------------------------ - -Synopsis: - virtual void printArray(PrintBuf &buf, Array const &array, Word index, - Word limit); - -Description: - Called to write a null-terminated character subsequence from an Array object - to a print buffer. - - The base implementation calls PrintArrayChar. - ------------------------------------------------------------ -ACSVM::Environment::printKill ------------------------------------------------------------ - -Synopsis: - virtual void printKill(Thread *thread, Word type, Word data); - -Description: - Called when a thread encounters an error and must terminate. This includes - executing Code::Kill or calling Func::Kill. When calling by ACSVM itself, the - type parameter has a value from the KillType enumeration. - - This function is expected to return normally, and the caller will handle - thread termination. - - The base implementation prints kill information to std::cerr. - ------------------------------------------------------------ -ACSVM::Environment::readModuleName ------------------------------------------------------------ - -Synopsis: - virtual ModuleName readModuleName(Serial &in) const; - -Description: - Called to read a ModuleName from a serialized environment. - - The base implementation reads the s and i members, leaving the p member null. - -Returns: - Deserialized ModuleName. - ------------------------------------------------------------ -ACSVM::Environment::readString ------------------------------------------------------------ - -Synopsis: - String *readString(Serial &in) const; - -Description: - Reads a String by index from a serialized Environment. If the written String - pointer was null, this function returns a null pointer. - -Returns: - Deserialized String. - ------------------------------------------------------------ -ACSVM::Environment::refStrings ------------------------------------------------------------ - -Synopsis: - virtual void refStrings(); - -Description: - Called by collectStrings to mark contained strings as referenced. - - The base implementation marks strings of all contained objects, as well as - performs an exhaustive scan of VM memory for string indexes. - ------------------------------------------------------------ -ACSVM::Environment::resetStrings ------------------------------------------------------------ - -Synopsis: - virtual void resetStrings(); - -Description: - Called by loadState after reading the new StringTable to reset any String - pointers to the corresponding entry in the read table. - - The base implementation resets strings of all contained objects. - ------------------------------------------------------------ -ACSVM::Environment::saveState ------------------------------------------------------------ - -Synopsis: - virtual void saveState(Serial &out) const; - -Description: - Serializes the environment state, which can be restored with a call to - loadState. - ------------------------------------------------------------ -ACSVM::Environment::writeModuleName ------------------------------------------------------------ - -Synopsis: - virtual void writeModuleName(Serial &out, - ModuleName const &name) const; - -Description: - Called to write a ModuleName. - - The base implementation writes the s and i members. - ------------------------------------------------------------ -ACSVM::Environment::writeString ------------------------------------------------------------ - -Synopsis: - void writeString(Serial &out, String const *in) const; - -Description: - Writes a String by index. If in is null, a null pointer will be returned by - the corresponding call to readString. - -=============================================================================== -Errors -=============================================================================== - -=========================================================== -ACSVM::ReadError -=========================================================== - -Synopsis: - #include - class ReadError : public std::exception - { - public: - ReadError(char const *msg = "ACSVM::ReadError"); - - virtual char const *what() const noexcept; - }; - -=============================================================================== -Modules -=============================================================================== - -=========================================================== -ACSVM::ModuleName -=========================================================== - -Synopsis: - #include - class ModuleName - { - public: - ModuleName(String *s, void *p, std::size_t i); - - bool operator == (ModuleName const &name) const; - bool operator != (ModuleName const &name) const; - - std::size_t hash() const; - - String *s; - void *p; - std::size_t i; - }; - -=========================================================== -ACSVM::Module -=========================================================== - -Synopsis: - #include - class Module - { - public: - void readBytecode(Byte const *data, std::size_t size); - - Environment *env; - ModuleName name; - - bool isACS0; - bool loaded; - - - static constexpr std::uint32_t ChunkID(char c0, char c1, char c2, char c3); - - static constexpr std::uint32_t ChunkID(char const (&s)[5]); - }; - -=============================================================================== -Print Buffers -=============================================================================== - -=========================================================== -ACSVM::PrintBuf -=========================================================== - -Synopsis: - #include - class PrintBuf - { - public: - PrintBuf(); - ~PrintBuf(); - - void clear(); - - char const *data() const; - char const *dataFull() const; - - void drop(); - - void format(char const *fmt, ...); - void formatv(char const *fmt, std::va_list arg); - - char *getBuf(std::size_t count); - - char *getLoadBuf(std::size_t countFull, std::size_t count); - - void push(); - - void put(char c); - void put(char const *s); - void put(char const *s, std::size_t n); - - void reserve(std::size_t count); - - std::size_t size() const; - std::size_t sizeFull() const; - }; - -=============================================================================== -Scopes -=============================================================================== - -=========================================================== -ACSVM::GlobalScope -=========================================================== - -Synopsis: - #include - class GlobalScope - { - public: - static constexpr std::size_t ArrC = 256; - static constexpr std::size_t RegC = 256; - - - void freeHubScope(HubScope *scope); - - HubScope *getHubScope(Word id); - - bool hasActiveThread() const; - - void lockStrings() const; - - void reset(); - - void unlockStrings() const; - - Environment *const env; - Word const id; - - Array arrV[ArrC]; - Word regV[RegC]; - - bool active; - }; - -=========================================================== -ACSVM::HubScope -=========================================================== - -Synopsis: - #include - class HubScope - { - public: - static constexpr std::size_t ArrC = 256; - static constexpr std::size_t RegC = 256; - - - void freeMapScope(MapScope *scope); - - MapScope *getMapScope(Word id); - - bool hasActiveThread() const; - - void lockStrings() const; - - void reset(); - - void unlockStrings() const; - - Environment *const env; - GlobalScope *const global; - Word const id; - - Array arrV[ArrC]; - Word regV[RegC]; - - bool active; - }; - -=========================================================== -ACSVM::MapScope -=========================================================== - -Synopsis: - #include - class MapScope - { - public: - using ScriptStartFunc = void (*)(Thread *); - using ScriptStartFuncC = MapScope_ScriptStartFuncC; - - class ScriptStartInfo; - - - void addModules(Module *const *moduleV, std::size_t moduleC); - - Script *findScript(ScriptName name); - - ModuleScope *getModuleScope(Module *module); - - String *getString(Word idx) const; - - bool hasActiveThread() const; - - bool hasModules() const; - - bool isScriptActive(Script *script); - - void loadState(Serial &in); - - void lockStrings() const; - - void reset(); - - void saveState(Serial &out) const; - - bool scriptPause(Script *script); - bool scriptPause(ScriptName name, ScopeID scope); - bool scriptStart(Script *script, ScriptStartInfo const &info); - bool scriptStart(ScriptName name, ScopeID scope, - ScriptStartInfo const &info); - bool scriptStartForced(Script *script, ScriptStartInfo const &info); - bool scriptStartForced(ScriptName name, ScopeID scope, - ScriptStartInfo const &info); - Word scriptStartResult(Script *script, ScriptStartInfo const &info); - Word scriptStartResult(ScriptName name, ScriptStartInfo const &info); - Word scriptStartType(Word type, ScriptStartInfo const &info); - Word scriptStartTypeForced(Word type, ScriptStartInfo const &info); - bool scriptStop(Script *script); - bool scriptStop(ScriptName name, ScopeID scope); - - void unlockStrings() const; - - Environment *const env; - HubScope *const hub; - Word const id; - - bool active; - bool clampCallSpec; - }; - -=========================================================== -ACSVM::MapScope::ScriptStartInfo -=========================================================== - -Synopsis: - #include - class ScriptStartInfo - { - public: - ScriptStartInfo(); - ScriptStartInfo(Word const *argV, std::size_t argC, - ThreadInfo const *info = nullptr, ScriptStartFunc func = nullptr); - ScriptStartInfo(Word const *argV, std::size_t argC, - ThreadInfo const *info, ScriptStartFuncC func); - - Word const *argV; - ScriptStartFunc func; - ScriptStartFuncC funcc; - ThreadInfo const *info; - std::size_t argC; - }; - -=========================================================== -ACSVM::ModuleScope -=========================================================== - -Synopsis: - #include - class ModuleScope - { - public: - static constexpr std::size_t ArrC = 256; - static constexpr std::size_t RegC = 256; - - - void lockStrings() const; - - void unlockStrings() const; - - Environment *const env; - MapScope *const map; - Module *const module; - - Array *arrV[ArrC]; - Word *regV[RegC]; - }; - -=============================================================================== -Scripts -=============================================================================== - -=========================================================== -ACSVM::ScriptName -=========================================================== - -Synopsis: - #include - class ScriptName - { - public: - ScriptName(); - ScriptName(String *s); - ScriptName(String *s, Word i); - ScriptName(Word i); - - String *s; - Word i; - }; - -=========================================================== -ACSVM::Script -=========================================================== - -Synopsis: - #include - class Script - { - public: - explicit Script(Module *module); - ~Script(); - - Module *const module; - - ScriptName name; - - Word argC; - Word codeIdx; - Word flags; - Word locArrC; - Word locRegC; - Word type; - - bool flagClient : 1; - bool flagNet : 1; - }; - -=============================================================================== -Stacks -=============================================================================== - -=========================================================== -ACSVM::Stack -=========================================================== - -Synopsis: - #include - template - class Stack - { - public: - Stack(); - ~Stack(); - - T &operator [] (std::size_t idx); - - T *begin(); - T const *begin() const; - - void clear(); - - void drop(); - void drop(std::size_t n); - - bool empty() const; - - T *end(); - T const *end() const; - - void push(T const &value); - void push(T &&value); - - void reserve(std::size_t count); - - std::size_t size() const; - }; - -=============================================================================== -Locals Storage -=============================================================================== - -=========================================================== -ACSVM::Store -=========================================================== - -Synopsis: - #include - template - class Store - { - public: - Store(); - ~Store(); - - T &operator [] (std::size_t idx); - - void alloc(std::size_t count); - - void allocLoad(std::size_t countFull, std::size_t count); - - T *begin(); - T const *begin() const; - - T *beginFull(); - T const *beginFull() const; - - void clear(); - - T const *dataFull() const; - - T *end(); - T const *end() const; - - void free(std::size_t count); - - std::size_t size() const; - - std::size_t sizeFull() const; - }; - -=============================================================================== -Strings -=============================================================================== - -=========================================================== -ACSVM::StringData -=========================================================== - -Synopsis: - #include - class StringData - { - public: - StringData(char const *first, char const *last); - StringData(char const *str, std::size_t len); - StringData(char const *str, std::size_t len, std::size_t hash); - - bool operator == (StringData const &r) const; - - char const *const str; - std::size_t const len; - std::size_t const hash; - }; - -=========================================================== -ACSVM::String -=========================================================== - -Synopsis: - #include - class String : public StringData - { - public: - std::size_t lock; - - Word const idx; - Word const len0; - - bool ref; - - char get(std::size_t i) const; - }; - -=========================================================== -ACSVM::StringTable -=========================================================== - -Synopsis: - #include - class StringTable - { - public: - StringTable(); - StringTable(StringTable &&table); - ~StringTable(); - - String &operator [] (Word idx) const; - String &operator [] (StringData const &data); - - void clear(); - - void collectBegin(); - void collectEnd(); - - String &getNone(); - - std::size_t size() const; - }; - -=============================================================================== -Threads -=============================================================================== - -=========================================================== -ACSVM::ThreadState -=========================================================== - -Synopsis: - #include - class ThreadState - { - public: - enum State - { - Inactive, - Running, - Stopped, - Paused, - WaitScrI, - WaitScrS, - WaitTag, - }; - - - ThreadState(); - ThreadState(State state); - ThreadState(State state, Word data); - ThreadState(State state, Word data, Word type); - - bool operator == (State s) const; - bool operator != (State s) const; - - State state; - Word data; - Word type; - }; - -=========================================================== -ACSVM::ThreadInfo -=========================================================== - -Synopsis: - #include - class ThreadInfo - { - public: - virtual ~ThreadInfo() {} - }; - -=========================================================== -ACSVM::Thread -=========================================================== - -Synopsis: - #include - class Thread - { - public: - virtual ThreadInfo const *getInfo() const; - - virtual void lockStrings() const; - - virtual void unlockStrings() const; - - Environment *const env; - - Stack callStk; - Stack dataStk; - Store localArr; - Store localReg; - PrintBuf printBuf; - ThreadState state; - - Word const *codePtr; - Module *module; - GlobalScope *scopeGbl; - HubScope *scopeHub; - MapScope *scopeMap; - ModuleScope *scopeMod; - Script *script; - Word delay; - Word result; - }; - -############################################################################### -EOF -############################################################################### - diff --git a/libs/ACSVM/lib/libacsvm-capi.dll.a b/libs/ACSVM/lib/libacsvm-capi.dll.a deleted file mode 100644 index e76867d99..000000000 Binary files a/libs/ACSVM/lib/libacsvm-capi.dll.a and /dev/null differ