mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Patched segault in parser
This commit is contained in:
@@ -1,50 +1,6 @@
|
|||||||
//test the standard library, under a number of different circumstances
|
import compound;
|
||||||
|
var arr: [int] = [1, 2, 3];
|
||||||
//test basic import
|
fn f(_, v: int): int { return v + 1; }
|
||||||
{
|
print arr.map(f);
|
||||||
import standard;
|
|
||||||
|
|
||||||
//this depends on external factors, so only check the length
|
|
||||||
assert clock().length() == 24, "import library failed";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//test import within a function
|
|
||||||
{
|
|
||||||
fn f() {
|
|
||||||
import standard;
|
|
||||||
|
|
||||||
assert clock != null, "import library within function failed";
|
|
||||||
|
|
||||||
return clock;
|
|
||||||
}
|
|
||||||
|
|
||||||
//invoke
|
|
||||||
assert f()().length() == 24, "import library within function and return failed";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//test closing over standard library element
|
|
||||||
{
|
|
||||||
import standard;
|
|
||||||
|
|
||||||
fn f() {
|
|
||||||
assert clock != null, "import library outside function failed";
|
|
||||||
|
|
||||||
return clock;
|
|
||||||
}
|
|
||||||
|
|
||||||
//invoke
|
|
||||||
assert f()().length() == 24, "import library outside function and return failed";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//test importing as an alias
|
|
||||||
{
|
|
||||||
import standard as std;
|
|
||||||
|
|
||||||
assert std["clock"]().length() == 24, "import library as alias failed";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
print "All good";
|
|
||||||
|
|||||||
@@ -1220,7 +1220,7 @@ static void parsePrecedence(Toy_Parser* parser, Toy_ASTNode** nodeHandle, Preced
|
|||||||
Toy_emitASTNodeBinary(nodeHandle, rhsNode, opcode);
|
Toy_emitASTNodeBinary(nodeHandle, rhsNode, opcode);
|
||||||
|
|
||||||
//optimise away the constants
|
//optimise away the constants
|
||||||
if (!calcStaticBinaryArithmetic(parser, nodeHandle)) {
|
if (!parser->panic && !calcStaticBinaryArithmetic(parser, nodeHandle)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
test/scripts/mustfail/arithmetic-without-operand.toy
Normal file
1
test/scripts/mustfail/arithmetic-without-operand.toy
Normal file
@@ -0,0 +1 @@
|
|||||||
|
print "foo" + + "bar";
|
||||||
@@ -96,6 +96,7 @@ int main() {
|
|||||||
//run each file in tests/scripts/
|
//run each file in tests/scripts/
|
||||||
char* filenames[] = {
|
char* filenames[] = {
|
||||||
"access-parent-directory.toy",
|
"access-parent-directory.toy",
|
||||||
|
"arithmetic-without-operand.toy",
|
||||||
"bad-function-identifier.toy",
|
"bad-function-identifier.toy",
|
||||||
"declare-types-array.toy",
|
"declare-types-array.toy",
|
||||||
"declare-types-dictionary-key.toy",
|
"declare-types-dictionary-key.toy",
|
||||||
|
|||||||
Reference in New Issue
Block a user