mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
Merge branch 'dev'
This commit is contained in:
@@ -621,7 +621,7 @@ int Toy_private_index(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments)
|
|||||||
|
|
||||||
//simple indexing assignment if second is null
|
//simple indexing assignment if second is null
|
||||||
if (TOY_IS_NULL(second)) {
|
if (TOY_IS_NULL(second)) {
|
||||||
bool ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (!Toy_setLiteralArray(TOY_AS_ARRAY(compound), first, assign)) {
|
if (!Toy_setLiteralArray(TOY_AS_ARRAY(compound), first, assign)) {
|
||||||
interpreter->errorOutput("Array index out of bounds in assignment");
|
interpreter->errorOutput("Array index out of bounds in assignment");
|
||||||
@@ -629,6 +629,7 @@ int Toy_private_index(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Toy_pushLiteralArray(&interpreter->stack, compound); //leave the array on the stack
|
Toy_pushLiteralArray(&interpreter->stack, compound); //leave the array on the stack
|
||||||
|
//...
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1689,7 +1689,7 @@ static bool execIndex(Toy_Interpreter* interpreter, bool assignIntermediate) {
|
|||||||
Toy_pushLiteralArray(&interpreter->stack, third);
|
Toy_pushLiteralArray(&interpreter->stack, third);
|
||||||
}
|
}
|
||||||
|
|
||||||
//call the _index function
|
//call the index function
|
||||||
if (Toy_private_index(interpreter, &arguments) < 0) {
|
if (Toy_private_index(interpreter, &arguments) < 0) {
|
||||||
interpreter->errorOutput("Something went wrong while indexing (simple index): ");
|
interpreter->errorOutput("Something went wrong while indexing (simple index): ");
|
||||||
Toy_printLiteralCustom(compoundIdn, interpreter->errorOutput);
|
Toy_printLiteralCustom(compoundIdn, interpreter->errorOutput);
|
||||||
@@ -1723,61 +1723,14 @@ static bool execIndex(Toy_Interpreter* interpreter, bool assignIntermediate) {
|
|||||||
static bool execIndexAssign(Toy_Interpreter* interpreter) {
|
static bool execIndexAssign(Toy_Interpreter* interpreter) {
|
||||||
//assume -> compound, first, second, third, assign are all on the stack
|
//assume -> compound, first, second, third, assign are all on the stack
|
||||||
|
|
||||||
Toy_Literal assign = Toy_popLiteralArray(&interpreter->stack);
|
Toy_Literal assign = TOY_TO_NULL_LITERAL, third = TOY_TO_NULL_LITERAL, second = TOY_TO_NULL_LITERAL, first = TOY_TO_NULL_LITERAL, compound = TOY_TO_NULL_LITERAL, result = TOY_TO_NULL_LITERAL;
|
||||||
Toy_Literal third = Toy_popLiteralArray(&interpreter->stack);
|
Toy_Literal compoundIdn = TOY_TO_NULL_LITERAL;
|
||||||
Toy_Literal second = Toy_popLiteralArray(&interpreter->stack);
|
|
||||||
Toy_Literal first = Toy_popLiteralArray(&interpreter->stack);
|
|
||||||
Toy_Literal compound = Toy_popLiteralArray(&interpreter->stack);
|
|
||||||
|
|
||||||
Toy_Literal assignIdn = assign;
|
|
||||||
if (TOY_IS_IDENTIFIER(assign) && Toy_parseIdentifierToValue(interpreter, &assign)) {
|
|
||||||
Toy_freeLiteral(assignIdn);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TOY_IS_IDENTIFIER(assign)) {
|
|
||||||
Toy_freeLiteral(compound);
|
|
||||||
Toy_freeLiteral(first);
|
|
||||||
Toy_freeLiteral(second);
|
|
||||||
Toy_freeLiteral(third);
|
|
||||||
Toy_freeLiteral(assign);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Toy_Literal compoundIdn = compound;
|
|
||||||
bool freeIdn = false;
|
bool freeIdn = false;
|
||||||
if (TOY_IS_IDENTIFIER(compound) && Toy_parseIdentifierToValue(interpreter, &compound)) {
|
|
||||||
freeIdn = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TOY_IS_IDENTIFIER(compound)) {
|
|
||||||
Toy_freeLiteral(compound);
|
|
||||||
Toy_freeLiteral(first);
|
|
||||||
Toy_freeLiteral(second);
|
|
||||||
Toy_freeLiteral(third);
|
|
||||||
Toy_freeLiteral(assign);
|
|
||||||
if (freeIdn) {
|
|
||||||
Toy_freeLiteral(compoundIdn);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!TOY_IS_ARRAY(compound) && !TOY_IS_DICTIONARY(compound) && !TOY_IS_STRING(compound)) {
|
|
||||||
interpreter->errorOutput("Unknown compound found in index assigning notation\n");
|
|
||||||
Toy_freeLiteral(assign);
|
|
||||||
Toy_freeLiteral(third);
|
|
||||||
Toy_freeLiteral(second);
|
|
||||||
Toy_freeLiteral(first);
|
|
||||||
Toy_freeLiteral(compound);
|
|
||||||
if (freeIdn) {
|
|
||||||
Toy_freeLiteral(compoundIdn);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//build the opcode
|
//build the opcode
|
||||||
unsigned char opcode = readByte(interpreter->bytecode, &interpreter->count);
|
unsigned char opcode = readByte(interpreter->bytecode, &interpreter->count);
|
||||||
char* opStr = "";
|
char* opStr = "";
|
||||||
switch(opcode) {
|
switch (opcode) {
|
||||||
case TOY_OP_VAR_ASSIGN:
|
case TOY_OP_VAR_ASSIGN:
|
||||||
opStr = "=";
|
opStr = "=";
|
||||||
break;
|
break;
|
||||||
@@ -1799,6 +1752,74 @@ static bool execIndexAssign(Toy_Interpreter* interpreter) {
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
interpreter->errorOutput("bad opcode in index assigning notation\n");
|
interpreter->errorOutput("bad opcode in index assigning notation\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//iterate...
|
||||||
|
while(interpreter->stack.count > 1) {
|
||||||
|
Toy_freeLiteral(assign);
|
||||||
|
Toy_freeLiteral(third);
|
||||||
|
Toy_freeLiteral(second);
|
||||||
|
Toy_freeLiteral(first);
|
||||||
|
Toy_freeLiteral(compound);
|
||||||
|
|
||||||
|
if (TOY_IS_NULL(result)) {
|
||||||
|
assign = Toy_popLiteralArray(&interpreter->stack);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
compound = result;
|
||||||
|
Toy_freeLiteral(result);
|
||||||
|
|
||||||
|
//suppress the extra assign value
|
||||||
|
Toy_Literal tmp = Toy_popLiteralArray(&interpreter->stack);
|
||||||
|
Toy_freeLiteral(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
third = Toy_popLiteralArray(&interpreter->stack);
|
||||||
|
second = Toy_popLiteralArray(&interpreter->stack);
|
||||||
|
first = Toy_popLiteralArray(&interpreter->stack);
|
||||||
|
compound = Toy_popLiteralArray(&interpreter->stack);
|
||||||
|
|
||||||
|
if (TOY_IS_IDENTIFIER(compound)) {
|
||||||
|
if (freeIdn) {
|
||||||
|
Toy_freeLiteral(compoundIdn);
|
||||||
|
}
|
||||||
|
|
||||||
|
compoundIdn = compound;
|
||||||
|
Toy_parseIdentifierToValue(interpreter, &compound);
|
||||||
|
freeIdn = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TOY_IS_IDENTIFIER(compound)) {
|
||||||
|
Toy_freeLiteral(compound);
|
||||||
|
Toy_freeLiteral(first);
|
||||||
|
Toy_freeLiteral(second);
|
||||||
|
Toy_freeLiteral(third);
|
||||||
|
Toy_freeLiteral(assign);
|
||||||
|
if (freeIdn) {
|
||||||
|
Toy_freeLiteral(compoundIdn);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Toy_Literal assignIdn = assign;
|
||||||
|
if (TOY_IS_IDENTIFIER(assign) && Toy_parseIdentifierToValue(interpreter, &assign)) {
|
||||||
|
Toy_freeLiteral(assignIdn);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TOY_IS_IDENTIFIER(assign)) {
|
||||||
|
Toy_freeLiteral(compound);
|
||||||
|
Toy_freeLiteral(first);
|
||||||
|
Toy_freeLiteral(second);
|
||||||
|
Toy_freeLiteral(third);
|
||||||
|
Toy_freeLiteral(assign);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TOY_IS_ARRAY(compound) && !TOY_IS_DICTIONARY(compound) && !TOY_IS_STRING(compound)) {
|
||||||
|
interpreter->errorOutput("Unknown compound found in index assigning notation: ");
|
||||||
|
Toy_printLiteralCustom(compound, interpreter->errorOutput);
|
||||||
|
interpreter->errorOutput("\n");
|
||||||
Toy_freeLiteral(assign);
|
Toy_freeLiteral(assign);
|
||||||
Toy_freeLiteral(third);
|
Toy_freeLiteral(third);
|
||||||
Toy_freeLiteral(second);
|
Toy_freeLiteral(second);
|
||||||
@@ -1824,7 +1845,7 @@ static bool execIndexAssign(Toy_Interpreter* interpreter) {
|
|||||||
Toy_pushLiteralArray(&arguments, assign); //it expects an assignment command
|
Toy_pushLiteralArray(&arguments, assign); //it expects an assignment command
|
||||||
Toy_pushLiteralArray(&arguments, op); //it expects an assignment "opcode"
|
Toy_pushLiteralArray(&arguments, op); //it expects an assignment "opcode"
|
||||||
|
|
||||||
//call the _index function
|
//call the index function
|
||||||
if (Toy_private_index(interpreter, &arguments) < 0) {
|
if (Toy_private_index(interpreter, &arguments) < 0) {
|
||||||
//clean up
|
//clean up
|
||||||
Toy_freeLiteral(assign);
|
Toy_freeLiteral(assign);
|
||||||
@@ -1842,69 +1863,17 @@ static bool execIndexAssign(Toy_Interpreter* interpreter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//save the result (assume top of the interpreter stack is the new compound value)
|
//save the result (assume top of the interpreter stack is the new compound value)
|
||||||
Toy_Literal result = Toy_popLiteralArray(&interpreter->stack);
|
|
||||||
|
|
||||||
//deep
|
|
||||||
if (!freeIdn) {
|
|
||||||
while (interpreter->stack.count > 1) {
|
|
||||||
//read the new values
|
|
||||||
Toy_freeLiteral(compound);
|
|
||||||
Toy_freeLiteral(third);
|
|
||||||
Toy_freeLiteral(second);
|
|
||||||
Toy_freeLiteral(first);
|
|
||||||
Toy_freeLiteralArray(&arguments);
|
|
||||||
Toy_initLiteralArray(&arguments);
|
|
||||||
Toy_freeLiteral(op);
|
|
||||||
|
|
||||||
//reuse these like an idiot
|
|
||||||
third = Toy_popLiteralArray(&interpreter->stack);
|
|
||||||
second = Toy_popLiteralArray(&interpreter->stack);
|
|
||||||
first = Toy_popLiteralArray(&interpreter->stack);
|
|
||||||
compound = Toy_popLiteralArray(&interpreter->stack);
|
|
||||||
|
|
||||||
char* opStr = "="; //shadow, but force assignment
|
|
||||||
int opLength = strlen(opStr);
|
|
||||||
op = TOY_TO_STRING_LITERAL(Toy_createRefStringLength(opStr, opLength)); //TODO: static reference optimisation?
|
|
||||||
|
|
||||||
//assign to the idn / compound - with _index
|
|
||||||
Toy_pushLiteralArray(&arguments, compound); //
|
|
||||||
Toy_pushLiteralArray(&arguments, first);
|
|
||||||
Toy_pushLiteralArray(&arguments, second);
|
|
||||||
Toy_pushLiteralArray(&arguments, third);
|
|
||||||
Toy_pushLiteralArray(&arguments, result);
|
|
||||||
Toy_pushLiteralArray(&arguments, op);
|
|
||||||
|
|
||||||
if (Toy_private_index(interpreter, &arguments) < 0) {
|
|
||||||
interpreter->errorOutput("Something went wrong while indexing (index assign): ");
|
|
||||||
Toy_printLiteralCustom(compound, interpreter->errorOutput);
|
|
||||||
interpreter->errorOutput("\n");
|
|
||||||
|
|
||||||
//clean up
|
|
||||||
Toy_freeLiteral(assign);
|
|
||||||
Toy_freeLiteral(third);
|
|
||||||
Toy_freeLiteral(second);
|
|
||||||
Toy_freeLiteral(first);
|
|
||||||
if (freeIdn) {
|
|
||||||
Toy_freeLiteral(compoundIdn);
|
|
||||||
}
|
|
||||||
Toy_freeLiteral(op);
|
|
||||||
Toy_freeLiteralArray(&arguments);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Toy_freeLiteral(result);
|
|
||||||
result = Toy_popLiteralArray(&interpreter->stack);
|
result = Toy_popLiteralArray(&interpreter->stack);
|
||||||
}
|
|
||||||
|
|
||||||
Toy_freeLiteral(compound);
|
Toy_freeLiteral(op);
|
||||||
compound = Toy_popLiteralArray(&interpreter->stack);
|
Toy_freeLiteralArray(&arguments);
|
||||||
compoundIdn = compound;
|
|
||||||
freeIdn = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TOY_IS_IDENTIFIER(compoundIdn) && !Toy_setScopeVariable(interpreter->scope, compoundIdn, result, true)) {
|
if (TOY_IS_IDENTIFIER(compoundIdn) && !Toy_setScopeVariable(interpreter->scope, compoundIdn, result, true)) {
|
||||||
interpreter->errorOutput("Incorrect type assigned to compound member ");
|
interpreter->errorOutput("Incorrect type assigned to compound member ");
|
||||||
Toy_printLiteralCustom(compoundIdn, interpreter->errorOutput);
|
Toy_printLiteralCustom(compoundIdn, interpreter->errorOutput);
|
||||||
|
interpreter->errorOutput(", value: ");
|
||||||
|
Toy_printLiteralCustom(result, interpreter->errorOutput);
|
||||||
interpreter->errorOutput("\n");
|
interpreter->errorOutput("\n");
|
||||||
|
|
||||||
//clean up
|
//clean up
|
||||||
@@ -1916,8 +1885,6 @@ static bool execIndexAssign(Toy_Interpreter* interpreter) {
|
|||||||
if (freeIdn) {
|
if (freeIdn) {
|
||||||
Toy_freeLiteral(compoundIdn);
|
Toy_freeLiteral(compoundIdn);
|
||||||
}
|
}
|
||||||
Toy_freeLiteral(op);
|
|
||||||
Toy_freeLiteralArray(&arguments);
|
|
||||||
Toy_freeLiteral(result);
|
Toy_freeLiteral(result);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1931,8 +1898,6 @@ static bool execIndexAssign(Toy_Interpreter* interpreter) {
|
|||||||
if (freeIdn) {
|
if (freeIdn) {
|
||||||
Toy_freeLiteral(compoundIdn);
|
Toy_freeLiteral(compoundIdn);
|
||||||
}
|
}
|
||||||
Toy_freeLiteral(op);
|
|
||||||
Toy_freeLiteralArray(&arguments);
|
|
||||||
Toy_freeLiteral(result);
|
Toy_freeLiteral(result);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user