From 2bd7d936e0ca47e445c7d946aa1ae8287a62f049 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 5 Mar 2017 14:54:20 -0400 Subject: - Added temporary implementations for Nat division and remainder. - Fixed a bug in the RT function for counting bits. --- luxc/src/lux/compiler/js/rt.clj | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'luxc') diff --git a/luxc/src/lux/compiler/js/rt.clj b/luxc/src/lux/compiler/js/rt.clj index b1c1aeb1b..0c34453f7 100644 --- a/luxc/src/lux/compiler/js/rt.clj +++ b/luxc/src/lux/compiler/js/rt.clj @@ -965,6 +965,45 @@ "return '+'.concat(LuxRT.encodeI64(input));" "}") "})") + "divN64" (str "(function divN64(l,r) {" + (str "if(LuxRT.ltI64(r,LuxRT.ZERO)) {" + (str "if(LuxRT.ltN64(l,r)) {" + "return LuxRT.ZERO;" + "}" + "else {" + "return LuxRT.ONE;" + "}") + "}" + "else if(LuxRT.ltI64(LuxRT.ZERO,l)) {" + "return LuxRT.divI64(l,r);" + "}" + "else {" + (str "if(LuxRT.eqI64(LuxRT.ZERO,r)) {" + "throw new Error('Cannot divide by zero!');" + "}" + "else {" + (str "if(LuxRT.ltI64(l,r)) {" + "return LuxRT.ZERO;" + "}" + "else {" + "throw new Error('AWAITING BIG-INT DIVISION IMPLEMENTATION!!!');" + "}") + "}") + "}") + "})") + "remN64" (str "(function remN64(l,r) {" + (str "if(LuxRT.ltI64(l,LuxRT.ZERO) || LuxRT.ltI64(r,LuxRT.ZERO)) {" + (str "if(LuxRT.ltN64(l,r)) {" + "return l;" + "}" + "else {" + "throw new Error('AWAITING BIG-INT REMAINDER IMPLEMENTATION!!!');" + "}") + "}" + "else {" + "return LuxRT.remI64(l,r);" + "}") + "})") "ltN64" (str "(function ltN64(l,r) {" "var li = LuxRT.addI64(l,LuxRT.MIN_VALUE_I64);" "var ri = LuxRT.addI64(r,LuxRT.MIN_VALUE_I64);" @@ -1123,7 +1162,7 @@ "countI64" (str "(function countI64(input) {" "var hs = (input.H).toString(2);" "var ls = (input.L).toString(2);" - "var num1s = hs.concat(ls).replace('0','').length;" + "var num1s = hs.concat(ls).replace(/0/g,'').length;" "return LuxRT.fromNumberI64(num1s);" "})") "shlI64" (str "(function shlI64(input,shift) {" -- cgit v1.2.3