Compare commits

...

5 Commits

Author SHA1 Message Date
Kayne Ruse 57af5a6d59 Tweaked some scripts 2023-02-14 09:21:22 +00:00
Kayne Ruse 0737b2a483 Dropped underscore functions in favour of UFCS 2023-02-14 08:37:31 +00:00
Kayne Ruse eae96d6403 Corrected the order of arguments to Toy_callLiteralFn() 2023-02-14 08:00:35 +00:00
Kayne Ruse b55b8e879e Added -n option to diable print newline 2023-02-13 15:51:38 +00:00
Kayne Ruse 1ed114b80d Allow for stmt to have empty clauses, resolved #58 2023-02-13 14:45:24 +00:00
22 changed files with 287 additions and 262 deletions
+19 -20
View File
@@ -200,7 +200,7 @@ static int nativeLoadScriptBytecode(Toy_Interpreter* interpreter, Toy_LiteralArr
static int nativeRunScript(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { static int nativeRunScript(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
//no arguments //no arguments
if (arguments->count != 1) { if (arguments->count != 1) {
interpreter->errorOutput("Incorrect number of arguments to _runScript\n"); interpreter->errorOutput("Incorrect number of arguments to runScript\n");
return -1; return -1;
} }
@@ -213,7 +213,7 @@ static int nativeRunScript(Toy_Interpreter* interpreter, Toy_LiteralArray* argum
} }
if (TOY_GET_OPAQUE_TAG(runnerLiteral) != TOY_OPAQUE_TAG_RUNNER) { if (TOY_GET_OPAQUE_TAG(runnerLiteral) != TOY_OPAQUE_TAG_RUNNER) {
interpreter->errorOutput("Unrecognized opaque literal in _runScript\n"); interpreter->errorOutput("Unrecognized opaque literal in runScript\n");
return -1; return -1;
} }
@@ -241,7 +241,7 @@ static int nativeRunScript(Toy_Interpreter* interpreter, Toy_LiteralArray* argum
static int nativeGetScriptVar(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { static int nativeGetScriptVar(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
//no arguments //no arguments
if (arguments->count != 2) { if (arguments->count != 2) {
interpreter->errorOutput("Incorrect number of arguments to _getScriptVar\n"); interpreter->errorOutput("Incorrect number of arguments to getScriptVar\n");
return -1; return -1;
} }
@@ -260,7 +260,7 @@ static int nativeGetScriptVar(Toy_Interpreter* interpreter, Toy_LiteralArray* ar
} }
if (TOY_GET_OPAQUE_TAG(runnerLiteral) != TOY_OPAQUE_TAG_RUNNER) { if (TOY_GET_OPAQUE_TAG(runnerLiteral) != TOY_OPAQUE_TAG_RUNNER) {
interpreter->errorOutput("Unrecognized opaque literal in _runScript\n"); interpreter->errorOutput("Unrecognized opaque literal in getScriptVar\n");
return -1; return -1;
} }
@@ -292,7 +292,7 @@ static int nativeGetScriptVar(Toy_Interpreter* interpreter, Toy_LiteralArray* ar
static int nativeCallScriptFn(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { static int nativeCallScriptFn(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
//no arguments //no arguments
if (arguments->count < 2) { if (arguments->count < 2) {
interpreter->errorOutput("Incorrect number of arguments to _callScriptFn\n"); interpreter->errorOutput("Incorrect number of arguments to callScriptFn\n");
return -1; return -1;
} }
@@ -309,7 +309,7 @@ static int nativeCallScriptFn(Toy_Interpreter* interpreter, Toy_LiteralArray* ar
Toy_LiteralArray rest; Toy_LiteralArray rest;
Toy_initLiteralArray(&rest); Toy_initLiteralArray(&rest);
while (tmp.count) { //correct the order of the rest args while (tmp.count > 0) { //correct the order of the rest args
Toy_Literal lit = Toy_popLiteralArray(&tmp); Toy_Literal lit = Toy_popLiteralArray(&tmp);
Toy_pushLiteralArray(&rest, lit); Toy_pushLiteralArray(&rest, lit);
Toy_freeLiteral(lit); Toy_freeLiteral(lit);
@@ -317,7 +317,6 @@ static int nativeCallScriptFn(Toy_Interpreter* interpreter, Toy_LiteralArray* ar
Toy_freeLiteralArray(&tmp); Toy_freeLiteralArray(&tmp);
//get the runner object //get the runner object
Toy_Literal varName = Toy_popLiteralArray(arguments); Toy_Literal varName = Toy_popLiteralArray(arguments);
Toy_Literal runnerLiteral = Toy_popLiteralArray(arguments); Toy_Literal runnerLiteral = Toy_popLiteralArray(arguments);
@@ -333,7 +332,7 @@ static int nativeCallScriptFn(Toy_Interpreter* interpreter, Toy_LiteralArray* ar
} }
if (TOY_GET_OPAQUE_TAG(runnerLiteral) != TOY_OPAQUE_TAG_RUNNER) { if (TOY_GET_OPAQUE_TAG(runnerLiteral) != TOY_OPAQUE_TAG_RUNNER) {
interpreter->errorOutput("Unrecognized opaque literal in _runScript\n"); interpreter->errorOutput("Unrecognized opaque literal in callScriptFn\n");
return -1; return -1;
} }
@@ -389,7 +388,7 @@ static int nativeCallScriptFn(Toy_Interpreter* interpreter, Toy_LiteralArray* ar
static int nativeResetScript(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { static int nativeResetScript(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
//no arguments //no arguments
if (arguments->count != 1) { if (arguments->count != 1) {
interpreter->errorOutput("Incorrect number of arguments to _resetScript\n"); interpreter->errorOutput("Incorrect number of arguments to resetScript\n");
return -1; return -1;
} }
@@ -402,7 +401,7 @@ static int nativeResetScript(Toy_Interpreter* interpreter, Toy_LiteralArray* arg
} }
if (TOY_GET_OPAQUE_TAG(runnerLiteral) != TOY_OPAQUE_TAG_RUNNER) { if (TOY_GET_OPAQUE_TAG(runnerLiteral) != TOY_OPAQUE_TAG_RUNNER) {
interpreter->errorOutput("Unrecognized opaque literal in _runScript\n"); interpreter->errorOutput("Unrecognized opaque literal in resetScript\n");
return -1; return -1;
} }
@@ -425,7 +424,7 @@ static int nativeResetScript(Toy_Interpreter* interpreter, Toy_LiteralArray* arg
static int nativeFreeScript(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { static int nativeFreeScript(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
//no arguments //no arguments
if (arguments->count != 1) { if (arguments->count != 1) {
interpreter->errorOutput("Incorrect number of arguments to _freeScript\n"); interpreter->errorOutput("Incorrect number of arguments to freeScript\n");
return -1; return -1;
} }
@@ -438,7 +437,7 @@ static int nativeFreeScript(Toy_Interpreter* interpreter, Toy_LiteralArray* argu
} }
if (TOY_GET_OPAQUE_TAG(runnerLiteral) != TOY_OPAQUE_TAG_RUNNER) { if (TOY_GET_OPAQUE_TAG(runnerLiteral) != TOY_OPAQUE_TAG_RUNNER) {
interpreter->errorOutput("Unrecognized opaque literal in _freeScript\n"); interpreter->errorOutput("Unrecognized opaque literal in freeScript\n");
return -1; return -1;
} }
@@ -459,7 +458,7 @@ static int nativeFreeScript(Toy_Interpreter* interpreter, Toy_LiteralArray* argu
static int nativeCheckScriptDirty(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { static int nativeCheckScriptDirty(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
//no arguments //no arguments
if (arguments->count != 1) { if (arguments->count != 1) {
interpreter->errorOutput("Incorrect number of arguments to _runScript\n"); interpreter->errorOutput("Incorrect number of arguments to checkScriptDirty\n");
return -1; return -1;
} }
@@ -472,7 +471,7 @@ static int nativeCheckScriptDirty(Toy_Interpreter* interpreter, Toy_LiteralArray
} }
if (TOY_GET_OPAQUE_TAG(runnerLiteral) != TOY_OPAQUE_TAG_RUNNER) { if (TOY_GET_OPAQUE_TAG(runnerLiteral) != TOY_OPAQUE_TAG_RUNNER) {
interpreter->errorOutput("Unrecognized opaque literal in _runScript\n"); interpreter->errorOutput("Unrecognized opaque literal in checkScriptDirty\n");
return -1; return -1;
} }
@@ -501,12 +500,12 @@ int Toy_hookRunner(Toy_Interpreter* interpreter, Toy_Literal identifier, Toy_Lit
Natives natives[] = { Natives natives[] = {
{"loadScript", nativeLoadScript}, {"loadScript", nativeLoadScript},
{"loadScriptBytecode", nativeLoadScriptBytecode}, {"loadScriptBytecode", nativeLoadScriptBytecode},
{"_runScript", nativeRunScript}, {"runScript", nativeRunScript},
{"_getScriptVar", nativeGetScriptVar}, {"getScriptVar", nativeGetScriptVar},
{"_callScriptFn", nativeCallScriptFn}, {"callScriptFn", nativeCallScriptFn},
{"_resetScript", nativeResetScript}, {"resetScript", nativeResetScript},
{"_freeScript", nativeFreeScript}, {"freeScript", nativeFreeScript},
{"_checkScriptDirty", nativeCheckScriptDirty}, {"checkScriptDirty", nativeCheckScriptDirty},
{NULL, NULL} {NULL, NULL}
}; };
+74 -74
View File
@@ -34,7 +34,7 @@ static int nativeClock(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments
static int nativeConcat(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { static int nativeConcat(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
//no arguments //no arguments
if (arguments->count != 2) { if (arguments->count != 2) {
interpreter->errorOutput("Incorrect number of arguments to _concat\n"); interpreter->errorOutput("Incorrect number of arguments to concat\n");
return -1; return -1;
} }
@@ -56,7 +56,7 @@ static int nativeConcat(Toy_Interpreter* interpreter, Toy_LiteralArray* argument
//for each self type //for each self type
if (TOY_IS_ARRAY(selfLiteral)) { if (TOY_IS_ARRAY(selfLiteral)) {
if (!TOY_IS_ARRAY(otherLiteral)) { if (!TOY_IS_ARRAY(otherLiteral)) {
interpreter->errorOutput("Incorrect argument type passed to _concat (unknown type for other)\n"); interpreter->errorOutput("Incorrect argument type passed to concat (unknown type for other)\n");
Toy_freeLiteral(selfLiteral); Toy_freeLiteral(selfLiteral);
Toy_freeLiteral(otherLiteral); Toy_freeLiteral(otherLiteral);
return -1; return -1;
@@ -78,7 +78,7 @@ static int nativeConcat(Toy_Interpreter* interpreter, Toy_LiteralArray* argument
if (TOY_IS_DICTIONARY(selfLiteral)) { if (TOY_IS_DICTIONARY(selfLiteral)) {
if (!TOY_IS_DICTIONARY(otherLiteral)) { if (!TOY_IS_DICTIONARY(otherLiteral)) {
interpreter->errorOutput("Incorrect argument type passed to _concat (unknown type for other)\n"); interpreter->errorOutput("Incorrect argument type passed to concat (unknown type for other)\n");
Toy_freeLiteral(selfLiteral); Toy_freeLiteral(selfLiteral);
Toy_freeLiteral(otherLiteral); Toy_freeLiteral(otherLiteral);
return -1; return -1;
@@ -102,7 +102,7 @@ static int nativeConcat(Toy_Interpreter* interpreter, Toy_LiteralArray* argument
if (TOY_IS_STRING(selfLiteral)) { //a little redundant if (TOY_IS_STRING(selfLiteral)) { //a little redundant
if (!TOY_IS_STRING(otherLiteral)) { if (!TOY_IS_STRING(otherLiteral)) {
interpreter->errorOutput("Incorrect argument type passed to _concat (unknown type for other)\n"); interpreter->errorOutput("Incorrect argument type passed to concat (unknown type for other)\n");
Toy_freeLiteral(selfLiteral); Toy_freeLiteral(selfLiteral);
Toy_freeLiteral(otherLiteral); Toy_freeLiteral(otherLiteral);
return -1; return -1;
@@ -112,7 +112,7 @@ static int nativeConcat(Toy_Interpreter* interpreter, Toy_LiteralArray* argument
size_t length = TOY_AS_STRING(selfLiteral)->length + TOY_AS_STRING(otherLiteral)->length + 1; size_t length = TOY_AS_STRING(selfLiteral)->length + TOY_AS_STRING(otherLiteral)->length + 1;
if (length > TOY_MAX_STRING_LENGTH) { if (length > TOY_MAX_STRING_LENGTH) {
interpreter->errorOutput("Can't concatenate these strings, result is too long (error found in _concat)\n"); interpreter->errorOutput("Can't concatenate these strings, result is too long (error found in concat)\n");
Toy_freeLiteral(selfLiteral); Toy_freeLiteral(selfLiteral);
Toy_freeLiteral(otherLiteral); Toy_freeLiteral(otherLiteral);
return -1; return -1;
@@ -135,7 +135,7 @@ static int nativeConcat(Toy_Interpreter* interpreter, Toy_LiteralArray* argument
return 1; return 1;
} }
interpreter->errorOutput("Incorrect argument type passed to _concat (unknown type for self)\n"); interpreter->errorOutput("Incorrect argument type passed to concat (unknown type for self)\n");
Toy_freeLiteral(selfLiteral); Toy_freeLiteral(selfLiteral);
Toy_freeLiteral(otherLiteral); Toy_freeLiteral(otherLiteral);
return -1; return -1;
@@ -144,7 +144,7 @@ static int nativeConcat(Toy_Interpreter* interpreter, Toy_LiteralArray* argument
static int nativeContainsKey(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { static int nativeContainsKey(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
//no arguments //no arguments
if (arguments->count != 2) { if (arguments->count != 2) {
interpreter->errorOutput("Incorrect number of arguments to _containsKey\n"); interpreter->errorOutput("Incorrect number of arguments to containsKey\n");
return -1; return -1;
} }
@@ -165,7 +165,7 @@ static int nativeContainsKey(Toy_Interpreter* interpreter, Toy_LiteralArray* arg
//check type //check type
if (!(/* TOY_IS_ARRAY(selfLiteral) || */ TOY_IS_DICTIONARY(selfLiteral) )) { if (!(/* TOY_IS_ARRAY(selfLiteral) || */ TOY_IS_DICTIONARY(selfLiteral) )) {
interpreter->errorOutput("Incorrect argument type passed to _containsKey\n"); interpreter->errorOutput("Incorrect argument type passed to containsKey\n");
Toy_freeLiteral(selfLiteral); Toy_freeLiteral(selfLiteral);
Toy_freeLiteral(keyLiteral); Toy_freeLiteral(keyLiteral);
return -1; return -1;
@@ -189,7 +189,7 @@ static int nativeContainsKey(Toy_Interpreter* interpreter, Toy_LiteralArray* arg
static int nativeContainsValue(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { static int nativeContainsValue(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
//no arguments //no arguments
if (arguments->count != 2) { if (arguments->count != 2) {
interpreter->errorOutput("Incorrect number of arguments to _containsValue\n"); interpreter->errorOutput("Incorrect number of arguments to containsValue\n");
return -1; return -1;
} }
@@ -210,7 +210,7 @@ static int nativeContainsValue(Toy_Interpreter* interpreter, Toy_LiteralArray* a
//check type //check type
if (!( TOY_IS_ARRAY(selfLiteral) || TOY_IS_DICTIONARY(selfLiteral) )) { if (!( TOY_IS_ARRAY(selfLiteral) || TOY_IS_DICTIONARY(selfLiteral) )) {
interpreter->errorOutput("Incorrect argument type passed to _containsValue\n"); interpreter->errorOutput("Incorrect argument type passed to containsValue\n");
Toy_freeLiteral(selfLiteral); Toy_freeLiteral(selfLiteral);
Toy_freeLiteral(valueLiteral); Toy_freeLiteral(valueLiteral);
return -1; return -1;
@@ -259,7 +259,7 @@ static int nativeContainsValue(Toy_Interpreter* interpreter, Toy_LiteralArray* a
static int nativeEvery(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { static int nativeEvery(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
//no arguments //no arguments
if (arguments->count != 2) { if (arguments->count != 2) {
interpreter->errorOutput("Incorrect number of arguments to _every\n"); interpreter->errorOutput("Incorrect number of arguments to every\n");
return -1; return -1;
} }
@@ -280,7 +280,7 @@ static int nativeEvery(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments
//check type //check type
if (!( TOY_IS_ARRAY(selfLiteral) || TOY_IS_DICTIONARY(selfLiteral) ) || !( TOY_IS_FUNCTION(fnLiteral) || TOY_IS_FUNCTION_NATIVE(fnLiteral) )) { if (!( TOY_IS_ARRAY(selfLiteral) || TOY_IS_DICTIONARY(selfLiteral) ) || !( TOY_IS_FUNCTION(fnLiteral) || TOY_IS_FUNCTION_NATIVE(fnLiteral) )) {
interpreter->errorOutput("Incorrect argument type passed to _every\n"); interpreter->errorOutput("Incorrect argument type passed to every\n");
Toy_freeLiteral(selfLiteral); Toy_freeLiteral(selfLiteral);
Toy_freeLiteral(fnLiteral); Toy_freeLiteral(fnLiteral);
return -1; return -1;
@@ -296,8 +296,8 @@ static int nativeEvery(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments
Toy_LiteralArray arguments; Toy_LiteralArray arguments;
Toy_initLiteralArray(&arguments); Toy_initLiteralArray(&arguments);
Toy_pushLiteralArray(&arguments, TOY_AS_ARRAY(selfLiteral)->literals[i]);
Toy_pushLiteralArray(&arguments, indexLiteral); Toy_pushLiteralArray(&arguments, indexLiteral);
Toy_pushLiteralArray(&arguments, TOY_AS_ARRAY(selfLiteral)->literals[i]);
Toy_LiteralArray returns; Toy_LiteralArray returns;
Toy_initLiteralArray(&returns); Toy_initLiteralArray(&returns);
@@ -337,8 +337,8 @@ static int nativeEvery(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments
Toy_LiteralArray arguments; Toy_LiteralArray arguments;
Toy_initLiteralArray(&arguments); Toy_initLiteralArray(&arguments);
Toy_pushLiteralArray(&arguments, TOY_AS_DICTIONARY(selfLiteral)->entries[i].value);
Toy_pushLiteralArray(&arguments, TOY_AS_DICTIONARY(selfLiteral)->entries[i].key); Toy_pushLiteralArray(&arguments, TOY_AS_DICTIONARY(selfLiteral)->entries[i].key);
Toy_pushLiteralArray(&arguments, TOY_AS_DICTIONARY(selfLiteral)->entries[i].value);
Toy_LiteralArray returns; Toy_LiteralArray returns;
Toy_initLiteralArray(&returns); Toy_initLiteralArray(&returns);
@@ -375,7 +375,7 @@ static int nativeEvery(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments
static int nativeFilter(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { static int nativeFilter(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
//no arguments //no arguments
if (arguments->count != 2) { if (arguments->count != 2) {
interpreter->errorOutput("Incorrect number of arguments to _filter\n"); interpreter->errorOutput("Incorrect number of arguments to filter\n");
return -1; return -1;
} }
@@ -396,7 +396,7 @@ static int nativeFilter(Toy_Interpreter* interpreter, Toy_LiteralArray* argument
//check type //check type
if (!( TOY_IS_ARRAY(selfLiteral) || TOY_IS_DICTIONARY(selfLiteral) ) || !( TOY_IS_FUNCTION(fnLiteral) || TOY_IS_FUNCTION_NATIVE(fnLiteral) )) { if (!( TOY_IS_ARRAY(selfLiteral) || TOY_IS_DICTIONARY(selfLiteral) ) || !( TOY_IS_FUNCTION(fnLiteral) || TOY_IS_FUNCTION_NATIVE(fnLiteral) )) {
interpreter->errorOutput("Incorrect argument type passed to _filter\n"); interpreter->errorOutput("Incorrect argument type passed to filter\n");
Toy_freeLiteral(selfLiteral); Toy_freeLiteral(selfLiteral);
Toy_freeLiteral(fnLiteral); Toy_freeLiteral(fnLiteral);
return -1; return -1;
@@ -413,8 +413,8 @@ static int nativeFilter(Toy_Interpreter* interpreter, Toy_LiteralArray* argument
Toy_LiteralArray arguments; Toy_LiteralArray arguments;
Toy_initLiteralArray(&arguments); Toy_initLiteralArray(&arguments);
Toy_pushLiteralArray(&arguments, TOY_AS_ARRAY(selfLiteral)->literals[i]);
Toy_pushLiteralArray(&arguments, indexLiteral); Toy_pushLiteralArray(&arguments, indexLiteral);
Toy_pushLiteralArray(&arguments, TOY_AS_ARRAY(selfLiteral)->literals[i]);
Toy_LiteralArray returns; Toy_LiteralArray returns;
Toy_initLiteralArray(&returns); Toy_initLiteralArray(&returns);
@@ -453,8 +453,8 @@ static int nativeFilter(Toy_Interpreter* interpreter, Toy_LiteralArray* argument
Toy_LiteralArray arguments; Toy_LiteralArray arguments;
Toy_initLiteralArray(&arguments); Toy_initLiteralArray(&arguments);
Toy_pushLiteralArray(&arguments, TOY_AS_DICTIONARY(selfLiteral)->entries[i].value);
Toy_pushLiteralArray(&arguments, TOY_AS_DICTIONARY(selfLiteral)->entries[i].key); Toy_pushLiteralArray(&arguments, TOY_AS_DICTIONARY(selfLiteral)->entries[i].key);
Toy_pushLiteralArray(&arguments, TOY_AS_DICTIONARY(selfLiteral)->entries[i].value);
Toy_LiteralArray returns; Toy_LiteralArray returns;
Toy_initLiteralArray(&returns); Toy_initLiteralArray(&returns);
@@ -489,7 +489,7 @@ static int nativeFilter(Toy_Interpreter* interpreter, Toy_LiteralArray* argument
static int nativeForEach(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { static int nativeForEach(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
//no arguments //no arguments
if (arguments->count != 2) { if (arguments->count != 2) {
interpreter->errorOutput("Incorrect number of arguments to _forEach\n"); interpreter->errorOutput("Incorrect number of arguments to forEach\n");
return -1; return -1;
} }
@@ -510,7 +510,7 @@ static int nativeForEach(Toy_Interpreter* interpreter, Toy_LiteralArray* argumen
//check type //check type
if (!( TOY_IS_ARRAY(selfLiteral) || TOY_IS_DICTIONARY(selfLiteral) ) || !( TOY_IS_FUNCTION(fnLiteral) || TOY_IS_FUNCTION_NATIVE(fnLiteral) )) { if (!( TOY_IS_ARRAY(selfLiteral) || TOY_IS_DICTIONARY(selfLiteral) ) || !( TOY_IS_FUNCTION(fnLiteral) || TOY_IS_FUNCTION_NATIVE(fnLiteral) )) {
interpreter->errorOutput("Incorrect argument type passed to _forEach\n"); interpreter->errorOutput("Incorrect argument type passed to forEach\n");
Toy_freeLiteral(selfLiteral); Toy_freeLiteral(selfLiteral);
Toy_freeLiteral(fnLiteral); Toy_freeLiteral(fnLiteral);
return -1; return -1;
@@ -523,8 +523,8 @@ static int nativeForEach(Toy_Interpreter* interpreter, Toy_LiteralArray* argumen
Toy_LiteralArray arguments; Toy_LiteralArray arguments;
Toy_initLiteralArray(&arguments); Toy_initLiteralArray(&arguments);
Toy_pushLiteralArray(&arguments, TOY_AS_ARRAY(selfLiteral)->literals[i]);
Toy_pushLiteralArray(&arguments, indexLiteral); Toy_pushLiteralArray(&arguments, indexLiteral);
Toy_pushLiteralArray(&arguments, TOY_AS_ARRAY(selfLiteral)->literals[i]);
Toy_LiteralArray returns; Toy_LiteralArray returns;
Toy_initLiteralArray(&returns); Toy_initLiteralArray(&returns);
@@ -546,8 +546,8 @@ static int nativeForEach(Toy_Interpreter* interpreter, Toy_LiteralArray* argumen
Toy_LiteralArray arguments; Toy_LiteralArray arguments;
Toy_initLiteralArray(&arguments); Toy_initLiteralArray(&arguments);
Toy_pushLiteralArray(&arguments, TOY_AS_DICTIONARY(selfLiteral)->entries[i].value);
Toy_pushLiteralArray(&arguments, TOY_AS_DICTIONARY(selfLiteral)->entries[i].key); Toy_pushLiteralArray(&arguments, TOY_AS_DICTIONARY(selfLiteral)->entries[i].key);
Toy_pushLiteralArray(&arguments, TOY_AS_DICTIONARY(selfLiteral)->entries[i].value);
Toy_LiteralArray returns; Toy_LiteralArray returns;
Toy_initLiteralArray(&returns); Toy_initLiteralArray(&returns);
@@ -567,7 +567,7 @@ static int nativeForEach(Toy_Interpreter* interpreter, Toy_LiteralArray* argumen
static int nativeGetKeys(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { static int nativeGetKeys(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
if (arguments->count != 1) { if (arguments->count != 1) {
interpreter->errorOutput("Incorrect number of arguments to _getKeys\n"); interpreter->errorOutput("Incorrect number of arguments to getKeys\n");
return -1; return -1;
} }
@@ -582,7 +582,7 @@ static int nativeGetKeys(Toy_Interpreter* interpreter, Toy_LiteralArray* argumen
//check type //check type
if (!TOY_IS_DICTIONARY(selfLiteral)) { if (!TOY_IS_DICTIONARY(selfLiteral)) {
interpreter->errorOutput("Incorrect argument type passed to _getKeys\n"); interpreter->errorOutput("Incorrect argument type passed to getKeys\n");
Toy_freeLiteral(selfLiteral); Toy_freeLiteral(selfLiteral);
return -1; return -1;
} }
@@ -612,7 +612,7 @@ static int nativeGetKeys(Toy_Interpreter* interpreter, Toy_LiteralArray* argumen
static int nativeGetValues(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { static int nativeGetValues(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
if (arguments->count != 1) { if (arguments->count != 1) {
interpreter->errorOutput("Incorrect number of arguments to _getValues\n"); interpreter->errorOutput("Incorrect number of arguments to getValues\n");
return -1; return -1;
} }
@@ -627,7 +627,7 @@ static int nativeGetValues(Toy_Interpreter* interpreter, Toy_LiteralArray* argum
//check type //check type
if (!TOY_IS_DICTIONARY(selfLiteral)) { if (!TOY_IS_DICTIONARY(selfLiteral)) {
interpreter->errorOutput("Incorrect argument type passed to _getValues\n"); interpreter->errorOutput("Incorrect argument type passed to getValues\n");
Toy_freeLiteral(selfLiteral); Toy_freeLiteral(selfLiteral);
return -1; return -1;
} }
@@ -658,7 +658,7 @@ static int nativeGetValues(Toy_Interpreter* interpreter, Toy_LiteralArray* argum
static int nativeIndexOf(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { static int nativeIndexOf(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
//no arguments //no arguments
if (arguments->count != 2) { if (arguments->count != 2) {
interpreter->errorOutput("Incorrect number of arguments to _indexOf\n"); interpreter->errorOutput("Incorrect number of arguments to indexOf\n");
return -1; return -1;
} }
@@ -705,7 +705,7 @@ static int nativeIndexOf(Toy_Interpreter* interpreter, Toy_LiteralArray* argumen
static int nativeMap(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { static int nativeMap(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
//no arguments //no arguments
if (arguments->count != 2) { if (arguments->count != 2) {
interpreter->errorOutput("Incorrect number of arguments to _map\n"); interpreter->errorOutput("Incorrect number of arguments to map\n");
return -1; return -1;
} }
@@ -726,7 +726,7 @@ static int nativeMap(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments)
//check type //check type
if (!( TOY_IS_ARRAY(selfLiteral) || TOY_IS_DICTIONARY(selfLiteral) ) || !( TOY_IS_FUNCTION(fnLiteral) || TOY_IS_FUNCTION_NATIVE(fnLiteral) )) { if (!( TOY_IS_ARRAY(selfLiteral) || TOY_IS_DICTIONARY(selfLiteral) ) || !( TOY_IS_FUNCTION(fnLiteral) || TOY_IS_FUNCTION_NATIVE(fnLiteral) )) {
interpreter->errorOutput("Incorrect argument type passed to _map\n"); interpreter->errorOutput("Incorrect argument type passed to map\n");
Toy_freeLiteral(selfLiteral); Toy_freeLiteral(selfLiteral);
Toy_freeLiteral(fnLiteral); Toy_freeLiteral(fnLiteral);
return -1; return -1;
@@ -742,8 +742,8 @@ static int nativeMap(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments)
Toy_LiteralArray arguments; Toy_LiteralArray arguments;
Toy_initLiteralArray(&arguments); Toy_initLiteralArray(&arguments);
Toy_pushLiteralArray(&arguments, TOY_AS_ARRAY(selfLiteral)->literals[i]);
Toy_pushLiteralArray(&arguments, indexLiteral); Toy_pushLiteralArray(&arguments, indexLiteral);
Toy_pushLiteralArray(&arguments, TOY_AS_ARRAY(selfLiteral)->literals[i]);
Toy_LiteralArray returns; Toy_LiteralArray returns;
Toy_initLiteralArray(&returns); Toy_initLiteralArray(&returns);
@@ -777,8 +777,8 @@ static int nativeMap(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments)
Toy_LiteralArray arguments; Toy_LiteralArray arguments;
Toy_initLiteralArray(&arguments); Toy_initLiteralArray(&arguments);
Toy_pushLiteralArray(&arguments, TOY_AS_DICTIONARY(selfLiteral)->entries[i].value);
Toy_pushLiteralArray(&arguments, TOY_AS_DICTIONARY(selfLiteral)->entries[i].key); Toy_pushLiteralArray(&arguments, TOY_AS_DICTIONARY(selfLiteral)->entries[i].key);
Toy_pushLiteralArray(&arguments, TOY_AS_DICTIONARY(selfLiteral)->entries[i].value);
Toy_LiteralArray returns; Toy_LiteralArray returns;
Toy_initLiteralArray(&returns); Toy_initLiteralArray(&returns);
@@ -808,7 +808,7 @@ static int nativeMap(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments)
static int nativeReduce(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { static int nativeReduce(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
//no arguments //no arguments
if (arguments->count != 3) { if (arguments->count != 3) {
interpreter->errorOutput("Incorrect number of arguments to _reduce\n"); interpreter->errorOutput("Incorrect number of arguments to reduce\n");
return -1; return -1;
} }
@@ -835,7 +835,7 @@ static int nativeReduce(Toy_Interpreter* interpreter, Toy_LiteralArray* argument
//check type //check type
if (!( TOY_IS_ARRAY(selfLiteral) || TOY_IS_DICTIONARY(selfLiteral) ) || !( TOY_IS_FUNCTION(fnLiteral) || TOY_IS_FUNCTION_NATIVE(fnLiteral) )) { if (!( TOY_IS_ARRAY(selfLiteral) || TOY_IS_DICTIONARY(selfLiteral) ) || !( TOY_IS_FUNCTION(fnLiteral) || TOY_IS_FUNCTION_NATIVE(fnLiteral) )) {
interpreter->errorOutput("Incorrect argument type passed to _reduce\n"); interpreter->errorOutput("Incorrect argument type passed to reduce\n");
Toy_freeLiteral(selfLiteral); Toy_freeLiteral(selfLiteral);
Toy_freeLiteral(defaultLiteral); Toy_freeLiteral(defaultLiteral);
Toy_freeLiteral(fnLiteral); Toy_freeLiteral(fnLiteral);
@@ -849,9 +849,9 @@ static int nativeReduce(Toy_Interpreter* interpreter, Toy_LiteralArray* argument
Toy_LiteralArray arguments; Toy_LiteralArray arguments;
Toy_initLiteralArray(&arguments); Toy_initLiteralArray(&arguments);
Toy_pushLiteralArray(&arguments, TOY_AS_ARRAY(selfLiteral)->literals[i]);
Toy_pushLiteralArray(&arguments, indexLiteral);
Toy_pushLiteralArray(&arguments, defaultLiteral); Toy_pushLiteralArray(&arguments, defaultLiteral);
Toy_pushLiteralArray(&arguments, indexLiteral);
Toy_pushLiteralArray(&arguments, TOY_AS_ARRAY(selfLiteral)->literals[i]);
Toy_LiteralArray returns; Toy_LiteralArray returns;
Toy_initLiteralArray(&returns); Toy_initLiteralArray(&returns);
@@ -879,9 +879,9 @@ static int nativeReduce(Toy_Interpreter* interpreter, Toy_LiteralArray* argument
Toy_LiteralArray arguments; Toy_LiteralArray arguments;
Toy_initLiteralArray(&arguments); Toy_initLiteralArray(&arguments);
Toy_pushLiteralArray(&arguments, TOY_AS_DICTIONARY(selfLiteral)->entries[i].value);
Toy_pushLiteralArray(&arguments, TOY_AS_DICTIONARY(selfLiteral)->entries[i].key);
Toy_pushLiteralArray(&arguments, defaultLiteral); Toy_pushLiteralArray(&arguments, defaultLiteral);
Toy_pushLiteralArray(&arguments, TOY_AS_DICTIONARY(selfLiteral)->entries[i].key);
Toy_pushLiteralArray(&arguments, TOY_AS_DICTIONARY(selfLiteral)->entries[i].value);
Toy_LiteralArray returns; Toy_LiteralArray returns;
Toy_initLiteralArray(&returns); Toy_initLiteralArray(&returns);
@@ -909,7 +909,7 @@ static int nativeReduce(Toy_Interpreter* interpreter, Toy_LiteralArray* argument
static int nativeSome(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { static int nativeSome(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
//no arguments //no arguments
if (arguments->count != 2) { if (arguments->count != 2) {
interpreter->errorOutput("Incorrect number of arguments to _some\n"); interpreter->errorOutput("Incorrect number of arguments to some\n");
return -1; return -1;
} }
@@ -930,7 +930,7 @@ static int nativeSome(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments)
//check type //check type
if (!( TOY_IS_ARRAY(selfLiteral) || TOY_IS_DICTIONARY(selfLiteral) ) || !( TOY_IS_FUNCTION(fnLiteral) || TOY_IS_FUNCTION_NATIVE(fnLiteral) )) { if (!( TOY_IS_ARRAY(selfLiteral) || TOY_IS_DICTIONARY(selfLiteral) ) || !( TOY_IS_FUNCTION(fnLiteral) || TOY_IS_FUNCTION_NATIVE(fnLiteral) )) {
interpreter->errorOutput("Incorrect argument type passed to _some\n"); interpreter->errorOutput("Incorrect argument type passed to some\n");
Toy_freeLiteral(selfLiteral); Toy_freeLiteral(selfLiteral);
Toy_freeLiteral(fnLiteral); Toy_freeLiteral(fnLiteral);
return -1; return -1;
@@ -946,8 +946,8 @@ static int nativeSome(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments)
Toy_LiteralArray arguments; Toy_LiteralArray arguments;
Toy_initLiteralArray(&arguments); Toy_initLiteralArray(&arguments);
Toy_pushLiteralArray(&arguments, TOY_AS_ARRAY(selfLiteral)->literals[i]);
Toy_pushLiteralArray(&arguments, indexLiteral); Toy_pushLiteralArray(&arguments, indexLiteral);
Toy_pushLiteralArray(&arguments, TOY_AS_ARRAY(selfLiteral)->literals[i]);
Toy_LiteralArray returns; Toy_LiteralArray returns;
Toy_initLiteralArray(&returns); Toy_initLiteralArray(&returns);
@@ -987,8 +987,8 @@ static int nativeSome(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments)
Toy_LiteralArray arguments; Toy_LiteralArray arguments;
Toy_initLiteralArray(&arguments); Toy_initLiteralArray(&arguments);
Toy_pushLiteralArray(&arguments, TOY_AS_DICTIONARY(selfLiteral)->entries[i].value);
Toy_pushLiteralArray(&arguments, TOY_AS_DICTIONARY(selfLiteral)->entries[i].key); Toy_pushLiteralArray(&arguments, TOY_AS_DICTIONARY(selfLiteral)->entries[i].key);
Toy_pushLiteralArray(&arguments, TOY_AS_DICTIONARY(selfLiteral)->entries[i].value);
Toy_LiteralArray returns; Toy_LiteralArray returns;
Toy_initLiteralArray(&returns); Toy_initLiteralArray(&returns);
@@ -1045,8 +1045,8 @@ static void recursiveLiteralQuicksortUtil(Toy_Interpreter* interpreter, Toy_Lite
Toy_initLiteralArray(&arguments); Toy_initLiteralArray(&arguments);
Toy_initLiteralArray(&returns); Toy_initLiteralArray(&returns);
Toy_pushLiteralArray(&arguments, ptr[literalCount - 1]); //backwards
Toy_pushLiteralArray(&arguments, ptr[checker]); Toy_pushLiteralArray(&arguments, ptr[checker]);
Toy_pushLiteralArray(&arguments, ptr[literalCount - 1]);
Toy_callLiteralFn(interpreter, fnCompareLiteral, &arguments, &returns); Toy_callLiteralFn(interpreter, fnCompareLiteral, &arguments, &returns);
@@ -1073,7 +1073,7 @@ static void recursiveLiteralQuicksortUtil(Toy_Interpreter* interpreter, Toy_Lite
static int nativeSort(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { static int nativeSort(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
//no arguments //no arguments
if (arguments->count != 2) { if (arguments->count != 2) {
interpreter->errorOutput("Incorrect number of arguments to _sort\n"); interpreter->errorOutput("Incorrect number of arguments to sort\n");
return -1; return -1;
} }
@@ -1094,7 +1094,7 @@ static int nativeSort(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments)
//check type //check type
if (!TOY_IS_ARRAY(selfLiteral) || !( TOY_IS_FUNCTION(fnLiteral) || TOY_IS_FUNCTION_NATIVE(fnLiteral) )) { if (!TOY_IS_ARRAY(selfLiteral) || !( TOY_IS_FUNCTION(fnLiteral) || TOY_IS_FUNCTION_NATIVE(fnLiteral) )) {
interpreter->errorOutput("Incorrect argument type passed to _sort\n"); interpreter->errorOutput("Incorrect argument type passed to sort\n");
Toy_freeLiteral(selfLiteral); Toy_freeLiteral(selfLiteral);
Toy_freeLiteral(fnLiteral); Toy_freeLiteral(fnLiteral);
return -1; return -1;
@@ -1116,7 +1116,7 @@ static int nativeSort(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments)
static int nativeToLower(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { static int nativeToLower(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
//no arguments //no arguments
if (arguments->count != 1) { if (arguments->count != 1) {
interpreter->errorOutput("Incorrect number of arguments to _toLower\n"); interpreter->errorOutput("Incorrect number of arguments to toLower\n");
return -1; return -1;
} }
@@ -1129,7 +1129,7 @@ static int nativeToLower(Toy_Interpreter* interpreter, Toy_LiteralArray* argumen
} }
if (!TOY_IS_STRING(selfLiteral)) { if (!TOY_IS_STRING(selfLiteral)) {
interpreter->errorOutput("Incorrect argument type passed to _toLower\n"); interpreter->errorOutput("Incorrect argument type passed to toLower\n");
Toy_freeLiteral(selfLiteral); Toy_freeLiteral(selfLiteral);
return -1; return -1;
} }
@@ -1176,7 +1176,7 @@ static void toStringUtil(const char* input) {
static int nativeToString(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { static int nativeToString(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
//no arguments //no arguments
if (arguments->count != 1) { if (arguments->count != 1) {
interpreter->errorOutput("Incorrect number of arguments to _toString\n"); interpreter->errorOutput("Incorrect number of arguments to toString\n");
return -1; return -1;
} }
@@ -1216,7 +1216,7 @@ static int nativeToString(Toy_Interpreter* interpreter, Toy_LiteralArray* argume
static int nativeToUpper(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { static int nativeToUpper(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
//no arguments //no arguments
if (arguments->count != 1) { if (arguments->count != 1) {
interpreter->errorOutput("Incorrect number of arguments to _toUpper\n"); interpreter->errorOutput("Incorrect number of arguments to toUpper\n");
return -1; return -1;
} }
@@ -1229,7 +1229,7 @@ static int nativeToUpper(Toy_Interpreter* interpreter, Toy_LiteralArray* argumen
} }
if (!TOY_IS_STRING(selfLiteral)) { if (!TOY_IS_STRING(selfLiteral)) {
interpreter->errorOutput("Incorrect argument type passed to _toUpper\n"); interpreter->errorOutput("Incorrect argument type passed to toUpper\n");
Toy_freeLiteral(selfLiteral); Toy_freeLiteral(selfLiteral);
return -1; return -1;
} }
@@ -1262,7 +1262,7 @@ static int nativeToUpper(Toy_Interpreter* interpreter, Toy_LiteralArray* argumen
static int nativeTrim(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { static int nativeTrim(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
if (arguments->count < 1 || arguments->count > 2) { if (arguments->count < 1 || arguments->count > 2) {
interpreter->errorOutput("Incorrect number of arguments to _trim\n"); interpreter->errorOutput("Incorrect number of arguments to trim\n");
return -1; return -1;
} }
@@ -1289,7 +1289,7 @@ static int nativeTrim(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments)
} }
if (!TOY_IS_STRING(selfLiteral)) { if (!TOY_IS_STRING(selfLiteral)) {
interpreter->errorOutput("Incorrect argument type passed to _trim\n"); interpreter->errorOutput("Incorrect argument type passed to trim\n");
Toy_freeLiteral(trimCharsLiteral); Toy_freeLiteral(trimCharsLiteral);
Toy_freeLiteral(selfLiteral); Toy_freeLiteral(selfLiteral);
return -1; return -1;
@@ -1373,7 +1373,7 @@ static int nativeTrim(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments)
static int nativeTrimBegin(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { static int nativeTrimBegin(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
if (arguments->count < 1 || arguments->count > 2) { if (arguments->count < 1 || arguments->count > 2) {
interpreter->errorOutput("Incorrect number of arguments to _trimBegin\n"); interpreter->errorOutput("Incorrect number of arguments to trimBegin\n");
return -1; return -1;
} }
@@ -1400,7 +1400,7 @@ static int nativeTrimBegin(Toy_Interpreter* interpreter, Toy_LiteralArray* argum
} }
if (!TOY_IS_STRING(selfLiteral)) { if (!TOY_IS_STRING(selfLiteral)) {
interpreter->errorOutput("Incorrect argument type passed to _trimBegin\n"); interpreter->errorOutput("Incorrect argument type passed to trimBegin\n");
Toy_freeLiteral(trimCharsLiteral); Toy_freeLiteral(trimCharsLiteral);
Toy_freeLiteral(selfLiteral); Toy_freeLiteral(selfLiteral);
return -1; return -1;
@@ -1461,7 +1461,7 @@ static int nativeTrimBegin(Toy_Interpreter* interpreter, Toy_LiteralArray* argum
static int nativeTrimEnd(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { static int nativeTrimEnd(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
if (arguments->count < 1 || arguments->count > 2) { if (arguments->count < 1 || arguments->count > 2) {
interpreter->errorOutput("Incorrect number of arguments to _trimEnd\n"); interpreter->errorOutput("Incorrect number of arguments to trimEnd\n");
return -1; return -1;
} }
@@ -1488,7 +1488,7 @@ static int nativeTrimEnd(Toy_Interpreter* interpreter, Toy_LiteralArray* argumen
} }
if (!TOY_IS_STRING(selfLiteral)) { if (!TOY_IS_STRING(selfLiteral)) {
interpreter->errorOutput("Incorrect argument type passed to _trimEnd\n"); interpreter->errorOutput("Incorrect argument type passed to trimEnd\n");
Toy_freeLiteral(trimCharsLiteral); Toy_freeLiteral(trimCharsLiteral);
Toy_freeLiteral(selfLiteral); Toy_freeLiteral(selfLiteral);
return -1; return -1;
@@ -1557,25 +1557,25 @@ int Toy_hookStandard(Toy_Interpreter* interpreter, Toy_Literal identifier, Toy_L
//build the natives list //build the natives list
Natives natives[] = { Natives natives[] = {
{"clock", nativeClock}, {"clock", nativeClock},
{"_concat", nativeConcat}, //array, dictionary, string {"concat", nativeConcat}, //array, dictionary, string
{"_containsKey", nativeContainsKey}, //dictionary {"containsKey", nativeContainsKey}, //dictionary
{"_containsValue", nativeContainsValue}, //array, dictionary {"containsValue", nativeContainsValue}, //array, dictionary
{"_every", nativeEvery}, //array, dictionary {"every", nativeEvery}, //array, dictionary
{"_filter", nativeFilter}, //array, dictionary {"filter", nativeFilter}, //array, dictionary
{"_forEach", nativeForEach}, //array, dictionary {"forEach", nativeForEach}, //array, dictionary
{"_getKeys", nativeGetKeys}, //dictionary {"getKeys", nativeGetKeys}, //dictionary
{"_getValues", nativeGetValues}, //dictionary {"getValues", nativeGetValues}, //dictionary
{"_indexOf", nativeIndexOf}, //array {"indexOf", nativeIndexOf}, //array
{"_map", nativeMap}, //array, dictionary {"map", nativeMap}, //array, dictionary
{"_reduce", nativeReduce}, //array, dictionary {"reduce", nativeReduce}, //array, dictionary
{"_some", nativeSome}, //array, dictionary {"some", nativeSome}, //array, dictionary
{"_sort", nativeSort}, //array {"sort", nativeSort}, //array
{"_toLower", nativeToLower}, //string {"toLower", nativeToLower}, //string
{"_toString", nativeToString}, //array, dictionary {"toString", nativeToString}, //array, dictionary
{"_toUpper", nativeToUpper}, //string {"toUpper", nativeToUpper}, //string
{"_trim", nativeTrim}, //string {"trim", nativeTrim}, //string
{"_trimBegin", nativeTrimBegin}, //string {"trimBegin", nativeTrimBegin}, //string
{"_trimEnd", nativeTrimEnd}, //string {"trimEnd", nativeTrimEnd}, //string
{NULL, NULL} {NULL, NULL}
}; };
+15
View File
@@ -1,3 +1,18 @@
/*
How to run this program:
toyrepl -n -t scripts/level.toy
How to move around:
move(up);
move(down);
move(left);
move(right);
*/
//constants //constants
var WIDTH: int const = 12; var WIDTH: int const = 12;
var HEIGHT: int const = 12; var HEIGHT: int const = 12;
+1 -1
View File
@@ -1,5 +1,5 @@
//number of iterations //number of iterations
var SIZE: int const = 260; var SIZE: int const = 100;
//lookup table //lookup table
var lookup = [ var lookup = [
-27
View File
@@ -1,27 +0,0 @@
import compound;
fn less(a, b) {
return a < b;
}
fn greater(a, b) {
return a > b;
}
var a = [7, 2, 1, 8, 6, 3, 5, 4];
var b = [7, 2, 1, 4, 6, 3, 5, 8];
var c = [1, 2, 3, 4, 5, 6, 7, 8];
var d = [7, 2, 1, 8, 6, 3, 5, 4];
a = a.sort(less);
b = b.sort(less);
c = c.sort(less);
d = d.sort(greater);
assert a == [1, 2, 3, 4, 5, 6, 7, 8], "array.sort(less) failed";
assert b == [1, 2, 3, 4, 5, 6, 7, 8], "array.sort(less) with pivot high failed";
assert c == [1, 2, 3, 4, 5, 6, 7, 8], "array.sort(less) pre-sorted array failed";
assert d == [8, 7, 6, 5, 4, 3, 2, 1], "array.sort(greater) failed";
print "All good";
+12
View File
@@ -135,6 +135,10 @@ static void freeASTNodeCustom(Toy_ASTNode* node, bool freeSelf) {
Toy_freeLiteral(node->import.identifier); Toy_freeLiteral(node->import.identifier);
Toy_freeLiteral(node->import.alias); Toy_freeLiteral(node->import.alias);
break; break;
case TOY_AST_NODE_PASS:
//EMPTY
break;
} }
if (freeSelf) { if (freeSelf) {
@@ -383,3 +387,11 @@ void Toy_emitASTNodeImport(Toy_ASTNode** nodeHandle, Toy_Literal identifier, Toy
*nodeHandle = tmp; *nodeHandle = tmp;
} }
void Toy_emitASTNodePass(Toy_ASTNode** nodeHandle) {
Toy_ASTNode* tmp = TOY_ALLOCATE(Toy_ASTNode, 1);
tmp->type = TOY_AST_NODE_PASS;
*nodeHandle = tmp;
}
+4
View File
@@ -34,6 +34,7 @@ typedef enum Toy_ASTNodeType {
TOY_AST_NODE_PREFIX_DECREMENT, //decrement a variable TOY_AST_NODE_PREFIX_DECREMENT, //decrement a variable
TOY_AST_NODE_POSTFIX_DECREMENT, //decrement a variable TOY_AST_NODE_POSTFIX_DECREMENT, //decrement a variable
TOY_AST_NODE_IMPORT, //import a library TOY_AST_NODE_IMPORT, //import a library
TOY_AST_NODE_PASS, //for doing nothing
} Toy_ASTNodeType; } Toy_ASTNodeType;
//literals //literals
@@ -238,6 +239,9 @@ typedef struct Toy_NodeImport {
Toy_Literal alias; Toy_Literal alias;
} Toy_NodeImport; } Toy_NodeImport;
//for doing nothing
void Toy_emitASTNodePass(Toy_ASTNode** nodeHandle);
union Toy_private_node { union Toy_private_node {
Toy_ASTNodeType type; Toy_ASTNodeType type;
Toy_NodeLiteral atomic; Toy_NodeLiteral atomic;
+8
View File
@@ -29,6 +29,7 @@ void Toy_initCommandLine(int argc, const char* argv[]) {
Toy_commandLine.outfile = "out.tb"; Toy_commandLine.outfile = "out.tb";
Toy_commandLine.source = NULL; Toy_commandLine.source = NULL;
Toy_commandLine.initialfile = NULL; Toy_commandLine.initialfile = NULL;
Toy_commandLine.enablePrintNewline = true;
Toy_commandLine.verbose = false; Toy_commandLine.verbose = false;
for (int i = 1; i < argc; i++) { //start at 1 to skip the program name for (int i = 1; i < argc; i++) { //start at 1 to skip the program name
@@ -87,6 +88,12 @@ void Toy_initCommandLine(int argc, const char* argv[]) {
continue; continue;
} }
if (!strcmp(argv[i], "-n")) {
Toy_commandLine.enablePrintNewline = false;
Toy_commandLine.error = false;
continue;
}
//option without a flag + ending in .tb = binary input //option without a flag + ending in .tb = binary input
if (i < argc) { if (i < argc) {
if (strncmp(&(argv[i][strlen(argv[i]) - 3]), ".tb", 3) == 0) { if (strncmp(&(argv[i][strlen(argv[i]) - 3]), ".tb", 3) == 0) {
@@ -117,6 +124,7 @@ void Toy_helpCommandLine(int argc, const char* argv[]) {
printf("-c\t| --compile filename\tParse and compile the specified source file into an output file.\n\n"); printf("-c\t| --compile filename\tParse and compile the specified source file into an output file.\n\n");
printf("-o\t| --output outfile\tName of the output file built with --compile (default: out.tb).\n\n"); printf("-o\t| --output outfile\tName of the output file built with --compile (default: out.tb).\n\n");
printf("-t\t| --initial filename\tStart the repl as normal, after first running the given file.\n\n"); printf("-t\t| --initial filename\tStart the repl as normal, after first running the given file.\n\n");
printf("-n\t|\t\t\tDisable the newline character at the end of the print statement.\n\n");
} }
void Toy_copyrightCommandLine(int argc, const char* argv[]) { void Toy_copyrightCommandLine(int argc, const char* argv[]) {
+3 -2
View File
@@ -5,8 +5,8 @@
#include <stdint.h> #include <stdint.h>
#define TOY_VERSION_MAJOR 0 #define TOY_VERSION_MAJOR 0
#define TOY_VERSION_MINOR 8 #define TOY_VERSION_MINOR 9
#define TOY_VERSION_PATCH 3 #define TOY_VERSION_PATCH 0
#define TOY_VERSION_BUILD __DATE__ " " __TIME__ #define TOY_VERSION_BUILD __DATE__ " " __TIME__
//platform/compiler-specific instructions //platform/compiler-specific instructions
@@ -39,6 +39,7 @@ typedef struct {
char* outfile; //defaults to out.tb char* outfile; //defaults to out.tb
char* source; char* source;
char* initialfile; char* initialfile;
bool enablePrintNewline;
bool verbose; bool verbose;
} Toy_CommandLine; } Toy_CommandLine;
+5
View File
@@ -965,6 +965,11 @@ static Toy_Opcode Toy_writeCompilerWithJumps(Toy_Compiler* compiler, Toy_ASTNode
return TOY_OP_INDEX_ASSIGN; //override binary's instruction IF it is assign return TOY_OP_INDEX_ASSIGN; //override binary's instruction IF it is assign
} }
break; break;
case TOY_AST_NODE_PASS: {
return TOY_OP_PASS;
}
break;
} }
return TOY_OP_EOF; return TOY_OP_EOF;
+50 -68
View File
@@ -12,8 +12,12 @@
#include <string.h> #include <string.h>
static void printWrapper(const char* output) { static void printWrapper(const char* output) {
printf("%s", output); if (Toy_commandLine.enablePrintNewline) {
// printf("\n"); //default new line printf("%s\n", output);
}
else {
printf("%s", output);
}
} }
static void assertWrapper(const char* output) { static void assertWrapper(const char* output) {
@@ -1085,6 +1089,8 @@ static bool execFalseJump(Toy_Interpreter* interpreter) {
static void execInterpreter(Toy_Interpreter*); static void execInterpreter(Toy_Interpreter*);
static void readInterpreterSections(Toy_Interpreter* interpreter); static void readInterpreterSections(Toy_Interpreter* interpreter);
//expect stack: identifier, arg1, arg2, arg3..., stackSize
//also supports identifier & arg1 to be other way around (looseFirstArgument)
static bool execFnCall(Toy_Interpreter* interpreter, bool looseFirstArgument) { static bool execFnCall(Toy_Interpreter* interpreter, bool looseFirstArgument) {
//BUGFIX: depth check - don't drown! //BUGFIX: depth check - don't drown!
if (interpreter->depth >= 200) { if (interpreter->depth >= 200) {
@@ -1121,24 +1127,7 @@ static bool execFnCall(Toy_Interpreter* interpreter, bool looseFirstArgument) {
Toy_freeLiteral(lit); Toy_freeLiteral(lit);
} }
//let's screw with the fn name, too //get the function literal
if (looseFirstArgument) {
if (!TOY_IS_IDENTIFIER(identifier)) {
interpreter->errorOutput("Bad literal passed as a function identifier\n");
Toy_freeLiteral(identifier);
Toy_freeLiteral(stackSize);
Toy_freeLiteralArray(&arguments);
return false;
}
int length = TOY_AS_IDENTIFIER(identifier)->length + 1;
char buffer[TOY_MAX_STRING_LENGTH];
snprintf(buffer, TOY_MAX_STRING_LENGTH, "_%s", Toy_toCString(TOY_AS_IDENTIFIER(identifier))); //prepend an underscore
Toy_freeLiteral(identifier);
identifier = TOY_TO_IDENTIFIER_LITERAL(Toy_createRefStringLength(buffer, length));
}
Toy_Literal func = identifier; Toy_Literal func = identifier;
if (!Toy_parseIdentifierToValue(interpreter, &func)) { if (!Toy_parseIdentifierToValue(interpreter, &func)) {
@@ -1148,30 +1137,7 @@ static bool execFnCall(Toy_Interpreter* interpreter, bool looseFirstArgument) {
return false; return false;
} }
//check for side-loaded native functions if (!TOY_IS_FUNCTION(func) && !TOY_IS_FUNCTION_NATIVE(func)) {
if (TOY_IS_FUNCTION_NATIVE(func)) {
//reverse the order to the correct order
Toy_LiteralArray correct;
Toy_initLiteralArray(&correct);
while(arguments.count) {
Toy_Literal lit = Toy_popLiteralArray(&arguments);
Toy_pushLiteralArray(&correct, lit);
Toy_freeLiteral(lit);
}
Toy_freeLiteralArray(&arguments);
//call the native function
TOY_AS_FUNCTION_NATIVE(func)(interpreter, &correct);
Toy_freeLiteralArray(&correct);
Toy_freeLiteral(stackSize);
Toy_freeLiteral(identifier);
return true;
}
if (!TOY_IS_FUNCTION(func)) {
interpreter->errorOutput("Function not found: "); interpreter->errorOutput("Function not found: ");
Toy_printLiteralCustom(identifier, interpreter->errorOutput); Toy_printLiteralCustom(identifier, interpreter->errorOutput);
interpreter->errorOutput("\n"); interpreter->errorOutput("\n");
@@ -1182,7 +1148,18 @@ static bool execFnCall(Toy_Interpreter* interpreter, bool looseFirstArgument) {
return false; return false;
} }
bool ret = Toy_callLiteralFn(interpreter, func, &arguments, &interpreter->stack); //BUGFIX: correct the argument order
Toy_LiteralArray correct;
Toy_initLiteralArray(&correct);
while (arguments.count > 0) {
Toy_Literal lit = Toy_popLiteralArray(&arguments);
Toy_pushLiteralArray(&correct, lit);
Toy_freeLiteral(lit);
}
//call the function literal
bool ret = Toy_callLiteralFn(interpreter, func, &correct, &interpreter->stack);
if (!ret) { if (!ret) {
interpreter->errorOutput("Error encountered in function \""); interpreter->errorOutput("Error encountered in function \"");
@@ -1190,6 +1167,7 @@ static bool execFnCall(Toy_Interpreter* interpreter, bool looseFirstArgument) {
interpreter->errorOutput("\"\n"); interpreter->errorOutput("\"\n");
} }
Toy_freeLiteralArray(&correct);
Toy_freeLiteralArray(&arguments); Toy_freeLiteralArray(&arguments);
Toy_freeLiteral(func); Toy_freeLiteral(func);
Toy_freeLiteral(stackSize); Toy_freeLiteral(stackSize);
@@ -1198,25 +1176,15 @@ static bool execFnCall(Toy_Interpreter* interpreter, bool looseFirstArgument) {
return ret; return ret;
} }
//expects arguments in correct order
bool Toy_callLiteralFn(Toy_Interpreter* interpreter, Toy_Literal func, Toy_LiteralArray* arguments, Toy_LiteralArray* returns) { bool Toy_callLiteralFn(Toy_Interpreter* interpreter, Toy_Literal func, Toy_LiteralArray* arguments, Toy_LiteralArray* returns) {
//check for side-loaded native functions //check for side-loaded native functions
if (TOY_IS_FUNCTION_NATIVE(func)) { if (TOY_IS_FUNCTION_NATIVE(func)) {
//reverse the order to the correct order
Toy_LiteralArray correct;
Toy_initLiteralArray(&correct);
while(arguments->count) {
Toy_Literal lit = Toy_popLiteralArray(arguments);
Toy_pushLiteralArray(&correct, lit);
Toy_freeLiteral(lit);
}
//call the native function //call the native function
int returnsCount = TOY_AS_FUNCTION_NATIVE(func)(interpreter, &correct); int returnsCount = TOY_AS_FUNCTION_NATIVE(func)(interpreter, arguments);
if (returnsCount < 0) { if (returnsCount < 0) {
interpreter->errorOutput("Unknown error from native function\n"); interpreter->errorOutput("Unknown error from native function\n");
Toy_freeLiteralArray(&correct);
return false; return false;
} }
@@ -1238,13 +1206,12 @@ bool Toy_callLiteralFn(Toy_Interpreter* interpreter, Toy_Literal func, Toy_Liter
} }
Toy_freeLiteralArray(&returnsFromInner); Toy_freeLiteralArray(&returnsFromInner);
Toy_freeLiteralArray(&correct);
return true; return true;
} }
//normal Toy function //normal Toy function
if (!TOY_IS_FUNCTION(func)) { if (!TOY_IS_FUNCTION(func)) {
interpreter->errorOutput("Function required in Toy_callLiteralFn()\n"); interpreter->errorOutput("Function literal required in Toy_callLiteralFn()\n");
return false; return false;
} }
@@ -1292,6 +1259,9 @@ bool Toy_callLiteralFn(Toy_Interpreter* interpreter, Toy_Literal func, Toy_Liter
return false; return false;
} }
//BUGFIX: access the arguments from the beginning
int argumentIndex = 0;
//contents is the indexes of identifier & type //contents is the indexes of identifier & type
for (int i = 0; i < paramArray->count - (TOY_IS_NULL(restParam) ? 0 : 2); i += 2) { //don't count the rest parameter, if present for (int i = 0; i < paramArray->count - (TOY_IS_NULL(restParam) ? 0 : 2); i += 2) { //don't count the rest parameter, if present
//declare and define each entry in the scope //declare and define each entry in the scope
@@ -1307,7 +1277,11 @@ bool Toy_callLiteralFn(Toy_Interpreter* interpreter, Toy_Literal func, Toy_Liter
return false; return false;
} }
Toy_Literal arg = Toy_popLiteralArray(arguments); //access the arguments in order
Toy_Literal arg = TOY_TO_NULL_LITERAL;
if (argumentIndex < arguments->count) {
arg = Toy_copyLiteral(arguments->literals[argumentIndex++]);
}
Toy_Literal argIdn = arg; Toy_Literal argIdn = arg;
if (TOY_IS_IDENTIFIER(arg) && Toy_parseIdentifierToValue(interpreter, &arg)) { if (TOY_IS_IDENTIFIER(arg) && Toy_parseIdentifierToValue(interpreter, &arg)) {
@@ -1334,8 +1308,9 @@ bool Toy_callLiteralFn(Toy_Interpreter* interpreter, Toy_Literal func, Toy_Liter
Toy_LiteralArray rest; Toy_LiteralArray rest;
Toy_initLiteralArray(&rest); Toy_initLiteralArray(&rest);
while (arguments->count > 0) { //access the arguments in order
Toy_Literal lit = Toy_popLiteralArray(arguments); while (argumentIndex < arguments->count) {
Toy_Literal lit = Toy_copyLiteral(arguments->literals[argumentIndex++]);
Toy_pushLiteralArray(&rest, lit); Toy_pushLiteralArray(&rest, lit);
Toy_freeLiteral(lit); Toy_freeLiteral(lit);
} }
@@ -1442,6 +1417,9 @@ bool Toy_callLiteralFn(Toy_Interpreter* interpreter, Toy_Literal func, Toy_Liter
Toy_freeLiteralArray(&inner.stack); Toy_freeLiteralArray(&inner.stack);
Toy_freeLiteralArray(&inner.literalCache); Toy_freeLiteralArray(&inner.literalCache);
//BUGFIX: this function needs to eat the arguments
Toy_freeLiteralArray(arguments);
//actual bytecode persists until next call //actual bytecode persists until next call
return true; return true;
} }
@@ -1827,6 +1805,10 @@ static void execInterpreter(Toy_Interpreter* interpreter) {
while(opcode != TOY_OP_EOF && opcode != TOY_OP_SECTION_END && !interpreter->panic) { while(opcode != TOY_OP_EOF && opcode != TOY_OP_SECTION_END && !interpreter->panic) {
switch(opcode) { switch(opcode) {
case TOY_OP_PASS:
//DO NOTHING
break;
case TOY_OP_ASSERT: case TOY_OP_ASSERT:
if (!execAssert(interpreter)) { if (!execAssert(interpreter)) {
return; return;
@@ -2445,12 +2427,12 @@ void Toy_resetInterpreter(Toy_Interpreter* interpreter) {
interpreter->scope = Toy_pushScope(NULL); interpreter->scope = Toy_pushScope(NULL);
//globally available functions //globally available functions
Toy_injectNativeFn(interpreter, "_set", Toy_private_set); Toy_injectNativeFn(interpreter, "set", Toy_private_set);
Toy_injectNativeFn(interpreter, "_get", Toy_private_get); Toy_injectNativeFn(interpreter, "get", Toy_private_get);
Toy_injectNativeFn(interpreter, "_push", Toy_private_push); Toy_injectNativeFn(interpreter, "push", Toy_private_push);
Toy_injectNativeFn(interpreter, "_pop", Toy_private_pop); Toy_injectNativeFn(interpreter, "pop", Toy_private_pop);
Toy_injectNativeFn(interpreter, "_length", Toy_private_length); Toy_injectNativeFn(interpreter, "length", Toy_private_length);
Toy_injectNativeFn(interpreter, "_clear", Toy_private_clear); Toy_injectNativeFn(interpreter, "clear", Toy_private_clear);
} }
void Toy_freeInterpreter(Toy_Interpreter* interpreter) { void Toy_freeInterpreter(Toy_Interpreter* interpreter) {
+3
View File
@@ -3,6 +3,9 @@
typedef enum Toy_Opcode { typedef enum Toy_Opcode {
TOY_OP_EOF, TOY_OP_EOF,
//do nothing
TOY_OP_PASS,
//basic statements //basic statements
TOY_OP_ASSERT, TOY_OP_ASSERT,
TOY_OP_PRINT, TOY_OP_PRINT,
+28 -5
View File
@@ -1350,13 +1350,36 @@ static void forStmt(Toy_Parser* parser, Toy_ASTNode** nodeHandle) {
//read the clauses //read the clauses
consume(parser, TOY_TOKEN_PAREN_LEFT, "Expected '(' at beginning of for clause"); consume(parser, TOY_TOKEN_PAREN_LEFT, "Expected '(' at beginning of for clause");
declaration(parser, &preClause); //allow defining variables in the pre-clause //check the pre-clause
if (parser->current.type != TOY_TOKEN_SEMICOLON) {
declaration(parser, &preClause); //allow defining variables in the pre-clause
}
else {
consume(parser, TOY_TOKEN_SEMICOLON, "Expected ';' after empty declaration of for clause");
Toy_emitASTNodePass(&preClause);
}
parsePrecedence(parser, &condition, PREC_TERNARY); //check the condition clause
consume(parser, TOY_TOKEN_SEMICOLON, "Expected ';' after condition of for clause"); if (parser->current.type != TOY_TOKEN_SEMICOLON) {
parsePrecedence(parser, &condition, PREC_TERNARY);
consume(parser, TOY_TOKEN_SEMICOLON, "Expected ';' after condition of for clause");
}
else {
consume(parser, TOY_TOKEN_SEMICOLON, "Expected ';' after empty condition of for clause");
//empty clause defaults to forever
Toy_Literal f = TOY_TO_BOOLEAN_LITERAL(true);
Toy_emitASTNodeLiteral(&condition, f);
}
parsePrecedence(parser, &postClause, PREC_ASSIGNMENT); //check the postfix clause
consume(parser, TOY_TOKEN_PAREN_RIGHT, "Expected ')' at end of for clause"); if (parser->current.type != TOY_TOKEN_PAREN_RIGHT) {
parsePrecedence(parser, &postClause, PREC_ASSIGNMENT);
consume(parser, TOY_TOKEN_PAREN_RIGHT, "Expected ')' at end of for clause");
}
else {
consume(parser, TOY_TOKEN_PAREN_RIGHT, "Expected ')' after empty increment of for clause");
Toy_emitASTNodePass(&postClause);
}
//read the path //read the path
declaration(parser, &thenPath); declaration(parser, &thenPath);
+17 -17
View File
@@ -2,11 +2,11 @@
var a = [1, 2, 3]; var a = [1, 2, 3];
var b = [4, 5, 6]; var b = [4, 5, 6];
assert _length(a) == _length(b), "a and b lengths are wrong"; assert length(a) == length(b), "a and b lengths are wrong";
var acc = 0; var acc = 0;
for (var i = 0; i < _length(a); i++) { for (var i = 0; i < length(a); i++) {
acc += _get(a, i) * _get(b, i); acc += get(a, i) * get(b, i);
} }
assert acc == 32, "dot product failed"; assert acc == 32, "dot product failed";
@@ -15,38 +15,38 @@ assert acc == 32, "dot product failed";
//assume the args are matrices //assume the args are matrices
fn matrix(first, second) { fn matrix(first, second) {
//get the matrix size //get the matrix size
var l1 = _length(first); //rows var l1 = length(first); //rows
var l2 = _length(_get(first, 0)); //cols var l2 = length(get(first, 0)); //cols
var l3 = _length(second); //rows var l3 = length(second); //rows
var l4 = _length(_get(second, 0)); //cols var l4 = length(get(second, 0)); //cols
//pre-allocate the matrix //pre-allocate the matrix
var row = []; var row = [];
for (var j = 0; j < l4; j++) { for (var j = 0; j < l4; j++) {
_push(row, 0); push(row, 0);
} }
var result = []; var result = [];
for (var i = 0; i < l1; i++) { for (var i = 0; i < l1; i++) {
_push(result, row); push(result, row);
} }
//assign the values //assign the values
for (var i = 0; i < _length(first); i++) { for (var i = 0; i < length(first); i++) {
//select each element of "first" //select each element of "first"
var firstElement = _get(first, i); var firstElement = get(first, i);
//for each element of second //for each element of second
for (var i2 = 0; i2 < _length(second); i2++) { for (var i2 = 0; i2 < length(second); i2++) {
for (var j2 = 0; j2 < _length(_get(second, 0)); j2++) { for (var j2 = 0; j2 < length(get(second, 0)); j2++) {
var val = _get(_get(first, i), i2) * _get(_get(second, i2), j2); var val = get(get(first, i), i2) * get(get(second, i2), j2);
//TODO: needs better notation than this tmpRow variable //TODO: needs better notation than this tmpRow variable
var tmpRow = _get(result, i); var tmpRow = get(result, i);
_set(tmpRow, j2, val); set(tmpRow, j2, val);
_set(result, i, tmpRow); set(result, i, tmpRow);
//result[ i ][ j2 ] += first[i][i2] * second[i2][j2] //result[ i ][ j2 ] += first[i][i2] * second[i2][j2]
} }
+1 -1
View File
@@ -9,7 +9,7 @@ It appears to be a compiler issue, see issue #38 for more info.
*/ */
fn _getValue(self) { fn getValue(self) {
return self; return self;
} }
+3 -3
View File
@@ -1,10 +1,10 @@
//test function chaining with the dot operator //test function chaining with the dot operator
fn _identity(self) { fn identity(self) {
return self; return self;
} }
fn _check(self) { fn check(self) {
assert self == 42, "dot chaining failed"; assert self == 42, "dot chaining failed";
return self; return self;
} }
@@ -20,7 +20,7 @@ val
//test the value is actually altered //test the value is actually altered
fn _increment(self) { fn increment(self) {
return self + 1; return self + 1;
} }
+1 -1
View File
@@ -1,5 +1,5 @@
fn _add(self, inc) { fn add(self, inc) {
return self + inc; return self + inc;
} }
+1 -1
View File
@@ -63,7 +63,7 @@ extra("one", "two", "three", "four", "five", "six", "seven");
//test underscore functions //test underscore functions
fn _example(self, a, b, c) { fn example(self, a, b, c) {
assert a == "a", "underscore failed (a)"; assert a == "a", "underscore failed (a)";
assert b == "b", "underscore failed (b)"; assert b == "b", "underscore failed (b)";
assert c == "c", "underscore failed (c)"; assert c == "c", "underscore failed (c)";
Binary file not shown.
+39 -39
View File
@@ -3,41 +3,41 @@
//test arrays without types //test arrays without types
var array = []; var array = [];
assert _length(array) == 0, "_length failed with array"; assert length(array) == 0, "length failed with array";
_push(array, 1); push(array, 1);
_push(array, 2); push(array, 2);
_push(array, 3); push(array, 3);
_push(array, 4); push(array, 4);
_push(array, "foo"); push(array, "foo");
assert _length(array) == 5, "_push failed with array"; assert length(array) == 5, "push failed with array";
assert _pop(array) == "foo", "_pop failed with array"; assert pop(array) == "foo", "pop failed with array";
_set(array, 2, "bar"); set(array, 2, "bar");
assert array == [1, 2, "bar", 4], "_set failed with array"; assert array == [1, 2, "bar", 4], "set failed with array";
assert _get(array, 3) == 4, "_get failed with array"; assert get(array, 3) == 4, "get failed with array";
//test dictionaries without types //test dictionaries without types
var dict = [:]; var dict = [:];
_set(dict, "key", "value"); set(dict, "key", "value");
_set(dict, 1, 2); set(dict, 1, 2);
assert dict == ["key":"value", 1:2], "_set failed with dictionaries"; assert dict == ["key":"value", 1:2], "set failed with dictionaries";
assert _get(dict, "key") == "value", "_get failed with dictionaries"; assert get(dict, "key") == "value", "get failed with dictionaries";
//test _length //test length
assert _length(array) == 4 && _length(dict) == 2, "_length failed with array or dictionaries"; assert length(array) == 4 && length(dict) == 2, "length failed with array or dictionaries";
//test clear //test clear
_clear(array); clear(array);
_clear(dict); clear(dict);
assert _length(array) == 0 && _length(dict) == 0, "_clear failed with array or dictionaries"; assert length(array) == 0 && length(dict) == 0, "clear failed with array or dictionaries";
} }
@@ -45,46 +45,46 @@
//test arrays with types //test arrays with types
var array: [int] = []; var array: [int] = [];
assert _length(array) == 0, "_length failed with array (+ types)"; assert length(array) == 0, "length failed with array (+ types)";
_push(array, 1); push(array, 1);
_push(array, 2); push(array, 2);
_push(array, 3); push(array, 3);
_push(array, 4); push(array, 4);
_push(array, 10); push(array, 10);
assert _length(array) == 5, "_push or failed with array (+ types)"; assert length(array) == 5, "push or failed with array (+ types)";
assert _pop(array) == 10, "_pop failed with array (+ types)"; assert pop(array) == 10, "pop failed with array (+ types)";
_set(array, 2, 70); set(array, 2, 70);
assert array == [1, 2, 70, 4], "_set failed with array (+ types)"; assert array == [1, 2, 70, 4], "set failed with array (+ types)";
assert _get(array, 3) == 4, "_get failed with array (+ types)"; assert get(array, 3) == 4, "get failed with array (+ types)";
//test dictionaries with types //test dictionaries with types
var dict: [string : string] = [:]; var dict: [string : string] = [:];
_set(dict, "key", "value"); set(dict, "key", "value");
assert dict == ["key":"value"], "_set failed with dictionaries (+ types)"; assert dict == ["key":"value"], "set failed with dictionaries (+ types)";
assert _get(dict, "key") == "value", "_get failed with dictionaries (+ types)"; assert get(dict, "key") == "value", "get failed with dictionaries (+ types)";
//test length with types //test length with types
assert _length(array) == 4 && _length(dict) == 1, "_length failed with array or dictionaries (+ types)"; assert length(array) == 4 && length(dict) == 1, "length failed with array or dictionaries (+ types)";
//test clear with types //test clear with types
_clear(array); clear(array);
_clear(dict); clear(dict);
assert _length(array) == 0 && _length(dict) == 0, "_clear failed with array or dictionaries (+ types)"; assert length(array) == 0 && length(dict) == 0, "clear failed with array or dictionaries (+ types)";
} }
{ {
var str = "hello world"; var str = "hello world";
assert _length(str) == 11, "_length failed with string"; assert length(str) == 11, "length failed with string";
} }
+2 -2
View File
@@ -1,5 +1,5 @@
//polyfill the _insert function //polyfill the insert function
fn _insert(self, k, v) { fn insert(self, k, v) {
var tmp1 = v; var tmp1 = v;
var tmp2; var tmp2;
for (var i = k; i < self.length(); i++) { for (var i = k; i < self.length(); i++) {
+1 -1
View File
@@ -1,5 +1,5 @@
//polyfill the remove function //polyfill the remove function
fn _remove(self, k) { fn remove(self, k) {
var result = []; var result = [];
for (var i = 0; i <= k - 1; i++) { for (var i = 0; i <= k - 1; i++) {