Fixing lalr on windows

This commit is contained in:
Ilusha 2024-03-09 12:02:02 +03:00 committed by Ilya Shurupov
parent 69db2b82a4
commit 8cc5f2f9f7
15 changed files with 1276 additions and 1226 deletions

View file

@ -29,6 +29,9 @@ endif()
#add_subdirectory(glew/build/cmake/) #add_subdirectory(glew/build/cmake/)
#target_compile_definitions(glew_s PUBLIC GLEW_NO_GLU) #target_compile_definitions(glew_s PUBLIC GLEW_NO_GLU)
add_subdirectory(lalr)
add_subdirectory(glfw) add_subdirectory(glfw)
project(Imgui) project(Imgui)

2
Externals/lalr vendored

@ -1 +1 @@
Subproject commit ebf41832eb51205afd7aaf3e097d0a6197fefc26 Subproject commit 62a0e9f7ad37de6081a7ede90f7e454c76a38e7b

View file

@ -1,8 +1,6 @@
project(Objects) project(Objects)
### ---------------------- Externals --------------------- ### ### ---------------------- Externals --------------------- ###
set(BINDINGS_INCLUDE ../Externals/lalr/src)
# set(BINDINGS_LIBS )
### ---------------------- Static Library --------------------- ### ### ---------------------- Static Library --------------------- ###
file(GLOB SOURCES "./private/*.cpp" "./private/*/*.cpp") file(GLOB SOURCES "./private/*.cpp" "./private/*/*.cpp")
@ -11,7 +9,8 @@ file(GLOB HEADERS "./public/*.hpp" "./public/*/*.hpp" "./applications/*.hpp")
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS}) add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})
target_include_directories(${PROJECT_NAME} PUBLIC ./public/ ${BINDINGS_INCLUDE}) target_include_directories(${PROJECT_NAME} PUBLIC ./public/ ${BINDINGS_INCLUDE})
target_link_libraries(${PROJECT_NAME} PUBLIC Strings Math Connection) target_link_libraries(${PROJECT_NAME} PUBLIC Strings Math Connection LALR)
target_compile_definitions(${PROJECT_NAME} PUBLIC USERDATA_DESTROY_FAILED_TREE_ROOTS)
### -------------------------- Applications -------------------------- ### ### -------------------------- Applications -------------------------- ###
#add_executable(osc ./applications/Compiler.cpp) #add_executable(osc ./applications/Compiler.cpp)

View file

