fOOrth 0.6.1 → 0.6.2

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
  SHA1:
3
- metadata.gz: 30474940c4c3e0647c0c1205d6165d3c3d11ee3a
4
- data.tar.gz: 8e65265692a9ed674814aa78c9fd2892da3456a1
3
+ metadata.gz: 2a310602eff6fd2746b07abee8e0ea1618aca564
4
+ data.tar.gz: 455f496faf46e85cd2b7ce47baa87b5318f58aa5
5
5
  SHA512:
6
- metadata.gz: e53b8c014e66a4f7f0401292c00e4e361a0a0667ade42bc26be9db1a93976f8686ca0c874fabca16efad207a6c89c45994bf4be17ea712861ecdf64c84cf2446
7
- data.tar.gz: 79cfd83122d97e5b83a357d6b7df7c8083a163c7467131d963396f13a300aae0c7a7e003dd51ec62776aa3adc33e8607bd711bf623808564fb5498baabb54758
6
+ metadata.gz: 208dd59bb806359e23b7178a493caf42819c5b55d17674a06f2b11a709fb7de16ccf1ebfb5b6df33515148fa27fa748c849fea63253ab246da48e5f47de6f721
7
+ data.tar.gz: 7755e262d1563086fa7c7769aa50b452e1331a0ddbf1358b76ccfc2d2fd14c56467f12c2e4c5c82a461b2cb8d4e2be526c331f4e9dafaa36a2617aa1079c3d83
data/README.md CHANGED
@@ -14,6 +14,24 @@ fOOrth Programming Language web site at:
14
14
  <br>http://www.foorth.org/
15
15
  <br>
