fix: do not fix extra root if it points to lama stack; uncomment extra roots registration; rise error if binary operation is done over pointers

This commit is contained in:
danyaberezun 2023-07-03 17:58:55 +02:00
parent 8bc173762d
commit ce0b369958
3 changed files with 134 additions and 43 deletions

View file

@ -306,9 +306,32 @@ let compile cmd env imports code =
| _ -> [Mov (v, eax); Mov (eax, I (0, x)); Mov (eax, x)]
)
| BINOP op ->
| BINOP op ->
let x, y, env' = env#pop2 in
env'#push y,
(match op with
|"<" | "<=" | "==" | "!=" | ">=" | ">" ->
[Push (eax);
Push (edx);
Mov (y, eax);
Binop("&&", L(1), eax);
Mov (x, edx);
Binop("&&", L(1), edx);
Binop("cmp", eax, edx);
CJmp ("nz", "_ERROR2");
Pop (edx);
Pop (eax)]
(* | "+" | "-" | "*" | "/" -> *)
| _ ->
[Mov (y, eax);
Binop("&&", L(1), eax);
Binop("cmp", L(0), eax);
CJmp ("z", "_ERROR");
Mov (x, eax);
Binop("&&", L(1), eax);
Binop("cmp", L(0), eax);
CJmp ("z", "_ERROR")]
| _ -> []) @
(match op with
| "/" ->
[Mov (y, eax);
@ -443,6 +466,12 @@ let compile cmd env imports code =
Binop ("test", eax, eax);
CJmp ("z", "_continue");
Ret;
Label ("_ERROR");
Call "Lbinoperror";
Ret;
Label ("_ERROR2");
Call "Lbinoperror2";
Ret;
Label "_continue";
Mov (L 1, M "_init");
]