the codegen scope system has been removed. instead, each generator state in the stack, from the current state backwards, is informed when a variable is defined, resolved, or captured. when a variable is defined, the state stack is traversed back-to-front (current generator first). each state has a chance to record the variable definition. once one state has signalled that it has recorded the variable definition, the traversal ends. when a variable is resolved, the state stack is traversed back-to-front (current generator first). each state is asked whether or not it recognises the variable identifier being resolved. if a state has the variable in question defined, it returns information about the variable definition, and the traversal stops. once a variable has been resolved, the state stack is traversed front-to-back (current generator last), starting from the generator /after/ the one that provided the variable definition. each generator in the iteration is given the chance to adjust the variable information, or generate IR in response to the variable being accessed. this is used to implement variable capture, where the state of a variable in the enclosing context is captured for later use.
36 lines
827 B
C
36 lines
827 B
C
#ifndef CODEGEN_VAR_MAP_H_
|
|
#define CODEGEN_VAR_MAP_H_
|
|
|
|
#include <ivy/status.h>
|
|
|
|
struct b_hashmap;
|
|
struct mie_value;
|
|
struct ivy_ast_node;
|
|
|
|
enum codegen_var_flags {
|
|
CODEGEN_VAR_F_PTR = 0x01u,
|
|
CODEGEN_VAR_F_CAPTURE = 0x02u,
|
|
};
|
|
|
|
struct codegen_var {
|
|
enum codegen_var_flags v_flags;
|
|
struct mie_type *v_type;
|
|
struct ivy_ast_node *v_node;
|
|
struct mie_value *v_value;
|
|
};
|
|
|
|
struct codegen_var_map {
|
|
struct b_hashmap *m_map;
|
|
};
|
|
|
|
extern enum ivy_status codegen_var_map_init(struct codegen_var_map *map);
|
|
extern enum ivy_status codegen_var_map_fini(struct codegen_var_map *map);
|
|
|
|
extern enum ivy_status codegen_var_map_get(
|
|
struct codegen_var_map *map, const char *ident, struct codegen_var **out);
|
|
extern enum ivy_status codegen_var_map_put(
|
|
struct codegen_var_map *map, const char *ident,
|
|
const struct codegen_var *var);
|
|
|
|
#endif
|