Skip to content

otherfunc/otherfunc-forth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

otherfunc-forth

Forth interpreter with compilation mode, 64 built-in primitives, and HTTP/KV outbound support.

Implementation

  • i64 cells, 65,536-cell memory, 1,024-depth stack limit
  • Compilation mode (: word ... ;) compiles to token sequences, interpreted mode for immediate execution
  • 64 built-in primitives: stack ops, arithmetic, comparison, logic, I/O, control flow, loops, memory, variables/constants, strings, HTTP, KV
  • Loop constructs: do...loop, +loop, begin...until, begin...while...repeat, begin...again
  • HTTP outbound via coroutine/yield: s" url" http-get, s" url" s" body" http-post, s" KEY" env
  • KV storage via coroutine/yield: s" key" kv-get, s" key" s" value" kv-set, s" key" kv-del
  • Default instruction limit: 10,000,000 (configurable via with_instruction_limit())

Install

cargo install --path .

Usage

# Inline code
forth "3 4 + ."

# From file
forth -f program.fth

# Piped input
echo "hello" | forth "begin key dup while emit repeat"

As a Library

use otherfunc_forth::ForthInterpreter;
use otherfunc_core::Interpreter;

let mut forth = ForthInterpreter::new();
let output = forth.execute("3 4 + .", "").unwrap();
assert_eq!(output, "7 ");

Tests

cargo test -p otherfunc-forth    # 23 tests

About

Forth interpreter with HTTP and KV support

Topics

Resources

License

Stars

Watchers

Forks

Languages