16
16
 
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ ```ruby
22
+ gem 'fOOrth'
23
+ ```
24
+
25
+ And then execute:
26
+
27
+ $ bundle
28
+
29
+ Or install it yourself as:
30
+
31
+ $ gem install fOOrth
32
+
33
+ The fOOrth gem itself is found at: ( https://rubygems.org/gems/fOOrth )
34
+
17
35
  ## Usage
18
36
  Adding fOOrth can be as simple as:
19
37
 
@@ -23,9 +41,13 @@ Adding fOOrth can be as simple as:
23
41
  This will launch an interactive fOOrth session. Alternatively this can be
24
42
  done with:
25
43
 
26
- rake run
44
+ $ fOOrth
45
+
46
+ or
47
+
48
+ $ rake run
27
49
 
28
- Be sure to be in the folder that contains the rakefile in order for this
50
+ Be sure to be in the folder that contains the rakefile in order for the latter
29
51
  command to work.
30
52
 
31
53
  <br>If, instead, a non-interactive facility is required, use:
@@ -41,12 +63,11 @@ where the string is fOOrth code to be executed, or for a file of code, use:
41
63
  ## Further Documentation
42
64
 
43
65
  The fOOrth Language System is documented in The fOOrth User Guide. This is
44
- currently only available in Open Office format, and is still also very much
45
- a work in progress. Please see The_fOOrth_User_Guide.odt in the docs folder.
66
+ currently only available in Open Office and PDF formats. The guide tracks
67
+ changes in the language fairly closely. The most current guide in PDF
68
+ format may be found at the community web site above.
46
69
 
47
- Also for those who do not have or don't want Open Office: As each major
48
- version of fOOrth is made available, expect to see portable document format
49
- (pdf) versions of the guide. (In the docs folder in the repository)
70
+ This code repo also has PDF formatted guides for majot revisions.
50
71
 
51
72
  ## Contributing
52
73
 
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
 
19
19
  spec.files = raw_list
20
20
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.test_files = spec.files.grep(%r{^(tests|integration)/})
22
22
  spec.require_paths = ["lib"]
23
23
  spec.executables = ["fOOrth"]
24
24
 
@@ -36,5 +36,5 @@ Gem::Specification.new do |spec|
36
36
  spec.add_runtime_dependency 'full_clone'
37
37
  spec.add_runtime_dependency 'safe_clone'
38
38
  spec.add_runtime_dependency 'in_array'
39
- spec.add_runtime_dependency 'mini_readline', ">= 0.4.2"
39
+ spec.add_runtime_dependency 'mini_readline', ">= 0.4.8"
40
40
  end
Binary file
Binary file
Binary file
@@ -187,4 +187,12 @@ class CompileLibraryTester < Minitest::Test
187
187
  foorth_equal('"integration/_FILE_test.foorth" .load ', [nm, 7, nm])
188
188
  end
189
189
 
190
+ def test_comments
191
+ foorth_equal('42 (foo (bar) etc) 33', [42, 33])
192
+
193
+ foorth_raises('( ( )')
194
+
195
+ foorth_equal('42 // foo bar etc 33', [42])
196
+ end
197
+
190
198
  end
@@ -75,6 +75,26 @@ class CtrlStructLibraryTester < Minitest::Test
75
75
  foorth_equal('42 .with{{ {{ self }} .call }}', [42])
76
76
  end
77
77
 
78
+ def test_compile_suspend
79
+ foorth_equal(': tcs [[ 42 ]] ;', [42])
80
+ foorth_raises('[[ ]]')
81
+
82
+ foorth_equal(': tcs [[ 42 , ]] ; tcs', [42])
83
+ foorth_raises('42 ,')
84
+
85
+ foorth_equal('asm" vm.push(42);" ', [42])
86
+ foorth_equal(': tcs asm" vm.push(42);" ; tcs', [42])
87
+
88
+ foorth_equal('"vm.push(42);" .asm ', [42])
89
+ foorth_equal(': tcs "vm.push(42);" .asm ; tcs', [42])
90
+
91
+ foorth_equal(': tcs [[ ,asm"vm.push(42);" ]] ; tcs', [42])
92
+ foorth_raises(',asm"vm.push(42);" ')
93
+
94
+ foorth_equal(': tcs [[ "vm.push(42);" ,asm ]] ; tcs', [42])
95
+ foorth_raises('"vm.push(42);" ,asm ')
96
+ end
97
+
78
98
  def test_for_unsupported_structures
79
99
  foorth_raises('4 .new{{ }}')
80
100
  foorth_raises('4 .each{{ }}')
data/irbt.rb ADDED
@@ -0,0 +1,20 @@
1
+ # coding: utf-8
2
+ # An IRB + fOOrth Test bed
3
+
4
+ require 'irb'
5
+ $force_alias_read_line_module = true
6
+ require 'mini_readline'
7
+
8
+ puts "Starting an IRB console with fOOrth loaded."
9
+
10
+ if ARGV[0] == 'local'
11
+ require_relative 'lib/fOOrth'
12
+ puts "fOOrth loaded locally: #{XfOOrth::VERSION}"
13
+
14
+ ARGV.shift
15
+ else
16
+ require 'fOOrth'
17
+ puts "fOOrth loaded from gem: #{XfOOrth::VERSION}"
18
+ end
19
+
20
+ IRB.start
@@ -31,6 +31,9 @@ module XfOOrth
31
31
  #The level of quote nesting.
32
32
  attr_accessor :quotes
33
33
 
34
+ #The level of comment nesting.
35
+ attr_accessor :parens
36
+
34
37
  #Is a force compile in effect?
35
38
  attr_accessor :force
36
39
 
@@ -39,6 +42,7 @@ module XfOOrth
39
42
  @buffer = nil
40
43
  @parser = nil
41
44
  @quotes = 0
45
+ @parens = 0
42
46
  @force = false
43
47
  @context = Context.new(nil, vm: self, mode: :execute)
44
48
  self
@@ -48,6 +52,13 @@ module XfOOrth
48
52
  def <<(text)
49
53
  dbg_puts " Append=#{text.inspect}"
50
54
  @buffer << text
55
+ rescue NoMethodError
56
+ error "F14: The current mode does not allow code to be appended."
57
+ end
58
+
59
+ #Is the buffer valid?
60
+ def buffer_valid?
61
+ @buffer.is_a?(String)
51
62
  end
52
63
 
53
64
  #Execute code from the interactive console.
@@ -11,8 +11,10 @@ module XfOOrth
11
11
  #<br>Parameters:
12
12
  #* text - Some text to append to the buffer before proceeding.
13
13
  #* ctrl - The control symbol that started the deferral.
14
- #<br>Note:
14
+ #<br>Notes:
15
15
  #* Adds a nested context level to be un-nested at a later point.
16
+ #* Enters deferred mode only if currently in execute mode. Otherwise
17
+ # continues in the current mode.
16
18
  def suspend_execute_mode(text, ctrl)
17
19
  dbg_puts " suspend_execute_mode"
18
20
  @context = Context.new(@context, ctrl: ctrl)
@@ -1,8 +1,8 @@
1
1
  # coding: utf-8
2
2
 
3
- #* compiler/modes/suspend.rb - The ability to suspend compile mode.
3
+ #* compiler/modes/suspend.rb - The ability to suspend buffered mode.
4
4
  module XfOOrth
5
- #* compiler/modes/suspend.rb - The ability to suspend compile mode.
5
+ #* compiler/modes/suspend.rb - The ability to suspend buffered mode.
6
6
  class VirtualMachine
7
7
 
8
8
  #While compiling, suspend compiling so that some code may be executed.
@@ -10,9 +10,13 @@ module XfOOrth
10
10
  #* ctrl - The control symbol that suspended the compilation.
11
11
  #<br>Note:
12
12
  #* Adds a nested context level to be un-nested at a later point.
13
- def suspend_compile_mode(ctrl)
14
- dbg_puts " suspend_compile_mode"
15
- @context.check_set(:mode, [:compile])
13
+ def suspend_buffered_mode(ctrl)
14
+ dbg_puts " suspend_buffered_mode"
15
+
16
+ unless buffer_valid?
17
+ error "F14: The #{ctrl} method is not available in execute mode."
18
+ end
19
+
16
20
  @context = Context.new(@context, mode: :execute, ctrl: ctrl)
17
21
  end
18
22
 
@@ -22,8 +26,8 @@ module XfOOrth
22
26
  # suspended the compilation.
23
27
  #<br>Note:
24
28
  #* Un-nests a context level.
25
- def resume_compile_mode(ctrls)
26
- dbg_puts " resume_compile_mode"
29
+ def resume_buffered_mode(ctrls)
30
+ dbg_puts " resume_buffered_mode"
27
31
  @context.check_set(:ctrl, ctrls)
28
32
  @context = @context.previous
29
33
  end
@@ -31,8 +31,18 @@ module XfOOrth
31
31
  #<br>Note:
32
32
  #* Raises an XfOOrthError exception on an unterminated comment.
33
33
  def skip_over_comment
34
- until @source.eoln?
35
- return true if @source.get == ')'
34
+ vm = Thread.current[:vm]
35
+ vm.parens += 1
36
+
37
+ until @source.eof?
38
+ input = @source.get
39
+
40
+ if input == ')'
41
+ vm.parens -= 1
42
+ return true
43
+ elsif input == '('
44
+ skip_over_comment
45
+ end
36
46
  end
37
47
 
38
48
  error "F10: Unbalanced comment detected."
@@ -72,7 +72,7 @@ module XfOOrth
72
72
  puts vm.pop
73
73
  end
74
74
 
75
- '>' * vm.context.depth + '"' * vm.quotes
75
+ '>' * vm.context.depth + '"' * vm.quotes + '(' * vm.parens
76
76
  end
77
77
 
78
78
  #What is the source of this text?
@@ -113,4 +113,48 @@ module XfOOrth
113
113
  })
