diff --git a/TODO b/TODO index f3be6f0..7bf4fa5 100644 --- a/TODO +++ b/TODO @@ -7,4 +7,4 @@ Make an interface to declare and call c functions <- just use parrots NCI and ho CONSIDER: All functions with a continuation-based predicate suck. It's inconsistant, it takes overhead that could be avoided using dup. I don't see why it needs to stay. CONSIDER: A way to make list copies take less overhead. Lazy copies might work if data was actually immutable. -CONSIDER: (This is a big one!) Write a pre-processor to analyse the stack from the top down. Build a tree. Follow lists and execution paths (walk the code and use 'pop'-s to determine branches). Statically optimize code perhaps? Think of a way to memoize functions, and after all this is done, spit out optimized, real fun code. After this, run it using a non-lazy interpreter. \ No newline at end of file +CONSIDER: (This is a big one!) Write a pre-processor to analyse the stack from the top down. Build a tree. Follow lists and execution paths (walk the code and use 'pop'-s to determine branches). Statically optimize code perhaps? Think of a way to memoize functions, and after all this is done, spit out optimized, real fun code. After this, run it using a non-lazy interpreter. diff --git a/examples/euler1.fun b/examples/euler1.fun index 063bcb7..6503dd4 100644 --- a/examples/euler1.fun +++ b/examples/euler1.fun @@ -1,4 +1,4 @@ 999 range -[dup 3 mod swap 5 mod and not] filter +[dup [3 mod] [5 mod] land not] filter 0 [+] fold . diff --git a/src/builtins/predicates.pir b/src/builtins/predicates.pir index ed96f1e..1b309cd 100644 --- a/src/builtins/predicates.pir +++ b/src/builtins/predicates.pir @@ -138,6 +138,56 @@ true: .return() .end +.sub 'lor' + .local pmc stack + stack = get_hll_global ['private'], 'funstack' + $P0 = stack.'pop'('List') + $P1 = stack.'pop'('List') + + stack.'push'($P1 :flat) + $P1 = stack.'pop'() + if $P1 goto pushtrue + +checktwo: + stack.'push'($P0 :flat) + $P0 = stack.'pop'() + if $P0 goto pushtrue + + $P0 = new 'Boolean' + $P0 = 0 + .tailcall stack.'push'($P0) + +pushtrue: + $P0 = new 'Boolean' + $P0 = 1 + .tailcall stack.'push'($P0) +.end + +.sub 'land' + .local pmc stack + stack = get_hll_global ['private'], 'funstack' + $P0 = stack.'pop'('List') + $P1 = stack.'pop'('List') + + stack.'push'($P1 :flat) + $P1 = stack.'pop'() + unless $P1 goto pushfalse + +checktwo: + stack.'push'($P0 :flat) + $P0 = stack.'pop'() + unless $P0 goto pushfalse + + $P0 = new 'Boolean' + $P0 = 1 + .tailcall stack.'push'($P0) + +pushfalse: + $P0 = new 'Boolean' + $P0 = 0 + .tailcall stack.'push'($P0) +.end + .sub 'xor' .local pmc stack stack = get_hll_global ['private'], 'funstack'