From 48013992736d6a0cb13ee63f5948808eed4ea7ae Mon Sep 17 00:00:00 2001 From: Augusto Gunsch Date: Wed, 6 Jan 2021 10:47:54 -0300 Subject: [PATCH] Remove OS for now (causing assembly bug) --- compiler/compiler-scopes.c | 13 +-- compiler/compiler.c | 4 - compiler/compiler.h | 1 - main.c | 1 - misc/os.c | 166 ------------------------------------- misc/os.h | 10 --- 6 files changed, 4 insertions(+), 191 deletions(-) delete mode 100644 misc/os.c delete mode 100644 misc/os.h diff --git a/compiler/compiler-scopes.c b/compiler/compiler-scopes.c index 6f22673..2af5eec 100644 --- a/compiler/compiler-scopes.c +++ b/compiler/compiler-scopes.c @@ -4,7 +4,6 @@ #include #include "compiler.h" #include "compiler-scopes.h" -#include "os.h" typedef enum { local, staticseg, arg, fieldseg } MEMSEGMENT; char* memsegnames[] = { "local", "static", "argument", "this" }; @@ -115,7 +114,7 @@ CLASS* getclass(SCOPE* s, const char* name) { } if(s->previous != NULL) return getclass(s->previous, name); - return getosclass(s->compiler->os, name); + return NULL; } SUBROUTDEC* getsubroutdecfromlist(SUBROUTDEC* start, char* name) { @@ -175,14 +174,10 @@ SUBROUTDEC* getsubroutdecwithoutparent(SCOPE* s, SUBROUTCALL* call) { SUBROUTDEC* getsubroutdecfromcall(SCOPE* s, SUBROUTCALL* call, VAR** varret) { SUBROUTDEC* d; *varret = NULL; - if(call->parentname != NULL) { - d = getossubroutdec(s->compiler->os, call); - if(d == NULL) - d = getsubroutdecwithparent(s, call, varret); - } - else { + if(call->parentname != NULL) + d = getsubroutdecwithparent(s, call, varret); + else d = getsubroutdecwithoutparent(s, call); - } if(d == NULL) notdeclared(call->name, call->debug); return d; diff --git a/compiler/compiler.c b/compiler/compiler.c index e8e97d7..927beb5 100644 --- a/compiler/compiler.c +++ b/compiler/compiler.c @@ -1,5 +1,4 @@ #include -#include "os.h" #include "compiler-structure.h" #include "compiler.h" @@ -28,7 +27,6 @@ COMPILER* mkcompiler(CLASS* classes) { c->globalscope->compiler = c; c->globalscope->classes = classes; c->classes = classes; - c->os = mkos(); pthread_mutex_init(&(c->ifmutex), NULL); pthread_mutex_init(&(c->whilemutex), NULL); pthread_mutex_init(&(c->staticmutex), NULL); @@ -39,8 +37,6 @@ void freecompiler(COMPILER* c) { pthread_mutex_destroy(&(c->ifmutex)); pthread_mutex_destroy(&(c->whilemutex)); pthread_mutex_destroy(&(c->staticmutex)); - // to be continued - freeos(c->os); freescope(c->globalscope); free(c); } diff --git a/compiler/compiler.h b/compiler/compiler.h index 3009896..1ecc1e0 100644 --- a/compiler/compiler.h +++ b/compiler/compiler.h @@ -15,7 +15,6 @@ typedef struct compiler { pthread_mutex_t whilemutex; pthread_mutex_t staticmutex; CLASS* classes; - CLASS* os; struct scope* globalscope; } COMPILER; diff --git a/main.c b/main.c index 7ea9edf..52d4eb9 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,6 @@ #include "parser.h" #include "compiler.h" #include "io.h" -#include "os.h" #include "assembler.h" int main(int argc, char* argv[]) { diff --git a/misc/os.c b/misc/os.c deleted file mode 100644 index a91a6d5..0000000 --- a/misc/os.c +++ /dev/null @@ -1,166 +0,0 @@ -#include -#include -#include "os.h" -#include "util.h" - -CLASS* mkosclass(CLASS* os, const char* name) { - CLASS* c = (CLASS*)malloc(sizeof(CLASS)); - c->name = ezheapstr(name); - c->subroutdecs = NULL; - c->next = os; - return c; -} - -void adddec(CLASS* c, SUBROUTCLASS subroutclass, char* type, const char* name) { - SUBROUTDEC* dec = (SUBROUTDEC*)malloc(sizeof(SUBROUTDEC)); - dec->class = c; - dec->subroutclass = subroutclass; - dec->name = ezheapstr(name); - dec->type = ezheapstr(type); - dec->next = c->subroutdecs; - c->subroutdecs = dec; -} - -CLASS* mkmath(CLASS* os) { - CLASS* mathclass = mkosclass(os, "Math"); - adddec(mathclass, function, "int", "multiply"); - adddec(mathclass, function, "int", "divide"); - adddec(mathclass, function, "int", "abs"); - adddec(mathclass, function, "int", "min"); - adddec(mathclass, function, "int", "max"); - adddec(mathclass, function, "int", "sqrt"); - return mathclass; -} - -CLASS* mkstringclass(CLASS* os) { - CLASS* strclass = mkosclass(os, "String"); - adddec(strclass, constructor, "String", "new"); - adddec(strclass, method, "int", "dispose"); - adddec(strclass, method, "int", "length"); - adddec(strclass, method, "char", "charAt"); - adddec(strclass, method, "void", "setCharAt"); - adddec(strclass, method, "String", "appendChar"); - adddec(strclass, method, "void", "eraseLastChar"); - adddec(strclass, method, "int", "intValue"); - adddec(strclass, method, "void", "setInt"); - adddec(strclass, function, "char", "backSpace"); - adddec(strclass, function, "char", "doubleQuote"); - adddec(strclass, function, "char", "newLine"); - return strclass; -} - -CLASS* mkarray(CLASS* os) { - CLASS* arrclass = mkosclass(os, "Array"); - adddec(arrclass, function, "Array", "new"); - adddec(arrclass, method, "void", "dispose"); - return arrclass; -} - -CLASS* mkoutput(CLASS* os) { - CLASS* outclass = mkosclass(os, "Output"); - adddec(outclass, function, "void", "moveCursor"); - adddec(outclass, function, "void", "printChar"); - adddec(outclass, function, "void", "printString"); - adddec(outclass, function, "void", "printInt"); - adddec(outclass, function, "void", "println"); - adddec(outclass, function, "void", "backSpace"); - return outclass; -} - -CLASS* mkscreen(CLASS* os) { - CLASS* scrclass = mkosclass(os, "Screen"); - adddec(scrclass, function, "void", "clearScreen"); - adddec(scrclass, function, "void", "setColor"); - adddec(scrclass, function, "void", "drawPixel"); - adddec(scrclass, function, "void", "drawLine"); - adddec(scrclass, function, "void", "drawRectangle"); - adddec(scrclass, function, "void", "drawCircle"); - return scrclass; -} - -CLASS* mkkeyboard(CLASS* os) { - CLASS* kbdclass = mkosclass(os, "Keyboard"); - adddec(kbdclass, function, "char", "keyPressed"); - adddec(kbdclass, function, "char", "readChar"); - adddec(kbdclass, function, "String", "readLine"); - adddec(kbdclass, function, "int", "readInt"); - return kbdclass; -} - -CLASS* mkmemory(CLASS* os) { - CLASS* memclass = mkosclass(os, "Memory"); - adddec(memclass, function, "int", "peek"); - adddec(memclass, function, "void", "poke"); - adddec(memclass, function, "Array", "alloc"); - adddec(memclass, function, "void", "deAlloc"); - return memclass; -} - -CLASS* mksys(CLASS* os) { - CLASS* sysclass = mkosclass(os, "Sys"); - adddec(sysclass, function, "void", "halt"); - adddec(sysclass, function, "void", "error"); - adddec(sysclass, function, "void", "wait"); - return sysclass; -} - -CLASS* mkos() { - CLASS* os = mkmath(NULL); - os = mkstringclass(os); - os = mkarray(os); - os = mkoutput(os); - os = mkscreen(os); - os = mkkeyboard(os); - os = mkmemory(os); - os = mksys(os); - return os; -} - -void freeossubroutdecs(SUBROUTDEC* d) { - free(d->name); - free(d->type); - SUBROUTDEC* next = d->next; - free(d); - if(next != NULL) - freeossubroutdecs(next); -} - -void freeosclasses(CLASS* c) { - freeossubroutdecs(c->subroutdecs); - free(c->name); - CLASS* next = c->next; - free(c); - if(next != NULL) - freeosclasses(next); -} - -void freeos(CLASS* os) { - freeosclasses(os); -} - -SUBROUTDEC* getsubroutdecinclass(CLASS* c, const char* name) { - SUBROUTDEC* curr = c->subroutdecs; - while(curr != NULL) { - if(!strcmp(curr->name, name)) - return curr; - curr = curr->next; - } - return NULL; -} - -CLASS* getosclass(CLASS* os, const char* name) { - CLASS* curr = os; - while(curr != NULL) { - if(!strcmp(curr->name, name)) - return curr; - curr = curr->next; - } - return NULL; -} - -SUBROUTDEC* getossubroutdec(CLASS* os, SUBROUTCALL* call) { - CLASS* c = getosclass(os, call->parentname); - if(c == NULL) - return NULL; - return getsubroutdecinclass(c, call->name); -} diff --git a/misc/os.h b/misc/os.h deleted file mode 100644 index 6ca468b..0000000 --- a/misc/os.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_H -#define OS_H -#include "parser-tree.h" - -SUBROUTDEC* getossubroutdec(CLASS* os, SUBROUTCALL* call); -CLASS* getosclass(CLASS* os, const char* name); -CLASS* mkos(); -void freeos(CLASS* os); - -#endif