Skip to content

Commit 78d4fb2

Browse files
committed
inline parameters
This replaces the current generic syntax for functions and replaces it with the concept of inline parameters. This paves the way for the "all structs anonymous" proposal. Closes #151.
1 parent 425c0ff commit 78d4fb2

19 files changed

+565
-293
lines changed

doc/langref.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ UseDecl = "use" Expression ";"
2525
2626
ExternDecl = "extern" (FnProto | VariableDeclaration) ";"
2727
28-
FnProto = "fn" option("Symbol") option(ParamDeclList) ParamDeclList option("->" TypeExpr)
28+
FnProto = "fn" option("Symbol") ParamDeclList option("->" TypeExpr)
2929
3030
Directive = "#" "Symbol" "(" Expression ")"
3131
@@ -35,7 +35,7 @@ FnDef = option("inline" | "extern") FnProto Block
3535
3636
ParamDeclList = "(" list(ParamDecl, ",") ")"
3737
38-
ParamDecl = option("noalias") option("Symbol" ":") TypeExpr | "..."
38+
ParamDecl = option("noalias" | "inline") option("Symbol" ":") TypeExpr | "..."
3939
4040
Block = "{" list(option(Statement), ";") "}"
4141

example/guess_number/main.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn main(args: [][]u8) -> %void {
2323
return err;
2424
};
2525

26-
const guess = io.parse_unsigned(u8)(line_buf[0...line_len - 1], 10) %% {
26+
const guess = io.parse_unsigned(u8, line_buf[0...line_len - 1], 10) %% {
2727
%%io.stdout.printf("Invalid number.\n");
2828
continue;
2929
};

src/all_types.hpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,8 @@ struct AstNodeRoot {
195195
struct AstNodeFnProto {
196196
TopLevelDecl top_level_decl;
197197
Buf name;
198-
ZigList<AstNode *> generic_params;
199198
ZigList<AstNode *> params;
200199
AstNode *return_type;
201-
bool generic_params_is_var_args;
202200
bool is_var_args;
203201
bool is_extern;
204202
bool is_inline;
@@ -210,7 +208,10 @@ struct AstNodeFnProto {
210208
FnTableEntry *fn_table_entry;
211209
bool skip;
212210
Expr resolved_expr;
213-
TypeTableEntry *generic_fn_type;
211+
// computed from params field
212+
int inline_arg_count;
213+
// if this is a generic function implementation, this points to the generic node
214+
AstNode *generic_proto_node;
214215
};
215216

216217
struct AstNodeFnDef {
@@ -219,6 +220,7 @@ struct AstNodeFnDef {
219220

220221
// populated by semantic analyzer
221222
TypeTableEntry *implicit_return_type;
223+
// the first child block context
222224
BlockContext *block_context;
223225
};
224226

@@ -230,6 +232,7 @@ struct AstNodeParamDecl {
230232
Buf name;
231233
AstNode *type;
232234
bool is_noalias;
235+
bool is_inline;
233236

234237
// populated by semantic analyzer
235238
VariableTableEntry *variable;
@@ -841,6 +844,7 @@ struct FnTypeId {
841844
bool is_naked;
842845
bool is_cold;
843846
bool is_extern;
847+
bool is_inline;
844848
FnTypeParamInfo prealloc_param_info[fn_type_id_prealloc_param_info_count];
845849
};
846850

@@ -1063,7 +1067,6 @@ struct FnTableEntry {
10631067
ZigList<LabelTableEntry *> all_labels;
10641068
Buf symbol_name;
10651069
TypeTableEntry *type_entry; // function type
1066-
bool is_inline;
10671070
bool internal_linkage;
10681071
bool is_extern;
10691072
bool is_test;
@@ -1172,8 +1175,8 @@ struct CodeGen {
11721175

11731176
ZigList<ImportTableEntry *> import_queue;
11741177
int import_queue_index;
1175-
ZigList<AstNode *> export_queue;
1176-
int export_queue_index;
1178+
ZigList<AstNode *> resolve_queue;
1179+
int resolve_queue_index;
11771180
ZigList<AstNode *> use_queue;
11781181
int use_queue_index;
11791182

0 commit comments

Comments
 (0)