Method object refactor
This commit is contained in:
parent
add66e6cac
commit
7332e72bb2
25 changed files with 420 additions and 529 deletions
|
|
@ -133,7 +133,7 @@ obj::Object* imgui_object_create_menu(obj::TypeGroups* type_group = nullptr) {
|
||||||
|
|
||||||
if (ImGui::Button((childo->key).c_str(), { 100, 0 })) {
|
if (ImGui::Button((childo->key).c_str(), { 100, 0 })) {
|
||||||
if (childo->key == "null") {
|
if (childo->key == "null") {
|
||||||
newo = NDO_NULL;
|
newo = objects_api::getNull();
|
||||||
} else {
|
} else {
|
||||||
newo = objects_api::createByName(childo->key.c_str());
|
newo = objects_api::createByName(childo->key.c_str());
|
||||||
}
|
}
|
||||||
|
|
@ -334,7 +334,7 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::interpreterView(obj::Interpreter
|
||||||
End();
|
End();
|
||||||
|
|
||||||
Begin("SourceCodeView");
|
Begin("SourceCodeView");
|
||||||
{ stringView(interp.mCallStack.mStack.last().mMethod->mScript->mReadable); }
|
{ stringView(interp.mCallStack.mStack.last().mMethod->mBytecodeLink->mReadable); }
|
||||||
End();
|
End();
|
||||||
|
|
||||||
Begin("OperandStack");
|
Begin("OperandStack");
|
||||||
|
|
@ -849,7 +849,7 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::classView(obj::ClassObject* self
|
||||||
|
|
||||||
obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::methodView(obj::MethodObject* in) {
|
obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::methodView(obj::MethodObject* in) {
|
||||||
|
|
||||||
if (in->mScript->mBytecode.mInstructions.size()) {
|
if (in->mBytecodeLink->mBytecode.mInstructions.size()) {
|
||||||
if (ImGui::Button("Recompile")) {
|
if (ImGui::Button("Recompile")) {
|
||||||
in->compile();
|
in->compile();
|
||||||
}
|
}
|
||||||
|
|
@ -867,7 +867,7 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::methodView(obj::MethodObject* in
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
auto ret = stringView(in->mScript->mReadable);
|
auto ret = stringView(in->mBytecodeLink->mReadable);
|
||||||
|
|
||||||
if (ret.obj) {
|
if (ret.obj) {
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
||||||
|
|
@ -30,15 +30,6 @@ ConstObjectsPool::~ConstObjectsPool() {
|
||||||
objects_api::destroy(mBoolTrue.mObj);
|
objects_api::destroy(mBoolTrue.mObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto obj : mStrings) {
|
|
||||||
delete obj->val;
|
|
||||||
}
|
|
||||||
for (auto obj : mIntegers) {
|
|
||||||
delete obj->val;
|
|
||||||
}
|
|
||||||
for (auto obj : mFloats) {
|
|
||||||
delete obj->val;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstObject* ConstObjectsPool::registerObject(Object* obj) {
|
ConstObject* ConstObjectsPool::registerObject(Object* obj) {
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,7 @@ void FunctionDefinition::EvalStatement(Statement* stm) {
|
||||||
func.EvalStatement(child_stm.data());
|
func.EvalStatement(child_stm.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
func.generateByteCode(function_obj->mScript->mBytecode);
|
func.generateByteCode(function_obj->mBytecodeLink->mBytecode);
|
||||||
|
|
||||||
inst(Instruction(OpCode::LOAD_CONST, method_const_obj));
|
inst(Instruction(OpCode::LOAD_CONST, method_const_obj));
|
||||||
inst(Instruction(OpCode::LOAD_CONST, mConstants.get(func.mFunctionId)));
|
inst(Instruction(OpCode::LOAD_CONST, mConstants.get(func.mFunctionId)));
|
||||||
|
|
@ -168,7 +168,7 @@ void FunctionDefinition::EvalStatement(Statement* stm) {
|
||||||
}
|
}
|
||||||
// create one last instruction - constructing class from function execution state
|
// create one last instruction - constructing class from function execution state
|
||||||
func.inst(Instruction(OpCode::CLASS_CONSTRUCT));
|
func.inst(Instruction(OpCode::CLASS_CONSTRUCT));
|
||||||
func.generateByteCode(function_obj->mScript->mBytecode);
|
func.generateByteCode(function_obj->mBytecodeLink->mBytecode);
|
||||||
|
|
||||||
inst(Instruction(OpCode::LOAD_CONST, method_const_obj));
|
inst(Instruction(OpCode::LOAD_CONST, method_const_obj));
|
||||||
inst(Instruction(OpCode::LOAD_CONST, mConstants.get(func.mFunctionId)));
|
inst(Instruction(OpCode::LOAD_CONST, mConstants.get(func.mFunctionId)));
|
||||||
|
|
@ -444,6 +444,8 @@ void FunctionDefinition::generateByteCode(ByteCode& out) {
|
||||||
|
|
||||||
mConstants.save(out.mConstants);
|
mConstants.save(out.mConstants);
|
||||||
|
|
||||||
|
out.updateRefCount();
|
||||||
|
|
||||||
alni inst_len = 0;
|
alni inst_len = 0;
|
||||||
for (auto inst_iter : mInstructions) {
|
for (auto inst_iter : mInstructions) {
|
||||||
inst_len += instSize(inst_iter.data());
|
inst_len += instSize(inst_iter.data());
|
||||||
|
|
@ -554,7 +556,7 @@ bool obj::Compile(obj::MethodObject* method) {
|
||||||
|
|
||||||
Parser parser;
|
Parser parser;
|
||||||
|
|
||||||
auto script = method->mScript->mReadable->val;
|
auto script = method->mBytecodeLink->mReadable->val;
|
||||||
auto res = parser.parse(script);
|
auto res = parser.parse(script);
|
||||||
|
|
||||||
if (res.isError) {
|
if (res.isError) {
|
||||||
|
|
@ -562,7 +564,7 @@ bool obj::Compile(obj::MethodObject* method) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Generate(method->mScript->mBytecode, res.scope);
|
Generate(method->mBytecodeLink->mBytecode, res.scope);
|
||||||
|
|
||||||
delete res.scope;
|
delete res.scope;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,7 @@ using namespace obj;
|
||||||
|
|
||||||
ObjectsContext* obj::gObjectsContext = nullptr;
|
ObjectsContext* obj::gObjectsContext = nullptr;
|
||||||
|
|
||||||
ObjectsContext::ObjectsContext() {
|
ObjectsContext::ObjectsContext() { interp = new Interpreter(); }
|
||||||
memSetVal(sl_callbacks, SAVE_LOAD_MAX_CALLBACK_SLOTS * sizeof(save_load_callbacks*), 0);
|
|
||||||
interp = new Interpreter();
|
|
||||||
}
|
|
||||||
|
|
||||||
ObjectsContext::~ObjectsContext() { delete interp; }
|
ObjectsContext::~ObjectsContext() { delete interp; }
|
||||||
|
|
||||||
|
|
@ -24,9 +21,12 @@ void objects_api::initialize() {
|
||||||
gObjectsContext = new ObjectsContext();
|
gObjectsContext = new ObjectsContext();
|
||||||
|
|
||||||
gObjectsContext->nullObject = create<NullObject>();
|
gObjectsContext->nullObject = create<NullObject>();
|
||||||
|
objects_api::increaseReferenceCount(gObjectsContext->nullObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
void objects_api::finalize() {
|
void objects_api::finalize() {
|
||||||
|
destroy(gObjectsContext->nullObject);
|
||||||
|
|
||||||
assertNoLeaks();
|
assertNoLeaks();
|
||||||
|
|
||||||
ASSERT(gObjectsContext)
|
ASSERT(gObjectsContext)
|
||||||
|
|
|
||||||
|
|
@ -327,32 +327,8 @@ bool objects_api::save(Object* in, const std::string& path, bool compressed) {
|
||||||
|
|
||||||
ndf.setFreeAddress(ndf.getAddress());
|
ndf.setFreeAddress(ndf.getAddress());
|
||||||
|
|
||||||
// pre allocate
|
|
||||||
for (alni i = 0; i < SAVE_LOAD_MAX_CALLBACK_SLOTS; i++) {
|
|
||||||
if (gObjectsContext->sl_callbacks[i]) {
|
|
||||||
DEBUG_ASSERT(gObjectsContext->sl_callbacks[i]->size);
|
|
||||||
ndf.setFreeAddress(
|
|
||||||
ndf.getFreeAddress() + gObjectsContext->sl_callbacks[i]->size(gObjectsContext->sl_callbacks[i]->self, ndf)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// pre-save
|
|
||||||
for (alni i = 0; i < SAVE_LOAD_MAX_CALLBACK_SLOTS; i++) {
|
|
||||||
if (gObjectsContext->sl_callbacks[i] && gObjectsContext->sl_callbacks[i]->pre_save) {
|
|
||||||
gObjectsContext->sl_callbacks[i]->pre_save(gObjectsContext->sl_callbacks[i]->self, ndf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
save(ndf, in);
|
save(ndf, in);
|
||||||
|
|
||||||
// post-save
|
|
||||||
for (alni i = 0; i < SAVE_LOAD_MAX_CALLBACK_SLOTS; i++) {
|
|
||||||
if (gObjectsContext->sl_callbacks[i] && gObjectsContext->sl_callbacks[i]->post_save) {
|
|
||||||
gObjectsContext->sl_callbacks[i]->post_save(gObjectsContext->sl_callbacks[i]->self, ndf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO : add compression
|
// TODO : add compression
|
||||||
/*
|
/*
|
||||||
if (compressed) {
|
if (compressed) {
|
||||||
|
|
@ -404,22 +380,8 @@ Object* objects_api::load(const std::string& path) {
|
||||||
|
|
||||||
ndf.setAddress(sizeof(ObjectsFileHeader));
|
ndf.setAddress(sizeof(ObjectsFileHeader));
|
||||||
|
|
||||||
// preload
|
|
||||||
for (alni i = 0; i < SAVE_LOAD_MAX_CALLBACK_SLOTS; i++) {
|
|
||||||
if (gObjectsContext->sl_callbacks[i] && gObjectsContext->sl_callbacks[i]->pre_load) {
|
|
||||||
gObjectsContext->sl_callbacks[i]->pre_load(gObjectsContext->sl_callbacks[i]->self, ndf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Object* out = load(ndf, ndf.getAddress());
|
Object* out = load(ndf, ndf.getAddress());
|
||||||
|
|
||||||
// post
|
|
||||||
for (alni i = 0; i < SAVE_LOAD_MAX_CALLBACK_SLOTS; i++) {
|
|
||||||
if (gObjectsContext->sl_callbacks[i] && gObjectsContext->sl_callbacks[i]->post_save) {
|
|
||||||
gObjectsContext->sl_callbacks[i]->post_load(gObjectsContext->sl_callbacks[i]->self, ndf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
free(loaded_file);
|
free(loaded_file);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -432,8 +394,3 @@ Object* objects_api::load(const std::string& path) {
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void objects_api::add_sl_callbacks(save_load_callbacks* in) {
|
|
||||||
gObjectsContext->sl_callbacks[gObjectsContext->sl_callbacks_load_idx] = in;
|
|
||||||
gObjectsContext->sl_callbacks_load_idx++;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
|
|
||||||
#include "compiler/Functions.hpp"
|
#include "compiler/Functions.hpp"
|
||||||
#include "primitives/PrimitiveObjects.hpp"
|
#include "primitives/PrimitiveObjects.hpp"
|
||||||
#include "core/ScriptSection.hpp"
|
|
||||||
|
|
||||||
using namespace tp;
|
using namespace tp;
|
||||||
using namespace obj;
|
using namespace obj;
|
||||||
|
|
@ -20,6 +19,7 @@ static void defineTypes() {
|
||||||
objects_api::define(&ColorObject::TypeData);
|
objects_api::define(&ColorObject::TypeData);
|
||||||
objects_api::define(&InterpreterObject::TypeData);
|
objects_api::define(&InterpreterObject::TypeData);
|
||||||
objects_api::define(&TypeObject::TypeData);
|
objects_api::define(&TypeObject::TypeData);
|
||||||
|
objects_api::define(&BytecodeObject::TypeData);
|
||||||
objects_api::define(&MethodObject::TypeData);
|
objects_api::define(&MethodObject::TypeData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,19 +42,13 @@ static void defineGroups() {
|
||||||
static bool init(const ModuleManifest*) {
|
static bool init(const ModuleManifest*) {
|
||||||
objects_api::initialize();
|
objects_api::initialize();
|
||||||
|
|
||||||
ScriptSection::initialize();
|
|
||||||
|
|
||||||
defineTypes();
|
defineTypes();
|
||||||
defineGroups();
|
defineGroups();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void deinit(const ModuleManifest*) {
|
static void deinit(const ModuleManifest*) { objects_api::finalize(); }
|
||||||
ScriptSection::uninitialize();
|
|
||||||
|
|
||||||
objects_api::finalize();
|
|
||||||
}
|
|
||||||
|
|
||||||
static ModuleManifest* sModuleDependencies[] = { nullptr };
|
static ModuleManifest* sModuleDependencies[] = { nullptr };
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,251 +0,0 @@
|
||||||
|
|
||||||
#include "core/ScriptSection.hpp"
|
|
||||||
|
|
||||||
using namespace tp;
|
|
||||||
using namespace obj;
|
|
||||||
|
|
||||||
ScriptSection* gScriptSection = nullptr;
|
|
||||||
|
|
||||||
struct script_data_head {
|
|
||||||
alni refc = 0;
|
|
||||||
alni store_adress = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
void set_script_head_store_adress(Script* in, alni address) { ((script_data_head*) in - 1)->store_adress = address; }
|
|
||||||
|
|
||||||
alni get_script_head_store_adress(Script* in) { return ((script_data_head*) in - 1)->store_adress; }
|
|
||||||
|
|
||||||
Script* ScriptSection::createScript() {
|
|
||||||
auto sdhead = (script_data_head*) malloc(sizeof(script_data_head) + sizeof(Script));
|
|
||||||
auto out = (Script*) (sdhead + 1);
|
|
||||||
|
|
||||||
if (!sdhead) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
sdhead->refc = 1;
|
|
||||||
sdhead->store_adress = -1;
|
|
||||||
|
|
||||||
mScripts.pushBack(out);
|
|
||||||
|
|
||||||
new (out) Script();
|
|
||||||
out->mReadable = obj::StringObject::create("");
|
|
||||||
objects_api::increaseReferenceCount(out->mReadable);
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScriptSection::delete_script(Script* script) {
|
|
||||||
script->~Script();
|
|
||||||
objects_api::destroy(script->mReadable);
|
|
||||||
|
|
||||||
free((((script_data_head*) script) - 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScriptSection::reference_script(Script* script) { (((script_data_head*) script) - 1)->refc++; }
|
|
||||||
|
|
||||||
void ScriptSection::abandonScript(Script* script) {
|
|
||||||
if ((((script_data_head*) script) - 1)->refc > 1) {
|
|
||||||
(((script_data_head*) script) - 1)->refc--;
|
|
||||||
} else {
|
|
||||||
// ISSUE : on delete list structure is outdated
|
|
||||||
// FIXME : use pool alloc with ref count
|
|
||||||
// forwarding to global destruction
|
|
||||||
// delete_script(script);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScriptSection::changeScript(Script** current_script, Script** new_script) {
|
|
||||||
abandonScript(*current_script);
|
|
||||||
reference_script(*new_script);
|
|
||||||
|
|
||||||
*current_script = *new_script;
|
|
||||||
}
|
|
||||||
|
|
||||||
alni ScriptSection::get_script_file_adress(Script* in) { return get_script_head_store_adress(in); }
|
|
||||||
|
|
||||||
alni ScriptSection::save_script_table_to_file_size(ScriptSection* self, ArchiverOut& file) {
|
|
||||||
alni size = 0;
|
|
||||||
size += 5; // header
|
|
||||||
size += sizeof(alni); // scripts length
|
|
||||||
|
|
||||||
for (auto iter : self->mScripts) {
|
|
||||||
|
|
||||||
set_script_head_store_adress(iter.data(), file.getAddress() + size);
|
|
||||||
|
|
||||||
size += sizeof(alni); // scripts string obj ref
|
|
||||||
size += sizeof(alni); // constants length
|
|
||||||
|
|
||||||
for (auto const_obj : iter->mBytecode.mConstants) {
|
|
||||||
size += sizeof(alni); // constant object addres
|
|
||||||
}
|
|
||||||
|
|
||||||
// instructions
|
|
||||||
size += SaveSizeCounter::calc(iter->mBytecode.mInstructions);
|
|
||||||
}
|
|
||||||
|
|
||||||
size += sizeof(alni); // objects mem offset
|
|
||||||
size += 5; // header
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScriptSection::save_script_table_to_file(ScriptSection* self, ArchiverOut& file) {
|
|
||||||
// header
|
|
||||||
file.writeBytes("/scr/", 5);
|
|
||||||
|
|
||||||
// scripts length
|
|
||||||
alni scripts_count = self->mScripts.length();
|
|
||||||
file << scripts_count;
|
|
||||||
|
|
||||||
for (auto iter : self->mScripts) {
|
|
||||||
|
|
||||||
// scripts string obj ref
|
|
||||||
auto obj_addres = objects_api::save(file, iter->mReadable);
|
|
||||||
file << obj_addres;
|
|
||||||
|
|
||||||
// constants length
|
|
||||||
alni consts_count = iter->mBytecode.mConstants.size();
|
|
||||||
file << consts_count;
|
|
||||||
|
|
||||||
for (auto const_obj : iter->mBytecode.mConstants) {
|
|
||||||
// constant object addres
|
|
||||||
auto obj_addres = objects_api::save(file, const_obj.data());
|
|
||||||
file << obj_addres;
|
|
||||||
}
|
|
||||||
|
|
||||||
// mInstructions
|
|
||||||
file << iter->mBytecode.mInstructions;
|
|
||||||
}
|
|
||||||
|
|
||||||
// header
|
|
||||||
file.writeBytes("/scr/", 5);
|
|
||||||
|
|
||||||
alni objects_mem_offset = file.getFreeAddress();
|
|
||||||
file << objects_mem_offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
void load_constants(ScriptSection* self, ArchiverIn& file, alni start_addr) {
|
|
||||||
auto addres = file.getAddress();
|
|
||||||
|
|
||||||
file.setAddress(start_addr);
|
|
||||||
file.setAddress(start_addr + 5); // header
|
|
||||||
|
|
||||||
alni scripts_count;
|
|
||||||
file >> scripts_count;
|
|
||||||
|
|
||||||
for (alni i = 0; i < scripts_count; i++) {
|
|
||||||
|
|
||||||
auto script = self->get_scritp_from_file_adress(file.getAddress());
|
|
||||||
|
|
||||||
// script text
|
|
||||||
alni str_addr;
|
|
||||||
file >> str_addr;
|
|
||||||
|
|
||||||
objects_api::destroy(script->mReadable); // we already have string object in the script when creating script
|
|
||||||
script->mReadable = objects_api::cast<StringObject>(objects_api::load(file, str_addr));
|
|
||||||
|
|
||||||
file.setAddress(file.getAddress() + sizeof(alni)); // constants length
|
|
||||||
|
|
||||||
for (auto const_obj : script->mBytecode.mConstants) {
|
|
||||||
alni consts_addr;
|
|
||||||
file >> consts_addr;
|
|
||||||
const_obj.data() = objects_api::load(file, consts_addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
// instructions
|
|
||||||
file.setAddress(file.getAddress() + SaveSizeCounter::calc(script->mBytecode.mInstructions));
|
|
||||||
}
|
|
||||||
|
|
||||||
file.setAddress(addres);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScriptSection::load_script_table_from_file(ScriptSection* self, ArchiverIn& file) {
|
|
||||||
for (auto iter : self->mScripts) {
|
|
||||||
set_script_head_store_adress(iter.data(), -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto section_start_addr = file.getAddress();
|
|
||||||
|
|
||||||
// header
|
|
||||||
file.setAddress(file.getAddress() + 5);
|
|
||||||
|
|
||||||
// scripts length
|
|
||||||
alni scripts_count;
|
|
||||||
file >> scripts_count;
|
|
||||||
|
|
||||||
for (alni i = 0; i < scripts_count; i++) {
|
|
||||||
|
|
||||||
auto new_script = self->createScript();
|
|
||||||
set_script_head_store_adress(new_script, file.getAddress());
|
|
||||||
|
|
||||||
// scripts text
|
|
||||||
file.setAddress(file.getAddress() + sizeof(alni));
|
|
||||||
|
|
||||||
// constants length
|
|
||||||
alni consts_count;
|
|
||||||
file >> consts_count;
|
|
||||||
|
|
||||||
new_script->mBytecode.mConstants.reserve(consts_count);
|
|
||||||
|
|
||||||
for (alni j = 0; j < consts_count; j++) {
|
|
||||||
// constant object addres
|
|
||||||
alni consts_addr;
|
|
||||||
file >> consts_addr;
|
|
||||||
|
|
||||||
// skiping
|
|
||||||
// new_script->mBytecode.mConstants[j] = objects_api::load(file, consts_addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
// mInstructions
|
|
||||||
file >> new_script->mBytecode.mInstructions;
|
|
||||||
}
|
|
||||||
|
|
||||||
load_constants(self, file, section_start_addr);
|
|
||||||
|
|
||||||
// header
|
|
||||||
file.setAddress(file.getAddress() + 5);
|
|
||||||
|
|
||||||
alni objects_mem_offset;
|
|
||||||
file >> objects_mem_offset;
|
|
||||||
|
|
||||||
file.setAddress(objects_mem_offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
Script* ScriptSection::get_scritp_from_file_adress(alni file_adress) {
|
|
||||||
for (auto iter : mScripts) {
|
|
||||||
if (get_script_head_store_adress(iter.data()) == file_adress) {
|
|
||||||
return iter.data();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
ScriptSection::~ScriptSection() {
|
|
||||||
for (auto iter : mScripts) {
|
|
||||||
delete_script(iter.data());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
obj::save_load_callbacks ScriptSection::slcb_script_section = {
|
|
||||||
.self = gScriptSection,
|
|
||||||
.pre_save = (obj::pre_save_callback*) ScriptSection::save_script_table_to_file,
|
|
||||||
.size = (obj::slcb_size_callback*) ScriptSection::save_script_table_to_file_size,
|
|
||||||
.pre_load = (obj::pre_load_callback*) ScriptSection::load_script_table_from_file,
|
|
||||||
.post_save = nullptr,
|
|
||||||
.post_load = nullptr,
|
|
||||||
};
|
|
||||||
|
|
||||||
void ScriptSection::initialize() {
|
|
||||||
ASSERT(!gScriptSection);
|
|
||||||
gScriptSection = new ScriptSection();
|
|
||||||
|
|
||||||
slcb_script_section.self = gScriptSection;
|
|
||||||
objects_api::add_sl_callbacks(&slcb_script_section);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScriptSection::uninitialize() {
|
|
||||||
ASSERT(gScriptSection);
|
|
||||||
delete gScriptSection;
|
|
||||||
gScriptSection = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
ScriptSection* ScriptSection::globalHandle() { return gScriptSection; }
|
|
||||||
|
|
@ -122,7 +122,7 @@ void TypeMethod::operator()(Interpreter* interp) const {
|
||||||
interp->mOperandsStack.push(ret.obj);
|
interp->mOperandsStack.push(ret.obj);
|
||||||
interp->mScopeStack.addTempReturn(ret.obj);
|
interp->mScopeStack.addTempReturn(ret.obj);
|
||||||
} else {
|
} else {
|
||||||
interp->mOperandsStack.push(NDO_NULL_REF);
|
interp->mOperandsStack.push(objects_api::getNullReferenced());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,11 @@ using namespace obj;
|
||||||
void CallStack::enter(const CallStack::CallFrame& frame) {
|
void CallStack::enter(const CallStack::CallFrame& frame) {
|
||||||
if (mStack.size()) {
|
if (mStack.size()) {
|
||||||
auto& last_frame = mStack.last();
|
auto& last_frame = mStack.last();
|
||||||
last_frame.mIp = last_frame.mMethod->mScript->mBytecode.mInstructionIdx;
|
last_frame.mIp = last_frame.mMethod->mBytecodeLink->mBytecode.mInstructionIdx;
|
||||||
}
|
}
|
||||||
|
|
||||||
frame.mMethod->mScript->mBytecode.mArgumentsLoaded = 0;
|
frame.mMethod->mBytecodeLink->mBytecode.mArgumentsLoaded = 0;
|
||||||
frame.mMethod->mScript->mBytecode.mInstructionIdx = 0;
|
frame.mMethod->mBytecodeLink->mBytecode.mInstructionIdx = 0;
|
||||||
objects_api::increaseReferenceCount(frame.mMethod);
|
objects_api::increaseReferenceCount(frame.mMethod);
|
||||||
mStack.append(frame);
|
mStack.append(frame);
|
||||||
}
|
}
|
||||||
|
|
@ -26,10 +26,10 @@ void CallStack::leave() {
|
||||||
|
|
||||||
if (mStack.size()) {
|
if (mStack.size()) {
|
||||||
auto& last_frame = mStack.last();
|
auto& last_frame = mStack.last();
|
||||||
last_frame.mMethod->mScript->mBytecode.mInstructionIdx = last_frame.mIp;
|
last_frame.mMethod->mBytecodeLink->mBytecode.mInstructionIdx = last_frame.mIp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteCode* CallStack::getBytecode() { return &mStack.last().mMethod->mScript->mBytecode; }
|
ByteCode* CallStack::getBytecode() { return &mStack.last().mMethod->mBytecodeLink->mBytecode; }
|
||||||
|
|
||||||
halni CallStack::len() const { return mStack.size(); }
|
halni CallStack::len() const { return mStack.size(); }
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ uint2 param(ByteCode* bytecode) { return loadConstDataIdx(bytecode); }
|
||||||
void Interpreter::exec(
|
void Interpreter::exec(
|
||||||
obj::MethodObject* method, obj::ClassObject* self, obj::DictObject* globals, InitialierList<GlobalDef> globals2
|
obj::MethodObject* method, obj::ClassObject* self, obj::DictObject* globals, InitialierList<GlobalDef> globals2
|
||||||
) {
|
) {
|
||||||
if (!method->mScript->mBytecode.mInstructions.size()) {
|
if (!method->mBytecodeLink->mBytecode.mInstructions.size()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,7 +99,7 @@ void Interpreter::stepBytecodeIn() {
|
||||||
mCallStack.leave();
|
mCallStack.leave();
|
||||||
|
|
||||||
if (mCallStack.len()) {
|
if (mCallStack.len()) {
|
||||||
mOperandsStack.push(NDO_NULL_REF);
|
mOperandsStack.push(objects_api::getNullReferenced());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -305,7 +305,7 @@ void Interpreter::stepBytecodeIn() {
|
||||||
mScopeStack.leaveScope();
|
mScopeStack.leaveScope();
|
||||||
mCallStack.leave();
|
mCallStack.leave();
|
||||||
if (mCallStack.len()) {
|
if (mCallStack.len()) {
|
||||||
mOperandsStack.push(NDO_NULL_REF);
|
mOperandsStack.push(objects_api::getNullReferenced());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -600,7 +600,7 @@ void Interpreter::stepBytecodeIn() {
|
||||||
void Interpreter::execAll(
|
void Interpreter::execAll(
|
||||||
obj::MethodObject* method, obj::ClassObject* self, obj::DictObject* globals, InitialierList<GlobalDef> globals2
|
obj::MethodObject* method, obj::ClassObject* self, obj::DictObject* globals, InitialierList<GlobalDef> globals2
|
||||||
) {
|
) {
|
||||||
if (!method->mScript->mBytecode.mInstructions.size()) {
|
if (!method->mBytecodeLink->mBytecode.mInstructions.size()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ const ParserSymbol symbols [] =
|
||||||
{48, (SymbolType) 1, "print_terminal", "print", "print"},
|
{48, (SymbolType) 1, "print_terminal", "print", "print"},
|
||||||
{49, (SymbolType) 2, "expr_list", "expr_list", "expr_list"},
|
{49, (SymbolType) 2, "expr_list", "expr_list", "expr_list"},
|
||||||
{50, (SymbolType) 1, "comma_terminal", ",", ","},
|
{50, (SymbolType) 1, "comma_terminal", ",", ","},
|
||||||
{51, (SymbolType) 1, "id", "[a-z]", "id"},
|
{51, (SymbolType) 1, "id", "([a-z]|[A-Z])+", "id"},
|
||||||
{52, (SymbolType) 1, "boolean", "true|false", "boolean"},
|
{52, (SymbolType) 1, "boolean", "true|false", "boolean"},
|
||||||
{53, (SymbolType) 1, "integer", "(\\+|\\-)?[0-9]+", "integer"},
|
{53, (SymbolType) 1, "integer", "(\\+|\\-)?[0-9]+", "integer"},
|
||||||
{54, (SymbolType) 1, "real", "(\\+|\\-)?[0-9]+(\\.[0-9]+)?((e|E)(\\+|\\-)?[0-9]+)?", "real"},
|
{54, (SymbolType) 1, "real", "(\\+|\\-)?[0-9]+(\\.[0-9]+)?((e|E)(\\+|\\-)?[0-9]+)?", "real"},
|
||||||
|
|
@ -1383,12 +1383,13 @@ const LexerTransition lexer_transitions [] =
|
||||||
{60, 61, &lexer_states[26], nullptr},
|
{60, 61, &lexer_states[26], nullptr},
|
||||||
{61, 62, &lexer_states[23], nullptr},
|
{61, 62, &lexer_states[23], nullptr},
|
||||||
{62, 63, &lexer_states[25], nullptr},
|
{62, 63, &lexer_states[25], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
{97, 98, &lexer_states[76], nullptr},
|
{97, 98, &lexer_states[76], nullptr},
|
||||||
{98, 99, &lexer_states[50], nullptr},
|
{98, 99, &lexer_states[50], nullptr},
|
||||||
{99, 100, &lexer_states[40], nullptr},
|
{99, 100, &lexer_states[40], nullptr},
|
||||||
{100, 101, &lexer_states[76], nullptr},
|
{100, 101, &lexer_states[76], nullptr},
|
||||||
{101, 102, &lexer_states[1], nullptr},
|
{101, 102, &lexer_states[1], nullptr},
|
||||||
{102, 103, &lexer_states[78], nullptr},
|
{102, 103, &lexer_states[80], nullptr},
|
||||||
{103, 105, &lexer_states[76], nullptr},
|
{103, 105, &lexer_states[76], nullptr},
|
||||||
{105, 106, &lexer_states[45], nullptr},
|
{105, 106, &lexer_states[45], nullptr},
|
||||||
{106, 109, &lexer_states[76], nullptr},
|
{106, 109, &lexer_states[76], nullptr},
|
||||||
|
|
@ -1405,11 +1406,26 @@ const LexerTransition lexer_transitions [] =
|
||||||
{120, 123, &lexer_states[76], nullptr},
|
{120, 123, &lexer_states[76], nullptr},
|
||||||
{123, 124, &lexer_states[32], nullptr},
|
{123, 124, &lexer_states[32], nullptr},
|
||||||
{125, 126, &lexer_states[33], nullptr},
|
{125, 126, &lexer_states[33], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 108, &lexer_states[76], nullptr},
|
||||||
{108, 109, &lexer_states[47], nullptr},
|
{108, 109, &lexer_states[47], nullptr},
|
||||||
|
{109, 114, &lexer_states[76], nullptr},
|
||||||
{114, 115, &lexer_states[2], nullptr},
|
{114, 115, &lexer_states[2], nullptr},
|
||||||
|
{115, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 114, &lexer_states[76], nullptr},
|
||||||
{114, 115, &lexer_states[3], nullptr},
|
{114, 115, &lexer_states[3], nullptr},
|
||||||
|
{115, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 111, &lexer_states[76], nullptr},
|
||||||
{111, 112, &lexer_states[4], nullptr},
|
{111, 112, &lexer_states[4], nullptr},
|
||||||
|
{112, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 114, &lexer_states[76], nullptr},
|
||||||
{114, 115, &lexer_states[5], nullptr},
|
{114, 115, &lexer_states[5], nullptr},
|
||||||
|
{115, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 123, &lexer_states[76], nullptr},
|
||||||
{119, 120, &lexer_states[7], nullptr},
|
{119, 120, &lexer_states[7], nullptr},
|
||||||
{104, 105, &lexer_states[8], nullptr},
|
{104, 105, &lexer_states[8], nullptr},
|
||||||
{105, 106, &lexer_states[9], nullptr},
|
{105, 106, &lexer_states[9], nullptr},
|
||||||
|
|
@ -1426,44 +1442,176 @@ const LexerTransition lexer_transitions [] =
|
||||||
{61, 62, &lexer_states[27], nullptr},
|
{61, 62, &lexer_states[27], nullptr},
|
||||||
{61, 62, &lexer_states[28], nullptr},
|
{61, 62, &lexer_states[28], nullptr},
|
||||||
{61, 62, &lexer_states[30], nullptr},
|
{61, 62, &lexer_states[30], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 101, &lexer_states[76], nullptr},
|
||||||
{101, 102, &lexer_states[35], nullptr},
|
{101, 102, &lexer_states[35], nullptr},
|
||||||
|
{102, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 116, &lexer_states[76], nullptr},
|
||||||
{116, 117, &lexer_states[36], nullptr},
|
{116, 117, &lexer_states[36], nullptr},
|
||||||
|
{117, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 104, &lexer_states[76], nullptr},
|
||||||
{104, 105, &lexer_states[37], nullptr},
|
{104, 105, &lexer_states[37], nullptr},
|
||||||
|
{105, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 111, &lexer_states[76], nullptr},
|
||||||
{111, 112, &lexer_states[38], nullptr},
|
{111, 112, &lexer_states[38], nullptr},
|
||||||
|
{112, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 100, &lexer_states[76], nullptr},
|
||||||
{100, 101, &lexer_states[39], nullptr},
|
{100, 101, &lexer_states[39], nullptr},
|
||||||
|
{101, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 108, &lexer_states[76], nullptr},
|
||||||
{108, 109, &lexer_states[41], nullptr},
|
{108, 109, &lexer_states[41], nullptr},
|
||||||
|
{109, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
{97, 98, &lexer_states[42], nullptr},
|
{97, 98, &lexer_states[42], nullptr},
|
||||||
|
{98, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 115, &lexer_states[76], nullptr},
|
||||||
{115, 116, &lexer_states[43], nullptr},
|
{115, 116, &lexer_states[43], nullptr},
|
||||||
|
{116, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 115, &lexer_states[76], nullptr},
|
||||||
{115, 116, &lexer_states[44], nullptr},
|
{115, 116, &lexer_states[44], nullptr},
|
||||||
|
{116, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 102, &lexer_states[76], nullptr},
|
||||||
{102, 103, &lexer_states[46], nullptr},
|
{102, 103, &lexer_states[46], nullptr},
|
||||||
|
{103, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 115, &lexer_states[76], nullptr},
|
||||||
{115, 116, &lexer_states[48], nullptr},
|
{115, 116, &lexer_states[48], nullptr},
|
||||||
|
{116, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 101, &lexer_states[76], nullptr},
|
||||||
{101, 102, &lexer_states[49], nullptr},
|
{101, 102, &lexer_states[49], nullptr},
|
||||||
|
{102, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 114, &lexer_states[76], nullptr},
|
||||||
{114, 115, &lexer_states[51], nullptr},
|
{114, 115, &lexer_states[51], nullptr},
|
||||||
|
{115, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 101, &lexer_states[76], nullptr},
|
||||||
{101, 102, &lexer_states[52], nullptr},
|
{101, 102, &lexer_states[52], nullptr},
|
||||||
|
{102, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
{97, 98, &lexer_states[53], nullptr},
|
{97, 98, &lexer_states[53], nullptr},
|
||||||
|
{98, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 107, &lexer_states[76], nullptr},
|
||||||
{107, 108, &lexer_states[54], nullptr},
|
{107, 108, &lexer_states[54], nullptr},
|
||||||
|
{108, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 101, &lexer_states[76], nullptr},
|
||||||
{101, 102, &lexer_states[56], nullptr},
|
{101, 102, &lexer_states[56], nullptr},
|
||||||
|
{102, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 116, &lexer_states[76], nullptr},
|
||||||
{116, 117, &lexer_states[57], nullptr},
|
{116, 117, &lexer_states[57], nullptr},
|
||||||
|
{117, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 117, &lexer_states[76], nullptr},
|
||||||
{117, 118, &lexer_states[58], nullptr},
|
{117, 118, &lexer_states[58], nullptr},
|
||||||
|
{118, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 114, &lexer_states[76], nullptr},
|
||||||
{114, 115, &lexer_states[59], nullptr},
|
{114, 115, &lexer_states[59], nullptr},
|
||||||
|
{115, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 110, &lexer_states[76], nullptr},
|
||||||
{110, 111, &lexer_states[60], nullptr},
|
{110, 111, &lexer_states[60], nullptr},
|
||||||
|
{111, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 104, &lexer_states[76], nullptr},
|
||||||
{104, 105, &lexer_states[62], nullptr},
|
{104, 105, &lexer_states[62], nullptr},
|
||||||
|
{105, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 105, &lexer_states[76], nullptr},
|
||||||
{105, 106, &lexer_states[63], nullptr},
|
{105, 106, &lexer_states[63], nullptr},
|
||||||
|
{106, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 108, &lexer_states[76], nullptr},
|
||||||
{108, 109, &lexer_states[64], nullptr},
|
{108, 109, &lexer_states[64], nullptr},
|
||||||
|
{109, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 101, &lexer_states[76], nullptr},
|
||||||
{101, 102, &lexer_states[65], nullptr},
|
{101, 102, &lexer_states[65], nullptr},
|
||||||
|
{102, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
{97, 98, &lexer_states[67], nullptr},
|
{97, 98, &lexer_states[67], nullptr},
|
||||||
|
{98, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 114, &lexer_states[76], nullptr},
|
||||||
{114, 115, &lexer_states[68], nullptr},
|
{114, 115, &lexer_states[68], nullptr},
|
||||||
|
{115, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 114, &lexer_states[76], nullptr},
|
||||||
{114, 115, &lexer_states[71], nullptr},
|
{114, 115, &lexer_states[71], nullptr},
|
||||||
|
{115, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 105, &lexer_states[76], nullptr},
|
||||||
{105, 106, &lexer_states[72], nullptr},
|
{105, 106, &lexer_states[72], nullptr},
|
||||||
|
{106, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 110, &lexer_states[76], nullptr},
|
||||||
{110, 111, &lexer_states[73], nullptr},
|
{110, 111, &lexer_states[73], nullptr},
|
||||||
|
{111, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 116, &lexer_states[76], nullptr},
|
||||||
{116, 117, &lexer_states[74], nullptr},
|
{116, 117, &lexer_states[74], nullptr},
|
||||||
{114, 115, &lexer_states[79], nullptr},
|
{117, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 114, &lexer_states[76], nullptr},
|
||||||
|
{114, 115, &lexer_states[78], nullptr},
|
||||||
|
{115, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 117, &lexer_states[76], nullptr},
|
||||||
|
{117, 118, &lexer_states[79], nullptr},
|
||||||
|
{118, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 101, &lexer_states[76], nullptr},
|
||||||
|
{101, 102, &lexer_states[84], nullptr},
|
||||||
|
{102, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
{97, 98, &lexer_states[81], nullptr},
|
{97, 98, &lexer_states[81], nullptr},
|
||||||
{117, 118, &lexer_states[80], nullptr},
|
{98, 123, &lexer_states[76], nullptr},
|
||||||
{101, 102, &lexer_states[84], nullptr},
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 108, &lexer_states[76], nullptr},
|
||||||
{108, 109, &lexer_states[82], nullptr},
|
{108, 109, &lexer_states[82], nullptr},
|
||||||
|
{109, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 115, &lexer_states[76], nullptr},
|
||||||
{115, 116, &lexer_states[83], nullptr},
|
{115, 116, &lexer_states[83], nullptr},
|
||||||
|
{116, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 101, &lexer_states[76], nullptr},
|
||||||
{101, 102, &lexer_states[84], nullptr},
|
{101, 102, &lexer_states[84], nullptr},
|
||||||
|
{102, 123, &lexer_states[76], nullptr},
|
||||||
|
{65, 91, &lexer_states[76], nullptr},
|
||||||
|
{97, 123, &lexer_states[76], nullptr},
|
||||||
{46, 47, &lexer_states[86], nullptr},
|
{46, 47, &lexer_states[86], nullptr},
|
||||||
{48, 58, &lexer_states[85], nullptr},
|
{48, 58, &lexer_states[85], nullptr},
|
||||||
{69, 70, &lexer_states[88], nullptr},
|
{69, 70, &lexer_states[88], nullptr},
|
||||||
|
|
@ -1483,106 +1631,106 @@ const LexerTransition lexer_transitions [] =
|
||||||
|
|
||||||
const LexerState lexer_states [] =
|
const LexerState lexer_states [] =
|
||||||
{
|
{
|
||||||
{0, 39, &lexer_transitions[0], nullptr},
|
{0, 40, &lexer_transitions[0], nullptr},
|
||||||
{1, 2, &lexer_transitions[39], &symbols[51]},
|
{1, 6, &lexer_transitions[40], &symbols[51]},
|
||||||
{2, 1, &lexer_transitions[41], nullptr},
|
{2, 4, &lexer_transitions[46], &symbols[51]},
|
||||||
{3, 1, &lexer_transitions[42], nullptr},
|
{3, 4, &lexer_transitions[50], &symbols[51]},
|
||||||
{4, 1, &lexer_transitions[43], nullptr},
|
{4, 4, &lexer_transitions[54], &symbols[51]},
|
||||||
{5, 0, &lexer_transitions[44], &symbols[2]},
|
{5, 2, &lexer_transitions[58], &symbols[2]},
|
||||||
{6, 1, &lexer_transitions[44], &symbols[10]},
|
{6, 1, &lexer_transitions[60], &symbols[10]},
|
||||||
{7, 1, &lexer_transitions[45], nullptr},
|
{7, 1, &lexer_transitions[61], nullptr},
|
||||||
{8, 1, &lexer_transitions[46], nullptr},
|
{8, 1, &lexer_transitions[62], nullptr},
|
||||||
{9, 1, &lexer_transitions[47], nullptr},
|
{9, 1, &lexer_transitions[63], nullptr},
|
||||||
{10, 1, &lexer_transitions[48], nullptr},
|
{10, 1, &lexer_transitions[64], nullptr},
|
||||||
{11, 1, &lexer_transitions[49], nullptr},
|
{11, 1, &lexer_transitions[65], nullptr},
|
||||||
{12, 1, &lexer_transitions[50], nullptr},
|
{12, 1, &lexer_transitions[66], nullptr},
|
||||||
{13, 1, &lexer_transitions[51], nullptr},
|
{13, 1, &lexer_transitions[67], nullptr},
|
||||||
{14, 1, &lexer_transitions[52], nullptr},
|
{14, 1, &lexer_transitions[68], nullptr},
|
||||||
{15, 1, &lexer_transitions[53], nullptr},
|
{15, 1, &lexer_transitions[69], nullptr},
|
||||||
{16, 0, &lexer_transitions[54], &symbols[3]},
|
{16, 0, &lexer_transitions[70], &symbols[3]},
|
||||||
{17, 0, &lexer_transitions[54], &symbols[4]},
|
{17, 0, &lexer_transitions[70], &symbols[4]},
|
||||||
{18, 0, &lexer_transitions[54], &symbols[5]},
|
{18, 0, &lexer_transitions[70], &symbols[5]},
|
||||||
{19, 1, &lexer_transitions[54], &symbols[6]},
|
{19, 1, &lexer_transitions[70], &symbols[6]},
|
||||||
{20, 1, &lexer_transitions[55], &symbols[7]},
|
{20, 1, &lexer_transitions[71], &symbols[7]},
|
||||||
{21, 0, &lexer_transitions[56], &symbols[8]},
|
{21, 0, &lexer_transitions[72], &symbols[8]},
|
||||||
{22, 0, &lexer_transitions[56], &symbols[9]},
|
{22, 0, &lexer_transitions[72], &symbols[9]},
|
||||||
{23, 1, &lexer_transitions[56], &symbols[11]},
|
{23, 1, &lexer_transitions[72], &symbols[11]},
|
||||||
{24, 0, &lexer_transitions[57], &symbols[12]},
|
{24, 0, &lexer_transitions[73], &symbols[12]},
|
||||||
{25, 1, &lexer_transitions[57], &symbols[13]},
|
{25, 1, &lexer_transitions[73], &symbols[13]},
|
||||||
{26, 1, &lexer_transitions[58], &symbols[14]},
|
{26, 1, &lexer_transitions[74], &symbols[14]},
|
||||||
{27, 0, &lexer_transitions[59], &symbols[15]},
|
{27, 0, &lexer_transitions[75], &symbols[15]},
|
||||||
{28, 0, &lexer_transitions[59], &symbols[16]},
|
{28, 0, &lexer_transitions[75], &symbols[16]},
|
||||||
{29, 1, &lexer_transitions[59], &symbols[18]},
|
{29, 1, &lexer_transitions[75], &symbols[18]},
|
||||||
{30, 0, &lexer_transitions[60], &symbols[17]},
|
{30, 0, &lexer_transitions[76], &symbols[17]},
|
||||||
{31, 0, &lexer_transitions[60], &symbols[19]},
|
{31, 0, &lexer_transitions[76], &symbols[19]},
|
||||||
{32, 0, &lexer_transitions[60], &symbols[23]},
|
{32, 0, &lexer_transitions[76], &symbols[23]},
|
||||||
{33, 0, &lexer_transitions[60], &symbols[24]},
|
{33, 0, &lexer_transitions[76], &symbols[24]},
|
||||||
{34, 1, &lexer_transitions[60], &symbols[51]},
|
{34, 4, &lexer_transitions[76], &symbols[51]},
|
||||||
{35, 1, &lexer_transitions[61], nullptr},
|
{35, 4, &lexer_transitions[80], &symbols[51]},
|
||||||
{36, 1, &lexer_transitions[62], nullptr},
|
{36, 4, &lexer_transitions[84], &symbols[51]},
|
||||||
{37, 1, &lexer_transitions[63], nullptr},
|
{37, 4, &lexer_transitions[88], &symbols[51]},
|
||||||
{38, 1, &lexer_transitions[64], nullptr},
|
{38, 4, &lexer_transitions[92], &symbols[51]},
|
||||||
{39, 0, &lexer_transitions[65], &symbols[37]},
|
{39, 2, &lexer_transitions[96], &symbols[37]},
|
||||||
{40, 1, &lexer_transitions[65], &symbols[51]},
|
{40, 4, &lexer_transitions[98], &symbols[51]},
|
||||||
{41, 1, &lexer_transitions[66], nullptr},
|
{41, 3, &lexer_transitions[102], &symbols[51]},
|
||||||
{42, 1, &lexer_transitions[67], nullptr},
|
{42, 4, &lexer_transitions[105], &symbols[51]},
|
||||||
{43, 1, &lexer_transitions[68], nullptr},
|
{43, 4, &lexer_transitions[109], &symbols[51]},
|
||||||
{44, 0, &lexer_transitions[69], &symbols[39]},
|
{44, 2, &lexer_transitions[113], &symbols[39]},
|
||||||
{45, 1, &lexer_transitions[69], &symbols[51]},
|
{45, 4, &lexer_transitions[115], &symbols[51]},
|
||||||
{46, 0, &lexer_transitions[70], &symbols[40]},
|
{46, 2, &lexer_transitions[119], &symbols[40]},
|
||||||
{47, 1, &lexer_transitions[70], nullptr},
|
{47, 4, &lexer_transitions[121], &symbols[51]},
|
||||||
{48, 1, &lexer_transitions[71], nullptr},
|
{48, 4, &lexer_transitions[125], &symbols[51]},
|
||||||
{49, 0, &lexer_transitions[72], &symbols[42]},
|
{49, 2, &lexer_transitions[129], &symbols[42]},
|
||||||
{50, 1, &lexer_transitions[72], &symbols[51]},
|
{50, 4, &lexer_transitions[131], &symbols[51]},
|
||||||
{51, 1, &lexer_transitions[73], nullptr},
|
{51, 4, &lexer_transitions[135], &symbols[51]},
|
||||||
{52, 1, &lexer_transitions[74], nullptr},
|
{52, 3, &lexer_transitions[139], &symbols[51]},
|
||||||
{53, 1, &lexer_transitions[75], nullptr},
|
{53, 4, &lexer_transitions[142], &symbols[51]},
|
||||||
{54, 0, &lexer_transitions[76], &symbols[43]},
|
{54, 2, &lexer_transitions[146], &symbols[43]},
|
||||||
{55, 1, &lexer_transitions[76], &symbols[51]},
|
{55, 4, &lexer_transitions[148], &symbols[51]},
|
||||||
{56, 1, &lexer_transitions[77], nullptr},
|
{56, 4, &lexer_transitions[152], &symbols[51]},
|
||||||
{57, 1, &lexer_transitions[78], nullptr},
|
{57, 4, &lexer_transitions[156], &symbols[51]},
|
||||||
{58, 1, &lexer_transitions[79], nullptr},
|
{58, 4, &lexer_transitions[160], &symbols[51]},
|
||||||
{59, 1, &lexer_transitions[80], nullptr},
|
{59, 4, &lexer_transitions[164], &symbols[51]},
|
||||||
{60, 0, &lexer_transitions[81], &symbols[44]},
|
{60, 2, &lexer_transitions[168], &symbols[44]},
|
||||||
{61, 1, &lexer_transitions[81], &symbols[51]},
|
{61, 4, &lexer_transitions[170], &symbols[51]},
|
||||||
{62, 1, &lexer_transitions[82], nullptr},
|
{62, 4, &lexer_transitions[174], &symbols[51]},
|
||||||
{63, 1, &lexer_transitions[83], nullptr},
|
{63, 4, &lexer_transitions[178], &symbols[51]},
|
||||||
{64, 1, &lexer_transitions[84], nullptr},
|
{64, 4, &lexer_transitions[182], &symbols[51]},
|
||||||
{65, 0, &lexer_transitions[85], &symbols[45]},
|
{65, 2, &lexer_transitions[186], &symbols[45]},
|
||||||
{66, 1, &lexer_transitions[85], &symbols[51]},
|
{66, 3, &lexer_transitions[188], &symbols[51]},
|
||||||
{67, 1, &lexer_transitions[86], nullptr},
|
{67, 4, &lexer_transitions[191], &symbols[51]},
|
||||||
{68, 0, &lexer_transitions[87], &symbols[46]},
|
{68, 2, &lexer_transitions[195], &symbols[46]},
|
||||||
{69, 0, &lexer_transitions[87], &symbols[47]},
|
{69, 0, &lexer_transitions[197], &symbols[47]},
|
||||||
{70, 1, &lexer_transitions[87], &symbols[51]},
|
{70, 4, &lexer_transitions[197], &symbols[51]},
|
||||||
{71, 1, &lexer_transitions[88], nullptr},
|
{71, 4, &lexer_transitions[201], &symbols[51]},
|
||||||
{72, 1, &lexer_transitions[89], nullptr},
|
{72, 4, &lexer_transitions[205], &symbols[51]},
|
||||||
{73, 1, &lexer_transitions[90], nullptr},
|
{73, 4, &lexer_transitions[209], &symbols[51]},
|
||||||
{74, 0, &lexer_transitions[91], &symbols[48]},
|
{74, 2, &lexer_transitions[213], &symbols[48]},
|
||||||
{75, 0, &lexer_transitions[91], &symbols[50]},
|
{75, 0, &lexer_transitions[215], &symbols[50]},
|
||||||
{76, 0, &lexer_transitions[91], &symbols[51]},
|
{76, 2, &lexer_transitions[215], &symbols[51]},
|
||||||
{77, 1, &lexer_transitions[91], &symbols[51]},
|
{77, 4, &lexer_transitions[217], &symbols[51]},
|
||||||
{78, 1, &lexer_transitions[92], &symbols[51]},
|
{78, 4, &lexer_transitions[221], &symbols[51]},
|
||||||
{79, 1, &lexer_transitions[93], nullptr},
|
{79, 4, &lexer_transitions[225], &symbols[51]},
|
||||||
{80, 1, &lexer_transitions[94], nullptr},
|
{80, 3, &lexer_transitions[229], &symbols[51]},
|
||||||
{81, 1, &lexer_transitions[95], nullptr},
|
{81, 4, &lexer_transitions[232], &symbols[51]},
|
||||||
{82, 1, &lexer_transitions[96], nullptr},
|
{82, 4, &lexer_transitions[236], &symbols[51]},
|
||||||
{83, 1, &lexer_transitions[97], nullptr},
|
{83, 4, &lexer_transitions[240], &symbols[51]},
|
||||||
{84, 0, &lexer_transitions[98], &symbols[52]},
|
{84, 2, &lexer_transitions[244], &symbols[51]},
|
||||||
{85, 4, &lexer_transitions[98], &symbols[53]},
|
{85, 4, &lexer_transitions[246], &symbols[53]},
|
||||||
{86, 1, &lexer_transitions[102], nullptr},
|
{86, 1, &lexer_transitions[250], nullptr},
|
||||||
{87, 3, &lexer_transitions[103], &symbols[54]},
|
{87, 3, &lexer_transitions[251], &symbols[54]},
|
||||||
{88, 3, &lexer_transitions[106], nullptr},
|
{88, 3, &lexer_transitions[254], nullptr},
|
||||||
{89, 1, &lexer_transitions[109], nullptr},
|
{89, 1, &lexer_transitions[257], nullptr},
|
||||||
{90, 1, &lexer_transitions[110], &symbols[54]},
|
{90, 1, &lexer_transitions[258], &symbols[54]},
|
||||||
{91, 0, &lexer_transitions[111], &symbols[55]},
|
{91, 0, &lexer_transitions[259], &symbols[55]},
|
||||||
{92, 1, &lexer_transitions[111], nullptr},
|
{92, 1, &lexer_transitions[259], nullptr},
|
||||||
{-1, 0, nullptr, nullptr}
|
{-1, 0, nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
||||||
const LexerStateMachine lexer_state_machine =
|
const LexerStateMachine lexer_state_machine =
|
||||||
{
|
{
|
||||||
1, // #actions
|
1, // #actions
|
||||||
112, // #transitions
|
260, // #transitions
|
||||||
93, // #states
|
93, // #states
|
||||||
lexer_actions, // actions
|
lexer_actions, // actions
|
||||||
lexer_transitions, // transitions
|
lexer_transitions, // transitions
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ oscript {
|
||||||
| id [expr_id]
|
| id [expr_id]
|
||||||
;
|
;
|
||||||
|
|
||||||
id: "[a-z]";
|
id: "([a-z]|[A-Z])+";
|
||||||
boolean: "true|false";
|
boolean: "true|false";
|
||||||
integer: "(\+|\-)?[0-9]+";
|
integer: "(\+|\-)?[0-9]+";
|
||||||
real: "(\+|\-)?[0-9]+(\.[0-9]+)?((e|E)(\+|\-)?[0-9]+)?";
|
real: "(\+|\-)?[0-9]+(\.[0-9]+)?((e|E)(\+|\-)?[0-9]+)?";
|
||||||
|
|
|
||||||
74
Objects/private/primitives/BytecodeObject.cpp
Normal file
74
Objects/private/primitives/BytecodeObject.cpp
Normal file
|
|
@ -0,0 +1,74 @@
|
||||||
|
|
||||||
|
#include "primitives/BytecodeObject.hpp"
|
||||||
|
|
||||||
|
using namespace tp;
|
||||||
|
using namespace obj;
|
||||||
|
|
||||||
|
void BytecodeObject::constructor(BytecodeObject* self) {
|
||||||
|
new (&self->mBytecode) ByteCode();
|
||||||
|
self->mReadable = objects_api::create<StringObject>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BytecodeObject::copy(BytecodeObject* self, BytecodeObject* in) {
|
||||||
|
// TODO : implement
|
||||||
|
ASSERT(!"can not copy bytecode object")
|
||||||
|
}
|
||||||
|
|
||||||
|
void BytecodeObject::destructor(BytecodeObject* self) {
|
||||||
|
self->mBytecode.~ByteCode();
|
||||||
|
objects_api::destroy(self->mReadable);
|
||||||
|
}
|
||||||
|
|
||||||
|
tp::alni BytecodeObject::save_size(BytecodeObject* self) {
|
||||||
|
alni out = sizeof(alni); // string object
|
||||||
|
out += sizeof(alni); // constants size
|
||||||
|
out += self->mBytecode.mConstants.size() * sizeof(alni); // constant objects
|
||||||
|
out += SaveSizeCounter::calc(self->mBytecode.mInstructions);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BytecodeObject::save(BytecodeObject* self, ArchiverOut& file) {
|
||||||
|
file << (alni) objects_api::save(file, self->mReadable);
|
||||||
|
file << (alni) self->mBytecode.mConstants.size();
|
||||||
|
|
||||||
|
for (auto const_obj : self->mBytecode.mConstants) {
|
||||||
|
file << (alni) objects_api::save(file, const_obj.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
// mInstructions
|
||||||
|
file << self->mBytecode.mInstructions;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BytecodeObject::load(ArchiverIn& file, obj::BytecodeObject* self) {
|
||||||
|
new (&self->mBytecode) ByteCode();
|
||||||
|
|
||||||
|
alni stringObjectAddress;
|
||||||
|
file >> stringObjectAddress;
|
||||||
|
self->mReadable = objects_api::cast<StringObject>(objects_api::load(file, stringObjectAddress));
|
||||||
|
|
||||||
|
alni consts_count;
|
||||||
|
file >> consts_count;
|
||||||
|
|
||||||
|
self->mBytecode.mConstants.reserve(consts_count);
|
||||||
|
|
||||||
|
for (auto const_obj : self->mBytecode.mConstants) {
|
||||||
|
alni consts_addr;
|
||||||
|
file >> consts_addr;
|
||||||
|
const_obj.data() = objects_api::load(file, consts_addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
file >> self->mBytecode.mInstructions;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ObjectType BytecodeObject::TypeData = {
|
||||||
|
.base = nullptr,
|
||||||
|
.constructor = (object_constructor) BytecodeObject::constructor,
|
||||||
|
.destructor = (object_destructor) BytecodeObject::destructor,
|
||||||
|
.copy = (object_copy) BytecodeObject::copy,
|
||||||
|
.size = sizeof(BytecodeObject),
|
||||||
|
.name = "bytecode",
|
||||||
|
.conversions = nullptr,
|
||||||
|
.save_size = (object_save_size) BytecodeObject::save_size,
|
||||||
|
.save = (object_save) BytecodeObject::save,
|
||||||
|
.load = (object_load) BytecodeObject::load,
|
||||||
|
};
|
||||||
|
|
@ -9,8 +9,8 @@ using namespace obj;
|
||||||
void ClassObject::constructor(ClassObject* self) {
|
void ClassObject::constructor(ClassObject* self) {
|
||||||
self->members = objects_api::create<DictObject>();
|
self->members = objects_api::create<DictObject>();
|
||||||
|
|
||||||
self->addMember(NDO_NULL, "__init__");
|
self->addMember(objects_api::getNull(), "__init__");
|
||||||
self->addMember(NDO_NULL, "__del__");
|
self->addMember(objects_api::getNull(), "__del__");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClassObject::copy(ClassObject* self, const ClassObject* blueprint) {
|
void ClassObject::copy(ClassObject* self, const ClassObject* blueprint) {
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ void InterpreterObject::exec(obj::ClassObject* self, tp::InitialierList<Interpre
|
||||||
}
|
}
|
||||||
|
|
||||||
auto method = objects_api::cast<MethodObject>(target);
|
auto method = objects_api::cast<MethodObject>(target);
|
||||||
if (!method || !method->mScript->mBytecode.mInstructions.size()) {
|
if (!method || !method->mBytecodeLink->mBytecode.mInstructions.size()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,7 +61,7 @@ void InterpreterObject::debug() {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto method = objects_api::cast<MethodObject>(target);
|
auto method = objects_api::cast<MethodObject>(target);
|
||||||
if (!method || !method->mScript->mBytecode.mInstructions.size()) {
|
if (!method || !method->mBytecodeLink->mBytecode.mInstructions.size()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,46 +1,53 @@
|
||||||
|
|
||||||
#include "compiler/Functions.hpp"
|
|
||||||
#include "core/ScriptSection.hpp"
|
|
||||||
#include "primitives/MethodObject.hpp"
|
#include "primitives/MethodObject.hpp"
|
||||||
|
#include "compiler/Functions.hpp"
|
||||||
|
|
||||||
using namespace tp;
|
using namespace tp;
|
||||||
using namespace obj;
|
using namespace obj;
|
||||||
|
|
||||||
void MethodObject::constructor(MethodObject* self) {
|
void MethodObject::constructor(MethodObject* self) {
|
||||||
self->mScript = obj::ScriptSection::globalHandle()->createScript();
|
// create empty bytecode
|
||||||
|
self->mBytecodeLink = objects_api::create<BytecodeObject>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MethodObject::copy(MethodObject* self, MethodObject* in) {
|
void MethodObject::copy(MethodObject* self, MethodObject* in) {
|
||||||
obj::ScriptSection::globalHandle()->changeScript(&self->mScript, &in->mScript);
|
objects_api::destroy(self->mBytecodeLink);
|
||||||
|
objects_api::increaseReferenceCount(in->mBytecodeLink);
|
||||||
|
self->mBytecodeLink = in->mBytecodeLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MethodObject::destructor(MethodObject* self) { obj::ScriptSection::globalHandle()->abandonScript(self->mScript); }
|
void MethodObject::destructor(MethodObject* self) {
|
||||||
|
// deference
|
||||||
|
objects_api::destroy(self->mBytecodeLink);
|
||||||
|
}
|
||||||
|
|
||||||
tp::alni MethodObject::save_size(MethodObject* self) {
|
tp::alni MethodObject::save_size(MethodObject* self) {
|
||||||
// script_table_file_address & script string object address
|
// just reference to the bytecode
|
||||||
return sizeof(tp::alni);
|
return sizeof(Object*);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MethodObject::save(MethodObject* self, ArchiverOut& file_self) {
|
void MethodObject::save(MethodObject* self, ArchiverOut& file_self) {
|
||||||
auto script_section = obj::ScriptSection::globalHandle();
|
// save bytecode
|
||||||
// script_table_file_address
|
file_self << objects_api::save(file_self, self->mBytecodeLink);
|
||||||
tp::alni script_table_file_address = script_section->get_script_file_adress(self->mScript);
|
|
||||||
file_self << script_table_file_address;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MethodObject::load(ArchiverIn& file_self, obj::MethodObject* self) {
|
void MethodObject::load(ArchiverIn& file_self, obj::MethodObject* self) {
|
||||||
auto script_section = obj::ScriptSection::globalHandle();
|
alni bytecodeAddress;
|
||||||
// script_table_file_address
|
file_self >> bytecodeAddress;
|
||||||
tp::alni script_table_file_address;
|
auto bytecode = objects_api::load(file_self, bytecodeAddress);
|
||||||
file_self >> script_table_file_address;
|
self->mBytecodeLink = objects_api::cast<BytecodeObject>(bytecode);
|
||||||
self->mScript = script_section->get_scritp_from_file_adress(script_table_file_address);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MethodObject::compile() { Compile(this); }
|
void MethodObject::compile() {
|
||||||
|
// call to compiler
|
||||||
|
Compile(this);
|
||||||
|
}
|
||||||
|
|
||||||
MethodObject* MethodObject::create(const std::string& script) {
|
MethodObject* MethodObject::create(const std::string& script) {
|
||||||
auto out = objects_api::create<MethodObject>();
|
auto out = objects_api::create<MethodObject>();
|
||||||
out->mScript->mReadable->val = script;
|
|
||||||
|
ASSERT(false)
|
||||||
|
|
||||||
out->compile();
|
out->compile();
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,6 @@ namespace tp::obj {
|
||||||
Map<std::string, const ObjectType*> types;
|
Map<std::string, const ObjectType*> types;
|
||||||
TypeGroups type_groups;
|
TypeGroups type_groups;
|
||||||
Interpreter* interp = nullptr;
|
Interpreter* interp = nullptr;
|
||||||
save_load_callbacks* sl_callbacks[SAVE_LOAD_MAX_CALLBACK_SLOTS]{};
|
|
||||||
alni sl_callbacks_load_idx = 0;
|
|
||||||
|
|
||||||
struct NullObject* nullObject = nullptr;
|
struct NullObject* nullObject = nullptr;
|
||||||
|
|
||||||
|
|
@ -67,8 +65,6 @@ namespace tp::obj {
|
||||||
|
|
||||||
static inline void setReferenceCount(Object* in, halni count) { in->references = count; }
|
static inline void setReferenceCount(Object* in, halni count) { in->references = count; }
|
||||||
|
|
||||||
static void add_sl_callbacks(save_load_callbacks*);
|
|
||||||
|
|
||||||
static alni objsize_file(Object* self);
|
static alni objsize_file(Object* self);
|
||||||
static alni objsize_file_recursive(Object* self);
|
static alni objsize_file_recursive(Object* self);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,20 +54,4 @@ namespace tp::obj {
|
||||||
void save_string(ArchiverOut& file, const std::string& string);
|
void save_string(ArchiverOut& file, const std::string& string);
|
||||||
ualni save_string_size(const std::string& string);
|
ualni save_string_size(const std::string& string);
|
||||||
void load_string(ArchiverIn& file, std::string& out);
|
void load_string(ArchiverIn& file, std::string& out);
|
||||||
|
|
||||||
#define SAVE_LOAD_MAX_CALLBACK_SLOTS 100
|
|
||||||
typedef void(pre_save_callback)(void* self, ArchiverOut&);
|
|
||||||
typedef void(pre_load_callback)(void* self, ArchiverIn&);
|
|
||||||
typedef void(post_save_callback)(void* self, ArchiverOut&);
|
|
||||||
typedef void(post_load_callback)(void* self, ArchiverIn&);
|
|
||||||
typedef alni(slcb_size_callback)(void* self, ArchiverOut&);
|
|
||||||
|
|
||||||
struct save_load_callbacks {
|
|
||||||
void* self;
|
|
||||||
pre_save_callback* pre_save;
|
|
||||||
slcb_size_callback* size;
|
|
||||||
pre_load_callback* pre_load;
|
|
||||||
post_save_callback* post_save;
|
|
||||||
post_load_callback* post_load;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "primitives/MethodObject.hpp"
|
|
||||||
#include "List.hpp"
|
|
||||||
|
|
||||||
namespace tp::obj {
|
|
||||||
|
|
||||||
// global singleton API for method object to manage the script
|
|
||||||
struct ScriptSection {
|
|
||||||
|
|
||||||
List<Script*> mScripts;
|
|
||||||
|
|
||||||
Script* createScript();
|
|
||||||
void changeScript(Script** current_script, Script** new_script);
|
|
||||||
void abandonScript(Script* script);
|
|
||||||
|
|
||||||
alni get_script_file_adress(Script* in);
|
|
||||||
Script* get_scritp_from_file_adress(alni file_adress);
|
|
||||||
|
|
||||||
~ScriptSection();
|
|
||||||
|
|
||||||
static void initialize();
|
|
||||||
static void uninitialize();
|
|
||||||
static ScriptSection* globalHandle();
|
|
||||||
|
|
||||||
private:
|
|
||||||
static obj::save_load_callbacks slcb_script_section;
|
|
||||||
|
|
||||||
void delete_script(Script* script);
|
|
||||||
void reference_script(Script* script);
|
|
||||||
|
|
||||||
static void save_script_table_to_file(ScriptSection* self, ArchiverOut& file);
|
|
||||||
static void load_script_table_from_file(ScriptSection* self, ArchiverIn& file);
|
|
||||||
static alni save_script_table_to_file_size(ScriptSection* self, ArchiverOut& file);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
@ -19,6 +19,12 @@ namespace tp::obj {
|
||||||
ualni mInstructionIdx = 0;
|
ualni mInstructionIdx = 0;
|
||||||
ualni mArgumentsLoaded = 0;
|
ualni mArgumentsLoaded = 0;
|
||||||
|
|
||||||
|
void updateRefCount() {
|
||||||
|
for (auto const_obj : mConstants) {
|
||||||
|
objects_api::setReferenceCount(const_obj.data(), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
~ByteCode() {
|
~ByteCode() {
|
||||||
for (auto const_obj : mConstants) {
|
for (auto const_obj : mConstants) {
|
||||||
objects_api::destroy(const_obj.data());
|
objects_api::destroy(const_obj.data());
|
||||||
|
|
|
||||||
23
Objects/public/primitives/BytecodeObject.hpp
Normal file
23
Objects/public/primitives/BytecodeObject.hpp
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "primitives/StringObject.hpp"
|
||||||
|
#include "interpreter/ByteCode.hpp"
|
||||||
|
|
||||||
|
namespace tp::obj {
|
||||||
|
|
||||||
|
struct BytecodeObject : Object {
|
||||||
|
|
||||||
|
static ObjectType TypeData;
|
||||||
|
|
||||||
|
StringObject* mReadable;
|
||||||
|
ByteCode mBytecode;
|
||||||
|
|
||||||
|
static void constructor(BytecodeObject* self);
|
||||||
|
static void copy(BytecodeObject* self, BytecodeObject* in);
|
||||||
|
static void destructor(BytecodeObject* self);
|
||||||
|
|
||||||
|
static alni save_size(BytecodeObject* self);
|
||||||
|
static void save(BytecodeObject* self, ArchiverOut& file_self);
|
||||||
|
static void load(ArchiverIn& file_self, BytecodeObject* self);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "primitives/StringObject.hpp"
|
#include "primitives/BytecodeObject.hpp"
|
||||||
#include "interpreter/Script.hpp"
|
|
||||||
|
|
||||||
namespace tp::obj {
|
namespace tp::obj {
|
||||||
|
|
||||||
|
|
@ -9,7 +8,7 @@ namespace tp::obj {
|
||||||
|
|
||||||
static ObjectType TypeData;
|
static ObjectType TypeData;
|
||||||
|
|
||||||
Script* mScript;
|
BytecodeObject* mBytecodeLink;
|
||||||
|
|
||||||
static void constructor(MethodObject* self);
|
static void constructor(MethodObject* self);
|
||||||
static void copy(MethodObject* self, MethodObject* in);
|
static void copy(MethodObject* self, MethodObject* in);
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,4 @@ namespace tp::obj {
|
||||||
static ObjectType TypeData;
|
static ObjectType TypeData;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NDO_NULL objects_api::getNull()
|
|
||||||
#define NDO_NULL_REF objects_api::getNullReferenced()
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -16,7 +16,7 @@ SUITE(Compiler) {
|
||||||
// no errors
|
// no errors
|
||||||
auto method = objects_api::create<MethodObject>();
|
auto method = objects_api::create<MethodObject>();
|
||||||
|
|
||||||
method->mScript->mReadable->val = "print 1 * 20 + 10;";
|
method->mBytecodeLink->mReadable->val = "print 1 * 20 + 10;";
|
||||||
method->compile();
|
method->compile();
|
||||||
|
|
||||||
objects_api::destroy(method);
|
objects_api::destroy(method);
|
||||||
|
|
@ -28,7 +28,7 @@ SUITE(Compiler) {
|
||||||
// with errors
|
// with errors
|
||||||
auto method = objects_api::create<MethodObject>();
|
auto method = objects_api::create<MethodObject>();
|
||||||
|
|
||||||
method->mScript->mReadable->val = "print undefinedVariable;";
|
method->mBytecodeLink->mReadable->val = "print undefinedVariable;";
|
||||||
method->compile();
|
method->compile();
|
||||||
|
|
||||||
objects_api::destroy(method);
|
objects_api::destroy(method);
|
||||||
|
|
|
||||||
|
|
@ -11,15 +11,15 @@ using namespace tp;
|
||||||
using namespace obj;
|
using namespace obj;
|
||||||
|
|
||||||
auto script1 = R"(
|
auto script1 = R"(
|
||||||
class A {
|
class a {
|
||||||
var string = "hello";
|
var string = "hello";
|
||||||
def log(name) {
|
method log(name) {
|
||||||
<< self.string;
|
<< self.string;
|
||||||
<< name;
|
<< name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def main() {
|
method main() {
|
||||||
var a = new A();
|
var a = new A();
|
||||||
a.log(" user ");
|
a.log(" user ");
|
||||||
}
|
}
|
||||||
|
|
@ -40,7 +40,7 @@ if (i == 10) {
|
||||||
)";
|
)";
|
||||||
|
|
||||||
auto script = R"(
|
auto script = R"(
|
||||||
print false;
|
print 101;
|
||||||
)";
|
)";
|
||||||
|
|
||||||
SUITE(Interpreter) {
|
SUITE(Interpreter) {
|
||||||
|
|
@ -53,7 +53,7 @@ SUITE(Interpreter) {
|
||||||
|
|
||||||
interpreter->getMember<LinkObject>("target method")->setLink(method);
|
interpreter->getMember<LinkObject>("target method")->setLink(method);
|
||||||
|
|
||||||
method->mScript->mReadable->val = script;
|
method->mBytecodeLink->mReadable->val = script;
|
||||||
method->compile();
|
method->compile();
|
||||||
|
|
||||||
interpreter->exec();
|
interpreter->exec();
|
||||||
|
|
@ -75,7 +75,7 @@ SUITE(Interpreter) {
|
||||||
|
|
||||||
interpreter->getMember<LinkObject>("target method")->setLink(method);
|
interpreter->getMember<LinkObject>("target method")->setLink(method);
|
||||||
|
|
||||||
method->mScript->mReadable->val = script;
|
method->mBytecodeLink->mReadable->val = script;
|
||||||
method->compile();
|
method->compile();
|
||||||
|
|
||||||
interpreter->exec();
|
interpreter->exec();
|
||||||
|
|
@ -107,7 +107,7 @@ SUITE(Interpreter) {
|
||||||
interpreter->getMember<LinkObject>("target method")->setLink(method);
|
interpreter->getMember<LinkObject>("target method")->setLink(method);
|
||||||
|
|
||||||
auto exec = [&](const char* script) {
|
auto exec = [&](const char* script) {
|
||||||
method->mScript->mReadable->val = script;
|
method->mBytecodeLink->mReadable->val = script;
|
||||||
method->compile();
|
method->compile();
|
||||||
|
|
||||||
auto startCount = objects_api::getObjCount();
|
auto startCount = objects_api::getObjCount();
|
||||||
|
|
@ -138,7 +138,7 @@ SUITE(Interpreter) {
|
||||||
objTestModule.deinitialize();
|
objTestModule.deinitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Complex) {
|
TEST_OFF(Complex) {
|
||||||
objTestModule.initialize();
|
objTestModule.initialize();
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
@ -147,7 +147,7 @@ SUITE(Interpreter) {
|
||||||
|
|
||||||
interpreter->getMember<LinkObject>("target method")->setLink(method);
|
interpreter->getMember<LinkObject>("target method")->setLink(method);
|
||||||
|
|
||||||
method->mScript->mReadable->val = script1;
|
method->mBytecodeLink->mReadable->val = script1;
|
||||||
method->compile();
|
method->compile();
|
||||||
|
|
||||||
interpreter->exec();
|
interpreter->exec();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue