v0.62: Fixed function call bug in compiled code

- The compiler was not pushing the SENTINEL value to the operator stack and popping it afterwards, so the expression parsing was getting messed up.  Now fixed.
- Also added targets to the Makefile to allow the emulators to be run directly (make xvic, make x64, make mame).
This commit is contained in:
Bobbi Webber-Manners 2018-05-04 00:02:16 -04:00 committed by GitHub
parent 7cdaccab52
commit d9532c8f71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 34 additions and 13 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -112,3 +112,11 @@ test.dsk: eightball.system ebvm.system sieve4.8b
java -jar $(APPLECMDR) -p test.dsk ebvm.system sys <ebvm.system
java -jar $(APPLECMDR) -p test.dsk sieve4.8b txt <sieve4.8b
xvic: test.d64
xvic -mem all -drive8type 1541 -8 test.d64
x64: test.d64
x64 -8 test.d64
mame: test.dsk
mame -w apple2ee -sl6 diskii -floppydisk1 test.dsk

Binary file not shown.

BIN
eightball

Binary file not shown.

View File

@ -952,7 +952,7 @@ unsigned char E()
*/
unsigned char subscript(int *idx)
{
/* Start a new subexpression */
/* Start a new subexpression */
push_operator_stack(SENTINEL);
if (expect('[')) {
@ -1078,9 +1078,11 @@ unsigned char P()
}
if (compile) {
push_operator_stack(SENTINEL);
if (docall()) {
return 1;
}
pop_operator_stack();
goto skip_var; // MESSY!!
} else {
@ -2931,6 +2933,7 @@ unsigned char doendfor()
emit(VM_GTE);
emitldi(return_stack[returnSP + 3]);
emit(VM_BRNCH);
emit(VM_DROP);
goto unwind;
}

Binary file not shown.

View File

@ -37,7 +37,7 @@
/* */
/**************************************************************************/
#define VERSIONSTR "0.61"
#define VERSIONSTR "0.62"
void print(char *str);

Binary file not shown.

View File

@ -209,7 +209,7 @@ void execute_instruction()
unsigned int delay;
#endif
// print("--->PC "); printhex(pc); print(" eval stk: "); printhex(evalptr); print("\n");
//print("--->PC "); printhex(pc); print(" eval stk: "); printhex(evalptr); print("\n");
#ifdef DEBUGREGS
unsigned int i;
print("\n");
@ -279,10 +279,14 @@ void execute_instruction()
* Miscellaneous
*/
case VM_END: /* Terminate execution */
if (evalptr > 0) {
print("WARNING: evalptr ");
printdec(evalptr);
printchar('\n');
}
#ifdef __GNUC__
exit(0);
#else
/* Spin forever */
for (delay = 0; delay < 25000; ++delay);
exit(0);
#endif

View File

@ -10,8 +10,8 @@ sub fact(word val)
if val == 0
return 1
else
' return val * fact(val-1) ; ' THIS DOES NOT WORK
return fact(val-1) * val ; ' BUT THIS DOES!!!
return val * fact(val-1) ; ' THIS DOES NOT WORK
' return fact(val-1) * val ; ' BUT THIS DOES!!!
endif
endsub

BIN
test.d64

Binary file not shown.

BIN
test.dsk

Binary file not shown.

View File

@ -251,6 +251,8 @@ call expect(iw==45)
call pbrfirstlevel(AA)
call expect(AA[3]==123)
call wrapper()
'------------------
' Invoke func
'------------------
@ -258,13 +260,11 @@ pr.msg "Invoke func:"; pr.nl
call expect(sqr(10)==100)
pr.msg " Recursive:"; pr.nl
iw=recurse2(4)
call expect(iw==24)
iw=recurse2(5)
call expect(iw==5*4*3*2)
' TODO: This is failing in the compiler where it returns 1
' But it is okay in interpreter where it returns 24 as it should.
iw=recurse3(4)
call expect(iw==24)
iw=recurse3(5)
call expect(iw==5*4*3*2)
'------------------
' Locals
@ -431,6 +431,12 @@ sub pbrsecondlevel(word XX[])
endfor
endsub
sub wrapper()
word xyz[10]=0
call pbrfirstlevel(xyz)
call expect(xyz[3]==123)
endsub
sub recurse2(word x)
if x==0
return 1;
@ -445,7 +451,7 @@ sub recurse3(word x)
if x==0
return 1;
else
return x*recurse2(x-1)
return x*recurse3(x-1)
endif
endsub