Commits

arkdro committed efe2351

adding operations. add and sum_list

Comments (0)

Files changed (1)

   | Eterm.ET_bignum x -> x
 
 let handle_payload = function
+    | Eterm.ET_tuple [|(Eterm.ET_atom "add"); Eterm.ET_bignum n1; Eterm.ET_bignum n2;|] ->
+      Trace.dbg "handle_payload" "add bignums\n%s\n%s\n%!"
+        (Num.string_of_num n1) (Num.string_of_num n2);
+      let res = Num.add_num n1 n2 in
+      Eterm.ET_bignum res
     | Eterm.ET_tuple [|(Eterm.ET_atom "multiply"); Eterm.ET_bignum n1; Eterm.ET_bignum n2;|] ->
       Trace.dbg "handle_payload" "mult bignums\n%s\n%s\n%!"
         (Num.string_of_num n1) (Num.string_of_num n2);
       in
       let res = List.fold_left f (Num.num_of_int 1) lst in
       Eterm.ET_bignum res
+    | Eterm.ET_tuple [|(Eterm.ET_atom "sum_list"); Eterm.ET_list lst;|] ->
+      Trace.dbg "handle_payload" "sum list\n%!";
+      let f acc x =
+        let bn = make_big_num x in
+        Num.add_num acc bn
+      in
+      let res = List.fold_left f (Num.num_of_int 0) lst in
+      Eterm.ET_bignum res
     | other ->
       Trace.dbg "handle_payload" "other\n%s\n%!" (Eterm.to_string other);
       Eterm.ET_atom "error"