def read(self): if self.pending: return self.pending.pop() if self.pos < self.length: c = el.at(self.string, self.pos) self.pos += 1 return c
def eval_sub(form, *, macroexpanding=False, **kws): if accessor_literal_p(form): return form if el.symbolp(form): # look up its binding in the lexical environment. lex_binding = el.assq(form, V.internal_interpreter_environment) if el.consp(lex_binding): return el.at(lex_binding, 1) else: return symbol_value(form) if not el.consp(form): return form original_fun = XCAR(form) original_args = XCDR(form) fun = indirect_function(original_fun) mac = CONSP(fun) and el.hd(fun, 'macro') if mac: fun = indirect_function(XCAR(XCDR(fun))) elif macroexpanding: return form args_left = [arg for arg in original_args] if CONSP(fun): fun = eval_sub(fun) if not SUBRP(fun): import pdb pdb.set_trace() raise NotImplementedError() else: maxargs = XSUBR_max_args(fun) if maxargs == UNEVALLED or mac: val = fun(*args_left, **kws) elif maxargs == MANY: vals = [] while CONSP(args_left): arg = XCAR(args_left) if el.keywordp(arg): k = arg[1:] args_left = XCDR(args_left) arg = XCAR(args_left) args_left = XCDR(args_left) kws[k] = eval_sub(arg) else: args_left = XCDR(args_left) vals.append(eval_sub(arg)) val = fun(*vals, **kws) else: import pdb pdb.set_trace() raise NotImplementedError() argvals = [] for i in range(maxargs): argvals.append(eval_sub(XCAR(args_left))) args_left = XCDR(args_left) val = fun(*argvals, **kws) if mac and not macroexpanding: val = eval_sub(val) return val
def get__special(place, key): if not el.stringp(key) and not INTP(key): raise ValueError("%get expected an index for key: {}".format( ['%get', place, key])) parts = accessor(key) while parts: key, *parts = parts if INTP(key): place = el.at(place, key) else: place = util.get_obj_from_module(place, key) return place
def get_place(place, setfn): place = macroexpand_1(place) if el.atom(place) or \ (el.hd(place, "get") and el.nilp(getenv("get", "place-expander"))) or \ accessor_literal_p(el.at(place, 1)): return setfn(place, lambda v: ["%set", place, v]) else: head = el.hd(place) gf = getenv(head, "place-expander") if not el.nilp(gf): return apply(gf, setfn, el.tl(place)) else: return error(str(place) + " is not a valid place expression")
def parse_accessor(key, out=None): if out is None: out = [] if accessor_literal_p(key): i = search(key, '.', 1) while i is not None and el.at(key, i - 1) == '\\': i = search(key, '.', i + 1) out.append(maybe_number(key[1:i])) if i is not None: key = key[i:] else: key = '' return parse_accessor(key, out) if key: out.append(maybe_number(key)) return out
def search_until(s, char, pos=1, backspace=True): i = search(s, char, pos) while i is not None and backspace and el.at(s, i - 1) == '\\': i = search(s, char, i + 1) return i
def peek(self): if self.pending: return self.pending[-1] if self.pos < self.length: return el.at(self.string, self.pos)
def maybe_number(x): if el.stringp(x) and el.at(x, 0) == '-' and el.numeric(x[1:]): return int(x) if el.numeric(x): return int(x) return x
def id_literal_p(x): return el.stringp(x) and el.at(x, 0) == "|"
def accessor_literal_p(x): return el.stringp(x) and \ el.at(x, 0) == "." and \ el.at(x, 1) != "." and \ el.some(x)