AstUnaryOp* make_cast(bh_allocator a, AstTyped* expr, Type* to);
AstZeroValue* make_zero_value(bh_allocator a, OnyxToken *token, Type* type);
AstStructLiteral* make_optional_literal_some(bh_allocator a, AstTyped *expr, Type* opt_type);
+AstStructLiteral* make_union_variant_of_void(bh_allocator a, Type* union_type, OnyxToken* token, UnionVariant* variant);
void arguments_initialize(Arguments* args);
b32 fill_in_arguments(Arguments* args, AstNode* provider, char** err_msg, b32 insert_zero_values);
}
if (node->kind == Ast_Kind_Unary_Field_Access) {
+ if (type->kind == Type_Kind_Union) {
+ token_toggle_end(node->token);
+ int index = 0;
+ if ((index = shgeti(type->Union.variants, node->token->text)) != -1) {
+ UnionVariant *uv = type->Union.variants[index].value;
+ if (uv->type != &basic_types[Basic_Kind_Void]) {
+ if (permanent) {
+ onyx_report_error(node->token->pos, Error_Critical,
+ "Shorthand union literal syntax '.%s' is not all for this variant, because its type is not void; it is '%s'. Use the longer syntax, '.{ %s = value }'",
+ node->token->text,
+ type_get_name(uv->type),
+ node->token->text);
+ }
+ token_toggle_end(node->token);
+ return TYPE_MATCH_FAILED;
+ }
+
+ if (permanent) {
+ AstStructLiteral *sl = make_union_variant_of_void(context.ast_alloc, type, node->token, uv);
+ *pnode = (AstTyped *) sl;
+ }
+
+ token_toggle_end(node->token);
+ return TYPE_MATCH_SUCCESS;
+ }
+ token_toggle_end(node->token);
+ }
+
AstType* ast_type = type->ast_type;
AstNode* resolved = try_symbol_resolve_from_node((AstNode *) ast_type, node->token);
if (resolved == NULL) {
return opt_lit;
}
+AstStructLiteral* make_union_variant_of_void(bh_allocator a, Type* union_type, OnyxToken* token, UnionVariant* variant) {
+ AstStructLiteral *lit = onyx_ast_node_new(a, sizeof(AstStructLiteral), Ast_Kind_Struct_Literal);
+ lit->token = token;
+
+ assert(variant->type == &basic_types[Basic_Kind_Void]);
+
+ arguments_initialize(&lit->args);
+ arguments_ensure_length(&lit->args, 2);
+ lit->args.values[0] = (AstTyped *) make_int_literal(a, variant->tag_value);
+ lit->args.values[1] = (AstTyped *) make_zero_value(a, token, variant->type);
+
+ lit->type = union_type;
+ lit->args.values[0]->type = union_type->Union.tag_type;
+
+ lit->flags |= Ast_Flag_Has_Been_Checked;
+ return lit;
+}
void arguments_initialize(Arguments* args) {
return .{
a,
*listen_addr,
- .{ None = .{} },
- .{ None = .{} }
+ .None,
+ .None
};
}
from_ptr :: macro (p: &$T) -> ?T {
p_ := p;
if p_ do return *p_;
- return .{ None = .{} };
+ return .None;
}
#doc """
#doc "Clears the value in the Optional, zeroing the memory of the value."
reset :: (o: &?$T) {
- *o = .{ None = .{} };
+ *o = .None;
}
#doc "Sets the value in the Optional."
and_then :: (o: ?$T, transform: (T) -> ?$R) -> ?R {
return switch o {
case v: .Some => transform(v);
- case #default => .{ None = .{} };
+ case #default => .None;
};
}
transform :: (o: ?$T, transform: (T) -> $R) -> ?R {
switch o {
case v: .Some do return .{ Some = transform(v) };
- case #default do return .{ None = .{} };
+ case #default do return .None;
}
}
m.details << .{
accessor = .{ Scope = .{} },
op = .Equal,
- value = .{ None = .{} },
+ value = .None,
};
} else {
m.details << .{
accessor = .{ Node = .{} },
op = .Equal,
- value = .{ None = .{} },
+ value = .None,
};
continue;
}
peek_char :: (self: &#Self) -> ? u32 {
codepoint_length := utf8.rune_length_from_first_byte(self.doc[self.cursor]);
- if self.cursor + codepoint_length >= self.doc.length do return .{ None = .{} };
+ if self.cursor + codepoint_length >= self.doc.length do return .None;
value := utf8.decode_rune(string.advance(self.doc, self.cursor));
return value;
eat_char :: (self: &#Self) -> ? u32 {
codepoint_length := utf8.rune_length_from_first_byte(self.doc[self.cursor]);
- if self.cursor + codepoint_length >= self.doc.length do return .{ None = .{} };
+ if self.cursor + codepoint_length >= self.doc.length do return .None;
value := utf8.decode_rune(string.advance(self.doc, self.cursor));
self.cursor += codepoint_length;
}
});
- return .{ Ok = .{ None = .{} } };
+ return .{ Ok = .None };
}
parse_identifier :: (self: &#Self) -> Result(? str, Parse_Error) {
}
case .EOF {
- return .{ Ok = .{ None = .{} } };
+ return .{ Ok = .None };
}
case #default {
create_node :: (d: &Document, name: str) -> &Node {
return d.allocator->move(Node.{
node = name,
- type_annotation = .{ None = .{} },
+ type_annotation = .None,
values = make([..] Value, d.allocator),
props = make(Map(str, Value), d.allocator),
children = make([..] &Node, d.allocator)
__futex_wait :: (addr: rawptr, expected: i32, timeout: i32) -> i32 {
tm: wasi.OptionTimestamp;
if timeout < 0 {
- tm = .{ None = .{} };
+ tm = .None;
} else {
tm = .{ Some = ~~timeout };
}