// SPDX-License-Identifier: Apache-2.0 ; specs/widgets/tc-immediate.t27 -- lesson 18 of the course "The ternary machine" (specs/course/ternary-computing.t27) ; Source of truth for public/widgets/tc-immediate/ (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-immediate/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_immediate; pub const KIND : str = "widget-tool"; pub const ID : str = "tc-immediate"; pub const TITLE : str = "The immediate: fifteen bits, clamped, and read back"; pub const DESCRIPTION : str = "An immediate lives in 15 bits of two's complement, -16384 to 16383. Push it past the edge and watch it clamp, then decode the word back."; pub const IMAGE_ALT : str = "Immediate card: LDI with an immediate of 20000 clamps to 16383, the largest 15-bit value; the fifteen bits are shown with the sign bit marked, and decoding the word gives 16383 back."; pub const HOOK : str = "Fifteen bits of immediate: everything past 16383 is clamped, not wrapped. The round trip shows it."; 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 : [3]u32 = [4, 132, 64]; pub const K_START_IMM : i32 = 20000; pub const SAY_PICK : str = "Instruction"; pub const SAY_OPS : [3]str = ["LDI", "LD_IMM", "JMP"]; 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: no immediate."; pub const SAY_FORM_2 : str = "Two-register form: no immediate."; pub const SAY_CLAMP : str = "immediate {0} is stored as {1}: its fifteen bits, sign bit outlined"; pub const SAY_BACK : str = "Decoded back from the word: {0}."; pub const SAY_NO_IMM : str = "This form carries no immediate."; 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_START_IMM == 20000; }