Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jorth

A Forth-inspired stack-based programming language written in vanilla JavaScript for the QuickJS engine.

Following this really cool implementation https://skilldrick.github.io/easyforth/

How to run

make

How to build

make bin

So far what's implemented

🧪 Testing jorth at: ./dist/jorth
============================================================

--- basic-add ---
  code:     1 2 3 + + .
  expected: "6"
  actual:   "6  ok"
  actual (ok stripped): "6"
  ✅ PASS

--- reverse-polish-mult ---
  code:     5 2 + 10 * .
  expected: "70"
  actual:   "70  ok"
  actual (ok stripped): "70"
  ✅ PASS

--- define-foo ---
  code:     : foo  100 + ; 1000 foo .
  expected: "1100"
  actual:   "1100  ok"
  actual (ok stripped): "1100"
  ✅ PASS

--- define-foo-chained ---
  code:     : foo  100 + ; 1000 foo foo foo .
  expected: "1300"
  actual:   "1300  ok"
  actual (ok stripped): "1300"
  ✅ PASS

--- dup ---
  code:     1 2 3 dup . . . .
  expected: "3 3 2 1"
  actual:   "3 3 2 1  ok"
  actual (ok stripped): "3 3 2 1"
  ✅ PASS

--- drop ---
  code:     1 2 3 drop . .
  expected: "2 1"
  actual:   "2 1  ok"
  actual (ok stripped): "2 1"
  ✅ PASS

--- swap ---
  code:     1 2 3 4 swap . . . .
  expected: "3 4 2 1"
  actual:   "3 4 2 1  ok"
  actual (ok stripped): "3 4 2 1"
  ✅ PASS

--- over ---
  code:     1 2 3 over . . . .
  expected: "2 3 2 1"
  actual:   "2 3 2 1  ok"
  actual (ok stripped): "2 3 2 1"
  ✅ PASS

--- rot ---
  code:     1 2 3 rot . . .
  expected: "1 3 2"
  actual:   "1 3 2  ok"
  actual (ok stripped): "1 3 2"
  ✅ PASS

--- dot-sequence ---
  code:     1 . 2 . 3 . 4 5 6 . . .
  expected: "1 2 3 6 5 4"
  actual:   "1 2 3 6 5 4  ok"
  actual (ok stripped): "1 2 3 6 5 4"
  ✅ PASS

--- emit-wow ---
  code:     33 119 111 87 emit emit emit emit
  expected: "Wow!"
  actual:   "Wow! ok"
  actual (ok stripped): "Wow!"
  ✅ PASS

--- cr-numbers ---
  code:     cr 100 . cr 200 . cr 300 .
  expected: "\n100 \n200 \n300"
  actual:   "100 \n200 \n300  ok"
  actual (ok stripped): "100 \n200 \n300"
  ✅ PASS

--- dot-quote-hello ---
  code:     : say-hello  ." Hello there!" ; say-hello
  expected: "Hello there!"
  actual:   "Hello there! ok"
  actual (ok stripped): "Hello there!"
  ✅ PASS

--- print-stack-top ---
  code:     : print-stack-top  cr dup ." The top of the stack is " . cr ." which looks like '" dup emit ." ' in ascii" ; 48 print-stack-top
  expected: "The top of the stack is 48 \nwhich looks like '0' in ascii  "
  actual:   "The top of the stack is 48 \nwhich looks like '0' in ascii ok"
  actual (ok stripped): "The top of the stack is 48 \nwhich looks like '0' in ascii"
  ✅ PASS

--- equals ---
  code:     3 4 = . 5 5 = .
  expected: "0 -1"
  actual:   "0 -1  ok"
  actual (ok stripped): "0 -1"
  ✅ PASS

--- less-greater ---
  code:     3 4 < . 3 4 > .
  expected: "-1 0"
  actual:   "-1 0  ok"
  actual (ok stripped): "-1 0"
  ✅ PASS

--- and ---
  code:     3 4 < 20 30 < and .
  expected: "-1"
  actual:   "-1  ok"
  actual (ok stripped): "-1"
  ✅ PASS

--- or ---
  code:     3 4 < 20 30 > or .
  expected: "-1"
  actual:   "-1  ok"
  actual (ok stripped): "-1"
  ✅ PASS

--- invert ---
  code:     3 4 < invert .
  expected: "0"
  actual:   "0  ok"
  actual (ok stripped): "0"
  ✅ PASS

--- if-then-buzz ---
  code:     : buzz?  5 mod 0 = if ." Buzz" then ; 3 buzz? 4 buzz? 5 buzz?
  expected: "Buzz"
  actual:   "Buzz ok"
  actual (ok stripped): "Buzz"
  ✅ PASS

--- if-else-then ---
  code:     : is-it-zero?  0 = if ." Yes!" else ." No!" then ; 0 is-it-zero? 1 is-it-zero? 2 is-it-zero?
  expected: "Yes!No!No!"
  actual:   "Yes!No!No! ok"
  actual (ok stripped): "Yes!No!No!"
  ✅ PASS

--- do-loop ---
  code:     : loop-test  10 0 do i . loop ; loop-test
  expected: "0 1 2 3 4 5 6 7 8 9"
  actual:   "0 1 2 3 4 5 6 7 8 9  ok"
  actual (ok stripped): "0 1 2 3 4 5 6 7 8 9"
  ✅ PASS

--- fizzbuzz ---
  code:     : fizz?  3 mod 0 = dup if ." Fizz" then ; : buzz?  5 mod 0 = dup if ." Buzz" then ; : fizz-buzz?  dup fizz? swap buzz? or invert ; : do-fizz-buzz  25 1 do cr i fizz-buzz? if i . then loop ; do-fizz-buzz
  expected: "\n1 \n2 \nFizz\n4 \nBuzz\nFizz\n7 \n8 \nFizz\nBuzz\n11 \nFizz\n13 \n14 \nFizzBuzz\n16 \n17 \nFizz\n19 \nBuzz\nFizz\n22 \n23 \nFizz"
  actual:   "1 \n2 \nFizz\n4 \nBuzz\nFizz\n7 \n8 \nFizz\nBuzz\n11 \nFizz\n13 \n14 \nFizzBuzz\n16 \n17 \nFizz\n19 \nBuzz\nFizz\n22 \n23 \nFizz ok"
  actual (ok stripped): "1 \n2 \nFizz\n4 \nBuzz\nFizz\n7 \n8 \nFizz\nBuzz\n11 \nFizz\n13 \n14 \nFizzBuzz\n16 \n17 \nFizz\n19 \nBuzz\nFizz\n22 \n23 \nFizz"
  ✅ PASS

--- variable-store-fetch ---
  code:     variable balance 123 balance ! balance @ .
  expected: "123"
  actual:   "123  ok"
  actual (ok stripped): "123"
  ✅ PASS

--- variable-question-mark ---
  code:     variable balance 123 balance ! balance ? 50 balance +! balance ?
  expected: "123 173"
  actual:   "123 173  ok"
  actual (ok stripped): "123 173"
  ✅ PASS

--- constant ---
  code:     42 constant answer 2 answer * .
  expected: "84"
  actual:   "84  ok"
  actual (ok stripped): "84"
  ✅ PASS

--- array-number-word ---
  code:     variable numbers 3 cells allot : number  ( offset -- addr )  cells numbers + ; 10 0 number ! 20 1 number ! 30 2 number ! 40 3 number ! 2 number ?
  expected: "30"
  actual:   "30  ok"
  actual (ok stripped): "30"
  ✅ PASS

--- stack-underflow ---
  code:     1 2 3 + + + .
  expected: "Error: Stack underflow"
  actual:   "Error: Stack underflow"
  ✅ PASS

============================================================
📊 Results: ✅ 28 passed, ❌ 0 failed, ℹ️ 0 info-only, 28 total

About

A Forth-inspired stack-based programming language written in vanilla JavaScript for the QuickJS engine

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages