Skip to content

Commit

Permalink
implement puts & print & p
Browse files Browse the repository at this point in the history
  • Loading branch information
astro committed Dec 14, 2010
1 parent 5167dc5 commit 803e99b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src-hs/GolfScript/Interpreter.hs
Expand Up @@ -257,6 +257,15 @@ vmSin = do GolfNumber a <- vmPop
truncate $
(fromIntegral a / 360.0) * 1000

vmPrint = do v <- vmPop
case v of
GolfString s ->
liftIO $ putStr s
GolfNumber n ->
liftIO $ putStr $ show n
_ ->
error $ "Cannot print " ++ show v

newVM :: VM
newVM = VM { vmStack = [],
vmVars = Map.fromList [(":", GolfBuiltin vmColon),
Expand All @@ -283,7 +292,10 @@ newVM = VM { vmStack = [],
("h", GolfString "Hello, World"),
("require", GolfBuiltin vmRequire),
("zip", GolfBuiltin vmZip),
("sin", GolfBuiltin vmSin)],
("sin", GolfBuiltin vmSin),
("puts", GolfBuiltin $ vmPrint >> liftIO (putStrLn "")),
("print", GolfBuiltin vmPrint),
("p", GolfBuiltin $ vmInspect >> vmPrint >> liftIO (putStrLn ""))],
vmInAssignment = False
}

Expand Down

0 comments on commit 803e99b

Please sign in to comment.