postscript 0.1.0 → 0.2.0
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/.rubocop.yml +19 -0
- data/.rubocop_todo.yml +323 -0
- data/CHANGELOG.md +71 -0
- data/LICENSE +24 -0
- data/exe/postscript +7 -0
- data/lib/postscript/cli.rb +83 -0
- data/lib/postscript/color.rb +6 -4
- data/lib/postscript/format_number.rb +4 -1
- data/lib/postscript/model/operator.rb +1 -1
- data/lib/postscript/model/operators/arithmetic.rb +30 -0
- data/lib/postscript/model/operators/boolean.rb +23 -11
- data/lib/postscript/model/operators/color.rb +8 -0
- data/lib/postscript/model/operators/container.rb +24 -0
- data/lib/postscript/model/operators/control_flow.rb +16 -1
- data/lib/postscript/model/operators/dictionary.rb +8 -0
- data/lib/postscript/model/operators/font.rb +14 -0
- data/lib/postscript/model/operators/graphics_state.rb +10 -0
- data/lib/postscript/model/operators/path.rb +16 -0
- data/lib/postscript/model/operators/stack.rb +4 -0
- data/lib/postscript/model/operators/transformations.rb +11 -1
- data/lib/postscript/model/program.rb +2 -2
- data/lib/postscript/serializer.rb +32 -212
- data/lib/postscript/source/ast_builder.rb +30 -22
- data/lib/postscript/source/lexer.rb +18 -21
- data/lib/postscript/version.rb +1 -1
- data/lib/postscript.rb +30 -0
- metadata +29 -6
- data/postscript.gemspec +0 -37
|
@@ -15,6 +15,7 @@ module Postscript
|
|
|
15
15
|
new(operand_a: a, operand_b: b)
|
|
16
16
|
end
|
|
17
17
|
attr_reader :operand_a, :operand_b
|
|
18
|
+
|
|
18
19
|
def initialize(operand_a:, operand_b:)
|
|
19
20
|
@operand_a = operand_a
|
|
20
21
|
@operand_b = operand_b
|
|
@@ -30,6 +31,7 @@ module Postscript
|
|
|
30
31
|
new(operand_a: a, operand_b: b)
|
|
31
32
|
end
|
|
32
33
|
attr_reader :operand_a, :operand_b
|
|
34
|
+
|
|
33
35
|
def initialize(operand_a:, operand_b:)
|
|
34
36
|
@operand_a = operand_a
|
|
35
37
|
@operand_b = operand_b
|
|
@@ -45,6 +47,7 @@ module Postscript
|
|
|
45
47
|
new(operand_a: a, operand_b: b)
|
|
46
48
|
end
|
|
47
49
|
attr_reader :operand_a, :operand_b
|
|
50
|
+
|
|
48
51
|
def initialize(operand_a:, operand_b:)
|
|
49
52
|
@operand_a = operand_a
|
|
50
53
|
@operand_b = operand_b
|
|
@@ -60,6 +63,7 @@ module Postscript
|
|
|
60
63
|
new(operand_a: a, operand_b: b)
|
|
61
64
|
end
|
|
62
65
|
attr_reader :operand_a, :operand_b
|
|
66
|
+
|
|
63
67
|
def initialize(operand_a:, operand_b:)
|
|
64
68
|
@operand_a = operand_a
|
|
65
69
|
@operand_b = operand_b
|
|
@@ -75,6 +79,7 @@ module Postscript
|
|
|
75
79
|
new(operand_a: a, operand_b: b)
|
|
76
80
|
end
|
|
77
81
|
attr_reader :operand_a, :operand_b
|
|
82
|
+
|
|
78
83
|
def initialize(operand_a:, operand_b:)
|
|
79
84
|
@operand_a = operand_a
|
|
80
85
|
@operand_b = operand_b
|
|
@@ -90,6 +95,7 @@ module Postscript
|
|
|
90
95
|
new(operand_a: a, operand_b: b)
|
|
91
96
|
end
|
|
92
97
|
attr_reader :operand_a, :operand_b
|
|
98
|
+
|
|
93
99
|
def initialize(operand_a:, operand_b:)
|
|
94
100
|
@operand_a = operand_a
|
|
95
101
|
@operand_b = operand_b
|
|
@@ -100,10 +106,12 @@ module Postscript
|
|
|
100
106
|
class Neg < Operator
|
|
101
107
|
register_as "neg", **UNARY_DEFAULT
|
|
102
108
|
attr_reader :operand
|
|
109
|
+
|
|
103
110
|
def initialize(operand:)
|
|
104
111
|
@operand = operand
|
|
105
112
|
freeze
|
|
106
113
|
end
|
|
114
|
+
|
|
107
115
|
def self.from_operands(stack)
|
|
108
116
|
new(operand: stack.pop_number)
|
|
109
117
|
end
|
|
@@ -112,10 +120,12 @@ module Postscript
|
|
|
112
120
|
class Abs < Operator
|
|
113
121
|
register_as "abs", **UNARY_DEFAULT
|
|
114
122
|
attr_reader :operand
|
|
123
|
+
|
|
115
124
|
def initialize(operand:)
|
|
116
125
|
@operand = operand
|
|
117
126
|
freeze
|
|
118
127
|
end
|
|
128
|
+
|
|
119
129
|
def self.from_operands(stack)
|
|
120
130
|
new(operand: stack.pop_number)
|
|
121
131
|
end
|
|
@@ -124,10 +134,12 @@ module Postscript
|
|
|
124
134
|
class Ceiling < Operator
|
|
125
135
|
register_as "ceiling", **UNARY_DEFAULT
|
|
126
136
|
attr_reader :operand
|
|
137
|
+
|
|
127
138
|
def initialize(operand:)
|
|
128
139
|
@operand = operand
|
|
129
140
|
freeze
|
|
130
141
|
end
|
|
142
|
+
|
|
131
143
|
def self.from_operands(stack)
|
|
132
144
|
new(operand: stack.pop_number)
|
|
133
145
|
end
|
|
@@ -136,10 +148,12 @@ module Postscript
|
|
|
136
148
|
class Floor < Operator
|
|
137
149
|
register_as "floor", **UNARY_DEFAULT
|
|
138
150
|
attr_reader :operand
|
|
151
|
+
|
|
139
152
|
def initialize(operand:)
|
|
140
153
|
@operand = operand
|
|
141
154
|
freeze
|
|
142
155
|
end
|
|
156
|
+
|
|
143
157
|
def self.from_operands(stack)
|
|
144
158
|
new(operand: stack.pop_number)
|
|
145
159
|
end
|
|
@@ -148,10 +162,12 @@ module Postscript
|
|
|
148
162
|
class Round < Operator
|
|
149
163
|
register_as "round", **UNARY_DEFAULT
|
|
150
164
|
attr_reader :operand
|
|
165
|
+
|
|
151
166
|
def initialize(operand:)
|
|
152
167
|
@operand = operand
|
|
153
168
|
freeze
|
|
154
169
|
end
|
|
170
|
+
|
|
155
171
|
def self.from_operands(stack)
|
|
156
172
|
new(operand: stack.pop_number)
|
|
157
173
|
end
|
|
@@ -160,10 +176,12 @@ module Postscript
|
|
|
160
176
|
class Truncate < Operator
|
|
161
177
|
register_as "truncate", **UNARY_DEFAULT
|
|
162
178
|
attr_reader :operand
|
|
179
|
+
|
|
163
180
|
def initialize(operand:)
|
|
164
181
|
@operand = operand
|
|
165
182
|
freeze
|
|
166
183
|
end
|
|
184
|
+
|
|
167
185
|
def self.from_operands(stack)
|
|
168
186
|
new(operand: stack.pop_number)
|
|
169
187
|
end
|
|
@@ -172,10 +190,12 @@ module Postscript
|
|
|
172
190
|
class Sqrt < Operator
|
|
173
191
|
register_as "sqrt", **UNARY_DEFAULT
|
|
174
192
|
attr_reader :operand
|
|
193
|
+
|
|
175
194
|
def initialize(operand:)
|
|
176
195
|
@operand = operand
|
|
177
196
|
freeze
|
|
178
197
|
end
|
|
198
|
+
|
|
179
199
|
def self.from_operands(stack)
|
|
180
200
|
new(operand: stack.pop_number)
|
|
181
201
|
end
|
|
@@ -189,6 +209,7 @@ module Postscript
|
|
|
189
209
|
new(operand_a: a, operand_b: b)
|
|
190
210
|
end
|
|
191
211
|
attr_reader :operand_a, :operand_b
|
|
212
|
+
|
|
192
213
|
def initialize(operand_a:, operand_b:)
|
|
193
214
|
@operand_a = operand_a
|
|
194
215
|
@operand_b = operand_b
|
|
@@ -199,10 +220,12 @@ module Postscript
|
|
|
199
220
|
class Cos < Operator
|
|
200
221
|
register_as "cos", **UNARY_DEFAULT
|
|
201
222
|
attr_reader :operand
|
|
223
|
+
|
|
202
224
|
def initialize(operand:)
|
|
203
225
|
@operand = operand
|
|
204
226
|
freeze
|
|
205
227
|
end
|
|
228
|
+
|
|
206
229
|
def self.from_operands(stack)
|
|
207
230
|
new(operand: stack.pop_number)
|
|
208
231
|
end
|
|
@@ -211,10 +234,12 @@ module Postscript
|
|
|
211
234
|
class Sin < Operator
|
|
212
235
|
register_as "sin", **UNARY_DEFAULT
|
|
213
236
|
attr_reader :operand
|
|
237
|
+
|
|
214
238
|
def initialize(operand:)
|
|
215
239
|
@operand = operand
|
|
216
240
|
freeze
|
|
217
241
|
end
|
|
242
|
+
|
|
218
243
|
def self.from_operands(stack)
|
|
219
244
|
new(operand: stack.pop_number)
|
|
220
245
|
end
|
|
@@ -223,10 +248,12 @@ module Postscript
|
|
|
223
248
|
class Ln < Operator
|
|
224
249
|
register_as "ln", **UNARY_DEFAULT
|
|
225
250
|
attr_reader :operand
|
|
251
|
+
|
|
226
252
|
def initialize(operand:)
|
|
227
253
|
@operand = operand
|
|
228
254
|
freeze
|
|
229
255
|
end
|
|
256
|
+
|
|
230
257
|
def self.from_operands(stack)
|
|
231
258
|
new(operand: stack.pop_number)
|
|
232
259
|
end
|
|
@@ -235,10 +262,12 @@ module Postscript
|
|
|
235
262
|
class Log < Operator
|
|
236
263
|
register_as "log", **UNARY_DEFAULT
|
|
237
264
|
attr_reader :operand
|
|
265
|
+
|
|
238
266
|
def initialize(operand:)
|
|
239
267
|
@operand = operand
|
|
240
268
|
freeze
|
|
241
269
|
end
|
|
270
|
+
|
|
242
271
|
def self.from_operands(stack)
|
|
243
272
|
new(operand: stack.pop_number)
|
|
244
273
|
end
|
|
@@ -252,6 +281,7 @@ module Postscript
|
|
|
252
281
|
new(operand_a: a, operand_b: b)
|
|
253
282
|
end
|
|
254
283
|
attr_reader :operand_a, :operand_b
|
|
284
|
+
|
|
255
285
|
def initialize(operand_a:, operand_b:)
|
|
256
286
|
@operand_a = operand_a
|
|
257
287
|
@operand_b = operand_b
|
|
@@ -16,13 +16,14 @@ module Postscript
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
class Eq < Operator
|
|
19
|
-
register_as "eq"
|
|
19
|
+
register_as "eq", consumes: 2, produces: 1
|
|
20
20
|
def self.from_operands(stack)
|
|
21
21
|
b = stack.pop
|
|
22
22
|
a = stack.pop
|
|
23
23
|
new(operand_a: a, operand_b: b)
|
|
24
24
|
end
|
|
25
25
|
attr_reader :operand_a, :operand_b
|
|
26
|
+
|
|
26
27
|
def initialize(operand_a:, operand_b:)
|
|
27
28
|
@operand_a = operand_a
|
|
28
29
|
@operand_b = operand_b
|
|
@@ -31,13 +32,14 @@ module Postscript
|
|
|
31
32
|
end
|
|
32
33
|
|
|
33
34
|
class Ne < Operator
|
|
34
|
-
register_as "ne"
|
|
35
|
+
register_as "ne", consumes: 2, produces: 1
|
|
35
36
|
def self.from_operands(stack)
|
|
36
37
|
b = stack.pop
|
|
37
38
|
a = stack.pop
|
|
38
39
|
new(operand_a: a, operand_b: b)
|
|
39
40
|
end
|
|
40
41
|
attr_reader :operand_a, :operand_b
|
|
42
|
+
|
|
41
43
|
def initialize(operand_a:, operand_b:)
|
|
42
44
|
@operand_a = operand_a
|
|
43
45
|
@operand_b = operand_b
|
|
@@ -46,13 +48,14 @@ module Postscript
|
|
|
46
48
|
end
|
|
47
49
|
|
|
48
50
|
class Gt < Operator
|
|
49
|
-
register_as "gt"
|
|
51
|
+
register_as "gt", consumes: 2, produces: 1
|
|
50
52
|
def self.from_operands(stack)
|
|
51
53
|
b = stack.pop_number
|
|
52
54
|
a = stack.pop_number
|
|
53
55
|
new(operand_a: a, operand_b: b)
|
|
54
56
|
end
|
|
55
57
|
attr_reader :operand_a, :operand_b
|
|
58
|
+
|
|
56
59
|
def initialize(operand_a:, operand_b:)
|
|
57
60
|
@operand_a = operand_a
|
|
58
61
|
@operand_b = operand_b
|
|
@@ -61,13 +64,14 @@ module Postscript
|
|
|
61
64
|
end
|
|
62
65
|
|
|
63
66
|
class Ge < Operator
|
|
64
|
-
register_as "ge"
|
|
67
|
+
register_as "ge", consumes: 2, produces: 1
|
|
65
68
|
def self.from_operands(stack)
|
|
66
69
|
b = stack.pop_number
|
|
67
70
|
a = stack.pop_number
|
|
68
71
|
new(operand_a: a, operand_b: b)
|
|
69
72
|
end
|
|
70
73
|
attr_reader :operand_a, :operand_b
|
|
74
|
+
|
|
71
75
|
def initialize(operand_a:, operand_b:)
|
|
72
76
|
@operand_a = operand_a
|
|
73
77
|
@operand_b = operand_b
|
|
@@ -76,13 +80,14 @@ module Postscript
|
|
|
76
80
|
end
|
|
77
81
|
|
|
78
82
|
class Lt < Operator
|
|
79
|
-
register_as "lt"
|
|
83
|
+
register_as "lt", consumes: 2, produces: 1
|
|
80
84
|
def self.from_operands(stack)
|
|
81
85
|
b = stack.pop_number
|
|
82
86
|
a = stack.pop_number
|
|
83
87
|
new(operand_a: a, operand_b: b)
|
|
84
88
|
end
|
|
85
89
|
attr_reader :operand_a, :operand_b
|
|
90
|
+
|
|
86
91
|
def initialize(operand_a:, operand_b:)
|
|
87
92
|
@operand_a = operand_a
|
|
88
93
|
@operand_b = operand_b
|
|
@@ -91,13 +96,14 @@ module Postscript
|
|
|
91
96
|
end
|
|
92
97
|
|
|
93
98
|
class Le < Operator
|
|
94
|
-
register_as "le"
|
|
99
|
+
register_as "le", consumes: 2, produces: 1
|
|
95
100
|
def self.from_operands(stack)
|
|
96
101
|
b = stack.pop_number
|
|
97
102
|
a = stack.pop_number
|
|
98
103
|
new(operand_a: a, operand_b: b)
|
|
99
104
|
end
|
|
100
105
|
attr_reader :operand_a, :operand_b
|
|
106
|
+
|
|
101
107
|
def initialize(operand_a:, operand_b:)
|
|
102
108
|
@operand_a = operand_a
|
|
103
109
|
@operand_b = operand_b
|
|
@@ -106,13 +112,14 @@ module Postscript
|
|
|
106
112
|
end
|
|
107
113
|
|
|
108
114
|
class And < Operator
|
|
109
|
-
register_as "and"
|
|
115
|
+
register_as "and", consumes: 2, produces: 1
|
|
110
116
|
def self.from_operands(stack)
|
|
111
117
|
b = stack.pop
|
|
112
118
|
a = stack.pop
|
|
113
119
|
new(operand_a: a, operand_b: b)
|
|
114
120
|
end
|
|
115
121
|
attr_reader :operand_a, :operand_b
|
|
122
|
+
|
|
116
123
|
def initialize(operand_a:, operand_b:)
|
|
117
124
|
@operand_a = operand_a
|
|
118
125
|
@operand_b = operand_b
|
|
@@ -121,13 +128,14 @@ module Postscript
|
|
|
121
128
|
end
|
|
122
129
|
|
|
123
130
|
class Or < Operator
|
|
124
|
-
register_as "or"
|
|
131
|
+
register_as "or", consumes: 2, produces: 1
|
|
125
132
|
def self.from_operands(stack)
|
|
126
133
|
b = stack.pop
|
|
127
134
|
a = stack.pop
|
|
128
135
|
new(operand_a: a, operand_b: b)
|
|
129
136
|
end
|
|
130
137
|
attr_reader :operand_a, :operand_b
|
|
138
|
+
|
|
131
139
|
def initialize(operand_a:, operand_b:)
|
|
132
140
|
@operand_a = operand_a
|
|
133
141
|
@operand_b = operand_b
|
|
@@ -136,13 +144,14 @@ module Postscript
|
|
|
136
144
|
end
|
|
137
145
|
|
|
138
146
|
class Xor < Operator
|
|
139
|
-
register_as "xor"
|
|
147
|
+
register_as "xor", consumes: 2, produces: 1
|
|
140
148
|
def self.from_operands(stack)
|
|
141
149
|
b = stack.pop
|
|
142
150
|
a = stack.pop
|
|
143
151
|
new(operand_a: a, operand_b: b)
|
|
144
152
|
end
|
|
145
153
|
attr_reader :operand_a, :operand_b
|
|
154
|
+
|
|
146
155
|
def initialize(operand_a:, operand_b:)
|
|
147
156
|
@operand_a = operand_a
|
|
148
157
|
@operand_b = operand_b
|
|
@@ -151,25 +160,28 @@ module Postscript
|
|
|
151
160
|
end
|
|
152
161
|
|
|
153
162
|
class Not < Operator
|
|
154
|
-
register_as "not"
|
|
163
|
+
register_as "not", consumes: 1, produces: 1
|
|
155
164
|
attr_reader :operand
|
|
165
|
+
|
|
156
166
|
def initialize(operand:)
|
|
157
167
|
@operand = operand
|
|
158
168
|
freeze
|
|
159
169
|
end
|
|
170
|
+
|
|
160
171
|
def self.from_operands(stack)
|
|
161
172
|
new(operand: stack.pop)
|
|
162
173
|
end
|
|
163
174
|
end
|
|
164
175
|
|
|
165
176
|
class Bitshift < Operator
|
|
166
|
-
register_as "bitshift"
|
|
177
|
+
register_as "bitshift", consumes: 2, produces: 1
|
|
167
178
|
def self.from_operands(stack)
|
|
168
179
|
shift = stack.pop_number.to_i
|
|
169
180
|
value = stack.pop_number.to_i
|
|
170
181
|
new(operand: value, shift: shift)
|
|
171
182
|
end
|
|
172
183
|
attr_reader :operand, :shift
|
|
184
|
+
|
|
173
185
|
def initialize(operand:, shift:)
|
|
174
186
|
@operand = operand
|
|
175
187
|
@shift = shift
|
|
@@ -7,10 +7,12 @@ module Postscript
|
|
|
7
7
|
class Setgray < Operator
|
|
8
8
|
register_as "setgray"
|
|
9
9
|
attr_reader :gray
|
|
10
|
+
|
|
10
11
|
def initialize(gray:)
|
|
11
12
|
@gray = gray
|
|
12
13
|
freeze
|
|
13
14
|
end
|
|
15
|
+
|
|
14
16
|
def self.from_operands(stack)
|
|
15
17
|
new(gray: stack.pop_number)
|
|
16
18
|
end
|
|
@@ -19,12 +21,14 @@ module Postscript
|
|
|
19
21
|
class Setrgbcolor < Operator
|
|
20
22
|
register_as "setrgbcolor"
|
|
21
23
|
attr_reader :red, :green, :blue
|
|
24
|
+
|
|
22
25
|
def initialize(red:, green:, blue:)
|
|
23
26
|
@red = red
|
|
24
27
|
@green = green
|
|
25
28
|
@blue = blue
|
|
26
29
|
freeze
|
|
27
30
|
end
|
|
31
|
+
|
|
28
32
|
def self.from_operands(stack)
|
|
29
33
|
blue = stack.pop_number
|
|
30
34
|
green = stack.pop_number
|
|
@@ -36,6 +40,7 @@ module Postscript
|
|
|
36
40
|
class Setcmykcolor < Operator
|
|
37
41
|
register_as "setcmykcolor"
|
|
38
42
|
attr_reader :cyan, :magenta, :yellow, :key
|
|
43
|
+
|
|
39
44
|
def initialize(cyan:, magenta:, yellow:, key:)
|
|
40
45
|
@cyan = cyan
|
|
41
46
|
@magenta = magenta
|
|
@@ -43,6 +48,7 @@ module Postscript
|
|
|
43
48
|
@key = key
|
|
44
49
|
freeze
|
|
45
50
|
end
|
|
51
|
+
|
|
46
52
|
def self.from_operands(stack)
|
|
47
53
|
key = stack.pop_number
|
|
48
54
|
yellow = stack.pop_number
|
|
@@ -55,12 +61,14 @@ module Postscript
|
|
|
55
61
|
class Sethsbcolor < Operator
|
|
56
62
|
register_as "sethsbcolor"
|
|
57
63
|
attr_reader :hue, :saturation, :brightness
|
|
64
|
+
|
|
58
65
|
def initialize(hue:, saturation:, brightness:)
|
|
59
66
|
@hue = hue
|
|
60
67
|
@saturation = saturation
|
|
61
68
|
@brightness = brightness
|
|
62
69
|
freeze
|
|
63
70
|
end
|
|
71
|
+
|
|
64
72
|
def self.from_operands(stack)
|
|
65
73
|
brightness = stack.pop_number
|
|
66
74
|
saturation = stack.pop_number
|
|
@@ -7,10 +7,12 @@ module Postscript
|
|
|
7
7
|
class Length < Operator
|
|
8
8
|
register_as "length", consumes: 1, produces: 1
|
|
9
9
|
attr_reader :operand
|
|
10
|
+
|
|
10
11
|
def initialize(operand:)
|
|
11
12
|
@operand = operand
|
|
12
13
|
freeze
|
|
13
14
|
end
|
|
15
|
+
|
|
14
16
|
def self.from_operands(stack)
|
|
15
17
|
new(operand: stack.pop)
|
|
16
18
|
end
|
|
@@ -19,11 +21,13 @@ module Postscript
|
|
|
19
21
|
class Get < Operator
|
|
20
22
|
register_as "get", consumes: 2, produces: 1
|
|
21
23
|
attr_reader :operand, :key
|
|
24
|
+
|
|
22
25
|
def initialize(operand:, key:)
|
|
23
26
|
@operand = operand
|
|
24
27
|
@key = key
|
|
25
28
|
freeze
|
|
26
29
|
end
|
|
30
|
+
|
|
27
31
|
def self.from_operands(stack)
|
|
28
32
|
key = stack.pop
|
|
29
33
|
coll = stack.pop
|
|
@@ -34,12 +38,14 @@ module Postscript
|
|
|
34
38
|
class Put < Operator
|
|
35
39
|
register_as "put", consumes: 3, produces: 0
|
|
36
40
|
attr_reader :operand, :key, :value
|
|
41
|
+
|
|
37
42
|
def initialize(operand:, key:, value:)
|
|
38
43
|
@operand = operand
|
|
39
44
|
@key = key
|
|
40
45
|
@value = value
|
|
41
46
|
freeze
|
|
42
47
|
end
|
|
48
|
+
|
|
43
49
|
def self.from_operands(stack)
|
|
44
50
|
value = stack.pop
|
|
45
51
|
key = stack.pop
|
|
@@ -51,12 +57,14 @@ module Postscript
|
|
|
51
57
|
class Getinterval < Operator
|
|
52
58
|
register_as "getinterval", consumes: 3, produces: 1
|
|
53
59
|
attr_reader :operand, :start, :count
|
|
60
|
+
|
|
54
61
|
def initialize(operand:, start:, count:)
|
|
55
62
|
@operand = operand
|
|
56
63
|
@start = start
|
|
57
64
|
@count = count
|
|
58
65
|
freeze
|
|
59
66
|
end
|
|
67
|
+
|
|
60
68
|
def self.from_operands(stack)
|
|
61
69
|
count = stack.pop_number.to_i
|
|
62
70
|
start = stack.pop_number.to_i
|
|
@@ -68,12 +76,14 @@ module Postscript
|
|
|
68
76
|
class Putinterval < Operator
|
|
69
77
|
register_as "putinterval", consumes: 3, produces: 0
|
|
70
78
|
attr_reader :operand, :start, :source
|
|
79
|
+
|
|
71
80
|
def initialize(operand:, start:, source:)
|
|
72
81
|
@operand = operand
|
|
73
82
|
@start = start
|
|
74
83
|
@source = source
|
|
75
84
|
freeze
|
|
76
85
|
end
|
|
86
|
+
|
|
77
87
|
def self.from_operands(stack)
|
|
78
88
|
source = stack.pop
|
|
79
89
|
start = stack.pop_number.to_i
|
|
@@ -85,11 +95,13 @@ module Postscript
|
|
|
85
95
|
class Forall < Operator
|
|
86
96
|
register_as "forall", consumes: 2, produces: 0
|
|
87
97
|
attr_reader :collection, :body
|
|
98
|
+
|
|
88
99
|
def initialize(collection:, body:)
|
|
89
100
|
@collection = collection
|
|
90
101
|
@body = body
|
|
91
102
|
freeze
|
|
92
103
|
end
|
|
104
|
+
|
|
93
105
|
def self.from_operands(stack)
|
|
94
106
|
body = stack.pop
|
|
95
107
|
coll = stack.pop
|
|
@@ -100,11 +112,13 @@ module Postscript
|
|
|
100
112
|
class Astore < Operator
|
|
101
113
|
register_as "astore", consumes: 1, produces: 1
|
|
102
114
|
attr_reader :array, :length
|
|
115
|
+
|
|
103
116
|
def initialize(array:, length:)
|
|
104
117
|
@array = array
|
|
105
118
|
@length = length
|
|
106
119
|
freeze
|
|
107
120
|
end
|
|
121
|
+
|
|
108
122
|
def self.from_operands(stack)
|
|
109
123
|
arr = stack.pop
|
|
110
124
|
length = stack.pop_number.to_i
|
|
@@ -115,11 +129,13 @@ module Postscript
|
|
|
115
129
|
class Search < Operator
|
|
116
130
|
register_as "search", consumes: 2, produces: 1
|
|
117
131
|
attr_reader :target, :pattern
|
|
132
|
+
|
|
118
133
|
def initialize(target:, pattern:)
|
|
119
134
|
@target = target
|
|
120
135
|
@pattern = pattern
|
|
121
136
|
freeze
|
|
122
137
|
end
|
|
138
|
+
|
|
123
139
|
def self.from_operands(stack)
|
|
124
140
|
pattern = stack.pop
|
|
125
141
|
target = stack.pop
|
|
@@ -130,11 +146,13 @@ module Postscript
|
|
|
130
146
|
class Anchorsearch < Operator
|
|
131
147
|
register_as "anchorsearch", consumes: 2, produces: 1
|
|
132
148
|
attr_reader :target, :pattern
|
|
149
|
+
|
|
133
150
|
def initialize(target:, pattern:)
|
|
134
151
|
@target = target
|
|
135
152
|
@pattern = pattern
|
|
136
153
|
freeze
|
|
137
154
|
end
|
|
155
|
+
|
|
138
156
|
def self.from_operands(stack)
|
|
139
157
|
pattern = stack.pop
|
|
140
158
|
target = stack.pop
|
|
@@ -145,10 +163,12 @@ module Postscript
|
|
|
145
163
|
class Token < Operator
|
|
146
164
|
register_as "token", consumes: 1, produces: 1
|
|
147
165
|
attr_reader :target
|
|
166
|
+
|
|
148
167
|
def initialize(target:)
|
|
149
168
|
@target = target
|
|
150
169
|
freeze
|
|
151
170
|
end
|
|
171
|
+
|
|
152
172
|
def self.from_operands(stack)
|
|
153
173
|
new(target: stack.pop)
|
|
154
174
|
end
|
|
@@ -157,10 +177,12 @@ module Postscript
|
|
|
157
177
|
class String < Operator
|
|
158
178
|
register_as "string", consumes: 1, produces: 1
|
|
159
179
|
attr_reader :count
|
|
180
|
+
|
|
160
181
|
def initialize(count:)
|
|
161
182
|
@count = count
|
|
162
183
|
freeze
|
|
163
184
|
end
|
|
185
|
+
|
|
164
186
|
def self.from_operands(stack)
|
|
165
187
|
new(count: stack.pop_number.to_i)
|
|
166
188
|
end
|
|
@@ -169,11 +191,13 @@ module Postscript
|
|
|
169
191
|
class Cvs < Operator
|
|
170
192
|
register_as "cvs", consumes: 2, produces: 1
|
|
171
193
|
attr_reader :value, :target
|
|
194
|
+
|
|
172
195
|
def initialize(value:, target:)
|
|
173
196
|
@value = value
|
|
174
197
|
@target = target
|
|
175
198
|
freeze
|
|
176
199
|
end
|
|
200
|
+
|
|
177
201
|
def self.from_operands(stack)
|
|
178
202
|
target = stack.pop
|
|
179
203
|
value = stack.pop
|
|
@@ -7,11 +7,13 @@ module Postscript
|
|
|
7
7
|
class If < Operator
|
|
8
8
|
register_as "if"
|
|
9
9
|
attr_reader :condition, :body
|
|
10
|
+
|
|
10
11
|
def initialize(condition:, body:)
|
|
11
12
|
@condition = condition
|
|
12
13
|
@body = body
|
|
13
14
|
freeze
|
|
14
15
|
end
|
|
16
|
+
|
|
15
17
|
def self.from_operands(stack)
|
|
16
18
|
body = stack.pop
|
|
17
19
|
condition = stack.pop
|
|
@@ -22,12 +24,14 @@ module Postscript
|
|
|
22
24
|
class Ifelse < Operator
|
|
23
25
|
register_as "ifelse"
|
|
24
26
|
attr_reader :condition, :if_body, :else_body
|
|
27
|
+
|
|
25
28
|
def initialize(condition:, if_body:, else_body:)
|
|
26
29
|
@condition = condition
|
|
27
30
|
@if_body = if_body
|
|
28
31
|
@else_body = else_body
|
|
29
32
|
freeze
|
|
30
33
|
end
|
|
34
|
+
|
|
31
35
|
def self.from_operands(stack)
|
|
32
36
|
else_body = stack.pop
|
|
33
37
|
if_body = stack.pop
|
|
@@ -39,11 +43,13 @@ module Postscript
|
|
|
39
43
|
class Repeat < Operator
|
|
40
44
|
register_as "repeat"
|
|
41
45
|
attr_reader :count, :body
|
|
46
|
+
|
|
42
47
|
def initialize(count:, body:)
|
|
43
48
|
@count = count
|
|
44
49
|
@body = body
|
|
45
50
|
freeze
|
|
46
51
|
end
|
|
52
|
+
|
|
47
53
|
def self.from_operands(stack)
|
|
48
54
|
body = stack.pop
|
|
49
55
|
count = stack.pop_number.to_i
|
|
@@ -54,10 +60,12 @@ module Postscript
|
|
|
54
60
|
class Loop < Operator
|
|
55
61
|
register_as "loop"
|
|
56
62
|
attr_reader :body
|
|
63
|
+
|
|
57
64
|
def initialize(body:)
|
|
58
65
|
@body = body
|
|
59
66
|
freeze
|
|
60
67
|
end
|
|
68
|
+
|
|
61
69
|
def self.from_operands(stack)
|
|
62
70
|
new(body: stack.pop)
|
|
63
71
|
end
|
|
@@ -66,6 +74,7 @@ module Postscript
|
|
|
66
74
|
class For < Operator
|
|
67
75
|
register_as "for"
|
|
68
76
|
attr_reader :initial, :increment, :limit, :body
|
|
77
|
+
|
|
69
78
|
def initialize(initial:, increment:, limit:, body:)
|
|
70
79
|
@initial = initial
|
|
71
80
|
@increment = increment
|
|
@@ -73,12 +82,14 @@ module Postscript
|
|
|
73
82
|
@body = body
|
|
74
83
|
freeze
|
|
75
84
|
end
|
|
85
|
+
|
|
76
86
|
def self.from_operands(stack)
|
|
77
87
|
body = stack.pop
|
|
78
88
|
limit = stack.pop_number
|
|
79
89
|
increment = stack.pop_number
|
|
80
90
|
initial = stack.pop_number
|
|
81
|
-
new(initial: initial, increment: increment, limit: limit,
|
|
91
|
+
new(initial: initial, increment: increment, limit: limit,
|
|
92
|
+
body: body)
|
|
82
93
|
end
|
|
83
94
|
end
|
|
84
95
|
|
|
@@ -93,10 +104,12 @@ module Postscript
|
|
|
93
104
|
class Exec < Operator
|
|
94
105
|
register_as "exec"
|
|
95
106
|
attr_reader :operand
|
|
107
|
+
|
|
96
108
|
def initialize(operand:)
|
|
97
109
|
@operand = operand
|
|
98
110
|
freeze
|
|
99
111
|
end
|
|
112
|
+
|
|
100
113
|
def self.from_operands(stack)
|
|
101
114
|
new(operand: stack.pop)
|
|
102
115
|
end
|
|
@@ -105,10 +118,12 @@ module Postscript
|
|
|
105
118
|
class Stopped < Operator
|
|
106
119
|
register_as "stopped"
|
|
107
120
|
attr_reader :body
|
|
121
|
+
|
|
108
122
|
def initialize(body:)
|
|
109
123
|
@body = body
|
|
110
124
|
freeze
|
|
111
125
|
end
|
|
126
|
+
|
|
112
127
|
def self.from_operands(stack)
|
|
113
128
|
new(body: stack.pop)
|
|
114
129
|
end
|