Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Convert new of parrot-based things to root_new (src/builtins)
  • Loading branch information
pmichaud committed May 20, 2009
1 parent b516413 commit 20ec24c
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 105 deletions.
6 changes: 3 additions & 3 deletions src/builtins/any-list.pir
Expand Up @@ -118,7 +118,7 @@ Return a List with the keys of the invocant.
.namespace ['Any']
.sub 'kv' :method
.local pmc result, it
result = new 'List'
result = new ['List']
it = self.'iterator'()
.local int i
i = 0
Expand Down Expand Up @@ -267,7 +267,7 @@ Parrot's built-in sort algorithm.

## create a FPA of indexes to be sorted using cmp
.local pmc fpa
fpa = new 'FixedPMCArray'
fpa = root_new ['parrot';'FixedPMCArray']
assign fpa, elems
$I0 = 0
fpa_loop:
Expand All @@ -293,7 +293,7 @@ Parrot's built-in sort algorithm.
## Because of TT #56, we can't store Sub PMCs directly into
## the namespace. So, we create an array to hold it for us.
set_global '@!compare', list
$P0 = new 'ResizablePMCArray'
$P0 = root_new ['parrot';'ResizablePMCArray']
push $P0, by
set_global '@!compare_by', $P0
.const 'Sub' $P99 = '!COMPARE_DO'
Expand Down
8 changes: 4 additions & 4 deletions src/builtins/any-num.pir
Expand Up @@ -24,7 +24,7 @@ the size of that file down and to emphasize their generic,
'!EXPORT'('abs,int,log,polar,sqrt,truncate,unpolar', 'from'=>$P0)

