added argument type annotations and runtime checks. To do that new opcodes were created (PUSHTYP, PUSHTYPTYP, ERROR)

This commit is contained in:
cozis
2022-08-14 16:25:47 +02:00
parent bc516f470a
commit 6bd60bc84a
18 changed files with 571 additions and 68 deletions
+42
View File
@@ -1147,6 +1147,39 @@ static _Bool step(Runtime *runtime, Error *error)
return 1;
}
case OPCODE_PUSHTYPTYP:
{
assert(opc == 0);
Object *obj = (Object*) Object_GetTypeType();
assert(obj != NULL);
if(!Runtime_Push(runtime, error, obj))
return 0;
return 1;
}
case OPCODE_PUSHTYP:
{
assert(opc == 0);
if(runtime->frame->used < 1)
{
Error_Report(error, 1, "Frame has not enough values on the stack to run PUSHTYP instruction");
return 0;
}
Object *top = Stack_Top(runtime->stack, 0);
assert(top != NULL);
Object *typ = (Object*) Object_GetType(top);
assert(typ != NULL);
if(!Runtime_Push(runtime, error, typ))
return 0;
return 1;
}
case OPCODE_RETURN:
{
assert(opc == 1);
@@ -1157,6 +1190,15 @@ static _Bool step(Runtime *runtime, Error *error)
return 0;
}
case OPCODE_ERROR:
{
assert(opc == 1);
assert(ops[0].type == OPTP_STRING);
const char *msg = ops[0].as_string;
Error_Report(error, 0, "%s", msg);
return 0;
}
case OPCODE_JUMP:
assert(opc == 1);
assert(ops[0].type == OPTP_INT);