aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/ast.h7
-rw-r--r--include/bytecode/bytecode.h8
-rw-r--r--include/compiler.h3
-rw-r--r--include/program.h9
-rw-r--r--include/tokenizer.h4
5 files changed, 22 insertions, 9 deletions
diff --git a/include/ast.h b/include/ast.h
index 0c34d0b..c45d4aa 100644
--- a/include/ast.h
+++ b/include/ast.h
@@ -132,6 +132,12 @@ struct Scope {
FunctionSignature *function_signature; /* Borrowed from FunctionDecl. Only used if the scope belongs to FunctionDecl */
};
+typedef enum {
+ VARIABLE_TYPE_FLAG_NONE = 0,
+ VARIABLE_TYPE_FLAG_OPTIONAL = 1 << 0,
+ VARIABLE_TYPE_FLAG_BORROW = 1 << 1
+} VariableTypeFlag;
+
typedef struct {
enum {
VARIABLE_TYPE_NONE,
@@ -143,6 +149,7 @@ typedef struct {
Variable *variable;
FunctionSignature *signature;
} value;
+ VariableTypeFlag variable_type_flags;
} VariableType;
struct FileScopeReference {
diff --git a/include/bytecode/bytecode.h b/include/bytecode/bytecode.h
index 8f786a2..23bc4cf 100644
--- a/include/bytecode/bytecode.h
+++ b/include/bytecode/bytecode.h
@@ -77,7 +77,8 @@ typedef enum {
typedef enum {
FUNC_FLAG_NONE = 0,
- FUNC_FLAG_EXPORTED = 1 << 0
+ FUNC_FLAG_EXPORTED = 1 << 0,
+ FUNC_FLAG_VARARGS = 1 << 1
} amal_func_flag;
typedef u8 AmalOpcodeType;
@@ -110,10 +111,13 @@ typedef struct {
#pragma pack(push, 1)
typedef struct {
u8 num_params;
+ u8 num_return_types;
+ u8 name_len;
+ u8 flags;
+
u32 params_num_pointers;
u32 params_fixed_size;
- u8 num_return_types;
u32 return_types_num_pointers;
u32 return_types_fixed_size;
} BytecodeHeaderExternFunction;
diff --git a/include/compiler.h b/include/compiler.h
index f6599a1..164cf4e 100644
--- a/include/compiler.h
+++ b/include/compiler.h
@@ -15,7 +15,7 @@
#define AMAL_COMPILER_ERR -1
#define AMAL_COMPILER_WORK_FAIL_ABORT -2
-#define NUM_ARITHMETIC_TYPES 10
+#define NUM_ARITHMETIC_TYPES 14
typedef struct {
LhsExpr lhs_expr;
@@ -42,6 +42,7 @@ typedef struct {
amal_default_type *c_int;
amal_default_type *c_long;
amal_default_type *c_void;
+ amal_default_type *c_varargs;
amal_default_type *str;
diff --git a/include/program.h b/include/program.h
index aa318d9..dc65cb7 100644
--- a/include/program.h
+++ b/include/program.h
@@ -38,13 +38,11 @@
#define AMAL_PROGRAM_INVALID_IMPORTS -26
#define AMAL_PROGRAM_SECTION_ERROR -27
-#define AMAL_PROGRAM_ARGS_SIZE_VARARGS -1
-
#define AMAL_PROGRAM_MAX_RETURN_VALUES 128
typedef struct {
void *func;
- int args_byte_size; /* -1 if varargs (AMAL_PROGRAM_ARGS_SIZE_VARARGS) */
+ u32 args_byte_size;
} ProgramExternFunc;
typedef struct {
@@ -81,9 +79,10 @@ void amal_program_deinit(amal_program *self);
/*
returns @AMAL_PROGRAM_EXTERN_FUNC_ALREADY_EXISTS if a function with the name @name already exists
- in the program
+ in the program.
+ If the function has a vararg parameter, then @args_byte_size should be the minimum parameters size excluding the varargs.
*/
-CHECK_RESULT int amal_program_register_extern_func(amal_program *self, BufferView name, void *func_ptr, int args_byte_size);
+CHECK_RESULT int amal_program_register_extern_func(amal_program *self, BufferView name, void *func_ptr, u32 args_byte_size);
CHECK_RESULT int amal_program_append_bytecode(amal_program *self, Bytecode *bytecode);
CHECK_RESULT int amal_program_run(amal_program *self);
diff --git a/include/tokenizer.h b/include/tokenizer.h
index b6b401b..53351a4 100644
--- a/include/tokenizer.h
+++ b/include/tokenizer.h
@@ -40,7 +40,9 @@ typedef enum {
TOK_WHILE,
TOK_EXTERN,
TOK_EXPORT,
- TOK_RETURN
+ TOK_RETURN,
+ TOK_QUESTION_MARK,
+ TOK_C_VARARGS
} Token;
struct Tokenizer {