Way, *way* behind, but here's my current thinking. Note that a good chunk of
these are as yet blank--I'm running out of caffeine right now. (More to come,
though, but I've waited too long as it is to type in and figure out some of this stuff)

Here's a list of python's opcodes and the translation to parrot
opcodes. Python's a stack-based system, but if its stack usage is
small enough, which generally it is, that can be directly translated
into operations on registers with no stack usage. I'm still up in the
air as to whether any stack usage will actually be necessary or not.

We may well want to implement a 'fake stack', that is use the P16-P31
as a 16 item stack, with one of the I registers as a "stack pointer",
overflowing the extras somewhere. (Maybe)

The translation for a number of the python ops depends on whether
we're going with runtime stack action or compile-time stack->register
translations. In the following list, python ops are uppercase, with
the parrot op after the colon, probably with some descriptive
text. Where there are alternatives then the stack case is first, with
the register case second, divided by a pipe. (I probably ought to
format this as a table but, well, it's ASCII)

For ops that take a parameter, the parameter name is in lower
case. These are part of the op stream in the python bytecode.

STOP_CODE: end

POP_TOP: restore $Px | noop

ROT_TWO: rotate_up 1 | noop

ROT_THREE: rotate_up 2 | noop

ROT_FOUR: rotate_up 3 | noop.

DUP_TOP: lookback Px, 0;save Px | noop

UNARY_POSITIVE: restore $Px; abs $Px; save $Px | abs $Px

UNARY_NEGATIVE: 

UNARY_NOT:

UNARY_CONVERT: restore $Px; set $Sx, $Px;set $Px, $Sx; save $Px | 
               $Sx = $Px; $Px = $Sx

UNARY_INVERT:

GET_ITER:

BINARY_POWER: restore $Px; restore $Py; new $Pz, Undef; $Pz = $Py ** $Px; save $Pz
            | new $Pz, Undef; $Pz = $Py ** $Px

BINARY_MULTIPLY: restore $Px; restore $Py; new $Pz, Undef; $Pz = $Py * $Px; save $Pz
            | new $Pz, Undef; $Pz = $Py * $Px

BINARY_DIVIDE: restore $Px; restore $Py; new $Pz, Undef; $Pz = $Px / $Py; save $Pz
            | new $Pz, Undef; $Pz = $Py / $Px

BINARY_FLOOR_DIVIDE:

BINARY_TRUE_DIVIDE:

BINARY_MODULO: restore $Px; restore $Py; new $Pz, Undef; $Pz = $Py % $Px; save $Pz
            | new $Pz, Undef; $Pz = $Py % $Px

BINARY_ADD: restore $Px; restore $Py; new $Pz, Undef; $Pz = $Py + $Px; save $Pz
            | new $Pz, Undef; $Pz = $Py + $Px

BINARY_SUBTRACT: restore $Px; restore $Py; new $Pz, Undef; $Pz = $Py - $Px; save $Pz
            | new $Pz, Undef; $Pz = $Py - $Px

BINARY_SUBSCR: restore $Px; restore $Py; new $Pz, Undef; $Pz = $Py[$Px]; save $Pz
            | new $Pz, Undef; $Pz = $Py[$Px]

BINARY_LSHIFT: restore $Px; restore $Py; new $Pz, Undef; $Pz = $Py << $Px; save $Pz
            | new $Pz, Undef; $Pz = $Py << $Px

BINARY_RSHIFT: restore $Px; restore $Py; new $Pz, Undef; $Pz = $Py >> $Px; save $Pz
            | new $Pz, Undef; $Pz = $Py >> $Px

BINARY_AND: restore $Px; restore $Py; new $Pz, Undef; $Pz = $Py & $Px; save $Pz
            | new $Pz, Undef; $Pz = $Py & $Px

BINARY_XOR: restore $Px; restore $Py; new $Pz, Undef; $Pz = $Py & $Px; save $Pz
            | new $Pz, Undef; $Pz = xor $Py, $Px

BINARY_OR: restore $Px; restore $Py; new $Pz, Undef; $Pz = $Py & $Px; save $Pz
            | new $Pz, Undef; $Pz = or $Py, $Px

INPLACE_POWER: restore $Px; restore $Py; $Px = $Py ** $Px; save $Px |
               $Px = $Px ** $Py

INPLACE_MULTIPLY: restore $Px; restore $Py; $Px = $Py ** $Px; save $Px |
               $Px = $Px * $Py

INPLACE_DIVIDE: restore $Px; restore $Py; $Px = $Py ** $Px; save $Px |
               $Px = $Px / $Py

INPLACE_FLOOR_DIVIDE:

INPLACE_TRUE_DIVIDE:

INPLACE_MODULO: restore $Px; restore $Py; $Px = $Py ** $Px; save $Px |
               $Px = $Px % $Py

INPLACE_ADD: restore $Px; restore $Py; $Px = $Py ** $Px; save $Px |
               $Px = $Px + $Py

INPLACE_SUBTRACT: restore $Px; restore $Py; $Px = $Py ** $Px; save $Px |
               $Px = $Px - $Py

INPLACE_LSHIFT: restore $Px; restore $Py; $Px = $Py ** $Px; save $Px |
               $Px = $Px << $Py

INPLACE_RSHIFT: restore $Px; restore $Py; $Px = $Py ** $Px; save $Px |
               $Px = $Px >> $Py

INPLACE_AND: restore $Px; restore $Py; $Px = $Py ** $Px; save $Px |
               $Px = $Px & $Py

INPLACE_OR: restore $Px; restore $Py; $Px = $Py ** $Px; save $Px |
               $Px = $Px | $Py

INPLACE_XOR: restore $Px; restore $Py; $Px = $Py ** $Px; save $Px |
               $Px = $Px ^ $Py

SLICE+0:

SLICE+1:

SLICE+2:

SLICE+3:

STORE_SLICE+0:

STORE_SLICE+1:

STORE_SLICE+2:

STORE_SLICE+3:

DELETE_SLICE+0:

DELETE_SLICE+1:

DELETE_SLICE+2:

DELETE_SLICE+3:

STORE_SUBSCR:

DELETE_SUBSCR:

PRINT_EXPR: 

PRINT_ITEM: restore Px; print Px | print Px

PRINT_ITEM_TO: restore Px; restore Py; print Px, Py | print Px, Py

PRINT_NEWLINE: print "\n"

PRINT_NEWLINE_TO: restore Px; print Px, "\n" | print Px, "\n"

BREAK_LOOP:

CONTINUE_LOOP:

LOAD_LOCALS:

RETURN_VALUE: 

YIELD_VALUE:

IMPORT_STAR:

EXEC_STMT:

POP_BLOCK:

END_FINALLY:

BUILD_CLASS:

STORE_NAME:

DELETE_NAME:

UNPACK_SEQUENCE

DUP_TOPX:

STORE_ATTR:

DELETE_ATTR:

STORE_GLOBAL:

DELETE_GLOBAL:

LOAD_CONST:

LOAD_NAME:

BUILD_TUPLE:

BUILD_LIST:

BUILD_MAP:

LOAD_ATTR:

COMPARE_OP:

IMPORT_NAME:

IMPORT_FROM:

JUUMP_FORWARD delta: branch delta

JUMP_IF_TRUE delta: lookback Px, 0; if Px, delta | if Px, delta 

JUMP_IF_FALSE delta: lookback Px, 0; unless Px, delta | unless Px, delta 

JUMP_ABSOLUTE target: jump target

FOR_ITER:

LOAD_GLOBAL:

SETUP_LOOP:

SETUP_EXCEPT:

SETUP_FINALLY:

LOAD_FAST:

STORE_FAST:

DELETE_FAST:

LOAD_CLOSURE:

LOAD_DEREF:

STORE_DEREF:

SET_LINENO:

RAISE_VARARGS:

CALL_FUNCTION:

MAKE_FUNCTION:

MAKE_CLOSURE:

BUILD_SLICE:

EXTENDED_ARG:

CALL_FUNCTION_VAR:

CALL_FUNCTION_KW:

CALL_FUNCTION_VAR_KW:

-- 
                                Dan

--------------------------------------it's like this-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even 
                                      teddy bears get drunk

Reply via email to