@@ -187,9 +187,8 @@ impl<'a> FunctionEmitter<'a> {
187
187
match & function_call. name . name [ ..] {
188
188
"int" => {
189
189
assert_arity ( & function_call, 1 ) ?;
190
- for arg in function_call. arguments {
191
- self . emit_expression ( arg) ?;
192
- }
190
+ self . emit_function_args ( function_call) ?;
191
+
193
192
self . push ( Instruction :: F64Floor ) ;
194
193
}
195
194
"if" => {
@@ -207,15 +206,79 @@ impl<'a> FunctionEmitter<'a> {
207
206
self . emit_expression ( alternate) ?;
208
207
self . push ( Instruction :: End ) ;
209
208
}
209
+ "abs" => {
210
+ assert_arity ( & function_call, 1 ) ?;
211
+ self . emit_function_args ( function_call) ?;
212
+
213
+ self . push ( Instruction :: F64Abs )
214
+ }
215
+ "sqrt" => {
216
+ assert_arity ( & function_call, 1 ) ?;
217
+ self . emit_function_args ( function_call) ?;
218
+
219
+ self . push ( Instruction :: F64Abs ) ;
220
+ self . push ( Instruction :: F64Sqrt )
221
+ }
222
+ "min" => {
223
+ assert_arity ( & function_call, 2 ) ?;
224
+ self . emit_function_args ( function_call) ?;
225
+
226
+ self . push ( Instruction :: F64Min )
227
+ }
228
+ "max" => {
229
+ assert_arity ( & function_call, 2 ) ?;
230
+ self . emit_function_args ( function_call) ?;
231
+
232
+ self . push ( Instruction :: F64Max )
233
+ }
234
+ "above" => {
235
+ assert_arity ( & function_call, 2 ) ?;
236
+ self . emit_function_args ( function_call) ?;
237
+
238
+ self . push ( Instruction :: F64Gt ) ;
239
+ self . push ( Instruction :: F64ConvertSI32 )
240
+ }
241
+ "below" => {
242
+ assert_arity ( & function_call, 2 ) ?;
243
+ self . emit_function_args ( function_call) ?;
244
+
245
+ self . push ( Instruction :: F64Lt ) ;
246
+ self . push ( Instruction :: F64ConvertSI32 )
247
+ }
248
+ "equal" => {
249
+ assert_arity ( & function_call, 2 ) ?;
250
+ self . emit_function_args ( function_call) ?;
251
+
252
+ self . push ( Instruction :: F64Sub ) ;
253
+ self . emit_is_zeroish ( ) ;
254
+ self . push ( Instruction :: F64ConvertSI32 )
255
+ }
256
+ "bnot" => {
257
+ assert_arity ( & function_call, 1 ) ?;
258
+ self . emit_function_args ( function_call) ?;
259
+
260
+ self . emit_is_zeroish ( ) ;
261
+ self . push ( Instruction :: F64ConvertSI32 )
262
+ }
263
+ "floor" => {
264
+ assert_arity ( & function_call, 1 ) ?;
265
+ self . emit_function_args ( function_call) ?;
266
+
267
+ self . push ( Instruction :: F64Floor )
268
+ }
269
+ "ceil" => {
270
+ assert_arity ( & function_call, 1 ) ?;
271
+ self . emit_function_args ( function_call) ?;
272
+
273
+ self . push ( Instruction :: F64Ceil )
274
+ }
210
275
"megabuf" => self . emit_memory_access ( & mut function_call, 0 ) ?,
211
276
"gmegabuf" => self . emit_memory_access ( & mut function_call, BUFFER_SIZE * 8 ) ?,
212
277
shim_name if Shim :: from_str ( shim_name) . is_some ( ) => {
213
278
let shim = Shim :: from_str ( shim_name) . unwrap ( ) ;
214
279
assert_arity ( & function_call, shim. arity ( ) ) ?;
280
+ self . emit_function_args ( function_call) ?;
215
281
216
- for arg in function_call. arguments {
217
- self . emit_expression ( arg) ?;
218
- }
219
282
let shim_index = self . shims . get ( shim) ;
220
283
self . push ( Instruction :: Call ( shim_index) ) ;
221
284
}
@@ -228,6 +291,12 @@ impl<'a> FunctionEmitter<'a> {
228
291
}
229
292
Ok ( ( ) )
230
293
}
294
+ fn emit_function_args ( & mut self , function_call : FunctionCall ) -> EmitterResult < ( ) > {
295
+ for arg in function_call. arguments {
296
+ self . emit_expression ( arg) ?;
297
+ }
298
+ Ok ( ( ) )
299
+ }
231
300
232
301
fn emit_memory_access (
233
302
& mut self ,
0 commit comments