Skip to content

Commit 9f8e595

Browse files
author
Jarrod
committed
Added lor and land. The 'l' stands for both 'list' and 'lazy'. They take 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.
1 parent 3419602 commit 9f8e595

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

TODO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ Make an interface to declare and call c functions <- just use parrots NCI and ho
77
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.
88
CONSIDER: A way to make list copies take less overhead. Lazy copies might work if data was actually immutable.
99

10-
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.
10+
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.

examples/euler1.fun

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
999 range
2-
[dup 3 mod swap 5 mod and not] filter
2+
[dup [3 mod] [5 mod] land not] filter
33
0 [+] fold
44
.

src/builtins/predicates.pir

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,56 @@ true:
138138
.return()
139139
.end
140140

141+
.sub 'lor'
142+
.local pmc stack
143+
stack = get_hll_global ['private'], 'funstack'
144+
$P0 = stack.'pop'('List')
145+
$P1 = stack.'pop'('List')
146+
147+
stack.'push'($P1 :flat)
148+
$P1 = stack.'pop'()
149+
if $P1 goto pushtrue
150+
151+
checktwo:
152+
stack.'push'($P0 :flat)
153+
$P0 = stack.'pop'()
154+
if $P0 goto pushtrue
155+
156+
$P0 = new 'Boolean'
157+
$P0 = 0
158+
.tailcall stack.'push'($P0)
159+
160+
pushtrue:
161+
$P0 = new 'Boolean'
162+
$P0 = 1
163+
.tailcall stack.'push'($P0)
164+
.end
165+
166+
.sub 'land'
167+
.local pmc stack
168+
stack = get_hll_global ['private'], 'funstack'
169+
$P0 = stack.'pop'('List')
170+
$P1 = stack.'pop'('List')
171+
172+
stack.'push'($P1 :flat)
173+
$P1 = stack.'pop'()
174+
unless $P1 goto pushfalse
175+
176+
checktwo:
177+
stack.'push'($P0 :flat)
178+
$P0 = stack.'pop'()
179+
unless $P0 goto pushfalse
180+
181+
$P0 = new 'Boolean'
182+
$P0 = 1
183+
.tailcall stack.'push'($P0)
184+
185+
pushfalse:
186+
$P0 = new 'Boolean'
187+
$P0 = 0
188+
.tailcall stack.'push'($P0)
189+
.end
190+
141191
.sub 'xor'
142192
.local pmc stack
143193
stack = get_hll_global ['private'], 'funstack'

0 commit comments

Comments
 (0)