spitewaste 0.1.011 → 0.1.012
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/Rakefile +2 -2
- data/lib/spitewaste/libspw/docs.json +2566 -2473
- data/lib/spitewaste/libspw/rational.spw +25 -0
- data/lib/spitewaste/libspw/string.spw +19 -6
- data/lib/spitewaste/libspw/util.spw +2 -0
- data/lib/spitewaste/parsers/spitewaste.rb +9 -3
- data/lib/spitewaste/version.rb +1 -1
- metadata +2 -2
|
@@ -174,3 +174,28 @@ ratpow:
|
|
|
174
174
|
swap $RAT :divmod copy 2 mul
|
|
175
175
|
copy 3 :pow swap copy 3 :pow
|
|
176
176
|
swap :to_r :ratsimp slide 2 ret
|
|
177
|
+
|
|
178
|
+
; converts the rational number R to a "pseudo-float" with a whole (W) part
|
|
179
|
+
; and a fractional (F) part composed of P digits after the decimal point
|
|
180
|
+
; [R P] => [W F]
|
|
181
|
+
;
|
|
182
|
+
; [R(22,7) 2] => [3 14]
|
|
183
|
+
; [R(355,113) 6] => [3 141592]
|
|
184
|
+
; [R(8675,309) 10] => [28 744336569] TODO: leading 0 is lost (bug)
|
|
185
|
+
; [R(2,4) 3] => [0 500]
|
|
186
|
+
to_f: push -2 swap store :from_r :divmod push 0 swap
|
|
187
|
+
_to_f_loop:
|
|
188
|
+
push -1 load :divmod swap
|
|
189
|
+
copy 2 push 10 mul add
|
|
190
|
+
swap push 10 mul
|
|
191
|
+
push 2 :dig
|
|
192
|
+
push -2 dup :dec load :neg? jz _to_f_loop pop ret
|
|
193
|
+
|
|
194
|
+
; converts the rational number R to a string S of the form
|
|
195
|
+
; "<simplified numerator>/<simplified denominator>"
|
|
196
|
+
; [R] => [S]
|
|
197
|
+
;
|
|
198
|
+
; [R(22,7)] => ["22/7"]
|
|
199
|
+
; [R(2,4)] => ["1/2"]
|
|
200
|
+
; [R(99,9)] => ["11/1"]
|
|
201
|
+
ratstr: :ratsimp :from_r push 2 map (:to_s) push '/' :strjoinc ret
|
|
@@ -207,8 +207,10 @@ center: push ' ' :centerc ret
|
|
|
207
207
|
; ["foobar"] => ["fooba"]
|
|
208
208
|
; ["abc"] => ["ab"]
|
|
209
209
|
; ["a"] => [""]
|
|
210
|
-
;
|
|
211
|
-
strchop: dup
|
|
210
|
+
; [""] => [""]
|
|
211
|
+
strchop: dup jz _strchop_empty
|
|
212
|
+
dup :strlen push 1 sub push 0 swap :strslice ret
|
|
213
|
+
_strchop_empty: ret
|
|
212
214
|
|
|
213
215
|
; splits string S on delimiting character C, leaving the resultant substrings
|
|
214
216
|
; on the stack as a pseudo-array (length at top of stack)
|
|
@@ -368,11 +370,13 @@ _strdel_comp: $_strdel(:pos?)
|
|
|
368
370
|
; ["ABC"] => [198]
|
|
369
371
|
; ["012"] => [147]
|
|
370
372
|
; ["a"] => [97]
|
|
371
|
-
; [""] => []
|
|
372
|
-
strsum:
|
|
373
|
+
; [""] => [0]
|
|
374
|
+
strsum: dup jz _strsum_empty
|
|
375
|
+
:strunpack push 0 :to_a reduce (add) ret
|
|
376
|
+
_strsum_empty: ret
|
|
373
377
|
|
|
374
378
|
; rotates the string S to the left N times, wrapping
|
|
375
|
-
; [S N]
|
|
379
|
+
; [S N] => [S']
|
|
376
380
|
;
|
|
377
381
|
; ["abc" 0] => ["abc"]
|
|
378
382
|
; ["abcd" 1] => ["bcda"]
|
|
@@ -381,9 +385,18 @@ strsum: :strunpack push 0 :to_a reduce (add) ret
|
|
|
381
385
|
strrotl: push 128 swap copy 2 :strlen mod :pow :divmod :strcat ret
|
|
382
386
|
|
|
383
387
|
; rotates the string S to the right N times, wrapping
|
|
384
|
-
; [S N]
|
|
388
|
+
; [S N] => [S']
|
|
385
389
|
;
|
|
386
390
|
; ["abcd" 1] => ["dabc"]
|
|
387
391
|
; ["abcd" 5] => ["dabc"]
|
|
388
392
|
; ["foodbar" 3] => ["barfood"]
|
|
389
393
|
strrotr: push 0 swap sub :strrotl ret
|
|
394
|
+
|
|
395
|
+
; frobnicates the string S by XORing all its bytes with 42
|
|
396
|
+
; [S] => [S']
|
|
397
|
+
;
|
|
398
|
+
; ["foobar"] => ["LEEHKX"]
|
|
399
|
+
; ["LEEHKX"] => ["foobar"]
|
|
400
|
+
memfrob:
|
|
401
|
+
dup :strlen pop :strunpack push -1 load $++
|
|
402
|
+
map (push 42 :bxor) pop :strpack ret
|
|
@@ -87,6 +87,7 @@ _stoi_invalid: pop pop slide 1 swap div push -2 load mul ret
|
|
|
87
87
|
_stoi_done: swap slide 2 push -2 load mul ret
|
|
88
88
|
|
|
89
89
|
; creature comforts
|
|
90
|
+
|
|
90
91
|
bin: push 2 :stoi ret
|
|
91
92
|
oct: push 8 :stoi ret
|
|
92
93
|
to_i: push 10 :stoi ret
|
|
@@ -113,6 +114,7 @@ _itos_loop:
|
|
|
113
114
|
_itos_done: swap slide 2 push 45,-2 load mul swap :strcat ret
|
|
114
115
|
|
|
115
116
|
; creature comforts
|
|
117
|
+
|
|
116
118
|
to_bin: push 2 :itos ret
|
|
117
119
|
to_oct: push 8 :itos ret
|
|
118
120
|
to_s: push 10 :itos ret
|
|
@@ -57,7 +57,7 @@ module Spitewaste
|
|
|
57
57
|
private
|
|
58
58
|
|
|
59
59
|
def preprocess!
|
|
60
|
-
@src
|
|
60
|
+
@src << "\nimport syntax"
|
|
61
61
|
resolve_imports
|
|
62
62
|
seed_prng if @seen.include? 'random'
|
|
63
63
|
resolve_strings
|
|
@@ -78,7 +78,13 @@ module Spitewaste
|
|
|
78
78
|
while @src['import']
|
|
79
79
|
imports = []
|
|
80
80
|
@src.gsub!(/import\s+(\S+).*/) {
|
|
81
|
-
|
|
81
|
+
if $1 == ?*
|
|
82
|
+
imports = Dir[LIBSPW + '/*.spw'].map {
|
|
83
|
+
File.read(_1) if @seen.add? File.basename(_1, '.spw')
|
|
84
|
+
}
|
|
85
|
+
else
|
|
86
|
+
imports << resolve($1) if @seen.add? $1
|
|
87
|
+
end
|
|
82
88
|
'' # remove import statement
|
|
83
89
|
}
|
|
84
90
|
@src << imports.join(?\n)
|
|
@@ -91,7 +97,7 @@ module Spitewaste
|
|
|
91
97
|
end
|
|
92
98
|
|
|
93
99
|
def seed_prng
|
|
94
|
-
@src.prepend "push $seed,#{rand 2**31} store $seed = -9001"
|
|
100
|
+
@src.prepend "push $seed,#{rand 2**31} store $seed = -9001\n"
|
|
95
101
|
end
|
|
96
102
|
|
|
97
103
|
def resolve_strings
|
data/lib/spitewaste/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: spitewaste
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.012
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Collided Scope (collidedscope)
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-01-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|