diff options
-rw-r--r-- | rip-lang.txt | 5 | ||||
-rw-r--r-- | rip.hs | 22 |
2 files changed, 24 insertions, 3 deletions
diff --git a/rip-lang.txt b/rip-lang.txt index 9c08942..2ddc1ed 100644 --- a/rip-lang.txt +++ b/rip-lang.txt @@ -12,7 +12,7 @@ d: decrement r: pops the number of items to rotate anti-clockwise R: pops the number of items to rotate clockwise l: push length of stack (before this push) -a s m q: + - * / (add, subtract, multiply, quotient (integer)) +a s m q M p: + - * / % ^ (add, subtract, multiply, quotient (integer), modulo, power) G L E: greater, less, equal; booleans are 1 and 0, as you expect n: not; equivalent to 0E [ ... ]: syntactical; a codeblock @@ -26,6 +26,9 @@ F<bla>[code]: define a function named "bla" with the body "code" $: outputs a stackdump whitespace: nop +'c: pushes the ascii value of c +#<file.rip>: literally includes contents of 'file.rip' in-place + Any error causes the interpreter to exit, saying "rip". @@ -38,6 +38,9 @@ fromRight (Right r) = r fromLeft :: Either a b -> a fromLeft (Left l) = l +ordI :: (Integral a) => Char -> a +ordI = fromIntegral . ord + safeGetChar :: IO (Maybe Char) safeGetChar = catch @@ -169,6 +172,14 @@ rip' code@(x:xs) fns st = do rip' xs fns (a `div` b : cs) where (b:a:cs) = st + 'M' -> + rip' xs fns (a `mod` b : cs) + where (b:a:cs) = st + + 'p' -> + rip' xs fns (a ^ b : cs) + where (b:a:cs) = st + 'G' -> rip' xs fns (booltoint (a > b) : cs) where (b:a:cs) = st @@ -251,6 +262,14 @@ rip' code@(x:xs) fns st = do Right (inblock,afterblock) -> rip' afterblock (Map.insert name inblock fns) st + '#' -> case (getfuncname xs) of + Left s -> riperror s + Right name -> do + contents <- readFile name + rip' (contents ++ drop (length name + 2) xs) fns st + + '\'' -> rip' (tail xs) fns $ ordI (head xs) : st + '$' -> do (putStrLn . List.intercalate " " . List.map show . reverse) st rip' xs fns st @@ -269,6 +288,5 @@ main = do putStrLn "Pass a rip file as the command-line argument" exitFailure else do - source <- readFile (argv !! 0) - rip source + readFile (argv !! 0) >>= rip return () |