예제 #1
0
def compile_word(word, context):
    """
    Compile a single word.
    """

    if word in context:
        # We've seen this word before, so either compile a call to it or
        # include it verbatim if it's inlined.
        pc, ucode = context[word]
        if pc is None:
            return ucode
        else:
            return call(pc)
    else:
        # Haven't seen this word, maybe it's a builtin?
        return builtin(word)
예제 #2
0
def bootloader(start):
    """
    Set up stacks and registers, and then jump to a starting point. After
    things are finished, pop some of the stack to registers, and halt with an
    illegal opcode.
    """

    # First things first. Set up the call stack. Currently hardcoded.
    ucode = assemble(SET, Z, 0xd000)
    # Hardcode the location of the tail, and call.
    ucode += call(start)
    # And we're off! As soon as we come back down, pop I and J so we can see
    # them easily.
    ucode += assemble(SET, I, POP)
    ucode += assemble(SET, J, POP)
    # Finish off with an illegal opcode.
    ucode += pack(">H", 0x0)
    return ucode