Example #1
0
 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))")
Example #2
0
 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))")
Example #3
0
 def eval(self, code):
     vm = VM()
     proc = self.compiler.compile(parse(code), vm.env)
     return vm.run(proc)
Example #4
0
 def eval(self, code):
     vm = VM()
     proc = self.compiler.compile(parse(code), vm.env)
     return vm.run(proc)
Example #5
0
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())
Example #6
0
 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))")
Example #7
0
 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)")
Example #8
0
 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)")
Example #9
0
def trans(m, expr):
    return filter_dc(m.transform(None, parse(expr))[0])
Example #10
0
def macro(code):
    return Macro(None, parse(code))
Example #11
0
 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))")
Example #12
0
 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)")
Example #13
0
 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)")
Example #14
0
def trans(m, expr):
    return filter_dc(m.transform(None, parse(expr))[0])
Example #15
0
def macro(code):
    return Macro(None, parse(code))