Remove OS for now (causing assembly bug)

This commit is contained in:
Augusto Gunsch 2021-01-06 10:47:54 -03:00
parent 5429edd444
commit 4801399273
No known key found for this signature in database
GPG Key ID: F7EEFE29825C72DC
6 changed files with 4 additions and 191 deletions

View File

@ -4,7 +4,6 @@
#include <pthread.h> #include <pthread.h>
#include "compiler.h" #include "compiler.h"
#include "compiler-scopes.h" #include "compiler-scopes.h"
#include "os.h"
typedef enum { local, staticseg, arg, fieldseg } MEMSEGMENT; typedef enum { local, staticseg, arg, fieldseg } MEMSEGMENT;
char* memsegnames[] = { "local", "static", "argument", "this" }; char* memsegnames[] = { "local", "static", "argument", "this" };
@ -115,7 +114,7 @@ CLASS* getclass(SCOPE* s, const char* name) {
} }
if(s->previous != NULL) if(s->previous != NULL)
return getclass(s->previous, name); return getclass(s->previous, name);
return getosclass(s->compiler->os, name); return NULL;
} }
SUBROUTDEC* getsubroutdecfromlist(SUBROUTDEC* start, char* name) { 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* getsubroutdecfromcall(SCOPE* s, SUBROUTCALL* call, VAR** varret) {
SUBROUTDEC* d; SUBROUTDEC* d;
*varret = NULL; *varret = NULL;
if(call->parentname != NULL) { if(call->parentname != NULL)
d = getossubroutdec(s->compiler->os, call);
if(d == NULL)
d = getsubroutdecwithparent(s, call, varret); d = getsubroutdecwithparent(s, call, varret);
} else
else {
d = getsubroutdecwithoutparent(s, call); d = getsubroutdecwithoutparent(s, call);
}
if(d == NULL) if(d == NULL)
notdeclared(call->name, call->debug); notdeclared(call->name, call->debug);
return d; return d;

View File

@ -1,5 +1,4 @@
#include <stdlib.h> #include <stdlib.h>
#include "os.h"
#include "compiler-structure.h" #include "compiler-structure.h"
#include "compiler.h" #include "compiler.h"
@ -28,7 +27,6 @@ COMPILER* mkcompiler(CLASS* classes) {
c->globalscope->compiler = c; c->globalscope->compiler = c;
c->globalscope->classes = classes; c->globalscope->classes = classes;
c->classes = classes; c->classes = classes;
c->os = mkos();
pthread_mutex_init(&(c->ifmutex), NULL); pthread_mutex_init(&(c->ifmutex), NULL);
pthread_mutex_init(&(c->whilemutex), NULL); pthread_mutex_init(&(c->whilemutex), NULL);
pthread_mutex_init(&(c->staticmutex), NULL); pthread_mutex_init(&(c->staticmutex), NULL);
@ -39,8 +37,6 @@ void freecompiler(COMPILER* c) {
pthread_mutex_destroy(&(c->ifmutex)); pthread_mutex_destroy(&(c->ifmutex));
pthread_mutex_destroy(&(c->whilemutex)); pthread_mutex_destroy(&(c->whilemutex));
pthread_mutex_destroy(&(c->staticmutex)); pthread_mutex_destroy(&(c->staticmutex));
// to be continued
freeos(c->os);
freescope(c->globalscope); freescope(c->globalscope);
free(c); free(c);
} }

View File

@ -15,7 +15,6 @@ typedef struct compiler {
pthread_mutex_t whilemutex; pthread_mutex_t whilemutex;
pthread_mutex_t staticmutex; pthread_mutex_t staticmutex;
CLASS* classes; CLASS* classes;
CLASS* os;
struct scope* globalscope; struct scope* globalscope;
} COMPILER; } COMPILER;

1
main.c
View File

@ -6,7 +6,6 @@
#include "parser.h" #include "parser.h"
#include "compiler.h" #include "compiler.h"
#include "io.h" #include "io.h"
#include "os.h"
#include "assembler.h" #include "assembler.h"
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {

166
misc/os.c
View File

@ -1,166 +0,0 @@
#include <stdlib.h>
#include <string.h>
#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);
}

View File

@ -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