def test_ellipsis(self): m = macro("(() ((_ (a ...) ...) ((a) ... ...)))") assert trans(m, "(_)") == None assert trans(m, "(_ ())") == None assert trans(m, "(_ (1))") == parse("((1))") assert trans(m, "(_ (1 2))") == parse("((1) (2))") assert trans(m, "(_ (1 2) (3))") == parse("((1) (2) (3))") assert trans(m, "(_ (1 2) () (3))") == parse("((1) (2) (3))")
def eval(self, code): vm = VM() proc = self.compiler.compile(parse(code), vm.env) return vm.run(proc)
op.add_option('-S', action="store_true", dest="do_not_run", help = "Compile source file and drop into .s file then stop."); (options, args) = op.parse_args() def is_valid_path(source_file_path): """ Returns true if given path exists and is a file Arguments: - `path`: path of Scheme source file """ source_file_path = path.abspath(source_file_path) return path.exists(source_file_path) and path.isfile(source_file_path) source_file = open(args[0]) vm = VM() compiler = Compiler() proc = compiler.compile(parse(source_file.read()), vm.env) if not options.do_not_run: result = vm.run(proc) print "Result is %s" % result source_file.close() else: print "Bytecode:\n%s" % str(proc.bytecode) print "Disasm run:\n%s\n" % str(proc.disasm())
def test_combined_ellipsis(self): m = macro("(() ((_ (a ...) (b ...)) ((a b) ...)))") assert trans(m, "(_ () ())") == None assert trans(m, "(_ (1 2) (3 4))") == parse("((1 3) (2 4))") assert_raises(SyntaxError, trans, m, "(_ (1) (3 4))") assert_raises(SyntaxError, trans, m, "(_ (1 2) (3))")
def test_sequence_ellipsis(self): m = macro("(() ((_ (a b) ...) (a ... b ...)))") assert trans(m, "(_)") == None assert trans(m, "(_ (1 2))") == parse("(1 2)") assert trans(m, "(_ (1 2) (3 4))") == parse("(1 3 2 4)")
def test_variable_ellipsis(self): m = macro("(() ((_ a ...) ((a) ...)))") assert trans(m, "(_)") == None assert trans(m, "(_ 1)") == parse("((1))") assert trans(m, "(_ 1 2)") == parse("((1) (2))") assert_raises(SyntaxError, trans, m, "(_ 1 . 2)")
def trans(m, expr): return filter_dc(m.transform(None, parse(expr))[0])
def macro(code): return Macro(None, parse(code))