write object file and fix void return type

This commit is contained in:
Andrew Kelley
2015-11-24 13:00:38 -07:00
parent e112818e25
commit c2e5d50027
11 changed files with 169 additions and 14 deletions

View File

@@ -1,3 +1,10 @@
/*
* Copyright (c) 2015 Andrew Kelley
*
* This file is part of zig, which is MIT licensed.
* See http://opensource.org/licenses/MIT
*/
#include "parser.hpp"
#include <stdarg.h>
@@ -168,6 +175,13 @@ static AstNode *ast_create_node_with_node(NodeType type, AstNode *other_node) {
return node;
}
static AstNode *ast_create_void_type_node(ParseContext *pc, Token *token) {
AstNode *node = ast_create_node(NodeTypeType, token);
node->data.type.type = AstNodeTypeTypePrimitive;
buf_init_from_str(&node->data.type.primitive_name, "void");
return node;
}
static void ast_buf_from_token(ParseContext *pc, Token *token, Buf *buf) {
buf_init_from_mem(buf, buf_ptr(pc->buf) + token->start_pos, token->end_pos - token->start_pos);
}
@@ -468,13 +482,11 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, int token_index, int *new_t
ast_parse_param_decl_list(pc, token_index, &token_index, &node->data.fn_proto.params);
Token *arrow = &pc->tokens->at(token_index);
token_index += 1;
if (arrow->id == TokenIdArrow) {
token_index += 1;
node->data.fn_proto.return_type = ast_parse_type(pc, token_index, &token_index);
} else if (arrow->id == TokenIdLBrace) {
node->data.fn_proto.return_type = nullptr;
} else {
ast_invalid_token_error(pc, arrow);
node->data.fn_proto.return_type = ast_create_void_type_node(pc, arrow);
}
*new_token_index = token_index;