114
114
  })
115
115
 
116
+ #Support for the [[ ... ]] construct.
117
+ VirtualMachine.create_shared_method('[[', VmSpec, [:immediate], &lambda {|vm|
118
+ suspend_buffered_mode('[[')
119
+
120
+ vm.context.create_local_method(']]', LocalSpec, [:immediate], &lambda {|vm|
121
+ resume_buffered_mode('[[')
122
+ })
123
+ })
124
+
125
+ #Support for the , method. Embed a value into the code stream.
126
+ Object.create_shared_method(',', TosSpec, [], &lambda {|vm|
127
+ vm << "vm.push(#{foorth_embed}); "
128
+ })
129
+
130
+ #Support for the asm" method. Perform some actions in assembly language.
131
+ #[] asm"asm_string" []
132
+ VirtualMachine.create_shared_method('asm"', VmSpec, [:immediate], &lambda {|vm|
133
+ code = vm.pop
134
+
135
+ if execute_mode?
136
+ vm.instance_exec(self, &eval("lambda {|vm| #{code} }"))
137
+ else
138
+ vm << code
139
+ end
140
+ })
141
+
142
+ #Support for the .asm method. Perform some actions in assembly language.
143
+ #[asm_string] .asm []
144
+ String.create_shared_method('.asm', TosSpec, [], &lambda {|vm|
145
+ vm.instance_exec(vm, &eval("lambda {|vm| #{self} }"))
146
+ })
147
+
148
+ #Support for the ,asm" method. Embed some actions in assembly language.
149
+ #[] ,asm"asm_string" []
150
+ String.create_shared_method(',asm"', TosSpec, [], &lambda {|vm|
151
+ vm << self
152
+ })
153
+
154
+ #Support for the ,asm method. Embed some actions in assembly language.
155
+ #[asm_string] ,asm []
156
+ String.create_shared_method(',asm', TosSpec, [], &lambda {|vm|
157
+ vm << self
158
+ })
159
+
116
160
  end