@ -145,13 +145,11 @@ namespace obj {
return; return;
} }
#ifdef OBJECT_REF_COUNT
ObjectMemHead* mh = NDO_MEMH_FROM_NDO(in); ObjectMemHead* mh = NDO_MEMH_FROM_NDO(in);
if (mh->refc > 1) { if (mh->refc > 1) {
mh->refc--; mh->refc--;
return; return;
} }
#endif
NDO_CASTV(ClassObject, in, classobj); NDO_CASTV(ClassObject, in, classobj);
if (classobj) { if (classobj) {
@ -175,7 +173,6 @@ namespace obj {
ObjectMemDeallocate(in); ObjectMemDeallocate(in);
} }
#ifdef OBJECT_REF_COUNT
tp::halni objects_api::getrefc(Object* in) { tp::halni objects_api::getrefc(Object* in) {
ObjectMemHead* mh = NDO_MEMH_FROM_NDO(in); ObjectMemHead* mh = NDO_MEMH_FROM_NDO(in);
return (tp::halni) mh->refc; return (tp::halni) mh->refc;
@ -190,7 +187,7 @@ namespace obj {
ObjectMemHead* mh = NDO_MEMH_FROM_NDO(in); ObjectMemHead* mh = NDO_MEMH_FROM_NDO(in);
mh->refc = refc; mh->refc = refc;
} }
#endif
void hierarchy_copy(Object* self, const Object* in, const ObjectType* type) { void hierarchy_copy(Object* self, const Object* in, const ObjectType* type) {
if (type->base) { if (type->base) {

View file

@ -11,6 +11,7 @@
namespace obj { namespace obj {
ObjectMemHead* bottom = nullptr; ObjectMemHead* bottom = nullptr;
tp::ualni count = 0;
struct ObjectsFileHeader { struct ObjectsFileHeader {
char name[10] = { 0 }; char name[10] = { 0 };
@ -33,16 +34,17 @@ namespace obj {
memh->down = NULL; memh->down = NULL;
memh->flags = 0; memh->flags = 0;
#ifdef OBJECT_REF_COUNT
memh->refc = (tp::alni) 1; memh->refc = (tp::alni) 1;
#endif
if (bottom) { if (bottom) {
bottom->down = memh; bottom->down = memh;
} }
memh->up = bottom; memh->up = bottom;
bottom = memh; bottom = memh;
count++;
NDO_FROM_MEMH(memh)->type = type; NDO_FROM_MEMH(memh)->type = type;
return NDO_FROM_MEMH(memh); return NDO_FROM_MEMH(memh);
} }
@ -61,6 +63,8 @@ namespace obj {
} }
tp::HeapAllocGlobal::deallocate(memh); tp::HeapAllocGlobal::deallocate(memh);
count--;
} }
void logTypeData(const ObjectType* type) { void logTypeData(const ObjectType* type) {
@ -71,6 +75,8 @@ namespace obj {
} }
} }
tp::ualni getObjCount() { return count; }
void assertNoLeaks() { void assertNoLeaks() {
if (bottom) { if (bottom) {
printf("ERROR : not all objects are destroyed\n"); printf("ERROR : not all objects are destroyed\n");

View file

@ -128,7 +128,7 @@ void Interpreter::stepBytecodeIn() {
case OpCode::IGNORE: case OpCode::IGNORE:
{ {
NDO->destroy(mOperandsStack.getOperand()); mOperandsStack.getOperand();
break; break;
} }

File diff suppressed because it is too large Load diff

View file

@ -9,7 +9,7 @@ oscript {
%left '==' '>' '<' '>=' '<=' '!=' '!'; %left '==' '>' '<' '>=' '<=' '!=' '!';
%left ';'; %left ';';
script : stmts [tmp]; script : stmts [tmp] | ;
scope: scope:
'{' stmts '}' [scope] '{' stmts '}' [scope]

View file

@ -61,10 +61,8 @@ alni LinkObject::allocated_size_recursive(LinkObject* self) {
Object* LinkObject::getLink() { return link; } Object* LinkObject::getLink() { return link; }
void LinkObject::setLink(Object* obj) { void LinkObject::setLink(Object* obj) {
#ifdef OBJECT_REF_COUNT
if (link) NDO->destroy(link); if (link) NDO->destroy(link);
if (obj) NDO->refinc(obj); if (obj) NDO->refinc(obj);
#endif // OBJECT_REF_COUNT
link = obj; link = obj;
} }

View file

@ -84,31 +84,23 @@ alni ListObject::allocated_size_recursive(ListObject* self) {
} }
void ListObject::pushBack(Object* obj) { void ListObject::pushBack(Object* obj) {
#ifdef OBJECT_REF_COUNT
obj::NDO->refinc(obj); obj::NDO->refinc(obj);
#endif // OBJECT_REF_COUNT
items.pushBack(obj); items.pushBack(obj);
} }
void ListObject::pushFront(Object* obj) { void ListObject::pushFront(Object* obj) {
#ifdef OBJECT_REF_COUNT
obj::NDO->refinc(obj); obj::NDO->refinc(obj);
#endif // OBJECT_REF_COUNT
items.pushFront(obj); items.pushFront(obj);
} }
void ListObject::delNode(tp::List<Object*>::Node* node) { void ListObject::delNode(tp::List<Object*>::Node* node) {
#ifdef OBJECT_REF_COUNT
obj::NDO->destroy(node->data); obj::NDO->destroy(node->data);
#endif // OBJECT_REF_COUNT
items.deleteNode(node); items.deleteNode(node);
} }
void ListObject::popBack() { void ListObject::popBack() {
#ifdef OBJECT_REF_COUNT
auto obj = items.last(); auto obj = items.last();
if (obj) obj::NDO->destroy(obj->data); if (obj) obj::NDO->destroy(obj->data);
#endif // OBJECT_REF_COUNT
items.popBack(); items.popBack();
} }

View file

@ -22,7 +22,6 @@ define base type
define struct members define struct members
implement construct, destruct and copy methods */ implement construct, destruct and copy methods */
#define OBJECT_REF_COUNT
#ifdef _DEBUG #ifdef _DEBUG
#define NDO_CAST(cast_type, ptr) ((cast_type*)ndo_cast(ptr, &cast_type::TypeData)) #define NDO_CAST(cast_type, ptr) ((cast_type*)ndo_cast(ptr, &cast_type::TypeData))
@ -93,9 +92,7 @@ namespace obj {
ObjectMemHead* up; ObjectMemHead* up;
ObjectMemHead* down; ObjectMemHead* down;
tp::alni flags; tp::alni flags;
#ifdef OBJECT_REF_COUNT
tp::alni refc; tp::alni refc;
#endif
}; };
struct Object { struct Object {
@ -210,13 +207,11 @@ namespace obj {
void destroy(Object* in); void destroy(Object* in);
#ifdef OBJECT_REF_COUNT
void refinc(Object* in); void refinc(Object* in);
tp::halni getrefc(Object* in); tp::halni getrefc(Object* in);
private: private:
void setrefc(Object* in, tp::halni refc); void setrefc(Object* in, tp::halni refc);
public: public:
#endif
save_load_callbacks* sl_callbacks[SAVE_LOAD_MAX_CALLBACK_SLOTS]; save_load_callbacks* sl_callbacks[SAVE_LOAD_MAX_CALLBACK_SLOTS];
tp::alni sl_callbacks_load_idx = 0; tp::alni sl_callbacks_load_idx = 0;
@ -238,6 +233,7 @@ namespace obj {
void logTypeData(const ObjectType* type); void logTypeData(const ObjectType* type);
void assertNoLeaks(); void assertNoLeaks();
tp::ualni getObjCount();
Object* ndo_cast(const Object* in, const ObjectType* to_type); Object* ndo_cast(const Object* in, const ObjectType* to_type);

View file

@ -23,10 +23,7 @@ namespace obj {
Type* createMember(tp::String id) { Type* createMember(tp::String id) {
auto out = NDO->create(Type::TypeData.name); auto out = NDO->create(Type::TypeData.name);
addMember(out, id); addMember(out, id);
#ifdef OBJECT_REF_COUNT
NDO->destroy(out); NDO->destroy(out);
#endif // OBJECT_REF_COUNT
return (Type*) out; return (Type*) out;
} }

View file

@ -44,7 +44,7 @@ auto script = R"(
print false; print false;
)"; )";
TEST_DEF_STATIC(Simple) { TEST_DEF_STATIC(Entry) {
auto method = NDO_CAST(MethodObject, NDO->create("method")); auto method = NDO_CAST(MethodObject, NDO->create("method"));
auto interpreter = NDO_CAST(InterpreterObject, NDO->create("interpreter")); auto interpreter = NDO_CAST(InterpreterObject, NDO->create("interpreter"));
@ -57,7 +57,7 @@ TEST_DEF_STATIC(Simple) {
NDO->destroy(interpreter); NDO->destroy(interpreter);
printf("\n\nEnd\n\n"); printf("\n");
} }
TEST_DEF_STATIC(SimpleSave) { TEST_DEF_STATIC(SimpleSave) {
@ -80,7 +80,42 @@ TEST_DEF_STATIC(SimpleSave) {
NDO->destroy(interpreterLoaded); NDO->destroy(interpreterLoaded);
NDO->destroy(interpreter); NDO->destroy(interpreter);
printf("\n\nEnd\n\n"); printf("\n");
}
TEST_DEF_STATIC(Simple) {
auto compileStartCount = getObjCount();
auto method = NDO_CAST(MethodObject, NDO->create("method"));
auto interpreter = NDO_CAST(InterpreterObject, NDO->create("interpreter"));
interpreter->getMember<LinkObject>("target method")->setLink(method);
auto exec = [&](const char* script){
method->mScript->mReadable->val = script;
method->compile();
auto startCount = getObjCount();
interpreter->exec();
if (getObjCount() != startCount) {
TEST(false && "Mem leaks in interpreter");
}
printf("\n");
};
exec("10 + 15;");
exec("print 10 + 15;");
exec("print (10 + 15) * 20;");
exec("var k : int;");
exec("var k : int; print k;");
NDO->destroy(interpreter);
if (getObjCount() != compileStartCount) {
TEST(false && "Mem leaks in compiler and interpreter");
}
} }
TEST_DEF_STATIC(Complex) { TEST_DEF_STATIC(Complex) {
@ -98,7 +133,8 @@ TEST_DEF_STATIC(Complex) {
} }
TEST_DEF(Interpreter) { TEST_DEF(Interpreter) {
testSimple(); testEntry();
// testSimple();
testSimpleSave(); testSimpleSave();
// testComplex(); // testComplex();
} }

View file

@ -7,14 +7,38 @@ using namespace tp;
using namespace obj; using namespace obj;
TEST_DEF_STATIC(Basic) { TEST_DEF_STATIC(Basic) {
Parser parser; {
Parser parser;
String stream = "var i = true; print (i + 1) * 10;"; String stream = "";
auto res = parser.parse(stream); auto res = parser.parse(stream);
TEST(!res.isError); TEST(!res.isError);
delete res.scope; delete res.scope;
}
{
Parser parser;
String stream = "var i = true;";
auto res = parser.parse(stream);
TEST(!res.isError);
delete res.scope;
}
{
Parser parser;
String stream = "var i = true; print (i + 1) * 10;";
auto res = parser.parse(stream);
TEST(!res.isError);
delete res.scope;
}
} }
TEST_DEF_STATIC(ErrorHandling) { TEST_DEF_STATIC(ErrorHandling) {

1
STATUS
View file

@ -46,6 +46,7 @@ Objects:
Not feature rich Not feature rich
Not stable Not stable
No tests No tests
Not thread safe
Language: Language:
Not implemented yet Not implemented yet