// $Id$ $use Arithm Box List StdIO Table; $use "rfp_helper"; $func Simplify-Infix t.asail-term = t.asail-term; $func Simplify-Arithm e = e; $func Simplify e.asail = e.asail; $func Remove-Unreachable e.asail = e.asail; $func Remove-Dupl-Decl (e.decls) (e.subst) e.asail = e.asail; $func Process-Var (e.decls) (e.subst) s.type t.var = e.maybe-decl (e.decls) (e.subst); $func Free-Idx = s.idx; $box Idx; Simplify-ASAIL e.asail = , >>; Simplify { t.first e.rest, t.first : { (IF (e.cond) e.body) = : { 0 = /*empty*/; 1 = ; e.c = (IF (e.c) ); }; (INT t.var e.expr) = (INT t.var ); (e1) = (); s1 = s1; } :: e.first = e.first ;; }; $box Blocks; $table Breaks; $box Last-Breaks; $func? GetR s.box = t.right-term; GetR s.box = : e1 t2, , t2; Remove-Unreachable { t1 e2, t1 : \{ (FUNC t.name t.in t.out e.body) = , , e.body; (FUNC? t.name t.in t.out e.body) = , , e.body; (FOR (e.cont) (e.break) (e.cond) (e.step) e.body) = , e.body; (LABEL (t.label) e.body) = , e.body; (IF (e.cond) e.body) = , e.body; (TRY e.body) = , e.body; (CATCH-ERROR e.body) = , e.body; } :: e.body = , :: e.body, : { (LABEL (t.label)) = { = (LABEL (t.label) e.body) (e2); { : e (LABEL (t.other-label)), : /*empty*/ = ;; } = /*empty*/ (e.body e2); }; (FOR (e.cont) (e.break) (/*empty-cond*/) (e.step)) = { = (FOR (e.cont) (e.break) (/*empty-cond*/) (e.step) e.body) (e2); (FOR (e.cont) (e.break) (/*empty-cond*/) (e.step) e.body) (); }; (TRY) = { : e (e Normal-Exit) = (TRY e.body) (e2); e2 : (CATCH-ERROR e.catch-body) e3, (TRY e.body) ((CATCH-ERROR e.catch-body e3)); }; (e.item) = (e.item e.body) (e2); } :: e.t1 (e2), :: t.breaks, { e.t1 : v, t.breaks : (e t.l e), , $fail;; }, e.t1 ; t1 e2, t1 : \{ (BREAK t.label) = : (e.breaks), , { : e (LABEL (t.label)); , t1; }; (CONTINUE t.label) = { : e (FOR (t.label) (e.break) (e.cond) (e.step)); t1; }; RETFAIL = t1; (ERROR e) = t1; FATAL = t1; }; t1 e2 = t1 ; /*empty*/ = { : (e.breaks), ;; }; }; Remove-Dupl-Decl (e.decls) (e.subst) e.items, e.items : { t1 e.rest = { t1 : (DECL s.type t.var) = :: e.d (e.decls) (e.subst), e.d ; t1 : (EXPR t.var e.expr) = :: e.d (e.decls2) (e.subst2), { e.d : (DECL s t.new-var) = (EXPR t.new-var ) ; (ASSIGN t.var ) ; }; t1 : (s.split expr (e.len) t.var1 t.var2), s.split : \{ LSPLIT; RSPLIT; } = :: expr, :: e.decl1 (e.decls) (e.subst), { e.decl1 : (DECL s.type t.new-var) = t.new-var; t.var1; } :: t.var1, :: e.decl2 (e.decls) (e.subst), { e.decl2 : (DECL s.type t.new-var) = t.new-var; t.var2; } :: t.var2, (s.split expr t.var1 t.var2) ; e.subst : e (t1 t.new-var) e = ; t1 : (e2) = () ; t1 ; }; /*empty*/ = /*empty*/; }; Process-Var (e.decls) (e.subst) s.type t.var, { e.decls : $r e (DECL s.type-old t.var) e = { s.type : s.type-old = /*empty*/ (e.decls) (e.subst); t.var : (s.tag e (e.name)), (s.tag 'dd' (e.name )) :: t.new-var, (DECL s.type t.new-var) :: t.decl, t.decl (e.decls t.decl) (e.subst (t.var t.new-var)); }; (DECL s.type t.var) (e.decls (DECL s.type t.var)) (e.subst); }; $func "Eval *" e = e; $func "Eval /" e = e; $func "Eval %" e = e; $func "Eval +" e = e; $func "Eval -" e = e; Simplify-Infix /*txxx = , txxx :*/ { (INFIX s.op e.args), s.op : { "*" = )>; "/" = )>; "%" = )>; "+" = )>; "-" = )>; s = ; } : { t1 = t1; e1 = (INFIX s.op ); }; (e1) = (); s1 = s1; }; Simplify-Arithm (e.args) = )> : { t1 = t1; e1 = (INFIX "+" ); }; "Eval *" { 0 e = 0; e 0 = 0; 1 e2 = e2; e1 1 = e1; s1 e2 s3 = e2 <"*" s1 s3>; s1 e2 = e2 s1; e2 = e2; }; "Eval +" { 0 e2 = e2; e1 0 = e1; s1 e2 s3 = e2 <"+" s1 s3>; s1 e2 = e2 s1; e2 = e2; }; "Eval /" { e1 1 = e1; e1 = e1; }; "Eval %" { e1 1 = 0; e1 = e1; }; "Eval -" { e1 0 = e1; e1 = e1; }; Free-Idx = { : s1 = <"+" s1 1>; 1; } :: s1, , s1;