Skip to content
This repository was archived by the owner on Jan 1, 2026. It is now read-only.

Commit 5f8dcfb

Browse files
committed
Initial version of forthic-rb
- Port Tokenizer and add initial test - Add word and module classes - Also add type documentation to each function - Ported interpreter and initial global module - Port global module tests from forthic-ts - Add >SYM word (Ruby specific) - Add .S word to print entire stack - Update README and gemspec
1 parent fd9b208 commit 5f8dcfb

40 files changed

Lines changed: 6178 additions & 0 deletions

forthic-rb/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/.bundle/
2+
/.yardoc
3+
/_yardoc/
4+
/coverage/
5+
/doc/
6+
/pkg/
7+
/spec/reports/
8+
/tmp/
9+
.DS_Store
10+
.ruby-lsp

forthic-rb/.standard.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# For available configuration options, see:
2+
# https://github.com/standardrb/standard
3+
ruby_version: 3.1

forthic-rb/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## [Unreleased]
2+
3+
## [0.1.0] - 2024-12-27
4+
5+
- Initial release

forthic-rb/Gemfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
# Specify your gem's dependencies in forthic.gemspec
6+
gemspec
7+
8+
gem "rake", "~> 13.0"
9+
10+
group :development do
11+
gem 'guard'
12+
gem 'guard-minitest'
13+
gem 'minitest-reporters'
14+
gem "minitest", "~> 5.16"
15+
gem "standard", "~> 1.3"
16+
end

forthic-rb/Gemfile.lock

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
PATH
2+
remote: .
3+
specs:
4+
forthic (0.1.0)
5+
6+
GEM
7+
remote: https://rubygems.org/
8+
specs:
9+
ansi (1.5.0)
10+
ast (2.4.2)
11+
builder (3.3.0)
12+
coderay (1.1.3)
13+
ffi (1.17.0)
14+
ffi (1.17.0-arm64-darwin)
15+
formatador (1.1.0)
16+
guard (2.19.0)
17+
formatador (>= 0.2.4)
18+
listen (>= 2.7, < 4.0)
19+
lumberjack (>= 1.0.12, < 2.0)
20+
nenv (~> 0.1)
21+
notiffany (~> 0.0)
22+
pry (>= 0.13.0)
23+
shellany (~> 0.0)
24+
thor (>= 0.18.1)
25+
guard-compat (1.2.1)
26+
guard-minitest (2.4.6)
27+
guard-compat (~> 1.2)
28+
minitest (>= 3.0)
29+
json (2.9.1)
30+
language_server-protocol (3.17.0.3)
31+
lint_roller (1.1.0)
32+
listen (3.9.0)
33+
rb-fsevent (~> 0.10, >= 0.10.3)
34+
rb-inotify (~> 0.9, >= 0.9.10)
35+
lumberjack (1.2.10)
36+
method_source (1.1.0)
37+
minitest (5.25.4)
38+
minitest-reporters (1.7.1)
39+
ansi
40+
builder
41+
minitest (>= 5.0)
42+
ruby-progressbar
43+
nenv (0.3.0)
44+
notiffany (0.1.3)
45+
nenv (~> 0.1)
46+
shellany (~> 0.0)
47+
parallel (1.26.3)
48+
parser (3.3.6.0)
49+
ast (~> 2.4.1)
50+
racc
51+
pry (0.15.2)
52+
coderay (~> 1.1)
53+
method_source (~> 1.0)
54+
racc (1.8.1)
55+
rainbow (3.1.1)
56+
rake (13.2.1)
57+
rb-fsevent (0.11.2)
58+
rb-inotify (0.11.1)
59+
ffi (~> 1.0)
60+
regexp_parser (2.10.0)
61+
rubocop (1.69.2)
62+
json (~> 2.3)
63+
language_server-protocol (>= 3.17.0)
64+
parallel (~> 1.10)
65+
parser (>= 3.3.0.2)
66+
rainbow (>= 2.2.2, < 4.0)
67+
regexp_parser (>= 2.9.3, < 3.0)
68+
rubocop-ast (>= 1.36.2, < 2.0)
69+
ruby-progressbar (~> 1.7)
70+
unicode-display_width (>= 2.4.0, < 4.0)
71+
rubocop-ast (1.37.0)
72+
parser (>= 3.3.1.0)
73+
rubocop-performance (1.23.0)
74+
rubocop (>= 1.48.1, < 2.0)
75+
rubocop-ast (>= 1.31.1, < 2.0)
76+
ruby-progressbar (1.13.0)
77+
shellany (0.0.1)
78+
standard (1.43.0)
79+
language_server-protocol (~> 3.17.0.2)
80+
lint_roller (~> 1.0)
81+
rubocop (~> 1.69.1)
82+
standard-custom (~> 1.0.0)
83+
standard-performance (~> 1.6)
84+
standard-custom (1.0.2)
85+
lint_roller (~> 1.0)
86+
rubocop (~> 1.50)
87+
standard-performance (1.6.0)
88+
lint_roller (~> 1.1)
89+
rubocop-performance (~> 1.23.0)
90+
thor (1.3.2)
91+
unicode-display_width (3.1.3)
92+
unicode-emoji (~> 4.0, >= 4.0.4)
93+
unicode-emoji (4.0.4)
94+
95+
PLATFORMS
96+
arm64-darwin-24
97+
ruby
98+
99+
DEPENDENCIES
100+
forthic!
101+
guard
102+
guard-minitest
103+
minitest (~> 5.16)
104+
minitest-reporters
105+
rake (~> 13.0)
106+
standard (~> 1.3)
107+
108+
BUNDLED WITH
109+
2.6.2

