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

View File

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

View File

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