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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e71f6368dc2bcc817f0095a389740a6676005ab8ddb862cdef02f0e0910d09d
4
- data.tar.gz: b408177ce893d5353aa00ce2a73698005c07e22e3d68a8ec6cade6032887a591
3
+ metadata.gz: b3faede941e29c0090a90077103892015502bb1bef7897726821932197a72be1
4
+ data.tar.gz: 4393b304179b84c9b1cca818ae04af1cf6800dcd07c86ff92ec5e1b1f4fc4bbf
5
5
  SHA512:
6
- metadata.gz: 2ffd692800bdf839d25a106c79bea485addaeabb7d2eafd5366a9d034927a642fed7b4ecb498e5f081016f5079077d3a4db4ba96eae113a8ce547024b4164736
7
- data.tar.gz: b4ab0aec5f7b788873bbbc71761f5382f565864057101125919338c24453bdccdedbcf26f281dc5c46dee4a16fc7824a08516a52c9c318af91ab0f932a329f42
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/(.*)\/?test_(.*)\.rb$})
21
- watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
22
- watch(%r{^test/test_helper\.rb$}) { 'test' }
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
@@ -11,4 +11,4 @@ task default: %i[test standard]
11
11
 
12
12
  task :guard do
13
13
  sh "bundle exec guard"
14
- end
14
+ end
@@ -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
- require_relative 'words/word'
4
- require_relative 'words/module_word'
5
- require_relative 'words/module_memo_word'
6
- require_relative 'words/module_memo_bang_word'
7
- require_relative 'words/module_memo_bang_at_word'
8
- require_relative 'words/imported_word'
9
- require_relative 'variable'
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 << { prefix: prefix, module: mod }
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