cleaning up tests

This commit is contained in:
2022-09-06 09:22:50 +01:00
parent b8f20add66
commit 17f1dc8647
10 changed files with 116 additions and 36 deletions

View File

@@ -306,7 +306,7 @@ static Opcode writeCompilerWithJumps(Compiler* compiler, Node* node, void* break
//pass to the child nodes, then embed the binary command (math, etc.)
Opcode override = writeCompilerWithJumps(compiler, node->binary.left, breakAddressesPtr, continueAddressesPtr, jumpOffsets);
//special case for when indexing
//special case for when indexing and assigning
if (override != OP_EOF && node->binary.opcode >= OP_VAR_ASSIGN && node->binary.opcode <= OP_VAR_MODULO_ASSIGN) {
writeCompilerWithJumps(compiler, node->binary.right, breakAddressesPtr, continueAddressesPtr, jumpOffsets);
compiler->bytecode[compiler->count++] = (unsigned char)override + 2; //1 byte WARNING: enum arithmetic
@@ -314,6 +314,11 @@ static Opcode writeCompilerWithJumps(Compiler* compiler, Node* node, void* break
return OP_EOF;
}
//compensate for... yikes
if (override != OP_EOF) {
compiler->bytecode[compiler->count++] = (unsigned char)override; //1 byte
}
//return from the index-binary
Opcode ret = writeCompilerWithJumps(compiler, node->binary.right, breakAddressesPtr, continueAddressesPtr, jumpOffsets);

View File

@@ -1355,6 +1355,8 @@ static bool execIndex(Interpreter* interpreter) {
if (!IS_IDENTIFIER(compound)) {
interpreter->errorOutput("Unknown literal found in indexing notation\n");
printLiteralCustom(compound, interpreter->errorOutput);
interpreter->errorOutput("\n");
freeLiteral(third);
freeLiteral(second);
freeLiteral(first);
@@ -1434,6 +1436,8 @@ static bool execDot(Interpreter* interpreter) {
if (!IS_IDENTIFIER(compound)) {
interpreter->errorOutput("Unknown literal found in dot notation\n");
printLiteralCustom(compound, interpreter->errorOutput);
interpreter->errorOutput("\n");
freeLiteral(first);
freeLiteral(compound);
return false;
@@ -1500,6 +1504,8 @@ static bool execIndexAssign(Interpreter* interpreter) {
if (!IS_IDENTIFIER(compound)) {
interpreter->errorOutput("Unknown literal found in index assigning notation\n");
printLiteralCustom(compound, interpreter->errorOutput);
interpreter->errorOutput("\n");
freeLiteral(assign);
freeLiteral(third);
freeLiteral(second);
@@ -1669,6 +1675,8 @@ static bool execDotAssign(Interpreter* interpreter) {
if (!IS_IDENTIFIER(compound)) {
interpreter->errorOutput("Unknown literal found in dot assigning notation\n");
printLiteralCustom(compound, interpreter->errorOutput);
interpreter->errorOutput("\n");
freeLiteral(assign);
freeLiteral(first);
freeLiteral(compound);

View File

@@ -41,7 +41,6 @@ int _index(Interpreter* interpreter, LiteralArray* arguments) {
if (IS_DICTIONARY(compound)) {
value = getLiteralDictionary(AS_DICTIONARY(compound), first);
//dictionary
//dictionary
if (IS_NULL(op)) {
pushLiteralArray(&interpreter->stack, value);
@@ -525,6 +524,8 @@ int _index(Interpreter* interpreter, LiteralArray* arguments) {
for (int i = AS_INTEGER(second) + 1; i < strlen(AS_STRING(compound)); i++) {
result[ resultIndex++ ] = AS_STRING(compound)[ i ];
}
result[ resultIndex++ ] = '\0';
}
//else override elements of the array instead
@@ -532,7 +533,7 @@ int _index(Interpreter* interpreter, LiteralArray* arguments) {
//copy compound to result
snprintf(result, MAX_STRING_LENGTH, AS_STRING(compound));
int min = AS_INTEGER(third) > 0 ? AS_INTEGER(first) : AS_INTEGER(second);
int min = AS_INTEGER(third) > 0 ? AS_INTEGER(first) : AS_INTEGER(second) - 1;
int assignIndex = 0;
for (int i = min; i >= AS_INTEGER(first) && i <= AS_INTEGER(second) && assignIndex < strlen(AS_STRING(assign)); i += AS_INTEGER(third)) {

View File

@@ -55,7 +55,7 @@ typedef enum Opcode {
OP_INDEX_ASSIGN,
OP_DOT_ASSIGN,
//comparion of values
//comparison of values
OP_COMPARE_EQUAL,
OP_COMPARE_NOT_EQUAL,
OP_COMPARE_LESS,

View File

@@ -530,6 +530,11 @@ static Opcode identifier(Parser* parser, Node** nodeHandle) {
//make a copy of the string
Token identifierToken = parser->previous;
if (identifierToken.type != TOKEN_IDENTIFIER) {
error(parser, parser->previous, "Expected identifier");
return OP_EOF;
}
int length = identifierToken.length;
//for safety
@@ -739,10 +744,10 @@ static Opcode indexAccess(Parser* parser, Node** nodeHandle) {
}
if (match(parser, TOKEN_BRACKET_RIGHT)) {
// freeNode(second);
// freeNode(third);
// second = NULL;
// third = NULL;
freeNode(second);
freeNode(third);
second = NULL;
third = NULL;
emitNodeIndex(nodeHandle, first, second, third);
return OP_INDEX;
@@ -756,8 +761,8 @@ static Opcode indexAccess(Parser* parser, Node** nodeHandle) {
}
if (match(parser, TOKEN_BRACKET_RIGHT)) {
// freeNode(third);
// third = NULL;
freeNode(third);
third = NULL;
emitNodeIndex(nodeHandle, first, second, third);
return OP_INDEX;
}
@@ -1267,6 +1272,11 @@ static void importStmt(Parser* parser, Node** nodeHandle) {
Node* node = NULL;
advance(parser);
identifier(parser, &node);
if (node == NULL) {
return;
}
Literal idn = copyLiteral(node->atomic.literal);
freeNode(node);
@@ -1292,6 +1302,11 @@ static void exportStmt(Parser* parser, Node** nodeHandle) {
Node* node = NULL;
advance(parser);
identifier(parser, &node);
if (node == NULL) {
return;
}
Literal idn = copyLiteral(node->atomic.literal);
freeNode(node);