%{^
#include "ats_counter.cats" /* only needed for [ATS/Geizella] */
%}
staload Deb = "ats_debug.sats"
staload Err = "ats_error.sats"
staload Loc = "ats_location.sats"
staload Lst = "ats_list.sats"
staload Stamp = "ats_stamp.sats"
staload Syn = "ats_syntax.sats"
staload "ats_staexp2.sats"
staload "ats_dynexp2.sats"
staload "ats_trans2_env.sats"
staload "ats_hiexp.sats"
staload "ats_ccomp.sats"
staload "ats_ccomp_env.sats"
typedef stamp_t = $Stamp.stamp_t
fn prerr_interror () = prerr "INTERNAL ERROR (ats_ccomp)"
local
typedef tmplab = '{
tmplab_stamp = stamp_t
}
assume tmplab_t = tmplab
fn _tmplab_make (): tmplab = '{
tmplab_stamp= $Stamp.tmplab_stamp_make ()
}
in
implement tmplab_make () = _tmplab_make ()
implement tmplab_stamp_get (tl) = tl.tmplab_stamp
implement
fprint_tmplab
(pf | out, tl) = () where {
val () = fprint1_string (pf | out, "__ats_lab_")
val () = $Stamp.fprint_stamp (pf | out, tl.tmplab_stamp)
}
end
local
typedef tmpvar = '{
tmpvar_typ= hityp_t
, tmpvar_ret= int
, tmpvar_top= int
, tmpvar_root= tmpvaropt
, tmpvar_stamp= stamp_t
}
assume tmpvar_t = tmpvar
in
extern typedef "tmpvar_t" = tmpvar
implement
fprint_tmpvar
(pf | out, tmp) = () where {
val () = fprint1_string (pf | out, "tmp(")
val () = $Stamp.fprint_stamp (pf | out, tmp.tmpvar_stamp)
val () = fprint1_string (pf | out, ")")
}
implement
eq_tmpvar_tmpvar (tmp1, tmp2) =
$Stamp.eq_stamp_stamp (tmp1.tmpvar_stamp, tmp2.tmpvar_stamp)
implement
compare_tmpvar_tmpvar (tmp1, tmp2) =
$Stamp.compare_stamp_stamp (tmp1.tmpvar_stamp, tmp2.tmpvar_stamp)
implement
tmpvar_make (hit) = let
val stamp = $Stamp.tmpvar_stamp_make () in '{
tmpvar_typ= hit
, tmpvar_ret= 0
, tmpvar_top= 0
, tmpvar_root= TMPVAROPTnone ()
, tmpvar_stamp= stamp
} end
extern fun tmpvar_ret_set
(tmp: tmpvar, ret: int): void = "atsccomp_tmpvar_ret_set"
implement
tmpvar_make_ret (hit) = let
val tmp = tmpvar_make (hit)
val () = tmpvar_ret_set (tmp, 1) in tmp
end
extern fun tmpvar_root_set
(tmp: tmpvar, otmp: tmpvaropt): void = "atsccomp_tmpvar_root_set"
implement
tmpvar_make_root (tmp) = let
val otmp = (case+ tmp.tmpvar_root of
| TMPVAROPTnone () => TMPVAROPTsome tmp | otmp => otmp
) : tmpvaropt
val () = tmpvar_root_set (tmp, otmp)
in
tmp
end
implement
tmpvarlst_make (hits) = let
val hits = hityplst_decode (hits)
fn aux (hit: hityp): tmpvar_t = tmpvar_make (hityp_encode hit)
in
$Lst.list_map_fun (hits, aux)
end
implement tmpvar_ret_get (tmp) = tmp.tmpvar_ret
implement tmpvar_top_get (tmp) = tmp.tmpvar_top
implement tmpvar_root_get (tmp) = tmp.tmpvar_root
implement tmpvar_stamp_get (tmp) = tmp.tmpvar_stamp
implement tmpvar_typ_get (tmp) = tmp.tmpvar_typ
implement tmpvar_is_void (tmp) = hityp_t_is_void (tmp.tmpvar_typ)
implement tmpvar_is_nonvoid (tmp) = begin
if hityp_t_is_void (tmp.tmpvar_typ) then false else true
end
end
local
typedef funlab = '{
funlab_name= string
, funlab_lev= int
, funlab_typ= hityp_t
, funlab_qua= d2cstopt
, funlab_stamp= stamp_t
, funlab_tailjoined= tmpvarlst
, funlab_entry= funentryopt
, funlab_prfck= int
}
assume funlab_t = funlab
in
extern typedef "funlab_t" = funlab
implement
fprint_funlab (pf | out, fl) = begin
fprint1_string (pf | out, fl.funlab_name)
end
implement
eq_funlab_funlab (fl1, fl2) = begin
$Stamp.eq_stamp_stamp (fl1.funlab_stamp, fl2.funlab_stamp)
end
implement
compare_funlab_funlab (fl1, fl2) = begin
$Stamp.compare_stamp_stamp (fl1.funlab_stamp, fl2.funlab_stamp)
end
fn _funlab_make (
name: string, level: int, hit: hityp_t, stamp: stamp_t, prfck: int
) : funlab = '{
funlab_name= name
, funlab_lev= level
, funlab_typ= hit
, funlab_qua= D2CSTOPTnone ()
, funlab_stamp= stamp
, funlab_tailjoined= list_nil ()
, funlab_entry= None ()
, funlab_prfck= prfck
}
implement
funlab_make_typ (hit) = let
val level = d2var_current_level_get ()
val stamp = $Stamp.funlab_stamp_make ()
val name = "__ats_fun_" + $Stamp.tostring_stamp stamp
in
_funlab_make (name, level, hit, stamp, 0)
end
implement
funlab_make_nam_typ
(name, hit) = let
val level = d2var_current_level_get ()
val stamp = $Stamp.funlab_stamp_make ()
in
_funlab_make (name, level, hit, stamp, 0)
end
fn global_cst_name_make
(d2c: d2cst_t): string = let
val extdef = d2cst_extdef_get d2c
in
case+ extdef of
| $Syn.DCSTEXTDEFnone () => $Sym.symbol_name (d2cst_sym_get d2c)
| $Syn.DCSTEXTDEFsome_fun name => name
| $Syn.DCSTEXTDEFsome_mac _name => begin
prerr_interror ();
prerr ": global_cst_name_make: DCSTEXTDEFcall: d2c = "; prerr_d2cst d2c;
prerr_newline ();
$Err.abort {string} ()
end end
implement
funlab_make_cst_typ
(d2c, tmparg, hit) = let
val is_global =
(case+ tmparg of list_cons _ => false | _ => true): bool
val name: string = (
if is_global then begin
global_cst_name_make (d2c)
end else let
val tmparg = hityplstlst_normalize (tmparg)
in
template_cst_name_make (d2c, tmparg)
end ) : string
val level = d2var_current_level_get ()
val stamp = $Stamp.funlab_stamp_make ()
val fl = _funlab_make (name, level, hit, stamp, 0)
val () = if is_global then funlab_qua_set (fl, D2CSTOPTsome d2c)
in
fl
end
implement
funlab_make_var_typ (d2v, hit) = let
val d2v_name = $Sym.symbol_name (d2var_sym_get d2v)
val level = d2var_current_level_get ()
val stamp = $Stamp.funlab_stamp_make ()
val stamp_name = $Stamp.tostring_stamp stamp
val name = tostringf ("%s_%s", @(d2v_name, stamp_name))
val name = string_of_strptr (name)
in
_funlab_make (name, level, hit, stamp, 0)
end
implement
funlab_make_cst_prfck (d2c) = let
val name = global_cst_name_make (d2c)
val hit = hityp_encode (
hityp_fun ($Syn.FUNCLOfun (), list_nil (), hityp_void)
) val stamp = $Stamp.funlab_stamp_make ()
val fl = _funlab_make (name, 0, hit, stamp, 1)
val () = funlab_qua_set (fl, D2CSTOPTsome d2c)
in
fl
end
implement funlab_name_get (fl) = fl.funlab_name
implement funlab_lev_get (fl) = fl.funlab_lev
implement funlab_typ_get (fl) = fl.funlab_typ
implement
funlab_typ_arg_get (fl) = let
val hit_fun = hityp_decode (fl.funlab_typ) in
case+ hit_fun.hityp_node of
| HITfun (_, hits_arg, _) =>
hityplst_encode (hits_arg)
| _ => begin
prerr_interror ();
prerr ": funlab_typ_arg_get: hit_fun = "; prerr_hityp hit_fun;
prerr_newline ();
$Err.abort {hityplst_t} ()
end
end
implement
funlab_typ_res_get (fl) = let
val hit_fun = hityp_decode (fl.funlab_typ) in
case+ hit_fun.hityp_node of
| HITfun (_, _, hit_res) =>
hityp_encode (hit_res)
| _ => begin
prerr_interror ();
prerr ": funlab_typ_res_get: hit_fun = "; prerr_hityp hit_fun;
prerr_newline ();
$Err.abort {hityp_t} ()
end
end
implement
funlab_funclo_get (fl) = let
val hit_fun = hityp_decode (fl.funlab_typ) in
case+ hit_fun.hityp_node of
| HITfun (funclo, _, _) => funclo
| _ => begin
prerr_interror ();
prerr ": funlab_funclo_get: hit_fun = "; prerr_hityp hit_fun;
prerr_newline ();
$Err.abort {$Syn.funclo} ()
end end
implement funlab_qua_get (fl) = fl.funlab_qua
implement funlab_tailjoined_get (fl) = fl.funlab_tailjoined
implement funlab_entry_get (fl) = fl.funlab_entry
implement funlab_entry_get_some (fl) = begin
case+ fl.funlab_entry of
| Some entry => entry | None () => begin
prerr_interror ();
prerr ": funlab_entry_get_some: fl = "; prerr_funlab fl; prerr_newline ();
$Err.abort {funentry_t} ()
end end
implement funlab_prfck_get (fl) = fl.funlab_prfck
end
implement
valprim_is_const (vp) =
case+ vp.valprim_node of
| VPbool _ => true
| VPcastfn (_d2c, vp) => valprim_is_const (vp)
| VPchar _ => true
| VPcst _ => true
| VPfloat _ => true
| VPfun _ => true
| VPint _ => true
| VPsizeof _ => true
| VPstring _ => true
| VPtop _ => true
| VPvoid _ => true
| _ => false
implement
valprim_is_mutable (vp) = begin
case+ vp.valprim_node of
| VPargref _ => true | VPtmpref _ => true | _ => false
end
implement
valprim_arg (n, hit) = '{
valprim_node= VParg (n), valprim_typ= hit
}
implement
valprim_argref (n, hit) = '{
valprim_node= VPargref (n), valprim_typ= hit
}
implement
valprim_bool (b) = '{
valprim_node= VPbool b, valprim_typ= hityp_encode (hityp_bool)
}
implement
valprim_castfn (d2c, vp, hit) = '{
valprim_node= VPcastfn (d2c, vp), valprim_typ= hit
}
implement
valprim_char (c) = '{
valprim_node= VPchar c, valprim_typ= hityp_encode (hityp_char)
}
implement
valprim_cst (d2c, hit) = '{
valprim_node= VPcst (d2c), valprim_typ= hit
}
implement
valprim_cstsp (loc, cst, hit) = '{
valprim_node= VPcstsp (loc, cst), valprim_typ= hit
}
implement
valprim_env (vt, hit) = '{
valprim_node= VPenv vt, valprim_typ= hit
}
implement
valprim_ext (code, hit) = '{
valprim_node= VPext code, valprim_typ= hit
}
implement
valprim_fix (vpr, hit) = '{
valprim_node= VPfix (vpr), valprim_typ = hit
}
implement
valprim_float f = '{
valprim_node= VPfloat f, valprim_typ= hityp_encode (hityp_double)
}
implement
valprim_floatsp (f, hit) = '{
valprim_node= VPfloatsp f, valprim_typ= hit
}
implement
valprim_clo (knd, fl, env) = let
val hit = (if knd <> 0 then hityp_ptr else hityp_clo): hityp
in '{
valprim_node= VPclo (knd, fl, env), valprim_typ= hityp_encode hit
} end
implement
valprim_fun (funlab) = '{
valprim_node= VPfun funlab, valprim_typ= funlab_typ_get funlab
}
implement
valprim_int (int) = '{
valprim_node= VPint (int), valprim_typ= hityp_encode (hityp_int)
}
implement
valprim_intsp (str, int, hit) = '{
valprim_node= VPintsp (str, int), valprim_typ= hit
}
implement
valprim_ptrof (vp) = '{
valprim_node= VPptrof vp, valprim_typ= hityp_encode (hityp_ptr)
}
implement
valprim_ptrof_ptr_offs
(vp, offs) = begin case+ offs of
| list_cons _ => '{
valprim_node= VPptrof_ptr_offs (vp, offs)
, valprim_typ= hityp_encode (hityp_ptr)
} | list_nil () => valprim_ptrof (vp)
end
implement
valprim_ptrof_var_offs
(vp, offs) = begin case+ offs of
| list_cons _ => '{
valprim_node= VPptrof_var_offs (vp, offs)
, valprim_typ= hityp_encode (hityp_ptr)
} | list_nil () => valprim_ptrof (vp)
end
implement
valprim_sizeof (hit) = '{
valprim_node= VPsizeof hit
, valprim_typ= hityp_encode (hityp_int)
}
implement
valprim_string (str, len) = '{
valprim_node= VPstring (str, len)
, valprim_typ= hityp_encode (hityp_string)
}
implement
valprim_tmp (tmp) = '{
valprim_node= VPtmp tmp, valprim_typ= tmpvar_typ_get tmp
}
implement
valprim_tmpref (tmp) = '{
valprim_node= VPtmpref tmp, valprim_typ= tmpvar_typ_get tmp
}
implement
valprim_top (hit) = '{
valprim_node= VPtop (), valprim_typ= hit
}
implement
valprim_void () = '{
valprim_node= VPvoid (), valprim_typ= hityp_encode (hityp_void)
}
implement
valprim_is_void (vp) = begin
hityp_is_void (hityp_decode vp.valprim_typ)
end
implement
instr_call
(loc, tmp_res, hit_fun, vp_fun, vps_arg) = '{
instr_loc= loc
, instr_node= INSTRcall (tmp_res, hit_fun, vp_fun, vps_arg)
}
implement
instr_call_tail (loc, fl) = '{
instr_loc= loc, instr_node= INSTRcall_tail (fl)
}
implement
instr_cond (loc, _test, _then, _else) = '{
instr_loc= loc, instr_node= INSTRcond (_test, _then, _else)
}
implement
instr_function
(loc, tmp_res, vps_arg, _body, tmp_ret) = '{
instr_loc= loc
, instr_node= INSTRfunction (tmp_res, vps_arg, _body, tmp_ret)
}
implement
instr_funlab (fl) = '{
instr_loc= $Loc.location_none, instr_node= INSTRfunlab (fl)
}
implement
instr_prfck_beg (d2c) = '{
instr_loc= $Loc.location_none
, instr_node= INSTRprfck_beg (d2c)
}
implement
instr_prfck_tst (d2c) = '{
instr_loc= $Loc.location_none
, instr_node= INSTRprfck_tst (d2c)
}
implement
instr_prfck_end (d2c) = '{
instr_loc= $Loc.location_none
, instr_node= INSTRprfck_end (d2c)
}
fun instr_arr_heap (
loc: loc_t
, tmp_res: tmpvar_t, asz: int, hit_elt: hityp_t
) : instr = '{
instr_loc= loc
, instr_node= INSTRarr_heap (tmp_res, asz, hit_elt)
}
implement
instr_add_arr_heap
(res, loc, tmp_res, asz, hit_elt) = begin
res := list_vt_cons (instr_arr_heap (loc, tmp_res, asz, hit_elt), res)
end
fun instr_arr_stack (
loc: loc_t
, tmp_res: tmpvar_t
, level: int , vp_asz: valprim
, hit_elt: hityp_t
) : instr = '{
instr_loc= loc
, instr_node= INSTRarr_stack (tmp_res, level, vp_asz, hit_elt)
}
implement
instr_add_arr_stack
(res, loc, tmp_res, level, vp_asz, hit_elt) = begin
res := list_vt_cons (instr_arr_stack (loc, tmp_res, level, vp_asz, hit_elt), res)
end
fun instr_assgn_arr (
loc: loc_t
, vp_arr: valprim
, vp_asz: valprim
, tmp_elt: tmpvar_t
, vp_tsz: valprim
) : instr = '{
instr_loc= loc
, instr_node= INSTRassgn_arr (vp_arr, vp_asz, tmp_elt, vp_tsz)
}
implement
instr_add_assgn_arr
(res, loc, vp_arr, vp_asz, tmp_elt, vp_tsz) = res :=
list_vt_cons (instr_assgn_arr (loc, vp_arr, vp_asz, tmp_elt, vp_tsz), res)
fun instr_assgn_clo (
loc: loc_t
, vp_clo: valprim
, fl: funlab_t
, env: envmap_t
) : instr = '{
instr_loc= loc
, instr_node= INSTRassgn_clo (vp_clo, fl, env)
}
implement
instr_add_assgn_clo
(res, loc, vp_clo, fl, env) =
res := list_vt_cons (instr_assgn_clo (loc, vp_clo, fl, env), res)
implement
instr_add_call
(res, loc, tmp_res, hit_fun, vp_fun, vps_arg) = let
val ins = instr_call (loc, tmp_res, hit_fun, vp_fun, vps_arg)
in
res := list_vt_cons (ins, res)
end
implement
instr_add_call_tail (res, loc, fl) =
res := list_vt_cons (instr_call_tail (loc, fl), res)
fun instr_define_clo (
loc: loc_t, d2c: d2cst_t, fl: funlab_t
) : instr = '{
instr_loc= loc, instr_node= INSTRdefine_clo (d2c, fl)
}
implement
instr_add_define_clo (res, loc, d2c, fl) =
res := list_vt_cons (instr_define_clo (loc, d2c, fl), res)
fun instr_define_fun (
loc: loc_t, d2c: d2cst_t, fl: funlab_t
) : instr = '{
instr_loc= loc, instr_node= INSTRdefine_fun (d2c, fl)
}
implement
instr_add_define_fun (res, loc, d2c, fl) =
res := list_vt_cons (instr_define_fun (loc, d2c, fl), res)
fun instr_define_val (
loc: loc_t, d2c: d2cst_t, vp: valprim
) : instr = '{
instr_loc= loc, instr_node= INSTRdefine_val (d2c, vp)
}
implement
instr_add_define_val (res, loc, d2c, vp) =
res := list_vt_cons (instr_define_val (loc, d2c, vp), res)
fun instr_extval (
loc: loc_t, name: string, vp: valprim
) : instr = '{
instr_loc= loc, instr_node= INSTRextval (name, vp)
}
implement
instr_add_extval (res, loc, name, vp) =
res := list_vt_cons (instr_extval (loc, name, vp), res)
fun instr_freeptr
(loc: loc_t, vp: valprim): instr = '{
instr_loc= loc, instr_node= INSTRfreeptr (vp)
}
implement
instr_add_freeptr (res, loc, vp) =
res := list_vt_cons (instr_freeptr (loc, vp), res)
fun instr_patck (
loc: loc_t
, vp: valprim, patck: patck, fail: kont
) : instr = '{
instr_loc= loc, instr_node= INSTRpatck (vp, patck, fail)
}
implement
instr_add_patck (res, loc, vp, patck, fail) =
res := list_vt_cons (instr_patck (loc, vp, patck, fail), res)
fun instr_dynload_file
(loc: loc_t, fil: fil_t): instr = '{
instr_loc= loc, instr_node= INSTRdynload_file (fil)
}
implement
instr_add_dynload_file (res, loc, fil) =
res := list_vt_cons (instr_dynload_file (loc, fil), res)
fun instr_load_ptr (
loc: loc_t, tmp: tmpvar_t, vp: valprim
) : instr = '{
instr_loc= loc, instr_node= INSTRload_ptr (tmp, vp)
}
fun instr_load_var (
loc: loc_t, tmp: tmpvar_t, vp: valprim
) : instr = '{
instr_loc= loc, instr_node= INSTRload_var (tmp, vp)
}
fun instr_load_ptr_offs (
loc: loc_t, tmp: tmpvar_t, vp: valprim, offs: offsetlst
) : instr = '{
instr_loc= loc, instr_node= INSTRload_ptr_offs (tmp, vp, offs)
}
fun instr_load_var_offs (
loc: loc_t, tmp: tmpvar_t, vp: valprim, offs: offsetlst
) : instr = '{
instr_loc= loc, instr_node= INSTRload_var_offs (tmp, vp, offs)
}
implement
instr_add_load_ptr
(res, loc, tmp, vp) = begin
res := list_vt_cons (instr_load_ptr (loc, tmp, vp), res)
end
implement
instr_add_load_ptr_offs
(res, loc, tmp, vp, offs) = let
val ins = (case+ offs of
| list_cons _ =>
instr_load_ptr_offs (loc, tmp, vp, offs)
| list_nil () => instr_load_ptr (loc, tmp, vp)
) : instr in
res := list_vt_cons (ins, res)
end
implement
instr_add_load_var_offs
(res, loc, tmp, vp, offs) = let
val ins = (case+ offs of
| list_cons _ =>
instr_load_var_offs (loc, tmp, vp, offs)
| list_nil () => instr_load_var (loc, tmp, vp)
) : instr in
res := list_vt_cons (ins, res)
end
fun instr_loop (
loc: loc_t
, lab_init: tmplab_t
, lab_fini: tmplab_t
, lab_cont: tmplab_t
, inss_init: instrlst
, vp_test: valprim
, inss_test: instrlst
, inss_post: instrlst
, inss_body: instrlst
) : instr = '{
instr_loc= loc
, instr_node= INSTRloop (
lab_init, lab_fini, lab_cont, inss_init, vp_test, inss_test, inss_post, inss_body
) }
implement
instr_add_loop (
res
, loc
, lab_init, lab_fini, lab_cont
, inss_init
, vp_test, inss_test
, inss_post
, inss_body
) = let
val ins = instr_loop (
loc, lab_init, lab_fini, lab_cont, inss_init, vp_test, inss_test, inss_post, inss_body
) in
res := list_vt_cons (ins, res)
end
fun instr_loopexn (
loc: loc_t, knd: int, tl: tmplab_t
) : instr = '{
instr_loc= loc, instr_node= INSTRloopexn (knd, tl)
}
implement
instr_add_loopexn (res, loc, knd, tl) =
res := list_vt_cons (instr_loopexn (loc, knd, tl), res)
fun instr_move_arg (
loc: loc_t, arg: int, vp: valprim
) : instr = '{
instr_loc= loc, instr_node= INSTRmove_arg (arg, vp)
}
implement
instr_add_move_arg
(res, loc, arg, vp) =
res := list_vt_cons (instr_move_arg (loc, arg, vp), res)
fun instr_move_con (
loc: loc_t
, tmp_res: tmpvar_t
, hit_sum: hityp_t
, d2c: d2con_t
, vps_arg: valprimlst
) : instr = '{
instr_loc= loc, instr_node= INSTRmove_con (tmp_res, hit_sum, d2c, vps_arg)
}
implement
instr_add_move_con
(res, loc, tmp_res, hit_sum, d2c, vps_arg) =
res := list_vt_cons (instr_move_con (loc, tmp_res, hit_sum, d2c, vps_arg), res)
fun instr_move_lazy_delay (
loc: loc_t
, tmp_res: tmpvar_t
, lin: int
, hit_body: hityp_t
, vp_clo: valprim
) : instr = '{
instr_loc= loc
, instr_node= INSTRmove_lazy_delay (tmp_res, lin, hit_body, vp_clo)
}
implement
instr_add_move_lazy_delay
(res, loc, tmp_res, lin, hit_body, vp_clo) = let
val ins = instr_move_lazy_delay (loc, tmp_res, lin, hit_body, vp_clo)
in
res := list_vt_cons (ins, res)
end
fun instr_move_lazy_force (
loc: loc_t
, tmp_res: tmpvar_t
, lin: int
, hit_val: hityp_t
, vp_lazy: valprim
) : instr = '{
instr_loc= loc
, instr_node= INSTRmove_lazy_force (tmp_res, lin, hit_val, vp_lazy)
}
implement
instr_add_move_lazy_force
(res, loc, tmp_res, lin, hit_val, vp_lazy) = let
val ins = instr_move_lazy_force (loc, tmp_res, lin, hit_val, vp_lazy)
in
res := list_vt_cons (ins, res)
end
fun instr_move_rec_flt (
loc: loc_t
, tmp_res: tmpvar_t
, hit_rec: hityp_t
, lvps: labvalprimlst
) : instr = '{
instr_loc= loc
, instr_node= INSTRmove_rec_flt (tmp_res, hit_rec, lvps)
}
fun instr_move_rec_box (
loc: loc_t
, tmp_res: tmpvar_t
, hit_rec: hityp_t
, lvps: labvalprimlst
) : instr = '{
instr_loc= loc
, instr_node= INSTRmove_rec_box (tmp_res, hit_rec, lvps)
}
implement
instr_add_move_rec
(res, loc, tmp_res, recknd, hit_rec, lvps) = let
val ins = (case+ 0 of
| _ when recknd = 0 => instr_move_rec_flt (loc, tmp_res, hit_rec, lvps)
| _ when recknd > 0 => instr_move_rec_box (loc, tmp_res, hit_rec, lvps)
| _ => begin
prerr_interror ();
prerr ": instr_add_move_rec: recknd = "; prerr recknd; prerr_newline ();
$Err.abort {instr} ()
end ) : instr in
res := list_vt_cons (ins, res)
end
fun instr_move_ref (
loc: loc_t, tmp_res: tmpvar_t, vp: valprim
) : instr = '{
instr_loc= loc, instr_node= INSTRmove_ref (tmp_res, vp)
}
implement
instr_add_move_ref (res, loc, tmp_res, vp) =
res := list_vt_cons (instr_move_ref (loc, tmp_res, vp), res)
fun instr_move_val (
loc: loc_t, tmp_res: tmpvar_t, vp: valprim
) : instr = '{
instr_loc= loc, instr_node= INSTRmove_val (tmp_res, vp)
}
implement
instr_add_move_val (res, loc, tmp_res, vp) =
res := list_vt_cons (instr_move_val (loc, tmp_res, vp), res)
fun instr_raise (
loc: loc_t, tmp_res: tmpvar_t, vp_exn: valprim
) : instr = '{
instr_loc= loc, instr_node= INSTRraise (tmp_res, vp_exn)
}
implement
instr_add_raise (res, loc, tmp_res, vp_exn) =
res := list_vt_cons (instr_raise (loc, tmp_res, vp_exn), res)
fun instr_select (
loc: loc_t
, tmp_res: tmpvar_t
, vp_root: valprim
, offs: offsetlst
) : instr = '{
instr_loc= loc
, instr_node= INSTRselect (tmp_res, vp_root, offs)
}
implement
instr_add_select
(res, loc, tmp_res, vp_root, offs) =
res := list_vt_cons (instr_select (loc, tmp_res, vp_root, offs), res)
fun instr_selcon (
loc: loc_t
, tmp_res: tmpvar_t
, vp_sum: valprim
, hit_sum: hityp_t
, ind: int
) : instr = '{
instr_loc= loc
, instr_node= INSTRselcon (tmp_res, vp_sum, hit_sum, ind)
}
implement
instr_add_selcon
(res, loc, tmp_res, vp_sum, hit_sum, ind) =
res := list_vt_cons (instr_selcon (loc, tmp_res, vp_sum, hit_sum, ind), res)
fun instr_selcon_ptr (
loc: loc_t
, tmp_res: tmpvar_t
, vp_sum: valprim
, hit_sum: hityp_t
, ind: int
) : instr = '{
instr_loc= loc
, instr_node= INSTRselcon_ptr (tmp_res, vp_sum, hit_sum, ind)
}
implement
instr_add_selcon_ptr
(res, loc, tmp_res, vp_sum, hit_sum, ind) = let
val ins = instr_selcon_ptr (loc, tmp_res, vp_sum, hit_sum, ind)
in
res := list_vt_cons (ins, res)
end
fun instr_store_ptr (
loc: loc_t, vp_ptr: valprim, vp_all: valprim
) : instr = '{
instr_loc= loc, instr_node= INSTRstore_ptr (vp_ptr, vp_all)
}
fun instr_store_ptr_offs (
loc: loc_t
, vp_ptr: valprim, offs: offsetlst, vp_all: valprim
) : instr = '{
instr_loc= loc, instr_node= INSTRstore_ptr_offs (vp_ptr, offs, vp_all)
}
implement
instr_add_store_ptr_offs
(res, loc, vp_ptr, offs, vp_val) = let
val ins = case+ offs of
| list_cons _ =>
instr_store_ptr_offs (loc, vp_ptr, offs, vp_val)
| list_nil () => instr_store_ptr (loc, vp_ptr, vp_val)
in
res := list_vt_cons (ins, res)
end
fun instr_store_var (
loc: loc_t, vp_mut: valprim, vp_all: valprim
) : instr = '{
instr_loc= loc, instr_node= INSTRstore_var (vp_mut, vp_all)
}
fun instr_store_var_offs (
loc: loc_t
, vp_mut: valprim, offs: offsetlst, vp_all: valprim
) : instr = '{
instr_loc= loc, instr_node= INSTRstore_var_offs (vp_mut, offs, vp_all)
}
implement
instr_add_store_var_offs
(res, loc, vp_mut, offs, vp_val) = let
val ins = (case+ offs of
| list_cons _ =>
instr_store_var_offs (loc, vp_mut, offs, vp_val)
| list_nil () => instr_store_var (loc, vp_mut, vp_val)
) : instr in
res := list_vt_cons (ins, res)
end
fun instr_switch
(loc: loc_t, brs: branchlst): instr = '{
instr_loc= loc, instr_node= INSTRswitch (brs)
}
implement
instr_add_switch (res, loc, brs) =
res := list_vt_cons (instr_switch (loc, brs), res)
fun instr_tmplabint
(loc: loc_t, tl: tmplab_t, ind: int): instr = '{
instr_loc= loc, instr_node= INSTRtmplabint (tl, ind)
}
implement
instr_add_tmplabint (res, loc, tl, ind) =
res := list_vt_cons (instr_tmplabint (loc, tl, ind), res)
fun instr_trywith (
loc: loc_t
, res_try: instrlst
, tmp_exn: tmpvar_t
, brs: branchlst
) : instr = '{
instr_loc= loc
, instr_node= INSTRtrywith (res_try, tmp_exn, brs)
}
implement
instr_add_trywith
(res, loc, res_try, tmp_exn, brs) =
res := list_vt_cons (instr_trywith (loc, res_try, tmp_exn, brs), res)
fun instr_vardec
(loc: loc_t, tmp: tmpvar_t): instr = '{
instr_loc= loc, instr_node= INSTRvardec (tmp)
}
implement
instr_add_vardec (res, loc, tmp) =
res := list_vt_cons (instr_vardec (loc, tmp), res)
%{$
ats_void_type
atsccomp_funlab_qua_set
(ats_ptr_type fl, ats_ptr_type od2c) {
((funlab_t)fl)->atslab_funlab_qua = od2c ; return ;
} // end of [atsccomp_funlab_qua_set]
ats_void_type
atsccomp_funlab_entry_set
(ats_ptr_type fl, ats_ptr_type entry) {
((funlab_t)fl)->atslab_funlab_entry = entry ; return ;
} // end of [atsccomp_funlab_entry_set]
ats_void_type
atsccomp_funlab_tailjoined_set
(ats_ptr_type fl, ats_ptr_type tmps) {
((funlab_t)fl)->atslab_funlab_tailjoined = tmps ; return ;
} // end of [atsccomp_funlab_tailjoined_set]
ats_void_type
atsccomp_tmpvar_ret_set
(ats_ptr_type tmp, ats_int_type ret) {
((tmpvar_t)tmp)->atslab_tmpvar_ret = ret ; return ;
} // end of [atsccomp_tmpvar_ret_set]
ats_void_type
atsccomp_tmpvar_top_set
(ats_ptr_type tmp, ats_int_type top) {
((tmpvar_t)tmp)->atslab_tmpvar_top = top ; return ;
} // end of [atsccomp_tmpvar_top_set]
ats_void_type
atsccomp_tmpvar_root_set
(ats_ptr_type tmp, ats_ptr_type root) {
((tmpvar_t)tmp)->atslab_tmpvar_root = root ; return ;
} // end of [atsccomp_tmpvar_root_set]
%}