| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A Zig implementation of the Forthic stack-based concatenative programming language.
Forthic is a stack-based, concatenative language designed for composable transformations. This is the official Zig runtime implementation, providing full compatibility with other Forthic runtimes while leveraging Zig's comptime metaprogramming and performance.
zig buildconst forthic = @import("forthic");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
var interp = try forthic.StandardInterpreter.init(allocator);
defer interp.deinit();
try interp.run("[1 2 3] \"2 *\" MAP");
const result = try interp.stackPop();
defer result.deinit(allocator);
// result is [2, 4, 6]
}# REPL mode
./zig-out/bin/forthic-zig repl
# Execute a script
./zig-out/bin/forthic-zig run script.forthic
# Eval mode (one-liner)
./zig-out/bin/forthic-zig eval "[1 2 3] LENGTH"# Build
zig build
# Run tests
zig build test
# Run specific test
zig test src/forthic/interpreter.zig
# Build with optimizations
zig build -Doptimize=ReleaseFastforthic-zig/ ├── src/ │ ├── main.zig # Entry point │ └── forthic/ │ ├── interpreter.zig # Core interpreter │ ├── tokenizer.zig # Lexical analysis │ ├── module.zig # Module system │ └── modules/standard/ # Standard library (8 modules) ├── tests/ # Test suites └── build.zig # Build configuration
Zig's comptime enables zero-overhead word registration:
const words = .{
.{ .name = "SWAP", .meta = Word.init("( a b -- b a )", "Swap"), .func = swap },
.{ .name = "DUP", .meta = Word.init("( a -- a a )", "Duplicate"), .func = dup },
};
// Compile-time registration
pub fn registerWords(module: *Module) void {
inline for (words) |word| {
module.addWord(word.name, word.meta, word.func);
}
}This runtime supports calling words from other Forthic runtimes via gRPC:
// Call a TypeScript word from Zig
const result = try interp.executeRemoteWord("typescript-runtime", "MY-WORD", args);Zig's manual memory management and comptime features provide excellent performance:
BSD 2-CLAUSE
| Back | FazBrowse Home | New Git URL |