fOOrth 0.6.6 → 0.6.11
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 +5 -5
- data/CODE_OF_CONDUCT.md +49 -0
- data/README.md +32 -1
- data/fOOrth.gemspec +3 -3
- data/integration/array_lib_tests.rb +10 -0
- data/integration/compile_lib_tests.rb +67 -1
- data/integration/exception_lib_tests.rb +4 -0
- data/integration/hash_lib_tests.rb +9 -0
- data/integration/numeric_lib_tests.rb +326 -321
- data/integration/procedure_lib_tests.rb +16 -0
- data/integration/queue_lib_tests.rb +2 -1
- data/integration/stack_lib_tests.rb +2 -1
- data/integration/stdio_lib_tests.rb +62 -0
- data/integration/string_lib_tests.rb +11 -0
- data/integration/thread_lib_tests.rb +19 -5
- data/lib/fOOrth.rb +0 -2
- data/lib/fOOrth/compiler/context.rb +64 -64
- data/lib/fOOrth/compiler/context/locals.rb +34 -34
- data/lib/fOOrth/compiler/context/map_name.rb +85 -74
- data/lib/fOOrth/compiler/context/tags.rb +60 -48
- data/lib/fOOrth/compiler/process/generate.rb +1 -1
- data/lib/fOOrth/compiler/process/procedure.rb +40 -0
- data/lib/fOOrth/compiler/word_specs.rb +3 -3
- data/lib/fOOrth/core/object.rb +1 -1
- data/lib/fOOrth/library.rb +3 -0
- data/lib/fOOrth/library/alias_library.rb +126 -0
- data/lib/fOOrth/library/array_library.rb +41 -21
- data/lib/fOOrth/library/command_library.rb +1 -1
- data/lib/fOOrth/library/compile_library.rb +266 -264
- data/lib/fOOrth/library/complex_library.rb +82 -80
- data/lib/fOOrth/library/float_library.rb +37 -0
- data/lib/fOOrth/library/formatting/array.rb +90 -0
- data/lib/fOOrth/library/formatting/bullets.rb +15 -79
- data/lib/fOOrth/library/formatting/columns.rb +20 -42
- data/lib/fOOrth/library/formatting/hash.rb +29 -0
- data/lib/fOOrth/library/formatting/nil.rb +13 -0
- data/lib/fOOrth/library/formatting/object.rb +18 -0
- data/lib/fOOrth/library/formatting/string.rb +46 -0
- data/lib/fOOrth/library/hash_library.rb +14 -6
- data/lib/fOOrth/library/introspection/class.rb +20 -18
- data/lib/fOOrth/library/introspection/context.rb +3 -2
- data/lib/fOOrth/library/introspection/object.rb +42 -20
- data/lib/fOOrth/library/introspection/string.rb +21 -5
- data/lib/fOOrth/library/introspection/vm.rb +17 -29
- data/lib/fOOrth/library/mutex_library.rb +8 -1
- data/lib/fOOrth/library/numeric_library.rb +359 -380
- data/lib/fOOrth/library/procedure_library.rb +69 -65
- data/lib/fOOrth/library/queue_library.rb +6 -1
- data/lib/fOOrth/library/rational_library.rb +89 -89
- data/lib/fOOrth/library/stack_library.rb +6 -1
- data/lib/fOOrth/library/stdio_library.rb +11 -8
- data/lib/fOOrth/library/string_library.rb +21 -6
- data/lib/fOOrth/library/stubs_library.rb +49 -0
- data/lib/fOOrth/monkey_patch/exceptions.rb +2 -6
- data/lib/fOOrth/monkey_patch/object.rb +7 -0
- data/lib/fOOrth/version.rb +1 -1
- data/reek.txt +1 -59
- data/sire.rb +0 -1
- data/tests/compiler/context_tests.rb +188 -177
- data/tests/compiler/file_source_tests.rb +130 -130
- data/tests/compiler/parser_tests.rb +4 -4
- data/tests/compiler/string_source_tests.rb +4 -4
- data/tests/core_tests.rb +138 -138
- data/tests/monkey_patch/complex_test.rb +24 -24
- data/tests/monkey_patch/object_test.rb +49 -49
- data/tests/monkey_patch/string_test.rb +61 -61
- metadata +20 -13
| @@ -1,380 +1,359 @@ | |
| 1 | 
            -
            # coding: utf-8
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            #* This meaningless entry exists to shut up rdoc!
         | 
| 4 | 
            -
            module Math #:nodoc: don't document this
         | 
| 5 | 
            -
            end
         | 
| 6 | 
            -
             | 
| 7 | 
            -
            #* library/numeric_library.rb - Numeric support for the fOOrth library.
         | 
| 8 | 
            -
            module XfOOrth
         | 
| 9 | 
            -
             | 
| 10 | 
            -
              #Connect the Numeric classes to the fOOrth class system.
         | 
| 11 | 
            -
              Numeric.create_foorth_proxy
         | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
              #  | 
| 15 | 
            -
               | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
              #  | 
| 20 | 
            -
               | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
              # [a]  | 
| 30 | 
            -
               | 
| 31 | 
            -
                begin
         | 
| 32 | 
            -
                  vm. | 
| 33 | 
            -
                rescue
         | 
| 34 | 
            -
                  vm. | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
               | 
| 40 | 
            -
             | 
| 41 | 
            -
                 | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
              #  | 
| 50 | 
            -
               | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
                   | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 60 | 
            -
               | 
| 61 | 
            -
             | 
