spitewaste 0.1.009 → 0.2.01
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +7 -6
- data/lib/spitewaste/assembler.rb +1 -1
- data/lib/spitewaste/libspw/array.spw +114 -14
- data/lib/spitewaste/libspw/bits.spw +9 -5
- data/lib/spitewaste/libspw/docs.json +6003 -1
- data/lib/spitewaste/libspw/fun.spw +42 -4
- data/lib/spitewaste/libspw/math.spw +7 -11
- data/lib/spitewaste/libspw/random.spw +28 -6
- data/lib/spitewaste/libspw/rational.spw +30 -1
- data/lib/spitewaste/libspw/stack.spw +11 -13
- data/lib/spitewaste/libspw/string.spw +57 -26
- data/lib/spitewaste/libspw/terminal.spw +14 -0
- data/lib/spitewaste/libspw/test.spw +3 -0
- data/lib/spitewaste/libspw/util.spw +72 -21
- data/lib/spitewaste/parsers/fucktional.rb +7 -3
- data/lib/spitewaste/parsers/spitewaste.rb +17 -7
- data/lib/spitewaste/version.rb +1 -1
- metadata +3 -2
@@ -64,9 +64,13 @@ maxby_lesser_%1$s: swap jump maxby_resume_%1$s
|
|
64
64
|
maxby_done_%1$s:
|
65
65
|
SPW
|
66
66
|
|
67
|
-
'minby'
|
68
|
-
'each'
|
69
|
-
'
|
67
|
+
'minby' => 'maxby (%2$s push -1 mul)',
|
68
|
+
'each' => 'dup times (dup call roll %2$s push 1 sub) pop',
|
69
|
+
'all' => 'map (%2$s) reduce (add) push -11 load call eq',
|
70
|
+
# TODO: optimize any to stop early if possible
|
71
|
+
'any' => 'map (%2$s) reduce (add) push 0 call gt',
|
72
|
+
'none' => 'map (%2$s) reduce (add) push 0 call eq',
|
73
|
+
'count' => 'select (%2$s) dup call nslide',
|
70
74
|
'select' => generate_filter_spw('select', 0, 1),
|
71
75
|
'reject' => generate_filter_spw('reject', 1, 0),
|
72
76
|
}
|
@@ -57,14 +57,14 @@ 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
|
64
|
-
remove_comments
|
65
64
|
add_sugar
|
66
|
-
|
65
|
+
remove_comments
|
67
66
|
propagate_macros
|
67
|
+
fucktionalize
|
68
68
|
end
|
69
69
|
|
70
70
|
def resolve_imports
|
@@ -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
|
@@ -111,6 +117,10 @@ module Spitewaste
|
|
111
117
|
@src.gsub!(/'(.)'/) { $1.ord }
|
112
118
|
# quick push (`push 1,2,3` desugars to individual pushes)
|
113
119
|
@src.gsub!(/push \S+/) { |m| m.split(?,) * ' push ' }
|
120
|
+
# quick store (`^2` = `push 2 swap store`)
|
121
|
+
@src.gsub!(/\^(\S+)/, 'push \1 swap store')
|
122
|
+
# quick load (`@2` = `push 2 load`)
|
123
|
+
@src.gsub!(/@(\S+)/, 'push \1 load')
|
114
124
|
end
|
115
125
|
|
116
126
|
def gensym
|
@@ -131,10 +141,10 @@ module Spitewaste
|
|
131
141
|
parse = -> s { s.split(?,).map &:strip }
|
132
142
|
|
133
143
|
# Macro "functions" get handled first.
|
134
|
-
@src.gsub!(/(\$\S+?)\(([^)]
|
144
|
+
@src.gsub!(/(\$\S+?)\(([^)]*)\)\s*{(.+?)}/m) {
|
135
145
|
@macros[$1] ||= [$2, $3]; ''
|
136
146
|
}
|
137
|
-
@src.gsub!(/(\$\S+?)\(([^)]
|
147
|
+
@src.gsub!(/(\$\S+?)\(([^)]*)\)/) {
|
138
148
|
params, body = @macros[$1]
|
139
149
|
raise "no macro function '#$1'" unless body
|
140
150
|
map = parse[params].zip(parse[$2]).to_h
|
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.
|
4
|
+
version: 0.2.01
|
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-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- lib/spitewaste/libspw/stack.spw
|
111
111
|
- lib/spitewaste/libspw/string.spw
|
112
112
|
- lib/spitewaste/libspw/syntax.spw
|
113
|
+
- lib/spitewaste/libspw/terminal.spw
|
113
114
|
- lib/spitewaste/libspw/test.spw
|
114
115
|
- lib/spitewaste/libspw/util.spw
|
115
116
|
- lib/spitewaste/parsers/assembly.rb
|