From c9305a0a424a592b3c5cf5789eb1e09e0e68f018 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Fri, 11 Apr 2025 22:44:36 -0500 Subject: [PATCH] Format. --- src/core/sysir.c | 73 +++++++++++++++++++++----------------------- src/core/sysir_x86.c | 26 ++++++++-------- 2 files changed, 49 insertions(+), 50 deletions(-) diff --git a/src/core/sysir.c b/src/core/sysir.c index 59d79ea5..0e913bd9 100644 --- a/src/core/sysir.c +++ b/src/core/sysir.c @@ -1087,47 +1087,44 @@ static int check_const_valid(JanetSysIR *sysir, Janet constant, uint32_t t) { switch (janet_type(constant)) { default: return 0; - case JANET_TUPLE: - { - const Janet *elements = janet_unwrap_tuple(constant); - int32_t len = janet_tuple_length(elements); - if (p != JANET_PRIM_ARRAY) return 0; - if ((uint64_t) len != tinfo->array.fixed_count) return 0; - for (int32_t i = 0; i < len; i++) { - if (!check_const_valid(sysir, elements[i], tinfo->array.type)) return 0; - } - return 1; + case JANET_TUPLE: { + const Janet *elements = janet_unwrap_tuple(constant); + int32_t len = janet_tuple_length(elements); + if (p != JANET_PRIM_ARRAY) return 0; + if ((uint64_t) len != tinfo->array.fixed_count) return 0; + for (int32_t i = 0; i < len; i++) { + if (!check_const_valid(sysir, elements[i], tinfo->array.type)) return 0; } + return 1; + } case JANET_BOOLEAN: return p == JANET_PRIM_BOOLEAN; case JANET_STRING: case JANET_SYMBOL: case JANET_POINTER: return p == JANET_PRIM_POINTER; - case JANET_NUMBER: - { - double x = janet_unwrap_number(constant); - if (p == JANET_PRIM_F64) return 1; - if (p == JANET_PRIM_F32) return 1; - if (x != floor(x)) return 0; /* Filter out non-integers */ - if (p == JANET_PRIM_U8 && (x >= 0 && x <= UINT8_MAX)) return 1; - if (p == JANET_PRIM_S8 && (x >= INT8_MIN && x <= INT8_MAX)) return 1; - if (p == JANET_PRIM_U16 && (x >= 0 && x <= UINT16_MAX)) return 1; - if (p == JANET_PRIM_S16 && (x >= INT16_MIN && x <= INT16_MAX)) return 1; - if (p == JANET_PRIM_U32 && (x >= 0 && x <= UINT32_MAX)) return 1; - if (p == JANET_PRIM_S32 && (x >= INT32_MIN && x <= INT32_MAX)) return 1; - if (p == JANET_PRIM_U64 && (x >= 0 && x <= UINT64_MAX)) return 1; - if (p == JANET_PRIM_S64 && (x >= INT64_MIN && x <= INT64_MAX)) return 1; - return 0; - } - case JANET_ABSTRACT: - { - void *point = janet_unwrap_abstract(constant); - const JanetAbstractType *at = janet_abstract_type(point); - if (at == &janet_s64_type && p == JANET_PRIM_S64) return 1; - if (at == &janet_u64_type && p == JANET_PRIM_U64) return 1; - return 0; - } + case JANET_NUMBER: { + double x = janet_unwrap_number(constant); + if (p == JANET_PRIM_F64) return 1; + if (p == JANET_PRIM_F32) return 1; + if (x != floor(x)) return 0; /* Filter out non-integers */ + if (p == JANET_PRIM_U8 && (x >= 0 && x <= UINT8_MAX)) return 1; + if (p == JANET_PRIM_S8 && (x >= INT8_MIN && x <= INT8_MAX)) return 1; + if (p == JANET_PRIM_U16 && (x >= 0 && x <= UINT16_MAX)) return 1; + if (p == JANET_PRIM_S16 && (x >= INT16_MIN && x <= INT16_MAX)) return 1; + if (p == JANET_PRIM_U32 && (x >= 0 && x <= UINT32_MAX)) return 1; + if (p == JANET_PRIM_S32 && (x >= INT32_MIN && x <= INT32_MAX)) return 1; + if (p == JANET_PRIM_U64 && (x >= 0 && x <= UINT64_MAX)) return 1; + if (p == JANET_PRIM_S64 && (x >= INT64_MIN && x <= INT64_MAX)) return 1; + return 0; + } + case JANET_ABSTRACT: { + void *point = janet_unwrap_abstract(constant); + const JanetAbstractType *at = janet_abstract_type(point); + if (at == &janet_s64_type && p == JANET_PRIM_S64) return 1; + if (at == &janet_u64_type && p == JANET_PRIM_U64) return 1; + return 0; + } } } @@ -1421,8 +1418,8 @@ static uint32_t janet_sysir_findprim(JanetSysIRLinkage *linkage, JanetPrim prim, td.prim = prim; janet_v_push(linkage->type_defs, td); janet_table_put(linkage->type_name_lookup, - janet_csymbolv(type_name), - janet_wrap_number(linkage->type_def_count)); + janet_csymbolv(type_name), + janet_wrap_number(linkage->type_def_count)); janet_v_push(linkage->type_names, janet_csymbol(type_name)); return linkage->type_def_count++; } @@ -1443,8 +1440,8 @@ static uint32_t janet_sysir_findpointer(JanetSysIRLinkage *linkage, uint32_t to, td.pointer.type = to; janet_v_push(linkage->type_defs, td); janet_table_put(linkage->type_name_lookup, - janet_csymbolv(type_name), - janet_wrap_number(linkage->type_def_count)); + janet_csymbolv(type_name), + janet_wrap_number(linkage->type_def_count)); janet_v_push(linkage->type_names, janet_csymbol(type_name)); return linkage->type_def_count++; } diff --git a/src/core/sysir_x86.c b/src/core/sysir_x86.c index ac6cc0fc..683ab59d 100644 --- a/src/core/sysir_x86.c +++ b/src/core/sysir_x86.c @@ -189,7 +189,7 @@ void assign_registers(JanetSysx64Context *ctx) { /* TODO - move into sysir.c and allow reuse for multiple targets */ JanetSysCallingConvention cc = ctx->calling_convention; - + /* Make trivial assigments */ uint32_t next_loc = 16; ctx->regs = janet_smalloc(ctx->ir->register_count * sizeof(x64Reg)); @@ -234,7 +234,7 @@ void assign_registers(JanetSysx64Context *ctx) { janet_panic("cannot assign registers for calling convention"); } } else if (assigned < 0xFFFF) { - //} else if (assigned < 1) { + //} else if (assigned < 1) { /* Assign to register */ uint32_t to = 0; while ((1 << to) & assigned) to++; @@ -311,13 +311,13 @@ static void i_chunk(JanetSysx64Context *C, InstrChunk c) { /* Emit one x86_64 instruction given all of the individual components */ static void i_combine(JanetSysx64Context *C, - InstrChunk prefix, - uint16_t opcode, - InstrChunk mod_reg_rm, - InstrChunk scaled_index, - InstrChunk displacement, - InstrChunk immediate, - const char *msg) { + InstrChunk prefix, + uint16_t opcode, + InstrChunk mod_reg_rm, + InstrChunk scaled_index, + InstrChunk displacement, + InstrChunk immediate, + const char *msg) { assert(mod_reg_rm.bytes < 3); assert(scaled_index.bytes < 2); assert(opcode < 512); @@ -363,12 +363,14 @@ static void e_mov_to_reg(JanetSysx64Context *ctx, x64Reg d, x64Reg s, MoveMode m return; } if (mm == MOV_LOAD || s.storage != JANET_SYSREG_REGISTER) { - x64Reg t = d; d = s; s = t; /* swap */ + x64Reg t = d; + d = s; + s = t; /* swap */ flip = 1; } assert(s.storage == JANET_SYSREG_REGISTER); opcode = 0x88; - mod_rm |= (uint8_t) (s.index & 7) << 3; + mod_rm |= (uint8_t)(s.index & 7) << 3; if (s.index >= 8) rex |= REX_R; if (s.kind >= JANET_SYSREG_64) rex |= REX_W; if (d.storage == JANET_SYSREG_REGISTER) { @@ -376,7 +378,7 @@ static void e_mov_to_reg(JanetSysx64Context *ctx, x64Reg d, x64Reg s, MoveMode m if (mm == MOV_FLAT) { mod_rm |= 0xC0u; /* mod = b11, reg, reg mode */ } - mod_rm |= (uint8_t) (d.index & 7); + mod_rm |= (uint8_t)(d.index & 7); } else { assert(mm == MOV_FLAT); /* d is memory */