impl scopes more or less properly
This commit is contained in:
@@ -30,22 +30,22 @@ typedef enum e_NodeKind {
|
||||
|
||||
typedef struct s_Node Node;
|
||||
typedef struct s_Nodes Nodes;
|
||||
typedef struct s_Scopes Scopes;
|
||||
|
||||
typedef Node *(*lisp_function_ptr)(Nodes *args);
|
||||
typedef struct s_LispFunction {
|
||||
Nob_String_View name;
|
||||
lisp_function_ptr apply;
|
||||
} LispFunction;
|
||||
typedef Node *(*LispFunction)(Nodes *args, Scopes *scopes);
|
||||
|
||||
typedef struct s_Node {
|
||||
struct s_Node {
|
||||
NodeKind kind;
|
||||
union {
|
||||
Nob_String_View as_symbol;
|
||||
Nodes *as_list;
|
||||
long long as_number;
|
||||
LispFunction as_function;
|
||||
struct {
|
||||
Nob_String_View name;
|
||||
LispFunction apply;
|
||||
} as_function;
|
||||
};
|
||||
} Node;
|
||||
};
|
||||
|
||||
struct s_Nodes {
|
||||
Node *items;
|
||||
@@ -53,14 +53,34 @@ struct s_Nodes {
|
||||
size_t capacity;
|
||||
};
|
||||
|
||||
typedef struct s_ScopeObject {
|
||||
Nob_String_View name;
|
||||
Node node;
|
||||
} ScopeObject;
|
||||
|
||||
// TODO: use hashtable
|
||||
typedef struct s_Scope {
|
||||
ScopeObject *items;
|
||||
size_t count;
|
||||
size_t capacity;
|
||||
} Scope;
|
||||
|
||||
struct s_Scopes {
|
||||
Scope *items;
|
||||
size_t count;
|
||||
size_t capacity;
|
||||
};
|
||||
|
||||
const char *token_kind_name(TokenKind kind);
|
||||
void node_print(Node node);
|
||||
|
||||
void build_scopes(Scopes *scopes);
|
||||
void tokenize(Nob_String_View content, Tokens *tokens);
|
||||
Node *parse(Tokens *tokens);
|
||||
Node *eval(Node *node);
|
||||
Node *eval(Node *node, Scopes *scopes);
|
||||
|
||||
// builtins
|
||||
Node *lisp_function_addition(Nodes *args);
|
||||
Node *lisp_function_addition(Nodes *args, Scopes *scopes);
|
||||
Node *lisp_function_println(Nodes *args, Scopes *scopes);
|
||||
|
||||
#endif // LISP_H
|
||||
|
||||
Reference in New Issue
Block a user