[HN Gopher] Forth in Zig and WebAssembly
       ___________________________________________________________________
        
       Forth in Zig and WebAssembly
        
       Author : afirium
       Score  : 19 points
       Date   : 2025-10-02 13:57 UTC (9 hours ago)
        
 (HTM) web link (zig-wasm.github.io)
 (TXT) w3m dump (zig-wasm.github.io)
        
       | afirium wrote:
       | Source: https://github.com/zig-wasm/zorth
        
         | hu3 wrote:
         | Nice! The whole implementation seems to be a bit over 1k lines.
         | https://github.com/zig-wasm/zorth/blob/main/src/zorth.zig
         | 
         | The tests give some examples of what to try like: 65 EMIT
         | const tests = .{             .{ "65 EMIT ", "A" },
         | .{ "777 65 EMIT ", "A" },             .{ "32 DUP + 1+ EMIT ",
         | "A" },             .{ "16 DUP 2DUP + + + 1+ EMIT ", "A" },
         | .{ "8 DUP * 1+ EMIT ", "A" },             .{ "CHAR A EMIT ",
         | "A" },             .{ ": SLOW WORD FIND >CFA EXECUTE ; 65 SLOW
         | EMIT ", "A" },             .{ fmt.comptimePrint("{d} DSP@ 8
         | TELL ", .{s}), "SYSCALL0" },             .{
         | fmt.comptimePrint("{d} DSP@ HERE @ 8 CMOVE HERE @ 8 TELL ",
         | .{s}), "SYSCALL0" },             .{ fmt.comptimePrint("{d} DSP@
         | 2 NUMBER DROP EMIT ", .{mem.readInt(u16, "65", .little)}), "A"
         | },             .{ "64 >R RSP@ 1 TELL RDROP ", "@" },
         | .{ "64 DSP@ RSP@ SWAP C@C! RSP@ 1 TELL ", "@" },             .{
         | "64 >R 1 RSP@ +! RSP@ 1 TELL ", "A" },             .{
         | \\: <BUILDS WORD CREATE DODOES , 0 , ;                 \\:
         | DOES> R> LATEST @ >DFA ! ;                 \\: CONST <BUILDS ,
         | DOES> @ ;                 \\                 \\65 CONST FOO
         | \\FOO EMIT                  ,                 "A",
         | },             .{ preamble ++ "VERSION . ", "47 " },
         | .{ preamble ++ "CR ", "\n" },             .{ preamble ++ "0 1 >
         | . 1 0 > . ", "0 -1 " },             .{ preamble ++ "0 1 >= . 0
         | 0 >= . ", "0 -1 " },             .{ preamble ++ "0 0<> . 1 0<>
         | . ", "0 -1 " },             .{ preamble ++ "1 0<= . 0 0<= . ",
         | "0 -1 " },             .{ preamble ++ "-1 0>= . 0 0>= . ", "0
         | -1 " },             .{ preamble ++ "0 0 OR . 0 -1 OR . ", "0 -1
         | " },             .{ preamble ++ "-1 -1 XOR . 0 -1 XOR . ", "0
         | -1 " },             .{ preamble ++ "-1 INVERT . 0 INVERT . ",
         | "0 -1 " },             .{ preamble ++ "3 4 5 .S ", "5 4 3 " },
         | .{ preamble ++ "1 2 3 4 2SWAP .S ", "2 1 4 3 " },
         | .{ preamble ++ "F_IMMED F_HIDDEN .S ", "32 128 " },
         | .{ preamble ++ ": CFA@ WORD FIND >CFA @ ; CFA@ >DFA DOCOL = .
         | ", "-1 " },             .{ preamble ++ "3 4 5 WITHIN . ", "0 "
         | },             .{ preamble ++ fmt.comptimePrint(": GETPPID {d}
         | SYSCALL0 ; GETPPID . ", .{@intFromEnum(syscalls.X64.getppid)}),
         | p },             .{ preamble ++ "ARGC . ", "2 " },
         | .{ preamble ++ "ENVIRON @ DUP STRLEN TELL ",
         | mem.sliceTo(os.environ[0], 0) },             .{ preamble ++
         | "SEE >DFA ", ": >DFA >CFA 8+ EXIT ;\n" },             .{
         | preamble ++ "SEE HIDE ", ": HIDE WORD FIND HIDDEN ;\n" },
         | .{ preamble ++ "SEE QUIT ", ": QUIT R0 RSP! INTERPRET BRANCH (
         | -16 ) ;\n" },             .{                 preamble ++
         | \\: FOO THROW ;                     \\: TEST-EXCEPTIONS 25 [']
         | FOO CATCH ?DUP IF ." FOO threw exception: " . CR DROP THEN ;
         | \\TEST-EXCEPTIONS                  ,                 "FOO threw
         | exception: 25 \n",             },
        
       | miga wrote:
       | Fails to recover after the first parse error.
        
       ___________________________________________________________________
       (page generated 2025-10-02 23:01 UTC)