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
+33
View File
@@ -0,0 +1,33 @@
#source
fun nop(a: None) {
return a;
}
#bytecode
PUSHFUN fun, 1;
ASS "nop";
POP 1;
JUMP end;
fun:
PUSHTYP;
PUSHVAR "None";
PUSHTYP;
PUSHTYPTYP;
EQL;
JUMPIFNOTANDPOP arg_annot_not_type;
EQL;
JUMPIFANDPOP arg_ok;
ERROR "Bad type for argument 0";
arg_annot_not_type:
ERROR "Argument 0 type annotation 0 is not a type";
arg_ok:
ASS "a";
POP 1;
PUSHVAR "a";
RETURN 1;
RETURN 0;
end:
RETURN 0;