Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
push/pop/shift/unshift get inlined
  • Loading branch information
sorear committed May 30, 2011
1 parent 0571dfc commit 2825023
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
16 changes: 16 additions & 0 deletions lib/CLRBackend.cs
Expand Up @@ -3827,6 +3827,11 @@ class NamProcessor {
thandlers["newarray"] = Methody(null, Tokens.Kernel_CreateArray);
thandlers["newhash"] = Methody(null, Tokens.Kernel_CreateHash);

thandlers["bif_shift"] = Contexty("mro_shift");
thandlers["bif_pop"] = Contexty("mro_pop");
thandlers["bif_push"] = Pushy("mro_push");
thandlers["bif_unshift"] = Pushy("mro_unshift");

thandlers["bif_defined"] = Contexty("mro_defined");
thandlers["bif_bool"] = Contexty("mro_Bool");
thandlers["bif_num"] = Contexty("mro_Numeric");
Expand Down Expand Up @@ -3926,6 +3931,17 @@ class NamProcessor {
};
}

static Func<CpsOp[], CpsOp> Pushy(string name) {
FieldInfo f = Tokens.STable.GetField(name);
MethodInfo g = f.FieldType.GetMethod("Invoke");
return delegate(CpsOp[] cpses) {
CpsOp[] args = new CpsOp[cpses.Length - 1];
Array.Copy(cpses, 1, args, 0, args.Length);
return CpsOp.Contexty(f, g, new CpsOp[2] {
cpses[0], CpsOp.NewArray(Tokens.Variable, args) });
};
}

static Func<NamProcessor, object[], CpsOp> MakeTotalHandler(
Func<CpsOp[], CpsOp> real) {
return delegate (NamProcessor th, object[] zyg) {
Expand Down
6 changes: 5 additions & 1 deletion src/NieczaPassSimplifier.pm6
Expand Up @@ -84,19 +84,23 @@ our %funcs = (
'&map' => &do_map_grep,
'&next' => do_nullary_control(1),
'&not' => do_builtin('not', 1),
'&pop' => do_builtin('pop', 1),
'&postfix:<++>' => do_builtin('postinc', 1),
'&prefix:<?>' => do_builtin('bool', 1),
'&prefix:<->' => do_builtin('negate', 1),
'&prefix:<!>' => do_builtin('not', 1),
'&prefix:<+>' => do_builtin('num', 1),
'&prefix:<~>' => do_builtin('str', 1),
'&proceed' => do_nullary_control(7),
'&push' => do_builtin('push', 1..*),
'&redo' => do_nullary_control(3),
'&return' => &do_return_take,
'&shift' => do_builtin('shift', 1),
'&so' => do_builtin('bool', 1),
'&substr' => do_builtin('substr3', 3),
'&succeed' => do_nullary_control(6),
'&take' => &do_return_take,
'&unshift' => do_builtin('unshift', 1..*),
'&_array_constructor' => do_builtin('array_constructor', 1),
);

Expand All @@ -108,7 +112,7 @@ sub do_assign($body, $nv, $invname, $op) {

sub do_builtin($name, $expect) { sub ($body, $nv, $invname, $op) {
return $op unless defined my $args = no_named_params($op);
return $op unless $args == $expect;
return $op unless $args ~~ $expect;
return ::Op::Builtin.new(name => $name, args => $args);
} }

Expand Down
3 changes: 2 additions & 1 deletion src/niecza
Expand Up @@ -526,7 +526,8 @@ for <
vvarlist_count vvarlist_from_fvarlist vvarlist_item
vvarlist_new_empty vvarlist_new_singleton vvarlist_pop
vvarlist_push vvarlist_shift vvarlist_sort vvarlist_to_fvarlist
vvarlist_unshift vvarlist_unshiftn whileloop xspan
vvarlist_unshift vvarlist_unshiftn whileloop xspan bif_times
bif_divop obj_can bif_sqrt bif_push bif_pop bif_unshift bif_shift
> -> $name {
my $fnc = anon sub CgOperator (\|@parcel) {
Q:CgOp {
Expand Down

0 comments on commit 2825023

Please sign in to comment.