diff --git a/VaninVM/Main.c b/VaninVM/Main.c index 45c985b..1aaf41e 100644 --- a/VaninVM/Main.c +++ b/VaninVM/Main.c @@ -47,87 +47,109 @@ int main(int argc, char** argv) push_int(-1); ip++; break; case DADD: + //DO(DADD, "Add 2 doubles on TOS, push value back.", 1) d1 = pop_double(); d2 = pop_double(); d1 += d2; push_double(d1); ip++; break; case IADD: + //DO(IADD, "Add 2 ints on TOS, push value back.", 1) i1 = pop_int(); i2 = pop_int(); i1 += i2; push_int(i1); ip++; break; case DSUB: + //DO(DSUB, "Subtract 2 doubles on TOS (lower from upper), push value back.", 1) d1 = pop_double(); d2 = pop_double(); d1 -= d2; push_double(d1); ip++; break; case ISUB: + //DO(ISUB, "Subtract 2 ints on TOS (lower from upper), push value back.", 1) i1 = pop_int(); i2 = pop_int(); i1 -= i2; push_int(i1); ip++; break; case DMUL: + //DO(DMUL, "Multiply 2 doubles on TOS, push value back.", 1) d1 = pop_double(); d2 = pop_double(); d1 *= d2; push_double(d1); ip++; break; case IMUL: + //DO(IMUL, "Multiply 2 ints on TOS, push value back.", 1) i1 = pop_int(); i2 = pop_int(); i1 *= i2; push_int(i1); ip++; break; case DDIV: + //DO(DDIV, "Divide 2 doubles on TOS (upper to lower), push value back.", 1) d1 = pop_double(); d2 = pop_double(); d1 /= d2; push_double(d1); ip++; break; case IDIV: + //DO(IDIV, "Divide 2 ints on TOS (upper to lower), push value back.", 1) i1 = pop_int(); i2 = pop_int(); i1 /= i2; push_int(i1); ip++; break; case IMOD: + //DO(IMOD, "Modulo operation on 2 ints on TOS (upper to lower), push value back.", 1) i1 = pop_int(); i2 = pop_int(); i1 %= i2; push_int(i1); ip++; break; case DNEG: + //DO(DNEG, "Negate double on TOS.", 1) d1 = pop_double(); d1 = -d1; push_double(d1); ip++; break; case INEG: + //DO(INEG, "Negate int on TOS.", 1) i1 = pop_int(); i1 = - i1; push_int(i1); ip++; break; case IAOR: + //DO(IAOR, "Arithmetic OR of 2 ints on TOS, push value back.", 1) i1 = pop_int(); i2 = pop_int(); i1 = i1 | i2; push_int(i1); - ip++;break; - case DPRINT: - printf("%f", pop_double()); ip++; break; + case IAAND: + //DO(IAAND, "Arithmetic AND of 2 ints on TOS, push value back.", 1) + ip++; break; + case IAXOR: + //DO(IAXOR, "Arithmetic XOR of 2 ints on TOS, push value back.", 1) case IPRINT: - printf("%d", pop_int()); + //DO(IPRINT, "Pop and print integer TOS.", 1) + i1 = pop_int(); + push_int(i1); + printf("%d", i1); + ip++; break; + case DPRINT: + //DO(DPRINT, "Pop and print double TOS.", 1) + d1 = pop_double(); + push_double(d1); + printf("%f", d1); ip++; break; case STOP: + //DO(STOP, "Stop execution.", 1) exec_status = 0; break; } } - getchar(); return 0; - } \ No newline at end of file diff --git a/VaninVM/TOS.c b/VaninVM/TOS.c index cf38a6f..27f4ab5 100644 --- a/VaninVM/TOS.c +++ b/VaninVM/TOS.c @@ -3,33 +3,32 @@ void push_int(int num) { - TOS[tp++] = num; + tos_num number; + number.num_i[1] = num; + TOS[tp++] = number.num_d; } int pop_int() { - int num = TOS[--tp]; - return num; + tos_num number; + number.num_d = TOS[--tp]; + return number.num_i[1]; } void push_double(double num) { - tos_num cont = { num }; - push_int(cont.num_i[0]); - push_int(cont.num_i[1]); + TOS[tp++] = num; } double pop_double() { - tos_num cont; - cont.num_i[1] = pop_int(); - cont.num_i[0] = pop_int(); - return cont.num_d; + double num = TOS[--tp]; + return num; } int initTOS() { - TOS = (int*)calloc(1, 1500); + TOS = (double*)calloc(1, 12000); tp = 0; return 0; } \ No newline at end of file diff --git a/VaninVM/TOS.h b/VaninVM/TOS.h index 6d48711..b95f1a2 100644 --- a/VaninVM/TOS.h +++ b/VaninVM/TOS.h @@ -7,7 +7,7 @@ typedef union int num_i[2]; } tos_num; -int* TOS; +double* TOS; int tp; int initTOS(); void push_int(int);