code wiki / (root) / nx_codon_test.nx

nx_codon_test.nx source

↩ module page · 64 lines · 2601 B

1// nx_codon_test.nx -- smoke for nx_codon. 2 3import "nx_syscalls.nx" 4import "nx_tier.nx" 5import "nx_ribosome.nx" 6import "nx_codon.nx" 7 8func main() -> i64 { 9 // 1: op enum sealed 10 if NX_OP_N_OPS != 14 { return 1 } 11 if nx_op_is_valid(NX_OP_ADD) != 1 { return 2 } 12 if nx_op_is_valid(NX_OP_RET) != 1 { return 3 } 13 if nx_op_is_valid(14) != 0 { return 4 } 14 15 // 2: stream construction 16 let s: *NxCodonStream = nx_codon_stream_new(16) 17 if s.capacity != 16 { return 5 } 18 if s.count != 0 { return 6 } 19 20 // 3: emit canonical sequence 21 if nx_codon_emit(s, NX_OP_LOAD, 0, 0, NX_RBT_N_TARGETS) != NX_CODON_OK { return 7 } 22 if nx_codon_emit(s, NX_OP_ADD, 1, 2, NX_RBT_N_TARGETS) != NX_CODON_OK { return 8 } 23 if nx_codon_emit(s, NX_OP_STORE, 3, 0, NX_RBT_N_TARGETS) != NX_CODON_OK { return 9 } 24 if nx_codon_emit(s, NX_OP_RET, 0, 0, NX_RBT_N_TARGETS) != NX_CODON_OK { return 10 } 25 if s.count != 4 { return 11 } 26 if nx_codon_stream_length(s) != 4 { return 12 } 27 28 // 4: bad op rejected 29 if nx_codon_emit(s, 99, 0, 0, NX_RBT_N_TARGETS) != NX_CODON_ERR_BAD_OP { return 13 } 30 31 // 5: explicit target hint 32 if nx_codon_emit(s, NX_OP_MUL, 4, 5, NX_RBT_PTX) != NX_CODON_OK { return 14 } 33 let c: *NxCodon = nx_codon_at(s, 4) 34 if c.target_hint != NX_RBT_PTX { return 15 } 35 36 // 6: bad target hint refused 37 if nx_codon_emit(s, NX_OP_ADD, 0, 0, 99) != NX_CODON_ERR_BAD_TARG { return 16 } 38 39 // 7: count by op 40 if nx_codon_count_by_op(s, NX_OP_ADD) != 1 { return 17 } 41 if nx_codon_count_by_op(s, NX_OP_LOAD) != 1 { return 18 } 42 if nx_codon_count_by_op(s, NX_OP_RET) != 1 { return 19 } 43 if nx_codon_count_by_op(s, NX_OP_NOP) != 0 { return 20 } 44 45 // 8: resolve_target with hint falls through to tier default 46 let codon_0_target: nx_int = nx_codon_resolve_target(s, 0, NX_TIER_MCU) 47 if codon_0_target != NX_RBT_CORTEX_M { return 21 } 48 let codon_0_target2: nx_int = nx_codon_resolve_target(s, 0, NX_TIER_WORKSTATION) 49 if codon_0_target2 != NX_RBT_X86_64 { return 22 } 50 51 // 9: resolve_target with explicit hint returns the hint 52 if nx_codon_resolve_target(s, 4, NX_TIER_MCU) != NX_RBT_PTX { return 23 } 53 54 // 10: out-of-range resolve 55 if nx_codon_resolve_target(s, 99, NX_TIER_WORKSTATION) != NX_RBT_X86_64 { return 24 } 56 57 // 11: FULL 58 let small: *NxCodonStream = nx_codon_stream_new(2) 59 nx_codon_emit(small, NX_OP_NOP, 0, 0, NX_RBT_N_TARGETS) 60 nx_codon_emit(small, NX_OP_NOP, 0, 0, NX_RBT_N_TARGETS) 61 if nx_codon_emit(small, NX_OP_NOP, 0, 0, NX_RBT_N_TARGETS) != NX_CODON_ERR_FULL { return 25 } 62 63 return 0 64}