1
0

ASSERT関数を実装,関数定義の後のコードが実行されない問題を修正

This commit is contained in:
otya128
2015-07-12 15:08:10 +09:00
parent 2139875751
commit 6741600c33
6 changed files with 56 additions and 5 deletions

View File

@@ -212,6 +212,7 @@
<File path="node.d" />
<File path="parser.d" />
<File path="petitcomputer.d" />
<File path="TEST.txt" />
<File path="token.d" />
<File path="type.d" />
<File path="VM.d" />

28
SMILEBASIC/TEST.txt Normal file
View File

@@ -0,0 +1,28 @@
ASSERT__ 1, "TRUE"
A$="A"
ASSERT__ A$=="A", "A$==A"
A$=A$+"B"
ASSERT__ A$=="AB", "A$==AA"
A=0
INC A
ASSERT__ A==1, "A==1"
INC A, 3
ASSERT__ A==4, "A==4"
DEC A, 3
ASSERT__ A==1, "A==1"
DEC A
ASSERT__ A==0, "A==0"
INCTEST 0
DEF INCTEST A
INC A
ASSERT__ A==1, "A==1"
INC A, 3
ASSERT__ A==4, "A==4"
DEC A, 3
ASSERT__ A==1, "A==1"
DEC A
ASSERT__ A==0, "A==0"
END
LOCATE 10,
COLOR 1,15
PRINT "テスト正常終了"

View File

@@ -94,6 +94,14 @@ class BuiltinFunction
{
p.cls;
}
static void ASSERT__(PetitComputer p, int cond, wstring message)
{
if(!cond)
{
p.printConsole("Assertion failed: ", message, "\n");
}
assert(cond, message.to!string);
}
//alias void function(PetitComputer, Value[], Value[]) BuiltinFunc;
static BuiltinFunction[wstring] builtinFunctions;
static this()
@@ -202,6 +210,10 @@ template GetFunctionParamType(T, string N)
{
const string arg = "ValueType.Integer, false";
}
else static if(is(P[0] == wstring))
{
const string arg = "ValueType.String, false";
}
else static if(is(P[0] == DefaultValue!int))
{
const string arg = "ValueType.Integer, true";
@@ -250,6 +262,11 @@ template AddFuncArg(int L, int N, int M, P...)
enum add = 1;
const string arg = "arg[" ~ I.to!string ~ "].castInteger";
}
else static if(is(P[0] == wstring))
{
enum add = 1;
const string arg = "arg[" ~ I.to!string ~ "].castString";
}
else static if(is(P[0] == DefaultValue!int))
{
enum add = 1;

View File

@@ -537,6 +537,7 @@ class Parser
}
isFuncReturnExpr = node.returnExpr;//面倒くさい
node.functionBody = functionStatements();
lex.popFront();
isFuncReturnExpr = false;
return node;
}

View File

@@ -347,7 +347,7 @@ class PetitComputer
}
}+/
//とりあえず
auto parser = new Parser(/*readText("FIZZBUZZ.TXT").to!wstring*//*"
auto parser = new Parser(readText("TEST.TXT").to!wstring/*readText("FIZZBUZZ.TXT").to!wstring*//*"
?ABS(-1)
LOCATE 0,10
COLOR 5
@@ -357,10 +357,10 @@ NEXT
DEF FACT(N)
IF N<=1 THEN RETURN 1
RETURN N*FACT(N-1)
END"*/
END"*//*
`CLS : CL=0 : Z=0
WHILE 1
INC Z
INC Z,2
?Z,
WEND
WHILE 1
@@ -370,7 +370,7 @@ WHILE 1
PRINT "★ 梅雨で雨が多い季節ですね ★"
NEXT
CL=(CL+1) MOD 16 : VSYNC 2
WEND`/*
WEND`*//*
`CLS : CL=0
WHILE 1
FOR I=0 TO 15
@@ -452,7 +452,7 @@ GOTO @LOOP`*/
auto back = console[y][x].backColor;
auto fore = consoleColor[console[y][x].foreColor];
auto texture = GRPFColor[back].texture;
//SDL_RenderCopy(renderer, texture, &fontTable[console[y][x].charater], &rect);
SDL_RenderCopy(renderer, texture, &fontTable[console[y][x].charater], &rect);
SDL_SetTextureColorMod(GRPF.texture, fore >> 16 & 0xFF, fore >> 8 & 0xFF, fore & 0xFF);
SDL_SetTextureAlphaMod(GRPF.texture, fore >> 24 & 0xFF);
SDL_RenderCopy(renderer, GRPF.texture, &fontTable[console[y][x].charater], &rect);

View File

@@ -90,6 +90,10 @@ struct Value
{
return this.type == ValueType.Integer ? this.integerValue : (this.type == ValueType.Double ? this.doubleValue : 0);
}
wstring castString()
{
return this.type == ValueType.String ? this.stringValue : "";
}
string toString()
{
import std.conv;