Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use new dispatcher API when compiling protoregexes
  • Loading branch information
sorear committed Apr 2, 2011
1 parent 6128027 commit f6aa8d6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/CLRBackend.cs
Expand Up @@ -892,7 +892,7 @@ sealed class Tokens {
n["Str"] = typeof(LADStr).GetConstructor(new Type[] { String });
n["Param"] = typeof(LADParam).GetConstructor(new Type[] { String });
n["Method"] = typeof(LADMethod).GetConstructor(new Type[] { String });
n["ProtoRegex"] = typeof(LADProtoRegex).GetConstructor(new Type[] { String });
n["Dispatcher"] = typeof(LADDispatcher).GetConstructor(new Type[] { });
n["StrNoCase"] = typeof(LADStrNoCase).GetConstructor(new Type[] { String });
n["Imp"] = typeof(LADImp).GetConstructor(new Type[] { });
n["Dot"] = typeof(LADDot).GetConstructor(new Type[] { });
Expand Down Expand Up @@ -3043,7 +3043,7 @@ class NamProcessor {
thandlers["rxgetpos"] = RxCall(null, "GetPos");
thandlers["rxcommitgroup"] = RxCall(null, "CommitGroup");
thandlers["get_lexer"] = Methody(null, typeof(Lexer).GetMethod("GetLexer"));
thandlers["run_protoregex"] = Methody(null, typeof(Lexer).GetMethod("RunProtoregex"));
thandlers["run_dispatch"] = Methody(null, typeof(Lexer).GetMethod("RunDispatch"));
handlers["ladconstruct"] = delegate(NamProcessor th, object[] z) {
return th.ProcessLADArr(z[1]); };
handlers["rawcall"] = delegate(NamProcessor th, object[] z) {
Expand Down Expand Up @@ -3325,9 +3325,9 @@ class NamProcessor {
return CpsOp.ConstructorCall(ci, new CpsOp[] {
CpsOp.ConstructorCall(Tokens.CC_ctor, new CpsOp[] {
CpsOp.NewIntArray(ccs) }) });
} else if (head == "Imp" || head == "Dot" || head == "Null" || head == "None") {
} else if (head == "Imp" || head == "Dot" || head == "Null" || head == "None" || head == "Dispatcher") {
return CpsOp.ConstructorCall(ci, new CpsOp[0]);
} else if (head == "Str" || head == "StrNoCase" || head == "Param" || head == "ProtoRegex" || head == "Method") {
} else if (head == "Str" || head == "StrNoCase" || head == "Param" || head == "Method") {
return CpsOp.ConstructorCall(ci, new CpsOp[]{
CpsOp.StringLiteral(JScalar.S(body[1])) });
} else if (head == "Opt" || head == "Star" || head == "Plus") {
Expand Down
1 change: 1 addition & 0 deletions lib/Cursor.cs
Expand Up @@ -1742,6 +1742,7 @@ public class Lexer {
si.param0 = cands;
si.sig_i = new int[3] { SubInfo.SIG_F_POSITIONAL, 0, 0 };
si.sig_r = new object[1] { "self" };
si.ltm = new LADDispatcher();
return Kernel.MakeSub(si, null);
}

Expand Down
36 changes: 36 additions & 0 deletions src/niecza
Expand Up @@ -138,6 +138,42 @@ method regex_def($/) {
}
}

augment class CgOp {
#method run_protoregex (*@_) { self._cgop("run_protoregex", @_) }
method run_dispatch (*@_) { self._cgop("run_dispatch", @_) }
}

augment class RxOp::ProtoRedis { #OK exist
method code($) {
CgOp.letn(
"fns", CgOp.run_dispatch(CgOp.callframe,
CgOp.fetch(CgOp.scopedlex('self'))),
"i", CgOp.int(0),
"ks", CgOp.null('vvarlist'),
CgOp.pushcut('LTM'),
CgOp.label('nextfn'),
CgOp.cgoto('backtrack',
CgOp.compare('>=', CgOp.letvar("i"),
CgOp.mrl_count(CgOp.letvar("fns")))),
CgOp.rxpushb('LTM', 'nextfn'),
CgOp.letvar("ks", CgOp.vvarlist_new_singleton(
CgOp.subcall(CgOp.mrl_index(CgOp.letvar("i"),
CgOp.letvar("fns")), CgOp.newscalar(CgOp.rxcall(
'MakeCursor'))))),
CgOp.letvar("i", CgOp.arith('+', CgOp.letvar("i"), CgOp.int(1))),
CgOp.label('nextcsr'),
CgOp.ncgoto('backtrack', CgOp.iter_hasflat(CgOp.letvar('ks'))),
CgOp.rxpushb('SUBRULE', 'nextcsr'),
CgOp.rxcall('EndWith', CgOp.cast('cursor',
CgOp.fetch(CgOp.vvarlist_shift(CgOp.letvar('ks'))))),
CgOp.goto('backtrack'));
}

method lad() {
$.cutltm ?? [ 'Imp' ] !! [ 'Dispatcher' ];
}
}

my $usage = q:to/EOM/;
niecza -- a command line wrapper for Niecza

Expand Down

0 comments on commit f6aa8d6

Please sign in to comment.