mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Dropped underscore functions in favour of UFCS
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -388,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -424,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -437,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -458,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -471,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -500,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}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -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;
|
||||||
@@ -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;
|
||||||
@@ -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;
|
||||||
@@ -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);
|
||||||
@@ -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;
|
||||||
@@ -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}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1127,24 +1127,6 @@ static bool execFnCall(Toy_Interpreter* interpreter, bool looseFirstArgument) {
|
|||||||
Toy_freeLiteral(lit);
|
Toy_freeLiteral(lit);
|
||||||
}
|
}
|
||||||
|
|
||||||
//let's screw with the fn name, too
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
//get the function literal
|
//get the function literal
|
||||||
Toy_Literal func = identifier;
|
Toy_Literal func = identifier;
|
||||||
|
|
||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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,5 +1,5 @@
|
|||||||
|
|
||||||
fn _add(self, inc) {
|
fn add(self, inc) {
|
||||||
return self + inc;
|
return self + inc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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)";
|
||||||
|
|||||||
@@ -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";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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,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++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user