Moved VARIABLE_TYPE to vartype.h. VARIABLE_TYPE functions.

The functions in ubasic.c that used int for variable values and
the function expr() in tokenizer.c now use VARIABLE_TYPE.

Also added a new test in tests.c.
This commit is contained in:
Danyil Bohdan 2013-12-21 23:55:48 +02:00
parent a519c98e6c
commit ea7a52e61f
7 changed files with 83 additions and 30 deletions

25
tests.c
View file

@ -38,16 +38,25 @@ static const char program_loop[] =
"10 for i = 0 to 126\n\
20 for j = 0 to 126\n\
30 for k = 0 to 10\n\
37 let a = i * j * k\n\
40 next k\n\
50 next j\n\
60 next i\n\
70 end\n";
40 let a = i * j * k\n\
50 next k\n\
60 next j\n\
70 next i\n\
80 end\n";
static const char program_let[] =
"10 let a = 42\n\
20 end\n";
static const char program_fibs[] =
"20 let a = 1\n\
40 let b = 1\n\
60 for i = 0 to 8\n\
80 let b = a + b\n\
100 let a = b - a\n\
140 next i\n\
160 end\n";
/*---------------------------------------------------------------------------*/
void run(const char program[]) {
@ -70,7 +79,7 @@ void run(const char program[]) {
end_t = clock();
delta_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;
printf("done. Run time: %.3f\n", delta_t);
printf("done. Run time: %.3f s\n", delta_t);
}
/*---------------------------------------------------------------------------*/
@ -79,9 +88,13 @@ main(void)
{
run(program_let);
assert(ubasic_get_variable(0) == 42);
run(program_loop);
assert(ubasic_get_variable(0) == (VARIABLE_TYPE)(126 * 126 * 10));
run(program_fibs);
assert(ubasic_get_variable(1) == 89);
return 0;
}
/*---------------------------------------------------------------------------*/