| 6777 | |
| 6778 | |
| 6779 | LClosure *luaY_parser (lua_State *L, LexState& lexstate, ZIO *z, Mbuffer *buff, |
| 6780 | Dyndata *dyd, const char *name, int firstchar) { |
| 6781 | FuncState funcstate; |
| 6782 | LClosure *cl = luaF_newLclosure(L, 1); /* create main closure */ |
| 6783 | setclLvalue2s(L, L->top.p, cl); /* anchor it (to avoid being collected) */ |
| 6784 | luaD_inctop(L); |
| 6785 | lexstate.h = luaH_new(L); /* create table for scanner */ |
| 6786 | sethvalue2s(L, L->top.p, lexstate.h); /* anchor it */ |
| 6787 | luaD_inctop(L); |
| 6788 | funcstate.f = cl->p = luaF_newproto(L); |
| 6789 | luaC_objbarrier(L, cl, cl->p); |
| 6790 | funcstate.f->source = luaS_new(L, name); /* create and anchor TString */ |
| 6791 | luaC_objbarrier(L, funcstate.f, funcstate.f->source); |
| 6792 | lexstate.buff = buff; |
| 6793 | lexstate.dyd = dyd; |
| 6794 | dyd->actvar.n = dyd->gt.n = dyd->label.n = 0; |
| 6795 | luaX_setinput(L, &lexstate, z, funcstate.f->source, firstchar); |
| 6796 | { decltype(lexstate.macros) bin; std::swap(lexstate.macros, bin); } /* free memory for macros map */ |
| 6797 | { decltype(lexstate.macro_args) bin; std::swap(lexstate.macro_args, bin); } |
| 6798 | if (L->l_G->have_preference_switch) |
| 6799 | applyenvkeywordpreference(&lexstate, TK_SWITCH, L->l_G->preference_switch); |
| 6800 | if (L->l_G->have_preference_continue) |
| 6801 | applyenvkeywordpreference(&lexstate, TK_CONTINUE, L->l_G->preference_continue); |
| 6802 | if (L->l_G->have_preference_enum) |
| 6803 | applyenvkeywordpreference(&lexstate, TK_ENUM, L->l_G->preference_enum); |
| 6804 | if (L->l_G->have_preference_new) |
| 6805 | applyenvkeywordpreference(&lexstate, TK_NEW, L->l_G->preference_new); |
| 6806 | if (L->l_G->have_preference_class) |
| 6807 | applyenvkeywordpreference(&lexstate, TK_CLASS, L->l_G->preference_class); |
| 6808 | if (L->l_G->have_preference_parent) |
| 6809 | applyenvkeywordpreference(&lexstate, TK_PARENT, L->l_G->preference_parent); |
| 6810 | if (L->l_G->have_preference_export) |
| 6811 | applyenvkeywordpreference(&lexstate, TK_EXPORT, L->l_G->preference_export); |
| 6812 | mainfunc(&lexstate, &funcstate); |
| 6813 | lua_assert(!funcstate.prev && funcstate.nups == 1 && !lexstate.fs); |
| 6814 | /* all scopes should be correctly finished */ |
| 6815 | lua_assert(dyd->actvar.n == 0 && dyd->gt.n == 0 && dyd->label.n == 0); |
| 6816 | L->top.p--; /* remove scanner's table */ |
| 6817 | return cl; /* closure is on the stack, too */ |
| 6818 | } |
no test coverage detected