示例#1
0
def compile_(output, filename):
    env = Env()
    with open(output, "w") as outfile:
        outfile.write(
            compile_list(parse(lex(pycell.library.as_text(env))), env))
        with open(filename, encoding="ascii") as infile:
            outfile.write(
                compile_list(parse(lex(chars_in_file(infile))), env))
示例#2
0
def import_(env):
    env.set("char_at", ("native", pycell.prologue.native.char_at.char_at))
    env.set("equals",  ("native", pycell.prologue.native.equals.equals))
    env.set("if",      ("native", pycell.prologue.native.if_.if_))
    env.set("len",     ("native", pycell.prologue.native.len_.len_))
    env.set("print",   ("native", pycell.prologue.native.print_.print_))
    env.set("set",     ("native", pycell.prologue.native.set_.set_))
    env.set("None",    ("none",))

    eval_list(parse(lex(as_text(env))), env)
示例#3
0
def import_(env):
    env.set("char_at", ("native", pycell.prologue.native.char_at.char_at))
    env.set("concat",  ("native", pycell.prologue.native.concat.concat))
    env.set("equals",  ("native", pycell.prologue.native.equals.equals))
    env.set("if",      ("native", pycell.prologue.native.if_.if_))
    env.set("len",     ("native", pycell.prologue.native.len_.len_))
    env.set("print",   ("native", pycell.prologue.native.print_.print_))
    env.set("set",     ("native", pycell.prologue.native.set_.set_))
    env.set("None",    ("none",))

    eval_list(parse(lex(as_text(env))), env)
示例#4
0
文件: repl.py 项目: andybalaam/cell
def repl(stdin, stdout, stderr):
    env = Env(parent=None, stdin=stdin, stdout=stdout, stderr=stderr)
    pycell.library.import_(env)
    while True:
        try:
            p = Prompt(stdout)
            for value in eval_iter(
                    parse(lex(p.handle_chars(chars_in_file(stdin)))), env):
                p.value(value)
            break
        except Exception as e:
            stderr.write(str(e))
            stderr.write("\n")
    stdout.write("\n")
    stdout.flush()
示例#5
0
文件: repl.py 项目: spider2449/cell
def repl(stdin, stdout, stderr):
    env = Env(parent=None, stdin=stdin, stdout=stdout, stderr=stderr)
    pycell.library.import_(env)
    while True:
        try:
            p = Prompt(stdout)
            for value in eval_iter(
                    parse(lex(p.handle_chars(chars_in_file(stdin)))), env):
                p.value(value)
            break
        except Exception as e:
            stderr.write(str(e))
            stderr.write("\n")
    stdout.write("\n")
    stdout.flush()
示例#6
0
def compiled(inp, env=None):
    if env is None:
        env = Env()
    return compile_list(parse(lex(inp)), env)
示例#7
0
def compiled(inp, env=None):
    if env is None:
        env = Env()
    return compile_list(parse(lex(inp)), env)
示例#8
0
def runned(inp):
    with StringIO() as stdin, StringIO() as stdout:
        env = Env(stdin=stdin, stdout=stdout, stderr=stdout)
        pycell.library.import_(env)
        return eval_list(parse(lex(inp)), env)
示例#9
0
def evald(inp, stdout=None):
    env = Env(stdout=stdout)
    pycell.library.import_(env)
    return eval_list(parse(lex(inp)), env)
示例#10
0
def evald(inp, env=None):
    if env is None:
        env = Env()
    return eval_list(parse(lex(inp)), env)
示例#11
0
def runned(inp):
    with StringIO() as stdin, StringIO() as stdout:
        env = Env(stdin=stdin, stdout=stdout, stderr=stdout)
        pycell.library.import_(env)
        return eval_list(parse(lex(inp)), env)
示例#12
0
def evald(inp, env=None):
    if env is None:
        env = Env()
    return eval_list(parse(lex(inp)), env)
示例#13
0
文件: run.py 项目: spider2449/cell
def run(filename, stdin, stdout, stderr):
    env = Env(stdin=stdin, stdout=stdout, stderr=stdout)
    pycell.library.import_(env)
    with open(filename, encoding="ascii") as f:
        eval_list(parse(lex(chars_in_file(f))), env)
示例#14
0
def parsed(inp):
    return list(parse(lex(inp)))