Exemple #1
0
def load_file(file):
    if not os.path.exists(file):
        parable.report('L00: Unable to find ' + str(file))
    else:
        f = open(file).readlines()
        f = parable.condense_lines(f)
        for line in f:
            if len(line) > 1:
                s = parable.compile(line, parable.request_slice())
                parable.interpret(s)
Exemple #2
0
def load_file(file):
    if not os.path.exists(file):
        parable.report('L00: Unable to find ' + str(file))
    else:
        f = open(file).readlines()
        f = parable.condense_lines(f)
        for line in f:
            if len(line) > 1:
                s = parable.compile(line, parable.request_slice())
                parable.interpret(s)
Exemple #3
0
def opcodes(slice, offset, opcode):
    if opcode == 9000:
        dump_stack()
    elif opcode == 9001:
        exit()
    elif opcode == 9002:
        dump_dict()
    elif opcode == 9003:
        name = parable.slice_to_string(parable.stack_pop())
        if os.path.exists(name):
            lines = parable.condense_lines(open(name).readlines())
            for l in lines:
                slice = parable.request_slice()
                parable.interpret(parable.compile(l, slice), opcodes)

    return offset
Exemple #4
0
def opcodes(slice, offset, opcode):
    if opcode == 9000:
        dump_stack()
    elif opcode == 9001:
        exit()
    elif opcode == 9002:
        dump_dict()
    elif opcode == 9003:
        name = parable.slice_to_string(parable.stack_pop())
        if os.path.exists(name):
            lines = parable.condense_lines(open(name).readlines())
            for l in lines:
                slice = parable.request_slice()
                parable.interpret(parable.compile(l, slice), opcodes)

    return offset
Exemple #5
0
    while 1 == 1:
        display(height, width)

        try:
            src = get_input()
        except:
            sys.stdout.write("\n")
            exit()

        cmd = ' '.join(src.split())

        if cmd == ':q':
            exit()
        elif cmd == ':r':
            revert()
            parable.parse_bootstrap(open('stdlib.p').readlines())
            parable.collect_garbage()
        elif cmd[0:2] == ':i':
            load_file(cmd[3:])
        else:
            if len(src) >= 1:
                try:
                    parable.interpret(
                        parable.compile(src, parable.request_slice()))
                except:
                    sys.stdout.write("\n")
                    pass

        sys.stdout.flush()
Exemple #6
0
def evaluate(s):
    parable.interpret(parable.compile(s, parable.request_slice()))
Exemple #7
0
    evaluate("[ \"-\"   `9002 ] 'words' :")
    evaluate("[ \"s-\"  `9003 ] 'include' :")

    try:
        home = expanduser("~")
        src = home + "/.parable/on_startup.p"
        parable.parse_bootstrap(open(src).readlines())
    except:
        pass

    while 1 == 1:
        try:
            src = get_input()
        except:
            sys.stdout.write("\n")
            exit()

        if len(src) >= 1:
            try:
                slice = parable.request_slice()
                parable.interpret(parable.compile(src, slice), opcodes)
            except KeyboardInterrupt:
                sys.stdout.write("\n")
                pass

        for e in parable.errors:
            sys.stdout.write(e + "\n")

        parable.clear_errors()
        sys.stdout.flush()
Exemple #8
0
        snapshot = open('parable.snapshot', 'r').read()
    bootstrap(snapshot)

# -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

if __name__ == '__main__':
    sys.stdout.write("Content-type: text/html\n\n")

    setup_environment()
    code = form.getvalue("code", "")
    message = code.replace("\\\r\n", " ")
    message = message.replace("\\\n", " ")
    f = parable.condense_lines(message.split("\n"))
    for line in f:
        if len(line) > 0:
            s = parable.compile(line, parable.request_slice())
            parable.interpret(s)

    with open('template.html') as file:
        template = file.read()

    stack = dump_stack()
    errors = dump_errors()
    dict = dump_dict()

    template = template.replace('{{code}}', code)
    template = template.replace('{{stack}}', stack)
    template = template.replace('{{errors}}', errors)
    template = template.replace('{{dict}}', dict)

    shot = encode_snapshot(compress_snapshot(create_snapshot()))
Exemple #9
0
def evaluate(s):
    parable.interpret(parable.compile(s, parable.request_slice()))
Exemple #10
0
    evaluate("[ \"-\"   `9002 ] 'words' :")
    evaluate("[ \"s-\"  `9003 ] 'include' :")

    try:
        home = expanduser("~")
        src = home + "/.parable/on_startup.p"
        parable.parse_bootstrap(open(src).readlines())
    except:
        pass

    while 1 == 1:
        try:
            src = get_input()
        except:
            sys.stdout.write("\n")
            exit()

        if len(src) >= 1:
            try:
                slice = parable.request_slice()
                parable.interpret(parable.compile(src, slice), opcodes)
            except KeyboardInterrupt:
                sys.stdout.write("\n")
                pass

        for e in parable.errors:
            sys.stdout.write(e + "\n")

        parable.clear_errors()
        sys.stdout.flush()
