diff options
author | Flavian Kaufmann <flavian@flaviankaufmann.ch> | 2025-05-20 11:31:50 +0200 |
---|---|---|
committer | Flavian Kaufmann <flavian@flaviankaufmann.ch> | 2025-05-20 11:31:50 +0200 |
commit | 9cf524df8c94920d7c7058692f2f83a95a4006e0 (patch) | |
tree | 526853cc7f935745bf703cbfaf7e5ebe7d32017e /include | |
parent | 3829a704150a06b2767d542b39179377a592da0f (diff) | |
download | imp-9cf524df8c94920d7c7058692f2f83a95a4006e0.tar.gz imp-9cf524df8c94920d7c7058692f2f83a95a4006e0.zip |
hashmap for context
Diffstat (limited to 'include')
-rw-r--r-- | include/ast.h | 4 | ||||
-rw-r--r-- | include/hash_map.h | 3 | ||||
-rw-r--r-- | include/interpreter.h | 12 |
3 files changed, 9 insertions, 10 deletions
diff --git a/include/ast.h b/include/ast.h index 9c6b6bd..c619c72 100644 --- a/include/ast.h +++ b/include/ast.h @@ -1,6 +1,7 @@ #ifndef AST_H #define AST_H + typedef enum { NT_SKIP, NT_ASSIGN, NT_SEQ, NT_IF, NT_WHILE, NT_INT, NT_VAR, NT_AOP, NT_BOP, NT_NOT, NT_ROP @@ -26,6 +27,7 @@ typedef struct ASTNode { } u; } ASTNode; + ASTNode *ast_skip(void); ASTNode *ast_assign(ASTNode *var, ASTNode *aexp); ASTNode *ast_seq(ASTNode *stm1, ASTNode *stm2); @@ -38,7 +40,7 @@ ASTNode *ast_bop(BOp bop, ASTNode *bexp1, ASTNode *bexp2); ASTNode *ast_not(ASTNode *bexp); ASTNode *ast_rop(ROp rop, ASTNode *aexp1, ASTNode *aexp2); -void free_ast(ASTNode *node); +void ast_free(ASTNode *node); #endif diff --git a/include/hash_map.h b/include/hash_map.h index ad873f8..6bc733f 100644 --- a/include/hash_map.h +++ b/include/hash_map.h @@ -1,12 +1,13 @@ #ifndef HASH_MAP_H #define HASH_MAP_H -typedef void *hashmap_t; +typedef struct HashMap *hashmap_t; hashmap_t hashmap_create(void); void hashmap_insert(hashmap_t map, const char *key, int value); int *hashmap_get(hashmap_t map, const char *key); void hashmap_delete(hashmap_t map, const char *key); void hashmap_free(hashmap_t map); +void hashmap_iterate(hashmap_t map, void (*callback)(const char *key, int value)); #endif
\ No newline at end of file diff --git a/include/interpreter.h b/include/interpreter.h index 182f2e5..301a3d8 100644 --- a/include/interpreter.h +++ b/include/interpreter.h @@ -1,17 +1,13 @@ #ifndef INTERPRETER_H #define INTERPRETER_H -#include "ast.h" +#include "ast.h" +#include "hash_map.h" -typedef struct Env { - char *name; - int val; - struct Env *next; -} Env; -void exec_stmt(Env **env, ASTNode *node); -void env_print(Env *env); +void exec_stmt(hashmap_t context, ASTNode *node); +void context_print(hashmap_t context); #endif
\ No newline at end of file |