fOOrth 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.rdoc_options +17 -0
- data/Gemfile +4 -0
- data/README.md +67 -0
- data/bin/fOOrth +8 -0
- data/demo.rb +24 -0
- data/fOOrth.gemspec +40 -0
- data/fOOrth.reek +109 -0
- data/integration/README.md +12 -0
- data/integration/_FILE_test.foorth +5 -0
- data/integration/array_lib_tests.rb +360 -0
- data/integration/class_lib_tests.rb +116 -0
- data/integration/clone_lib_tests.rb +108 -0
- data/integration/comparison_tests.rb +132 -0
- data/integration/compile_lib_tests.rb +190 -0
- data/integration/ctrl_struct_lib_tests.rb +80 -0
- data/integration/data_ref_lib_tests.rb +43 -0
- data/integration/exception_lib_tests.rb +86 -0
- data/integration/fiber_bundle_tests.rb +380 -0
- data/integration/hash_lib_tests.rb +120 -0
- data/integration/in_stream_test_1.txt +4 -0
- data/integration/load_test_one.foorth +6 -0
- data/integration/load_test_two.foorth +4 -0
- data/integration/numeric_lib_tests.rb +321 -0
- data/integration/object_lib_tests.rb +38 -0
- data/integration/procedure_lib_tests.rb +40 -0
- data/integration/queue_lib_tests.rb +66 -0
- data/integration/stack_lib_tests.rb +70 -0
- data/integration/standard_lib_tests.rb +208 -0
- data/integration/stdio_lib_tests.rb +52 -0
- data/integration/stream_lib_tests.rb +196 -0
- data/integration/string_lib_tests.rb +217 -0
- data/integration/support/foorth_testing.rb +135 -0
- data/integration/thread_lib_tests.rb +83 -0
- data/integration/time_lib_tests.rb +791 -0
- data/integration/vm_lib_tests.rb +38 -0
- data/lib/fOOrth.rb +57 -0
- data/lib/fOOrth/compiler.rb +78 -0
- data/lib/fOOrth/compiler/context.rb +49 -0
- data/lib/fOOrth/compiler/context/locals.rb +34 -0
- data/lib/fOOrth/compiler/context/map_name.rb +92 -0
- data/lib/fOOrth/compiler/context/tags.rb +48 -0
- data/lib/fOOrth/compiler/modes.rb +32 -0
- data/lib/fOOrth/compiler/modes/compiled.rb +41 -0
- data/lib/fOOrth/compiler/modes/deferred.rb +57 -0
- data/lib/fOOrth/compiler/modes/delayed.rb +40 -0
- data/lib/fOOrth/compiler/modes/nested.rb +34 -0
- data/lib/fOOrth/compiler/modes/suspend.rb +32 -0
- data/lib/fOOrth/compiler/parser.rb +26 -0
- data/lib/fOOrth/compiler/parser/get_string.rb +71 -0
- data/lib/fOOrth/compiler/parser/normal.rb +53 -0
- data/lib/fOOrth/compiler/parser/skip.rb +50 -0
- data/lib/fOOrth/compiler/parser/special.rb +42 -0
- data/lib/fOOrth/compiler/process.rb +47 -0
- data/lib/fOOrth/compiler/process/generate.rb +24 -0
- data/lib/fOOrth/compiler/process/get_token.rb +23 -0
- data/lib/fOOrth/compiler/process/procedure.rb +55 -0
- data/lib/fOOrth/compiler/process/string.rb +20 -0
- data/lib/fOOrth/compiler/source.rb +51 -0
- data/lib/fOOrth/compiler/source/console.rb +70 -0
- data/lib/fOOrth/compiler/source/file_source.rb +37 -0
- data/lib/fOOrth/compiler/source/read_point.rb +46 -0
- data/lib/fOOrth/compiler/source/string_source.rb +28 -0
- data/lib/fOOrth/compiler/token.rb +37 -0
- data/lib/fOOrth/compiler/word_specs.rb +178 -0
- data/lib/fOOrth/core.rb +27 -0
- data/lib/fOOrth/core/class.rb +116 -0
- data/lib/fOOrth/core/object.rb +78 -0
- data/lib/fOOrth/core/virtual_machine.rb +28 -0
- data/lib/fOOrth/debug.rb +13 -0
- data/lib/fOOrth/debug/context_dump.rb +31 -0
- data/lib/fOOrth/debug/dbg_puts.rb +17 -0
- data/lib/fOOrth/debug/display_abort.rb +37 -0
- data/lib/fOOrth/debug/vm_dump.rb +27 -0
- data/lib/fOOrth/initialize.rb +83 -0
- data/lib/fOOrth/interpreter.rb +24 -0
- data/lib/fOOrth/interpreter/add_to_hash.rb +17 -0
- data/lib/fOOrth/interpreter/data_stack.rb +125 -0
- data/lib/fOOrth/interpreter/do_loop.rb +55 -0
- data/lib/fOOrth/interpreter/squash.rb +25 -0
- data/lib/fOOrth/library.rb +38 -0
- data/lib/fOOrth/library/array_library.rb +577 -0
- data/lib/fOOrth/library/bundle_library.rb +112 -0
- data/lib/fOOrth/library/class_library.rb +90 -0
- data/lib/fOOrth/library/clone_library.rb +72 -0
- data/lib/fOOrth/library/command_library.rb +205 -0
- data/lib/fOOrth/library/compile_library.rb +181 -0
- data/lib/fOOrth/library/complex_library.rb +81 -0
- data/lib/fOOrth/library/ctrl_struct_library.rb +116 -0
- data/lib/fOOrth/library/data_ref_library.rb +100 -0
- data/lib/fOOrth/library/duration/arithmetic.rb +114 -0
- data/lib/fOOrth/library/duration/formatter.rb +152 -0
- data/lib/fOOrth/library/duration/intervals.rb +233 -0
- data/lib/fOOrth/library/duration/make.rb +75 -0
- data/lib/fOOrth/library/duration_library.rb +52 -0
- data/lib/fOOrth/library/fiber_library.rb +120 -0
- data/lib/fOOrth/library/hash_library.rb +203 -0
- data/lib/fOOrth/library/in_stream_library.rb +81 -0
- data/lib/fOOrth/library/integer_library.rb +104 -0
- data/lib/fOOrth/library/mutex_library.rb +31 -0
- data/lib/fOOrth/library/numeric_library.rb +380 -0
- data/lib/fOOrth/library/object_library.rb +80 -0
- data/lib/fOOrth/library/other_value_types_library.rb +96 -0
- data/lib/fOOrth/library/out_stream_library.rb +146 -0
- data/lib/fOOrth/library/procedure_library.rb +65 -0
- data/lib/fOOrth/library/queue_library.rb +47 -0
- data/lib/fOOrth/library/rational_library.rb +90 -0
- data/lib/fOOrth/library/stack_library.rb +56 -0
- data/lib/fOOrth/library/stdio_library.rb +56 -0
- data/lib/fOOrth/library/string_library.rb +285 -0
- data/lib/fOOrth/library/stubs.rb +76 -0
- data/lib/fOOrth/library/sync_bundle_library.rb +50 -0
- data/lib/fOOrth/library/thread_library.rb +73 -0
- data/lib/fOOrth/library/time_library.rb +302 -0
- data/lib/fOOrth/library/vm_library.rb +105 -0
- data/lib/fOOrth/main.rb +125 -0
- data/lib/fOOrth/monkey_patch.rb +14 -0
- data/lib/fOOrth/monkey_patch/complex.rb +30 -0
- data/lib/fOOrth/monkey_patch/exceptions.rb +154 -0
- data/lib/fOOrth/monkey_patch/false.rb +11 -0
- data/lib/fOOrth/monkey_patch/float.rb +22 -0
- data/lib/fOOrth/monkey_patch/integer.rb +22 -0
- data/lib/fOOrth/monkey_patch/nil.rb +11 -0
- data/lib/fOOrth/monkey_patch/numeric.rb +33 -0
- data/lib/fOOrth/monkey_patch/object.rb +43 -0
- data/lib/fOOrth/monkey_patch/rational.rb +31 -0
- data/lib/fOOrth/monkey_patch/string.rb +51 -0
- data/lib/fOOrth/symbol_map.rb +82 -0
- data/lib/fOOrth/version.rb +7 -0
- data/license.txt +21 -0
- data/rakefile.rb +65 -0
- data/reek.txt +1 -0
- data/sire.rb +132 -0
- data/t.txt +3 -0
- data/test.foorth +5 -0
- data/tests/compiler/context_tests.rb +180 -0
- data/tests/compiler/file_source_test_one.txt +1 -0
- data/tests/compiler/file_source_test_three.txt +3 -0
- data/tests/compiler/file_source_test_two.txt +3 -0
- data/tests/compiler/file_source_tests.rb +130 -0
- data/tests/compiler/mode_tests.rb +45 -0
- data/tests/compiler/parser_tests.rb +116 -0
- data/tests/compiler/spec_tests.rb +113 -0
- data/tests/compiler/string_source_tests.rb +128 -0
- data/tests/core_tests.rb +138 -0
- data/tests/interpreter/data_stack_tests.rb +119 -0
- data/tests/monkey_patch/coerce_test.rb +131 -0
- data/tests/monkey_patch/complex_test.rb +25 -0
- data/tests/monkey_patch/numeric_test.rb +62 -0
- data/tests/monkey_patch/object_test.rb +49 -0
- data/tests/monkey_patch/rational_test.rb +57 -0
- data/tests/monkey_patch/string_test.rb +53 -0
- data/tests/symbol_map_tests.rb +53 -0
- metadata +366 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 555eecaccf4bd5f00d4adb2c45d95a229fcc286d
|
4
|
+
data.tar.gz: 39ab0f4185e63de1958507d4a4bd85f117dd8fef
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cc6b7b66c30d45a9f0aa7717afad8fc2eac30151b9cbaa82bd495bbf98dc3687506f53d3094780f17fbc64c614115666df7d633debc9f7f2bf674f8f1d99020a
|
7
|
+
data.tar.gz: 897a8d530c9cfe6a81448f90cb45ad2134904048d625075318a2ca49fe92b21b10462ce5abf6835d5451a936decf090c61b2f1a72d3240560dfc69c163fdc4df
|
data/.gitignore
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
*.bat
|
2
|
+
*.zip
|
3
|
+
*.tmp
|
4
|
+
*.gem
|
5
|
+
*.rbc
|
6
|
+
.bundle
|
7
|
+
.config
|
8
|
+
.yardoc
|
9
|
+
Gemfile.lock
|
10
|
+
InstalledFiles
|
11
|
+
_yardoc
|
12
|
+
coverage
|
13
|
+
docs/.~lock.*
|
14
|
+
lib/bundler/man
|
15
|
+
pkg
|
16
|
+
rdoc
|
17
|
+
spec/reports
|
18
|
+
test/tmp
|
19
|
+
test/version_tmp
|
20
|
+
tmp
|
21
|
+
temp.txt
|
data/.rdoc_options
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
--- !ruby/object:RDoc::Options
|
2
|
+
encoding: UTF-8
|
3
|
+
static_path: []
|
4
|
+
rdoc_include:
|
5
|
+
- .
|
6
|
+
charset: UTF-8
|
7
|
+
exclude: !ruby/regexp /(?-mix:doc)|(?-mix:sire.rb)|(?-mix:.*\.4th)|(?-mix:.*\.odt)|(?-mix:.*bat)/
|
8
|
+
hyperlink_all: false
|
9
|
+
line_numbers: false
|
10
|
+
main_page:
|
11
|
+
markup: rdoc
|
12
|
+
page_dir:
|
13
|
+
show_hash: false
|
14
|
+
tab_width: 8
|
15
|
+
title:
|
16
|
+
visibility: :protected
|
17
|
+
webcvs:
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# The fOOrth Language gem.
|
2
|
+
|
3
|
+
This file contains the read-me for the fOOrth language gem. The fOOrth
|
4
|
+
language is an experimental variant of FORTH that attempts to incorporate
|
5
|
+
object oriented and functional programming concepts.
|
6
|
+
|
7
|
+
As an aside, there can be no doubt that the fOOrth project is an utter waste
|
8
|
+
of anyone's time, unless one counts the insights gained into the inner
|
9
|
+
workings of Ruby and meta programming.
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
Adding fOOrth can be as simple as:
|
13
|
+
|
14
|
+
require 'fOOrth'
|
15
|
+
XfOOrth.main
|
16
|
+
|
17
|
+
This will launch an interactive fOOrth session. Alternatively this can be
|
18
|
+
done with:
|
19
|
+
|
20
|
+
rake run
|
21
|
+
|
22
|
+
Be sure to be in the folder that contains the rakefile in order for this
|
23
|
+
command to work.
|
24
|
+
|
25
|
+
<br>If, instead, a non-interactive facility is required, use:
|
26
|
+
|
27
|
+
require 'fOOrth'
|
28
|
+
XfOOrth.virtual_machine.process_string '1 2 +'
|
29
|
+
|
30
|
+
where the string is fOOrth code to be executed, or for a file of code, use:
|
31
|
+
|
32
|
+
require 'fOOrth'
|
33
|
+
XfOOrth.virtual_machine.process_file 'my_file.foorth'
|
34
|
+
|
35
|
+
## Further Documentation
|
36
|
+
|
37
|
+
The fOOrth Language System is documented in The fOOrth User Guide. This is
|
38
|
+
currently only available in Open Office format, and is still also very much
|
39
|
+
a work in progress. Please see The_fOOrth_User_Guide.odt in the docs folder.
|
40
|
+
|
41
|
+
Also for those who do not have or don't want Open Office: As each major
|
42
|
+
version of fOOrth is made available, expect to see portable document format
|
43
|
+
(pdf) versions of the guide. (In the docs folder in the repository)
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
#### Plan A
|
48
|
+
|
49
|
+
1. Fork it
|
50
|
+
2. Switch to the development branch ('git branch development')
|
51
|
+
3. Create your feature branch ('git checkout -b my-new-feature')
|
52
|
+
4. Commit your changes ('git commit -am "Add some feature"')
|
53
|
+
5. Push to the branch ('git push origin my-new-feature')
|
54
|
+
6. Create new Pull Request
|
55
|
+
|
56
|
+
|
57
|
+
For more details on the branching strategy, please see:
|
58
|
+
http://nvie.com/posts/a-successful-git-branching-model/
|
59
|
+
|
60
|
+
|
61
|
+
#### Plan B
|
62
|
+
|
63
|
+
Go to the GitHub repository and raise an issue calling attention to some
|
64
|
+
aspect that could use some TLC or a suggestion or an idea. Apply labels
|
65
|
+
to the issue that match the point you are trying to make. Then follow
|
66
|
+
your issue and keep up-to-date as it is worked on. All input are greatly
|
67
|
+
appreciated.
|
data/bin/fOOrth
ADDED
data/demo.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#This file contains a minimum host environment for running the fOOrth system.
|
4
|
+
|
5
|
+
if ARGV[0] == 'local'
|
6
|
+
require_relative 'lib/fOOrth'
|
7
|
+
puts "\nOption(local) Loaded fOOrth from the local code folder."
|
8
|
+
elsif defined?(XfOOrth)
|
9
|
+
puts "\nThe fOOrth system is already loaded."
|
10
|
+
else
|
11
|
+
begin
|
12
|
+
require 'fOOrth'
|
13
|
+
puts "\nLoaded fOOrth from the system gem."
|
14
|
+
rescue LoadError
|
15
|
+
require_relative 'lib/fOOrth'
|
16
|
+
puts "\nLoaded fOOrth from the local code folder."
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
puts
|
21
|
+
|
22
|
+
if __FILE__==$0
|
23
|
+
XfOOrth::main
|
24
|
+
end
|
data/fOOrth.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fOOrth/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fOOrth"
|
8
|
+
spec.version = XfOOrth::VERSION
|
9
|
+
spec.authors = ["Peter Camilleri"]
|
10
|
+
spec.email = "peter.c.camilleri@gmail.com"
|
11
|
+
spec.homepage = "http://teuthida-technologies.com/"
|
12
|
+
spec.description = "An Object Oriented FORTHesque language gem."
|
13
|
+
spec.summary = "FNF == fOOrth is Not FORTH."
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
raw_list = `git ls-files`.split($/)
|
17
|
+
raw_list = raw_list.keep_if {|entry| !entry.start_with?("docs") }
|
18
|
+
|
19
|
+
spec.files = raw_list
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
spec.executables = ["fOOrth"]
|
24
|
+
|
25
|
+
spec.required_ruby_version = '>=1.9.3'
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
28
|
+
spec.add_development_dependency 'rake'
|
29
|
+
spec.add_development_dependency 'reek', "~> 3.0"
|
30
|
+
spec.add_development_dependency 'minitest', "~> 5.7"
|
31
|
+
spec.add_development_dependency 'minitest_visible', ">= 0.1.0"
|
32
|
+
spec.add_development_dependency 'rdoc', "~> 4.0.1"
|
33
|
+
|
34
|
+
spec.add_runtime_dependency 'ruby_sscanf', ">= 0.2.0"
|
35
|
+
spec.add_runtime_dependency 'format_engine', ">= 0.7.0"
|
36
|
+
spec.add_runtime_dependency 'full_clone'
|
37
|
+
spec.add_runtime_dependency 'safe_clone'
|
38
|
+
spec.add_runtime_dependency 'in_array'
|
39
|
+
spec.add_runtime_dependency 'mini_readline', ">= 0.3.3"
|
40
|
+
end
|
data/fOOrth.reek
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
---
|
2
|
+
Attribute:
|
3
|
+
enabled: false
|
4
|
+
exclude: []
|
5
|
+
BooleanParameter:
|
6
|
+
enabled: true
|
7
|
+
exclude: []
|
8
|
+
ClassVariable:
|
9
|
+
enabled: true
|
10
|
+
exclude: []
|
11
|
+
ControlParameter:
|
12
|
+
enabled: true
|
13
|
+
exclude: []
|
14
|
+
DataClump:
|
15
|
+
enabled: true
|
16
|
+
exclude: []
|
17
|
+
max_copies: 2
|
18
|
+
min_clump_size: 2
|
19
|
+
DuplicateMethodCall:
|
20
|
+
enabled: true
|
21
|
+
exclude: []
|
22
|
+
max_calls: 1
|
23
|
+
allow_calls: []
|
24
|
+
FeatureEnvy:
|
25
|
+
enabled: true
|
26
|
+
exclude: []
|
27
|
+
IrresponsibleModule:
|
28
|
+
enabled: true
|
29
|
+
exclude: []
|
30
|
+
LongParameterList:
|
31
|
+
enabled: true
|
32
|
+
exclude: []
|
33
|
+
max_params: 3
|
34
|
+
overrides:
|
35
|
+
initialize:
|
36
|
+
max_params: 5
|
37
|
+
LongYieldList:
|
38
|
+
enabled: true
|
39
|
+
exclude: []
|
40
|
+
max_params: 3
|
41
|
+
NestedIterators:
|
42
|
+
enabled: true
|
43
|
+
exclude: []
|
44
|
+
max_allowed_nesting: 1
|
45
|
+
ignore_iterators: []
|
46
|
+
NilCheck:
|
47
|
+
enabled: true
|
48
|
+
exclude: []
|
49
|
+
PrimaDonnaMethod:
|
50
|
+
enabled: true
|
51
|
+
exclude: []
|
52
|
+
RepeatedConditional:
|
53
|
+
enabled: true
|
54
|
+
exclude: []
|
55
|
+
max_ifs: 2
|
56
|
+
TooManyInstanceVariables:
|
57
|
+
enabled: true
|
58
|
+
exclude: []
|
59
|
+
max_instance_variables: 9
|
60
|
+
TooManyMethods:
|
61
|
+
enabled: true
|
62
|
+
exclude: []
|
63
|
+
max_methods: 25
|
64
|
+
TooManyStatements:
|
65
|
+
enabled: true
|
66
|
+
exclude:
|
67
|
+
- initialize
|
68
|
+
max_statements: 7
|
69
|
+
UncommunicativeMethodName:
|
70
|
+
enabled: true
|
71
|
+
exclude: []
|
72
|
+
reject:
|
73
|
+
- !ruby/regexp /^[a-z]$/
|
74
|
+
- !ruby/regexp /[0-9]$/
|
75
|
+
- !ruby/regexp /[A-Z]/
|
76
|
+
accept: []
|
77
|
+
UncommunicativeModuleName:
|
78
|
+
enabled: true
|
79
|
+
exclude: []
|
80
|
+
reject:
|
81
|
+
- !ruby/regexp /^.$/
|
82
|
+
- !ruby/regexp /[0-9]$/
|
83
|
+
accept:
|
84
|
+
- Inline::C
|
85
|
+
UncommunicativeParameterName:
|
86
|
+
enabled: true
|
87
|
+
exclude: []
|
88
|
+
reject:
|
89
|
+
- !ruby/regexp /^.$/
|
90
|
+
- !ruby/regexp /[0-9]$/
|
91
|
+
- !ruby/regexp /[A-Z]/
|
92
|
+
- !ruby/regexp /^_/
|
93
|
+
accept: []
|
94
|
+
UncommunicativeVariableName:
|
95
|
+
enabled: true
|
96
|
+
exclude: []
|
97
|
+
reject:
|
98
|
+
- !ruby/regexp /^.$/
|
99
|
+
- !ruby/regexp /[0-9]$/
|
100
|
+
- !ruby/regexp /[A-Z]/
|
101
|
+
accept:
|
102
|
+
- _
|
103
|
+
UnusedParameters:
|
104
|
+
enabled: true
|
105
|
+
exclude: []
|
106
|
+
UtilityFunction:
|
107
|
+
enabled: true
|
108
|
+
exclude: []
|
109
|
+
max_helper_calls: 1
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# The Integration Test Suite.
|
2
|
+
|
3
|
+
While the tests folder mostly focuses on the internals of fOOrth, and in fact
|
4
|
+
does not even load the run time libraries, the integration test suite loads
|
5
|
+
the entire fOOrth language in order to be able to conduct testing on the
|
6
|
+
system as a whole.
|
7
|
+
|
8
|
+
This is done via the following rake command:
|
9
|
+
|
10
|
+
rake integration
|
11
|
+
|
12
|
+
Most of the integration testing is done in fOOrth itself.
|
@@ -0,0 +1,360 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require_relative '../lib/fOOrth'
|
4
|
+
require_relative 'support/foorth_testing'
|
5
|
+
gem 'minitest'
|
6
|
+
require 'minitest/autorun'
|
7
|
+
require 'minitest_visible'
|
8
|
+
|
9
|
+
#Test the standard fOOrth library.
|
10
|
+
class ArrayLibraryTester < Minitest::Test
|
11
|
+
|
12
|
+
include XfOOrthTestExtensions
|
13
|
+
|
14
|
+
#Track mini-test progress.
|
15
|
+
include MinitestVisible
|
16
|
+
|
17
|
+
def test_some_array_basics
|
18
|
+
foorth_equal(' Array ', [Array])
|
19
|
+
|
20
|
+
foorth_equal(' Array .new ', [[]])
|
21
|
+
foorth_equal(': tt00 Array .new ; ', [])
|
22
|
+
foorth_equal('tt00 ', [[]])
|
23
|
+
|
24
|
+
foorth_equal(' 3 Array .new_size ', [[0,0,0]])
|
25
|
+
foorth_equal(': tt01 3 Array .new_size ; ', [])
|
26
|
+
foorth_equal('tt01 ', [[0,0,0]])
|
27
|
+
|
28
|
+
foorth_equal('try "apple" Array .new_size catch end', [])
|
29
|
+
foorth_equal('try -3 Array .new_size catch end', [])
|
30
|
+
|
31
|
+
|
32
|
+
foorth_equal(' 3 Array .new_value ', [[3]])
|
33
|
+
foorth_equal(': tt02 3 Array .new_value ; ', [])
|
34
|
+
foorth_equal('tt02 ', [[3]])
|
35
|
+
|
36
|
+
foorth_equal(' 3 2 Array .new_values ', [[3,3]])
|
37
|
+
foorth_equal(': tt03 3 2 Array .new_values ; ', [])
|
38
|
+
foorth_equal('tt03 ', [[3,3]])
|
39
|
+
|
40
|
+
foorth_equal('try "apple" "pie" Array .new_values catch end', [])
|
41
|
+
foorth_equal('try "apple" -3 Array .new_values catch end', [])
|
42
|
+
|
43
|
+
foorth_equal(' 3 Array .new{{ x }} ', [[0,1,2]])
|
44
|
+
foorth_equal(': tt04 3 Array .new{{ x }} ; ', [])
|
45
|
+
foorth_equal('tt04 ', [[0,1,2]])
|
46
|
+
|
47
|
+
foorth_equal('try -3 Array .new{{ x }} catch end', [])
|
48
|
+
foorth_equal('try "apple" Array .new{{ x }} catch end', [])
|
49
|
+
foorth_equal('try 3 Array .new{{ throw"xx" }} catch end', [])
|
50
|
+
|
51
|
+
foorth_equal(' [ 0 1 2 ] ', [[0,1,2]])
|
52
|
+
foorth_equal(': tt05 [ 0 1 2 ] ; ', [])
|
53
|
+
foorth_equal('tt05 ', [[0,1,2]])
|
54
|
+
|
55
|
+
foorth_equal(' [ 3 6 do i loop ] ', [[3,4,5]])
|
56
|
+
foorth_equal(': tt06 [ 3 6 do i loop ] ; ', [])
|
57
|
+
foorth_equal('tt06 ', [[3,4,5]])
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_arrays_in_variables
|
61
|
+
foorth_equal('[ 3 6 9 ] val$: $taiv1 ', [])
|
62
|
+
foorth_equal('$taiv1 ', [[3,6,9]])
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_some_basic_operators
|
66
|
+
foorth_equal('[ 3 6 9 ] [ 3 6 9 ] = ', [true])
|
67
|
+
foorth_equal('[ 3 6 9 ] [ 3 6 8 ] = ', [false])
|
68
|
+
foorth_equal('[ 3 6 9 ] [ 3 6 ] = ', [false])
|
69
|
+
|
70
|
+
foorth_equal('[ 3 6 9 ] [ 3 6 9 ] <>', [false])
|
71
|
+
foorth_equal('[ 3 6 9 ] [ 3 6 8 ] <>', [true])
|
72
|
+
foorth_equal('[ 3 6 9 ] [ 3 6 ] <>', [true])
|
73
|
+
|
74
|
+
foorth_equal('[ 3 6 9 ] [ 3 6 9 ] identical?', [false])
|
75
|
+
foorth_equal('[ 3 6 9 ] [ 3 6 9 ] distinct?', [true])
|
76
|
+
|
77
|
+
foorth_equal('[ 3 6 9 ] dup identical?', [true])
|
78
|
+
foorth_equal('[ 3 6 9 ] dup distinct?', [false])
|
79
|
+
|
80
|
+
foorth_equal('[ 3 6 9 ] clone identical?', [false])
|
81
|
+
foorth_equal('[ 3 6 9 ] clone distinct?', [true])
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_the_each
|
85
|
+
foorth_equal('4 Array .new{{ x 1 + dup * }} val$: $tte ', [])
|
86
|
+
foorth_equal('$tte', [[1,4,9,16]])
|
87
|
+
|
88
|
+
foorth_equal('$tte .each{{ x }} ', [0,1,2,3])
|
89
|
+
foorth_equal('$tte .each{{ v }} ', [1,4,9,16])
|
90
|
+
|
91
|
+
foorth_equal(': tte $tte .each{{ v }} ;', [])
|
92
|
+
foorth_equal('tte', [1,4,9,16])
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_the_map
|
96
|
+
foorth_equal('[ 2 3 4 ] .map{{ v 1+ }}', [[3,4,5]])
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_the_select
|
100
|
+
foorth_equal('[ 0 10 do i loop ] .select{{ v 1 and 0= }}', [[0,2,4,6,8]])
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_simple_array_indexing
|
104
|
+
foorth_equal('4 Array .new{{ x 1 + dup * }} val$: $tte ', [])
|
105
|
+
foorth_equal('$tte', [[1,4,9,16]])
|
106
|
+
|
107
|
+
foorth_equal('$tte @ ', [1])
|
108
|
+
foorth_equal('10 $tte ! ', [])
|
109
|
+
foorth_equal('$tte @ ', [10])
|
110
|
+
|
111
|
+
foorth_equal(' 0 $tte .[]@ ', [10])
|
112
|
+
foorth_equal(' -1 $tte .[]@ ', [16])
|
113
|
+
foorth_equal('1 0 $tte .[]! ', [])
|
114
|
+
foorth_equal('$tte @ ', [1])
|
115
|
+
|
116
|
+
foorth_equal(' 10 $tte .[]@ ', [nil])
|
117
|
+
foorth_equal('-10 $tte .[]@ ', [nil])
|
118
|
+
|
119
|
+
foorth_equal(' "0" $tte .[]@ ', [1])
|
120
|
+
foorth_equal('try "apple" $tte .[]@ catch end ', [])
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_the_left_group
|
125
|
+
foorth_equal('2 [ 9 3 5 ] .left ', [[9,3]])
|
126
|
+
foorth_equal('2 [ 9 3 5 ] .-left ', [[5]])
|
127
|
+
foorth_equal('2 [ 0 8 9 ] [ 9 3 5 ] .+left ', [[0,8,9,5]])
|
128
|
+
foorth_equal('2 "apple" [ 9 3 5 ] .+left ', [["apple",5]])
|
129
|
+
foorth_equal('2 [ 0 8 9 7 ] .^left ', [[9,7], [0,8]])
|
130
|
+
|
131
|
+
foorth_equal('try "apple" [ 9 3 5 ] .left catch end', [])
|
132
|
+
foorth_equal('try -1 [ 9 3 5 ] .left catch end', [])
|
133
|
+
|
134
|
+
foorth_equal('try "apple" [ 9 3 5 ] .-left catch end', [])
|
135
|
+
foorth_equal('try -1 [ 9 3 5 ] .-left catch end', [])
|
136
|
+
|
137
|
+
foorth_equal('try -2 [ 0 8 9 ] [ 9 3 5 ] .+left catch end', [])
|
138
|
+
foorth_equal('try "apple" [ 0 8 9 ] [ 9 3 5 ] .+left catch end', [])
|
139
|
+
|
140
|
+
foorth_equal('try -2 [ 0 8 9 7 ] .^left catch end ', [])
|
141
|
+
foorth_equal('try "apple" [ 0 8 9 7 ] .^left catch end ', [])
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_the_right_group
|
145
|
+
foorth_equal('2 [ 9 3 5 ] .right ', [[3,5]])
|
146
|
+
foorth_equal('2 [ 9 3 5 ] .-right ', [[9]])
|
147
|
+
foorth_equal('2 [ 0 8 9 ] [ 9 3 5 ] .+right ', [[9,0,8,9]])
|
148
|
+
foorth_equal('2 "apple" [ 9 3 5 ] .+right ', [[9,"apple"]])
|
149
|
+
foorth_equal('2 [ 0 8 9 7 ] .^right ', [[0,8], [9,7]])
|
150
|
+
|
151
|
+
foorth_equal('try "apple" [ 9 3 5 ] .right catch end', [])
|
152
|
+
foorth_equal('try -1 [ 9 3 5 ] .right catch end', [])
|
153
|
+
|
154
|
+
foorth_equal('try "apple" [ 9 3 5 ] .-right catch end', [])
|
155
|
+
foorth_equal('try -1 [ 9 3 5 ] .-right catch end', [])
|
156
|
+
|
157
|
+
foorth_equal('try -2 [ 0 8 9 ] [ 9 3 5 ] .+right catch end', [])
|
158
|
+
foorth_equal('try "apple" [ 0 8 9 ] [ 9 3 5 ] .+right catch end', [])
|
159
|
+
|
160
|
+
foorth_equal('try -2 [ 0 8 9 7 ] .^right catch end ', [])
|
161
|
+
foorth_equal('try "apple" [ 0 8 9 7 ] .^right catch end ', [])
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_the_mid_group
|
165
|
+
foorth_equal('1 2 [ 9 3 5 7 ] .mid ', [[3,5]])
|
166
|
+
foorth_equal('1 2 [ 9 3 5 7 ] .-mid ', [[9,7]])
|
167
|
+
foorth_equal('1 2 [ 0 8 9 ] [ 9 3 5 7 ] .+mid ', [[9,0,8,9,7]])
|
168
|
+
foorth_equal('1 2 "apple" [ 9 3 5 7 ] .+mid ', [[9,"apple",7]])
|
169
|
+
foorth_equal('1 2 [ 9 3 5 7 ] .^mid ', [[9,7], [3,5]])
|
170
|
+
|
171
|
+
foorth_equal('try "apple" 2 [ 9 3 5 7 ] .mid catch end', [])
|
172
|
+
foorth_equal('try 1 "apple" [ 9 3 5 7 ] .mid catch end', [])
|
173
|
+
foorth_equal('try -1 2 [ 9 3 5 7 ] .mid catch end', [])
|
174
|
+
foorth_equal('try 1 -2 [ 9 3 5 7 ] .mid catch end', [])
|
175
|
+
|
176
|
+
foorth_equal('try "apple" 2 [ 9 3 5 7 ] .-mid catch end', [])
|
177
|
+
foorth_equal('try 1 "apple" [ 9 3 5 7 ] .-mid catch end', [])
|
178
|
+
foorth_equal('try -1 2 [ 9 3 5 7 ] .-mid catch end', [])
|
179
|
+
foorth_equal('try 1 -2 [ 9 3 5 7 ] .-mid catch end', [])
|
180
|
+
|
181
|
+
foorth_equal('try "apple" 2 [ 0 8 9 ] [ 9 3 5 7 ] .+mid catch end ', [])
|
182
|
+
foorth_equal('try 1 "apple" [ 0 8 9 ] [ 9 3 5 7 ] .+mid catch end ', [])
|
183
|
+
foorth_equal('try -1 2 [ 0 8 9 ] [ 9 3 5 7 ] .+mid catch end ', [])
|
184
|
+
foorth_equal('try 1 -2 [ 0 8 9 ] [ 9 3 5 7 ] .+mid catch end ', [])
|
185
|
+
|
186
|
+
foorth_equal('try -1 2 [ 9 3 5 7 ] .^mid catch end', [])
|
187
|
+
foorth_equal('try "apple" 2 [ 9 3 5 7 ] .^mid catch end', [])
|
188
|
+
foorth_equal('try 1 -2 [ 9 3 5 7 ] .^mid catch end', [])
|
189
|
+
foorth_equal('try 1 "apple" [ 9 3 5 7 ] .^mid catch end', [])
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_the_midlr_group
|
193
|
+
foorth_equal('1 1 [ 9 3 5 7 ] .midlr ', [[3,5]])
|
194
|
+
foorth_equal('1 1 [ 9 3 5 7 ] .-midlr ', [[9,7]])
|
195
|
+
foorth_equal('0 2 [ 9 3 5 7 ] .-midlr ', [[5,7]])
|
196
|
+
foorth_equal('2 0 [ 9 3 5 7 ] .-midlr ', [[9,3]])
|
197
|
+
foorth_equal('1 1 [ 0 8 9 ] [ 9 3 5 7 ] .+midlr ', [[9,0,8,9,7]])
|
198
|
+
foorth_equal('0 2 [ 0 8 9 ] [ 9 3 5 7 ] .+midlr ', [[0,8,9,5,7]])
|
199
|
+
foorth_equal('2 0 [ 0 8 9 ] [ 9 3 5 7 ] .+midlr ', [[9,3,0,8,9]])
|
200
|
+
foorth_equal('1 1 "apple" [ 9 3 5 7 ] .+midlr ', [[9,"apple",7]])
|
201
|
+
foorth_equal('1 1 [ 9 3 5 7 ] .^midlr ', [[9,7], [3,5]])
|
202
|
+
|
203
|
+
foorth_equal('try "apple" 2 [ 9 3 5 7 ] .midlr catch end', [])
|
204
|
+
foorth_equal('try 2 "apple" [ 9 3 5 7 ] .midlr catch end', [])
|
205
|
+
foorth_equal('try -2 2 [ 9 3 5 7 ] .midlr catch end', [])
|
206
|
+
foorth_equal('try 2 -2 [ 9 3 5 7 ] .midlr catch end', [])
|
207
|
+
|
208
|
+
foorth_equal('try "apple" 2 [ 9 3 5 7 ] .-midlr catch end', [])
|
209
|
+
foorth_equal('try 2 "apple" [ 9 3 5 7 ] .-midlr catch end', [])
|
210
|
+
foorth_equal('try -2 2 [ 9 3 5 7 ] .-midlr catch end', [])
|
211
|
+
foorth_equal('try 2 -2 [ 9 3 5 7 ] .-midlr catch end', [])
|
212
|
+
|
213
|
+
foorth_equal('try "apple" 1 [ 0 8 9 ] [ 9 3 5 7 ] .+midlr catch end', [])
|
214
|
+
foorth_equal('try 1 "apple" [ 0 8 9 ] [ 9 3 5 7 ] .+midlr catch end', [])
|
215
|
+
foorth_equal('try -1 1 [ 0 8 9 ] [ 9 3 5 7 ] .+midlr catch end', [])
|
216
|
+
foorth_equal('try 1 -1 [ 0 8 9 ] [ 9 3 5 7 ] .+midlr catch end', [])
|
217
|
+
|
218
|
+
foorth_equal('try -1 1 [ 9 3 5 7 ] .^midlr catch end ', [])
|
219
|
+
foorth_equal('try "apple" 1 [ 9 3 5 7 ] .^midlr catch end ', [])
|
220
|
+
foorth_equal('try 1 -1 [ 9 3 5 7 ] .^midlr catch end ', [])
|
221
|
+
foorth_equal('try 1 "apple" [ 9 3 5 7 ] .^midlr catch end ', [])
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_the_dequeue_methods
|
225
|
+
foorth_run('[ 1 2 3 ] val$: $tdqm')
|
226
|
+
|
227
|
+
#Test the non-mutating methods.
|
228
|
+
foorth_equal('$tdqm .pop_left', [[2,3], 1])
|
229
|
+
foorth_equal('$tdqm ', [[1,2,3]])
|
230
|
+
foorth_raises('[ ] .pop_left')
|
231
|
+
|
232
|
+
foorth_equal('$tdqm .pop_right', [[1,2], 3])
|
233
|
+
foorth_equal('$tdqm ', [[1,2,3]])
|
234
|
+
foorth_raises('[ ] .pop_right')
|
235
|
+
|
236
|
+
foorth_equal('0 $tdqm .push_left', [[0,1,2,3]])
|
237
|
+
foorth_equal('$tdqm ', [[1,2,3]])
|
238
|
+
|
239
|
+
foorth_equal('4 $tdqm .push_right', [[1,2,3,4]])
|
240
|
+
foorth_equal('$tdqm ', [[1,2,3]])
|
241
|
+
|
242
|
+
foorth_equal('$tdqm .peek_left', [[1,2,3], 1])
|
243
|
+
foorth_equal('$tdqm ', [[1,2,3]])
|
244
|
+
foorth_raises('[ ] .peek_left')
|
245
|
+
|
246
|
+
foorth_equal('$tdqm .peek_right', [[1,2,3], 3])
|
247
|
+
foorth_equal('$tdqm ', [[1,2,3]])
|
248
|
+
foorth_raises('[ ] .peek_right')
|
249
|
+
|
250
|
+
|
251
|
+
#Test the mutating methods.
|
252
|
+
foorth_equal('$tdqm .pop_left!', [1])
|
253
|
+
foorth_equal('$tdqm ', [[2,3]])
|
254
|
+
foorth_raises('[ ] .pop_left!')
|
255
|
+
|
256
|
+
foorth_equal('$tdqm .pop_right!', [3])
|
257
|
+
foorth_equal('$tdqm ', [[2]])
|
258
|
+
foorth_raises('[ ] .pop_right!')
|
259
|
+
|
260
|
+
foorth_equal('1 $tdqm .push_left!', [])
|
261
|
+
foorth_equal('$tdqm ', [[1,2]])
|
262
|
+
|
263
|
+
foorth_equal('3 $tdqm .push_right!', [])
|
264
|
+
foorth_equal('$tdqm ', [[1,2,3]])
|
265
|
+
|
266
|
+
foorth_equal('$tdqm .peek_left!', [1])
|
267
|
+
foorth_equal('$tdqm ', [[1,2,3]])
|
268
|
+
foorth_raises('[ ] .peek_left!')
|
269
|
+
|
270
|
+
foorth_equal('$tdqm .peek_right!', [3])
|
271
|
+
foorth_equal('$tdqm ', [[1,2,3]])
|
272
|
+
foorth_raises('[ ] .peek_right!')
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_other_array_ops
|
276
|
+
foorth_equal('[ 0 1 2 ] .reverse ', [[2,1,0]])
|
277
|
+
foorth_equal('[ 9 3 5 ] .sort ', [[3,5,9]])
|
278
|
+
|
279
|
+
foorth_equal('[ 9 3 5 ] .length ', [3])
|
280
|
+
|
281
|
+
foorth_equal('[ 9 3 5 ] 0 << ', [[9,3,5,0]])
|
282
|
+
foorth_equal('[ 9 3 5 ] { } << ', [[9,3,5,{}]])
|
283
|
+
foorth_equal('[ 9 3 5 ] [ 4 1 ] << ', [[9,3,5,[4,1]]])
|
284
|
+
foorth_equal('[ 9 3 5 ] [ 4 1 ] << ', [[9,3,5,[4,1]]])
|
285
|
+
|
286
|
+
foorth_equal('[ 9 3 5 ] 0 + ', [[9,3,5,0]])
|
287
|
+
foorth_equal('[ 9 3 5 ] [ 0 ] + ', [[9,3,5,0]])
|
288
|
+
foorth_equal('[ 9 3 5 ] { } + ', [[9,3,5,{}]])
|
289
|
+
|
290
|
+
foorth_equal('[ "9" 3 5 ] .sort ', [[3,5,"9"]])
|
291
|
+
foorth_equal('[ 9 "3" 5 ] .sort ', [["3",5,9]])
|
292
|
+
|
293
|
+
foorth_equal('try [ 9 "apple" 5 ] .sort catch end', [])
|
294
|
+
end
|
295
|
+
|
296
|
+
def test_formatting_and_related
|
297
|
+
foorth_equal('[ 0 1 "hello" ] .strmax', [5])
|
298
|
+
end
|
299
|
+
|
300
|
+
def test_array_min_max
|
301
|
+
foorth_equal('[ 9 0 1 12 2 ] .min', [0])
|
302
|
+
foorth_equal('[ 9 0 1 12 2 ] .max', [12])
|
303
|
+
|
304
|
+
foorth_equal('[ "c" "d" "a" "g" "f" ] .min', ["a"])
|
305
|
+
foorth_equal('[ "c" "d" "a" "g" "f" ] .max', ["g"])
|
306
|
+
|
307
|
+
foorth_equal('[ "9" 0 1 "pear" ] .min', ["0"])
|
308
|
+
foorth_equal('[ "9" 0 1 "apple" ] .max', ["apple"])
|
309
|
+
|
310
|
+
foorth_raises('[ 9 0 1 "pear" ] .min')
|
311
|
+
foorth_raises('[ 9 0 1 "apple" ] .max')
|
312
|
+
|
313
|
+
foorth_equal('try [ 9 0 1 "pear" ] .min catch end', [])
|
314
|
+
foorth_equal('try [ 9 0 1 "pear" ] .max catch end', [])
|
315
|
+
end
|
316
|
+
|
317
|
+
def test_array_empty
|
318
|
+
foorth_equal('[ ] .empty?', [true])
|
319
|
+
foorth_equal('[ 1 2 3 ] .empty?', [false])
|
320
|
+
end
|
321
|
+
|
322
|
+
def test_array_split
|
323
|
+
foorth_equal('1 2 [ 3 4 ] .split', [1,2,3,4])
|
324
|
+
end
|
325
|
+
|
326
|
+
def test_array_join
|
327
|
+
foorth_equal('1 2 3 4 2 .join', [1,2,[3,4]])
|
328
|
+
foorth_raises('1 2 3 4 -2 .join')
|
329
|
+
foorth_raises('1 2 3 4 20 .join')
|
330
|
+
end
|
331
|
+
|
332
|
+
def test_scatter
|
333
|
+
foorth_equal('[ 1 2 3 ] .scatter', [1, 2, 3])
|
334
|
+
foorth_equal('5 6 [ 1 2 3 ] .scatter', [5, 6, 1, 2, 3])
|
335
|
+
end
|
336
|
+
|
337
|
+
def test_gather
|
338
|
+
foorth_equal(' gather', [[]])
|
339
|
+
foorth_equal(' 1 2 3 gather', [[1,2,3]])
|
340
|
+
|
341
|
+
foorth_equal(' 1 2 3 3 .gather', [[1,2,3]])
|
342
|
+
foorth_equal('5 6 1 2 3 3 .gather', [5,6,[1,2,3]])
|
343
|
+
|
344
|
+
foorth_raises('5 6 1 2 3 -1 .gather')
|
345
|
+
foorth_raises('5 6 1 2 3 0 .gather')
|
346
|
+
foorth_raises('5 6 1 2 3 9 .gather')
|
347
|
+
end
|
348
|
+
|
349
|
+
def test_array_to_s
|
350
|
+
foorth_equal('[ 1 2 3 ] .to_s', ["[ 1 2 3 ]"])
|
351
|
+
end
|
352
|
+
|
353
|
+
def test_compatibility_methods
|
354
|
+
foorth_equal('[ 2 4 6 8 ] .to_a ', [[2,4,6,8]])
|
355
|
+
foorth_equal('[ 2 4 6 8 ] .to_h ', [{0=>2, 1=>4, 2=>6, 3=>8}])
|
356
|
+
foorth_equal('[ 2 4 6 8 ] .values ', [[2,4,6,8]])
|
357
|
+
foorth_equal('[ 2 4 6 8 ] .keys ', [[0,1,2,3]])
|
358
|
+
end
|
359
|
+
|
360
|
+
end
|