From a27a3e6ae09e8396584c95a3567b145e86d8bc40 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 24 Feb 2019 17:53:46 +0100 Subject: Fixed CHECK_RESULT macro, use scoped allocator Scoped allocator gives us better performance and cleanup code for error cases is much cleaner --- src/parser.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'src/parser.c') diff --git a/src/parser.c b/src/parser.c index 875c0bc..6a1c796 100644 --- a/src/parser.c +++ b/src/parser.c @@ -7,17 +7,12 @@ static CHECK_RESULT int parser_parse_body(Parser *self, Ast *ast); int parser_init(Parser *self) { - buffer_init(&self->ast_objects); return_if_error(scoped_allocator_init(&self->allocator)); + return_if_error(buffer_init(&self->ast_objects, &self->allocator, sizeof(Ast) * 8)); return PARSER_OK; } void parser_deinit(Parser *self) { - usize i; - for(i = 0; i < self->ast_objects.size / sizeof(Ast); ++i) { - ast_deinit((Ast*)&self->ast_objects.data[i]); - } - buffer_deinit(&self->ast_objects); scoped_allocator_deinit(&self->allocator); } @@ -62,7 +57,7 @@ static CHECK_RESULT int parser_parse_function_decl(Parser *self, FunctionDecl ** return_if_error(tokenizer_accept(&self->tokenizer, TOK_OPEN_BRACE)); return_if_error(scoped_allocator_alloc(&self->allocator, sizeof(FunctionDecl), (void**)func_decl)); - funcdecl_init(*func_decl); + cleanup_if_error(funcdecl_init(*func_decl, &self->allocator)); for(;;) { Ast body_obj; -- cgit v1.2.3