-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split
src/eval/eval.h
to separate Ast
from IR
- create `src/eval/ast.h`, `src/eval/ir.h`, `src/eval/common.h` - introduce a macro `MATCH_TYPED_UNION` for easier pattern matching of tagged unions - move src/funcs/funcs.* to src/runtime/runtime.*
- Loading branch information
Showing
22 changed files
with
1,961 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#ifndef IR_H | ||
#define IR_H | ||
|
||
#include "src/eval/eval.h" | ||
|
||
struct IR_Node; | ||
struct Eval_Context; | ||
|
||
typedef struct IR_Node (*func_t)(struct IR_Node *left, struct IR_Node *right); | ||
|
||
typedef enum IR_Type { | ||
IR_Type_None = 0, | ||
IR_Type_Array, | ||
IR_Type_Monad, | ||
IR_Type_Dyad, | ||
IR_Type_Assign, | ||
IR_Type_Function, | ||
} IR_Type; | ||
|
||
typedef struct IR_Node { | ||
IR_Type type; | ||
Element_Type eval_type; | ||
u64 ref_count; | ||
union { | ||
Array *array; | ||
func_t function; | ||
char identifier[16]; | ||
struct { | ||
Node_Handle left; | ||
Node_Handle right; | ||
Node_Handle callee; | ||
} args; | ||
} as; | ||
} IR_Node; | ||
|
||
|
||
#endif // IR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#ifndef AST_H | ||
#define AST_H | ||
|
||
#include "lib/format/types.h" | ||
#include "lib/string/types.h" | ||
|
||
#include "common.h" | ||
|
||
#include "src/array/array.h" | ||
|
||
typedef enum Ast_Type { | ||
Ast_Type_None = 0, | ||
Ast_Type_Array_Ptr, | ||
Ast_Type_Monadic, | ||
Ast_Type_Dyadic, | ||
Ast_Type_Assignment, | ||
Ast_Type_Identifier, | ||
} Ast_Type; | ||
|
||
typedef Array * Array_Ptr; | ||
typedef struct { Node_Handle func, right; } Monadic; | ||
typedef struct { Node_Handle func, left, right; } Dyadic; | ||
typedef struct { Node_Handle left, right; } Assignment; | ||
typedef Short_String Identifier; | ||
|
||
struct Ast_Node { | ||
Ast_Type type; | ||
union { | ||
Array_Ptr as_Array_Ptr; | ||
Monadic as_Monadic; | ||
Dyadic as_Dyadic; | ||
Assignment as_Assignment; | ||
Identifier as_Identifier; | ||
}; | ||
}; | ||
|
||
// variant: a possible type in struct `Ast_Node`'s anonymous union. | ||
// bind_name: an identifier | ||
// expression: a value of type `Ast_Node` | ||
// | ||
// introduces a case statement for the corresponding `Ast_Type` value, | ||
// and declares a variable `bind_name` initialized to the specified | ||
// union value of `expression` | ||
#define MATCH_AST(variant, bind_name, expression) MATCH_TYPED_UNION(Ast_Type_, variant, bind_name, expression, type) | ||
|
||
// variant: a possible type in struct `Ast_Node`'s anonymous union. | ||
// bind_name: an identifier | ||
// expression: a value of type `Ast_Node` | ||
// | ||
// introduces a case statement for the corresponding `Ast_Type` value, | ||
// and declares a variable `bind_name` initialized to a pointer to the | ||
// specified union value of `expression` | ||
#define REF_MATCH_AST(variant, bind_name, expression) REF_MATCH_TYPED_UNION(Ast_Type_, bind_name, variant, expression, type) | ||
|
||
#endif // AST_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef COMMON_H | ||
#define COMMON_H | ||
|
||
#include "lib/builtin.h" | ||
|
||
typedef i32 Node_Handle; | ||
|
||
typedef struct Ast_Node Ast_Node; | ||
typedef struct IR_Node IR_Node; | ||
typedef struct Eval_Context Eval_Context; | ||
typedef struct Lookup_Scope Lookup_Scope; | ||
|
||
typedef IR_Node (*func_t)(IR_Node *left, IR_Node *right); | ||
|
||
#endif // COMMON_H |
Oops, something went wrong.