From 3a1f403a0146f4717b210373167640a07f0248dd Mon Sep 17 00:00:00 2001 From: aarne Date: Sat, 18 Sep 2004 09:24:51 +0000 Subject: doc --- examples/gfcc/ImperJVM.gf | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'examples/gfcc/ImperJVM.gf') diff --git a/examples/gfcc/ImperJVM.gf b/examples/gfcc/ImperJVM.gf index 10457fbfe..9acbfa263 100644 --- a/examples/gfcc/ImperJVM.gf +++ b/examples/gfcc/ImperJVM.gf @@ -4,25 +4,40 @@ concrete ImperJVM of Imper = open Prelude, Precedence, ResImper in { flags lexer=codevars ; unlexer=code ; startcat=Stm ; lincat - Stm = SS ; + Stm = Instr ; Typ = SS ; Exp = SS ; Var = SS ; lin - Decl typ cont = ss [] ; ---- - Assign t x exp = statement (exp.s ++ t.s ++ "_store" ++ x.s) ; - Return t exp = statement (exp.s ++ t.s ++ "_return") ; - While exp loop = statement ("TEST:" ++ exp.s ++ "ifzero_goto" ++ - "END" ++ ";" ++ loop.s ++ "END") ; - Block stm = stm ; - Next stm cont = ss (stm.s ++ cont.s) ; + Decl typ cont = instrc ( + "alloc_" ++ typ.s ++ cont.$0 + ) cont ; + Assign t x exp = instrc ( + exp.s ++ + t.s ++ "_store" ++ x.s + ) ; + Return t exp = instr ( + exp.s ++ + t.s ++ "_return") ; + While exp loop = instrc ( + "TEST:" ++ exp.s ++ + "ifzero_goto" ++ "END" ++ ";" ++ + loop.s ++ + "END" + ) ; + Block stm = instrc stm.s ; + End = ss [] ** {s3 = []} ; - EVar t x = statement (t.s ++ "_load" ++ x.s) ; - EInt n = statement ("i_push" ++ n.s) ; - EFloat a b = statement ("f_push" ++ a.s ++ "." ++ b.s) ; - EAddI x y = statement (x.s ++ y.s ++ "iadd") ; - EAddF x y = statement (x.s ++ y.s ++ "fadd") ; + EVar t x = instr (t.s ++ "_load" ++ x.s) ; + EInt n = instr ("ipush" ++ n.s) ; + EFloat a b = instr ("fpush" ++ a.s ++ "." ++ b.s) ; + EAddI = binop "iadd" ; + EAddF = binop "fadd" ; + EMulI = binop "imul" ; + EMulF = binop "fmul" ; + ELtI = binop ("call" ++ "ilt") ; + ELtF = binop ("call" ++ "flt") ; TInt = ss "i" ; TFloat = ss "f" ; -- cgit v1.2.3