バグ修正
This commit is contained in:
@@ -12,11 +12,13 @@ class VM
|
||||
int pc;
|
||||
Value[] stack;
|
||||
Value[] global;
|
||||
this(Code[] code, int len)
|
||||
int[wstring] debugTable;
|
||||
this(Code[] code, int len, int[wstring] debugTable)
|
||||
{
|
||||
this.code = code;
|
||||
this.stack = new Value[1024 * 1024];
|
||||
this.global = new Value[len];
|
||||
this.debugTable = debugTable;
|
||||
}
|
||||
void run()
|
||||
{
|
||||
@@ -33,6 +35,10 @@ class VM
|
||||
{
|
||||
value = stack[--stacki];
|
||||
}
|
||||
Value testGetGlobaVariable(wstring name)
|
||||
{
|
||||
return global[debugTable[name]];
|
||||
}
|
||||
}
|
||||
enum CodeType
|
||||
{
|
||||
@@ -134,8 +140,8 @@ class Operate : Code
|
||||
{
|
||||
Value l;
|
||||
Value r;
|
||||
vm.pop(l);
|
||||
vm.pop(r);
|
||||
vm.pop(l);
|
||||
double ld = l.integerValue;
|
||||
double rd = r.integerValue;
|
||||
//とりあえずInteger
|
||||
@@ -154,6 +160,7 @@ class Operate : Code
|
||||
ld /= rd;
|
||||
break;
|
||||
default:
|
||||
writeln("NotImpl: ", operator);
|
||||
break;
|
||||
}
|
||||
l.integerValue = cast(int)ld;
|
||||
|
||||
@@ -89,6 +89,7 @@ class Compiler
|
||||
}
|
||||
break;
|
||||
default:
|
||||
stderr.writeln("Compile:NotImpl ", exp.type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -132,6 +133,16 @@ class Compiler
|
||||
stderr.writeln("Compile:NotImpl ", i.type);
|
||||
}
|
||||
}
|
||||
return new VM(code, globalIndex + 1);
|
||||
return new VM(code, globalIndex + 1, global);
|
||||
}
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
import otya.smilebasic.parser;
|
||||
auto parser = new Parser("A=1+2+3+4*5/4-5+(6+6)*7");
|
||||
auto vm = parser.compile();
|
||||
vm.run();
|
||||
writeln(vm.testGetGlobaVariable("A").integerValue);
|
||||
assert(vm.testGetGlobaVariable("A").integerValue == 1+2+3+4*5/4-5+(6+6)*7);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ int main(string[] argv)
|
||||
writeln(parser.calc());
|
||||
}
|
||||
|
||||
auto parser = new Parser("A=1+2+3+4\nPRINT 1+1,2+3;10-5,A");
|
||||
auto parser = new Parser("A=1+2+3+4\nPRINT 1+1,2+3;10-5,A:A=A*2:PRINT A");
|
||||
auto vm = parser.compile();
|
||||
vm.run();
|
||||
readln();
|
||||
|
||||
@@ -359,6 +359,11 @@ class Parser
|
||||
}
|
||||
else
|
||||
{
|
||||
if(token.type == TokenType.Colon || token.type == TokenType.NewLine)
|
||||
{
|
||||
print.addLine();
|
||||
break;
|
||||
}
|
||||
lex.popFront();
|
||||
if(token.type == TokenType.Semicolon)
|
||||
{
|
||||
@@ -514,4 +519,5 @@ unittest
|
||||
//Eval("test(2+5)") = 2+5;
|
||||
//Eval("test(2+5, test(2, 3+5))") = 3+5;
|
||||
Test!"2-3*4-5"();
|
||||
Test!"1+2+3+4*5/4-5+(6+6)*7"();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user