stage0 重命名 stage1 ast重新整理

This commit is contained in:
zzy
2026-08-16 10:51:45 +08:00
parent 78d767bf21
commit d3c63dab5c
6 changed files with 27 additions and 21 deletions

View File

@@ -54,7 +54,7 @@ int main(int argc, const char **argv) {
spl_vm_ins_t *ins = &vec_at(prog.insns, i);
printf("%4zd: %s", i, spl_vm_opcode_name((spl_vm_opcode_t)ins->opcode));
if (ins->type != SPL_VOID)
printf(" %s", spl_vm_type_kind_name((spl_type_t)ins->type));
printf(" %s", spl_vm_type_kind_name((spl_vm_kind_t)ins->type));
printf(" %zd", ins->imm);
/* annotate jumps / calls */

View File

@@ -427,7 +427,7 @@ const char *opcode_name[] = {
#undef X
};
const char *spl_vm_opcode_name(spl_vm_opcode_t opcode) { return opcode_name[opcode]; }
const char *spl_vm_type_kind_name(spl_type_t type) {
const char *spl_vm_type_kind_name(spl_vm_kind_t type) {
switch (type) {
case SPL_VOID:
return "void";
@@ -467,7 +467,7 @@ const char *spl_vm_type_kind_name(spl_type_t type) {
void spl_vm_ins_dump(spl_vm_ins_t *ins, spl_vm_val_t addr) {
printf("%4zu: %s", addr, spl_vm_opcode_name((spl_vm_opcode_t)ins->opcode));
if (ins->type != SPL_VOID)
printf(" %s", spl_vm_type_kind_name((spl_type_t)ins->type));
printf(" %s", spl_vm_type_kind_name((spl_vm_kind_t)ins->type));
printf(" %zd:%zx", ins->imm, ins->imm);
printf("\n");
}

View File

@@ -29,7 +29,7 @@ typedef enum {
SPL_F64,
SPL_PTR,
SPL_TYPE_COUNT,
} spl_type_t;
} spl_vm_kind_t;
/* clang-format off */
#define SPL_OPCODES(X) \
@@ -213,7 +213,7 @@ spl_vm_native_t *spl_prog_get_native(spl_prog_t *prog, const char *name);
/* Opcode name lookup for debugging/dumping */
const char *spl_vm_opcode_name(spl_vm_opcode_t opcode);
const char *spl_vm_type_kind_name(spl_type_t type);
const char *spl_vm_type_kind_name(spl_vm_kind_t type);
void spl_vm_ins_dump(spl_vm_ins_t *ins, spl_vm_val_t addr);

View File

@@ -28,8 +28,8 @@
* Type helpers
* ================================================================ */
static int spl_is_float(spl_type_t t) { return t == SPL_F32 || t == SPL_F64; }
static int spl_is_signed(spl_type_t t) {
static int spl_is_float(spl_vm_kind_t t) { return t == SPL_F32 || t == SPL_F64; }
static int spl_is_signed(spl_vm_kind_t t) {
switch (t) {
case SPL_I8:
case SPL_I16:
@@ -41,7 +41,7 @@ static int spl_is_signed(spl_type_t t) {
return 0;
}
}
static int spl_type_size(spl_type_t t) {
static int spl_type_size(spl_vm_kind_t t) {
switch (t) {
case SPL_VOID:
return 0;
@@ -123,7 +123,7 @@ static int spl_type_size(spl_type_t t) {
do { \
spl_vm_val_t _b = POP(), _a = POP(); \
spl_vm_val_t _r = 0; \
if (spl_is_float((spl_type_t)ins->type)) { \
if (spl_is_float((spl_vm_kind_t)ins->type)) { \
double _da, _db, _dr; \
if (ins->type == SPL_F32) { \
float _fa, _fb; \
@@ -185,7 +185,7 @@ static int spl_type_size(spl_type_t t) {
if (_b == 0) \
VM_ERROR("division by zero"); \
spl_vm_val_t _r = 0; \
if (spl_is_float((spl_type_t)ins->type)) { \
if (spl_is_float((spl_vm_kind_t)ins->type)) { \
double _da, _db, _dr; \
if (ins->type == SPL_F32) { \
float _fa, _fb; \
@@ -545,6 +545,7 @@ LONG WINAPI UnhandledExceptionFilterImpl(EXCEPTION_POINTERS *pExceptionInfo) {
* ================================================================ */
void spl_vm_init_ex(spl_vm_t *vm, int stack_size, int call_depth) {
#ifdef _WIN32
SetErrorMode(SEM_FAILCRITICALERRORS);
SetUnhandledExceptionFilter(UnhandledExceptionFilterImpl);
SetConsoleOutputCP(CP_UTF8);
SetConsoleCP(CP_UTF8);
@@ -843,7 +844,7 @@ int spl_vm_run_once(spl_vm_t *vm) {
case SPL_NEG: {
spl_vm_val_t _a = POP();
if (spl_is_float((spl_type_t)ins->type)) {
if (spl_is_float((spl_vm_kind_t)ins->type)) {
double _d;
if (ins->type == SPL_F32) {
float _f;