forthic 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/CLAUDE.md +74 -0
- data/Guardfile +3 -3
- data/Rakefile +1 -1
- data/lib/forthic/forthic_error.rb +1 -2
- data/lib/forthic/forthic_module.rb +10 -9
- data/lib/forthic/global_module.rb +321 -334
- data/lib/forthic/interpreter.rb +204 -104
- data/lib/forthic/token.rb +1 -2
- data/lib/forthic/tokenizer.rb +3 -3
- data/lib/forthic/variable.rb +1 -1
- data/lib/forthic/version.rb +1 -1
- data/lib/forthic/words/definition_word.rb +15 -17
- data/lib/forthic/words/end_array_word.rb +3 -3
- data/lib/forthic/words/end_module_word.rb +2 -2
- data/lib/forthic/words/imported_word.rb +3 -3
- data/lib/forthic/words/map_word.rb +5 -5
- data/lib/forthic/words/module_memo_bang_at_word.rb +3 -3
- data/lib/forthic/words/module_memo_bang_word.rb +3 -3
- data/lib/forthic/words/module_memo_word.rb +2 -2
- data/lib/forthic/words/module_word.rb +3 -3
- data/lib/forthic/words/push_value_word.rb +3 -3
- data/lib/forthic/words/start_module_word.rb +6 -6
- data/lib/forthic/words/word.rb +1 -1
- data/lib/forthic.rb +19 -19
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3faede941e29c0090a90077103892015502bb1bef7897726821932197a72be1
|
4
|
+
data.tar.gz: 4393b304179b84c9b1cca818ae04af1cf6800dcd07c86ff92ec5e1b1f4fc4bbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8dea528434b695a7c272c1cd3d9b6d3885c2eb0d4acd43b876663f764abaca97b9896df81e8618dfe98612c4e4a2b18ba883ccbde93873d232cc933eb7ca28e
|
7
|
+
data.tar.gz: baefe4a1a1157b5c190c7e62c703fcf7e0568aefb7103e2a463d514c798ba739a2f5eacdf35af70dd47d51e705ad546738bdac3f7b9de1c25d99d30b5e1153d5
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.2.0] - 2025-01-13
|
4
|
+
|
5
|
+
- Add `import_module` method to Interpreter class
|
6
|
+
- Add test coverage for module importing functionality
|
7
|
+
- Implement module importing with prefix support matching forthic-ts behavior
|
8
|
+
|
3
9
|
## [0.1.0] - 2024-12-27
|
4
10
|
|
5
11
|
- Initial release
|
data/CLAUDE.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# CLAUDE.md
|
2
|
+
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
4
|
+
|
5
|
+
## Development Commands
|
6
|
+
|
7
|
+
### Testing
|
8
|
+
- `rake test` - Run all tests using Minitest
|
9
|
+
- `rake test TEST=test/test_specific_file.rb` - Run a specific test file
|
10
|
+
- `bundle exec guard` - Start Guard for continuous testing (watches file changes)
|
11
|
+
- `rake guard` - Alternative command to start Guard
|
12
|
+
|
13
|
+
### Code Quality
|
14
|
+
- `rake standard` - Run StandardRB linter for code formatting and style
|
15
|
+
- `rake standard:fix` - Auto-fix StandardRB issues where possible
|
16
|
+
- `rake` - Run default task (both tests and linting)
|
17
|
+
|
18
|
+
### Development
|
19
|
+
- `bundle install` - Install gem dependencies
|
20
|
+
- `bundle exec rake build` - Build the gem
|
21
|
+
- `bundle exec rake install` - Install the gem locally
|
22
|
+
- `bundle exec rake release` - Release the gem (requires proper credentials)
|
23
|
+
|
24
|
+
## Architecture Overview
|
25
|
+
|
26
|
+
This is a Ruby implementation of the Forthic programming language - a stack-based language inspired by Forth. The codebase follows a clean modular architecture:
|
27
|
+
|
28
|
+
### Core Components
|
29
|
+
|
30
|
+
**Interpreter (`lib/forthic/interpreter.rb`)**: The main execution engine that:
|
31
|
+
- Manages the execution stack and module stack
|
32
|
+
- Handles tokenization and parsing of Forthic code
|
33
|
+
- Provides word lookup and execution
|
34
|
+
- Supports profiling and debugging capabilities
|
35
|
+
- Manages compilation of word definitions
|
36
|
+
|
37
|
+
**Tokenizer (`lib/forthic/tokenizer.rb`)**: Lexical analyzer that breaks Forthic code into tokens (strings, words, arrays, modules, definitions, comments).
|
38
|
+
|
39
|
+
**Word System (`lib/forthic/words/`)**: Polymorphic word execution system where each word type implements an `execute` method:
|
40
|
+
- `Word` - Base class for all executable words
|
41
|
+
- `PushValueWord` - Pushes values onto the stack
|
42
|
+
- `DefinitionWord` - User-defined words compiled from Forthic code
|
43
|
+
- `EndArrayWord` - Handles array construction
|
44
|
+
- `ModuleWord` variants - Handle module operations and memoization
|
45
|
+
- `StartModuleWord`/`EndModuleWord` - Module boundary management
|
46
|
+
|
47
|
+
**Module System**:
|
48
|
+
- `GlobalModule` - Built-in words and core functionality
|
49
|
+
- `ForthicModule` - User-defined modules with isolated namespaces
|
50
|
+
- Module stack for hierarchical word resolution
|
51
|
+
|
52
|
+
### Key Design Patterns
|
53
|
+
|
54
|
+
- **Stack-based execution**: All operations work with a central execution stack
|
55
|
+
- **Autoloading**: Classes are autoloaded for better startup performance
|
56
|
+
- **Error handling**: Custom `ForthicError` with location tracking for debugging
|
57
|
+
- **Compilation**: Words can be compiled into definition words for reuse
|
58
|
+
- **Memoization**: Special memo words for caching expensive computations
|
59
|
+
|
60
|
+
### Testing Strategy
|
61
|
+
|
62
|
+
Uses Minitest for testing with:
|
63
|
+
- `test_helper.rb` sets up Minitest with SpecReporter for better output
|
64
|
+
- Guard for continuous testing during development
|
65
|
+
- Tests cover tokenizer, interpreter, and module functionality
|
66
|
+
- StandardRB enforces consistent code style
|
67
|
+
|
68
|
+
### File Organization
|
69
|
+
|
70
|
+
- `lib/forthic.rb` - Main entry point with autoload declarations
|
71
|
+
- `lib/forthic/` - Core implementation files
|
72
|
+
- `lib/forthic/words/` - Word implementation classes
|
73
|
+
- `test/` - Test files following Minitest conventions
|
74
|
+
- `sig/` - RBS type signatures for static analysis
|
data/Guardfile
CHANGED
@@ -17,9 +17,9 @@
|
|
17
17
|
|
18
18
|
guard :minitest do
|
19
19
|
# with Minitest::Unit
|
20
|
-
watch(%r{^test/(.*)
|
21
|
-
watch(%r{^lib/(.*/)?([^/]+)\.rb$})
|
22
|
-
watch(%r{^test/test_helper\.rb$})
|
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
23
|
|
24
24
|
# with Minitest::Spec
|
25
25
|
# watch(%r{^spec/(.*)_spec\.rb$})
|
data/Rakefile
CHANGED
@@ -14,7 +14,6 @@ module Forthic
|
|
14
14
|
@description = description
|
15
15
|
@location = location
|
16
16
|
@caught_error = nil
|
17
|
-
puts "ForthicError: #{error_key}, #{title}, #{description}, #{location}"
|
18
17
|
end
|
19
18
|
|
20
19
|
# @param [ForthicError] error
|
@@ -48,4 +47,4 @@ module Forthic
|
|
48
47
|
result.reverse
|
49
48
|
end
|
50
49
|
end
|
51
|
-
end
|
50
|
+
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
require_relative
|
5
|
-
require_relative
|
6
|
-
require_relative
|
7
|
-
require_relative
|
8
|
-
require_relative
|
9
|
-
require_relative
|
3
|
+
require "set"
|
4
|
+
require_relative "words/word"
|
5
|
+
require_relative "words/module_word"
|
6
|
+
require_relative "words/module_memo_word"
|
7
|
+
require_relative "words/module_memo_bang_word"
|
8
|
+
require_relative "words/module_memo_bang_at_word"
|
9
|
+
require_relative "words/imported_word"
|
10
|
+
require_relative "variable"
|
10
11
|
|
11
12
|
module Forthic
|
12
13
|
class ForthicModule
|
@@ -42,7 +43,7 @@ module Forthic
|
|
42
43
|
# @param [String] prefix
|
43
44
|
# @param [ForthicModule] mod
|
44
45
|
def require_module(prefix, mod)
|
45
|
-
@required_modules << {
|
46
|
+
@required_modules << {prefix: prefix, module: mod}
|
46
47
|
end
|
47
48
|
|
48
49
|
# @param [String] name
|
@@ -142,4 +143,4 @@ module Forthic
|
|
142
143
|
var_result ? PushValueWord.new(varname, var_result) : nil
|
143
144
|
end
|
144
145
|
end
|
145
|
-
end
|
146
|
+
end
|