{"modulePath":"github.com/raff/gpython","version":"v0.0.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package vm\n\nEvaluate opcodes\n\n### Opcodes from opcodes.h {#hdr-Opcodes_from_opcodes_h}\n\nPython virtual machine\n\n## Constants\n\n```go\nconst (\n\tPyCmp_LT = iota\n\tPyCmp_LE\n\tPyCmp_EQ\n\tPyCmp_NE\n\tPyCmp_GT\n\tPyCmp_GE\n\tPyCmp_IN\n\tPyCmp_NOT_IN\n\tPyCmp_IS\n\tPyCmp_IS_NOT\n\tPyCmp_EXC_MATCH\n\tPyCmp_BAD\n)\n```\nRich comparison opcodes\n\n## Functions\n\n```go\nfunc EvalCode(co *py.Code, globals, locals py.StringDict) (py.Object, error)\n```\n\n```go\nfunc EvalCodeEx(co *py.Code, globals, locals py.StringDict, args []py.Object, kws py.StringDict, defs []py.Object, kwdefs py.StringDict, closure py.Tuple) (retval py.Object, err error)\n```\n\n```go\nfunc EvalGetFuncDesc(fn py.Object) string\n```\nEvalGetFuncDesc returns a description of the arguments for the function object\n\n```go\nfunc EvalGetFuncName(fn py.Object) string\n```\nEvalGetFuncName returns the name of the function object passed in\n\n```go\nfunc Run(globals, locals py.StringDict, code *py.Code, closure py.Tuple) (res py.Object, err error)\n```\nRun the virtual machine on a Code object\n\n### Any parameters are expected to have been decoded into locals {#hdr-Any_parameters_are_expected_to_have_been_decoded_into_locals}\n\nReturns an Object and an error.  The error will be a py.ExceptionInfo\n\nThis is the equivalent of PyEval\\_EvalCode with closure support\n\n```go\nfunc RunFrame(frame *py.Frame) (res py.Object, err error)\n```\nRun the virtual machine on a Frame object\n\nFIXME figure out how we are going to signal exceptions!\n\nReturns an Object and an error.  The error will be a py.ExceptionInfo\n\nThis is the equivalent of PyEval\\_EvalFrame\n\n## Types\n\n```go\ntype OpCode byte\n```\nType for OpCodes\n\n```go\nconst (\n\tPOP_TOP     OpCode = 1\n\tROT_TWO     OpCode = 2\n\tROT_THREE   OpCode = 3\n\tDUP_TOP     OpCode = 4\n\tDUP_TOP_TWO OpCode = 5\n\tNOP         OpCode = 9\n\n\tUNARY_POSITIVE OpCode = 10\n\tUNARY_NEGATIVE OpCode = 11\n\tUNARY_NOT      OpCode = 12\n\n\tUNARY_INVERT OpCode = 15\n\n\tBINARY_POWER OpCode = 19\n\n\tBINARY_MULTIPLY OpCode = 20\n\n\tBINARY_MODULO        OpCode = 22\n\tBINARY_ADD           OpCode = 23\n\tBINARY_SUBTRACT      OpCode = 24\n\tBINARY_SUBSCR        OpCode = 25\n\tBINARY_FLOOR_DIVIDE  OpCode = 26\n\tBINARY_TRUE_DIVIDE   OpCode = 27\n\tINPLACE_FLOOR_DIVIDE OpCode = 28\n\tINPLACE_TRUE_DIVIDE  OpCode = 29\n\n\tSTORE_MAP        OpCode = 54\n\tINPLACE_ADD      OpCode = 55\n\tINPLACE_SUBTRACT OpCode = 56\n\tINPLACE_MULTIPLY OpCode = 57\n\n\tINPLACE_MODULO OpCode = 59\n\tSTORE_SUBSCR   OpCode = 60\n\tDELETE_SUBSCR  OpCode = 61\n\n\tBINARY_LSHIFT    OpCode = 62\n\tBINARY_RSHIFT    OpCode = 63\n\tBINARY_AND       OpCode = 64\n\tBINARY_XOR       OpCode = 65\n\tBINARY_OR        OpCode = 66\n\tINPLACE_POWER    OpCode = 67\n\tGET_ITER         OpCode = 68\n\tPRINT_EXPR       OpCode = 70\n\tLOAD_BUILD_CLASS OpCode = 71\n\tYIELD_FROM       OpCode = 72\n\n\tINPLACE_LSHIFT OpCode = 75\n\tINPLACE_RSHIFT OpCode = 76\n\tINPLACE_AND    OpCode = 77\n\tINPLACE_XOR    OpCode = 78\n\tINPLACE_OR     OpCode = 79\n\tBREAK_LOOP     OpCode = 80\n\tWITH_CLEANUP   OpCode = 81\n\n\tRETURN_VALUE OpCode = 83\n\tIMPORT_STAR  OpCode = 84\n\n\tYIELD_VALUE OpCode = 86\n\tPOP_BLOCK   OpCode = 87\n\tEND_FINALLY OpCode = 88\n\tPOP_EXCEPT  OpCode = 89\n\n\tHAVE_ARGUMENT OpCode = 90 // OpCodes from here have an argument:\n\n\tSTORE_NAME      OpCode = 90 // Index in name list\n\tDELETE_NAME     OpCode = 91 // \"\"\n\tUNPACK_SEQUENCE OpCode = 92 // Number of sequence items\n\tFOR_ITER        OpCode = 93\n\tUNPACK_EX       OpCode = 94 // Num items before variable part + (Num items after variable part \u003c\u003c 8)\n\n\tSTORE_ATTR    OpCode = 95 // Index in name list\n\tDELETE_ATTR   OpCode = 96 // \"\"\n\tSTORE_GLOBAL  OpCode = 97 // \"\"\n\tDELETE_GLOBAL OpCode = 98 // \"\"\n\n\tLOAD_CONST  OpCode = 100 // Index in const list\n\tLOAD_NAME   OpCode = 101 // Index in name list\n\tBUILD_TUPLE OpCode = 102 // Number of tuple items\n\tBUILD_LIST  OpCode = 103 // Number of list items\n\tBUILD_SET   OpCode = 104 // Number of set items\n\tBUILD_MAP   OpCode = 105 // Always zero for now\n\tLOAD_ATTR   OpCode = 106 // Index in name list\n\tCOMPARE_OP  OpCode = 107 // Comparison operator\n\tIMPORT_NAME OpCode = 108 // Index in name list\n\tIMPORT_FROM OpCode = 109 // Index in name list\n\n\tJUMP_FORWARD         OpCode = 110 // Number of bytes to skip\n\tJUMP_IF_FALSE_OR_POP OpCode = 111 // Target byte offset from beginning of code\n\tJUMP_IF_TRUE_OR_POP  OpCode = 112 // \"\"\n\tJUMP_ABSOLUTE        OpCode = 113 // \"\"\n\tPOP_JUMP_IF_FALSE    OpCode = 114 // \"\"\n\tPOP_JUMP_IF_TRUE     OpCode = 115 // \"\"\n\n\tLOAD_GLOBAL OpCode = 116 // Index in name list\n\n\tCONTINUE_LOOP OpCode = 119 // Start of loop (absolute)\n\tSETUP_LOOP    OpCode = 120 // Target address (relative)\n\tSETUP_EXCEPT  OpCode = 121 // \"\"\n\tSETUP_FINALLY OpCode = 122 // \"\"\n\n\tLOAD_FAST   OpCode = 124 // Local variable number\n\tSTORE_FAST  OpCode = 125 // Local variable number\n\tDELETE_FAST OpCode = 126 // Local variable number\n\n\tRAISE_VARARGS OpCode = 130 // Number of raise arguments (1, 2 or 3)\n\t// CALL_FUNCTION_XXX opcodes defined below depend on this definition\n\tCALL_FUNCTION OpCode = 131 // #args + (#kwargs\u003c\u003c8)\n\tMAKE_FUNCTION OpCode = 132 // #defaults + #kwdefaults\u003c\u003c8 + #annotations\u003c\u003c16\n\tBUILD_SLICE   OpCode = 133 // Number of items\n\n\tMAKE_CLOSURE OpCode = 134 // same as MAKE_FUNCTION\n\tLOAD_CLOSURE OpCode = 135 // Load free variable from closure\n\tLOAD_DEREF   OpCode = 136 // Load and dereference from closure cell\n\tSTORE_DEREF  OpCode = 137 // Store into cell\n\tDELETE_DEREF OpCode = 138 // Delete closure cell\n\n\t// The next 3 opcodes must be contiguous and satisfy\n\t// (CALL_FUNCTION_VAR - CALL_FUNCTION) \u0026 3 == 1\n\tCALL_FUNCTION_VAR    OpCode = 140 // #args + (#kwargs\u003c\u003c8)\n\tCALL_FUNCTION_KW     OpCode = 141 // #args + (#kwargs\u003c\u003c8)\n\tCALL_FUNCTION_VAR_KW OpCode = 142 // #args + (#kwargs\u003c\u003c8)\n\n\tSETUP_WITH OpCode = 143\n\n\t// Support for opargs more than 16 bits long\n\tEXTENDED_ARG OpCode = 144\n\n\tLIST_APPEND OpCode = 145\n\tSET_ADD     OpCode = 146\n\tMAP_ADD     OpCode = 147\n\n\tLOAD_CLASSDEREF OpCode = 148 // New in Python 3.4\n)\n```\n\n```go\nfunc (op OpCode) HAS_ARG() bool\n```\nIf op has an argument\n\n```go\nfunc (i OpCode) String() string\n```\n\n```go\ntype Vm struct {\n\t// contains filtered or unexported fields\n}\n```\nVirtual machine state\n\n```go\nfunc (vm *Vm) AddTraceback(exc *py.ExceptionInfo)\n```\nAdds a traceback to the exc passed in for the current vm state\n\n```go\nfunc (vm *Vm) Call(argc int32, starArgs py.Object, starKwargs py.Object) error\n```\nImplements a function call - see CALL\\_FUNCTION for a description of how the arguments are arranged.\n\n### Optionally pass in args and kwargs {#hdr-Optionally_pass_in_args_and_kwargs}\n\nThe result is put on the stack\n\n```go\nfunc (vm *Vm) CheckException()\n```\nCheck for an exception (panic)\n\nMust be called as a defer function\n\n```go\nfunc (vm *Vm) CheckExceptionRecover(r interface{})\n```\nCheck for an exception (panic)\n\nShould be called with the result of recover\n\n```go\nfunc (vm *Vm) DROP()\n```\n\n```go\nfunc (vm *Vm) DROPN(n int)\n```\n\n```go\nfunc (vm *Vm) EXTEND(items py.Tuple)\n```\nPush items to top of vm stack\n\n```go\nfunc (vm *Vm) EXTEND_REVERSED(items py.Tuple)\n```\nPush items to top of vm stack in reverse order\n\n```go\nfunc (vm *Vm) FOURTH() py.Object\n```\n\n```go\nfunc (vm *Vm) PEEK(n int) py.Object\n```\n\n```go\nfunc (vm *Vm) POP() py.Object\n```\nPop from top of vm stack\n\n```go\nfunc (vm *Vm) PUSH(obj py.Object)\n```\nPush to top of vm stack\n\n```go\nfunc (vm *Vm) SECOND() py.Object\n```\n\n```go\nfunc (vm *Vm) SET_FOURTH(v py.Object)\n```\n\n```go\nfunc (vm *Vm) SET_SECOND(v py.Object)\n```\n\n```go\nfunc (vm *Vm) SET_THIRD(v py.Object)\n```\n\n```go\nfunc (vm *Vm) SET_TOP(v py.Object)\n```\n\n```go\nfunc (vm *Vm) SET_VALUE(n int, v py.Object)\n```\n\n```go\nfunc (vm *Vm) STACK_LEVEL() int\n```\nStack operations\n\n```go\nfunc (vm *Vm) SetException(exception py.Object)\n```\nSet an exception in the VM\n\nThe exception must be a valid exception instance (eg as returned by py.MakeException)\n\nIt sets vm.curexc.\\* and sets vm.why to whyException\n\n```go\nfunc (vm *Vm) THIRD() py.Object\n```\n\n```go\nfunc (vm *Vm) TOP() py.Object\n```\n\n```go\nfunc (vm *Vm) UnwindBlock(frame *py.Frame, block *py.TryBlock)\n```\nUnwinds the stack for a block\n\n```go\nfunc (vm *Vm) UnwindExceptHandler(frame *py.Frame, block *py.TryBlock)\n```\nUnwinds the stack in the presence of an exception\n\n","path":"github.com/raff/gpython/vm","name":"vm","synopsis":"Evaluate opcodes","isRedistributable":true}
