fOOrth 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/integration/clone_lib_tests.rb +3 -2
- data/integration/object_lib_tests.rb +28 -0
- data/integration/string_lib_tests.rb +19 -0
- data/lib/fOOrth/library/object_library.rb +34 -0
- data/lib/fOOrth/library/string_library.rb +0 -5
- data/lib/fOOrth/monkey_patch/exceptions.rb +14 -0
- data/lib/fOOrth/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30474940c4c3e0647c0c1205d6165d3c3d11ee3a
|
4
|
+
data.tar.gz: 8e65265692a9ed674814aa78c9fd2892da3456a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e53b8c014e66a4f7f0401292c00e4e361a0a0667ade42bc26be9db1a93976f8686ca0c874fabca16efad207a6c89c45994bf4be17ea712861ecdf64c84cf2446
|
7
|
+
data.tar.gz: 79cfd83122d97e5b83a357d6b7df7c8083a163c7467131d963396f13a300aae0c7a7e003dd51ec62776aa3adc33e8607bd711bf623808564fb5498baabb54758
|
@@ -49,14 +49,15 @@ class CloneLibraryTester < Minitest::Test
|
|
49
49
|
foorth_run('$tscx1 .clone val$: $tscx2')
|
50
50
|
|
51
51
|
foorth_equal('$tscx1 .clone_exclude', [["@b"]])
|
52
|
+
foorth_equal('$tscx2 .clone_exclude', [["@b"]])
|
52
53
|
|
53
54
|
foorth_equal('$tscx1 .a', ["a"])
|
54
55
|
foorth_equal('$tscx1 .b', ["b"])
|
55
56
|
foorth_equal('$tscx2 .a', ["a"])
|
56
57
|
foorth_equal('$tscx2 .b', ["b"])
|
57
58
|
|
58
|
-
|
59
|
-
|
59
|
+
foorth_equal('$tscx1 .a "1" << ', ["a1"])
|
60
|
+
foorth_equal('$tscx1 .b "1" << ', ["b1"])
|
60
61
|
|
61
62
|
foorth_equal('$tscx1 .a', ["a1"])
|
62
63
|
foorth_equal('$tscx1 .b', ["b1"])
|
@@ -35,4 +35,32 @@ class ObjectLibraryTester < Minitest::Test
|
|
35
35
|
foorth_equal("4 .strlen", [1])
|
36
36
|
end
|
37
37
|
|
38
|
+
def test_for_mutable_and_protect
|
39
|
+
foorth_equal('"abc" .mutable?', [false])
|
40
|
+
foorth_equal('"abc" dup .protect .mutable?', [false])
|
41
|
+
foorth_equal('"abc" protect .mutable?', [false])
|
42
|
+
|
43
|
+
foorth_equal('"abc"* .mutable?', [true])
|
44
|
+
foorth_equal('"abc"* dup .protect .mutable?', [false])
|
45
|
+
foorth_equal('"abc"* protect .mutable?', [false])
|
46
|
+
foorth_raises('"abc"* dup .protect "a" <<', RuntimeError)
|
47
|
+
foorth_raises('"abc"* protect "a" <<', RuntimeError)
|
48
|
+
|
49
|
+
foorth_equal('42 .mutable?', [false])
|
50
|
+
foorth_equal('42.5 .mutable?', [false])
|
51
|
+
foorth_equal('42/5 .mutable?', [false])
|
52
|
+
foorth_equal('42+5i .mutable?', [false])
|
53
|
+
|
54
|
+
foorth_equal('[ "abc" ] .mutable?', [true])
|
55
|
+
foorth_equal('[ "abc" ] dup .protect .mutable?', [false])
|
56
|
+
foorth_equal('[ "abc" ] protect .mutable?', [false])
|
57
|
+
|
58
|
+
foorth_equal('true .mutable?', [false])
|
59
|
+
foorth_equal('false .mutable?', [false])
|
60
|
+
foorth_equal('nil .mutable?', [false])
|
61
|
+
|
62
|
+
foorth_equal('Object .new dup .protect .mutable?', [false])
|
63
|
+
foorth_equal('Object .new protect .mutable?', [false])
|
64
|
+
end
|
65
|
+
|
38
66
|
end
|
@@ -72,6 +72,25 @@ class StringLibraryTester < Minitest::Test
|
|
72
72
|
foorth_equal('"A"* "B" >>', ["BA"])
|
73
73
|
end
|
74
74
|
|
75
|
+
def test_some_additionelle_stuff
|
76
|
+
foorth_equal('"A"* .to_s .class ', [String])
|
77
|
+
|
78
|
+
foorth_equal('"A"* .to_s .mutable? ', [false])
|
79
|
+
|
80
|
+
foorth_equal('"A"* protect .class ', [StringBuffer])
|
81
|
+
foorth_equal('"A"* dup .protect .class ', [StringBuffer])
|
82
|
+
|
83
|
+
foorth_equal('"A"* protect .mutable? ', [false])
|
84
|
+
foorth_equal('"A"* dup .protect .mutable? ', [false])
|
85
|
+
|
86
|
+
foorth_equal('"A"* .to_s* .class ', [StringBuffer])
|
87
|
+
foorth_equal('"A"* .to_s* .mutable? ', [true])
|
88
|
+
foorth_equal('"A"* dup .to_s* distinct? ', [true])
|
89
|
+
|
90
|
+
foorth_equal('"A"* protect .to_s* .class ', [StringBuffer])
|
91
|
+
foorth_equal('"A"* protect .to_s* .mutable? ', [true])
|
92
|
+
end
|
93
|
+
|
75
94
|
def test_file_loading
|
76
95
|
foorth_equal('"integration/load_test_one.foorth" .load ', [42])
|
77
96
|
foorth_equal('4 double ', [8])
|
@@ -87,4 +87,38 @@ module XfOOrth
|
|
87
87
|
end
|
88
88
|
})
|
89
89
|
|
90
|
+
#Is this object mutable?
|
91
|
+
# [a] .mutable? [flag]
|
92
|
+
Object.create_shared_method('.mutable?', TosSpec, [],
|
93
|
+
&lambda {|vm| vm.push(!self.frozen?); })
|
94
|
+
|
95
|
+
#Is this number mutable? No!
|
96
|
+
# [a] .mutable? [false]
|
97
|
+
Numeric.create_shared_method('.mutable?', TosSpec, [],
|
98
|
+
&lambda {|vm| vm.push(false); })
|
99
|
+
|
100
|
+
#Is this boolean mutable? No!
|
101
|
+
# [a] .mutable? [false]
|
102
|
+
TrueClass.create_shared_method('.mutable?', TosSpec, [],
|
103
|
+
&lambda {|vm| vm.push(false); })
|
104
|
+
|
105
|
+
#Is this boolean mutable? No!
|
106
|
+
# [a] .mutable? [false]
|
107
|
+
FalseClass.create_shared_method('.mutable?', TosSpec, [],
|
108
|
+
&lambda {|vm| vm.push(false); })
|
109
|
+
|
110
|
+
#Is nil mutable? No!
|
111
|
+
# [a] .mutable? [false]
|
112
|
+
NilClass.create_shared_method('.mutable?', TosSpec, [],
|
113
|
+
&lambda {|vm| vm.push(false); })
|
114
|
+
|
115
|
+
#Protect this object from change!
|
116
|
+
# [a] .protect [] The object is protected against change.
|
117
|
+
Object.create_shared_method('.protect', TosSpec, [],
|
118
|
+
&lambda{|vm| self.freeze })
|
119
|
+
|
120
|
+
#Protect this object from change!
|
121
|
+
# [a] protect [a] The object is protected against change.
|
122
|
+
VirtualMachine.create_shared_method('protect', VmSpec, [],
|
123
|
+
&lambda{|vm| vm.poke(vm.peek.freeze) })
|
90
124
|
end
|
@@ -12,11 +12,6 @@ module XfOOrth
|
|
12
12
|
# A no operation place holder for string literals
|
13
13
|
VirtualMachine.create_shared_method('"', MacroSpec, [:macro, " "])
|
14
14
|
|
15
|
-
#Is this mutable? StringBuffers are, Strings are not.
|
16
|
-
# [a] .mutable? [flag]
|
17
|
-
String.create_shared_method('.mutable?', TosSpec, [],
|
18
|
-
&lambda {|vm| vm.push(!self.frozen?); })
|
19
|
-
|
20
15
|
# [string] .each{{ ... }} [unspecified]
|
21
16
|
String.create_shared_method('.each{{', NosSpec, [], &lambda { |vm|
|
22
17
|
block, idx = vm.pop, 0
|
@@ -105,6 +105,20 @@ class SystemCallError
|
|
105
105
|
|
106
106
|
end
|
107
107
|
|
108
|
+
#Extensions to the RunTimeError to support fOOrth
|
109
|
+
class RuntimeError
|
110
|
+
|
111
|
+
#Massage the messages a bit
|
112
|
+
def message
|
113
|
+
msg = super
|
114
|
+
|
115
|
+
msg["frozen"] && msg["frozen"] = "protected"
|
116
|
+
|
117
|
+
msg
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
108
122
|
# Extensions to Interrupt to support fOOrth.
|
109
123
|
class Interrupt
|
110
124
|
|
data/lib/fOOrth/version.rb
CHANGED
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.
|
4
|
+
version: 0.6.1
|
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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|