aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/ast.h35
-rw-r--r--include/parser.h1
-rw-r--r--include/std/types.h3
-rw-r--r--include/tokenizer.h15
4 files changed, 48 insertions, 6 deletions
diff --git a/include/ast.h b/include/ast.h
index 529b3c8..fb0f275 100644
--- a/include/ast.h
+++ b/include/ast.h
@@ -10,12 +10,18 @@ typedef struct FunctionDecl FunctionDecl;
typedef struct FunctionCall FunctionCall;
typedef struct LhsExpr LhsExpr;
typedef struct Import Import;
+typedef struct String String;
+typedef struct Variable Variable;
+typedef struct Number Number;
typedef union {
FunctionDecl *func_decl;
FunctionCall *func_call;
LhsExpr *lhs_expr;
Import *import;
+ String *string;
+ Number *number;
+ Variable *variable;
} AstValue;
typedef enum {
@@ -23,7 +29,10 @@ typedef enum {
AST_FUNCTION_DECL,
AST_FUNCTION_CALL,
AST_LHS,
- AST_IMPORT
+ AST_IMPORT,
+ AST_STRING,
+ AST_NUMBER,
+ AST_VARIABLE
} AstType;
typedef struct {
@@ -38,6 +47,7 @@ struct FunctionDecl {
struct FunctionCall {
BufferView name;
+ Buffer args;
};
struct LhsExpr {
@@ -50,15 +60,30 @@ struct Import {
BufferView path;
};
+struct String {
+ BufferView str;
+};
+
+struct Number {
+ union {
+ i64 integer;
+ f64 floating;
+ } value;
+ bool is_integer;
+};
+
+struct Variable {
+ BufferView name;
+};
+
Ast ast_none();
CHECK_RESULT int funcdecl_init(FunctionDecl *self, ScopedAllocator *allocator);
CHECK_RESULT int funcdecl_add_to_body(FunctionDecl *self, Ast ast);
-
-void funccall_init(FunctionCall *self, BufferView name);
-
+CHECK_RESULT int funccall_init(FunctionCall *self, BufferView name, ScopedAllocator *allocator);
void lhsexpr_init(LhsExpr *self, int isConst, BufferView var_name);
-
void import_init(Import *self, BufferView path);
+CHECK_RESULT int string_init(String *self, BufferView str);
+void number_init(Number *self, i64 value, bool is_integer);
#endif
diff --git a/include/parser.h b/include/parser.h
index 9b41e5e..531d67d 100644
--- a/include/parser.h
+++ b/include/parser.h
@@ -31,6 +31,7 @@ typedef struct {
ScopedAllocator *allocator; /* borrowed. Copied from @compiler for faster access to allocator */
amal_compiler *compiler;
bool started;
+ TokenizerError error;
} Parser;
CHECK_RESULT int parser_thread_data_init(ParserThreadData *self);
diff --git a/include/std/types.h b/include/std/types.h
index 68e2d0f..a8a44fd 100644
--- a/include/std/types.h
+++ b/include/std/types.h
@@ -17,4 +17,7 @@ typedef uint64_t u64;
typedef ptrdiff_t isize;
typedef size_t usize;
+typedef float f32;
+typedef double f64;
+
#endif
diff --git a/include/tokenizer.h b/include/tokenizer.h
index fac61e7..c76cd52 100644
--- a/include/tokenizer.h
+++ b/include/tokenizer.h
@@ -19,9 +19,12 @@ typedef enum {
TOK_EQUALS,
TOK_OPEN_PAREN,
TOK_CLOSING_PAREN,
+ TOK_COMMA,
TOK_OPEN_BRACE,
TOK_CLOSING_BRACE,
- TOK_IMPORT
+ TOK_IMPORT,
+ TOK_NUMBER,
+ TOK_DOT
} Token;
typedef struct {
@@ -40,9 +43,17 @@ typedef struct {
union {
BufferView identifier;
BufferView string;
+ i64 integer;
+ f64 floating;
} value;
+ bool number_is_integer;
} Tokenizer;
+typedef struct {
+ int index;
+ const char* str;
+} TokenizerError;
+
CHECK_RESULT int tokenizer_init(Tokenizer *self, BufferView code, BufferView code_name);
CHECK_RESULT int tokenizer_accept(Tokenizer *self, Token expected_token);
/*
@@ -51,5 +62,7 @@ CHECK_RESULT int tokenizer_accept(Tokenizer *self, Token expected_token);
*/
CHECK_RESULT int tokenizer_consume_if(Tokenizer *self, Token expected_token, bool *result);
void tokenizer_print_error(Tokenizer *self, const char *fmt, ...);
+void tokenizer_print_error_object(Tokenizer *self, TokenizerError *error);
+TokenizerError tokenizer_create_error(Tokenizer *tokenizer, const char *err_str);
#endif