From cdb3baaca3413897f2470be8c9e77ae4412e87fb Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sun, 16 Jun 2024 13:37:25 -0700 Subject: [PATCH] Work on windows. --- examples/sysir/run_samples.bat | 4 ++++ examples/sysir/samples.janet | 4 ++-- src/core/sysir.c | 4 ++-- src/core/sysir_x86.c | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 examples/sysir/run_samples.bat diff --git a/examples/sysir/run_samples.bat b/examples/sysir/run_samples.bat new file mode 100644 index 00000000..d75243a5 --- /dev/null +++ b/examples/sysir/run_samples.bat @@ -0,0 +1,4 @@ +janet.exe examples/sysir/samples.janet > temp.nasm +nasm -fwin64 temp.nasm -l temp.lst -o temp.o +link temp.o legacy_stdio_definitions.lib msvcrt.lib /out:temp.exe +temp.exe diff --git a/examples/sysir/samples.janet b/examples/sysir/samples.janet index 819d5fc9..8a495d00 100644 --- a/examples/sysir/samples.janet +++ b/examples/sysir/samples.janet @@ -32,8 +32,8 @@ (return x))) (def main-fn - '(defn _start:void [] - (syscall 1 1 "Hello, world!\n" 14) + '(defn WinMain:void [] + #(syscall 1 1 "Hello, world!\n" 14) (doloop 10 20) (exit (the int 0)) (return))) diff --git a/src/core/sysir.c b/src/core/sysir.c index f0a08791..0ba5b667 100644 --- a/src/core/sysir.c +++ b/src/core/sysir.c @@ -287,7 +287,7 @@ static uint32_t instr_read_type_operand(Janet x, JanetSysIR *ir, ReadOpMode rmod return (uint32_t) n; } else if (rmode == READ_TYPE_FORWARD_REF) { uint32_t operand = linkage->type_def_count++; - janet_table_put(linkage->type_name_lookup, x, janet_wrap_number(-operand - 1)); + janet_table_put(linkage->type_name_lookup, x, janet_wrap_number(-(int64_t)operand - 1)); return operand; } else if (rmode == READ_TYPE_DEFINITION) { uint32_t operand = linkage->type_def_count++; @@ -1600,7 +1600,7 @@ void janet_sys_ir_lower_to_ir(JanetSysIRLinkage *linkage, JanetArray *into) { build_tuple[0] = janet_csymbolv("type-array"); build_tuple[1] = janet_sys_get_desttype(linkage, instruction.array.dest_type); build_tuple[2] = janet_sys_get_desttype(linkage, instruction.array.type); - build_tuple[4] = janet_wrap_number(instruction.array.fixed_count); + build_tuple[4] = janet_wrap_number((double) instruction.array.fixed_count); break; } const Janet *tuple = janet_tuple_end(build_tuple); diff --git a/src/core/sysir_x86.c b/src/core/sysir_x86.c index bcbdb680..f70c5756 100644 --- a/src/core/sysir_x86.c +++ b/src/core/sysir_x86.c @@ -585,8 +585,8 @@ void janet_sys_ir_lower_to_x64(JanetSysIRLinkage *linkage, JanetBuffer *buffer) sysemit_operand(&ctx, instruction.branch.cond, ", 0\n"); janet_formatb(buffer, "%s label_%d_%u\n", - instruction.opcode == JANET_SYSOP_BRANCH ? "jnz " : "jz ", - i, instruction.branch.to); + instruction.opcode == JANET_SYSOP_BRANCH ? "jnz" : "jz", + i, (uint64_t) instruction.branch.to); break; case JANET_SYSOP_JUMP: janet_formatb(buffer, "jmp label_%d_%u\n", i, instruction.jump.to);