aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2016-01-08 22:18:22 +0100
committertomsmeding <tom.smeding@gmail.com>2016-01-08 22:18:22 +0100
commit73725d0f4d1eea724829104b4483aa1585a31afd (patch)
tree40aca60a98516a4ca2a238eb1baa4da3f08cd0b3
parent534cd47f7488d7081d68c641b28a7c30c93643b9 (diff)
meta.rip stub
-rw-r--r--README.md4
-rw-r--r--meta.rip64
-rw-r--r--rip.hs4
-rw-r--r--stdlib.rip14
-rw-r--r--test.rip4
5 files changed, 84 insertions, 6 deletions
diff --git a/README.md b/README.md
index e48613b..bb466e0 100644
--- a/README.md
+++ b/README.md
@@ -9,8 +9,8 @@ All stack items are signed bigints.
- `D`: duplicate
- `i`: increment
- `d`: decrement
-- `r`: pops the number of items to rotate anti-clockwise
-- `R`: pops the number of items to rotate clockwise
+- `r`: pops the number of items to rotate anti-clockwise ("insert")
+- `R`: pops the number of items to rotate clockwise ("extract")
- `l`: push length of stack (before this push)
- `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
diff --git a/meta.rip b/meta.rip
new file mode 100644
index 0000000..9f5107b
--- /dev/null
+++ b/meta.rip
@@ -0,0 +1,64 @@
+#<stdlib.rip>
+<varinit>
+
+'l 0 <varstore> 0I[stack length storage]
+F<add_l>['l<varhaulup>3Ra<varstore>]
+F<sub_l>['l<varhaulup>3Rs<varstore>]
+F<inc_l>[1<add_l>]
+F<dec_l>[1<sub_l>]
+F<get_l>['l<varget>]
+
+0I[executes a piece of rip code, potentially recursively calling itself]
+0I[TODO: [], <>, 'c, #<>, IWCwtcF$]
+F<execrip>[
+ DW[
+ D<strlast>S<strinit>S
+ DD'0LnS'9GnmI[ 0I[0-9]
+ '0sS
+ <inc_l>
+ 0]
+ D'PEI[P SP <dec_l> 0]
+ D'SEI[P 3RS 0]
+ D'DEI[P SD3R <inc_l> 0]
+ D'iEI[P SiS 0]
+ D'dEI[P SdS 0]
+ D'lEI[P <get_l>S 0]
+ D'rEI[P lr r lR 0]
+ D'REI[P lr R lR 0]
+ D'aEI[P 3raS <dec_l> 0]
+ D'sEI[P 3rsS <dec_l> 0]
+ D'mEI[P 3rmS <dec_l> 0]
+ D'qEI[P 3rqS <dec_l> 0]
+ D'MEI[P 3rMS <dec_l> 0]
+ D'pEI[P 3rpS <dec_l> 0]
+ D'GEI[P 3rGS <dec_l> 0]
+ D'LEI[P 3rLS <dec_l> 0]
+ D'EEI[P 3rES <dec_l> 0]
+ D'nEI[P SnS 0]
+ D'oEI[P So <dec_l> 0]
+ D'OEI[P SO <dec_l> 0]
+ D'gEI[P gS <inc_l> 0]
+ D''EI[P D<strlast> S <strinit> 0]
+ D<isspace>I[P 0]
+ DI[
+ 'ro 'io 'po ':o ' o $ P
+ 0]
+ P
+ D]
+]
+
+0I[pushes whether argument is space, tab or newline]
+F<isspace>[
+ D' ESD9ES9iEaann
+]
+
+
+0I[Read all the code in a string]
+0
+gDiW[
+ <strpush>
+gDi]
+P
+
+<strrev>
+<execrip>
diff --git a/rip.hs b/rip.hs
index 3efd081..6660c76 100644
--- a/rip.hs
+++ b/rip.hs
@@ -19,7 +19,7 @@ type Stackelem = Integer
c_ripmode :: Bool
-c_ripmode = True
+c_ripmode = False
c_debugmode :: Bool
c_debugmode = False
@@ -332,7 +332,7 @@ rip' code@(x:xs) fns conns st = do
'\'' -> rip' (tail xs) fns conns $ ordI (head xs) : st
'$' -> do
- (putStrLn . intercalate " " . map show . reverse) st
+ putStrLn $ '[' : ((intercalate " " . map show . reverse) st) ++ "]"
rip' xs fns conns st
c | isSpace c ->
diff --git a/stdlib.rip b/stdlib.rip
index 56bacc6..7d209b7 100644
--- a/stdlib.rip
+++ b/stdlib.rip
@@ -8,6 +8,16 @@ F<strprint>[
PP
]
+0I[gets last character of string; destructive]
+F<strlast>[
+ 28pM
+]
+
+0I[drops last character of string; destructive]
+F<strinit>[
+ 28pq
+]
+
0I[takes string char; returns string+char]
F<strpush>[
S28pma
@@ -61,8 +71,8 @@ F<varinit>[
0lr 0lr 0lr 0I[guard]
]
-0I[INTERNAL FUNCTION
- hauls variable by name in argument to top of stack; pushes 0 0 if non-existent]
+0I[hauls variable by name in argument to top of stack (result: name value);
+ pushes 0 0 if non-existent]
F<varhaulup>[
00 0I[guard]
lRlR
diff --git a/test.rip b/test.rip
new file mode 100644
index 0000000..8e74f98
--- /dev/null
+++ b/test.rip
@@ -0,0 +1,4 @@
+1DO '+o
+2DO '=o
+aO
+9io