## pre-seed a random number generator
$P0 = new 'Random'
$P0 = root_new ['parrot';'Random']
set_hll_global ['Any'], '$!random', $P0
srand()
.end
Expand Down Expand Up @@ -169,7 +169,7 @@ interval -pi <= $theta <= pi .
x = self
pi = atan 1
pi *= 4
roots = new 'FixedPMCArray'
roots = root_new ['parrot';'FixedPMCArray']
if n > 0 goto positive
roots = 1 # single element array
roots[0] = 'NaN'
Expand Down Expand Up @@ -199,7 +199,7 @@ interval -pi <= $theta <= pi .
$N1 = ln $N4 # ln(abs(x)) = ln(r)
loop:
if $I0 >= n goto done
$P2 = new 'Complex' # this can surely be optimized
$P2 = root_new ['parrot';'Complex'] # this can surely be optimized
$N3 = $N0
$N3 *= 2
$N3 *= pi
Expand Down Expand Up @@ -233,7 +233,7 @@ interval -pi <= $theta <= pi .
.local num mag
.local pmc result
mag = self
result = new 'Complex'
result = root_new ['parrot';'Complex']
$N0 = cos angle
$N0 *= mag
result[0] = $N0
Expand Down
48 changes: 23 additions & 25 deletions src/builtins/any-str.pir
Expand Up @@ -63,7 +63,7 @@ the size of that file down and to emphasize their generic,
if lastchar != "\r" goto done
chopn tmps, 1
done:
retv = new 'Str'
retv = new ['Str']
retv = tmps
.return (retv)
.end
Expand Down Expand Up @@ -176,13 +176,12 @@ file.
if pos < 0 goto fail
done:
$P0 = new 'Int'
$P0 = new ['Int']
$P0 = pos
.return ($P0)
fail:
$P0 = new 'Failure'
.return ($P0)
.tailcall '!FAIL'("Attempt to index from negative position")
.end
=item match()
Expand Down Expand Up @@ -227,7 +226,7 @@ file.
substring_search:
$I0 = self.'isa'('String')
if $I0 goto self_string
$P0 = new 'String'
$P0 = root_new ['parrot';'String']
$S0 = self
$P0 = $S0
goto do_search
Expand All @@ -238,13 +237,12 @@ file.
if pos < 0 goto fail
done:
$P0 = new 'Int'
$P0 = new ['Int']
$P0 = pos
.return ($P0)
fail:
$P0 = new 'Failure'
.return ($P0)
.tailcall '!FAIL'("Attempt to index from negative position")
.end
=item split
Expand Down Expand Up @@ -304,7 +302,7 @@ B<Note:> partial implementation only
.sub '!transtable' :multi(_)
.param pmc r
.local pmc retval, tmps
retval = new 'ResizablePMCArray'
retval = root_new ['parrot';'ResizablePMCArray']
tmps = clone r
range_loop:
unless tmps, done
Expand All @@ -320,7 +318,7 @@ B<Note:> partial implementation only
.sub '!transtable' :multi('Sub')
.param pmc r
.local pmc retval
retval = new 'ResizablePMCArray'
retval = root_new ['parrot';'ResizablePMCArray']
push retval, r
.return(retval)
.end
Expand All @@ -330,8 +328,8 @@ B<Note:> partial implementation only
.local pmc retval, prior, frm, to, next_str
.local int start, end, len, ind, skipped, r_start, r_end, s_len
.local string p
retval = new 'ResizablePMCArray'
prior = new 'ResizablePMCArray'
retval = root_new ['parrot';'ResizablePMCArray']
prior = root_new ['parrot';'ResizablePMCArray']
start = 0
skipped = 0
len = length str
Expand Down Expand Up @@ -360,7 +358,7 @@ B<Note:> partial implementation only
process_pstring:
unless prior, start_range
$S2 = shift prior
next_str = new 'Str'
next_str = new ['Str']
next_str = $S2
push retval, next_str
goto process_pstring
Expand All @@ -372,7 +370,7 @@ B<Note:> partial implementation only
# If needed we can switch this over to use a true string Range
if $I0 > $I1 goto next_loop
$S2 = chr $I0
next_str = new 'Str'
next_str = new ['Str']
next_str = $S2
push retval, next_str
inc $I0
Expand All @@ -394,7 +392,7 @@ B<Note:> partial implementation only
process_lstring:
unless prior, check_rval
$S0 = shift prior
next_str = new 'Str'
next_str = new ['Str']
next_str = $S0
push retval, next_str
goto process_lstring
Expand Down Expand Up @@ -427,8 +425,8 @@ B<Note:> partial implementation only
.local int len, klen, vlen, adjpos, pos, ind, nhits
by = get_hll_global 'infix:<=>'
# itable maps matching positions to key, value array
itable = new 'Perl6Hash'
retv = new 'Str'
itable = new ['Perl6Hash']
retv = new ['Str']

init_pair_loop:
.local pmc pair, pkey, pval, pairlist
Expand Down Expand Up @@ -486,7 +484,7 @@ B<Note:> partial implementation only
val = lastval
goto init_index_loop
get_prev2:
val = new 'Str'
val = new ['Str']
val = ''
init_index_loop:
nhits = 0
Expand Down Expand Up @@ -519,7 +517,7 @@ B<Note:> partial implementation only
$I1 = prev_key.'chars'()
if klen < $I1 goto next_hit
new_hit:
$P1 = new 'ResizablePMCArray'
$P1 = root_new ['parrot';'ResizablePMCArray']
push $P1, km
push $P1, val
itable[ind] = $P1
Expand All @@ -536,19 +534,19 @@ B<Note:> partial implementation only
.local pmc hit_set, inv_set, inv_table, it
.local int kvdiff, llm, pr_pos, st, end
.local string vs
hit_set = new 'ResizableIntegerArray'
hit_set = root_new ['parrot';'ResizableIntegerArray']
normal_hits:
hit_set = itable.'keys'()
hit_set = hit_set.'sort'(by)
unless comp, st_trans
comp_hits:
# if :c is indicated, rebuild complement set and use that instead
# of original itable
inv_table = new 'Perl6Hash'
inv_table = new ['Perl6Hash']
st = 0
end = 0
len = length tmps
inv_set = new 'ResizableIntegerArray'
inv_set = root_new ['parrot';'ResizableIntegerArray']
it = hit_set.'iterator'()
comp_loop1:
unless it, fence_post
Expand All @@ -563,7 +561,7 @@ B<Note:> partial implementation only
# modify the following to replace the entire unmatched range once
# or each char (latter implemented for now to match tests)
push inv_set, st
$P1 = new 'ResizablePMCArray'
$P1 = root_new ['parrot';'ResizablePMCArray']
push $P1, 'x' # placeholder char; we can replace with substr if needed
push $P1, comp_match
inv_table[st] = $P1
Expand All @@ -582,7 +580,7 @@ B<Note:> partial implementation only
st_trans:
.local int k_isa_match, v_isa_closure, pass_match
.local pmc lastmatch, v
lastmatch = new 'Str'
lastmatch = new ['Str']
lastmatch = ''
pos = 0 # original unadjusted position
pr_pos = 0 # prior unadjusted position
Expand Down Expand Up @@ -779,7 +777,7 @@ Partial implementation. The :g modifier on regexps doesn't work, for example.
.local int n_cnt, x_cnt
n_cnt = 0
x_cnt = 0
matchlist = new 'ResizablePMCArray'
matchlist = root_new ['parrot';'ResizablePMCArray']
match = regex.'!invoke'(source)
unless match goto matchlist_done
Expand Down
14 changes: 7 additions & 7 deletions src/builtins/assign.pir
Expand Up @@ -139,7 +139,7 @@ src/builtins/assign.pir - assignments

## now build our 'real' source list, cloning any targets we encounter
.local pmc slist, it
slist = new 'List'
slist = new ['List']
it = iter source
source_loop:
unless it goto source_done
Expand Down Expand Up @@ -169,15 +169,15 @@ src/builtins/assign.pir - assignments
if $I0 goto assign_hash
assign_scalar:
if slist goto have_slist
slist = new 'Nil'
slist = new ['Nil']
have_slist:
$P0 = shift slist
'infix:='(cont, $P0)
goto assign_loop
assign_array:
assign_hash:
cont.'!STORE'(slist)
slist = new 'Nil'
slist = new ['Nil']
goto assign_loop
assign_done:
.return (list)
Expand Down Expand Up @@ -332,7 +332,7 @@ src/builtins/assign.pir - assignments
# Create result list and get iterators over the two.
go_hyper:
.local pmc result, it_a, it_b
result = new 'Perl6Array'
result = new ['Perl6Array']
it_a = iter a
it_b = iter b

Expand Down Expand Up @@ -365,7 +365,7 @@ src/builtins/assign.pir - assignments
cur_a = 'list'(cur_a)
recurse:
$P0 = '!HYPEROP'(opname, cur_a, cur_b, dwim_lhs, dwim_rhs)
$P0 = new 'Perl6Scalar', $P0
$P0 = root_new ['parrot';'Perl6Scalar'], $P0
push result, $P0
goto loop

Expand All @@ -386,7 +386,7 @@ src/builtins/assign.pir - assignments

# First, work out applicable keys.
.local pmc keys_applicable, it
keys_applicable = new 'ResizablePMCArray'
keys_applicable = root_new ['parrot';'ResizablePMCArray']
$I0 = dwim_lhs * dwim_rhs
if $I0 goto intersection
$I0 = dwim_lhs + dwim_rhs
Expand Down Expand Up @@ -433,7 +433,7 @@ src/builtins/assign.pir - assignments
.local pmc opfunc, result
$S0 = concat 'infix:', opname
opfunc = find_name $S0
result = new 'Perl6Hash'
result = new ['Perl6Hash']
it = iter keys_applicable
it_loop:
unless it goto it_loop_end
Expand Down

0 comments on commit 20ec24c

Please sign in to comment.