Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use iter opcode instead of new 'Iterator'

Signed-off-by: Ted Reed <ted.reed@gmail.com>
  • Loading branch information...
commit ff8ddf9f0bdd50b8fba27e478e7991f8c91a8348 1 parent 0503fb6
Joeri Samson joeri authored treed committed
18 cardinal.pir
View
@@ -81,13 +81,13 @@ to the cardinal compiler.
.param pmc args_str
## create ARGS global.
- .local pmc args, iter
+ .local pmc args, it
args = new 'CardinalArray'
- iter = new 'Iterator', args_str
- $P0 = shift iter
+ it = iter args_str
+ $P0 = shift it
args_loop:
- unless iter goto args_end
- $P0 = shift iter
+ unless it goto args_end
+ $P0 = shift it
push args, $P0
goto args_loop
args_end:
@@ -98,11 +98,11 @@ to the cardinal compiler.
.include 'iterator.pasm'
$P0 = get_hll_global ['cardinal'], '@?END_BLOCKS'
- iter = new 'Iterator', $P0
- iter = .ITERATE_FROM_END
+ it = iter $P0
+ it = .ITERATE_FROM_END
iter_loop:
- unless iter goto iter_end
- $P0 = pop iter
+ unless it goto iter_end
+ $P0 = pop it
$P0()
goto iter_loop
iter_end:
10 src/builtins/eval.pir
View
@@ -117,7 +117,7 @@ such as C<eval>, C<require>, and C<use>.
.local pmc it, item, callerns
$P0 = getinterp
callerns = $P0['namespace';1]
- it = new 'Iterator', module
+ it = iter module
it_loop:
unless it goto it_loop_end
$S0 = shift it
@@ -148,11 +148,11 @@ such as C<eval>, C<require>, and C<use>.
library = compiler.'load_library'(name)
imports = library['symbols']
imports = imports['DEFAULT']
- .local pmc iter, item
- iter = new 'Iterator', imports
+ .local pmc it, item
+ it = iter imports
import_loop:
- unless iter goto import_loop_end
- $S0 = shift iter
+ unless it goto import_loop_end
+ $S0 = shift it
$P0 = imports[$S0]
callerns[$S0] = $P0
goto import_loop
16 src/builtins/guts.pir
View
@@ -105,18 +105,18 @@ Internal helper method to create a class.
.sub '!keyword_class'
.param string name
- .local pmc class, resolve_list, methods, iter
+ .local pmc class, resolve_list, methods, it
# Create class.
class = newclass name
# Set resolve list to include all methods of the class.
methods = inspect class, 'methods'
- iter = new 'Iterator', methods
+ it = iter methods
resolve_list = new 'ResizableStringArray'
resolve_loop:
- unless iter goto resolve_loop_end
- $P0 = shift iter
+ unless it goto resolve_loop_end
+ $P0 = shift it
push resolve_list, $P0
goto resolve_loop
resolve_loop_end:
@@ -231,14 +231,14 @@ Adds an attribute with the given name to the class.
.sub 'die'
.param pmc list :slurpy
- .local pmc iter
+ .local pmc it
.local string message
message = ''
- iter = new 'Iterator', list
+ it = iter list
iter_loop:
- unless iter goto iter_end
- $P0 = shift iter
+ unless it goto iter_end
+ $P0 = shift it
$S0 = $P0
message .= $S0
goto iter_loop
8 src/builtins/op.pir
View
@@ -34,12 +34,12 @@ src/builtins/op.pir - Cardinal ops
.param pmc a
.param pmc b
$P0 = new 'CardinalArray'
- .local pmc iter
- iter = new 'Iterator', a
+ .local pmc it
+ it = iter a
$P3 = get_hll_global['Bool'], 'False'
iter_loop:
- unless iter goto done
- $P1 = shift iter
+ unless it goto done
+ $P1 = shift it
$P2 = b.'include?'($P1)
$I0 = 'infix:=='($P2, $P3)
eq $I0, 1, appendit
8 src/builtins/say.pir
View
@@ -10,11 +10,11 @@ builtin functions for Ruby.
.sub 'print'
.param pmc args :slurpy
- .local pmc iter
- iter = new 'Iterator', args
+ .local pmc it
+ it = iter args
iter_loop:
- unless iter goto iter_end
- $P0 = shift iter
+ unless it goto iter_end
+ $P0 = shift it
print $P0
goto iter_loop
iter_end:
20 src/classes/Array.pir
View
@@ -292,11 +292,11 @@ Return true if self contains ELEMENT
=cut
.sub 'include?' :method
.param pmc args
- .local pmc iter
- iter = new 'Iterator', self
+ .local pmc it
+ it = iter self
iter_loop:
- unless iter goto done_f
- $P0 = shift iter
+ unless it goto done_f
+ $P0 = shift it
eq $P0, args, done_t
goto iter_loop
done_f:
@@ -899,7 +899,7 @@ Run C<block> once for each item in C<self>, with the item passed as an arg.
.sub 'each' :method
.param pmc block :named('!BLOCK')
- $P0 = new 'Iterator', self
+ $P0 = iter self
each_loop:
unless $P0 goto each_loop_end
$P1 = shift $P0
@@ -933,7 +933,7 @@ Creates a new Array containing the results and returns it.
.param pmc block :named('!BLOCK')
.local pmc result
result = new 'CardinalArray'
- $P0 = new 'Iterator', self
+ $P0 = iter self
each_loop:
unless $P0 goto each_loop_end
$P1 = shift $P0
@@ -971,7 +971,7 @@ Creates a new Array containing the results and returns it.
.local pmc returnMe
.local pmc iterator
returnMe = new 'CardinalArray'
- iterator = new 'Iterator', self
+ iterator = iter self
each_loop:
unless iterator goto each_loop_end
$P1 = shift iterator
@@ -982,7 +982,7 @@ Creates a new Array containing the results and returns it.
goto each_loop
inner_flatten:
$P2 = $P1.'flatten'()
- $P3 = new 'Iterator', $P2
+ $P3 = iter $P2
inner_loop:
unless $P3 goto each_loop
$P4 = shift $P3
@@ -1100,12 +1100,12 @@ The zip operator.
# Get minimum element count - what we'll zip to.
.local pmc iterator, args_iter, arg, item
.local int i
- iterator = new 'Iterator', self
+ iterator = iter self
i = 0
setup_loop:
unless iterator, setup_loop_done
- args_iter = new 'Iterator', args
+ args_iter = iter args
item = new 'CardinalArray'
$P0 = shift iterator
item.'push'($P0)
4 src/classes/Dir.pir
View
@@ -138,7 +138,7 @@ Perform initializations and create the Dir class
os = new 'OS'
list = new 'CardinalArray'
$P0 = os.'readdir'(path)
- $P1 = new 'Iterator', $P0
+ $P1 = iter $P0
loop:
unless $P1 goto loop_end
$P2 = shift $P1
@@ -154,7 +154,7 @@ Perform initializations and create the Dir class
.param pmc block :named('!BLOCK')
.local pmc names
names = self.'entries'(path)
- $P0 = new 'Iterator', names
+ $P0 = iter names
loop:
unless $P0 goto loop_end
$P1 = shift $P0
2  src/classes/File.pir
View
@@ -200,7 +200,7 @@ Perform initializations and create the File class
.sub 'unlink' :method
.param pmc file_names :slurpy
.local pmc os
- $P0 = new 'Iterator', file_names
+ $P0 = iter file_names
os = new 'OS'
loop:
unless $P0 goto done
2  src/classes/GC.pir
View
@@ -101,7 +101,7 @@ Perform initializations and create the GC class
addr_space[$I0] = test
#$P0 = addr_space.'methods'()
#say $P0
- itr = new 'Iterator', addr_space
+ itr = iter addr_space
print "created iterator: "
say itr
$S0 = typeof itr
78 src/classes/Hash.pir
View
@@ -24,15 +24,15 @@ src/classes/CardinalHash.pir - Cardinal hash class and related functions
.sub 'get_string' :vtable :method
$S0 = '{'
- .local pmc iter
- iter = new 'Iterator', self
+ .local pmc it
+ it = iter self
goto loop_start
loop:
- unless iter goto end
+ unless it goto end
$S0 = concat $S0, ','
loop_start:
- $S1 = shift iter
- $S2 = iter[$S1]
+ $S1 = shift it
+ $S2 = it[$S1]
$S0 = concat $S0, $S1
$S0 = concat $S0, '=>'
concat $S0, $S2
@@ -49,15 +49,15 @@ Returns a string of keys and values appended together.
=cut
.sub 'to_s' :method
- .local pmc iter
+ .local pmc it
.local pmc rv
- iter = new 'Iterator', self
+ it = iter self
rv = new 'CardinalString'
loop:
- unless iter goto end
- $S1 = shift iter
+ unless it goto end
+ $S1 = shift it
concat rv, $S1
- $S1 = iter[$S1]
+ $S1 = it[$S1]
concat rv, $S1
goto loop
end:
@@ -73,15 +73,15 @@ Returns elements of hash as array of C<Pair(key, value)>
=cut
.sub 'kv' :method
- .local pmc iter
+ .local pmc it
.local pmc rv
- iter = new 'Iterator', self
+ it = iter self
rv = new 'CardinalArray'
loop:
- unless iter goto end
- $S1 = shift iter
+ unless it goto end
+ $S1 = shift it
push rv, $S1
- $S1 = iter[$S1]
+ $S1 = it[$S1]
push rv, $S1
goto loop
end:
@@ -91,13 +91,13 @@ Returns elements of hash as array of C<Pair(key, value)>
.sub 'keys' :method
- .local pmc iter
+ .local pmc it
.local pmc rv
- iter = new 'Iterator', self
+ it = iter self
rv = new 'CardinalArray'
loop:
- unless iter goto end
- $S1 = shift iter
+ unless it goto end
+ $S1 = shift it
push rv, $S1
goto loop
end:
@@ -106,14 +106,14 @@ Returns elements of hash as array of C<Pair(key, value)>
.sub 'values' :method
- .local pmc iter
+ .local pmc it
.local pmc rv
- iter = new 'Iterator', self
+ it = iter self
rv = new 'CardinalArray'
loop:
- unless iter goto end
- $S1 = shift iter
- $S1 = iter[$S1]
+ unless it goto end
+ $S1 = shift it
+ $S1 = it[$S1]
push rv, $S1
goto loop
end:
@@ -128,12 +128,12 @@ Run C<block> once for each item in C<self>, with the key and value passed as arg
.sub 'each' :method
.param pmc block
- .local pmc iter
- iter = new 'Iterator', self
+ .local pmc it
+ it = iter self
each_loop:
- unless iter goto each_loop_end
- $P1 = shift iter
- $P2 = iter[$P1]
+ unless it goto each_loop_end
+ $P1 = shift it
+ $P2 = it[$P1]
block($P1,$P2)
goto each_loop
each_loop_end:
@@ -142,13 +142,13 @@ Run C<block> once for each item in C<self>, with the key and value passed as arg
.sub 'to_a' :method
.local pmc newlist
.local pmc item
- .local pmc iter
+ .local pmc it
newlist = new 'CardinalArray'
- iter = new 'Iterator', self
+ it = iter self
each_loop:
- unless iter goto each_loop_end
- $P1 = shift iter
- $P2 = iter[$P1]
+ unless it goto each_loop_end
+ $P1 = shift it
+ $P2 = it[$P1]
item = new 'CardinalArray'
push item, $P1
push item, $P2
@@ -162,12 +162,12 @@ Run C<block> once for each item in C<self>, with the key and value passed as arg
## FIXME: Parrot currently requires us to write our own "clone" method.
.sub 'clone' :vtable :method
$P0 = new 'CardinalHash'
- .local pmc iter
- iter = new 'Iterator', self
+ .local pmc it
+ it = iter self
loop:
- unless iter goto end
- $P1 = shift iter
- $P2 = iter[$P1]
+ unless it goto end
+ $P1 = shift it
+ $P2 = it[$P1]
$P0[$P1] = $P2
goto loop
end:
10 src/classes/Object.pir
View
@@ -44,18 +44,18 @@ Internal helper method to create a class.
.sub '!keyword_class' :method
.param string name
- .local pmc class, resolve_list, methods, iter
+ .local pmc class, resolve_list, methods, it
# Create class.
class = newclass name
# Set resolve list to include all methods of the class.
methods = inspect class, 'methods'
- iter = new 'Iterator', methods
+ it = iter methods
resolve_list = new 'ResizableStringCardinalArray'
resolve_loop:
- unless iter goto resolve_loop_end
- $P0 = shift iter
+ unless it goto resolve_loop_end
+ $P0 = shift it
push resolve_list, $P0
goto resolve_loop
resolve_loop_end:
@@ -292,7 +292,7 @@ Get a list of all methods in the object.
$P0 = class self
$P1 = $P0.'methods'()
.local pmc meth_iter
- meth_iter = new 'Iterator', $P1
+ meth_iter = iter $P1
.local pmc method_list
method_list = new 'CardinalArray'
methods_loop:
4 src/classes/String.pir
View
@@ -103,7 +103,7 @@ Returns a new CardinalString with the characters of C<self> in reverse order.
res = new 'CardinalString'
.local pmc iterator, item
- iterator = new 'Iterator', self
+ iterator = iter self
each_loop:
unless iterator goto each_loop_done
item = shift iterator
@@ -471,7 +471,7 @@ Warning: Partial implementation. Look for TODO
.sub 'each_byte' :method
.param pmc block :named('!BLOCK')
.local pmc iterator, item
- iterator = new 'Iterator', self
+ iterator = iter self
each_loop:
unless iterator goto each_loop_done
item = shift iterator
2  src/classes/Time.pir
View
@@ -158,7 +158,7 @@ Returns true if he object is defined, false otherwise
.return (return_value)
#print out all values in the time array
- #$P2 = new 'Iterator', $P0
+ #$P2 = iter $P0
#each_loop:
# unless $P2 goto done
# $P3 = shift $P2
10 src/parser/quote_expression.pir
View
@@ -41,13 +41,13 @@
action = options['action']
## set up options based on flags
- .local pmc flagarray, iter
+ .local pmc flagarray, it
flagarray = split ' ', flags
- iter = new 'Iterator', flagarray
+ it = iter flagarray
iter_loop:
- unless iter goto iter_end
+ unless it goto iter_end
.local string oname
- oname = shift iter
+ oname = shift it
oname = substr oname, 1
options[oname] = 1
if oname == 'ww' goto opt_ww
@@ -115,7 +115,7 @@
## wwdoubleopts = clone options
wwdoubleopts = new 'Hash'
.local pmc iter2
- iter2 = new 'Iterator', options
+ iter2 = iter options
iter2_loop:
unless iter2 goto iter2_end
$S0 = shift iter2
Please sign in to comment.
Something went wrong with that request. Please try again.