@@ -65,6 +65,10 @@ module XfOOrth
65
65
  Object.create_shared_method('.default{{', NosSpec, [:stub])
66
66
  Object.create_shared_method('.new_default{{', NosSpec, [:stub])
67
67
 
68
+ #Embedding stubs.
69
+ Object.create_shared_method(',asm', TosSpec, [:stub])
70
+ Object.create_shared_method(',asm"', TosSpec, [:stub])
71
+
68
72
  #Define some "crossover" symbols.
69
73
  SymbolMap.add_entry('.is_class?', "foorth_is_class?".to_sym)
70
74
  SymbolMap.add_entry('.to_s', :to_foorth_s)
@@ -4,6 +4,7 @@
4
4
 
5
5
  require_relative 'monkey_patch/exceptions'
6
6
  require_relative 'monkey_patch/object'
7
+ require_relative 'monkey_patch/true'
7
8
  require_relative 'monkey_patch/false'
8
9
  require_relative 'monkey_patch/nil'
9
10
  require_relative 'monkey_patch/numeric'
@@ -8,4 +8,11 @@ class FalseClass
8
8
  self
9
9
  end
10
10
 
11
+ #Convert this object to a form suitable for embedding in a source string.
12
+ #<br>Returns
13
+ #* An embeddable form of this object as a string.
14
+ def foorth_embed
15
+ 'false'
16
+ end
17
+
11
18
  end
@@ -8,4 +8,11 @@ class NilClass
8
8
  false
9
9
  end
10
10
 
11
+ #Convert this object to a form suitable for embedding in a source string.
12
+ #<br>Returns
13
+ #* An embeddable form of this object as a string.
14
+ def foorth_embed
15
+ 'nil'
16
+ end
17
+
11
18
  end
@@ -6,14 +6,14 @@ class Numeric
6
6
  #<br>Returns
7
7
  #* An embeddable form of this number as a string.
8
8
  def foorth_embed
9
- self.to_s.freeze
9
+ self.to_s
10
10
  end
11
11
 
12
12
  #Convert this number to a single character string.
13
13
  def to_foorth_c
14
14
  as_int = Integer.foorth_coerce(self)
15
15
 
16
- if as_int < 0 || as_int > 1114111
16
+ if as_int < 0 || as_int > 1_114_111
17
17
  error "F40: Can't convert #{self} to a character."
18
18
  else
19
19
  [as_int].pack('U')
@@ -0,0 +1,18 @@
1
+ # coding: utf-8
2
+
3
+ #Extensions to the \TrueClass class required by the fOOrth language system.
4
+ class TrueClass
5
+
6
+ #Convert this object to a fOOrth boolean.
7
+ def to_foorth_b
8
+ self
9
+ end
10
+
11
+ #Convert this object to a form suitable for embedding in a source string.
12
+ #<br>Returns
13
+ #* An embeddable form of this object as a string.
14
+ def foorth_embed
15
+ 'true'
16
+ end
17
+
18
+ end
@@ -3,5 +3,5 @@
3
3
  #* version.rb - The version string for fOOrth.
4
4
  module XfOOrth
5
5
  #The version string for fOOrth.
6
- VERSION = "0.6.1"
6
+ VERSION = "0.6.2"
7
7
  end
@@ -45,12 +45,7 @@ end
45
45
 
46
46
  desc "Fire up an IRB session with fOOrth preloaded."
47
47
  task :console do
48
- require 'irb'
49
- require 'irb/completion'
50
- require './lib/fOOrth'
51
- puts "Starting an IRB console for fOOrth."
52
- ARGV.clear
53
- IRB.start
48
+ system "ruby irbt.rb local"
54
49
  end
55
50
 
56
51
  desc "Run an Interactive fOOrth Session."
@@ -42,4 +42,17 @@ class CompilerModeTester < Minitest::Test
42
42
  assert_raises(XfOOrth::XfOOrthError) { vm.unnest_mode("", ["{"]) }
43
43
  end
44
44
 
45
+ def test_vm_code_buffer
46
+ #Get the virtual machine.
47
+ vm = Thread.current[:vm]
48
+ vm.interpreter_reset
49
+ vm.compiler_reset
50
+
51
+ assert_raises(XfOOrth::XfOOrthError) { vm << "test" }
52
+ refute(vm.buffer_valid?)
53
+
54
+ vm.suspend_execute_mode("", "!")
55
+ assert(vm.buffer_valid?)
56
+ end
57
+
45
58
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fOOrth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Camilleri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-20 00:00:00.000000000 Z
11
+ date: 2016-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -170,14 +170,14 @@ dependencies:
170
170
  requirements:
171
171
  - - ">="
172
172
  - !ruby/object:Gem::Version
173
- version: 0.4.2
173
+ version: 0.4.8
174
174
  type: :runtime
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
- version: 0.4.2
180
+ version: 0.4.8
181
181
  description: An Object Oriented FORTHesque language gem.
182
182
  email: peter.c.camilleri@gmail.com
183
183
  executables:
@@ -193,6 +193,10 @@ files:
193
193
  - demo.rb
194
194
  - fOOrth.gemspec
195
195
  - fOOrth.reek
196
+ - images/banner_1.png
197
+ - images/banner_1.xcf
198
+ - images/cute-brown-owl-288.png
199
+ - images/cute-brown-owl.png
196
200
  - images/fOOrth_logo.png
197
201
  - integration/README.md
198
202
  - integration/_FILE_test.foorth
@@ -222,6 +226,7 @@ files:
222
226
  - integration/thread_lib_tests.rb
223
227
  - integration/time_lib_tests.rb
224
228
  - integration/vm_lib_tests.rb
229
+ - irbt.rb
225
230
  - lib/fOOrth.rb
226
231
  - lib/fOOrth/compiler.rb
227
232
  - lib/fOOrth/compiler/context.rb
@@ -313,6 +318,7 @@ files:
313
318
  - lib/fOOrth/monkey_patch/object.rb
314
319
  - lib/fOOrth/monkey_patch/rational.rb
315
320
  - lib/fOOrth/monkey_patch/string.rb
321
+ - lib/fOOrth/monkey_patch/true.rb
316
322
  - lib/fOOrth/symbol_map.rb
317
323
  - lib/fOOrth/version.rb
318
324
  - license.txt
@@ -363,5 +369,51 @@ rubygems_version: 2.2.2
363
369
  signing_key:
364
370
  specification_version: 4
365
371
  summary: FNF == fOOrth is Not FORTH.
366
- test_files: []
372
+ test_files:
373
+ - integration/README.md
374
+ - integration/_FILE_test.foorth
375
+ - integration/array_lib_tests.rb
376
+ - integration/class_lib_tests.rb
377
+ - integration/clone_lib_tests.rb
378
+ - integration/comparison_tests.rb
379
+ - integration/compile_lib_tests.rb
380
+ - integration/ctrl_struct_lib_tests.rb
381
+ - integration/data_ref_lib_tests.rb
382
+ - integration/exception_lib_tests.rb
383
+ - integration/fiber_bundle_tests.rb
384
+ - integration/hash_lib_tests.rb
385
+ - integration/in_stream_test_1.txt
386
+ - integration/load_test_one.foorth
387
+ - integration/load_test_two.foorth
388
+ - integration/numeric_lib_tests.rb
389
+ - integration/object_lib_tests.rb
390
+ - integration/procedure_lib_tests.rb
391
+ - integration/queue_lib_tests.rb
392
+ - integration/stack_lib_tests.rb
393
+ - integration/standard_lib_tests.rb
394
+ - integration/stdio_lib_tests.rb
395
+ - integration/stream_lib_tests.rb
396
+ - integration/string_lib_tests.rb
397
+ - integration/support/foorth_testing.rb
398
+ - integration/thread_lib_tests.rb
399
+ - integration/time_lib_tests.rb
400
+ - integration/vm_lib_tests.rb
401
+ - tests/compiler/context_tests.rb
402
+ - tests/compiler/file_source_test_one.txt
403
+ - tests/compiler/file_source_test_three.txt
404
+ - tests/compiler/file_source_test_two.txt
405
+ - tests/compiler/file_source_tests.rb
406
+ - tests/compiler/mode_tests.rb
407
+ - tests/compiler/parser_tests.rb
408
+ - tests/compiler/spec_tests.rb
409
+ - tests/compiler/string_source_tests.rb
410
+ - tests/core_tests.rb
411
+ - tests/interpreter/data_stack_tests.rb
412
+ - tests/monkey_patch/coerce_test.rb
413
+ - tests/monkey_patch/complex_test.rb
414
+ - tests/monkey_patch/numeric_test.rb
415
+ - tests/monkey_patch/object_test.rb
416
+ - tests/monkey_patch/rational_test.rb
417
+ - tests/monkey_patch/string_test.rb
418
+ - tests/symbol_map_tests.rb
367
419
  has_rdoc: