From 1ec0f63f761165d0ead9f6533a8581baea47ae7a Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 21 Jul 2023 04:25:36 +1000 Subject: [PATCH] Removed unneeded safties from the libs I missed removing these before, and I haven't needed these in a long time. --- repl/lib_random.c | 15 --------------- repl/lib_runner.c | 42 ------------------------------------------ repl/lib_standard.c | 45 --------------------------------------------- 3 files changed, 102 deletions(-) diff --git a/repl/lib_random.c b/repl/lib_random.c index 6b70cc8..97cbe44 100644 --- a/repl/lib_random.c +++ b/repl/lib_random.c @@ -30,11 +30,6 @@ static int nativeCreateRandomGenerator(Toy_Interpreter* interpreter, Toy_Literal Toy_freeLiteral(seedLiteralIdn); } - if (TOY_IS_IDENTIFIER(seedLiteral)) { - Toy_freeLiteral(seedLiteral); - return -1; - } - if (!TOY_IS_INTEGER(seedLiteral)) { interpreter->errorOutput("Incorrect literal type passed to createRandomGenerator"); Toy_freeLiteral(seedLiteral); @@ -70,11 +65,6 @@ static int nativeGenerateRandomNumber(Toy_Interpreter* interpreter, Toy_LiteralA Toy_freeLiteral(generatorLiteralIdn); } - if (TOY_IS_IDENTIFIER(generatorLiteral)) { - Toy_freeLiteral(generatorLiteral); - return -1; - } - if (TOY_GET_OPAQUE_TAG(generatorLiteral) != TOY_OPAQUE_TAG_RANDOM) { interpreter->errorOutput("Unrecognized opaque literal in generateRandomNumber\n"); return -1; @@ -111,11 +101,6 @@ static int nativeFreeRandomGenerator(Toy_Interpreter* interpreter, Toy_LiteralAr Toy_freeLiteral(generatorLiteralIdn); } - if (TOY_IS_IDENTIFIER(generatorLiteral)) { - Toy_freeLiteral(generatorLiteral); - return -1; - } - if (TOY_GET_OPAQUE_TAG(generatorLiteral) != TOY_OPAQUE_TAG_RANDOM) { interpreter->errorOutput("Unrecognized opaque literal in freeRandomGenerator\n"); return -1; diff --git a/repl/lib_runner.c b/repl/lib_runner.c index 27f05e7..1271429 100644 --- a/repl/lib_runner.c +++ b/repl/lib_runner.c @@ -32,11 +32,6 @@ static int nativeLoadScript(Toy_Interpreter* interpreter, Toy_LiteralArray* argu Toy_freeLiteral(drivePathLiteralIdn); } - if (TOY_IS_IDENTIFIER(drivePathLiteral)) { - Toy_freeLiteral(drivePathLiteral); - return -1; - } - Toy_Literal filePathLiteral = Toy_getDrivePathLiteral(interpreter, &drivePathLiteral); if (TOY_IS_NULL(filePathLiteral)) { @@ -107,11 +102,6 @@ static int nativeLoadScriptBytecode(Toy_Interpreter* interpreter, Toy_LiteralArr Toy_freeLiteral(drivePathLiteralIdn); } - if (TOY_IS_IDENTIFIER(drivePathLiteral)) { - Toy_freeLiteral(drivePathLiteral); - return -1; - } - Toy_Literal filePathLiteral = Toy_getDrivePathLiteral(interpreter, &drivePathLiteral); if (TOY_IS_NULL(filePathLiteral)) { @@ -172,11 +162,6 @@ static int nativeRunScript(Toy_Interpreter* interpreter, Toy_LiteralArray* argum Toy_freeLiteral(runnerIdn); } - if (TOY_IS_IDENTIFIER(runnerLiteral)) { - Toy_freeLiteral(runnerLiteral); - return -1; - } - if (TOY_GET_OPAQUE_TAG(runnerLiteral) != TOY_OPAQUE_TAG_RUNNER) { interpreter->errorOutput("Unrecognized opaque literal in runScript\n"); return -1; @@ -224,12 +209,6 @@ static int nativeGetScriptVar(Toy_Interpreter* interpreter, Toy_LiteralArray* ar Toy_freeLiteral(runnerIdn); } - if (TOY_IS_IDENTIFIER(varName) || TOY_IS_IDENTIFIER(runnerLiteral)) { - Toy_freeLiteral(varName); - Toy_freeLiteral(runnerLiteral); - return -1; - } - if (TOY_GET_OPAQUE_TAG(runnerLiteral) != TOY_OPAQUE_TAG_RUNNER) { interpreter->errorOutput("Unrecognized opaque literal in getScriptVar\n"); return -1; @@ -302,12 +281,6 @@ static int nativeCallScriptFn(Toy_Interpreter* interpreter, Toy_LiteralArray* ar Toy_freeLiteral(runnerIdn); } - if (TOY_IS_IDENTIFIER(varName) || TOY_IS_IDENTIFIER(runnerLiteral)) { - Toy_freeLiteral(varName); - Toy_freeLiteral(runnerLiteral); - return -1; - } - if (TOY_GET_OPAQUE_TAG(runnerLiteral) != TOY_OPAQUE_TAG_RUNNER) { interpreter->errorOutput("Unrecognized opaque literal in callScriptFn\n"); return -1; @@ -377,11 +350,6 @@ static int nativeResetScript(Toy_Interpreter* interpreter, Toy_LiteralArray* arg Toy_freeLiteral(runnerIdn); } - if (TOY_IS_IDENTIFIER(runnerLiteral)) { - Toy_freeLiteral(runnerLiteral); - return -1; - } - if (TOY_GET_OPAQUE_TAG(runnerLiteral) != TOY_OPAQUE_TAG_RUNNER) { interpreter->errorOutput("Unrecognized opaque literal in resetScript\n"); return -1; @@ -418,11 +386,6 @@ static int nativeFreeScript(Toy_Interpreter* interpreter, Toy_LiteralArray* argu Toy_freeLiteral(runnerIdn); } - if (TOY_IS_IDENTIFIER(runnerLiteral)) { - Toy_freeLiteral(runnerLiteral); - return -1; - } - if (TOY_GET_OPAQUE_TAG(runnerLiteral) != TOY_OPAQUE_TAG_RUNNER) { interpreter->errorOutput("Unrecognized opaque literal in freeScript\n"); return -1; @@ -457,11 +420,6 @@ static int nativeCheckScriptDirty(Toy_Interpreter* interpreter, Toy_LiteralArray Toy_freeLiteral(runnerIdn); } - if (TOY_IS_IDENTIFIER(runnerLiteral)) { - Toy_freeLiteral(runnerLiteral); - return -1; - } - if (TOY_GET_OPAQUE_TAG(runnerLiteral) != TOY_OPAQUE_TAG_RUNNER) { interpreter->errorOutput("Unrecognized opaque literal in checkScriptDirty\n"); return -1; diff --git a/repl/lib_standard.c b/repl/lib_standard.c index 2a348b1..3c31403 100644 --- a/repl/lib_standard.c +++ b/repl/lib_standard.c @@ -1502,12 +1502,6 @@ static int nativeSort(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) Toy_freeLiteral(fnLiteralIdn); } - if (TOY_IS_IDENTIFIER(selfLiteral) || TOY_IS_IDENTIFIER(fnLiteral)) { - Toy_freeLiteral(selfLiteral); - Toy_freeLiteral(fnLiteral); - return -1; - } - //check type if (!TOY_IS_ARRAY(selfLiteral) || !( TOY_IS_FUNCTION(fnLiteral) || TOY_IS_FUNCTION_NATIVE(fnLiteral) )) { interpreter->errorOutput("Incorrect argument type passed to sort\n"); @@ -1570,11 +1564,6 @@ static int nativeToLower(Toy_Interpreter* interpreter, Toy_LiteralArray* argumen Toy_freeLiteral(selfLiteralIdn); } - if (TOY_IS_IDENTIFIER(selfLiteral)) { - Toy_freeLiteral(selfLiteral); - return -1; - } - if (!TOY_IS_STRING(selfLiteral)) { interpreter->errorOutput("Incorrect argument type passed to toLower\n"); Toy_freeLiteral(selfLiteral); @@ -1636,17 +1625,6 @@ static int nativeToString(Toy_Interpreter* interpreter, Toy_LiteralArray* argume Toy_freeLiteral(selfLiteralIdn); } - if (TOY_IS_IDENTIFIER(selfLiteral)) { - Toy_freeLiteral(selfLiteral); - return -1; - } - - //BUGFIX: probably an undefined variable - if (TOY_IS_IDENTIFIER(selfLiteral)) { - Toy_freeLiteral(selfLiteral); - return -1; - } - //print it to a custom function Toy_printLiteralCustom(selfLiteral, toStringUtil); @@ -1680,11 +1658,6 @@ static int nativeToUpper(Toy_Interpreter* interpreter, Toy_LiteralArray* argumen Toy_freeLiteral(selfLiteralIdn); } - if (TOY_IS_IDENTIFIER(selfLiteral)) { - Toy_freeLiteral(selfLiteral); - return -1; - } - if (!TOY_IS_STRING(selfLiteral)) { interpreter->errorOutput("Incorrect argument type passed to toUpper\n"); Toy_freeLiteral(selfLiteral); @@ -1745,12 +1718,6 @@ static int nativeTrim(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) Toy_freeLiteral(selfLiteralIdn); } - if (TOY_IS_IDENTIFIER(selfLiteral) || TOY_IS_IDENTIFIER(trimCharsLiteral)) { - Toy_freeLiteral(selfLiteral); - Toy_freeLiteral(trimCharsLiteral); - return -1; - } - if (!TOY_IS_STRING(selfLiteral) || !TOY_IS_STRING(trimCharsLiteral)) { interpreter->errorOutput("Incorrect argument type passed to trim\n"); Toy_freeLiteral(trimCharsLiteral); @@ -1862,12 +1829,6 @@ static int nativeTrimBegin(Toy_Interpreter* interpreter, Toy_LiteralArray* argum Toy_freeLiteral(selfLiteralIdn); } - if (TOY_IS_IDENTIFIER(selfLiteral) || TOY_IS_IDENTIFIER(trimCharsLiteral)) { - Toy_freeLiteral(selfLiteral); - Toy_freeLiteral(trimCharsLiteral); - return -1; - } - if (!TOY_IS_STRING(selfLiteral) || !TOY_IS_STRING(trimCharsLiteral)) { interpreter->errorOutput("Incorrect argument type passed to trimBegin\n"); Toy_freeLiteral(trimCharsLiteral); @@ -1956,12 +1917,6 @@ static int nativeTrimEnd(Toy_Interpreter* interpreter, Toy_LiteralArray* argumen Toy_freeLiteral(selfLiteralIdn); } - if (TOY_IS_IDENTIFIER(selfLiteral) || TOY_IS_IDENTIFIER(trimCharsLiteral)) { - Toy_freeLiteral(selfLiteral); - Toy_freeLiteral(trimCharsLiteral); - return -1; - } - if (!TOY_IS_STRING(selfLiteral) || !TOY_IS_STRING(trimCharsLiteral)) { interpreter->errorOutput("Incorrect argument type passed to trimEnd\n"); Toy_freeLiteral(trimCharsLiteral);