def inner_invoke(self, args): import pixie.vm.rt as rt import pixie.vm.persistent_vector as vector with with_ns(u"user"): NS_VAR.deref().include_stdlib() acc = vector.EMPTY for x in self._argv: acc = rt.conj(acc, rt.wrap(x)) PROGRAM_ARGUMENTS.set_root(acc) with with_ns(u"user"): try: f = None if self._file == '-': f, _, _ = create_stdio() else: if not path.isfile(self._file): print "Error: Cannot open '" + self._file + "'" os._exit(1) f = open(self._file) data = f.read() f.close() if data.startswith("#!"): newline_pos = data.find("\n") if newline_pos > 0: data = data[newline_pos:] interpret(compile(read(StringReader(unicode(data)), True))) except WrappedException as ex: print "Error: ", ex._ex.__repr__() os._exit(1)
def inner_invoke(self, args): import pixie.vm.rt as rt with with_ns(u"user"): NS_VAR.deref().include_stdlib() interpret(compile(read(StringReader(unicode(self._expr)), True)))
def inner_invoke(self, args): import pixie.vm.rt as rt with with_ns(u"user"): NS_VAR.deref().include_stdlib() interpret( compile(read(StringReader(unicode_from_utf8(self._expr)), True)))
def test_if(): code = compile(read_code("(if 1 2 3)")) assert isinstance(code, Code) retval = interpret(code) assert isinstance(retval, Integer) and retval.int_val() == 2 code = compile(read_code("(if false 2 3)")) assert isinstance(code, Code) retval = interpret(code) assert isinstance(retval, Integer) and retval.int_val() == 3
def inner_invoke(self, args): from pixie.vm.keyword import keyword import pixie.vm.rt as rt from pixie.vm.string import String import pixie.vm.persistent_vector as vector with with_ns(u"user"): NS_VAR.deref().include_stdlib() acc = vector.EMPTY for x in self._argv: acc = rt.conj(acc, rt.wrap(x)) PROGRAM_ARGUMENTS.set_root(acc) rdr = MetaDataReader(PromptReader()) with with_ns(u"user"): while True: try: val = read(rdr, False) if val is eof: break val = interpret(compile(val)) except WrappedException as ex: print "Error: ", ex._ex.__repr__() rdr.reset_line() continue if val is keyword(u"exit-repl"): break val = rt.str(val) assert isinstance(val, String), "str should always return a string" print val._str
def inner_invoke(self, args): import pixie.vm.rt as rt import pixie.vm.persistent_vector as vector with with_ns(u"user"): NS_VAR.deref().include_stdlib() acc = vector.EMPTY for x in self._argv: acc = rt.conj(acc, rt.wrap(x)) PROGRAM_ARGUMENTS.set_root(acc) with with_ns(u"user"): if self._file == '-': stdin, _, _ = create_stdio() code = stdin.read() interpret(compile(read(StringReader(unicode(code)), True))) else: rt.load_file(rt.wrap(self._file))
def repl(): from pixie.vm.keyword import keyword import pixie.vm.rt as rt from pixie.vm.string import String with with_ns(u"user"): NS_VAR.deref().include_stdlib() rdr = PromptReader() while True: with with_ns(u"user"): try: val = interpret(compile(read(rdr, True))) except WrappedException as ex: print "Error: ", ex._ex.__repr__() continue if val is keyword(u"exit-repl"): break val = rt.str(val) assert isinstance(val, String), "str should always return a string" print val._str
def inner_invoke(self, args): from pixie.vm.keyword import keyword import pixie.vm.rt as rt from pixie.vm.string import String import pixie.vm.persistent_vector as vector print "Pixie 0.1 - Interactive REPL" print "(" + platform.name + ", " + platform.cc + ")" print ":exit-repl or Ctrl-D to quit" print "----------------------------" with with_ns(u"user"): NS_VAR.deref().include_stdlib() acc = vector.EMPTY for x in self._argv: acc = rt.conj(acc, rt.wrap(x)) PROGRAM_ARGUMENTS.set_root(acc) rdr = MetaDataReader(PromptReader()) with with_ns(u"user"): while True: try: val = read(rdr, False) if val is eof: break val = interpret(compile(val)) self.set_recent_vars(val) except WrappedException as ex: print "Error: ", ex._ex.__repr__() rdr.reset_line() self.set_error_var(ex._ex) continue if val is keyword(u"exit-repl"): break val = rt._repr(val) assert isinstance(val, String), "str should always return a string" print unicode_to_utf8(val._str)
def eval(form): from pixie.vm.compiler import compile from pixie.vm.interpreter import interpret val = interpret(compile(form)) return val
def test_fn(): with with_ns(u"user", True): code = compile(read_code("((fn* [x y] (-add x y)) 1 2)")) assert isinstance(code, Code) retval = interpret(code) assert isinstance(retval, Integer) and retval.int_val() == 3
def test_fn(): code = compile(read_code("((fn [x y] (+ x y)) 1 2)")) assert isinstance(code, Code) retval = interpret(code) assert isinstance(retval, Integer) and retval.int_val() == 3