Hacker Newsnew | past | comments | ask | show | jobs | submit | afirium's commentslogin


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",
        },


That's exactly what zig-mcp does. It gives the LLM tools like search_std_lib, get_std_lib_item, and it decides when and how to use them based on context


LLMs have issues with zig, namely outdated docs. Then I found @jedisct1's project, context7 MCPwhich provides a way to search through zig docs using natural language: https://github.com/jedisct1/zig-for-mcp

But context7 returns semantically processed responses that often summarize or rephrase the information instead of quoting it. And that's why there is now zig-mcp which returns documentation in markdown format for stdlib and builtin functions


Rest in peace, Bram...


> Given that, we have not yet introduced any production applications written in Zig into our codebase (where the toolchain is fully set up), because only a few people in the company know the language at the moment.

Do you have any plans where you can use zig in production applications? Thanks!


Hi!

No plans yet. In my opinion, it needs a good reason to be picked instead of C (which we have sizable) to overcome the "number of developers" argument.

Introducing a new general purpose language into a large company carries a significant cost, especially into the future. The company is rightly cautious.



Lectures[0], after which you will read more than one book on category theory

[0] https://www.youtube.com/playlist?list=PLbgaMIhjbmEnaH_LTkxLI...


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: