Skip to content

Commit

Permalink
Convert any-num to the rand/srand dynops
Browse files Browse the repository at this point in the history
The Random PMC was deprecated in Parrot 1.1 and is being removed as part
of 1.5 . This fixes the Rakudo build to use the dynamically loadable
math ops instead.

Plus changes by moritz:

 + bump build/PARROT_REVISION to r40598 where dynops installing is fixed
 + remove left-over usages of !random hll_global

Signed-off-by: Moritz Lenz <moritz@faui2k3.org>
  • Loading branch information
leto authored and moritz committed Aug 16, 2009
1 parent 9959b21 commit 5637208
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build/PARROT_REVISION
@@ -1 +1 @@
40521
40598
7 changes: 3 additions & 4 deletions src/builtins/any-list.pir
Expand Up @@ -105,18 +105,18 @@ Return a List with the keys of the invocant.
.end

.namespace ['Any']
.loadlib 'math_ops'
.sub 'pick' :method :multi()
.param int p_num :optional
.param int has_num :opt_flag
.param pmc p_repl :optional :named('repl')
.param int has_repl :opt_flag

.local pmc list, result, rand
.local pmc list, result
.local int elems
list = self.'list'()
elems = list.'elems'()
result = 'list'()
rand = get_hll_global ['Any'], '$!random'

if has_num goto have_num
p_num = 1
Expand All @@ -134,8 +134,7 @@ Return a List with the keys of the invocant.
loop:
unless p_num > 0 goto done
unless elems > 0 goto done
$N0 = rand
$N0 *= elems
$N0 = rand elems
$I0 = $N0
$P0 = list[$I0]
push result, $P0
Expand Down
13 changes: 4 additions & 9 deletions src/builtins/any-num.pir
Expand Up @@ -19,14 +19,13 @@ the size of that file down and to emphasize their generic,
=cut

.namespace []
.loadlib 'math_ops'
.sub 'onload' :anon :init :load
$P0 = get_hll_namespace ['Any']
'!EXPORT'('abs,int,log,polar,sqrt,truncate,unpolar', 'from'=>$P0)

## pre-seed a random number generator
$P0 = root_new ['parrot';'Random']
set_hll_global ['Any'], '$!random', $P0
srand()
'srand'()
.end


Expand Down Expand Up @@ -103,18 +102,14 @@ error.
if has_seed goto have_seed
seed = time
have_seed:
$P0 = get_hll_global ['Any'], '$!random'
$I0 = seed
$P0 = $I0
srand seed
.return ()
.end

.namespace ['Any']
.sub 'srand' :method
$N0 = self
$I0 = $N0
$P0 = get_hll_global ['Any'], '$!random'
$P0 = $I0
srand $N0
.return ()
.end

Expand Down
6 changes: 2 additions & 4 deletions src/setting/Any-num.pm
Expand Up @@ -30,10 +30,8 @@ class Any is also {
our Num method rand() {
Q:PIR {
$N0 = self
$P0 = get_hll_global ['Any'], '$!random'
$N1 = $P0
$N0 *= $N1
%r = box $N0
$N1 = rand $N0
%r = box $N1
}
}

Expand Down

0 comments on commit 5637208

Please sign in to comment.