Skip to content

Commit 31c8d0f

Browse files
committed
More inlined functions
1 parent b3326c9 commit 31c8d0f

File tree

2 files changed

+75
-29
lines changed

2 files changed

+75
-29
lines changed

compiler-rs/src/function_emitter.rs

+75-6
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,8 @@ impl<'a> FunctionEmitter<'a> {
187187
match &function_call.name.name[..] {
188188
"int" => {
189189
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+
193192
self.push(Instruction::F64Floor);
194193
}
195194
"if" => {
@@ -207,15 +206,79 @@ impl<'a> FunctionEmitter<'a> {
207206
self.emit_expression(alternate)?;
208207
self.push(Instruction::End);
209208
}
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+
}
210275
"megabuf" => self.emit_memory_access(&mut function_call, 0)?,
211276
"gmegabuf" => self.emit_memory_access(&mut function_call, BUFFER_SIZE * 8)?,
212277
shim_name if Shim::from_str(shim_name).is_some() => {
213278
let shim = Shim::from_str(shim_name).unwrap();
214279
assert_arity(&function_call, shim.arity())?;
280+
self.emit_function_args(function_call)?;
215281

216-
for arg in function_call.arguments {
217-
self.emit_expression(arg)?;
218-
}
219282
let shim_index = self.shims.get(shim);
220283
self.push(Instruction::Call(shim_index));
221284
}
@@ -228,6 +291,12 @@ impl<'a> FunctionEmitter<'a> {
228291
}
229292
Ok(())
230293
}
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+
}
231300

232301
fn emit_memory_access(
233302
&mut self,

compiler-rs/tests/compatibility_test.rs

-23
Original file line numberDiff line numberDiff line change
@@ -333,29 +333,14 @@ fn compatibility_tests() {
333333
];
334334

335335
let expected_failing: Vec<&str> = vec![
336-
"Absolute value negative",
337-
"Absolute value positive",
338-
"Function used as expression",
339-
"Min",
340-
"Min reversed",
341-
"Max",
342-
"Max reversed",
343-
"Sqrt",
344-
"Sqrt (negative)",
345336
"Sqr",
346337
"Cos",
347338
"Tan",
348339
"Asin",
349340
"Acos",
350341
"Atan",
351342
"Atan2",
352-
"above (true)",
353-
"above (false)",
354-
"below (true)",
355-
"below (false)",
356343
"Line comments (\\\\)",
357-
"Equal (false)",
358-
"Equal (true)",
359344
"Pow",
360345
"Log",
361346
"Log10",
@@ -375,10 +360,6 @@ fn compatibility_tests() {
375360
"Band (false, false)",
376361
"Band does not shortcircut",
377362
"Band respects epsilon",
378-
"Bnot (true)",
379-
"Bnot (false)",
380-
"Bnot 0.1",
381-
"Bnot < epsilon",
382363
"Plus equals",
383364
"Plus equals (local var)",
384365
"Plus equals (megabuf)",
@@ -437,10 +418,6 @@ fn compatibility_tests() {
437418
"Sigmoid 0, 0",
438419
"Sigmoid 10, 10",
439420
"Exp",
440-
"Floor",
441-
"Floor",
442-
"Ceil",
443-
"Ceil",
444421
"Assign",
445422
"Assign return value",
446423
"EPSILON buffer indexes",

0 commit comments

Comments
 (0)