Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Mergeback, start of @!foo-ish stuff
  • Loading branch information
sorear committed May 26, 2011
1 parent 0a829c2 commit 98debd4
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 387 deletions.
19 changes: 14 additions & 5 deletions src/CgOp.pm6
Expand Up @@ -252,8 +252,6 @@ method vvarlist_to_fvarlist (*@_) { self._cgop("vvarlist_to_fvarlist", @_) }
method vvarlist_unshift (*@_) { self._cgop("vvarlist_unshift", @_) }
method vvarlist_unshiftn (*@_) { self._cgop("vvarlist_unshiftn", @_) }
method whileloop (*@_) { self._cgop("whileloop", @_) }
method get_lexer (*@_) { self._cgop("get_lexer", @_) }
method label_table (*@_) { self._cgop("label_table", @_) }
method mrl_count (*@_) { self._cgop("mrl_count", @_) }
method mrl_index (*@_) { self._cgop("mrl_index", @_) }
method treader_open (*@_) { self._cgop("treader_open", @_) }
Expand Down Expand Up @@ -284,6 +282,19 @@ method bif_simple_eval($str) { self._cgop("bif_simple_eval", $str) }
method run_dispatch (*@_) { self._cgop("run_dispatch", @_) }
method var_get_var ($v) { self._cgop("var_get_var", $v) }
method var_new_tied ($t,$b,$f,$s) { self._cgop("var_new_tied", $t,$b,$f,$s) }
method rxincorpcut($caps,$zw,$ng,$pc,$call) { self._cgop("rxincorpcut",$caps,$zw,$ng,$pc,$call) }
method rxincorpshift($caps,$pc,$label) { self._cgop("rxincorpshift",$caps,$pc,$label) }
method boxlist($mo,$obj) { self._cgop("boxlist", $mo, $obj) }
method bif_comma(*@bits) { self._cgop("bif_comma", @bits) }
method bif_pair($key,$val) { self._cgop("bif_pair", $key, $val) }
method ltm_push_alts (*@x) { self._cgop("ltm_push_alts", @x) }
method outerlex ($n) { self._cgop("outerlex", $n) }
method newtypedscalar ($t) { self._cgop("newtypedscalar", $t) }
method bif_rand () { self._cgop("bif_rand") }
method exactnum ($base, $digits) { self._cgop("exactnum", $base, $digits) }
method bif_rat_approx ($center, $eps) { self._cgop("bif_rat_approx", $center, $eps) }
method bif_coerce_to_num ($v) { self._cgop("bif_coerce_to_num", $v) }
method bif_coerce_to_int ($v) { self._cgop("bif_coerce_to_int", $v) }

