Example #1
0
 public static IP6 NominalCheck(string name, DynMetaObject mo, Variable v)
 {
     IP6 r = v.Fetch();
     if (!r.mo.HasMRO(mo))
         throw new NieczaException("Nominal type check failed for " + name +
                 " needed " + mo.name + " got " + r.mo.name);
     return r;
 }
Example #2
0
 public Cursor(GState g, DynMetaObject klass, int from, int pos, CapInfo captures)
 {
     this.global = g;
     this.captures = captures;
     this.pos = pos;
     this.from = from;
     this.mo = Kernel.MatchMO;
     this.save_klass = klass;
 }
Example #3
0
 public Cursor(GState g, DynMetaObject klass, NState ns, Choice xact, int pos, CapInfo captures)
 {
     this.mo = klass;
     this.xact = xact;
     this.nstate = ns;
     this.global = g;
     this.pos = pos;
     this.captures = captures;
 }
Example #4
0
 public void SetClass(DynMetaObject dm)
 {
     st.ns.klass = dm;
 }
Example #5
0
 public NState(Choice cut_to, string name, NState proto)
 {
     next = proto; this.cut_to = cut_to; this.name = name;
     if (proto != null) klass = proto.klass;
 }
Example #6
0
 public LexerCache(DynMetaObject mo)
 {
     this.mo = mo;
     if (mo.superclasses.Count == 1) {
         parent = mo.superclasses[0].GetLexerCache();
         repl_methods = new HashSet<string>();
         foreach (string mn in mo.local.Keys) {
             int ix = mn.IndexOf(':');
             if (ix >= 0) repl_methods.Add(mn.Substring(0,ix));
             else repl_methods.Add(mn);
         }
     }
 }
Example #7
0
    public static Lexer GetProtoregexLexer(DynMetaObject kl, string name)
    {
        LexerCache lc = kl.GetLexerCache();
        DynObject[] candidates = ResolveProtoregex(lc, name);
        Lexer l;

        if (lc.protorx_nfa.TryGetValue(name, out l)) {
            if (LtmTrace)
                Console.WriteLine("+ Protoregex lexer HIT on {0}.{1}",
                        kl.name, name);
            return l;
        }

        if (LtmTrace)
            Console.WriteLine("+ Protoregex lexer MISS on {0}.{1}",
                    kl.name, name);

        if (lc.parent != null && !lc.repl_methods.Contains(name)) {
            if (LtmTrace)
                Console.WriteLine("+ Trying to delegate to {0}",
                        lc.parent.mo.name);
            Lexer pl = GetProtoregexLexer(lc.parent.mo, name);

            foreach (string used in pl.pad.used_methods) {
                if (lc.repl_methods.Contains(used)) {
                    if (LtmTrace)
                        Console.WriteLine("+ Can't; {0} is overridden",
                                used);
                    goto anew;
                }
            }

            if (LtmTrace)
                Console.WriteLine("+ Success!");

            return lc.protorx_nfa[name] = pl;
        }
        anew:
        LAD[] branches = new LAD[candidates.Length];
        NFA pad = new NFA();
        pad.used_methods.Add(name);
        pad.cursor_class = kl;
        for (int i = 0; i < candidates.Length; i++) {
            pad.outer_stack.Add((Frame) candidates[i].GetSlot("outer"));
            branches[i] = (((SubInfo) candidates[i].GetSlot("info")).ltm).
                Reify(pad);
            pad.outer_stack.RemoveAt(pad.outer_stack.Count - 1);
        }
        return lc.protorx_nfa[name] = new Lexer(pad, name, branches);
    }
Example #8
0
    public static Lexer GetLexer(Frame fromf, DynMetaObject kl, LAD[] lads, string title)
    {
        LexerCache lc = kl.GetLexerCache();
        Lexer ret;
        if (lc.nfas.TryGetValue(lads, out ret))
            return ret;
        if (lc.parent != null && lc.parent.mo.name != "Cursor" && lc.parent.mo.name != "Any") {
            ret = GetLexer(fromf, lc.parent.mo, lads, title);
            foreach (string u in ret.pad.used_methods) {
                if (lc.repl_methods.Contains(u))
                    goto anew;
            }
            if (LtmTrace)
                Console.WriteLine("Reused {0} alternation lexer for {1} in {2}",
                        title, lc.parent.mo.name, kl.name);
            return lc.nfas[lads] = ret;
        }
        anew:
        if (LtmTrace) {
            Console.WriteLine("Need new alternation lexer for {0} in {1}",
                    title, kl.name);
        }
        NFA pad = new NFA();
        pad.cursor_class = kl;
        LAD[] lads_p = new LAD[lads.Length];
        pad.outer_stack.Add(fromf);
        for (int i = 0; i < lads_p.Length; i++)
            lads_p[i] = lads[i].Reify(pad);

        ret = new Lexer(pad, title, lads_p);
        lc.nfas[lads] = ret;
        return ret;
    }