Repository navigation
Description
Context
At main commit 30218a8, minipy has no token, AST node, source type, or runtime value for Python's ... singleton.
The current architecture already provides the required extension points:
lexer.(*Lexer).scanOperatorowns longest-match operator scanning;.currently always emitstoken.DOT.parser.(*Parser).parsePrimaryalready parses subscript contents as ordinary expressions, soa[...]can be represented asSubscript{Index: EllipsisLit}without a separate subscript grammar path.types.Resolveowns simple annotation names, soEllipsisTypedoes not need a dedicated annotation parser branch.operator.Comparableandoperator.EmitCompareStackown comparison typing and lowering.- minivm already provides ref-kind structs, constants,
CONST_GET, andREF_EQ; no new VM value kind or opcode is required.
Goal
Add the smallest complete implementation of Python's Ellipsis singleton:
- literal expression
... - builtin fallback name
Ellipsis - annotation name
EllipsisType is,is not,==, and!=between Ellipsis values- a targeted static diagnostic for unsupported ellipsis subscripts
... and the unshadowed builtin name Ellipsis must always lower to the same immutable runtime singleton.
Implementation plan
1. Add the token and lexer rule
Affected files/symbols:
token/token.gotoken.ELLIPSISnames
lexer/lexer.go(*Lexer).scanOperator
Steps:
- Add
ELLIPSISnext toDOTin the delimiter token group. - Add
names[ELLIPSIS] = "...". - In
scanOperator, makecase '.'emitELLIPSISwhen the next two runes are also., otherwise preserve the existingDOTbehavior. - Do not change numeric scanning:
.5is already routed throughscanNumberbeforescanOperator.
2. Add the AST node and parser atom
Affected files/symbols:
ast/ast.goEllipsisLit(*EllipsisLit).exprNode
parser/parser.go(*Parser).parseAtom
Steps:
-
Add a data-only node next to
NoneLit:type EllipsisLit struct { Base }
-
Parse
token.ELLIPSISas*ast.EllipsisLitinparseAtom. -
Do not modify
parsePrimary,parseSubscriptIndex, orast.Subscript; the existing expression-index path already preservesa[...]as an ellipsis index expression.
3. Add the source type and runtime singleton
Affected files/symbols:
types/types.gotypes.Ellipsistypes.Resolve
compiler/lower.go- package-level Ellipsis VM value
(*lowerer).expr
Steps:
-
Reuse the existing
primitivesource-type representation:Ellipsis Type = primitive{ name: "EllipsisType", vm: vmtypes.NewStructType(), }
-
Make
types.Resolve("EllipsisType")returntypes.Ellipsis. -
Create one package-level zero-field minivm struct instance for the Ellipsis value.
-
Lower every
EllipsisLitthroughconstGetusing that shared instance. -
Do not allocate a new runtime object per literal occurrence.
No new types.Type implementation is needed; primitive already supplies source-level identity and VM mapping.
4. Resolve the literal and builtin fallback name
Affected files/symbols:
compiler/check.go(*checker).typeOf(*checker).nameType(*checker).indexResultType
compiler/lower.go(*lowerer).expr
Steps:
-
Make
typeOf(*ast.EllipsisLit)returntypes.Ellipsis. -
Keep all existing name resolution ahead of the builtin fallback: temporary names, narrowing, locals, captures, module globals, functions, classes, and modules retain their current precedence.
-
Only when no normal binding exists, resolve the name
Ellipsisas the builtin singleton with typetypes.Ellipsis. -
Preserve normal shadowing behavior. For example:
Ellipsis = 1 x = Ellipsis # int
-
In lowering, emit the singleton constant directly only when an
ast.NamenamedEllipsiswas typed astypes.Ellipsis; shadowed names continue through the existinggetpath. -
At the start of
indexResultType, reject an index typed astypes.Ellipsiswith:UnsupportedFeature: ellipsis subscript is not supported
This single check covers list, dict, tuple, class, string, and bytes receivers without duplicating receiver-specific branches.
5. Add comparison semantics
Affected files/symbols:
operator/types.goComparableidentityComparable
operator/emit.goEmitCompareStack
Steps:
- Treat
types.Ellipsisas identity-comparable. - Allow
==and!=only when both operands areEllipsisType. - Reject
<,<=,>, and>=withtoken.NotComparable. - Lower
is,is not,==, and!=throughREF_EQ; appendI32_EQZfor the negative forms. - Do not broaden equality between Ellipsis and unrelated types.
6. Update language documentation
Affected files:
docs/spec/01-lexical.md—...tokendocs/spec/02-types.md—EllipsisTypedocs/spec/03-grammar.md— ellipsis atomdocs/spec/04-static-semantics.md— type, comparisons, and unsupported subscript ruledocs/spec/05-codegen.md— singleton constant and ref comparison loweringdocs/spec/06-builtins.md— builtin fallback name and shadowingdocs/compatibility.md— compatibility statusdocs/roadmap.md— only if it currently tracks Ellipsis as missing
Do not update README.md or docs/coding-patterns.md; this change adds language behavior but does not change project structure or coding conventions.
Non-goals
- NumPy-style multidimensional indexing or ellipsis expansion
- passing Ellipsis through a dynamic
__getitem__/__setitem__protocol - the standard-library
typesmodule ortypes.EllipsisTypeimports Literal[Ellipsis]- Ellipsis as a dict key or set element
- general
repr,str,print,type, reflection, or attribute support - constructing values with
EllipsisType() - mutable fields or attributes on the singleton
- broader cross-type equality rules
Explicitly unaffected areas
Do not modify:
compiler/compiler.gobuiltins/*module/*- the minivm repository or dependency version
- VM opcodes or value kinds
Native module symbols currently model callable names rather than first-class constants. Extending that API for one singleton would add unnecessary surface area.
Acceptance criteria
-
...is emitted as oneELLIPSIStoken. -
Existing tokenization of
.,.5, anda.bis unchanged. -
The parser produces
*ast.EllipsisLitfor.... -
a[...]preserves*ast.EllipsisLitas the subscript index. -
The following compiles and runs:
x: EllipsisType = ... assert x is Ellipsis assert ... is Ellipsis assert ... == Ellipsis assert not (... != Ellipsis)
-
Singleton identity survives repeated literals, name lookup, function arguments, and return values.
-
EllipsisTyperesolves as an annotation but cannot be called or directly constructed. -
A local or global binding named
Ellipsisshadows the builtin fallback consistently with existing name rules. -
Ordering comparisons such as
... < ...fail withNotComparable. -
a[...]anda[Ellipsis]on currently supported receiver types fail with the same targetedUnsupportedFeaturediagnostic. -
Literal use does not allocate a new runtime object each time.
-
No
builtins,module, minivm API, dependency, or opcode changes are introduced. -
go test ./...passes.
Tests
Add or update tests in:
token/token_test.goELLIPSIS.String() == "..."
lexer/lexer_test.go- longest match for
... - regressions for
.,.5, anda.b ....tokenizes asELLIPSIS, thenDOT
- longest match for
ast/ast_test.goEllipsisLitsatisfiesExprand preservesPos
parser/parser_test.go- standalone literal
- assignment RHS
- call argument
a[...]AST shape
types/types_test.gotypes.EllipsisResolve("EllipsisType")- inequality with other primitives
- ref-kind VM representation
operator/operator_test.gois,is not,==, and!=- ordering rejection
REF_EQand negation opcode sequences
compiler/compiler_test.go- literal/name identity end to end
- annotation and function round-trip
- shadowing
- unsupported subscript diagnostic
- direct-construction rejection
Validation commands:
go test ./token ./lexer ./ast ./parser ./types ./operator ./compiler
go test ./...Benchmarks
Do not add a benchmark.
This is a compatibility feature, not a performance change. The implementation should simply guarantee that the singleton is created once and reused through the existing constant pool; no performance claim or numeric target is required.
Activity
chore: stage issue #7 implementation
chore: stage issue #7 implementation
chore: stage issue #7 implementation
chore: prepare issue #7 validation
siyul-park commentedon Aug 13, 2026
Verified against current
main: #7 is already fully implemented. The repository containsELLIPSIS,EllipsisLit,EllipsisType, singleton lowering, shadowing-awareEllipsisfallback, targeted ellipsis-subscript diagnostics, and dedicated tests in token/lexer/AST/parser/types/compiler.go test ./token ./lexer ./ast ./parser ./types ./operator ./compiler,go test ./compiler ./conformance, andgo vet ./...pass. Closing as completed.