Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Reimplement return-pass, Whatever currying
  • Loading branch information
sorear committed Oct 5, 2011
1 parent 11c6923 commit 63597b7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
1 change: 0 additions & 1 deletion lib/CORE.setting
Expand Up @@ -890,7 +890,6 @@ my class Nil is Cool {
my class Parcel is Cool {
method ACCEPTS(\$what) { defined(self) ?? self.flat.ACCEPTS($what) !! nextsame }
method flat() { self.iterator.flat }
method list() { self.iterator.list }
method postcircumfix:<[ ]>(\$key) { @(self).[$key] }
method at_pos($key) { @(self).[$key] }
Expand Down
14 changes: 13 additions & 1 deletion lib/CodeGen.cs
Expand Up @@ -4328,7 +4328,8 @@ class NamProcessor {
EnterCode(enter);

// TODO: bind a ro container around return values
if (sub.mo.HasMRO(Kernel.RoutineMO)) {
if (sub.mo.HasMRO(Kernel.RoutineMO) &&
(sub.special & RuntimeUnit.SUB_RETURN_PASS) == 0) {
enter.Add(new object[] { new JScalar("return"),
new object[] { new JScalar("xspan"),
new JScalar("rstart"), new JScalar("rend"),
Expand Down Expand Up @@ -4983,6 +4984,10 @@ public class DowncallReceiver : CallReceiver {
((SubInfo)Handle.Unbox(args[1])).special |=
RuntimeUnit.SUB_CANNOT_INLINE;
return null;
} else if (cmd == "sub_set_return_pass") {
((SubInfo)Handle.Unbox(args[1])).special |=
RuntimeUnit.SUB_RETURN_PASS;
return null;
} else if (cmd == "sub_set_transparent") {
((SubInfo)Handle.Unbox(args[1])).special |=
RuntimeUnit.SUB_TRANSPARENT;
Expand Down Expand Up @@ -5042,6 +5047,13 @@ public class DowncallReceiver : CallReceiver {
} else if (cmd == "sub_set_class") {
((SubInfo)Handle.Unbox(args[1])).mo = ResolveSubClass((string)args[2]);
return null;
} else if (cmd == "sub_delete_lex") {
// XXX This leaves a gap in the lexical/number mapping.
// Don't use it too much.
SubInfo from = (SubInfo)Handle.Unbox(args[1]);
string lkey = (string)args[2];
from.dylex.Remove(lkey);
return null;
} else if (cmd == "sub_lookup_lex") {
SubInfo from = (SubInfo)Handle.Unbox(args[1]);
string lkey = (string)args[2];
Expand Down
1 change: 1 addition & 0 deletions lib/Kernel.cs
Expand Up @@ -744,6 +744,7 @@ class IdentityComparer : IEqualityComparer<object> {
public const int SUB_TRANSPARENT = 64;
public const int SUB_INLINED = 128;
public const int SUB_CANNOT_INLINE = 256;
public const int SUB_RETURN_PASS = 512;

public void LoadStashes(int from) {
int ct = ReadInt(ref from);
Expand Down
26 changes: 25 additions & 1 deletion src/niecza
Expand Up @@ -371,7 +371,7 @@ method process_block_traits($/, @tr) {
$sub.set_extend('builtin',
self.trivial_eval($T, $tr<Niecza::builtin>));
} elsif !$pack && $tr<return_pass> {
$sub.returnable = False;
$sub.set_return_pass;
} elsif !$pack && $tr<of> {
} elsif !$pack && $tr<rw> {
} elsif !$pack && $tr<unsafe> {
Expand All @@ -382,6 +382,30 @@ method process_block_traits($/, @tr) {
}
}

method whatever_postcheck($/, $st, $term) {
if @$st {
my $slot = self.gensym;

my $body = $*unit.create_sub(
outer => $*CURLEX<!sub>,
class => 'WhateverCode',
in_class => $*CURLEX<!sub>.in_class,
cur_pkg => $*CURLEX<!sub>.cur_pkg);

$body.add_my_name($_, :noinit) for @$st;
$body.set_signature(::GLOBAL::Sig.new(params => [
map { ::Sig::Parameter.new(slot => $_, name => $_) }, @$st ]));
$body.set_transparent;
$body.finish($term);

$*CURLEX<!sub>.add_my_sub($slot, $body);

::Op::WhateverCode.new(ops => Any, vars => $st, :$slot, |node($/));
} else {
$term;
}
}

method variable_declarator($/) {
if $*MULTINESS {
$/.CURSOR.sorry("Multi variables NYI");
Expand Down

0 comments on commit 63597b7

Please sign in to comment.