diff options
author | Flavian Kaufmann <flavian@flaviankaufmann.ch> | 2025-05-21 14:05:27 +0200 |
---|---|---|
committer | Flavian Kaufmann <flavian@flaviankaufmann.ch> | 2025-05-21 14:05:27 +0200 |
commit | 8b6acc85633520f109d348c5e46c8a89521b3932 (patch) | |
tree | 1196ec5c493fd57937e7c84ca6ffb9f2d511b264 /include | |
parent | 442eba08dba74c3254a8d089ca1961147e59972b (diff) | |
download | imp-8b6acc85633520f109d348c5e46c8a89521b3932.tar.gz imp-8b6acc85633520f109d348c5e46c8a89521b3932.zip |
procedures
Diffstat (limited to 'include')
-rw-r--r-- | include/ast.h | 18 | ||||
-rw-r--r-- | include/hash_map.h | 13 | ||||
-rw-r--r-- | include/hashmap.h | 23 | ||||
-rw-r--r-- | include/interpreter.h | 19 | ||||
-rw-r--r-- | include/repl.h | 2 |
5 files changed, 53 insertions, 22 deletions
diff --git a/include/ast.h b/include/ast.h index 8482aab..2d25057 100644 --- a/include/ast.h +++ b/include/ast.h @@ -4,7 +4,8 @@ typedef enum { NT_SKIP, NT_ASSIGN, NT_SEQ, NT_IF, NT_WHILE, - NT_INT, NT_VAR, NT_AOP, NT_BOP, NT_NOT, NT_ROP, NT_LET + NT_INT, NT_VAR, NT_AOP, NT_BOP, NT_NOT, NT_ROP, NT_LET, + NT_PROCDECL, NT_PROCCALL } NodeType; typedef enum { AOP_ADD, AOP_SUB, AOP_MUL } AOp; @@ -25,9 +26,16 @@ typedef struct ASTNode { struct { struct ASTNode *bexp; } d_not; struct { ROp rop; struct ASTNode *aexp1, *aexp2; } d_rop; struct { struct ASTNode *var, *aexp, *stm; } d_let; + struct { char *name; struct ASTNodeList *args, *vargs; struct ASTNode *stm; } d_procdecl; + struct { char *name; struct ASTNodeList *args, *vargs; } d_proccall; } u; } ASTNode; +typedef struct ASTNodeList { + ASTNode *node; + struct ASTNodeList *next; +} ASTNodeList; + ASTNode *ast_skip(void); ASTNode *ast_assign(ASTNode *var, ASTNode *aexp); @@ -41,8 +49,14 @@ ASTNode *ast_bop(BOp bop, ASTNode *bexp1, ASTNode *bexp2); ASTNode *ast_not(ASTNode *bexp); ASTNode *ast_rop(ROp rop, ASTNode *aexp1, ASTNode *aexp2); ASTNode *ast_let(ASTNode *var, ASTNode *aexp, ASTNode *stm); +ASTNode *ast_procdecl(const char *name, ASTNodeList *args, ASTNodeList *vargs, ASTNode *stm); +ASTNode *ast_proccall(const char *name, ASTNodeList *args, ASTNodeList *vargs); + + +ASTNodeList *ast_node_list(ASTNode *node, ASTNodeList *list); +ASTNode *ast_clone(ASTNode *node); void ast_free(ASTNode *node); -#endif +#endif
\ No newline at end of file diff --git a/include/hash_map.h b/include/hash_map.h deleted file mode 100644 index 6bc733f..0000000 --- a/include/hash_map.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef HASH_MAP_H -#define HASH_MAP_H - -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/hashmap.h b/include/hashmap.h new file mode 100644 index 0000000..c62a319 --- /dev/null +++ b/include/hashmap.h @@ -0,0 +1,23 @@ +#ifndef HASHMAP_H +#define HASHMAP_H + + +typedef struct HashMap *hashmap_t; +typedef struct HashMapKeys *hashmap_keys_t; + + +hashmap_t hashmap_create(void); +void hashmap_free(hashmap_t map); + +void **hashmap_get(hashmap_t map, const char *key); +void hashmap_insert(hashmap_t map, const char *key, void *value); +int hashmap_delete(hashmap_t map, const char *key); + +void hashmap_iterate(hashmap_t map, void (*callback)(const char *key, void *value)); +hashmap_keys_t hashmap_keys_create(hashmap_t map); +const char *hashmap_keys_next(hashmap_keys_t iter); +void hashmap_keys_free(hashmap_keys_t iter); + + + +#endif
\ No newline at end of file diff --git a/include/interpreter.h b/include/interpreter.h index 6e60113..cb3ba75 100644 --- a/include/interpreter.h +++ b/include/interpreter.h @@ -3,17 +3,22 @@ #include "ast.h" -#include "hash_map.h" -void exec_stmt(hashmap_t context, ASTNode *node); -void context_print(hashmap_t context); +typedef struct Context *context_t; -void context_set(hashmap_t context, const char *name, int value); -int context_get(hashmap_t context, const char *name); -int exec_file (hashmap_t context, const char *path); -int exec_str (hashmap_t context, const char *str); +context_t context_create(void); +void context_free(context_t context); + +int context_get_var(context_t context, const char *name); +void context_set_var(context_t context, const char *name, int value); +void context_print_var_table(context_t context); +void context_print_proc_table(context_t context); + +void interp_ast(context_t context, ASTNode *node); +int interp_file (context_t context, const char *path); +int interp_str (context_t context, const char *str); #endif
\ No newline at end of file diff --git a/include/repl.h b/include/repl.h index 804b702..4b833ad 100644 --- a/include/repl.h +++ b/include/repl.h @@ -1,6 +1,8 @@ #ifndef REPL_H #define REPL_H + void repl(void); + #endif
\ No newline at end of file |