summaryrefslogtreecommitdiff
path: root/examples/gfcc/compiler/CleanJVM.hs
diff options
context:
space:
mode:
authoraarne <unknown>2004-12-20 07:57:05 +0000
committeraarne <unknown>2004-12-20 07:57:05 +0000
commit6e1f41b26af8154033fda32c573aba56d7cb89fb (patch)
treecdfd17dd3a1444f3a921cadc6d0a141178767819 /examples/gfcc/compiler/CleanJVM.hs
parent8caa3ed737900c0fc004b24720f909244d17dd59 (diff)
gfcc in Types
Diffstat (limited to 'examples/gfcc/compiler/CleanJVM.hs')
-rw-r--r--examples/gfcc/compiler/CleanJVM.hs22
1 files changed, 9 insertions, 13 deletions
diff --git a/examples/gfcc/compiler/CleanJVM.hs b/examples/gfcc/compiler/CleanJVM.hs
index 7dafa0083..ab879ff0e 100644
--- a/examples/gfcc/compiler/CleanJVM.hs
+++ b/examples/gfcc/compiler/CleanJVM.hs
@@ -24,27 +24,23 @@ mkJVM cls = unlines . reverse . fst . foldl trans ([],([],0)) . lines where
| f == "main" ->
(".method public static main([Ljava/lang/String;)V":code,([],1))
| otherwise ->
- (unwords [".method",p,s, f ++ typesig ns] : code,([],0))
+ (unwords [".method",p,s, f ++ glue ns] : code,([],0))
"alloc":t:x:_ -> (("; " ++ s):code, ((x,v):env, v + size t))
".limit":"locals":ns -> chCode (".limit locals " ++ show (length ns))
- "invokestatic":t:f:ns
- | take 8 f == "runtime/" ->
- chCode $ "invokestatic " ++ "runtime/" ++ t ++ drop 8 f ++ typesig ns
- "invokestatic":f:ns ->
- chCode $ "invokestatic " ++ cls ++ "/" ++ f ++ typesig ns
+ "runtime":f:ns -> chCode $ "invokestatic " ++ "runtime/" ++ f ++ glue ns
+ "static":f:ns -> chCode $ "invokestatic " ++ cls ++ "/" ++ f ++ glue ns
"alloc":ns -> chCode $ "; " ++ s
- t:('_':instr):[";"] -> chCode $ t ++ instr
- t:('_':instr):x:_ -> chCode $ t ++ instr ++ " " ++ look x
- "goto":ns -> chCode $ "goto " ++ label ns
- "ifeq":ns -> chCode $ "ifeq " ++ label ns
- "label":ns -> chCode $ label ns ++ ":"
+ ins:x:_ | symb ins -> chCode $ ins ++ " " ++ look x
+ "goto":ns -> chCode $ "goto " ++ glue ns
+ "ifeq":ns -> chCode $ "ifeq " ++ glue ns
+ "label":ns -> chCode $ glue ns ++ ":"
";":[] -> chCode ""
_ -> chCode s
where
chCode c = (c:code,(env,v))
look x = maybe (error $ x ++ show env) show $ lookup x env
- typesig = init . map toUpper . concat
- label = init . concat
+ glue = init . concat
+ symb = flip elem ["load","store"] . tail
size t = case t of
"d" -> 2
_ -> 1