示例#1
0
文件: pils.py 项目: miedzinski/pils
def repl(env):
    while True:
        try:
            sexp = PilsParser.parse_interactive(input('pils> '))
            compiler = PilsCompiler()
            exec(compiler.compile_interactive(sexp), env)
        except PilsSyntaxError as e:
            print('SyntaxError: {}'.format(e), file=sys.stderr)
        except EOFError:
            raise
        except:
            traceback.print_exc()
示例#2
0
文件: pils.py 项目: miedzinski/pils
def main():
    env = {'PilsAtom': PilsAtom, 'PilsList': PilsList}
    import_core(env)

    if len(sys.argv) == 2:
        with open(sys.argv[1], 'r') as f:
            prog = f.read()
            compiler = PilsCompiler()
            sexps = PilsParser.parse_module(prog)
            exec(compiler.compile_module(sexps, sys.argv[1]), env)

    repl(env)
示例#3
0
文件: pils.py 项目: miedzinski/pils
def import_core(env):
    core = pkg_resources.resource_string(__name__, 'core.pils').decode()
    compiler = PilsCompiler()
    sexps = PilsParser.parse_module(core)
    exec(compiler.compile_module(sexps, '<core>'), env)