aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-02-24 17:53:46 +0100
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commita307f17f44b461f58441926fcbf87883f17ebe61 (patch)
treeea03a634f06c33591c8afea5139e7e931d429cf7 /include
parent12e5135d95dc34fd7f7a7c50d6dbac453f252683 (diff)
Fixed CHECK_RESULT macro, use scoped allocator
Scoped allocator gives us better performance and cleanup code for error cases is much cleaner
Diffstat (limited to 'include')
-rw-r--r--include/misc.h2
-rw-r--r--include/parser.h4
-rw-r--r--include/scoped_allocator.h27
-rw-r--r--include/tokenizer.h1
4 files changed, 31 insertions, 3 deletions
diff --git a/include/misc.h b/include/misc.h
index 633ccfd..9cb2dde 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -12,7 +12,7 @@ do { \
#define cleanup_if_error(result) do { if((result) != 0) goto cleanup; } while(0)
#if defined(__GNUC__) && __GNUC__ >= 4
-#define CHECK_RESULT __attribute__ ((CHECK_RESULT))
+#define CHECK_RESULT __attribute__ ((warn_unused_result))
#elif defined(_MSC_VER) && _MSC_VER >= 1700
#define CHECK_RESULT _Check_return_
#else
diff --git a/include/parser.h b/include/parser.h
index d66a096..e90871f 100644
--- a/include/parser.h
+++ b/include/parser.h
@@ -4,6 +4,7 @@
#include "buffer.h"
#include "buffer_view.h"
#include "tokenizer.h"
+#include "scoped_allocator.h"
#define PARSER_OK 0
/* General error */
@@ -11,8 +12,9 @@
#define PARSER_UNEXPECTED_TOKEN -2
typedef struct {
- Buffer ast_objects;
Tokenizer tokenizer;
+ ScopedAllocator allocator;
+ Buffer ast_objects;
} Parser;
CHECK_RESULT int parser_init(Parser *self);
diff --git a/include/scoped_allocator.h b/include/scoped_allocator.h
new file mode 100644
index 0000000..1193439
--- /dev/null
+++ b/include/scoped_allocator.h
@@ -0,0 +1,27 @@
+#ifndef AMALGAM_SCOPED_ALLOCATOR_H
+#define AMALGAM_SCOPED_ALLOCATOR_H
+
+#include "misc.h"
+#include "types.h"
+
+typedef struct ScopedAllocatorNode ScopedAllocatorNode;
+
+struct ScopedAllocatorNode {
+ char *data;
+ usize size;
+ ScopedAllocatorNode *next;
+};
+
+typedef struct {
+ ScopedAllocatorNode head;
+ ScopedAllocatorNode *current;
+} ScopedAllocator;
+
+CHECK_RESULT int scoped_allocator_node_init(ScopedAllocatorNode *self);
+void scoped_allocator_node_deinit(ScopedAllocatorNode *self);
+
+CHECK_RESULT int scoped_allocator_init(ScopedAllocator *self);
+void scoped_allocator_deinit(ScopedAllocator *self);
+CHECK_RESULT int scoped_allocator_alloc(ScopedAllocator *self, usize size, void **mem);
+
+#endif \ No newline at end of file
diff --git a/include/tokenizer.h b/include/tokenizer.h
index f572860..9584542 100644
--- a/include/tokenizer.h
+++ b/include/tokenizer.h
@@ -32,7 +32,6 @@ typedef struct {
} Tokenizer;
CHECK_RESULT int tokenizer_init(Tokenizer *self, BufferView code);
-void tokenizer_deinit(Tokenizer *self);
CHECK_RESULT int tokenizer_next(Tokenizer *self, Token *token);
CHECK_RESULT int tokenizer_accept(Tokenizer *self, Token expected_token);