| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Pugs
Revision: 22179
Author: pmurias
Date: 07 Sep 2008 08:05:38
Changes:[pugs-m0ld] basic functions calls with only positionals and integer literals
Files:| ... | ...@@ -12,6 +12,7 @@ | |
| 12 | 12 | id <- get |
| 13 | 13 | return $ "$id"++(show id) |
| 14 | 14 | void = "$void" |
| 15 | placeholder other r = return $ "my "++ r ++ " = " ++ (show other) ++ "; #placeholder\n" | |
| 15 | 16 | |
| 16 | 17 | class EmitM0ld a where |
| 17 | 18 | emit :: a -> [Char] -> State Int [Char] |
| ... | ...@@ -31,7 +32,7 @@ | |
| 31 | 32 | instance EmitM0ld PIL_Stmt where |
| 32 | 33 | emit statement r = case statement of |
| 33 | 34 | PPos {pNode=stmt} -> emit stmt r |
| 34 | PNoop -> return "; #noop\n" | |
| 35 | PNoop -> return "#noop\n" | |
| 35 | 36 | PStmt {pExpr=expr} -> emit expr r |
| 36 | 37 | |
| 37 | 38 | instance EmitM0ld PIL_Expr where |
| ... | ...@@ -44,22 +45,31 @@ | |
| 44 | 45 | ++ body |
| 45 | 46 | ++ void ++ " = $interpreter.\"return\"(" ++ ret ++ ");\n" |
| 46 | 47 | ++ "});\n") |
| 48 | PLit {pLit=lit} -> emit lit r | |
| 49 | other -> placeholder other r | |
| 50 | ||
| 51 | instance EmitM0ld PIL_Literal where | |
| 52 | emit PVal {pVal=val} r = emit val r | |
| 53 | ||
| 54 | instance EmitM0ld Val where | |
| 55 | emit (VInt int) r = return $ "my " ++ r ++ " = " ++ (show int) ++ ";\n" | |
| 56 | emit other r = placeholder other r | |
| 47 | 57 | |
| 48 | 58 | instance EmitM0ld PIL_LValue where |
| 49 | 59 | emit lvalue r = case lvalue of |
| 50 | 60 | PApp {pFun=fun,pArgs=args,pInv=Nothing} -> do |
| 51 | 61 | fun_r <- uniqueId |
| 52 | 62 | fun_code <- emit fun fun_r |
| 53 | return (fun_code ++ "my " ++ r ++ " = " ++ fun_r ++ ".\"postcircumfix:( )\"(" ++ (show args) ++ ");\n") | |
| 54 | PApp {pFun=fun,pArgs=args,pInv=Just inv} -> do | |
| 55 | inv <- emit inv r | |
| 56 | fun <- emit fun r | |
| 57 | return (inv ++ ".(" ++ fun ++ ")(" ++ (show args) ++ ")") | |
| 63 | args <- mapM (\arg -> do | |
| 64 | id <- uniqueId | |
| 65 | code <- emit arg id | |
| 66 | return (code,id)) args | |
| 67 | return (fun_code ++ (concat $ fmap fst args) ++ "my " ++ r ++ " = " ++ fun_r ++ ".\"postcircumfix:( )\"(" ++ (concat $ fmap snd args) ++ ");\n") | |
| 58 | 68 | PVar {pVarName=name} -> do |
| 59 | 69 | return $ "my " ++ r ++ " = $scope.\"postcircumfix:{ }\"(\"" ++ name ++ "\");\n" |
| 60 | other -> return $ show other | |
| 70 | other -> return $ (show other) ++ ";\n" | |
| 61 | 71 | |
| 62 | 72 | genM0ld :: FilePath -> Eval Val |
| 63 | 73 | genM0ld filepath = do |
| 64 | 74 | penv <- compile () :: Eval PIL_Environment |
| 65 | return $ VStr $ (evalState (emit penv void) 0) ++ "\n" | |
| 75 | return $ VStr $ (evalState (emit penv void) 0) |