void prefix(int /* UnOpr */ op, expdesc e, int line) { expdesc e2 = new expdesc(); e2.init(LexState.VKNUM, 0); switch (op) { case LexState.OPR_MINUS: { if (e.isnumeral()) /* minus constant? */ e.u.setNval(e.u.nval().neg()); /* fold it */ else { this.exp2anyreg(e); this.codearith(OP_UNM, e, e2, line); } break; } case LexState.OPR_NOT: this.codenot(e); break; case LexState.OPR_LEN: { this.exp2anyreg(e); /* cannot operate on constants */ this.codearith(OP_LEN, e, e2, line); break; } default: _assert(false); } }
static int singlevaraux(FuncState fs, LuaString n, expdesc var, int base) { if (fs == null) /* no more levels? */ return LexState.VVOID; /* default is global */ int v = fs.searchvar(n); /* look up at current level */ if (v >= 0) { var.init(LexState.VLOCAL, v); if (base == 0) fs.markupval(v); /* local will be used as an upval */ return LexState.VLOCAL; } else { /* not found at current level; try upvalues */ int idx = fs.searchupvalue(n); /* try existing upvalues */ if (idx < 0) { /* not found? */ if (singlevaraux(fs.prev, n, var, 0) == LexState.VVOID) /* try upper levels */ return LexState.VVOID; /* not found; is a global */ /* else was LOCAL or UPVAL */ idx = fs.newupvalue(n, var); /* will be a new upvalue */ } var.init(LexState.VUPVAL, idx); return LexState.VUPVAL; } }