// SPDX-License-Identifier: Apache-2.0 ; specs/widgets/tc-instruction-word.t27 -- lesson 16 of the course "The ternary machine" (specs/course/ternary-computing.t27) ; Source of truth for public/widgets/tc-instruction-word/ (gHashTag/trinity): scripts/widget-pages-from-spec.mjs compiles this ; file, checks its constants, evaluates the tests below and writes the page; the page hands every constant to ; tool.js as window.T27_WIDGET. tool.js draws through ../ternary-kit.js and computes nothing: every number comes ; from public/widgets/tc-instruction-word/logic.js, the fn bodies of the gHashTag/t27 spec in logic.t27, compiled to wasm. ; ASCII only (L3), English only (LANG-EN). ; phi^2 + 1/phi^2 = 3 | TRINITY module widget_tc_instruction_word; pub const KIND : str = "widget-tool"; pub const ID : str = "tc-instruction-word"; pub const TITLE : str = "The TRI-27 instruction word, field by field"; pub const DESCRIPTION : str = "Pick an instruction and its registers. The emulator packs them into a 32-bit word: opcode, destination, sources or an immediate."; pub const IMAGE_ALT : str = "Instruction word card: ADD r1, r2, r3 as a 32-bit TRI-27 word, opcode 16 in bits 7..0, destination 1 in bits 12..8, the two sources above, each field underlined in its colour and decoded back."; pub const HOOK : str = "A ternary machine still ships 32-bit words: the trits live in the registers, the instruction is binary."; pub const CATEGORY : str = "compiler"; pub const DATA_SOURCES : [1]str = ["gHashTag/t27 specs/isa/ternary_encoding.t27: the TRI-27 instruction word as the pinned Trinity emulator decodes it (src/tri27/emu/decoder.zig at 976df517); every value on the page is its fn bodies, compiled to wasm (logic.js)"]; pub const READS_LOCAL_FILES : bool = false; pub const SENDS_NOTHING : bool = true; pub const K_CARD_WIDTH : u16 = 1200; pub const K_CARD_HEIGHT : u16 = 630; pub const SAY_LOADING : str = "Loading"; pub const K_OPS : [6]u32 = [16, 17, 26, 4, 64, 77]; pub const K_START_IMM : i32 = 5; pub const SAY_PICK : str = "Instruction"; pub const SAY_OPS : [6]str = ["ADD", "SUB", "XOR", "LDI", "JMP", "HALT"]; pub const SAY_IMM : str = "imm"; pub const SAY_WORD : str = "{0} encodes to {1}"; pub const SAY_F_OP : str = "opcode"; pub const SAY_FORM_IMM : str = "Immediate form: src1 has four bits, the immediate fifteen."; pub const SAY_FORM_3 : str = "Three-register form: dst, src1, src2 five bits each."; pub const SAY_FORM_2 : str = "Two-register form: the bits above src1 are unused."; pub const SAY_SOURCE : str = "Logic: t27 spec isa/ternary_encoding.t27, compiled"; test the_card_is_the_share_size { assert K_CARD_WIDTH == 1200; assert K_CARD_HEIGHT == 630; assert K_CARD_WIDTH * 21 == K_CARD_HEIGHT * 40; } test the_widget_starts_where_its_card_says { assert K_OPS[0] == 16; }