|
@@ -3,52 +3,6 @@
|
|
|
|
|
|
|
|
#include "Code.h"
|
|
#include "Code.h"
|
|
|
#include "Compiler.h"
|
|
#include "Compiler.h"
|
|
|
-#include "Values.h"
|
|
|
|
|
-
|
|
|
|
|
-#define POP_VALUE(name) \
|
|
|
|
|
- Value name; \
|
|
|
|
|
- if(popValue(&name)) \
|
|
|
|
|
- return true
|
|
|
|
|
-
|
|
|
|
|
-static bool iAdd() {
|
|
|
|
|
- POP_VALUE(a);
|
|
|
|
|
- POP_VALUE(b);
|
|
|
|
|
- return pushValue(INT_VALUE(a.intValue + b.intValue));
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-static bool iPushConstantString() {
|
|
|
|
|
- return pushValue(CSTRING_VALUE(codeReadConstantString()));
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-static bool iPushInt() {
|
|
|
|
|
- return pushValue(INT_VALUE(codeReadI64()));
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-static bool iPrint() {
|
|
|
|
|
- POP_VALUE(a);
|
|
|
|
|
- switch(a.type) {
|
|
|
|
|
- case INT64: printf("%ld", a.intValue); break;
|
|
|
|
|
- case CONSTANT_STRING: printf("%s", a.constantStringValue); break;
|
|
|
|
|
- }
|
|
|
|
|
- return false;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-static bool iPrintNewline() {
|
|
|
|
|
- putchar('\n');
|
|
|
|
|
- return false;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-static bool execute(Instruction command) {
|
|
|
|
|
- switch(command) {
|
|
|
|
|
- case ADD: return iAdd();
|
|
|
|
|
- case PUSH_CONSTANT_STRING: return iPushConstantString();
|
|
|
|
|
- case PUSH_INT64: return iPushInt();
|
|
|
|
|
- case PRINT: return iPrint();
|
|
|
|
|
- case PRINT_NEWLINE: return iPrintNewline();
|
|
|
|
|
- case STOP: return true;
|
|
|
|
|
- }
|
|
|
|
|
- return false;
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
int main(int argCount, const char** args) {
|
|
int main(int argCount, const char** args) {
|
|
|
if(argCount < 2) {
|
|
if(argCount < 2) {
|
|
@@ -59,37 +13,7 @@ int main(int argCount, const char** args) {
|
|
|
puts(e->text);
|
|
puts(e->text);
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
- // if(strcmp(args[1], "./test/Print.basic") == 0) {
|
|
|
|
|
- // (void)pushInstruction(PUSH_CONSTANT_STRING);
|
|
|
|
|
- // (void)pushConstantString("Hi");
|
|
|
|
|
- // (void)pushInstruction(PRINT);
|
|
|
|
|
- // (void)pushInstruction(PRINT_NEWLINE);
|
|
|
|
|
-
|
|
|
|
|
- // (void)pushInstruction(PUSH_INT);
|
|
|
|
|
- // (void)pushI64(6);
|
|
|
|
|
- // (void)pushInstruction(PRINT);
|
|
|
|
|
- // (void)pushInstruction(PRINT_NEWLINE);
|
|
|
|
|
-
|
|
|
|
|
- // (void)pushInstruction(PUSH_CONSTANT_STRING);
|
|
|
|
|
- // (void)pushConstantString("Hi there ");
|
|
|
|
|
- // (void)pushInstruction(PRINT);
|
|
|
|
|
- // (void)pushInstruction(PUSH_INT);
|
|
|
|
|
- // (void)pushI64(8);
|
|
|
|
|
- // (void)pushInstruction(PRINT);
|
|
|
|
|
- // (void)pushInstruction(PUSH_CONSTANT_STRING);
|
|
|
|
|
- // (void)pushConstantString(" great");
|
|
|
|
|
- // (void)pushInstruction(PRINT);
|
|
|
|
|
- // (void)pushInstruction(PRINT_NEWLINE);
|
|
|
|
|
- //} else if(strcmp(args[1], "./test/Add.basic") == 0) {
|
|
|
|
|
- // (void)pushInstruction(PUSH_INT);
|
|
|
|
|
- // (void)pushI64(1);
|
|
|
|
|
- // (void)pushInstruction(PUSH_INT);
|
|
|
|
|
- // (void)pushI64(20);
|
|
|
|
|
- // (void)pushInstruction(ADD);
|
|
|
|
|
- // (void)pushInstruction(PRINT);
|
|
|
|
|
- // (void)pushInstruction(PRINT_NEWLINE);
|
|
|
|
|
- //}
|
|
|
|
|
- while(!execute(codeReadInstruction())) {}
|
|
|
|
|
|
|
+ codeRun();
|
|
|
// char line[256];
|
|
// char line[256];
|
|
|
// while(true) {
|
|
// while(true) {
|
|
|
// fgets(line, sizeof(line), stdin);
|
|
// fgets(line, sizeof(line), stdin);
|