1
0

Implement USE/EXEC compilation

This commit is contained in:
otya128
2016-12-23 17:16:38 +09:00
parent 0b9fd70bcb
commit 0440c33184
4 changed files with 59 additions and 3 deletions

View File

@@ -2182,3 +2182,22 @@ class Pop : Code
vm.decSP(); vm.decSP();
} }
} }
class Exec : Code
{
override void execute(VM vm)
{
Value arg;
vm.pop(arg);
}
}
class Use : Code
{
override void execute(VM vm)
{
Value arg;
vm.pop(arg);
}
}

View File

@@ -933,6 +933,16 @@ class Compiler
{ {
genCode(new SetX(x.func, false)); genCode(new SetX(x.func, false));
} }
void compileExec(otya.smilebasic.node.Exec exec, Scope sc)
{
compileExpression(exec.expression, sc);
genCode(new otya.smilebasic.vm.Exec);
}
void compileUse(otya.smilebasic.node.Use use, Scope sc)
{
compileExpression(use.expression, sc);
genCode(new otya.smilebasic.vm.Use);
}
void compileStatement(Statement i, Scope s) void compileStatement(Statement i, Scope s)
{ {
switch(i.type) switch(i.type)
@@ -1201,6 +1211,12 @@ class Compiler
case NodeType.XOff: case NodeType.XOff:
compileXOff(cast(XOff)i, s); compileXOff(cast(XOff)i, s);
break; break;
case NodeType.Exec:
compileExec(cast(otya.smilebasic.node.Exec)i, s);
break;
case NodeType.Use:
compileUse(cast(otya.smilebasic.node.Use)i, s);
break;
default: default:
stderr.writeln("Compile:NotImpl ", i.type); stderr.writeln("Compile:NotImpl ", i.type);
} }

View File

@@ -48,6 +48,8 @@ enum NodeType
VarRef, VarRef,
XOn, XOn,
XOff, XOff,
Exec,
Use,
} }
abstract class Node abstract class Node
{ {
@@ -653,4 +655,23 @@ class XOff : Statement
this.func = func; this.func = func;
} }
} }
class Exec : Statement
{
Expression expression;
this(Expression e, SourceLocation loc)
{
super.location = loc;
expression = e;
this.type = NodeType.Exec;
}
}
class Use : Statement
{
Expression expression;
this(Expression e, SourceLocation loc)
{
super.location = loc;
expression = e;
this.type = NodeType.Use;
}
}

View File

@@ -1111,14 +1111,14 @@ class Parser
{ {
lex.popFront(); lex.popFront();
auto expr = expression(); auto expr = expression();
writeln("NOTIMPL:USE"); return new Use(expr, lex.location);
} }
break; break;
case TokenType.Exec: case TokenType.Exec:
{ {
lex.popFront(); lex.popFront();
auto expr = expression(); auto expr = expression();
writeln("NOTIMPL:EXEC"); return new Exec(expr, lex.location);
} }
break; break;
case TokenType.Swap: case TokenType.Swap: