newtRef protoREGEX_match(newtRefArg rcvr, newtRefArg str) { newtRefVar preg; newtRefVar r; if (NewtRefIsNIL(rcvr)) return kNewtRefUnbind; NcSetSlot(rcvr, NSSYM(_matchs), kNewtRefNIL); preg = NcGetSlot(rcvr, NSSYM(_preg)); if (NewtRefIsNIL(preg)) { protoREGEX_compile(rcvr); preg = NcGetSlot(rcvr, NSSYM(_preg)); if (NewtRefIsNIL(preg)) return kNewtRefNIL; } r = protoREGEX_regexec(preg, str); NcSetSlot(rcvr, NSSYM(_matchs), r); return r; }
newtRef NcFullLookupFrame(newtRefArg start, newtRefArg name) { newtRefVar current; newtRefVar left = start; if (! NewtRefIsFrame(start)) return kNewtRefUnbind; while (NewtRefIsNotNIL(left)) { current = left; while (NewtRefIsNotNIL(current)) { current = NcResolveMagicPointer(current); if (NewtRefIsMagicPointer(current)) return kNewtRefUnbind; if (NewtHasSlot(current, name)) return current; current = NcGetSlot(current, NSSYM0(_proto)); } left = NcGetSlot(left, NSSYM0(_parent)); } return kNewtRefUnbind; }
newtRef protoREGEX_compile(newtRefArg rcvr) { newtRefVar preg; if (NewtRefIsNIL(rcvr)) return kNewtRefUnbind; preg = protoREGEX_regcomp(NcGetSlot(rcvr, NSSYM(pattern)), NcGetSlot(rcvr, NSSYM(option))); return NcSetSlot(rcvr, NSSYM(_preg), preg); }
newtRef NcLexicalLookup(newtRefArg start, newtRef name) { newtRefVar current = start; while (NewtRefIsNotNIL(current)) { current = NcResolveMagicPointer(current); if (NewtRefIsMagicPointer(current)) return kNewtRefUnbind; if (NewtHasSlot(current, name)) return NcGetSlot(current, name); current = NcGetSlot(current, NSSYM0(_nextArgFrame)); } return kNewtRefUnbind; }
newtRef NcProtoLookup(newtRefArg start, newtRefArg name) { newtRefVar current; current = NcProtoLookupFrame(start, name); if (current != kNewtRefUnbind) return NcGetSlot(current, name); else return kNewtRefUnbind; }
newtRef NcResolveNamedMP(newtRefArg r) { newtRefVar sym; if (! NewtRefIsNamedMP(r)) return r; sym = NewtMPToSymbol(r); if (NewtHasSlot(NAMED_MPS, sym)) return NcGetSlot(NAMED_MPS, sym); else return r; }
newtRef protoREGEX_cleanup(newtRefArg rcvr) { newtRefVar preg; if (NewtRefIsNIL(rcvr)) return kNewtRefUnbind; NcSetSlot(rcvr, NSSYM(_matchs), kNewtRefNIL); preg = NcGetSlot(rcvr, NSSYM(_preg)); if (NewtRefIsNotNIL(preg)) { protoREGEX_regfree(preg); NcSetSlot(rcvr, NSSYM(_preg), kNewtRefNIL); } return kNewtRefNIL; }
newtRef NsGetGlobalVar(newtRefArg rcvr, newtRefArg r) { return NcGetSlot(GLOBALS, r); }
newtRef NsGetGlobalFn(newtRefArg rcvr, newtRefArg r) { return NcGetSlot(GLOBAL_FNS, r); }