added assignment operator

This commit is contained in:
cozis
2021-11-01 15:55:59 +00:00
parent 7f37c51f98
commit 5bf6a9f085
12 changed files with 132 additions and 28 deletions
+26 -2
View File
@@ -83,7 +83,7 @@ _Bool Runtime_Push(Runtime *runtime, Error *error, Object *obj)
if(runtime->frame->used == MAX_FRAME_STACK)
{
Error_Report(error, 0, "Frames stack limit of %d reached", MAX_FRAME_STACK);
Error_Report(error, 0, "Frame stack limit of %d reached", MAX_FRAME_STACK);
return 0;
}
@@ -112,7 +112,7 @@ _Bool Runtime_Pop(Runtime *runtime, Error *error, unsigned int n)
if((unsigned int) runtime->frame->used < n)
{
Error_Report(error, 0, "Frames has not enough values on the stack");
Error_Report(error, 0, "Frame has not enough values on the stack");
return 0;
}
@@ -365,6 +365,30 @@ static _Bool step(Runtime *runtime, Error *error)
break;
}
case OPCODE_ASS:
{
assert(opc == 1);
assert(ops[0].type == OPTP_STRING);
if(runtime->frame->used == 0)
{
Error_Report(error, 0, "Frame has not enough values on the stack");
return 0;
}
Object *val = Stack_Top(runtime->stack, 0);
assert(val != NULL);
Object *key = Object_FromString(ops[0].as_string, -1, runtime->heap, error);
if(key == NULL)
return 0;
if(!Object_Insert(runtime->frame->vars, key, val, runtime->heap, error))
return 0;
return 1;
}
case OPCODE_POP:
{
assert(opc == 1);