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