The mapping is one-to-many: a CPython file may split across several Go
files (or vice-versa). Where multiple C files collapse into one Go package,
the package’s doc.go lists the source files it derives from.
Conventions:
All Go packages live at the module root (gopy/<pkg>). We do not
use Go’s internal/ directory convention. See 1601 for rationale.
Files named like dynload_*.c and emscripten_*.c are platform glue we
do not port. Go’s runtime handles the equivalents. They are listed here
for completeness with a -- Go target.
Generated headers (generated_cases.c.h, executor_cases.c.h,
optimizer_cases.c.h, opcode_targets.h) are regenerated from the
CPython DSL via our own Go-emitting code generator. See 1621.
Compiler pipeline
C file
Go target
Purpose
Python/asdl.c
ast/asdl.go
ASDL sequence helpers (asdl_seq_*)
Python/Python-ast.c
ast/nodes_gen.go (generated)
Generated AST node constructors
Python/ast.c
ast/validate.go
_PyAST_Validate
Python/ast_preprocess.c
ast/preprocess.go
Constant fold, PEP 765 control-flow checks
Python/ast_unparse.c
ast/unparse.go
AST → source (annotations)
Python/symtable.c
symtable/
Two-pass symbol table builder
Python/future.c
future/future.go
__future__ extraction
Python/compile.c
compile/compiler.go
Pipeline orchestration
Python/codegen.c
compile/codegen.go plus codegen_*.go panel
AST → instruction sequence (split per stmt/expr family)
Bytecode + PEP 626 line table + PEP 657 exception table
Lib/dis.py
compile/dis.go
Disassembler used by the v05test gate
(none)
compile/code.go
Code value type, mirrors PyCodeObject
(generator output)
compile/opcodes_gen.go
Opcode constants and metadata (generated)
Bytecode interpreter & frame
C file
Go target
Purpose
Python/ceval.c
vm/eval.go
Eval loop entry & unwind
Python/ceval_gil.c
vm/gil.go
GIL acquire/release, eval breaker
Python/ceval_macros.h
vm/dispatch.go
Dispatch helpers
Python/bytecodes.c
(input to generator)
Source-of-truth ISA
Python/generated_cases.c.h
vm/opcodes_gen.go (generated)
Tier-1 dispatch handlers
Python/opcode_targets.h
vm/opcode_targets_gen.go (generated)
Computed-goto table replaced by switch
Python/frame.c
vm/frame.go
PyFrameObject
Python/stackrefs.c
vm/stackref.go
Tagged stack references
Specializer / optimizer / JIT / instrumentation
C file
Go target
Purpose
Python/specialize.c
specialize/
PEP 659 adaptive specialization
Python/optimizer.c
optimizer/optimizer.go
Trace projection, executor build
Python/optimizer_analysis.c
optimizer/analysis.go
Type/global watcher, dataflow
Python/optimizer_bytecodes.c
(input to generator)
Tier-2 abstract-interp DSL
Python/optimizer_symbols.c
optimizer/symbols.go
Symbol lattice
Python/optimizer_cases.c.h
optimizer/cases_gen.go (generated)
Abstract interp cases
Python/executor_cases.c.h
optimizer/executor_gen.go (generated)
Tier-2 interpreter cases
Python/jit.c
jit/stub.go (deferred)
Copy-and-patch JIT, deferred
Python/instrumentation.c
monitor/instrumentation.go
PEP 669 monitoring
Python/legacy_tracing.c
monitor/legacy.go
sys.settrace / sys.setprofile
Python/intrinsics.c
intrinsics/intrinsics.go
INTRINSIC_1 / INTRINSIC_2
State, lifecycle, init, run
C file
Go target
Purpose
Python/pystate.c
state/
Runtime / Interpreter / Thread
Python/pylifecycle.c
lifecycle/lifecycle.go
Initialize / Finalize phases
Python/initconfig.c
initconfig/config.go
PyConfig
Python/preconfig.c
initconfig/preconfig.go
PyPreConfig
Python/interpconfig.c
initconfig/interpconfig.go
Per-interpreter config
Python/pathconfig.c
pathconfig/pathconfig.go
sys.path, prefix, exec_prefix
Python/bootstrap_hash.c
hash/secret.go
PYTHONHASHSEED bootstrap
Python/pythonrun.c
pythonrun/
REPL, file/string eval
Python/frozen.c
imp/frozen.go
Frozen module table
Python/frozenmain.c
cmd/gopy-frozen/
Embedded entry point
Python/import.c
imp/import.go
importlib bootstrap, sys.modules
Python/importdl.c
imp/importdl_stub.go (deferred)
Native .so/.pyd loading, deferred
Python/marshal.c
marshal/marshal.go
.pyc wire format
Python/crossinterp.c
crossinterp/
XIData, sub-interpreter handoff
Errors, modules, codecs
C file
Go target
Purpose
Python/errors.c
errors/errors.go
PyErr_* exception protocol
Python/traceback.c
traceback/traceback.go
Traceback objects, formatting
Python/suggestions.c
errors/suggest.go
“Did you mean…?” hints
Python/bltinmodule.c
builtin/
__builtins__
Python/sysmodule.c
sysmod/
sys
Python/_warnings.c
warnings/warnings.go
warnings
Python/_contextvars.c
contextvar/contextvars_module.go
_contextvars C module
Python/codecs.c
codecs/codecs.go
Codec registry, error handlers
Python/modsupport.c
modsupport/modsupport.go
Py_BuildValue, module init helpers
Python/structmember.c
structmember/structmember.go
tp_members descriptors
Python/getargs.c
getargs/getargs.go
PyArg_Parse* parsers
Memory, GC, concurrency
C file
Go target
Purpose
Python/gc.c
gc/collector.go
Generational cycle collector (GIL)
Python/gc_gil.c
gc/gil.go
GIL-build helpers
Python/gc_free_threading.c
gc/freethreading.go
nogil cycle collector
Python/brc.c
gc/brc.go
Biased reference counting
Python/qsbr.c
gc/qsbr.go
Quiescent-state-based reclamation
Python/uniqueid.c
gc/uniqueid.go
Per-thread refcount index pool
Python/index_pool.c
gc/indexpool.go
Free index allocator
Python/object_stack.c
gc/objstack.go
GC mark stack
Python/pyarena.c
arena/arena.go
Bump arena (compiler scratch)
Python/thread.c
pythread/thread.go
Thread create/join
Python/lock.c
pysync/lock.go
PyMutex, _PyOnceFlag
Python/parking_lot.c
pysync/parkinglot.go
WebKit-style park/unpark
Python/critical_section.c
pysync/criticalsection.go
Per-object critical sections (nogil)
Note on pysync: we use the package name pysync (not sync) to
avoid shadowing Go’s standard library sync package inside the gopy
module, since these CPython primitives have semantics distinct from
sync.Mutex / sync.Cond.
Strings, numbers, hashing, time, hamt, context
C file
Go target
Purpose
Python/formatter_unicode.c
format/format.go
__format__ mini-language
Python/pystrtod.c
pystrconv/strtod.go
strtod wrapper (calls dtoa)
Python/dtoa.c
pystrconv/dtoa.go
David Gay shortest-roundtrip dtoa
Python/pystrhex.c
pystrconv/hex.go
bytes-to-hex helpers
Python/pystrcmp.c
pystrconv/cmp.go
locale-independent strcmp
Python/mystrtoul.c
pystrconv/strtoul.go
int parsing
Python/mysnprintf.c
(drop, use fmt.Sprintf)
n/a in Go
Python/pyhash.c
hash/hash.go
SipHash-1-3, FNV, x86_aes
Python/pyctype.c
pystrconv/ctype.go
ASCII isalpha/isdigit (locale-independent)
Python/pymath.c
pymath/pymath.go
math primitives, NaN/Inf
Python/pyfpe.c
pymath/fpe.go
float-point exception handling
Python/hamt.c
hamt/hamt.go
Hash array mapped trie (contextvars)
Python/hashtable.c
hashtable/hashtable.go
Internal hash table for caches
Python/context.c
contextvar/context.go
PEP 567 contextvars
Python/pytime.c
pytime/pytime.go
monotonic, perf_counter, FromSeconds
Python/Python-tokenize.c
tokenize/tokenize.go
tokenizer C-API hooks
Grammar/Tokens plus Include/internal/pycore_token.h plus Lib/token.py
tokenize/types_gen.go (generated by tools/tokens_go), tokenize/types.go
Token kind constants and Type.String
Python/getopt.c
getopt/getopt.go
argv parsing for python.exe
Python/tracemalloc.c
tracemalloc/tracemalloc.go
allocation tracing
Python/remote_debugging.c
remotedebug/remotedebug.go (deferred)
remote debug hooks
Note on pystrconv: same reasoning as pysync. Avoids colliding
with Go’s standard library strconv. pystrconv holds the
Python-specific string/number routines (dtoa, locale-independent
strcmp, mystrtoul). Go’s strconv is used for plain Go conversions.
Go’s internal/ directory convention restricts imports to packages within
the same module subtree. We deliberately do not use it for gopy, for
three reasons:
Embedders: third-party Go programs that embed gopy as a Python
runtime (think python -c style execution from Go code) need to import
vm, state, lifecycle, compile etc. directly. Burying them under
internal/ would block that.
Stdlib re-implementations: the Go-native ports of CPython’s
Modules/* and Lib/* live in companion modules (tamnd/gopy-stdlib,
etc.). Those need to import from this module’s runtime packages.
Tooling and tests: compat/ and external golden-test harnesses
import the same packages the runtime uses. internal/ would force
awkward indirections.
Discoverability is preserved by the package name itself. There is no
ambiguity that compile, vm, gc, frame etc. belong to the gopy
runtime.
← → section · ↑ ↓ slide · Space next · F fullscreen · Esc exit