Exemple #11
0
def evaluate(s):
    parable.interpret(parable.compile(s), opcodes)
Exemple #12
0
def opcodes(slice, offset, opcode):
    if opcode == 9000:
        display_value()
        parable.stack_pop()
    elif opcode == 9010:
        dump_stack()
    elif opcode == 9020:
        exit()
    elif opcode == 9030:
        dump_dict()
    elif opcode == 9040:
        s = parable.request_slice()
        i = 0
        for word in parable.dictionary_names():
            value = parable.string_to_slice(word)
            parable.store(value, s, i, parable.TYPE_STRING)
            i = i + 1
        parable.stack_push(s, parable.TYPE_POINTER)
    elif opcode == 3000:
        slot = 0
        i = 1
        while i < 8:
            if files[i] == 0:
                slot = i
            i = i + 1
        mode = parable.slice_to_string(parable.stack_pop())
        name = parable.slice_to_string(parable.stack_pop())
        if slot != 0:
            files[int(slot)] = open(name, mode)
        stack_push(slot, TYPE_NUMBER)
    elif opcode == 3001:
        slot = int(parable.stack_pop())
        files[slot].close()
        files[slot] = 0
    elif opcode == 3002:
        slot = int(parable.stack_pop())
        stack_push(ord(files[slot].read(1)), TYPE_NUMBER)
    elif opcode == 3003:
        slot = int(parable.stack_pop())
        files[slot].write(unichr(int(parable.stack_pop())))
    elif opcode == 3004:
        slot = int(parable.stack_pop())
        parable.stack_push(files[slot].tell(), TYPE_NUMBER)
    elif opcode == 3005:
        slot = int(parable.stack_pop())
        pos = int(parable.stack_pop())
        parable.stack_push(files[slot].seek(pos, 0), TYPE_NUMBER)
    elif opcode == 3006:
        slot = int(parable.stack_pop())
        at = files[slot].tell()
        files[slot].seek(0, 2) # SEEK_END
        parable.stack_push(files[slot].tell(), TYPE_NUMBER)
        files[slot].seek(at, 0) # SEEK_SET
    elif opcode == 3007:
        name = parable.slice_to_string(parable.stack_pop())
        if os.path.exists(name):
            os.remove(name)
    elif opcode == 3008:
        name = parable.slice_to_string(parable.stack_pop())
        if os.path.exists(name):
            stack_push(-1, TYPE_FLAG)
        else:
            stack_push(0, TYPE_FLAG)
    elif opcode == 4000:
        name = parable.slice_to_string(parable.stack_pop())
        print name
        if os.path.exists(name):
            lines = parable.condense_lines(open(name).readlines())
            for l in lines:
                s = rewrite(l)
                print s
                slice = parable.request_slice()
                parable.interpret(parable.compile(s, slice), opcodes)
    return offset
Exemple #13
0
def evaluate(s):
    parable.interpret(parable.compile(s), opcodes)
Exemple #14
0
    bootstrap(snapshot)


# -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

if __name__ == '__main__':
    sys.stdout.write("Content-type: text/html\n\n")

    setup_environment()
    code = form.getvalue("code", "")
    message = code.replace("\\\r\n", " ")
    message = message.replace("\\\n", " ")
    f = parable.condense_lines(message.split("\n"))
    for line in f:
        if len(line) > 0:
            s = parable.compile(line, parable.request_slice())
            parable.interpret(s)

    with open('template.html') as file:
        template = file.read()

    stack = dump_stack()
    errors = dump_errors()
    dict = dump_dict()

    template = template.replace('{{code}}', code)
    template = template.replace('{{stack}}', stack)
    template = template.replace('{{errors}}', errors)
    template = template.replace('{{dict}}', dict)

    shot = encode_snapshot(compress_snapshot(create_snapshot()))
Exemple #15
0
        pass

    while 1 == 1:
        display(height, width)

        try:
            src = get_input()
        except:
            sys.stdout.write("\n")
            exit()

        cmd = ' '.join(src.split())

        if cmd == ':q':
            exit()
        elif cmd == ':r':
            revert()
            parable.parse_bootstrap(open('stdlib.p').readlines())
            parable.collect_garbage()
        elif cmd[0:2] == ':i':
            load_file(cmd[3:])
        else:
            if len(src) >= 1:
                try:
                    parable.interpret(parable.compile(src, parable.request_slice()))
                except:
                    sys.stdout.write("\n")
                    pass

        sys.stdout.flush()