Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implement use of submethod BUILD

  • Loading branch information...
commit ca4d6f17415d09538f2f256e87211f52aba6099a 1 parent b40503b
@sorear authored
Showing with 61 additions and 3 deletions.
  1. +32 −2 lib/Kernel.cs
  2. +13 −1 perf/std-20110528.pl6
  3. +16 −0 test2.pl
View
34 lib/Kernel.cs
@@ -2970,15 +2970,45 @@ public class MMDCandidateLongname {
th.resultSlot = vx;
} else if (prog[i].init == null) {
th.resultSlot = null;
+ } else if (prog[i].name == null) {
+ P6any init = prog[i].init;
+ th.lexi0 = i;
+
+ SubInfo si = (SubInfo) init.GetSlot("info");
+ VarHash build_args = new VarHash();
+ int ic = 0;
+ int oc = 0;
+ while (ic < si.sig_i.Length) {
+ int fl = si.sig_i[ic + SubInfo.SIG_I_FLAGS];
+ int nn = si.sig_i[ic + SubInfo.SIG_I_NNAMES];
+ ic += SubInfo.SIG_I_RECORD;
+
+ for (int j = 0; j < nn; j++) {
+ string name = (string) si.sig_r[oc+j+1];
+ if (args.ContainsKey(name)) {
+ build_args[name] = args[name];
+ args.Remove(name);
+ }
+ }
+
+ oc += 1 + nn;
+ if ((fl & SubInfo.SIG_F_HASTYPE) != 0) oc++;
+ if ((fl & SubInfo.SIG_F_HASDEFAULT) != 0) oc++;
+ }
+
+ return init.Invoke(th, new Variable[] { NewROScalar(n) },
+ build_args);
} else {
P6any init = prog[i].init;
- if (prog[i].name == null)
- return Die(th, "BUILD NYI");
th.lexi0 = i;
return init.Invoke(th, Variable.None, null);
}
value: vx = (Variable) th.resultSlot;
+ if (prog[i].name == null) {
+ i++;
+ goto again;
+ }
if ((prog[i].flags & ~P6how.A_PUBLIC) == 0) {
n.SetSlot(prog[i].name, NewRWScalar(prog[i].type,
View
14 perf/std-20110528.pl6
@@ -31,6 +31,18 @@ my class CAttrInits {
has $.z = 3;
}
+my class CBuild {
+ has $.x;
+ has $.y;
+ has $.z;
+ submethod BUILD(:$x, :$y, :$z) {
+ $!x = $x // 1;
+ $!y = $y // 2;
+ $!z = $z // 3;
+ }
+}
+
bench "CEmpty.new", 1000000, sub () { CEmpty.new };
bench "CAttrs.new", 1000000, sub () { CAttrs.new };
-bench "CAttrInits.new", 100000, sub () { CAttrInits.new };
+bench "CAttrInits.new", 1000000, sub () { CAttrInits.new };
+bench "CBUILD.new", 1000000, sub () { CBuild.new };
View
16 test2.pl
@@ -2,6 +2,22 @@
use Test;
use MONKEY_TYPING;
+{
+ my class Bt {
+ has $!pie;
+ method get_pie() { $!pie }
+ submethod BUILD(:$x) { $!pie = $x }
+ }
+ is Bt.new(x => 5).get_pie, 5, "BUILD basically works";
+ my class SubBT is Bt {
+ has $!pie2;
+ method get_pie2() { $!pie2 }
+ submethod BUILD(:$y) { $!pie2 = $y }
+ }
+ is SubBT.new(x => 5, y => 2).get_pie, 5, "superclass' BUILD in subclass";
+ is SubBT.new(x => 5, y => 2).get_pie2, 2, "subclass' BUILD in subclass";
+}
+
#is $?ORIG.substr(0,5), '# vim', '$?ORIG works';
# {
Please sign in to comment.
Something went wrong with that request. Please try again.