%{^
#include "ats_counter.cats" /* only needed for [ATS/Geizella] */
%}
staload Lst = "ats_list.sats"
staload Stamp = "ats_stamp.sats"
staload Syn = "ats_syntax.sats"
staload "ats_staexp2.sats"
staload "ats_dynexp2.sats"
#define nil list_nil
#define cons list_cons
#define :: list_cons
typedef d2mac_struct (narg:int) = @{
d2mac_loc= loc_t
, d2mac_sym= sym_t
, d2mac_kind= int , d2mac_narg= int narg , d2mac_arglst= list (macarg, narg) , d2mac_def= d2exp , d2mac_stamp= stamp_t }
local
assume d2mac_abs_t (narg:int) =
[l:addr] (vbox (d2mac_struct narg @ l) | ptr l)
in
implement d2mac_make {narg} (loc, name, knd, args, def) = let
val narg = aux args where {
fun aux {narg:nat}
(args: macarglst narg): int narg = case+ args of
| list_cons (_, args) => 1 + aux (args) | list_nil () => 0
}
val stamp = $Stamp.d2mac_stamp_make ()
val (pf_gc, pf | p) =
ptr_alloc_tsz {d2mac_struct narg} (sizeof<d2mac_struct narg>)
prval () = free_gc_elim {d2mac_struct narg} (pf_gc)
val () = begin
p->d2mac_loc := loc;
p->d2mac_sym := name;
p->d2mac_kind := knd;
p->d2mac_narg := narg;
p->d2mac_arglst := args;
p->d2mac_def := def;
p->d2mac_stamp := stamp
end
val (pfbox | ()) = vbox_make_view_ptr (pf | p)
in
(pfbox | p)
end
implement d2mac_loc_get (d2m) =
let val (vbox pf | p) = d2m in p->d2mac_loc end
implement d2mac_sym_get (d2m) =
let val (vbox pf | p) = d2m in p->d2mac_sym end
implement d2mac_kind_get (d2m) =
let val (vbox pf | p) = d2m in p->d2mac_kind end
implement d2mac_narg_get (d2m) =
let val (vbox pf | p) = d2m in p->d2mac_narg end
implement d2mac_arglst_get (d2m) =
let val (vbox pf | p) = d2m in p->d2mac_arglst end
implement d2mac_def_get (d2m) =
let val (vbox pf | p) = d2m in p->d2mac_def end
implement d2mac_def_set (d2m, def) =
let val (vbox pf | p) = d2m in p->d2mac_def := def end
implement d2mac_stamp_get (d2m) =
let val (vbox pf | p) = d2m in p->d2mac_stamp end
end
implement fprint_d2mac (pf_out | out, d2m) = begin
$Sym.fprint_symbol (pf_out | out, d2mac_sym_get d2m)
end
implement print_d2mac (d2m) = print_mac (fprint_d2mac, d2m)
implement prerr_d2mac (d2m) = prerr_mac (fprint_d2mac, d2m)