def setup_globals(names): if not isinstance(names, list): names = [names] global next_global for x in names: ts.init('( gread ' + str(next_global) + ')'); getter = ts.intern(str(x)) getter.macro = ts.readList() setter = ts.intern('set' + str(x)) ts.init('gwrite ' + str(next_global)) setter.macro = ts.readList() next_global += 1
def setup_globals(names): if not isinstance(names, list): names = [names] global next_global for x in names: ts.init('( gread ' + str(next_global) + ')') getter = ts.intern(str(x)) getter.macro = ts.readList() setter = ts.intern('set' + str(x)) ts.init('gwrite ' + str(next_global)) setter.macro = ts.readList() next_global += 1
def pass1_fcn(name, args, body): if 'type' in name.__dict__: raise ValueError(str(name) + " already defined") add((name, args, body)) name.args = len(args) name.argnames = args name.type = 'ufun' name.outputs = mmmember(ts.intern('output'), body)
def handle_waituntil(): add_and_count(['-[-', 0], 3) newbody = state.body.pop(0) oldbody, state.body = state.body, newbody pass2_argloop(1, 'waituntil') add_and_count(['-]-r', 0], 1) add_and_count(['prim', ts.intern('waituntil')], 1) state.body = oldbody
def setup_specials(*newprims): for x in newprims: name, outputs, handler = x sym = ts.intern(name) sym.type = 'prim' sym.args = 0 sym.outputs = outputs sym.special = True sym.handler = handler
def setup_prims(primtype, dest, *newprims): for x in newprims: name, outputs, args = x sym = ts.intern(name) sym.args = args sym.outputs = outputs if sym.args < 0: infixes.append(sym) sym.type = primtype sym.special = False dest.append(sym)
def pass2_fcn(fcn): global state state = record() state.toplevel = True state.command = True state.body = [] state.locals = [] state.name, state.arglist, body = fcn state.name.addr = pc state.name.locals = 0 add_and_count(['to', state.name], 2) pass2_body(body[:]) add_and_count(['prim', ts.intern('stop')], 1) state.name.endaddr = pc
def sym(x): if not isinstance(x, ts.symbol) and not isinstance(x, ts.qsym): raise LogoError(mmstr(x) + " isn't a valid local") return ts.dsym(ts.intern(str(x)))
def handle_opening(): pass2_argloop(1, ')') if [] == state.body or state.body.pop(0) != ts.intern(')'): raise LogoError('() error')