51 lines
1.4 KiB
C
51 lines
1.4 KiB
C
#include "../log.h"
|
|
#include "../util.h"
|
|
#include "ast.h"
|
|
|
|
struct FuncDef {
|
|
void (*func)(struct VStack *, int);
|
|
const char *name;
|
|
// enum ArgType *args;
|
|
};
|
|
struct OpDef {
|
|
struct PawStackVal (*op)(struct PawStackVal, struct PawStackVal);
|
|
const char *sym;
|
|
int importance;
|
|
// enum ArgType *args;
|
|
};
|
|
|
|
struct FuncDef PAW_CFUNCS[] = {
|
|
{print, "io::print"},
|
|
};
|
|
|
|
// important to unimportant!!!
|
|
struct OpDef PAW_OPS[] = {
|
|
{op_equals, "==", 0}, {op_unequals, "!=", 0}, {NULL, "*", 2},
|
|
{NULL, "/", 2}, {op_add, "+", 1}, {NULL, "-", 1},
|
|
};
|
|
|
|
uint32_t paw_get_ops_size() { return sizeof(PAW_OPS); }
|
|
const char *paw_get_op_sym(uint32_t index) { return PAW_OPS[index].sym; }
|
|
int paw_get_op_importance(uint32_t index) { return PAW_OPS[index].importance; }
|
|
|
|
uint32_t paw_get_op_index(char *sym) {
|
|
for (int i = 0; i < sizeof(PAW_OPS) / sizeof(PAW_OPS[0]); i++) {
|
|
if (strcmp(sym, PAW_OPS[i].sym) == 0) {
|
|
return i;
|
|
}
|
|
}
|
|
meow("could not find op %s, returning %d", sym, UINT32_NULL);
|
|
return UINT32_NULL;
|
|
}
|
|
void *paw_get_op(uint32_t index) { return PAW_OPS[index].op; }
|
|
|
|
uint32_t paw_get_cfunc_index(char *name) {
|
|
for (int i = 0; i < sizeof(PAW_CFUNCS) / sizeof(PAW_CFUNCS[0]); i++) {
|
|
if (strcmp(name, PAW_CFUNCS[i].name) == 0) {
|
|
return i;
|
|
}
|
|
}
|
|
meow("could not find cfunc %s, returning %d", name, UINT32_NULL);
|
|
return UINT32_NULL;
|
|
}
|
|
void *paw_get_cfunc(uint32_t index) { return PAW_CFUNCS[index].func; }
|