|
@@ -27,18 +27,24 @@ static bool iPushInt() {
|
|
|
static bool iPrint() {
|
|
static bool iPrint() {
|
|
|
POP_VALUE(a);
|
|
POP_VALUE(a);
|
|
|
switch(a.type) {
|
|
switch(a.type) {
|
|
|
- case INT64: printf("%ld\n", a.intValue); break;
|
|
|
|
|
- case CONSTANT_STRING: printf("%s\n", a.constantStringValue); break;
|
|
|
|
|
|
|
+ case INT64: printf("%ld", a.intValue); break;
|
|
|
|
|
+ case CONSTANT_STRING: printf("%s", a.constantStringValue); break;
|
|
|
}
|
|
}
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+static bool iPrintNewline() {
|
|
|
|
|
+ putchar('\n');
|
|
|
|
|
+ return false;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
static bool execute(Instruction command) {
|
|
static bool execute(Instruction command) {
|
|
|
switch(command) {
|
|
switch(command) {
|
|
|
case ADD: return iAdd();
|
|
case ADD: return iAdd();
|
|
|
case PUSH_CONSTANT_STRING: return iPushConstantString();
|
|
case PUSH_CONSTANT_STRING: return iPushConstantString();
|
|
|
case PUSH_INT: return iPushInt();
|
|
case PUSH_INT: return iPushInt();
|
|
|
case PRINT: return iPrint();
|
|
case PRINT: return iPrint();
|
|
|
|
|
+ case PRINT_NEWLINE: return iPrintNewline();
|
|
|
case STOP: return true;
|
|
case STOP: return true;
|
|
|
}
|
|
}
|
|
|
return false;
|
|
return false;
|
|
@@ -48,25 +54,36 @@ int main(int argCount, const char** args) {
|
|
|
if(argCount < 2) {
|
|
if(argCount < 2) {
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
- if(argCount >= 2 && strcmp(args[1], "help") == 0) {
|
|
|
|
|
- return 0;
|
|
|
|
|
- }
|
|
|
|
|
- printf("RUNNING TEST %s\n", args[1]);
|
|
|
|
|
- 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(16);
|
|
|
|
|
- (void)pushInstruction(PUSH_INT);
|
|
|
|
|
- (void)pushI64(50);
|
|
|
|
|
- (void)pushInstruction(ADD);
|
|
|
|
|
- (void)pushInstruction(PUSH_INT);
|
|
|
|
|
- (void)pushI64(40);
|
|
|
|
|
- (void)pushInstruction(ADD);
|
|
|
|
|
- (void)pushInstruction(PRINT);
|
|
|
|
|
- (void)pushInstruction(PUSH_CONSTANT_STRING);
|
|
|
|
|
- (void)pushConstantString("Das ist ein Test");
|
|
|
|
|
- (void)pushInstruction(PRINT);
|
|
|
|
|
|
|
+ (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(readInstruction())) {}
|
|
while(!execute(readInstruction())) {}
|
|
|
// char line[256];
|
|
// char line[256];
|
|
|
// while(true) {
|
|
// while(true) {
|