method double($x) {
# Hack - prevent JSON syntax errors
Expand All @@ -310,7 +321,6 @@ method let($head,$body) {
}

method cc_expr($cc) { CgOp._cgop('newcc', @( $cc.terms )) }
method construct_lad(*@trees) { CgOp._cgop('ladconstruct', [@trees]) }

method _process_arglist(*@araw) {
my @aout;
Expand All @@ -335,6 +345,5 @@ method subcall($sub, *@args) {

method methodcall($obj, $name, *@args) {
my ($sig, $aout) = CgOp._process_arglist(@args);
CgOp.let($obj, -> $of {
CgOp._cgop('methodcall', $name, $sig, CgOp.fetch($of), $of, @$aout) });
CgOp._cgop('methodcall', $name, $sig, $obj, @$aout);
}
15 changes: 8 additions & 7 deletions src/Metamodel.pm6
Expand Up @@ -224,7 +224,7 @@ class RefTarget {
class Package is RefTarget {
has $.exports; # is rw

method add_attribute($name, $public, $ivar, $ibody, $tc) { #OK not used
method add_attribute($name, $sigil, $public, $ivar, $ibody, $tc) { #OK not used
die "attribute $name defined in a lowly package";
}

Expand Down Expand Up @@ -254,6 +254,7 @@ class Method {

class Attribute {
has $.name; # Str, required
has $.sigil; # Str, required
has $.public; # Bool
has $.ivar; # Str
has $.ibody; # Xref
Expand All @@ -267,8 +268,8 @@ class Class is Module {
has $.linearized_mro; # is rw
has $!closing;

method add_attribute($name, $public, $ivar, $ibody, $typeconstraint) {
push $.attributes, Metamodel::Attribute.new(:$name,
method add_attribute($name, $sigil, $public, $ivar, $ibody, $typeconstraint) {
push $.attributes, Metamodel::Attribute.new(:$name, :$sigil,
:$public, :$ivar, :$ibody, :$typeconstraint);
}

Expand Down Expand Up @@ -356,8 +357,8 @@ class Role is Module {
has $.methods = [];
has $.superclasses = [];

method add_attribute($name, $public, $ivar, $ibody, $typeconstraint) {
push $.attributes, Metamodel::Attribute.new(:$name,
method add_attribute($name, $sigil, $public, $ivar, $ibody, $typeconstraint) {
push $.attributes, Metamodel::Attribute.new(:$name, :$sigil,
:$public, :$ivar, :$ibody, :$typeconstraint);
}

Expand All @@ -380,8 +381,8 @@ class ParametricRole is Module {
has $.methods = [];
has $.superclasses = [];

method add_attribute($name, $public, $ivar, $ibody, $typeconstraint) {
push $.attributes, Metamodel::Attribute.new(:$name,
method add_attribute($name, $sigil, $public, $ivar, $ibody, $typeconstraint) {
push $.attributes, Metamodel::Attribute.new(:$name, :$sigil,
:$public, :$ivar, :$ibody, :$typeconstraint);
}

Expand Down
29 changes: 20 additions & 9 deletions src/NieczaActions.pm6
Expand Up @@ -125,25 +125,28 @@ method decint($/) { make from_base($/, 10) }
method hexint($/) { make from_base($/, 16) }
method octint($/) { make from_base($/, 8) }
method binint($/) { make from_base($/, 2) }
method integer($/) {
$<decint> andthen make [10, ~$<decint>];
$<octint> andthen make [8, ~$<octint>];
$<hexint> andthen make [16, ~$<hexint>];
$<binint> andthen make [2, ~$<binint>];
}

method decints($/) { make [ map *.ast, @$<decint> ] }
method hexints($/) { make [ map *.ast, @$<hexint> ] }
method octints($/) { make [ map *.ast, @$<octint> ] }
method binints($/) { make [ map *.ast, @$<binint> ] }
method integer($/) {
make ($<decint> // $<octint> // $<hexint> // $<binint>).ast
}

method escale ($/) { }
method dec_number ($/) {
make +((~$/).comb(/<-[_]>/).join(""));
if $<escale> { make +((~$/).comb(/<-[_]>/).join("")) }
else { make [10, ~$/] }
}

# XXX niecza rats will break this
method number($/) {
my $child = $<integer> // $<dec_number> // $<rad_number>;
make (defined($child) ?? $child.ast !!
$child eq 'NaN' ?? ((1/0) / (1/0)) !! (1/0));
$child eq 'NaN' ?? NaN !! Inf);
}

# Value :: Op
Expand Down Expand Up @@ -2071,8 +2074,14 @@ method variable_declarator($/) {
if $*MULTINESS {
$/.CURSOR.sorry("Multi variables NYI");
}
if $<trait> || $<post_constraint> || $<postcircumfix> || $<semilist> {
$/.CURSOR.sorry("Traits, postconstraints, and shapes on variable declarators NYI");
for @$<trait> -> $t {
if $t.ast<rw> {
} else {
$/.CURSOR.sorry("Trait $t.ast.keys.[0] not available on variables");
}
}
if $<post_constraint> || $<postcircumfix> || $<semilist> {
$/.CURSOR.sorry("Postconstraints, and shapes on variable declarators NYI");
}

my $scope = $*SCOPE // 'my';
Expand Down Expand Up @@ -2112,7 +2121,7 @@ method variable_declarator($/) {

if $scope eq 'has' {
make ::Op::Attribute.new(|node($/), name => $v<name>,
accessor => $t eq '.', :$typeconstraint);
sigil => $v<sigil>, accessor => $t eq '.', :$typeconstraint);
} elsif $scope eq 'state' {
make ::Op::Lexical.new(|node($/), name => $slot, state_decl => True,
state_backing => self.gensym, declaring => True, :$typeconstraint,
Expand Down Expand Up @@ -2645,6 +2654,7 @@ method routine_def ($/) {
} elsif $t.ast<return_pass> {
$return_pass = 1;
} elsif $t.ast<of> {
} elsif $t.ast<rw> {
} elsif $t.ast<unsafe> {
$unsafe = True;
} else {
Expand Down Expand Up @@ -2724,6 +2734,7 @@ method method_def ($/) {
} elsif $t.ast<unsafe> {
$unsafe = True;
} elsif $t.ast<of> {
} elsif $t.ast<rw> {
} else {
$/.CURSOR.sorry("NYI method trait $t");
}
Expand Down
2 changes: 1 addition & 1 deletion src/NieczaPassBegin.pm6
Expand Up @@ -250,7 +250,7 @@ augment class Op::Attribute { #OK exist
$ibref = $ibody.xref;
}
$ns = $*unit.deref($ns);
$ns.add_attribute($.name, +$.accessor, $ibvar, $ibref, $tc);
$ns.add_attribute($.name, $.sigil, +$.accessor, $ibvar, $ibref, $tc);
my $nb = ::Metamodel::StaticSub.new(
transparent=> True,
unit => $*unit,
Expand Down
14 changes: 13 additions & 1 deletion src/Op.pm6
Expand Up @@ -473,6 +473,10 @@ class Labelled is Op {
method code($body) {
CgOp.prog(CgOp.label("goto_$.name"),$.stmt.cgop_labelled($body,$.name));
}

method statement_level() {
self.new(name => $.name, stmt => $.stmt.statement_level);
}
}

class When is Op {
Expand Down Expand Up @@ -548,7 +552,13 @@ class Control is Op {
{ class Num is Op {
has $.value = die "Num.value required"; # Numeric

method code($) { CgOp.const(CgOp.box('Num', CgOp.double($.value))) }
method code($) {
if $.value ~~ Array {
CgOp.const(CgOp.exactnum(|$.value))
} else {
CgOp.const(CgOp.box('Num', CgOp.double($.value)))
}
}
}; }

class Bind is Op {
Expand Down Expand Up @@ -613,6 +623,7 @@ class Super is Op {

class Attribute is Op {
has $.name; # Str
has $.sigil;
has $.accessor; # Bool
has $.initializer; # Body, is rw
has $.typeconstraint; # Array of Str
Expand Down Expand Up @@ -788,6 +799,7 @@ class RegexBody is Op {
has $.pre = []; # Array of Op
has $.canback = True;

method ctxzyg($ ) { (map { $_, 0 }, @$.pre), $.rxop.ctxopzyg }
method zyg() { @$.pre, $.rxop.opzyg }

method code($body) {
Expand Down
67 changes: 24 additions & 43 deletions src/RxOp.pm6
Expand Up @@ -5,11 +5,12 @@ use CClass;

has $.zyg = []; # Array of RxOp

method opzyg() { map *.opzyg, @$!zyg }
method oplift() { map *.oplift, @$!zyg }
method uncut() { self }
method opzyg() { map *.opzyg, @$!zyg }
method ctxopzyg() { map *.ctxopzyg, @$!zyg }
method oplift() { map *.oplift, @$!zyg }
method uncut() { self }

method check() { for @$!zyg { $_.check } }
method check() { for @$!zyg { $_.check } }
method tocclist() { CClass }

# all that matters is 0-1-infty; $*in_quant valid here
Expand Down Expand Up @@ -107,6 +108,7 @@ class String is RxOp {
class VarString is RxOp {
has $.param; # Str
has $.ops = die "RxOp::VarString.ops required"; # Op
method ctxopzyg() { $!ops, 1 }
method opzyg() { $!ops }

method code($body) {
Expand Down Expand Up @@ -448,6 +450,7 @@ class Subrule is Capturing {
captures => $.captures, |%_);
}

method ctxopzyg() { defined($!regex) ?? ($!regex, 1) !! () }
method opzyg() { $!regex // Nil }

method used_caps() {
Expand All @@ -472,46 +475,21 @@ class Subrule is Capturing {
}

method code($body) {
my $bt = self.label;

my $callf = $!regex ?? $!regex.cgop($body) !!
CgOp.methodcall(CgOp.newscalar(CgOp.rxcall("MakeCursor")),
CgOp.methodcall(CgOp.rxcall("MakeCursorV"),
$!method);
my @newcapf = (!$.captures) ?? () !!
CgOp.rxpushcapture(
($!passcap ??
CgOp.newscalar(CgOp.rxstripcaps(
CgOp.cast("cursor", CgOp.letvar("k")))) !!
CgOp.letvar("kv")), @$.captures);
my @pushcapf = ($!passcap ??
(CgOp.rxsetcapsfrom(CgOp.cast("cursor", CgOp.letvar("k")))) !! ()),
@newcapf;
my @bfargs = 'backtrack', CgOp.obj_is_defined(CgOp.letvar("k"));
my $backf = $!negative ?? CgOp.cgoto(@bfargs) !! CgOp.ncgoto(@bfargs);
my $updatef = CgOp.prog(@pushcapf,
CgOp.rxsetpos(CgOp.cursor_pos(CgOp.cast("cursor",
CgOp.letvar("k")))));
$updatef = CgOp.prog() if $!zerowidth;

my @code;

if $!selfcut {
push @code, CgOp.letn(
"kv", CgOp.get_first($callf),
"k", CgOp.fetch(CgOp.letvar("kv")),
$backf,
$updatef);
push @code, CgOp.rxincorpcut($.captures, +?$!zerowidth,
+?$!negative, +?$!passcap, $callf);
} else {
push @code, CgOp.rxcall("SetCursorList", CgOp.vvarlist_new_singleton($callf));
my $bt = self.label;

push @code, CgOp.rxcall("InitCursorList", $callf);
push @code, CgOp.label($bt);
push @code, CgOp.ncgoto("backtrack", CgOp.iter_hasflat(
CgOp.rxcall("GetCursorIter")));
push @code, CgOp.letn(
"kv", CgOp.vvarlist_shift(CgOp.rxcall("GetCursorIter")),
"k", CgOp.fetch(CgOp.letvar("kv")),
CgOp.rxpushb("SUBRULE", $bt),
$updatef);
push @code, CgOp.rxcall("SetCursorList", CgOp.null("var"));
push @code, CgOp.rxincorpshift($.captures, +?$!passcap, $bt);
}

@code;
Expand Down Expand Up @@ -544,8 +522,14 @@ class CutRule is RxOp {
method lad() { [ 'Null' ]; }
}

class CutBrack is RxOp {
method code($) { CgOp.rxcall('CommitGroup', CgOp.str("BRACK")) }
method lad() { [ 'Null' ]; }
}

class SetLang is RxOp {
has $.expr = die "SetLang.expr required"; #Op
method ctxopzyg() { $!expr, 1 }
method opzyg() { $!expr }

method code($body) {
Expand All @@ -565,13 +549,7 @@ class Alt is AltBase {
die "check screwed up" unless defined $.dba;

my @code;
push @code, CgOp.rxcall("LTMPushAlts",
CgOp.get_lexer(
CgOp.callframe,
CgOp.rxcall('GetClass'),
CgOp.const(CgOp.construct_lad(@lads)),
CgOp.str($.dba)),
CgOp.const(CgOp.label_table(@ls)));
push @code, CgOp.ltm_push_alts([@lads], $.dba, [@ls]);
push @code, CgOp.goto('backtrack');
my $i = 0;
while $i < @ls {
Expand All @@ -590,6 +568,7 @@ class Alt is AltBase {

class CheckBlock is RxOp {
has $.block = die "CheckBlock.block required"; # Op
method ctxopzyg() { $!block, 1 }
method opzyg() { $!block }

method code($body) {
Expand All @@ -602,6 +581,7 @@ class CheckBlock is RxOp {
class SaveValue is RxOp {
has $.capid = die "SaveValue.capid required"; # Str
has $.block = die "SaveValue.block required"; # Op
method ctxopzyg() { $!block, 1 }
method opzyg() { $!block }

method used_caps() {
Expand All @@ -614,6 +594,7 @@ class SaveValue is RxOp {

class VoidBlock is RxOp {
has $.block = die "VoidBlock.block required"; # Op
method ctxopzyg() { $!block, 0 }
method opzyg() { $!block }

method code($body) { CgOp.sink($!block.cgop($body)); }
Expand Down

0 comments on commit 98debd4

Please sign in to comment.