Author: mesyeti <mesyeti@mesyeti.uk>
it's broken
basic-std/std/file.bas | 20 +++++++++--------- basic/source/parser.c | 48 +++++++++++++++++++++++++++++++++---------- vm/source/mem.h | 9 ++++++++ vm/source/vm.c | 3 ++ vm/source/vm.h | 3 -
diff --git a/basic/source/parser.c b/basic/source/parser.c index 2e2135c7576eef6685f888487f4563ffb4028ed8..90d678660bc15237448ec0644d4007995dc5aa4c 100644 --- a/basic/source/parser.c +++ b/basic/source/parser.c @@ -598,6 +598,12 @@ } } else { ret.elseLen = 0; + + printf("Skipping past line\n"); + Expect(p, TOKEN_END); + Advance(p); + Expect(p, TOKEN_LINE); + printf("This token is a %s\n", Lexer_TypeAsString(&p->tokens[p->i])); } Node node; @@ -759,17 +765,29 @@ return node; } static Node ParseNode(Parser* p) { + static int level = 0; + + Token* token = &p->tokens[p->i]; + for (int i = 0; i < level; ++ i) { + printf(" "); + } + printf("Parsing '%s' on line %d\n", Lexer_TypeAsString(token), token->err.line); + + ++ level; + + Node ret; + switch (p->tokens[p->i].type) { case TOKEN_FUNC: - case TOKEN_SUB: return ParseFuncDef(p); - case TOKEN_DIM: return ParseDim(p); - case TOKEN_EXTERN: return ParseExtern(p); - case TOKEN_IF: return ParseIf(p); - case TOKEN_WHILE: return ParseWhile(p); - case TOKEN_TYPE: return ParseTypeDef(p); - case TOKEN_PROGRAM: return ParseProgram(p); - case TOKEN_IMPORT: return ParseImport(p); - case TOKEN_RETURN: return ParseReturn(p); + case TOKEN_SUB: ret = ParseFuncDef(p); break; + case TOKEN_DIM: ret = ParseDim(p); break; + case TOKEN_EXTERN: ret = ParseExtern(p); break; + case TOKEN_IF: ret = ParseIf(p); break; + case TOKEN_WHILE: ret = ParseWhile(p); break; + case TOKEN_TYPE: ret = ParseTypeDef(p); break; + case TOKEN_PROGRAM: ret = ParseProgram(p); break; + case TOKEN_IMPORT: ret = ParseImport(p); break; + case TOKEN_RETURN: ret = ParseReturn(p); break; case TOKEN_LPAREN: case TOKEN_ACCESS_XOR: case TOKEN_IDENTIFIER: { @@ -777,7 +795,7 @@ if (p->i == p->tokenNum - 1) { PrintError(p->tokens[p->i].err, "Unexpected EOF"); } - Node ret = ParseBinary(p); + ret = ParseBinary(p); // this if statement is sickening if ( @@ -790,7 +808,7 @@ ) { PrintError(p->tokens[p->i].err, "Unexpected %s", Parser_TypeStr(ret.i.type)); } - return ret; + break; } default: { PrintError( @@ -800,6 +818,14 @@ ); exit(1); } } + + -- level; + for (int i = 0; i < level; ++ i) { + printf(" "); + } + printf("Finished parsing '%s' on line %d\n", Lexer_TypeAsString(token), token->err.line); + + return ret; } static void PrintDec(FuncDec dec) { diff --git a/basic-std/std/file.bas b/basic-std/std/file.bas index cc31f916f4e4c9f4c10a2ba182ec22cde3cb703d..38a2c0218a9b8f3abdfbca7b3d2a6d23f110fbd4 100644 --- a/basic-std/std/file.bas +++ b/basic-std/std/file.bas @@ -1,11 +1,11 @@ 'NITRON -extern func fopen(path as ptr(char), mode as ptr(char)) ptr(unit) -extern func fclose(file as ptr(unit)) i32 - -type File - file as ptr(unit) -end +'extern func fopen(path as ptr(char), mode as ptr(char)) ptr(unit) +'extern func fclose(file as ptr(unit)) i32 +'' +'type File +'' file as ptr(unit) +'end func File_Open(this as ptr(File), path as ptr(char), write as bool) bool dim file as ptr(unit) @@ -19,10 +19,10 @@ end file = fopen(path, modeStr) - if file != 0 then - return 0 - end + 'if file != 0 then + '' return 0 + 'end 'this.file = file - return 1 + 'return 1 end diff --git a/vm/source/mem.h b/vm/source/mem.h new file mode 100644 index 0000000000000000000000000000000000000000..8bbb703b4f3dfcc48d976c0bb21f61a12321c50e --- /dev/null +++ b/vm/source/mem.h @@ -0,0 +1,9 @@ +#ifndef N_MEM_H +#define N_MEM_H + +typedef struct { + uint8_t* mem; + size_t memSize; +} Memory; + +#endif diff --git a/vm/source/vm.c b/vm/source/vm.c new file mode 100644 index 0000000000000000000000000000000000000000..f5df765ecd4fe33e61e49f1cac58da9aca53ad86 --- /dev/null +++ b/vm/source/vm.c @@ -0,0 +1,3 @@ +#include "vm.h" + +#define INST(NAME) static void Inst_##NAME(VM* vm) diff --git a/vm/source/vm.h b/vm/source/vm.h index 45ffbac7e5350d8d79d20dbdc7b0ecc04e3dc28f..11af517deb9f84f7bb7fc05698735482482e96f3 100644 --- a/vm/source/vm.h +++ b/vm/source/vm.h @@ -42,7 +42,6 @@ VM_INST_RET = 0x24 }; typedef struct { - -} VMState; +} VM; #endif