def eval_file(name: str, env: scope.Scope) -> None: with open(name) as f: while True: line: str = f.readline() if not line: break print(repl.REPL(line, env))
def main() -> None: lib: str = load_std_lib() env: scope.Scope = scope.root_scope() repl.REPL(lib, env) if len(sys.argv) == 2: if sys.argv[1] == '--version': print(version) return else: eval_file(sys.argv[1]) elif len(sys.argv) > 2: print('Too many arguments') sys.exit(2) readline.parse_and_bind('set editing-mode vi') while True: line: str = input(">> ") r: str = repl.REPL(line, env) if len(r) > 0: print(r)
except Exception as e: warn( "Could not open the serial port that was remembered from last time" ) portscan.forget() name = portscan.find(DEVICE_NAME) if name == None: fail("Still can't find a port, giving in") PORT = name # go round again and try and open serial port #----- GET RAW REPL ----------------------------------------------------------- # wrap a repl around it trace("creating a raw REPL connection via serial") repl = repl.REPL(s) trace("entering raw repl mode") repl.to_raw() #----- CREATE MICROBIT ABSTRACTION -------------------------------------------- trace("creating a MicroBit API class around it") microbit = api.MicroBit(repl) #----- TURN THIS MODULE into a microbit instance ------------------------------ # i.e. when people do import microbit # what they then want is to be able to say microbit.button_a.was_pressed() # and for it to map directly through to the microbit object above.