Created: 2016-08-09 Tue 22:10
: 1 2 + __ user input [ 3 ] __ output
: 1 2 swap [ 2 1 ] __ okay : 1 dup [ 1 1 ] __ exciting : 1 drop incomplete expression __ what? : 1 2 drop [ 1 ] __ okay, at least that works
dup
& swap
work like you'd expectdrop
is a little different, it takes 2 arguments and returns the first
: 1 2 3 __ how to rotate these? : 1 2 3 [] pushl __ push the thing to the left into the list [ 1 2 [ 3 ] ] __ neat : 1 2 3 [] pushl pushl [ 1 [ 2 3 ] ] __ I can just keep doing this : 1 [2 3] swap pushr __ push the thing on the right (after swap) into the list [ [ 2 3 1 ] ] __ okay, how do I get them out?
: [ 2 3 1 ] popr [ [ 2 3 ] 1 ] __ cool, it's the inverse of pushr : [ 2 3 1 ] popr swap popr swap popr swap drop [ 1 3 2 ] __ not quite what we wanted, but you get the idea
popl
?
: 2 [1 +] pushl [ 2 1 + ] : 2 [1 +] pushl popr [ [] 3 ]
: 1 2 | 3 + [ { 4 | 5 } ] __ woah : 1 2 | dup { [ 1 1 ] | [ 2 2 ] } : 1 2 | dup 1 == { [ 1 True ] | [ 2 False ] }
!
) is like drop
, except it fails if the second argument is not True
: 1 2 | dup 1 == ! [ 1 ]
: Hi There False ! drop [ Hi ] : Hi There False ! [] pushl drop [ Hi ]
: Yes Yes =:= True
True
and False
: IO Hi print There print Hi There [ IO ] : IO Hi You | print There print Hi There You There [ { IO | IO } ] __ does not handle IO alts correctly yet
IO
symbol is threaded through both print
s so that they are properly sequencedmodule a: f1: 1 + f2: 2 * dup other_module: module b module c module b: f3: swap drop module c: f4: dup dup
<module>.<word>
a.other_module
is the union of modules b & c (contains definitions from both)
: 1 2 | 3 +
[ { 4 | 5 } ]
alt_set
s, which store which branch produced which valuesabababa ... ababa
:a | b | |
---|---|---|
X | 0 | 0 |
0 | 0 | 1 |
1 | 1 | 0 |
E | 1 | 1 |
X1X + XX0 => X10 X1X + X00 => XE0 __ conflict (E)
alt_set
propagationreduce()
.value.type
alt_set
.value.alt_set
as_conflict()
across arguments
reduce_arg()
alt_set
Example
: 1 2 | dup 10 * { [ 1 10 ] | [ 2 20 ] }
alt_set
s correlate the results so that, for example, [ 1 20 ]
is not valid1 +
produces the following trace:cell[0]: var, type = ?i x1 cell[1]: val 1, type = i x1 cell[2]: __primitive.add 0 1, type = ?i x1 cell[3]: return [ 2 ], type = r x1
module tests: fact2: [1 == 1 swap !] [dup 1- swap [*] pushl swap pushr pushl get2 fact2] | pushl pushl get2 get2: popr swap popr swap drop swap
int tests_fact2(int int1, int int0, int *out_int0) { int int2 = 1; int sym3; int int4 = 1; int int5; int int7; int int8 = 1; int int9; body: sym3 = __primitive_eq(int0, int2); // assert int5 = int4; if(!sym3) goto block7; phi5: *out_int0 = int5; return int1; block7: int7 = __primitive_mul(int1, int0); int9 = __primitive_sub(int0, int8); // tail call int1 = int7; int0 = int9; goto body; }
module tests: fib: [dup 1 <= !] [1- dup 1- fib swap fib +] | pushl popr swap drop
int tests_fib(int int0) { int int1 = 1; int sym2; int int3; int int5 = 1; int int6; int int7 = 1; int int8; int int9; int int10; int int11; body: sym2 = __primitive_lte(int0, int1); // assert int3 = int0; if(!sym2) goto block5; phi3: return int3; block5: int6 = __primitive_sub(int0, int5); int8 = __primitive_sub(int6, int7); int9 = tests_fib(int8); int10 = tests_fib(int6); int11 = __primitive_add(int9, int10); return int11; }