aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-12-31 17:10:29 -0500
committerAndrew Kelley <superjoe30@gmail.com>2016-12-31 17:10:29 -0500
commit69132bdeda9f9ee672d883fd442b6158d8725422 (patch)
tree29b1bfd8acbab82442f83bbad2d06d0eea0d7f35 /src/parser.cpp
parent5f89393acb0e3626d942302ca24de14349850040 (diff)
downloadzig-69132bdeda9f9ee672d883fd442b6158d8725422.tar.gz
zig-69132bdeda9f9ee672d883fd442b6158d8725422.zip
IR: progress toward compiling standard library
* comptime fn call * is_comptime doesn't count as an instruction dependency * update more std code to latest zig
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index 54994034f9..a27927cb05 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -837,7 +837,7 @@ static AstNode *ast_parse_curly_suffix_expr(ParseContext *pc, size_t *token_inde
}
/*
-SuffixOpExpression : PrimaryExpression option(FnCallExpression | ArrayAccessExpression | FieldAccessExpression | SliceExpression)
+SuffixOpExpression = option("inline") PrimaryExpression option(FnCallExpression | ArrayAccessExpression | FieldAccessExpression | SliceExpression)
FnCallExpression : token(LParen) list(Expression, token(Comma)) token(RParen)
ArrayAccessExpression : token(LBracket) Expression token(RBracket)
SliceExpression : token(LBracket) Expression token(Ellipsis) option(Expression) token(RBracket) option(token(Const))
@@ -845,8 +845,22 @@ FieldAccessExpression : token(Dot) token(Symbol)
StructLiteralField : token(Dot) token(Symbol) token(Eq) Expression
*/
static AstNode *ast_parse_suffix_op_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
+ Token *inline_token = &pc->tokens->at(*token_index);
+ bool is_comptime;
+ if (inline_token->id == TokenIdKeywordInline) {
+ // TODO make it an error if something other than function call has the comptime keyword
+ is_comptime = true;
+ *token_index += 1;
+ } else {
+ is_comptime = false;
+ }
+
+
AstNode *primary_expr = ast_parse_primary_expr(pc, token_index, mandatory);
if (!primary_expr) {
+ if (is_comptime) {
+ *token_index -= 1;
+ }
return nullptr;
}
@@ -857,6 +871,7 @@ static AstNode *ast_parse_suffix_op_expr(ParseContext *pc, size_t *token_index,
AstNode *node = ast_create_node(pc, NodeTypeFnCallExpr, first_token);
node->data.fn_call_expr.fn_ref_expr = primary_expr;
+ node->data.fn_call_expr.is_comptime = is_comptime;
ast_parse_fn_call_param_list(pc, token_index, &node->data.fn_call_expr.params);
primary_expr = node;