summaryrefslogtreecommitdiff
path: root/src/jib/jib_compile.ml
diff options
context:
space:
mode:
authorAlasdair Armstrong2019-03-22 16:14:23 +0000
committerAlasdair Armstrong2019-03-22 16:16:16 +0000
commitc9471630ad64af00a58a3c92f4b6a22f2194e9ee (patch)
treeb3ccdf6840378de84943fc6f48b96afa33aa3422 /src/jib/jib_compile.ml
parent2b0a4e2746e632d3f823baade49b560f79317497 (diff)
C: Fix as-patterns in C output
Most such patterns are re-written away by various re-writing steps, but for those that arn't they are fairly easy to handle by just having as patterns directly in the ANF-patterns. Fixes #39
Diffstat (limited to 'src/jib/jib_compile.ml')
-rw-r--r--src/jib/jib_compile.ml7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/jib/jib_compile.ml b/src/jib/jib_compile.ml
index 15f945e5..c13b814f 100644
--- a/src/jib/jib_compile.ml
+++ b/src/jib/jib_compile.ml
@@ -416,6 +416,7 @@ let rec apat_ctyp ctx (AP_aux (apat, _, _)) =
| AP_cons (apat, _) -> CT_list (apat_ctyp ctx apat)
| AP_wild typ | AP_nil typ | AP_id (_, typ) -> ctyp_of_typ ctx typ
| AP_app (_, _, typ) -> ctyp_of_typ ctx typ
+ | AP_as (_, _, typ) -> ctyp_of_typ ctx typ
let rec compile_match ctx (AP_aux (apat_aux, env, l)) cval case_label =
let ctx = { ctx with local_env = env } in
@@ -441,6 +442,12 @@ let rec compile_match ctx (AP_aux (apat_aux, env, l)) cval case_label =
let ctx = { ctx with locals = Bindings.add pid (Immutable, id_ctyp) ctx.locals } in
[idecl id_ctyp (name pid); icopy l (CL_id (name pid, id_ctyp)) cval], [iclear id_ctyp (name pid)], ctx
+ | AP_as (apat, id, typ), _ ->
+ let id_ctyp = ctyp_of_typ ctx typ in
+ let instrs, cleanup, ctx = compile_match ctx apat cval case_label in
+ let ctx = { ctx with locals = Bindings.add id (Immutable, id_ctyp) ctx.locals } in
+ instrs @ [idecl id_ctyp (name id); icopy l (CL_id (name id, id_ctyp)) cval], iclear id_ctyp (name id) :: cleanup, ctx
+
| AP_tup apats, (frag, ctyp) ->
begin
let get_tup n ctyp = (F_field (frag, "ztup" ^ string_of_int n), ctyp) in