#ifndef APLWC_INTERNAL_H #define APLWC_INTERNAL_H #include #include #include #include #include #include struct aplwc { struct aplwc_fns fns; enum aplwc_rc last_error; struct aplwc_module *modules; /* Memory management */ uint8_t *data; uint8_t *unaligned_data; size_t size; struct memory_ptr_frame *memptrs; struct root_ptr *rootptrs; }; struct memory_ptr_frame { struct memory_ptr_frame *link; void ***ptrs; size_t count; }; struct root_ptr { int id; void *ptr; struct root_ptr *link; }; struct aplwc_line { struct string *text; struct token_list *tokens; }; struct string { size_t bytes; size_t chars; uint8_t utf8[1]; }; enum token_tag { TOKEN_TAG_IDENTIFIER, TOKEN_TAG_NEWLINE, TOKEN_TAG_NUMBER, TOKEN_TAG_LEFT_ARROW, TOKEN_TAG_DIAMOND, TOKEN_TAG_KEYWORD, TOKEN_TAG_TEXT, TOKEN_TAG_DEL, TOKEN_TAG_LEFT_PAREN, TOKEN_TAG_RIGHT_PAREN, TOKEN_TAG_IBEAM, TOKEN_TAG_QUAD, TOKEN_TAG_UNKNOWN_SYM }; struct token { enum token_tag tag; size_t start; size_t end; }; struct token_list { struct string *text; size_t length; struct token tokens[1]; }; enum value_tag { VALUE_NULL, VALUE_NUMBER }; struct aplwc_value { enum value_tag tag; }; struct aplwc_module { struct string *name; struct token_list *tokens; struct aplwc_module *link; }; /* eval.c */ struct aplwc_value *eval_line(struct aplwc *, struct aplwc_line *); /* memory.c */ void memory_init(struct aplwc *); void memory_destroy(struct aplwc *); struct aplwc_line *memory_alloc_aplwc_line(struct aplwc *); struct string *memory_alloc_string(struct aplwc *, size_t); struct token_list *memory_alloc_token_list(struct aplwc *, size_t); struct aplwc_value *memory_alloc_aplwc_value(struct aplwc *); struct aplwc_module *memory_alloc_aplwc_module(struct aplwc *); struct module_imports *memory_alloc_module_imports(struct aplwc *, size_t); struct aplwc_ref memory_root_new(struct aplwc *, void *); void *memory_root_get(struct aplwc_ref); void memory_root_free(struct aplwc_ref); void memptrs_add(struct aplwc *, struct memory_ptr_frame *, void ***, size_t); void memptrs_remove(struct aplwc *, struct memory_ptr_frame *); void clear_ref(struct aplwc_ref *); int valid_ref(struct aplwc_ref); #define MEMPTRS(aplwc, n) \ void **memptrs[n]; \ struct memory_ptr_frame memptrs_frame; \ memptrs_add(aplwc, &memptrs_frame, memptrs, n); #define MEMPTR(n, ptr) memptrs[n] = (void **)&ptr #define MEMPTRS_EXIT(aplwc) memptrs_remove(aplwc, &memptrs_frame) /* string.c */ struct string *chars_to_string(struct aplwc *, const char *, int len); uint32_t string_char(struct string *, size_t); size_t char_length(struct string *, size_t); int string_compare(struct string *, struct string *); /* syntax.c */ struct token_list *scan_string(struct aplwc *, struct string *, int); enum aplwc_rc check_tokens(struct token_list *); /* module.c */ enum aplwc_rc load_module(struct aplwc *, struct string *, struct token_list *); struct aplwc_module *module_lookup(struct aplwc *, struct string *); struct string *module_imports_syms(struct module_imports *); #endif /* APLWC_INTERNAL_H */