1
0

引数あり関数を呼べるようにした

This commit is contained in:
otya128
2015-06-13 20:34:19 +09:00
parent c5b2f1af67
commit f1ecd08462
3 changed files with 6 additions and 3 deletions

View File

@@ -710,6 +710,7 @@ class ReturnFunction : Code
Value bp, pc; Value bp, pc;
vm.pop(pc); vm.pop(pc);
vm.pop(bp); vm.pop(bp);
vm.stacki -= func.argCount;
if(func.returnExpr) if(func.returnExpr)
{ {
vm.push(retexpr); vm.push(retexpr);
@@ -739,9 +740,10 @@ class CallFunctionCode : Code
throw new IllegalFunctionCall(); throw new IllegalFunctionCall();
} }
//TODO:args //TODO:args
auto bp = vm.stacki;
vm.push(Value(vm.bp)); vm.push(Value(vm.bp));
vm.push(Value(vm.pc)); vm.push(Value(vm.pc));
vm.bp = vm.stacki - 2; vm.bp = bp;
vm.pc = func.address - 1; vm.pc = func.address - 1;
} }
} }

View File

@@ -71,7 +71,7 @@ class Function
int var = this.variable.get(name, 0); int var = this.variable.get(name, 0);
if(var == 0) if(var == 0)
{ {
this.variable[name] = var = ++variableIndex; this.variable[name] = var = --argumentIndex;
} }
else else
{ {

View File

@@ -60,6 +60,7 @@ V[0,1]=12
?1/2 ?1/2
GOSUB @A GOSUB @A
?A() ?A()
?B(1,2,3)
END END
@A @A
?\"SUBROUTINE TEST\" ?\"SUBROUTINE TEST\"
@@ -70,7 +71,7 @@ DEF A()
END END
DEF B(A,B[],C) DEF B(A,B[],C)
?\"FUNCTION B\" ?\"FUNCTION B\"
RETURN 0 RETURN -1
END END
"); ");
version(none) auto parser = new Parser(readText("FIZZBUZZ.TXT").to!wstring); version(none) auto parser = new Parser(readText("FIZZBUZZ.TXT").to!wstring);