1
0

変数を使う時の捜索順を変更

This commit is contained in:
otya128
2015-07-06 22:14:55 +09:00
parent c466670b5f
commit 3c14a80890
5 changed files with 51 additions and 16 deletions

View File

@@ -53,7 +53,7 @@
<cccmd>$(CC) -c</cccmd>
<ccTransOpt>1</ccTransOpt>
<program>$(DMDInstallDir)windows\bin\dmd.exe</program>
<imppath />
<imppath>$(DMDInstallDir)src</imppath>
<fileImppath />
<outdir>$(ConfigurationName)</outdir>
<objdir>$(OutDir)</objdir>
@@ -89,8 +89,8 @@
<cv2pdbOptions />
<objfiles />
<linkswitches />
<libfiles />
<libpaths />
<libfiles>DerelictSDL2.lib;DerelictUtil.lib</libfiles>
<libpaths>$(DMDInstallDir)windows\lib\</libpaths>
<deffile />
<resfile />
<exefile>$(OutDir)\$(ProjectName).exe</exefile>
@@ -210,6 +210,7 @@
<File path="main.d" />
<File path="node.d" />
<File path="parser.d" />
<File path="petitcomputer.d" />
<File path="token.d" />
<File path="type.d" />
<File path="VM.d" />

View File

@@ -154,31 +154,31 @@ class Compiler
void genCodePushVar(wstring name, Scope sc)
{
auto global = hasGlobalVarIndex(name);
if(global)
{
code ~= new PushG(global);
return;
}
if(sc.func)
{
code ~= new PushL(sc.func.getLocalVarIndex(name, this));
return;
}
if(global)
{
code ~= new PushG(global);
return;
}
code ~= new PushG(getGlobalVarIndex(name));
}
void genCodePopVar(wstring name, Scope sc)
{
auto global = hasGlobalVarIndex(name);
if(global)
{
code ~= new PopG(global);
return;
}
if(sc.func)
{
code ~= new PopL(sc.func.getLocalVarIndex(name, this));
return;
}
if(global)
{
code ~= new PopG(global);
return;
}
code ~= new PopG(getGlobalVarIndex(name));
}
void genCodeOP(TokenType op)

View File

@@ -15,7 +15,10 @@ int main(string[] argv)
auto parser = new Parser(
//"@A\nA=1+2+3+4\nPRINT 1+1,2+3;10-5,A:A=A*2 PRINT A
"IF 1 THEN PRINT 2
"
TEST2 6,7,8 OUT K,L,M
?K,L,M
IF 1 THEN PRINT 2
IF 0 THEN PRINT 4 ELSE PRINT 5
IF 0 THEN
PRINT 111
@@ -67,6 +70,8 @@ NEXT
TEST \"HELLO\",\",\",\"WORLD\"
TEST2 6,7,8 OUT K,L,M
?K,L,M
FACT 10 OUT F
?F
END
@A
?\"SUBROUTINE TEST\"
@@ -87,12 +92,17 @@ DEF FACT(N)
END
DEF TEST A,B,C
?\"TEST\",A,B,C
RETURN
END
?\"CHECK\"
DEF TEST2 A,B,C OUT D,E,F
?\"TEST\",A,B,C
?\"TEST2\",A,B,C
F=C
F=C
D=A
E=B
F=C
?F
RETURN
END
");
version(none) auto parser = new Parser(readText("FIZZBUZZ.TXT").to!wstring);

View File

@@ -0,0 +1,9 @@
module otya.smilebasic.petitcomputer;
import derelict.sdl2.sdl;
class PetitComputer
{
this()
{
DerelictSDL2.load();
}
}

View File

@@ -90,6 +90,21 @@ struct Value
{
return this.type == ValueType.Integer ? this.integerValue : (this.type == ValueType.Double ? this.doubleValue : 0);
}
string toString()
{
import std.conv;
switch(this.type)
{
case ValueType.Void:
return "void";
case ValueType.Integer:
return this.integerValue.to!string;
case ValueType.String:
return this.stringValue.to!string;
default:
return "default";
}
}
}
class Array(T)
{