# Path: pigeon/xerblin/btree.py
# def fill_tree(node, items):
#     '''
#     Add the (key, value) pairs in items to a btree in a balanced way.
# 
#     You can balance a tree like so:
# 
#         tree = fill_tree((), items(tree))
# 
#     This iterates through the tree and returns a new, balanced tree from
#     its contents.
#     '''
#     for key, value in _yield_balanced(sorted(items)):
#         node = insert(node, key, value)
#     return node
# 
# def items(node):
#     '''
#     Iterate in order over the (key, value) pairs in a tree.
#     '''
#     if not node:
#         return
# 
#     key, value, lower, higher = node
#     
#     for kv in items(lower):
#         yield kv
#     
#     yield key, value
#     
#     for kv in items(higher):
#         yield kv
# 
# Path: pigeon/xerblin/library.py
# def assemble((stack, dictionary)):
# def compile((stack, dictionary)):
# def dup((stack, dictionary)):
# def swap((stack, dictionary)):
# def pick((stack, dictionary)):
# def tuck((stack, dictionary)):
# def drop((stack, dictionary)):
# def over((stack, dictionary)):
# def lookup(interpreter):
# def inscribe((stack, dictionary)):
# def NewSeqWord((stack, dictionary)):
# def NewLoopWord((stack, dictionary)):
# def NewBranchWord((stack, dictionary)):
# def NewEnstackener((stack, dictionary)):
# def add((stack, dictionary)):
# def sub((stack, dictionary)):
# def mul((stack, dictionary)):
# def pickle(interpreter):
# def unpickle(interpreter):
# def rebalance((stack, dictionary)):
# def view(interpreter):
# def listwords(interpreter):
#     HEX = assemble_raw(source)
# 
# Path: pigeon/xerblin/base.py
# def interpret(I, command):
#     '''
#     Given an interpreter and a string command, interpret that string on
#     the interpreter and return the modified interpreter.
#     '''
#     for word in command:
# 
#         # Is it an integer?
#         try:
#             literal = int(word)
#         except ValueError:
# 
#             # Is it a float?
#             try:
#                 literal = float(word)
#             except ValueError:
# 
#                 # Is it a string literal?
#                 if word.startswith('"') and word.endswith('"'):
#                     literal = word[1:-1]
# 
#                 # Nope, it must be a command word.
#                 else:
#                     # Interpret the word.
#                     func = get(I[1], word)
#                     I = apply_func(I, func)
#                     continue
# 
#         # A literal was found, push it onto the stack.
#         I = (literal, I[0]), I[1]
# 
#     return I


import pickle, pprint, StringIO, os
from pigeon.xerblin.btree import fill_tree, items
from pigeon.xerblin.library import words
from pigeon.xerblin.base import interpret
    from xerblin.btree import items
        '''
        if initial is None:
            initial = ROOT

        if save_file is None:
            save_file = StringIO.StringIO()

        elif isinstance(save_file, basestring):
            save_file = open(save_file, 'w')

        # If save_file isn't None or a string or unicode object then we
        # assume it's a file-like object suitable for the Pickler.
        assert hasattr(save_file, 'write'), repr(save_file)

        self.serializer = Serializer(initial, save_file)
        self._view = view
        self.setCurrentState(initial)

    def view(self, state):
        self._view(state)

    def step(self, command):
        '''
        Run one command, a list of strings, on the interpreter then save
        the command and resulting new interpreter to the serialized
        stream and call the view function on the new interpreter.
        '''
        I = self.getCurrentState()

        # Run the command.

# Path: pigeon/xerblin/btree.py
# def fill_tree(node, items):
#     '''
#     Add the (key, value) pairs in items to a btree in a balanced way.
# 
#     You can balance a tree like so:
# 
#         tree = fill_tree((), items(tree))
# 
#     This iterates through the tree and returns a new, balanced tree from
#     its contents.
#     '''
#     for key, value in _yield_balanced(sorted(items)):
#         node = insert(node, key, value)
#     return node
# 
# def items(node):
#     '''
#     Iterate in order over the (key, value) pairs in a tree.
#     '''
#     if not node:
#         return
# 
#     key, value, lower, higher = node
#     
#     for kv in items(lower):
#         yield kv
#     
#     yield key, value
#     
#     for kv in items(higher):
#         yield kv
# 
# Path: pigeon/xerblin/library.py
# def assemble((stack, dictionary)):
# def compile((stack, dictionary)):
# def dup((stack, dictionary)):
# def swap((stack, dictionary)):
# def pick((stack, dictionary)):
# def tuck((stack, dictionary)):
# def drop((stack, dictionary)):
# def over((stack, dictionary)):
# def lookup(interpreter):
# def inscribe((stack, dictionary)):
# def NewSeqWord((stack, dictionary)):
# def NewLoopWord((stack, dictionary)):
# def NewBranchWord((stack, dictionary)):
# def NewEnstackener((stack, dictionary)):
# def add((stack, dictionary)):
# def sub((stack, dictionary)):
# def mul((stack, dictionary)):
# def pickle(interpreter):
# def unpickle(interpreter):
# def rebalance((stack, dictionary)):
# def view(interpreter):
# def listwords(interpreter):
#     HEX = assemble_raw(source)
# 
# Path: pigeon/xerblin/base.py
# def interpret(I, command):
#     '''
#     Given an interpreter and a string command, interpret that string on
#     the interpreter and return the modified interpreter.
#     '''
#     for word in command:
# 
#         # Is it an integer?
#         try:
#             literal = int(word)
#         except ValueError:
# 
#             # Is it a float?
#             try:
#                 literal = float(word)
#             except ValueError:
# 
#                 # Is it a string literal?
#                 if word.startswith('"') and word.endswith('"'):
#                     literal = word[1:-1]
# 
#                 # Nope, it must be a command word.
#                 else:
#                     # Interpret the word.
#                     func = get(I[1], word)
#                     I = apply_func(I, func)
#                     continue
# 
#         # A literal was found, push it onto the stack.
#         I = (literal, I[0]), I[1]
# 
#     return I


# Path: pigeon/xerblin/world.py
import pickle, pprint, StringIO, os
from pigeon.xerblin.btree import fill_tree, items
from pigeon.xerblin.library import words
from pigeon.xerblin.base import interpret
    from xerblin.btree import items

        '''
        if initial is None:
            initial = ROOT

        if save_file is None:
            save_file = StringIO.StringIO()

        elif isinstance(save_file, basestring):
            save_file = open(save_file, 'w')

        # If save_file isn't None or a string or unicode object then we
        # assume it's a file-like object suitable for the Pickler.
        assert hasattr(save_file, 'write'), repr(save_file)

        self.serializer = Serializer(initial, save_file)
        self._view = view
        self.setCurrentState(initial)

    def view(self, state):
        self._view(state)

    def step(self, command):
        '''
        Run one command, a list of strings, on the interpreter then save
        the command and resulting new interpreter to the serialized
        stream and call the view function on the new interpreter.
        '''
        I = self.getCurrentState()

        # Run the command.

        I = interpret(I, command)