Skip to content

Implement tuple in the stdlib#402

Merged
antocuni merged 22 commits into
mainfrom
typed-tuples
Feb 27, 2026
Merged

Implement tuple in the stdlib#402
antocuni merged 22 commits into
mainfrom
typed-tuples

Conversation

@antocuni
Copy link
Copy Markdown
Member

@antocuni antocuni commented Feb 24, 2026

Introduce stdlib/_tuple.spy, which implements tuple in SPy and thus it's automatically supported by the C backend.

Tuples are implemented as structs like this:

struct tuple_int_int {
    int _item0;
    int _item1;
};

Moreover, the "tuple packing" syntax now automatically infers the right tuple type and creates an instance of it: STATIC_TYPE((1, 'hello')) == tuple[int, str].

Similarly, we support tuple unpacking: a, b = sometuple.

The old "blue only, untyped tuple" now lives in __spy__.interp_tuple. It's still used for *varargs.

Unrelated misc changes:

  • build libspy.wasm in a way that always include/exports all the symbols which might be needed in tests

@antocuni antocuni mentioned this pull request Feb 24, 2026
antocuni added a commit that referenced this pull request Feb 24, 2026
From the comment in ast.py:
```
# The Expr class has an optional field w_T which indicates the type of the expression.
#
# AST trees are said UNTYPED when all their Exprs have w_T == None.
# AST trees are said TYPED when all their Exprs have w_T != None.
#
# It is a logical error to have AST trees which mix typed and untyped nodes.
#
# The parser produces UNTYPED ASTs. DopplerFrame produces TYPED ASTs.
```

This will be useful because the it allows the C backend to know the type
of expressions.
In particular it's needed for tuple unpacking (PR #402) and "preserve
left-to-right arg evaluation" (PR #386 which is now closed and will be
redone in a different way).

@Jemeljanov this is probably what you will need for your PR :)
@antocuni antocuni force-pushed the typed-tuples branch 2 times, most recently from 0e3e269 to 750cc7b Compare February 27, 2026 10:46
@antocuni antocuni marked this pull request as ready for review February 27, 2026 16:40
@antocuni antocuni merged commit 3eafa09 into main Feb 27, 2026
@antocuni antocuni deleted the typed-tuples branch February 27, 2026 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant