Skip to content

Commit

Permalink
Added lor and land. The 'l' stands for both 'list' and 'lazy'. They t…
Browse files Browse the repository at this point in the history
…ake list arguments and run them, instead of pulling two value types off the stack. The big advantage is that these are short circuiting expressions, so using these should save a few cpu cycles.
  • Loading branch information
Jarrod committed Feb 7, 2009
1 parent 3419602 commit 9f8e595
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion TODO
Expand Up @@ -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.
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.
2 changes: 1 addition & 1 deletion 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
.
50 changes: 50 additions & 0 deletions src/builtins/predicates.pir
Expand Up @@ -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'
Expand Down

0 comments on commit 9f8e595

Please sign in to comment.