Fixed pattern matching in SM

This commit is contained in:
Dmitry Boulytchev 2018-05-11 02:40:52 +03:00
parent a5dbf5156a
commit 34767b9dcb
2 changed files with 63 additions and 42 deletions

View file

@ -251,6 +251,18 @@ let compile env code =
else env, [Jmp env#epilogue]
| CALL (f, n, p) -> call env f n p
(*
| SEXP (t, n) ->
| DROP -> snd env#pop, []
| DUP -> let x = env#peek in
let s, env = env#allocate in
env, [Mov (x, s)]
| SWAP -> let x, y = env#peek2 in
env, [Push x; Push y; Pop x; Pop y]
| TAG t
| ENTER xs
| LEAVE *)
in
let env'', code'' = compile' env' scode' in
env'', code' @ code''
@ -287,11 +299,10 @@ class env =
method allocate =
let x, n =
let rec allocate' = function
| [] -> ebx , 0
| (S n)::_ -> S (n+1) , n+2
| (R n)::_ when n < num_of_regs -> R (n+1) , stack_slots
| (M _)::s -> allocate' s
| _ -> S 0 , 1
| [] -> ebx , 0
| (S n)::_ -> S (n+1) , n+2
| (R n)::_ when n < num_of_regs -> R (n+1) , stack_slots
| _ -> S stack_slots, stack_slots+1
in
allocate' stack
in