Skip to content

Commit

Permalink
Use a portable API for low-level list ops
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Oct 1, 2010
1 parent 4f60774 commit 747ffe7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
46 changes: 23 additions & 23 deletions lib/SAFE.setting
Expand Up @@ -344,48 +344,48 @@ my class List is Cool {
method !elem is rawcall { Q:CgOp { (pos 1) } }
sub count-items($self) { Q:CgOp {
(box Num (cast num (rawcall (getslot items vvarlist (@ {$self})) Count)))
(box Num (cast num (vvarlist_count (getslot items vvarlist (@ {$self})))))
} }
sub shift-item($self) { Q:CgOp {
(rawcall (getslot items clr:VarDeque (@ {$self})) Shift)
(vvarlist_shift (getslot items vvarlist (@ {$self})))
} }
method !item-at-pos($ix) { Q:CgOp {
(getindex (cast int (unbox num (@ {$ix}))) (getslot items clr:VarDeque (@ {self})))
(vvarlist_item (cast int (unbox num (@ {$ix}))) (getslot items vvarlist (@ {self})))
} }
sub pop-item($self) { Q:CgOp {
(rawcall (getslot items clr:VarDeque (@ {$self})) Pop)
(vvarlist_pop (getslot items vvarlist (@ {$self})))
} }
sub push-iterator is rawcall { Q:CgOp {
(rnull (rawcall (getslot rest clr:VarDeque (@ (pos 0))) Push (pos 1)))
(rnull (vvarlist_push (getslot rest vvarlist (@ (pos 0))) (pos 1)))
} }
sub push-item is rawcall { Q:CgOp {
(prog (rawcall (getslot items clr:VarDeque (@ (pos 0))) Push (pos 1)) (null var))
(rnull (vvarlist_push (getslot items vvarlist (@ (pos 0))) (pos 1)))
} }
method !fill($nr) { Q:CgOp {
(letn nr (cast int (unbox num (@ {$nr})))
items (getslot items clr:VarDeque (@ {self}))
rest (getslot rest clr:VarDeque (@ {self}))
items (getslot items vvarlist (@ {self}))
rest (getslot rest vvarlist (@ {self}))
flat (getslot flat bool (@ {self}))
v (null var)
ItMo (rawcall (@ {Iterator}) GetMO)
ItMo (obj_llhow (@ {Iterator}))
(whileloop 0 0
(ternary (< (rawcall (l items) Count) (l nr))
(!= (rawcall (l rest) Count) (i 0)) (b 0))
(ternary (< (vvarlist_count (l items)) (l nr))
(!= (vvarlist_count (l rest)) (i 0)) (b 0))
(prog
(l v (rawcall (l rest) Shift))
(l v (vvarlist_shift (l rest)))
(ternary (ternary (l flat) (getfield islist (l v)) (b 0))
(rawcall (l rest) Unshift (methodcall (l v) iterator))
(ternary (rawcall (@ (l v)) Isa (l ItMo))
(rawcall (l rest) UnshiftN (unbox 'clr:Variable[]'
(vvarlist_unshift (l rest) (methodcall (l v) iterator))
(ternary (obj_isa (@ (l v)) (l ItMo))
(vvarlist_unshiftn (l rest) (unbox fvarlist
(@ (methodcall (l v) reify))))
(rawcall (l items) Push (methodcall {self} !elem (l v)))))))
(box Bool (>= (rawcall (l items) Count) (l nr))))
(vvarlist_push (l items) (methodcall {self} !elem (l v)))))))
(box Bool (>= (vvarlist_count (l items)) (l nr))))
} }
method Bool() { self!fill(1) }
Expand Down Expand Up @@ -460,23 +460,23 @@ my class Array is List {
my $inn := @in.Seq.eager;
Q:CgOp { (rnull
(setslot items (@ {self}) (getslot items clr:VarDeque (@ {$inn}))))
(setslot items (@ {self}) (getslot items vvarlist (@ {$inn}))))
};
unitem(self);
}
method !extend is rawcall {
Q:CgOp {
(letn i (getslot items clr:VarDeque (@ (pos 0)))
(letn i (getslot items vvarlist (@ (pos 0)))
ct (- (cast int (unbox num (@ (pos 1))))
(rawcall (l i) Count))
(vvarlist_count (l i)))
(ternary (>= (l ct) (int 0)) [prog]
[sink [die "Autovivification collision"]])
(whileloop 0 0 (!= (l ct) (int 0))
(prog
(l ct (- (l ct) (int 1)))
(rawcall (l i) Push (newrwscalar (@ {Any})))))
(rawcall (l i) Push (pos 2))
(vvarlist_push (l i) (newrwscalar (@ {Any})))))
(vvarlist_push (l i) (pos 2))
(null var))
};
}
Expand All @@ -492,7 +492,7 @@ my class Array is List {
my class Hash {
has $!value;
method new() { Q:CgOp { (box Hash (rawnew clr:Dictionary<string,Variable>)) } }
method new() { Q:CgOp { (box Hash (varhash_new)) } }
method !extend is rawcall {
Q:CgOp {
(letn d [unbox varhash (@ (pos 0))]
Expand Down
7 changes: 7 additions & 0 deletions src/CgOp.pm
Expand Up @@ -254,6 +254,13 @@ use warnings;

sub vvarlist_from_fvarlist { rawnew('vvarlist', $_[0]) }
sub vvarlist_new_empty { rawnew('vvarlist') }
sub vvarlist_shift { rawcall($_[0], 'Shift') }
sub vvarlist_pop { rawcall($_[0], 'Pop') }
sub vvarlist_count { rawcall($_[0], 'Count') }
sub vvarlist_unshift { rawcall($_[0], 'Unshift', $_[1]) }
sub vvarlist_unshiftn { rawcall($_[0], 'UnshiftN', $_[1]) }
sub vvarlist_push { rawcall($_[0], 'Push', $_[1]) }
sub vvarlist_item { getindex($_[0], $_[1]) }

sub bget { getfield('v', $_[0]) }
sub bset { setfield('v', $_[0], $_[1]) }
Expand Down

0 comments on commit 747ffe7

Please sign in to comment.