ExternalMaster of string
| InternalMaster of string
-val ip = fn (EApp ((EVar "ip_of_node", _), e), _) => Option.map nodeIp (Env.string e)
- | e => Env.string e
+val ip = Env.string
+
+val _ = Env.registerFunction ("ip_of_node",
+ fn [(EString node, _)] => SOME (EString (nodeIp node), dl)
+ | _ => NONE)
val master = fn (EApp ((EVar "externalMaster", _), e), _) => Option.map ExternalMaster (ip e)
| (EApp ((EVar "internalMaster", _), e), _) => Option.map InternalMaster (Env.string e)
val containerV_one : string -> string * 'a arg -> (env_vars * 'a -> unit) * (unit -> unit) -> unit
+ val registerFunction : string * (Ast.exp list -> Ast.exp option) -> unit
+ val function : string -> (Ast.exp list -> Ast.exp option) option
+
type env
val empty : env
containers := SM.insert (!containers, name, (befor, after))
fun container name = SM.find (!containers, name)
+val functions : (exp list -> exp option) SM.map ref = ref SM.empty
+fun registerFunction (name, f) =
+ functions := SM.insert (!functions, name, f)
+fun function name = SM.find (!functions, name)
+
local
val pr = ref (fn () => ())
in
else
(EALam (x', p, subst x e b'), loc)
+fun findPrim (e, _) =
+ case e of
+ EApp (f, x) =>
+ (case findPrim f of
+ NONE => NONE
+ | SOME (f, xs) => SOME (f, xs @ [x]))
+ | EVar x => SOME (x, [])
+ | _ => NONE
+
fun reduceExp G (eAll as (e, loc)) =
case e of
EInt _ => eAll
in
case e1' of
(ELam (x, _, b), _) => reduceExp G (subst x e2' b)
- | _ => (EApp (e1', e2'), loc)
+ | _ =>
+ case findPrim eAll of
+ NONE => (EApp (e1', e2'), loc)
+ | SOME (f, args) =>
+ case function f of
+ NONE => (EApp (e1', e2'), loc)
+ | SOME f => case f (map (reduceExp G) args) of
+ NONE => (EApp (e1', e2'), loc)
+ | SOME e' => reduceExp G e'
end
| ESkip => eAll