예제 #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))")
예제 #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))")
예제 #3
0
 def eval(self, code):
     vm = VM()
     proc = self.compiler.compile(parse(code), vm.env)
     return vm.run(proc)
예제 #4
0
파일: helper.py 프로젝트: adamfeuer/skime
 def eval(self, code):
     vm = VM()
     proc = self.compiler.compile(parse(code), vm.env)
     return vm.run(proc)
예제 #5
0
파일: skime.py 프로젝트: adamfeuer/skime
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())
예제 #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))")
예제 #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)")
예제 #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)")
예제 #9
0
def trans(m, expr):
    return filter_dc(m.transform(None, parse(expr))[0])
예제 #10
0
def macro(code):
    return Macro(None, parse(code))
예제 #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))")
예제 #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)")
예제 #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)")
예제 #14
0
def trans(m, expr):
    return filter_dc(m.transform(None, parse(expr))[0])
예제 #15
0
def macro(code):
    return Macro(None, parse(code))