Skip to content

GoPy

Specification series for gopy — a port of CPython's Python/ runtime to Go with 100% behavioural compatibility.

Port of CPython’s Python/ (and related Objects/, Parser/) runtime to Go. Each spec file maps directly to one or more CPython C source files and defines the Go package, types, and functions that replace them.

#SpecTopic
16001600_gopy_overviewgopy overview
16011601_gopy_naminggopy naming conventions
16021602_gopy_filemapgopy file map
16031603_gopy_roadmapgopy roadmap
16041604_gopy_arenagopy arena spec
16051605_gopy_pythreadgopy pythread spec
16061606_gopy_pysyncgopy pysync spec
16071607_gopy_hashsecretgopy hash secret spec
16111611_gopy_errorsgopy errors
16131613_gopy_gcgopy gc, weakrefs, finalizers
16201620_gopy_compile_pipelinegopy compile pipeline
16211621_gopy_bytecodes_dslgopy bytecodes DSL
16221622_gopy_lifecyclegopy lifecycle
16241624_gopy_pythonrungopy pythonrun
16251625_gopy_compile_testinggopy v0.5 testing strategy
16261626_gopy_codegengopy codegen
16271627_gopy_flowgraphgopy flowgraph
16281628_gopy_assemblegopy assemble
16291629_gopy_compile_goldensgopy compile golden tests
16301630_gopy_vm_overviewgopy vm overview
16351635_gopy_intrinsicsgopy intrinsics
16361636_gopy_eval_loopgopy eval loop
16371637_gopy_framegopy frame
16381638_gopy_stackrefgopy stackref
16391639_gopy_eval_gilgopy eval GIL
16401640_gopy_parser_overviewgopy parser overview
16411641_gopy_lexer_tokenizergopy lexer tokenizer
16421642_gopy_pegengopy pegen
16431643_gopy_parser_errorsgopy parser errors
16441644_gopy_string_parsergopy string parser
16451645_gopy_myreadlinegopy myreadline
16511651_gopy_modulesgopy modules
16601660_gopy_strings_numbersgopy strings and numbers
16611661_gopy_hashgopy hash
16621662_gopy_hamtgopy HAMT
16631663_gopy_contextgopy context
16641664_gopy_timegopy time
16651665_gopy_tokenizegopy tokenize
16681668_gopy_runtime_helpersgopy runtime helpers
16701670_gopy_objects_overviewgopy objects overview
16711671_gopy_object_protocolgopy object protocol
16721672_gopy_typegopy type
16731673_gopy_longgopy long
16741674_gopy_float_complexgopy float complex
16751675_gopy_bool_nonegopy bool none
16761676_gopy_bytesgopy bytes
16771677_gopy_unicodegopy unicode
16781678_gopy_tuplegopy tuple
16791679_gopy_listgopy list
16801680_gopy_dictgopy dict
16811681_gopy_setgopy set
16821682_gopy_slice_rangegopy slice range
16831683_gopy_abstractgopy abstract
16841684_gopy_callgopy call
16851685_gopy_descr_methodgopy descr method
16861686_gopy_exceptionsgopy exceptions
16871687_gopy_code_frame_gengopy code frame gen
16881688_gopy_module_miscgopy module misc
16891689_gopy_obj_miscgopy obj misc
16901690_gopy_marshalgopy marshal
16911691_gopy_importgopy import
16921692_gopy_codecsgopy codecs
16931693_gopy_vm_remaininggopy vm remaining
gopy overviewTop-level overview of the gopy project. Ports CPython's Python/ runtime to Go with 100% behavioural compatibility.
8 min
gopy naming conventionsMechanical translation rules for converting CPython C identifiers to Go-idiomatic names while preserving 1:1 semantics.
7 min
gopy file mapOne-line per CPython source file, with the target Go package path and a short purpose note. Canonical lookup table for porters.
6 min
gopy roadmapPhased milestone plan from v0.0.1 (parser smoke) to v1.0 (full CPython parity). Defines the ordering of subsystem ports and the gating criteria for each release.
9 min
gopy arena specFaithful port of cpython/Python/pyarena.c to gopy/arena. Bump-allocator with linked-block layout used by the compiler pipeline for AST and scratch buffers.
4 min
gopy pythread specPort of cpython/Python/thread.c to gopy/pythread. Thread create, join, ident, and stack-size hooks layered over Go's goroutine scheduler. The OS-specific thread_pthread.h / thread_nt.h files are dropped.
3 min
gopy pysync specPort of cpython/Python/lock.c, parking_lot.c, and critical_section.c into the gopy/pysync package. Address-keyed parking, byte-flag PyMutex, PyEvent, PyOnceFlag, RecursiveMutex, RWMutex, SeqLock, and the PEP 703 critical-section stack.
6 min
gopy hash secret specPort of the seed-init half of cpython/Python/bootstrap_hash.c to gopy/hash. PYTHONHASHSEED parsing, the LCG used when a seed is given, and an OS-entropy fallback. The full SipHash-1-3 / FNV / x86_aes hashing land in v0.4.
4 min
gopy errorsPort of cpython/Python/errors.c and the gating subset of cpython/Objects/exceptions.c. Exception types, set/get/clear, raise/chain, normalize.
4 min
gopy gc, weakrefs, finalizersv0.10 cycle GC port. Maps Python/gc.c, Python/gc_gil.c, Python/object_stack.c, Objects/weakrefobject.c onto gopy/gc and objects/weakref. Defines what '100% behavioural compatibility' means when the host runtime is Go (which already collects cycles).
8 min
gopy compile pipelineAST, future flags, symbol table, codegen, flowgraph, assemble. Ports asdl.c, Python-ast.c, ast.c, ast_preprocess.c, ast_unparse.c, future.c, symtable.c, instruction_sequence.c, codegen.c, flowgraph.c, assemble.c, compile.c.
22 min
gopy bytecodes DSLPort of cpython/Tools/cases_generator. Reads Python/bytecodes.c, emits the Go dispatch table at vm/opcodes_gen.go and metadata at compile/opcodes_gen.go.
7 min
gopy lifecyclePort of cpython/Python/pylifecycle.c, preconfig.c, initconfig.c, interpconfig.c, pathconfig.c. Py_Initialize / Py_Finalize and the config plumbing they consume.
4 min
gopy pythonrunPort of cpython/Python/pythonrun.c. PyRun_SimpleString, PyRun_File, the REPL loop, and the .pyc read/write helpers that the lifecycle calls.
2 min
gopy v0.5 testing strategyPer-package test plan covering every checklist item in 1620 (compile pipeline) and 1665 (tokenize). Each entry maps a CPython source range to the Go test that locks parity.
8 min
gopy codegenDetailed port plan for cpython/Python/codegen.c (~6500 lines) to compile/codegen.go. Statement and expression visitors, frame block stack, pattern matching panel, with-statement state machine, deferred annotations, PEP 695 type-parameter codegen, comprehensive test plan.
13 min
gopy flowgraphDetailed port plan for cpython/Python/flowgraph.c (~4200 lines) to compile/flowgraph.go. CFG construction, optimization passes (jump threading, dead-code, const fold, swaptimize, super-instructions), stackdepth, exception handler labelling, comprehensive test plan.
9 min
gopy assembleDetailed port plan for cpython/Python/assemble.c (~800 lines) to compile/assemble.go. Sequence-to-Code conversion, line table varint format, exception table varint format, co_consts/names/varnames/freevars/cellvars layout, fastlocalskinds, comprehensive test plan.
8 min
gopy compile golden testsDisassembly-golden corpus for the v05test gate. Each fixture is a Go-built AST plus a checked-in .golden file with the expected dis.dis output. Refresh via `go test -update`.
5 min
gopy vm overviewTop-level overview of the gopy VM (Tier-1 bytecode interpreter) port. Covers ceval, ceval_macros, ceval_gil, frame, stackrefs, and the bytecodes DSL output. Lives in the 1630-1639 block.
5 min
gopy intrinsicsPort of cpython/Python/intrinsics.c. The CALL_INTRINSIC_1 / CALL_INTRINSIC_2 dispatch tables that back compile-time-emitted runtime helpers (print expr, list-to-tuple, import-star, type-alias).
4 min
gopy eval loopPort of cpython/Python/ceval.c and cpython/Python/ceval_macros.h. The Tier-1 bytecode dispatch loop, exception unwind, generator resume, and call/return trampolines.
8 min
gopy framePort of cpython/Python/frame.c. Frame layout, locals-plus storage, frame chain push/pop, generator frame suspension.
6 min
gopy stackrefPort of cpython/Python/stackrefs.c. Tagged stack reference values, borrow tracking, and the conversion shims between PyObject* and stackref.
4 min
gopy eval gilPort of cpython/Python/ceval_gil.c. The GIL acquire/release protocol, the eval breaker bitfield, signal pending flags, and the gopy-vs-Go-runtime threading mapping.
5 min
gopy parser overviewTop-level overview of the gopy Parser port. Covers the PEG parser, lexer, tokenizer drivers, string literal parser, error helpers, and readline. Lives in the 1640-1645 block of the 1600 spec series.
4 min
gopy lexer and tokenizerPort of cpython/Parser/lexer/ and cpython/Parser/tokenizer/. Lexer state machine, buffer, token emission, and the four tokenizer drivers (file, string, utf8, readline).
5 min
gopy pegenPort of cpython/Parser/pegen.c and the generated cpython/Parser/parser.c. PEG runtime plus the parser table that turns a token stream into an AST.
5 min
gopy parser errors and helpersPort of cpython/Parser/pegen_errors.c, action_helpers.c, peg_api.c, and token.c. SyntaxError text panel, AST construction helpers, and the token table.
4 min
gopy string parserPort of cpython/Parser/string_parser.c. Decodes Python string, bytes, f-string, and t-string literals into AST nodes. Handles escape sequences, prefixes, and f-string interpolation re-entry.
4 min
gopy myreadlinePort of cpython/Parser/myreadline.c. Cross-platform readline shim used by the interactive REPL. Mostly a thin wrapper over the host readline library; gopy substitutes Go-native line editing.
3 min
gopy modulesPort of cpython/Python/bltinmodule.c (subset), sysmodule.c (subset), _warnings.c, and the _contextvars hook. The minimum builtins/sys surface v0.7 needs to ship.
4 min
gopy strings and numbersLocale-independent string and number conversion. Ports pyctype.c, pystrcmp.c, mystrtoul.c, pystrtod.c, dtoa.c, pystrhex.c, pymath.c, pyfpe.c, formatter_unicode.c.
5 min
gopy hashPort of cpython/Python/pyhash.c. SipHash-1-3 plus FNV-1a, secret seed bootstrap from 1607.
2 min
gopy hamtHash Array Mapped Trie immutable mapping. Backs contextvars (1663). Ports cpython/Python/hamt.c byte-for-byte preserving the 5-bit-per-level tree shape.
4 min
gopy contextvarsPEP 567 contextvars. Ports cpython/Python/context.c plus _contextvars.c. Uses the HAMT (1662) as backing store.
4 min
gopy pytimeInternal time utilities. Ports cpython/Python/pytime.c. Provides PyTime_t (int64 nanoseconds), monotonic / perf / wall clocks, double / timespec / timeval conversions, deadline math.
4 min
gopy tokenizePublic TokenizerIter wrapper. Ports Python-tokenize.c. The actual lexer lives in cpython/Parser/tokenizer/ and is covered by the parser spec series.
4 min
gopy runtime helpersTwo small infra ports - getopt.c (CLI option parser used during interpreter init) and hashtable.c (generic _Py_hashtable_t internal hash table). Bundled because each is tiny and self-contained.
5 min
gopy objects overviewTop-level overview of the gopy Objects port. Ports cpython/Objects/ to Go with 100% behavioural compatibility. Lives in the 1670-1689 block of the 1600 spec series.
5 min
gopy object protocolObject interface, Header, VarHeader, refcount, and identity. Mirrors PyObject and PyVarObject in cpython/Include/object.h.
6 min
gopy typeType, slots, MRO, lookup. Mirrors PyTypeObject from cpython/Include/cpython/typeobject.h.
5 min
gopy longPort of cpython/Objects/longobject.c. Arbitrary-precision int with the small-int cache, base-2/8/10/16 parsing, hash, and the full numeric protocol.
3 min
gopy float and complexPort of cpython/Objects/floatobject.c and complexobject.c. IEEE-754 binary64 float with shortest-roundtrip repr, plus the complex builtin used by cmath.
2 min
gopy bool and singletonsPort of cpython/Objects/boolobject.c plus the None and NotImplemented singletons. bool is a subtype of int.
2 min
gopy bytesPort of cpython/Objects/bytesobject.c, bytearrayobject.c, and bytes_methods.c. Immutable bytes plus mutable bytearray with the full string-like method panel.
3 min
gopy unicodePort of cpython/Objects/unicodeobject.c and unicodectype.c. PEP 393 kind-tagged str with the full method surface and Unicode classification tables.
4 min
gopy tuplePort of cpython/Objects/tupleobject.c. Immutable sequence with the empty-tuple singleton and the CPython tuple hash.
2 min
gopy listPort of cpython/Objects/listobject.c. Mutable variable-length sequence with the CPython list_resize growth curve and Timsort.
2 min
gopy dictPort of cpython/Objects/dictobject.c and odictobject.c. Insertion-ordered open-addressing hash table with the CPython probing sequence.
3 min
gopy setPort of cpython/Objects/setobject.c. set and frozenset on the same open-addressing layout as dict, sharing the probing sequence.
2 min
gopy slice and rangePort of cpython/Objects/sliceobject.c and rangeobject.c. The slice and range builtins, plus the Ellipsis singleton.
2 min
gopy abstractPort of cpython/Objects/abstract.c. Cross-type protocol dispatch (PyObject_*, PyNumber_*, PySequence_*, PyMapping_*, PyIter_*) that the bytecode interpreter calls into.
3 min
gopy callPort of cpython/Objects/call.c. Vectorcall fast path, generic call dispatch, argument tuple construction, and the kwargs handling rules.
3 min
gopy descriptor and methodPort of cpython/Objects/descrobject.c, methodobject.c, classobject.c, and funcobject.c. The descriptor protocol (data and non-data), bound methods, builtin function objects, and Python function objects.
3 min
gopy exceptionsPort of cpython/Objects/exceptions.c. The full BaseException hierarchy with the args slot byte-equal to CPython for every constructor.
3 min
gopy code, frame, generatorPort of cpython/Objects/codeobject.c, frameobject.c, genobject.c, and cellobject.c. The four objects the VM thinks in: bytecode, execution frame, generator state machine, and closure cells.
4 min
gopy module and miscPort of cpython/Objects/moduleobject.c, namespaceobject.c, structseq.c, capsule.c, iterobject.c, and enumobject.c. Module, SimpleNamespace, structseq, Capsule, the generic iterator wrappers, and enumerate / reversed.
3 min
gopy objects miscPort of the remaining cpython/Objects/ files. weakref, memoryview, file, picklebuffer, typevar / TypeAliasType, union, GenericAlias, Interpolation / Template, plus the obmalloc stub.
4 min
gopy marshalPort of cpython/Python/marshal.c (2163 lines) to the marshal/ package. Full type-tag dispatch, TYPE_LONG arbitrary-precision encoding, FLAG_REF back-reference dedup, TYPE_CODE read/write, and .pyc file header. Gates the v0.8 milestone.
9 min
gopy importPort of cpython/Python/import.c (4956 lines) and Python/frozen.c (132 lines). Frozen module loader, sys.modules lookup, source and bytecode loaders, builtin module table, and the IMPORT_NAME / IMPORT_FROM / IMPORT_STAR bytecodes. Gates v0.8.
7 min
gopy codecsPort of cpython/Python/codecs.c (1708 lines) to the codecs/ package. Codec registry, error-handler registry, Encode/Decode entry points, and the three built-in codecs (utf-8, ascii, latin-1) needed by the import source reader.
7 min
gopy vm remaining bytecodesBytecodes ported in v0.9 that finish the Tier-1 panel: import, generator, pattern-match, with/finally, set builders, and the async-protocol stubs.
5 min