Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Reimplement compilation of subsets
  • Loading branch information
sorear committed Oct 27, 2011
1 parent 9f04acf commit 52fdc3b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/CodeGen.cs
Expand Up @@ -4118,8 +4118,22 @@ public class DowncallReceiver : CallReceiver {
nst.mo.rtype = type;
nst.mo.isPackage = (type == "package");
nst.mo.isRole = (type == "role" || type == "prole");
nst.mo.isSubset = (type == "subset");

return new Handle(nst);
} else if (cmd == "type_set_basetype") {
STable subset = (STable)Handle.Unbox(args[1]);
STable basety = (STable)Handle.Unbox(args[2]);

subset.mo.FillSubset(basety);
subset.initObject = basety.initObject;
subset.initVar = basety.initVar;
return null;
} else if (cmd == "type_set_where") {
STable subset = (STable)Handle.Unbox(args[1]);
SubInfo where = (SubInfo)Handle.Unbox(args[2]);
subset.mo.subsetWhereThunk = where.protosub;
return null;
} else if (cmd == "create_sub") {
RuntimeUnit ru = (RuntimeUnit)Handle.Unbox(args[1]);
string name = (string)args[2];
Expand Down
31 changes: 31 additions & 0 deletions src/niecza
Expand Up @@ -21,6 +21,37 @@ use Sig;
use STD;

augment class NieczaActions {
method type_declarator:subset ($/) {
my ($basetype) = self.process_name($*OFTYPE<longname>);
$basetype //= $*CURLEX<!sub>.compile_get_pkg('CORE', 'Any');
my @exports;

for map *.ast, @$<trait> -> $t {
if $t<export> {
push @exports, @( $t<export> );
} elsif $t<of> {
$basetype = $t<of>;
} else {
$/.CURSOR.sorry("Unsupported subset trait $t.keys()");
}
}

my $body = self.thunk_sub($<EXPR> ?? $<EXPR>.ast !! mklex($/, 'True'));

my ($lexvar, $obj) = "Any";

$/.CURSOR.trymop({
($lexvar, $obj) = self.do_new_package($/, scope => $*SCOPE,
name => $<longname>, class => 'subset', :@exports);

$*CURLEX<!sub>.create_static_pad;

$obj.set_basetype($basetype);
$obj.set_where($body);
});

make mklex($/, $lexvar);
}
}

CgOp._register_ops: < who sc_root sc_indir temporize _addmethod _invalidate
Expand Down

0 comments on commit 52fdc3b

Please sign in to comment.