Browse Source

compile more than 2 arguments to math functions

Inderjit Gill 2 months ago
parent
commit
75f7f0f03b
2 changed files with 25 additions and 3 deletions
  1. 25
    2
      core/sen-core/src/compiler.rs
  2. 0
    1
      core/sen-core/src/vm.rs

+ 25
- 2
core/sen-core/src/compiler.rs View File

@@ -2185,10 +2185,11 @@ impl Compiler {
2185 2185
         children: &[&Node],
2186 2186
         op: Opcode,
2187 2187
     ) -> Result<()> {
2188
-        for n in children {
2188
+        self.compile(compilation, children[0])?;
2189
+        for n in &children[1..] {
2189 2190
             self.compile(compilation, n)?;
2191
+            compilation.emit_opcode(op)?;
2190 2192
         }
2191
-        compilation.emit_opcode(op)?;
2192 2193
         Ok(())
2193 2194
     }
2194 2195
 
@@ -2793,6 +2794,28 @@ mod tests {
2793 2794
     }
2794 2795
 
2795 2796
     #[test]
2797
+    fn test_adding_multiple_numbers() {
2798
+        assert_eq!(
2799
+            compile(
2800
+                "(+ 5 6 7 8 9)"
2801
+            ),
2802
+            vec![
2803
+                jump(1),
2804
+                load_const_f32(5.0),
2805
+                load_const_f32(6.0),
2806
+                add(),
2807
+                load_const_f32(7.0),
2808
+                add(),
2809
+                load_const_f32(8.0),
2810
+                add(),
2811
+                load_const_f32(9.0),
2812
+                add(),
2813
+                stop()
2814
+            ]
2815
+        );
2816
+    }
2817
+
2818
+    #[test]
2796 2819
     fn test_fn_invocation() {
2797 2820
         assert_eq!(
2798 2821
             compile(

+ 0
- 1
core/sen-core/src/vm.rs View File

@@ -1013,7 +1013,6 @@ impl Vm {
1013 1013
         } else if let Var::Vector(ref mut vec_vec) = &mut self.stack[self.sp - 1] {
1014 1014
             vec_vec.push(cloned_var_value);
1015 1015
         } else {
1016
-            println!("{:?}", &self.stack[self.sp - 1]);
1017 1016
             return Err(Error::VM(
1018 1017
                 "append requires either a Vector or V2D".to_string(),
1019 1018
             ));