| 62 | 
            -
             | 
| 63 | 
            -
             | 
| 64 | 
            -
             | 
| 65 | 
            -
                   | 
| 66 | 
            -
             | 
| 67 | 
            -
             | 
| 68 | 
            -
             | 
| 69 | 
            -
             | 
| 70 | 
            -
               | 
| 71 | 
            -
             | 
| 72 | 
            -
             | 
| 73 | 
            -
             | 
| 74 | 
            -
             | 
| 75 | 
            -
                   | 
| 76 | 
            -
             | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 80 | 
            -
              # [b,a]  | 
| 81 | 
            -
              Numeric.create_shared_method(' | 
| 82 | 
            -
                 | 
| 83 | 
            -
             | 
| 84 | 
            -
             | 
| 85 | 
            -
             | 
| 86 | 
            -
             | 
| 87 | 
            -
             | 
| 88 | 
            -
               | 
| 89 | 
            -
             | 
| 90 | 
            -
             | 
| 91 | 
            -
             | 
| 92 | 
            -
             | 
| 93 | 
            -
             | 
| 94 | 
            -
                 | 
| 95 | 
            -
             | 
| 96 | 
            -
             | 
| 97 | 
            -
             | 
| 98 | 
            -
             | 
| 99 | 
            -
             | 
| 100 | 
            -
              #  | 
| 101 | 
            -
               | 
| 102 | 
            -
             | 
| 103 | 
            -
             | 
| 104 | 
            -
             | 
| 105 | 
            -
               | 
| 106 | 
            -
             | 
| 107 | 
            -
             | 
| 108 | 
            -
             | 
| 109 | 
            -
              # [b,a]  | 
| 110 | 
            -
              Numeric.create_shared_method(' | 
| 111 | 
            -
                 | 
| 112 | 
            -
             | 
| 113 | 
            -
             | 
| 114 | 
            -
             | 
| 115 | 
            -
             | 
| 116 | 
            -
             | 
| 117 | 
            -
               | 
| 118 | 
            -
             | 
| 119 | 
            -
             | 
| 120 | 
            -
             | 
| 121 | 
            -
             | 
| 122 | 
            -
             | 
| 123 | 
            -
                 | 
| 124 | 
            -
             | 
| 125 | 
            -
             | 
| 126 | 
            -
             | 
| 127 | 
            -
             | 
| 128 | 
            -
             | 
| 129 | 
            -
              #  | 
| 130 | 
            -
               | 
| 131 | 
            -
             | 
| 132 | 
            -
             | 
| 133 | 
            -
             | 
| 134 | 
            -
             | 
| 135 | 
            -
                   | 
| 136 | 
            -
             | 
| 137 | 
            -
             | 
| 138 | 
            -
             | 
| 139 | 
            -
             | 
| 140 | 
            -
               | 
| 141 | 
            -
             | 
| 142 | 
            -
             | 
| 143 | 
            -
             | 
| 144 | 
            -
             | 
| 145 | 
            -
                   | 
| 146 | 
            -
             | 
| 147 | 
            -
             | 
| 148 | 
            -
             | 
| 149 | 
            -
             | 
| 150 | 
            -
               | 
| 151 | 
            -
             | 
| 152 | 
            -
             | 
| 153 | 
            -
             | 
| 154 | 
            -
             | 
| 155 | 
            -
                   | 
| 156 | 
            -
             | 
| 157 | 
            -
             | 
| 158 | 
            -
             | 
| 159 | 
            -
             | 
| 160 | 
            -
               | 
| 161 | 
            -
             | 
| 162 | 
            -
             | 
| 163 | 
            -
             | 
| 164 | 
            -
             | 
| 165 | 
            -
                   | 
| 166 | 
            -
             | 
| 167 | 
            -
             | 
| 168 | 
            -
             | 
| 169 | 
            -
             | 
| 170 | 
            -
               | 
| 171 | 
            -
             | 
| 172 | 
            -
             | 
| 173 | 
            -
             | 
| 174 | 
            -
             | 
| 175 | 
            -
             | 
| 176 | 
            -
             | 
| 177 | 
            -
             | 
| 178 | 
            -
               | 
| 179 | 
            -
             | 
| 180 | 
            -
             | 
| 181 | 
            -
               | 
| 182 | 
            -
             | 
| 183 | 
            -
             | 
| 184 | 
            -
             | 
| 185 | 
            -
             | 
| 186 | 
            -
             | 
| 187 | 
            -
                 | 
| 188 | 
            -
             | 
| 189 | 
            -
             | 
| 190 | 
            -
               | 
| 191 | 
            -
             | 
| 192 | 
            -
             | 
| 193 | 
            -
             | 
| 194 | 
            -
               | 
| 195 | 
            -
             | 
| 196 | 
            -
             | 
| 197 | 
            -
             | 
| 198 | 
            -
               | 
| 199 | 
            -
             | 
| 200 | 
            -
             | 
| 201 | 
            -
             | 
| 202 | 
            -
               | 
| 203 | 
            -
             | 
| 204 | 
            -
             | 
| 205 | 
            -
             | 
| 206 | 
            -
               | 
| 207 | 
            -
             | 
| 208 | 
            -
             | 
| 209 | 
            -
             | 
| 210 | 
            -
               | 
| 211 | 
            -
             | 
| 212 | 
            -
             | 
| 213 | 
            -
             | 
| 214 | 
            -
               | 
| 215 | 
            -
             | 
| 216 | 
            -
             | 
| 217 | 
            -
             | 
| 218 | 
            -
              #  | 
| 219 | 
            -
               | 
| 220 | 
            -
             | 
| 221 | 
            -
             | 
| 222 | 
            -
              # [ | 
| 223 | 
            -
               | 
| 224 | 
            -
             | 
| 225 | 
            -
             | 
| 226 | 
            -
               | 
| 227 | 
            -
             | 
| 228 | 
            -
             | 
| 229 | 
            -
             | 
| 230 | 
            -
             | 
| 231 | 
            -
             | 
| 232 | 
            -
             | 
| 233 | 
            -
             | 
| 234 | 
            -
             | 
| 235 | 
            -
             | 
| 236 | 
            -
             | 
| 237 | 
            -
             | 
| 238 | 
            -
             | 
| 239 | 
            -
             | 
| 240 | 
            -
              # []  | 
| 241 | 
            -
               | 
| 242 | 
            -
             | 
| 243 | 
            -
             | 
| 244 | 
            -
               | 
| 245 | 
            -
             | 
| 246 | 
            -
             | 
| 247 | 
            -
             | 
| 248 | 
            -
             | 
| 249 | 
            -
               | 
| 250 | 
            -
             | 
| 251 | 
            -
             | 
| 252 | 
            -
             | 
| 253 | 
            -
               | 
| 254 | 
            -
             | 
| 255 | 
            -
             | 
| 256 | 
            -
             | 
| 257 | 
            -
               | 
| 258 | 
            -
             | 
| 259 | 
            -
             | 
| 260 | 
            -
             | 
| 261 | 
            -
               | 
| 262 | 
            -
             | 
| 263 | 
            -
             | 
| 264 | 
            -
             | 
| 265 | 
            -
               | 
| 266 | 
            -
             | 
| 267 | 
            -
             | 
| 268 | 
            -
             | 
| 269 | 
            -
               | 
| 270 | 
            -
             | 
| 271 | 
            -
             | 
| 272 | 
            -
             | 
| 273 | 
            -
               | 
| 274 | 
            -
             | 
| 275 | 
            -
             | 
| 276 | 
            -
             | 
| 277 | 
            -
               | 
| 278 | 
            -
             | 
| 279 | 
            -
             | 
| 280 | 
            -
             | 
| 281 | 
            -
               | 
| 282 | 
            -
             | 
| 283 | 
            -
             | 
| 284 | 
            -
             | 
| 285 | 
            -
               | 
| 286 | 
            -
             | 
| 287 | 
            -
             | 
| 288 | 
            -
             | 
| 289 | 
            -
               | 
| 290 | 
            -
             | 
| 291 | 
            -
             | 
| 292 | 
            -
             | 
| 293 | 
            -
               | 
| 294 | 
            -
             | 
| 295 | 
            -
             | 
| 296 | 
            -
             | 
| 297 | 
            -
             | 
| 298 | 
            -
               | 
| 299 | 
            -
             | 
| 300 | 
            -
             | 
| 301 | 
            -
             | 
| 302 | 
            -
               | 
| 303 | 
            -
             | 
| 304 | 
            -
             | 
| 305 | 
            -
             | 
| 306 | 
            -
               | 
| 307 | 
            -
             | 
| 308 | 
            -
             | 
| 309 | 
            -
             | 
| 310 | 
            -
               | 
| 311 | 
            -
             | 
| 312 | 
            -
             | 
| 313 | 
            -
             | 
| 314 | 
            -
               | 
| 315 | 
            -
             | 
| 316 | 
            -
             | 
| 317 | 
            -
             | 
| 318 | 
            -
             | 
| 319 | 
            -
               | 
| 320 | 
            -
             | 
| 321 | 
            -
             | 
| 322 | 
            -
             | 
| 323 | 
            -
               | 
| 324 | 
            -
             | 
| 325 | 
            -
             | 
| 326 | 
            -
             | 
| 327 | 
            -
             | 
| 328 | 
            -
               | 
| 329 | 
            -
             | 
| 330 | 
            -
             | 
| 331 | 
            -
             | 
| 332 | 
            -
               | 
| 333 | 
            -
             | 
| 334 | 
            -
             | 
| 335 | 
            -
               | 
| 336 | 
            -
             | 
| 337 | 
            -
             | 
| 338 | 
            -
             | 
| 339 | 
            -
               | 
| 340 | 
            -
             | 
| 341 | 
            -
             | 
| 342 | 
            -
             | 
| 343 | 
            -
              # [ | 
| 344 | 
            -
              Numeric.create_shared_method('. | 
| 345 | 
            -
                 | 
| 346 | 
            -
               | 
| 347 | 
            -
                 | 
| 348 | 
            -
             | 
| 349 | 
            -
               | 
| 350 | 
            -
             | 
| 351 | 
            -
             | 
| 352 | 
            -
             | 
| 353 | 
            -
             | 
| 354 | 
            -
             | 
| 355 | 
            -
                 | 
| 356 | 
            -
             | 
| 357 | 
            -
             | 
| 358 | 
            -
             | 
| 359 | 
            -
             | 
| 360 | 
            -
              Numeric.create_shared_method('.hypot', TosSpec, [], &lambda {|vm|
         | 
| 361 | 
            -
                vm.poke(Math::hypot(Float.foorth_coerce(self), Float.foorth_coerce(vm.peek)));
         | 
| 362 | 
            -
              })
         | 
| 363 | 
            -
             | 
| 364 | 
            -
              # [r t] .p2c [x y]; Polar to Cartesian.
         | 
| 365 | 
            -
              Numeric.create_shared_method('.p2c', TosSpec, [], &lambda {|vm|
         | 
| 366 | 
            -
                radius = Float.foorth_coerce(vm.pop)
         | 
| 367 | 
            -
                theta  = Float.foorth_coerce(self)
         | 
| 368 | 
            -
                vm.push(radius * Math::cos(theta))
         | 
| 369 | 
            -
                vm.push(radius * Math::sin(theta))
         | 
| 370 | 
            -
              })
         | 
| 371 | 
            -
             | 
| 372 | 
            -
              # [x y] .c2p [r t]; Cartesian to Polar.
         | 
| 373 | 
            -
              Numeric.create_shared_method('.c2p', TosSpec, [], &lambda {|vm|
         | 
| 374 | 
            -
                real = Float.foorth_coerce(vm.pop)
         | 
| 375 | 
            -
                imag = Float.foorth_coerce(self)
         | 
| 376 | 
            -
                vm.push(Math::hypot(real,imag))
         | 
| 377 | 
            -
                vm.push(Math::atan2(imag,real))
         | 
| 378 | 
            -
              })
         | 
| 379 | 
            -
             | 
| 380 | 
            -
            end
         | 
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            #* This meaningless entry exists to shut up rdoc!
         | 
| 4 | 
            +
            module Math #:nodoc: don't document this
         | 
| 5 | 
            +
            end
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            #* library/numeric_library.rb - Numeric support for the fOOrth library.
         | 
| 8 | 
            +
            module XfOOrth
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              #Connect the Numeric classes to the fOOrth class system.
         | 
| 11 | 
            +
              Numeric.create_foorth_proxy
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              # Some conversion words.
         | 
| 14 | 
            +
              # [a] .to_n [Number or nil]
         | 
| 15 | 
            +
              Object.create_shared_method('.to_n', TosSpec, [],
         | 
| 16 | 
            +
                &lambda {|vm| vm.push(self.to_foorth_n); })
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              # Some conversion words.
         | 
| 19 | 
            +
              # [a] .to_n! [Number]
         | 
| 20 | 
            +
              Object.create_shared_method('.to_n!', TosSpec, [], &lambda {|vm|
         | 
| 21 | 
            +
                if (result = self.to_foorth_n)
         | 
| 22 | 
            +
                  vm.push(result);
         | 
| 23 | 
            +
                else
         | 
| 24 | 
            +
                  error "F40: Cannot convert a #{self.foorth_name} to a Numeric instance"
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
              })
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              # Some comparison words.
         | 
| 29 | 
            +
              # [b,a] > if b > a then [true] else [false]
         | 
| 30 | 
            +
              Numeric.create_shared_method('>', NosSpec, [], &lambda {|vm|
         | 
| 31 | 
            +
                begin
         | 
| 32 | 
            +
                  vm.poke(self > self.foorth_coerce(vm.peek))
         | 
| 33 | 
            +
                rescue
         | 
| 34 | 
            +
                  vm.data_stack.pop
         | 
| 35 | 
            +
                  raise
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
              })
         | 
| 38 | 
            +
             | 
| 39 | 
            +
              # [b,a] < if b < a then [true] else [false]
         | 
| 40 | 
            +
              Numeric.create_shared_method('<', NosSpec, [], &lambda {|vm|
         | 
| 41 | 
            +
                begin
         | 
| 42 | 
            +
                  vm.poke(self < self.foorth_coerce(vm.peek))
         | 
| 43 | 
            +
                rescue
         | 
| 44 | 
            +
                  vm.data_stack.pop
         | 
| 45 | 
            +
                  raise
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
              })
         | 
| 48 | 
            +
             | 
| 49 | 
            +
              # [b,a] >= if b >= a then [true] else [false]
         | 
| 50 | 
            +
              Numeric.create_shared_method('>=', NosSpec, [], &lambda {|vm|
         | 
| 51 | 
            +
                begin
         | 
| 52 | 
            +
                  vm.poke(self >= self.foorth_coerce(vm.peek))
         | 
| 53 | 
            +
                rescue
         | 
| 54 | 
            +
                  vm.data_stack.pop
         | 
| 55 | 
            +
                  raise
         | 
| 56 | 
            +
                end
         | 
| 57 | 
            +
              })
         | 
| 58 | 
            +
             | 
| 59 | 
            +
              # [b,a] <= if b <= a then [true] else [false]
         | 
| 60 | 
            +
              Numeric.create_shared_method('<=', NosSpec, [], &lambda {|vm|
         | 
| 61 | 
            +
                begin
         | 
| 62 | 
            +
                  vm.poke(self <= self.foorth_coerce(vm.peek))
         | 
| 63 | 
            +
                rescue
         | 
| 64 | 
            +
                  vm.data_stack.pop
         | 
| 65 | 
            +
                  raise
         | 
| 66 | 
            +
                end
         | 
| 67 | 
            +
              })
         | 
| 68 | 
            +
             | 
| 69 | 
            +
              # [b,a] <=> if b <=> a then [true] else [false]
         | 
| 70 | 
            +
              Numeric.create_shared_method('<=>', NosSpec, [], &lambda {|vm|
         | 
| 71 | 
            +
                begin
         | 
| 72 | 
            +
                  vm.poke(self <=> self.foorth_coerce(vm.peek))
         | 
| 73 | 
            +
                rescue
         | 
| 74 | 
            +
                  vm.data_stack.pop
         | 
| 75 | 
            +
                  raise
         | 
| 76 | 
            +
                end
         | 
| 77 | 
            +
              })
         | 
| 78 | 
            +
             | 
| 79 | 
            +
              # Some comparison with zero words.
         | 
| 80 | 
            +
              # [b,a] 0= if b == 0 then [true] else [false]
         | 
| 81 | 
            +
              Numeric.create_shared_method('0=', TosSpec, [],
         | 
| 82 | 
            +
                &lambda {|vm| vm.push(self.zero?); })
         | 
| 83 | 
            +
             | 
| 84 | 
            +
              # [b,a] 0<> if b != 0 then [true] else [false]
         | 
| 85 | 
            +
              Numeric.create_shared_method('0<>', TosSpec, [],
         | 
| 86 | 
            +
                &lambda {|vm| vm.push(!self.zero?); })
         | 
| 87 | 
            +
             | 
| 88 | 
            +
              # [b,a] 0> if b > 0 then [true] else [false]
         | 
| 89 | 
            +
              Numeric.create_shared_method('0>', TosSpec, [],
         | 
| 90 | 
            +
                &lambda {|vm| vm.push(self > 0); })
         | 
| 91 | 
            +
             | 
| 92 | 
            +
              # [b,a] 0< if b < 0 then [true] else [false]
         | 
| 93 | 
            +
              Numeric.create_shared_method('0<', TosSpec, [],
         | 
| 94 | 
            +
                &lambda {|vm| vm.push(self < 0); })
         | 
| 95 | 
            +
             | 
| 96 | 
            +
              # [b,a] 0>= if b >= 0 then [true] else [false]
         | 
| 97 | 
            +
              Numeric.create_shared_method('0>=', TosSpec, [],
         | 
| 98 | 
            +
                &lambda {|vm| vm.push(self >= 0); })
         | 
| 99 | 
            +
             | 
| 100 | 
            +
              # [b,a] 0<= if b <= 0 then [true] else [false]
         | 
| 101 | 
            +
              Numeric.create_shared_method('0<=', TosSpec, [],
         | 
| 102 | 
            +
                &lambda {|vm| vm.push(self <= 0); })
         | 
| 103 | 
            +
             | 
| 104 | 
            +
              # [b] 0<=> b < 0 [-1], b = 0 [0], b > 0 [1]
         | 
| 105 | 
            +
              Numeric.create_shared_method('0<=>', TosSpec, [],
         | 
| 106 | 
            +
                &lambda {|vm| vm.push(self <=> 0); })
         | 
| 107 | 
            +
             | 
| 108 | 
            +
              # Some stack arithmetic words.
         | 
| 109 | 
            +
              # [b,a] + [b+a]
         | 
| 110 | 
            +
              Numeric.create_shared_method('+', NosSpec, [], &lambda {|vm|
         | 
| 111 | 
            +
                begin
         | 
| 112 | 
            +
                  vm.poke(self + self.foorth_coerce(vm.peek))
         | 
| 113 | 
            +
                rescue
         | 
| 114 | 
            +
                  vm.data_stack.pop
         | 
| 115 | 
            +
                  raise
         | 
| 116 | 
            +
                end
         | 
| 117 | 
            +
              })
         | 
| 118 | 
            +
             | 
| 119 | 
            +
              # [b,a] - [b-a]
         | 
| 120 | 
            +
              Numeric.create_shared_method('-', NosSpec, [], &lambda {|vm|
         | 
| 121 | 
            +
                begin
         | 
| 122 | 
            +
                  vm.poke(self - self.foorth_coerce(vm.peek))
         | 
| 123 | 
            +
                rescue
         | 
| 124 | 
            +
                  vm.data_stack.pop
         | 
| 125 | 
            +
                  raise
         | 
| 126 | 
            +
                end
         | 
| 127 | 
            +
              })
         | 
| 128 | 
            +
             | 
| 129 | 
            +
              # [b,a] * [b*a]
         | 
| 130 | 
            +
              Numeric.create_shared_method('*', NosSpec, [], &lambda {|vm|
         | 
| 131 | 
            +
                begin
         | 
| 132 | 
            +
                  vm.poke(self * self.foorth_coerce(vm.peek))
         | 
| 133 | 
            +
                rescue
         | 
| 134 | 
            +
                  vm.data_stack.pop
         | 
| 135 | 
            +
                  raise
         | 
| 136 | 
            +
                end
         | 
| 137 | 
            +
              })
         | 
| 138 | 
            +
             | 
| 139 | 
            +
              # [b,a] ** [b**a]
         | 
| 140 | 
            +
              Numeric.create_shared_method('**', NosSpec, [], &lambda {|vm|
         | 
| 141 | 
            +
                begin
         | 
| 142 | 
            +
                  vm.poke(self ** Float.foorth_coerce(vm.peek))
         | 
| 143 | 
            +
                rescue
         | 
| 144 | 
            +
                  vm.data_stack.pop
         | 
| 145 | 
            +
                  raise
         | 
| 146 | 
            +
                end
         | 
| 147 | 
            +
              })
         | 
| 148 | 
            +
             | 
| 149 | 
            +
              # [b,a] / [b/a]
         | 
| 150 | 
            +
              Numeric.create_shared_method('/', NosSpec, [], &lambda {|vm|
         | 
| 151 | 
            +
                begin
         | 
| 152 | 
            +
                  vm.poke(self / self.foorth_coerce(vm.peek))
         | 
| 153 | 
            +
                rescue
         | 
| 154 | 
            +
                  vm.data_stack.pop
         | 
| 155 | 
            +
                  raise
         | 
| 156 | 
            +
                end
         | 
| 157 | 
            +
              })
         | 
| 158 | 
            +
             | 
| 159 | 
            +
              # [b,a] mod [b%a]
         | 
| 160 | 
            +
              Numeric.create_shared_method('mod', NosSpec, [], &lambda {|vm|
         | 
| 161 | 
            +
                begin
         | 
| 162 | 
            +
                  vm.poke(self % self.foorth_coerce(vm.peek))
         | 
| 163 | 
            +
                rescue
         | 
| 164 | 
            +
                  vm.data_stack.pop
         | 
| 165 | 
            +
                  raise
         | 
| 166 | 
            +
                end
         | 
| 167 | 
            +
              })
         | 
| 168 | 
            +
             | 
| 169 | 
            +
              # [a] neg [-a]
         | 
| 170 | 
            +
              Numeric.create_shared_method('neg', TosSpec, [],
         | 
| 171 | 
            +
                &lambda {|vm| vm.push(-self); })
         | 
| 172 | 
            +
             | 
| 173 | 
            +
              # [a] .1/x [-a]
         | 
| 174 | 
            +
              Numeric.create_shared_method('.1/x', TosSpec, [],
         | 
| 175 | 
            +
                &lambda {|vm| vm.push(1/self); })
         | 
| 176 | 
            +
             | 
| 177 | 
            +
              # [a] .abs [|a|]
         | 
| 178 | 
            +
              Numeric.create_shared_method('.abs', TosSpec, [],
         | 
| 179 | 
            +
                &lambda {|vm| vm.push(self.abs); })
         | 
| 180 | 
            +
             | 
| 181 | 
            +
              # [a] 1+ [a+1]
         | 
| 182 | 
            +
              Numeric.create_shared_method('1+', TosSpec, [],
         | 
| 183 | 
            +
                &lambda {|vm| vm.push(self+1); })
         | 
| 184 | 
            +
             | 
| 185 | 
            +
              # [a] 1- [a-1]
         | 
| 186 | 
            +
              Numeric.create_shared_method('1-', TosSpec, [],
         | 
| 187 | 
            +
                &lambda {|vm| vm.push(self-1); })
         | 
| 188 | 
            +
             | 
| 189 | 
            +
              # [a] 2+ [a+2]
         | 
| 190 | 
            +
              Numeric.create_shared_method('2+', TosSpec, [],
         | 
| 191 | 
            +
                &lambda {|vm| vm.push(self+2); })
         | 
| 192 | 
            +
             | 
| 193 | 
            +
              # [a] 2- [a-2]
         | 
| 194 | 
            +
              Numeric.create_shared_method('2-', TosSpec, [],
         | 
| 195 | 
            +
                &lambda {|vm| vm.push(self-2); })
         | 
| 196 | 
            +
             | 
| 197 | 
            +
              # [a] 2* [a*2]
         | 
| 198 | 
            +
              Numeric.create_shared_method('2*', TosSpec, [],
         | 
| 199 | 
            +
                &lambda {|vm| vm.push(self*2); })
         | 
| 200 | 
            +
             | 
| 201 | 
            +
              # [a] 2/ [a/2]
         | 
| 202 | 
            +
              Numeric.create_shared_method('2/', TosSpec, [],
         | 
| 203 | 
            +
                &lambda {|vm| vm.push(self/2); })
         | 
| 204 | 
            +
             | 
| 205 | 
            +
              # [a] .ceil [a']; where a' is the closest integer >= a
         | 
| 206 | 
            +
              Numeric.create_shared_method('.ceil', TosSpec, [],
         | 
| 207 | 
            +
                &lambda {|vm| vm.push(self.ceil); })
         | 
| 208 | 
            +
             | 
| 209 | 
            +
              # [a] .floor [a']; where a' is the closest integer <= a
         | 
| 210 | 
            +
              Numeric.create_shared_method('.floor', TosSpec, [],
         | 
| 211 | 
            +
                &lambda {|vm| vm.push(self.floor); })
         | 
| 212 | 
            +
             | 
| 213 | 
            +
              # [a] .round [a']; where a' is the integer closest to a
         | 
| 214 | 
            +
              Numeric.create_shared_method('.round', TosSpec, [],
         | 
| 215 | 
            +
                &lambda {|vm| vm.push(self.round); })
         | 
| 216 | 
            +
             | 
| 217 | 
            +
             | 
| 218 | 
            +
              #Advanced math stuff!
         | 
| 219 | 
            +
              # [] pi [3.141592653589793]
         | 
| 220 | 
            +
              VirtualMachine.create_shared_method('pi', MacroSpec, [:macro, "vm.push(Math::PI)"])
         | 
| 221 | 
            +
             | 
| 222 | 
            +
              # [] e [2.718281828459045]
         | 
| 223 | 
            +
              VirtualMachine.create_shared_method('e', MacroSpec, [:macro, "vm.push(Math::E)"])
         | 
| 224 | 
            +
             | 
| 225 | 
            +
              #The number of degrees in one radian.
         | 
| 226 | 
            +
              DegreesPerRadian = 180.0/Math::PI
         | 
| 227 | 
            +
             | 
| 228 | 
            +
              # [] dpr [2.718281828459045]
         | 
| 229 | 
            +
              VirtualMachine.create_shared_method('dpr', MacroSpec,
         | 
| 230 | 
            +
                [:macro, "vm.push(DegreesPerRadian)"])
         | 
| 231 | 
            +
             | 
| 232 | 
            +
              # [degrees] .d2r [radians]
         | 
| 233 | 
            +
              Numeric.create_shared_method('.d2r', TosSpec, [],
         | 
| 234 | 
            +
                &lambda {|vm| vm.push(Float.foorth_coerce(self)/DegreesPerRadian); })
         | 
| 235 | 
            +
             | 
| 236 | 
            +
              # [radians] .r2d [degrees]
         | 
| 237 | 
            +
              Numeric.create_shared_method('.r2d', TosSpec, [],
         | 
| 238 | 
            +
                &lambda {|vm| vm.push(Float.foorth_coerce(self)*DegreesPerRadian); })
         | 
| 239 | 
            +
             | 
| 240 | 
            +
              # [radians] .cos [cos(radians)]
         | 
| 241 | 
            +
              Numeric.create_shared_method('.cos', TosSpec, [],
         | 
| 242 | 
            +
                &lambda {|vm| vm.push(Math::cos(Float.foorth_coerce(self))); })
         | 
| 243 | 
            +
             | 
| 244 | 
            +
              # [radians] .sin [sin(radians)]
         | 
| 245 | 
            +
              Numeric.create_shared_method('.sin', TosSpec, [],
         | 
| 246 | 
            +
                &lambda {|vm| vm.push(Math::sin(Float.foorth_coerce(self))); })
         | 
| 247 | 
            +
             | 
| 248 | 
            +
              # [radians] .tan [tan(radians)]
         | 
| 249 | 
            +
              Numeric.create_shared_method('.tan', TosSpec, [],
         | 
| 250 | 
            +
                &lambda {|vm| vm.push(Math::tan(Float.foorth_coerce(self))); })
         | 
| 251 | 
            +
             | 
| 252 | 
            +
              # [cos(radians)] .acos [radians]
         | 
| 253 | 
            +
              Numeric.create_shared_method('.acos', TosSpec, [],
         | 
| 254 | 
            +
                &lambda {|vm| vm.push(Math::acos(Float.foorth_coerce(self))); })
         | 
| 255 | 
            +
             | 
| 256 | 
            +
              # [sin(radians)] .asin [radians]
         | 
| 257 | 
            +
              Numeric.create_shared_method('.asin', TosSpec, [],
         | 
| 258 | 
            +
                &lambda {|vm| vm.push(Math::asin(Float.foorth_coerce(self))); })
         | 
| 259 | 
            +
             | 
| 260 | 
            +
              # [y/x] .atan [radians]
         | 
| 261 | 
            +
              Numeric.create_shared_method('.atan', TosSpec, [],
         | 
| 262 | 
            +
                &lambda {|vm| vm.push(Math::atan(Float.foorth_coerce(self))); })
         | 
| 263 | 
            +
             | 
| 264 | 
            +
              # [y x] .atan2 [radians]
         | 
| 265 | 
            +
              Numeric.create_shared_method('.atan2', TosSpec, [],
         | 
| 266 | 
            +
                &lambda {|vm| vm.poke(Math::atan2(Float.foorth_coerce(vm.peek), Float.foorth_coerce(self))); })
         | 
| 267 | 
            +
             | 
| 268 | 
            +
              # [radians] .cosh [cosh(radians)]
         | 
| 269 | 
            +
              Numeric.create_shared_method('.cosh', TosSpec, [],
         | 
| 270 | 
            +
                &lambda {|vm| vm.push(Math::cosh(Float.foorth_coerce(self))); })
         | 
| 271 | 
            +
             | 
| 272 | 
            +
              # [radians] .sinh [sinh(radians)]
         | 
| 273 | 
            +
              Numeric.create_shared_method('.sinh', TosSpec, [],
         | 
| 274 | 
            +
                &lambda {|vm| vm.push(Math::sinh(Float.foorth_coerce(self))); })
         | 
| 275 | 
            +
             | 
| 276 | 
            +
              # [radians] .tanh [tanh(radians)]
         | 
| 277 | 
            +
              Numeric.create_shared_method('.tanh', TosSpec, [],
         | 
| 278 | 
            +
                &lambda {|vm| vm.push(Math::tanh(Float.foorth_coerce(self))); })
         | 
| 279 | 
            +
             | 
| 280 | 
            +
              # [cosh(radians)] .acosh [radians]
         | 
| 281 | 
            +
              Numeric.create_shared_method('.acosh', TosSpec, [],
         | 
| 282 | 
            +
                &lambda {|vm| vm.push(Math::acosh(Float.foorth_coerce(self))); })
         | 
| 283 | 
            +
             | 
| 284 | 
            +
              # [sinh(radians)] .asinh [radians]
         | 
| 285 | 
            +
              Numeric.create_shared_method('.asinh', TosSpec, [],
         | 
| 286 | 
            +
                &lambda {|vm| vm.push(Math::asinh(Float.foorth_coerce(self))); })
         | 
| 287 | 
            +
             | 
| 288 | 
            +
              # [y/x] .atanh [radians]
         | 
| 289 | 
            +
              Numeric.create_shared_method('.atanh', TosSpec, [],
         | 
| 290 | 
            +
                &lambda {|vm| vm.push(Math::atanh(Float.foorth_coerce(self))); })
         | 
| 291 | 
            +
             | 
| 292 | 
            +
              # [x] .e** [e**x]
         | 
| 293 | 
            +
              Numeric.create_shared_method('.e**', TosSpec, [],
         | 
| 294 | 
            +
                &lambda {|vm| vm.push(Math::exp(self)); })
         | 
| 295 | 
            +
              Complex.create_shared_method('.e**', TosSpec, [],
         | 
| 296 | 
            +
                &lambda {|vm| vm.push(Math::E ** self); })
         | 
| 297 | 
            +
             | 
| 298 | 
            +
              # [x] .ln [ln(x)]
         | 
| 299 | 
            +
              Numeric.create_shared_method('.ln', TosSpec, [],
         | 
| 300 | 
            +
                &lambda {|vm| vm.push(Math::log(Float.foorth_coerce(self))); })
         | 
| 301 | 
            +
             | 
| 302 | 
            +
              # [x] .10** [10**x]
         | 
| 303 | 
            +
              Numeric.create_shared_method('.10**', TosSpec, [],
         | 
| 304 | 
            +
                &lambda {|vm| vm.push(10.0**self); })
         | 
| 305 | 
            +
             | 
| 306 | 
            +
              # [x] .log10 [log10(x)]
         | 
| 307 | 
            +
              Numeric.create_shared_method('.log10', TosSpec, [],
         | 
| 308 | 
            +
                &lambda {|vm| vm.push(Math::log10(Float.foorth_coerce(self))); })
         | 
| 309 | 
            +
             | 
| 310 | 
            +
              # [x] .2** [2**x]
         | 
| 311 | 
            +
              Numeric.create_shared_method('.2**', TosSpec, [],
         | 
| 312 | 
            +
                &lambda {|vm| vm.push(2.0**self); })
         | 
| 313 | 
            +
             | 
| 314 | 
            +
              # [x] .log2 [log2(x)]
         | 
| 315 | 
            +
              Numeric.create_shared_method('.log2', TosSpec, [],
         | 
| 316 | 
            +
                &lambda {|vm| vm.push(Math::log2(Float.foorth_coerce(self))); })
         | 
| 317 | 
            +
             | 
| 318 | 
            +
              # [x] .sqr [square(x)]
         | 
| 319 | 
            +
              Numeric.create_shared_method('.sqr', TosSpec, [],
         | 
| 320 | 
            +
                &lambda {|vm| vm.push(self*self); })
         | 
| 321 | 
            +
             | 
| 322 | 
            +
              # [x] .sqrt [square root(x)]
         | 
| 323 | 
            +
              Numeric.create_shared_method('.sqrt', TosSpec, [],
         | 
| 324 | 
            +
                &lambda {|vm| vm.push(Math::sqrt(self)); })
         | 
| 325 | 
            +
              Complex.create_shared_method('.sqrt', TosSpec, [],
         | 
| 326 | 
            +
                &lambda {|vm| vm.push(self ** 0.5); })
         | 
| 327 | 
            +
             | 
| 328 | 
            +
              # [x] .cube [cube(x)]
         | 
| 329 | 
            +
              Numeric.create_shared_method('.cube', TosSpec, [],
         | 
| 330 | 
            +
                &lambda {|vm| vm.push(self*self*self); })
         | 
| 331 | 
            +
             | 
| 332 | 
            +
              # [x] .cbrt [cube root(x)]
         | 
| 333 | 
            +
              Numeric.create_shared_method('.cbrt', TosSpec, [],
         | 
| 334 | 
            +
                &lambda {|vm| vm.push(Math::cbrt(self)); })
         | 
| 335 | 
            +
              Complex.create_shared_method('.cbrt', TosSpec, [],
         | 
| 336 | 
            +
                &lambda {|vm| vm.push(self ** Rational(1,3)); })
         | 
| 337 | 
            +
             | 
| 338 | 
            +
              # [x y] .hypot [sqrt(x**2 + y**2)]
         | 
| 339 | 
            +
              Numeric.create_shared_method('.hypot', TosSpec, [], &lambda {|vm|
         | 
| 340 | 
            +
                vm.poke(Math::hypot(Float.foorth_coerce(self), Float.foorth_coerce(vm.peek)));
         | 
| 341 | 
            +
              })
         | 
| 342 | 
            +
             | 
| 343 | 
            +
              # [r t] .p2c [x y]; Polar to Cartesian.
         | 
| 344 | 
            +
              Numeric.create_shared_method('.p2c', TosSpec, [], &lambda {|vm|
         | 
| 345 | 
            +
                radius = Float.foorth_coerce(vm.pop)
         | 
| 346 | 
            +
                theta  = Float.foorth_coerce(self)
         | 
| 347 | 
            +
                vm.push(radius * Math::cos(theta))
         | 
| 348 | 
            +
                vm.push(radius * Math::sin(theta))
         | 
| 349 | 
            +
              })
         | 
| 350 | 
            +
             | 
| 351 | 
            +
              # [x y] .c2p [r t]; Cartesian to Polar.
         | 
| 352 | 
            +
              Numeric.create_shared_method('.c2p', TosSpec, [], &lambda {|vm|
         | 
| 353 | 
            +
                real = Float.foorth_coerce(vm.pop)
         | 
| 354 | 
            +
                imag = Float.foorth_coerce(self)
         | 
| 355 | 
            +
                vm.push(Math::hypot(real,imag))
         | 
| 356 | 
            +
                vm.push(Math::atan2(imag,real))
         | 
| 357 | 
            +
              })
         | 
| 358 | 
            +
             | 
| 359 | 
            +
            end
         |