Initial Commit

This commit is contained in:
2018-10-15 12:47:14 -06:00
commit 0c531ffff9
55 changed files with 7285 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
/* do some function
definitions and calls
in various orders
*/
Keys -> x
F 2 x -> a
a -> Prt
NL
Halt
Def G a b c .
Mult a b -> x
Mult x c -> x
x -> Ret
Def F a b .
Add a 1 -> c
Sub b 1 -> d
G c d 5 -> r
r -> Ret
+21
View File
@@ -0,0 +1,21 @@
/* main function
for computing
factorial of
input value
*/
Keys -> n
Fact n -> f
f -> Prt NL
Halt
Def Fact n .
Less n 2 -> Jmp small:
Sub n 1 -> temp
Fact temp -> f
Mult n f -> Ret
small:
1 -> Ret
+44
View File
@@ -0,0 +1,44 @@
[ 0] 1 1000
------------ ? -------------
0: -
1: n
2: f
[ 2] 4 3
[ 4] 27 0
[ 6] 23 1 0
[ 9] 3 1
[ 11] 2 2000
[ 13] 6 0
[ 15] 23 2 0
[ 18] 23 0 2
[ 21] 28 0
[ 23] 29
[ 24] 26
[ 25] 1 2000
------------ Fact -------------
0: n
1: -
2: 2
3: 1
4: temp
5: f
[ 27] 4 5
[ 29] 22 2 2
[ 32] 22 3 1
[ 35] 16 1 0 2
[ 39] 8 2001 1
[ 42] 10 1 0 3
[ 46] 23 4 1
[ 49] 3 4
[ 51] 2 2000
[ 53] 6 1
[ 55] 23 5 1
[ 58] 11 1 0 5
[ 62] 5 1
[ 64] 1 2001
[ 66] 23 1 3
[ 69] 5 1
+29
View File
@@ -0,0 +1,29 @@
1 1000
4 3
27 0
23 1 0
3 1
2 2000
6 0
23 2 0
23 0 2
28 0
29
26
1 2000
4 5
22 2 2
22 3 1
16 1 0 2
8 2001 1
10 1 0 3
23 4 1
3 4
2 2000
6 1
23 5 1
11 1 0 5
5 1
1 2001
23 1 3
5 1
+27
View File
@@ -0,0 +1,27 @@
Keys -> x
top:
x -> Prt NL
Eq x 1 -> Jmp exit:
Rem x 2 -> r
Eq r 0 -> Jmp even:
Jmp odd:
even:
Quot x 2 -> x
Jmp top:
odd:
Mult 3 x -> x
Add x 1 -> x
Jmp top:
exit:
Halt
+15
View File
@@ -0,0 +1,15 @@
/* unit tests, sort of,
on global stuff
*/
Globs a b c .
17 -> Sto a
23 -> Sto b
41 -> Sto c
Fet a -> Prt NL
Fet b -> Prt NL
Fet c -> Prt NL
Halt
+51
View File
@@ -0,0 +1,51 @@
GetList -> a
PutList a -> .
Halt
/*--------------------------------------*/
Def GetList .
Keys -> size
Add size 1 -> objSize /* 1 extra cell for size */
New objSize -> list
size -> Put list 0 /* store size at index 0 */
1 -> index
top:
Less size index -> Jmp exit:
Keys -> input
input -> Put list index
Add index 1 -> index
Jmp top:
exit:
list -> Ret
/*--------------------------------------*/
Def PutList list .
0 -> index /* get size of list */
Get list index -> size
1 -> index
top:
Less size index -> Jmp exit:
Get list index -> value
value -> Prt 32 -> Sym
Add index 1 -> index
Jmp top:
exit:
0 -> Ret
+10
View File
@@ -0,0 +1,10 @@
ShowSyms -> .
Halt
Def ShowSyms .
65 -> Sym
33 -> Sym
97 -> Sym
NL
0 -> Ret
+22
View File
@@ -0,0 +1,22 @@
Keys -> row
Keys -> col
PasTri row col -> Prt
Halt
Def PasTri row col .
Eq col 0 -> temp1
Eq row col -> temp2
Or temp1 temp2 -> easy
easy -> Jmp easy:
Sub col 1 -> upLeft
Sub row 1 -> rowAbove
PasTri rowAbove upLeft -> res1
PasTri rowAbove col -> res2
Add res1 res2 -> Ret
easy:
1 -> Ret
+71
View File
@@ -0,0 +1,71 @@
Globs p rowSize .
Main -> .
/* ------------------------------------ */
Def Pastri2 row col .
GetArray2d row col -> temp
NotEq temp 0 -> Jmp easy:
Eq col 0 -> Jmp onEdge:
Eq col row -> Jmp onEdge:
Sub col 1 -> col1
Sub row 1 -> row1
Pastri2 row1 col1 -> temp1
Pastri2 row1 col -> temp2
Add temp1 temp2 -> result
PutArray2d row col result -> .
result -> Ret
onEdge:
PutArray2d row col 1 -> .
1 -> Ret
easy:
temp -> Ret
/* ------------------------------------ */
Def Main .
Keys -> row
Keys -> col
Add row 1 -> rowsize
Add col 1 -> colsize
Mult rowsize colsize -> n
New n -> Sto p
colsize -> Sto rowSize
Pastri2 row col -> Prt NL
Halt
/* ------------------------------------ */
Def GetArray2d r c .
Fet p -> array
Fet rowSize -> cols
Mult r cols -> index
Add c index -> index
Get array index -> result
result -> Ret
/* ------------------------------------ */
Def PutArray2d r c value .
Fet p -> array
Fet rowSize -> cols
Mult r cols -> index
Add c index -> index
value -> Put array index
0 -> Ret
+13
View File
@@ -0,0 +1,13 @@
Keys -> x
Keys -> y
Keys -> z
Add3 x y z -> Prt NL
Halt
Def Add3 a b c .
Add a b -> x
Add x c -> x
x -> Ret
+7
View File
@@ -0,0 +1,7 @@
Globs a b c .
17 -> Sto b
Fet b -> Prt
Halt