Permalink
Browse files

Call action methods on the same runloop

  • Loading branch information...
1 parent 2c9ae3e commit 6e796b31350716e4298edc5ab69f870a7c80ca03 @sorear committed May 28, 2011
Showing with 39 additions and 26 deletions.
  1. +14 −4 lib/CLRBackend.cs
  2. +6 −5 lib/CORE.setting
  3. +19 −17 lib/Cursor.cs
View
@@ -3677,7 +3677,7 @@ class NamProcessor {
x[i-1] = th.Scan(z[i]);
x[0] = CpsOp.RxFrame();
string name = JScalar.S(z[1]);
- return CpsOp.CpsCall((name == "EndWith" || name == "End") ? Tokens.Void : null, Tokens.RxFrame.GetMethod(name), x); };
+ return CpsOp.MethodCall(Tokens.RxFrame.GetMethod(name), x); };
handlers["rxinit"] = delegate(NamProcessor th, object[] z) {
return CpsOp.SetField(Tokens.Frame_rx, CpsOp.CallFrame(),
CpsOp.ConstructorCall(Tokens.RxFrame_ctor,
@@ -3694,8 +3694,18 @@ class NamProcessor {
return CpsOp.MethodCall(Tokens.RxFrame.GetMethod("LTMPushAlts"),
CpsOp.RxFrame(), CpsOp.CallFrame(), ai); };
thandlers["popcut"] = RxCall(null, "PopCutGroup");
- thandlers["rxend"] = RxCall(Tokens.Void, "End");
- thandlers["rxfinalend"] = RxCall(Tokens.Void, "FinalEnd");
+ thandlers["rxend"] = delegate(CpsOp[] zyg) {
+ return CpsOp.Sequence(
+ CpsOp.CpsCall(Tokens.Void,
+ Tokens.RxFrame.GetMethod("MakeMatch"), CpsOp.RxFrame()),
+ CpsOp.CpsCall(Tokens.Void,
+ Tokens.RxFrame.GetMethod("End"), CpsOp.RxFrame())); };
+ thandlers["rxfinalend"] = delegate(CpsOp[] zyg) {
+ return CpsOp.Sequence(
+ CpsOp.CpsCall(Tokens.Void,
+ Tokens.RxFrame.GetMethod("MakeMatch"), CpsOp.RxFrame()),
+ CpsOp.CpsCall(Tokens.Void,
+ Tokens.RxFrame.GetMethod("FinalEnd"), CpsOp.RxFrame())); };
thandlers["rxbacktrack"] = RxCall(Tokens.Void, "Backtrack");
thandlers["rxgetquant"] = RxCall(null, "GetQuant");
thandlers["rxsetquant"] = RxCall(null, "SetQuant");
@@ -3800,7 +3810,7 @@ class NamProcessor {
thandlers["cursor_item"] = Methody(null, Tokens.Cursor.GetMethod("GetKey"));
thandlers["cursor_unpackcaps"] = Methody(null, Tokens.Cursor.GetMethod("UnpackCaps"));
thandlers["cursor_O"] = Methody(null, Tokens.Cursor.GetMethod("O"));
- thandlers["cursor_synthetic"] = Methody(null, Tokens.Cursor.GetMethod("Synthetic"));
+ thandlers["cursor_synthetic"] = Methody(Tokens.Variable, Tokens.Cursor.GetMethod("Synthetic"));
thandlers["cursor_fresh"] = Methody(null, Tokens.Cursor.GetMethod("FreshClass"));
thandlers["cursor_unmatch"] = Methody(null, Tokens.Cursor.GetMethod("UnMatch"));
thandlers["cursor_reduced"] = Methody(null, Tokens.Cursor.GetMethod("Reduced"));
View
@@ -1155,12 +1155,13 @@ my class Match is Cool {
method reduced() { Q:CgOp { (box Str (cursor_reduced (cast cursor (@ {self})))) } }
method synthetic(:$cursor!, :$method!, :@captures!, :$from!, :$to!) {
Q:CgOp {
- (newscalar (cursor_synthetic
- (cast cursor (@ {$cursor})) (obj_getstr {$method})
- (cast int (obj_getnum {$from}))
- (cast int (obj_getnum {$to}))
- {@captures}))
+ (cursor_synthetic
+ (cast cursor (@ {$cursor})) (obj_getstr {$method})
+ (cast int (obj_getnum {$from}))
+ (cast int (obj_getnum {$to}))
+ {@captures})
};
+ $/
}
}
View
@@ -12,11 +12,11 @@ public sealed class GState {
public Variable actions;
- internal void CallAction(string name, Cursor match) {
+ internal Frame CallAction(Frame th, string name, Cursor match) {
+ if (actions == null || name == "" || name == null)
+ return th;
if (Cursor.Trace)
Console.WriteLine("To call action {0}", name);
- if (actions == null || name == "" || name == null)
- return;
DispatchEnt m;
P6any actions_p = actions.Fetch();
Variable[] pos;
@@ -27,13 +27,13 @@ public sealed class GState {
Kernel.BoxAnyMO<string>(name, Kernel.StrMO),
Kernel.NewROScalar(match) };
} else {
- return;
+ return th;
}
- Frame nf = m.info.Binder(Kernel.GetInferiorRoot()
- .MakeChild(m.outer, m.info), pos, null, false);
+ Frame nf = m.info.Binder(th.MakeChild(m.outer, m.info),
+ pos, null, false);
nf.curDisp = m;
- Kernel.RunInferior(nf);
+ return nf;
}
public GState(string orig, P6any actions) {
@@ -463,23 +463,26 @@ public sealed class RxFrame {
public Variable MakeCursorV() { return Kernel.NewROScalar(MakeCursor()); }
- public Cursor MakeMatch() {
+ Cursor _matchObj;
+ public Frame MakeMatch(Frame th) {
if (Cursor.Trace)
Console.WriteLine("Matching {0} from {1} to {2}",
name, from, st.pos);
- return new Cursor(global, st.ns.klass, from, st.pos, st.captures, ast, name);
+ _matchObj = new Cursor(global, st.ns.klass, from, st.pos,
+ st.captures, ast, name);
+ return global.CallAction(th, name, _matchObj);
}
public static Variable EmptyList;
public Frame FinalEnd(Frame th) {
if (st.pos > global.highwater)
global.IncHighwater(st.pos);
- th.caller.resultSlot = Kernel.NewROScalar(MakeMatch());
+ th.caller.resultSlot = Kernel.NewROScalar(_matchObj);
return th.caller;
}
public Frame End(Frame th) {
- return EndWith(th, MakeMatch());
+ return EndWith(th, _matchObj);
}
// currently just used for protoregex
public Frame EndWith(Frame th, Cursor m) {
@@ -547,9 +550,6 @@ public Cursor(P6any proto, string text, P6any actions)
this.mo = Kernel.MatchMO;
this.save_klass = klass;
this.reduced = reduced;
-
- if (reduced != null)
- g.CallAction(reduced, this);
}
public Cursor(GState g, STable klass, RxFrame feedback, NState ns, Choice xact, int pos, CapInfo captures) {
@@ -562,8 +562,8 @@ public Cursor(P6any proto, string text, P6any actions)
this.captures = captures;
}
- public static Cursor Synthetic(Cursor parent, string method, int from,
- int to, Variable caplist) {
+ public static Frame Synthetic(Frame th, Cursor parent, string method,
+ int from, int to, Variable caplist) {
VarDeque iter = Builtins.start_iter(caplist);
CapInfo ci = null;
while (Kernel.IterHasFlat(iter, true)) {
@@ -573,8 +573,10 @@ public Cursor(P6any proto, string text, P6any actions)
ci = new CapInfo(ci, new string[] {
k.Fetch().mo.mro_raw_Str.Get(k) }, v);
}
- return new Cursor(parent.global, parent.save_klass, from, to, ci,
+ Cursor r = new Cursor(parent.global, parent.save_klass, from, to, ci,
null, method);
+ Kernel.SetStatus(th, "$*/", Kernel.NewROScalar(r));
+ return r.global.CallAction(th, method, r);
}
public override bool IsDefined() {

0 comments on commit 6e796b3

Please sign in to comment.