diff --git a/SMILEBASIC/VM.d b/SMILEBASIC/VM.d index ecef73e..9309360 100644 --- a/SMILEBASIC/VM.d +++ b/SMILEBASIC/VM.d @@ -867,8 +867,8 @@ class CallBuiltinFunction : Code } override void execute(VM vm) { - Value[] arg = vm.stack[vm.stacki - argcount..vm.stacki - 1]; - Value[] result = vm.stack[vm.stacki - argcount..vm.stacki - argcount + outcount - 1];//雑; + Value[] arg = vm.stack[vm.stacki - argcount..vm.stacki]; + Value[] result = vm.stack[vm.stacki - argcount..vm.stacki - argcount + outcount];//雑; func.func(vm.petitcomputer, arg, result); } } diff --git a/SMILEBASIC/builtinfunctions.d b/SMILEBASIC/builtinfunctions.d index 84d7ab5..b197acf 100644 --- a/SMILEBASIC/builtinfunctions.d +++ b/SMILEBASIC/builtinfunctions.d @@ -50,11 +50,12 @@ class BuiltinFunction } import std.math; /* - static pure double ABS(double a, double b) + static pure double ABS(double a) { return a < 0 ? -a : a; }*/ - static ABS = function(double x) => abs(x); + static double function(double) ABS = &abs!double; + //static ABS = function double(double x) => abs(this.result == ValueType.Double ? 1 : 0); static void LOCATE(PetitComputer p, DefaultValue!int x, DefaultValue!int y, DefaultValue!int z) { } diff --git a/SMILEBASIC/compiler.d b/SMILEBASIC/compiler.d index b23773e..f730e85 100644 --- a/SMILEBASIC/compiler.d +++ b/SMILEBASIC/compiler.d @@ -335,7 +335,15 @@ class Compiler { compileExpression(i, sc); } - genCode(new CallFunctionCode(func.name, func.args.length)); + auto bfun = otya.smilebasic.builtinfunctions.BuiltinFunction.builtinFunctions.get(func.name, null); + if(bfun) + { + genCode(new CallBuiltinFunction(bfun, func.args.length, 1)); + } + else + { + genCode(new CallFunctionCode(func.name, func.args.length)); + } } break; case NodeType.IndexExpressions://[expr,expr,expr,expr]用 @@ -598,7 +606,15 @@ class Compiler { compileExpression(j, s); } - genCode(new CallFunctionCode(func.name, func.args.length, func.outVariable.length)); + auto bfun = otya.smilebasic.builtinfunctions.BuiltinFunction.builtinFunctions.get(func.name, null); + if(bfun) + { + genCode(new CallBuiltinFunction(bfun, func.args.length, func.outVariable.length)); + } + else + { + genCode(new CallFunctionCode(func.name, func.args.length, func.outVariable.length)); + } //TODO:OUT foreach_reverse(wstring var; func.outVariable) { diff --git a/SMILEBASIC/main.d b/SMILEBASIC/main.d index 9372fab..fe7c265 100644 --- a/SMILEBASIC/main.d +++ b/SMILEBASIC/main.d @@ -13,7 +13,8 @@ int main(string[] argv) writeln(parser.calc()); } - + version(none) + { auto parser = new Parser( //"@A\nA=1+2+3+4\nPRINT 1+1,2+3;10-5,A:A=A*2 PRINT A " @@ -120,6 +121,7 @@ END { writeln(t); } + } try { auto pc = new PetitComputer(); diff --git a/SMILEBASIC/petitcomputer.d b/SMILEBASIC/petitcomputer.d index 1c51b4d..674e44a 100644 --- a/SMILEBASIC/petitcomputer.d +++ b/SMILEBASIC/petitcomputer.d @@ -178,7 +178,7 @@ class PetitComputer GRPF.createTexture(renderer); //とりあえず auto parser = new Parser(/*readText("FIZZBUZZ.TXT").to!wstring*/" - +?ABS(-1) FOR I=0 TO 10 ?I;\"!\",\"=\",FACT(I) NEXT @@ -209,7 +209,7 @@ END"); catch { } - } + }/* catch(Throwable t) { running = false; @@ -220,7 +220,7 @@ END"); catch { } - } + }*/ elapse = SDL_GetTicks() - startTicks; } while(elapse <= 1000 / 60); SDL_Event event;