Exemple #1
0
def dump_dict():
    """display named items"""
    html = "<table>"
    l = ''
    i = 0
    for w in parable.dictionary_names():
        wx = '<pre>' + w.replace('<', '&lt;').replace('>', '&gt;') + '</pre>'

        slice = parable.dictionary_slices()[i]
        cell, type = parable.fetch(slice, 0)
        size = parable.memory_size[slice]
        if type == parable.TYPE_REMARK:
            comment = parable.slice_to_string(cell)
            l = l + '<tr>'
            l = l + '<td width="10%">' + str(slice) + '</td>' + '<td>' + wx
            cell, type = parable.fetch(slice, size)
            if type == parable.TYPE_REMARK:
                l = l + '<br>' + parable.slice_to_string(cell)
            l = l + '</td>'
            l = l + '<td width="20%"><pre>' + comment + '</pre></td></tr>\n'
        else:
            l = l + '<tr><td width-"10%">' + str(slice) + '</td>'
            l = l + '<td colspan="3">' + wx + '</td></tr>\n'
        i = i + 1
    html = html + l
    html = html + "</table>"
    return html
Exemple #2
0
def dump_dict():
    """display named items"""
    l = ''
    for w in parable.dictionary_names():
        l = l + w + ' '
    sys.stdout.write(l)
    sys.stdout.write("\n")
Exemple #3
0
def dump_dict():
    """display named items"""
    html = "<table>"
    l = ''
    i = 0
    for w in parable.dictionary_names():
        wx = '<pre>' + w.replace('<', '&lt;').replace('>', '&gt;') + '</pre>'

        slice = parable.dictionary_slices()[i]
        cell, type = parable.fetch(slice, 0)
        size = parable.memory_size[slice]
        if type == parable.TYPE_REMARK:
            comment = parable.slice_to_string(cell)
            l = l + '<tr>'
            l = l + '<td width="10%">' + str(slice) + '</td>' + '<td>' + wx
            cell, type = parable.fetch(slice, size)
            if type == parable.TYPE_REMARK:
                l = l + '<br>' + parable.slice_to_string(cell)
            l = l + '</td>'
            l = l + '<td width="20%"><pre>' + comment + '</pre></td></tr>\n'
        else:
            l = l + '<tr><td width-"10%">' + str(slice) + '</td>'
            l = l + '<td colspan="3">' + wx + '</td></tr>\n'
        i = i + 1
    html = html + l
    html = html + "</table>"
    return html
Exemple #4
0
def dump_dict():
    """display named items"""
    l = ''
    for w in parable.dictionary_names():
        l = l + w + ' '
    sys.stdout.write(l)
    sys.stdout.write("\n")
Exemple #5
0
def opcode_display_words():
    print(' '.join(parable.dictionary_names()))
Exemple #6
0
def tab_completion(text, state):
    options = [x for x in parable.dictionary_names() if x.startswith(text)]
    try:
        return options[state]
    except IndexError:
        return None
Exemple #7
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 #8
0
def opcode_display_words():
    print(' '.join(parable.dictionary_names()))
Exemple #9
0
def tab_completion(text, state):
    options = [x for x in parable.dictionary_names() if x.startswith(text)]
    try:
        return options[state]
    except IndexError:
        return None