// SPDX-License-Identifier: Apache-2.0 ; specs/widgets/tc-ternary-alu.t27 -- lesson 19 of the course "The ternary machine" (specs/course/ternary-computing.t27) ; Source of truth for public/widgets/tc-ternary-alu/ (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-ternary-alu/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_ternary_alu; pub const KIND : str = "widget-tool"; pub const ID : str = "tc-ternary-alu"; pub const TITLE : str = "A ternary ALU built from this course's adders"; pub const DESCRIPTION : str = "Add, subtract, negate and compare 9-trit registers. Subtraction is a flip and an add; an overflow past 9 trits is flagged."; pub const IMAGE_ALT : str = "Ternary ALU card: two 9-trit registers, 40 and 13, added by the ripple-carry adder to 53. Subtract is add with every trit of b flipped; compare answers one trit."; pub const HOOK : str = "Subtraction in balanced ternary is addition of the flipped number. No two's complement, no special case."; pub const CATEGORY : str = "compiler"; pub const DATA_SOURCES : [2]str = ["gHashTag/t27 specs/ternary/trits.t27 (t27#8979): every value on the page is its fn bodies, compiled to wasm (logic.js), with 18 tests and 4108 runtime asserts", "N. P. Brusentsov and others, the Setun computer, Moscow State University, 1958: a working balanced-ternary machine"]; 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_TRITS : u32 = 9; pub const K_START_A : i32 = 40; pub const K_START_B : i32 = 13; pub const SAY_PICK : str = "Operation"; pub const SAY_OPS : [4]str = ["ADD", "SUB", "NEG", "CMP"]; pub const SAY_OUT : str = "result"; pub const SAY_RESULT : str = "{0}: {1}"; pub const SAY_OVER : str = "overflow: the result needs more than {0} trits (+/-{1})"; pub const SAY_OP_TIPS : [4]str = ["a + b by the ripple-carry adder.", "a + (b with every trit flipped).", "Every trit of a flipped.", "One trit: -1 less, 0 equal, +1 greater."]; pub const SAY_SOURCE : str = "Logic: t27 spec ternary/trits.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_TRITS == 9; }