Changed organisation of TOS. Now its 8-byte stack instead 4-byte before
This commit is contained in:
parent
c70ee283ba
commit
486b73fcea
3 changed files with 39 additions and 18 deletions
|
@ -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;
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -7,7 +7,7 @@ typedef union
|
|||
int num_i[2];
|
||||
} tos_num;
|
||||
|
||||
int* TOS;
|
||||
double* TOS;
|
||||
int tp;
|
||||
int initTOS();
|
||||
void push_int(int);
|
||||
|
|
Loading…
Reference in a new issue