spitewaste 0.1.009 → 0.2.01

Sign up to get free protection for your applications and to get access to all the features.
@@ -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' => 'maxby (%2$s push -1 mul)',
68
- 'each' => 'dup times (dup call roll %2$s push 1 sub) pop',
69
- 'count' => 'select (%2$s) dup call nslide',
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.prepend "import syntax\n"
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
- fucktionalize
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
- imports << resolve($1) if @seen.add? $1
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+?)\(([^)]+)\)\s*{(.+?)}/m) {
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
@@ -1,3 +1,3 @@
1
1
  module Spitewaste
2
- VERSION = '0.1.009'
2
+ VERSION = '0.2.01'
3
3
  end
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.009
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: 2020-12-18 00:00:00.000000000 Z
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