Skip to content

Commit 9a36236

Browse files
committed
feat: add basic support for the multi-value proposal
1 parent 2180c8c commit 9a36236

9 files changed

Lines changed: 464 additions & 95 deletions

File tree

cli/options.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@
219219
" threads Threading and atomic operations.",
220220
" simd SIMD types and operations.",
221221
" reference-types Reference types and operations.",
222+
" multi-value Multi value types.",
222223
" gc Garbage collection (WIP).",
223224
" stringref String reference types.",
224225
" relaxed-simd Relaxed SIMD operations.",
@@ -227,7 +228,6 @@
227228
"TODO_doesNothingYet": [
228229
" exception-handling Exception handling.",
229230
" tail-calls Tail call operations.",
230-
" multi-value Multi value types.",
231231
" memory64 Memory64 operations.",
232232
" extended-const Extended const expressions."
233233
],

src/ast.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export const enum NodeKind {
5050
// types
5151
NamedType,
5252
FunctionType,
53+
TupleType,
5354
TypeName,
5455
TypeParameter,
5556
Parameter,
@@ -161,6 +162,14 @@ export abstract class Node {
161162
return new FunctionTypeNode(parameters, returnType, explicitThisType, isNullable, range);
162163
}
163164

165+
static createTupleType(
166+
elements: TypeNode[],
167+
isNullable: bool,
168+
range: Range
169+
): TupleTypeNode {
170+
return new TupleTypeNode(elements, isNullable, range);
171+
}
172+
164173
static createOmittedType(
165174
range: Range
166175
): NamedTypeNode {
@@ -862,6 +871,9 @@ export abstract class TypeNode extends Node {
862871
if (functionTypeNode.returnType.hasGenericComponent(typeParameterNodes)) return true;
863872
let explicitThisType = functionTypeNode.explicitThisType;
864873
if (explicitThisType && explicitThisType.hasGenericComponent(typeParameterNodes)) return true;
874+
} else if (this.kind == NodeKind.TupleType) {
875+
let tupleTypeNode = <TupleTypeNode>changetype<TypeNode>(this);
876+
if (tupleTypeNode.elements.some((v) => v.hasGenericComponent(typeParameterNodes))) return true;
865877
} else {
866878
assert(false);
867879
}
@@ -928,6 +940,20 @@ export class FunctionTypeNode extends TypeNode {
928940
}
929941
}
930942

943+
/** Represents a tuple type. */
944+
export class TupleTypeNode extends TypeNode {
945+
constructor(
946+
/** Tuple elements. */
947+
public elements: TypeNode[],
948+
/** Whether nullable or not. */
949+
isNullable: bool,
950+
/** Source range. */
951+
range: Range
952+
) {
953+
super(NodeKind.TupleType, isNullable, range);
954+
}
955+
}
956+
931957
/** Represents a type parameter. */
932958
export class TypeParameterNode extends Node {
933959
constructor(

0 commit comments

Comments
 (0)