forthic-rb/Guardfile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# A sample Guardfile
2+
# More info at https://github.com/guard/guard#readme
3+
4+
## Uncomment and set this to only include directories you want to watch
5+
# directories %w(app lib config test spec features) \
6+
# .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}
7+
8+
## Note: if you are using the `directories` clause above and you are not
9+
## watching the project directory ('.'), then you will want to move
10+
## the Guardfile to a watched dir and symlink it back, e.g.
11+
#
12+
# $ mkdir config
13+
# $ mv Guardfile config/
14+
# $ ln -s config/Guardfile .
15+
#
16+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17+
18+
guard :minitest do
19+
# with Minitest::Unit
20+
watch(%r{^test/(.*)\/?test_(.*)\.rb$})
21+
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
22+
watch(%r{^test/test_helper\.rb$}) { 'test' }
23+
24+
# with Minitest::Spec
25+
# watch(%r{^spec/(.*)_spec\.rb$})
26+
# watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
27+
# watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
28+
29+
# Rails 4
30+
# watch(%r{^app/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
31+
# watch(%r{^app/controllers/application_controller\.rb$}) { 'test/controllers' }
32+
# watch(%r{^app/controllers/(.+)_controller\.rb$}) { |m| "test/integration/#{m[1]}_test.rb" }
33+
# watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
34+
# watch(%r{^lib/(.+)\.rb$}) { |m| "test/lib/#{m[1]}_test.rb" }
35+
# watch(%r{^test/.+_test\.rb$})
36+
# watch(%r{^test/test_helper\.rb$}) { 'test' }
37+
38+
# Rails < 4
39+
# watch(%r{^app/controllers/(.*)\.rb$}) { |m| "test/functional/#{m[1]}_test.rb" }
40+
# watch(%r{^app/helpers/(.*)\.rb$}) { |m| "test/helpers/#{m[1]}_test.rb" }
41+
# watch(%r{^app/models/(.*)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" }
42+
end

forthic-rb/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Forthic
2+
3+
A Forthic interpreter that runs within Ruby.
4+
5+
## Installation
6+
7+
Install the gem and add to the application's Gemfile by executing:
8+
9+
```bash
10+
bundle add forthic
11+
```
12+
13+
If bundler is not being used to manage dependencies, install the gem by executing:
14+
15+
```bash
16+
gem install forthic
17+
```
18+
19+
## Usage
20+
21+
Here's a basic example of how to use the Forthic interpreter:
22+
23+
```ruby
24+
require 'forthic'
25+
26+
interp = Forthic::Interpreter.new
27+
interp.run("[1 2 3] '8 *' MAP")
28+
puts interp.stack_pop
29+
30+
# Output:
31+
#
32+
# [ 8, 16, 24 ]
33+
```
34+
35+
## Contributing
36+
37+
Bug reports and pull requests are welcome on GitHub at https://github.com/linkedin/forthic.

forthic-rb/Rakefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
require "bundler/gem_tasks"
4+
require "minitest/test_task"
5+
6+
Minitest::TestTask.create
7+
8+
require "standard/rake"
9+
10+
task default: %i[test standard]
11+
12+
task :guard do
13+
sh "bundle exec guard"
14+
end

forthic-rb/bin/console

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require "bundler/setup"
5+
require "forthic"
6+
7+
# You can add fixtures and/or initialization code here to make experimenting
8+
# with your gem easier. You can also use a different console, if you like.
9+
10+
require "irb"
11+
IRB.start(__FILE__)

forthic-rb/bin/setup

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
set -vx
5+
6+
bundle install
7+
8+
# Do any other automated setup that you need to do here

0 commit comments

Comments
 (0)