fOOrth 0.5.3 → 0.6.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/.gitignore +1 -0
- data/README.md +9 -5
- data/integration/array_lib_tests.rb +2 -0
- data/integration/clone_lib_tests.rb +21 -11
- data/integration/standard_lib_tests.rb +5 -2
- data/integration/string_lib_tests.rb +304 -14
- data/integration/thread_lib_tests.rb +2 -2
- data/lib/fOOrth/compiler/process/string.rb +8 -1
- data/lib/fOOrth/compiler/source.rb +13 -2
- data/lib/fOOrth/compiler/source/console.rb +19 -3
- data/lib/fOOrth/core/class.rb +2 -2
- data/lib/fOOrth/library/array_library.rb +5 -1
- data/lib/fOOrth/library/class_library.rb +1 -1
- data/lib/fOOrth/library/command_library.rb +2 -2
- data/lib/fOOrth/library/duration_library.rb +1 -1
- data/lib/fOOrth/library/hash_library.rb +1 -1
- data/lib/fOOrth/library/in_stream_library.rb +3 -3
- data/lib/fOOrth/library/object_library.rb +11 -1
- data/lib/fOOrth/library/out_stream_library.rb +6 -6
- data/lib/fOOrth/library/procedure_library.rb +1 -1
- data/lib/fOOrth/library/stdio_library.rb +1 -1
- data/lib/fOOrth/library/string_library.rb +82 -33
- data/lib/fOOrth/library/thread_library.rb +1 -1
- data/lib/fOOrth/library/vm_library.rb +1 -1
- data/lib/fOOrth/monkey_patch/numeric.rb +1 -1
- data/lib/fOOrth/monkey_patch/object.rb +5 -0
- data/lib/fOOrth/monkey_patch/string.rb +58 -1
- data/lib/fOOrth/version.rb +1 -1
- data/tests/monkey_patch/string_test.rb +10 -2
- metadata +2 -2
@@ -6,7 +6,7 @@ module XfOOrth
|
|
6
6
|
#Get the VM as a string.
|
7
7
|
# [vm] .to_s ["vm as a string"]
|
8
8
|
VirtualMachine.create_shared_method('.to_s', TosSpec, [],
|
9
|
-
&lambda {|vm| vm.push(self.foorth_name)})
|
9
|
+
&lambda {|vm| vm.push(self.foorth_name.freeze)})
|
10
10
|
|
11
11
|
#Create a macro to get at the current virtual machine instance.
|
12
12
|
# [] vm [the_current_vm]
|
@@ -13,7 +13,7 @@ class String
|
|
13
13
|
#<br>Endemic Code Smells
|
14
14
|
#* :reek:FeatureEnvy -- false positive
|
15
15
|
def foorth_coerce(arg)
|
16
|
-
arg.to_s
|
16
|
+
arg.to_s.freeze
|
17
17
|
rescue
|
18
18
|
error "F40: Cannot coerce a #{arg.foorth_name} to an String instance"
|
19
19
|
end
|
@@ -48,4 +48,61 @@ class String
|
|
48
48
|
self.to_foorth_n.to_foorth_r
|
49
49
|
end
|
50
50
|
|
51
|
+
#A special patch for safe_clone
|
52
|
+
def safe_clone
|
53
|
+
self.freeze
|
54
|
+
end
|
55
|
+
|
56
|
+
#A special patch for full_clone
|
57
|
+
def full_clone(_arg=nil)
|
58
|
+
self.freeze
|
59
|
+
end
|
60
|
+
|
61
|
+
#Freeze only pure strings
|
62
|
+
def foorth_string_freeze
|
63
|
+
self.freeze
|
64
|
+
end
|
65
|
+
|
66
|
+
#Create an instance of a String.
|
67
|
+
#<br>Parameters:
|
68
|
+
#* vm - The current fOOrth virtual machine.
|
69
|
+
def self.create_foorth_instance(vm)
|
70
|
+
(obj = "".freeze).foorth_init(vm)
|
71
|
+
obj
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
#The \StringBuffer class is the mutable variant of the String class.
|
77
|
+
class StringBuffer < String
|
78
|
+
|
79
|
+
#Create a string buffer from an object. Make sure that object is a
|
80
|
+
#string and make sure that string is not frozen.
|
81
|
+
def initialize(text="")
|
82
|
+
super(text)
|
83
|
+
end
|
84
|
+
|
85
|
+
#A special patch for safe_clone
|
86
|
+
def safe_clone
|
87
|
+
self.clone
|
88
|
+
end
|
89
|
+
|
90
|
+
#A special patch for full_clone
|
91
|
+
def full_clone(_arg=nil)
|
92
|
+
self.clone
|
93
|
+
end
|
94
|
+
|
95
|
+
#Freeze only pure strings
|
96
|
+
def foorth_string_freeze
|
97
|
+
self
|
98
|
+
end
|
99
|
+
|
100
|
+
#Create an instance of StringBuffer.
|
101
|
+
#<br>Parameters:
|
102
|
+
#* vm - The current fOOrth virtual machine.
|
103
|
+
def self.create_foorth_instance(vm)
|
104
|
+
(obj = self.new).foorth_init(vm)
|
105
|
+
obj
|
106
|
+
end
|
107
|
+
|
51
108
|
end
|
data/lib/fOOrth/version.rb
CHANGED
@@ -46,8 +46,16 @@ class StringMonkeyPatchTester < Minitest::Test
|
|
46
46
|
def test_to_rational
|
47
47
|
assert_equal(Rational(1,2), '1/2'.to_foorth_r)
|
48
48
|
assert_equal(nil, 'apple'.to_foorth_r)
|
49
|
-
|
50
49
|
end
|
51
50
|
|
51
|
+
def test_clone_patches
|
52
|
+
s = "abc"
|
53
|
+
assert_equal(s.object_id, s.safe_clone.object_id)
|
54
|
+
assert_equal(s.object_id, s.full_clone.object_id)
|
55
|
+
|
56
|
+
b = StringBuffer.new('abc')
|
57
|
+
refute_equal(b.object_id, b.safe_clone.object_id)
|
58
|
+
refute_equal(b.object_id, b.full_clone.object_id)
|
59
|
+
end
|
52
60
|
|
53
|
-
end
|
61
|
+
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.
|
4
|
+
version: 0.6.0
|
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-
|
11
|
+
date: 2016-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|