/* Aplwc - A Programming Language With Constraints * * Copyright (C) 2026 Peter Mikkelsen * * This file is part of aplwc. * * Aplwc is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Aplwc is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with aplwc. If not, see . */ #ifndef APLWC_INTERNAL_H #define APLWC_INTERNAL_H #include #include #include enum aplwc_token_tag { APLWC_TOKEN_SYSCMD, APLWC_TOKEN_SYSCMD_ARGS, APLWC_TOKEN_ERROR, }; enum aplwc_ast_tag { APLWC_AST_SYSCMD, APLWC_AST_ERROR, }; enum aplwc_instr_tag { APLWC_INSTR_SYSCMD_CALL, APLWC_INSTR_ERROR, APLWC_INSTR_END, }; struct aplwc { void *(*alloc)(size_t); void (*free)(void *); void *(*realloc)(void *, size_t); struct aplwc_syscmd **syscmds; int n_syscmds; bool running; }; struct aplwc_eval_context { struct aplwc *aplwc; char *text; size_t offset; size_t length; size_t n_tokens; struct aplwc_token **tokens; size_t token_offset; struct aplwc_ast *ast; struct aplwc_instrs *instrs; }; struct aplwc_token { enum aplwc_token_tag tag; size_t offset_start; size_t offset_end; union { } data; }; struct aplwc_ast { enum aplwc_ast_tag tag; union { struct { struct aplwc_syscmd *syscmd; char *args; } syscmd; } data; }; struct aplwc_instrs { size_t n_instrs; uint64_t *instrs; }; struct aplwc_instr { int type; enum aplwc_instr_tag op; uint64_t encoded; }; struct aplwc_syscmd *aplwc_lookup_syscmd(struct aplwc *, const char *); struct aplwc_eval_context *aplwc_new_eval_context(struct aplwc *); void aplwc_scan_line(struct aplwc_eval_context *, const char *); void aplwc_parse(struct aplwc_eval_context *); void aplwc_compile(struct aplwc_eval_context *); void aplwc_eval(struct aplwc_eval_context *); void aplwc_free_eval_context(struct aplwc_eval_context *); void aplwc_free_ast(struct aplwc *, struct aplwc_ast *); char *aplwc_strdup(struct aplwc *, const char *); void aplwc_output(struct aplwc *, const char *, ...); void aplwc_voutput(struct aplwc *, const char *, va_list); void aplwc_encode_instr(struct aplwc_instr *); void aplwc_decode_instr(struct aplwc_instr *); #endif /* APLWC_INTERNAL_H */