shithub: mc

Download patch

ref: aca3176dbcded47fd46782e844da16fea02e86e5
parent: b3a8a63686f2447dea9c135ab863cee5364b3a07
author: Ori Bernstein <[email protected]>
date: Sat Sep 6 17:18:34 EDT 2014

Fix missing methods.

--- a/libstd/bigint.myr
+++ b/libstd/bigint.myr
@@ -20,7 +20,7 @@
 	;;
 
 	/* administrivia */
-	const mkbigint	: (v : int32 -> bigint#)
+	generic mkbigint	: (v : @a::(numeric,integral) -> bigint#)
 	const bigfree	: (a : bigint# -> void)
 	const bigdup	: (a : bigint# -> bigint#)
 	const bigassign	: (d : bigint#, s : bigint# -> bigint#)
@@ -52,8 +52,10 @@
 
 const Base = 0x100000000ul
 
-const mkbigint = {v
+generic mkbigint = {v : @a::(integral,numeric)
 	var a
+	var i
+
 	a = zalloc()
 
 	a.dig = slalloc(1)
@@ -63,7 +65,11 @@
 	elif v > 0
 		a.sign = 1
 	;;
-	a.dig[0] = (v castto(uint32))
+	i = 0
+	while v != 0
+		a.dig[i++] = (v castto(uint32))
+		v /= (Base castto(@a::(numeric,integral)))
+	;;
 	-> trim(a)
 }
 
@@ -500,6 +506,46 @@
 	| n:	die("shift by way too much\n")
 	;;
 }
+
+/* a + b, b is integer.
+FIXME: acually make this a performace improvement
+*/
+const bigaddi = {a, b
+	var bigb
+
+	bigb = mkbigint(b)
+	bigadd(a, bigb)
+	bigfree(bigb)
+	-> a
+}
+
+const bigsubi = {a, b
+	var bigb
+
+	bigb = mkbigint(b)
+	bigsub(a, bigb)
+	bigfree(bigb)
+	-> a
+}
+
+const bigmuli = {a, b
+	var bigb
+
+	bigb = mkbigint(b)
+	bigmul(a, bigb)
+	bigfree(bigb)
+	-> a
+}
+
+const bigdivi = {a, b
+	var bigb
+
+	bigb = mkbigint(b)
+	bigdiv(a, bigb)
+	bigfree(bigb)
+	-> a
+}
+
 
 /* 
   a << s, with integer arg.
--- a/libstd/bitset.myr
+++ b/libstd/bitset.myr
@@ -21,7 +21,7 @@
 	const bsintersect	: (a : bitset#, b : bitset# -> void)
 	const bsunion	: (a : bitset#, b : bitset# -> void)
 	const bseq	: (a : bitset#, b : bitset# -> bool)
-	const bsissub	: (a : bitset#, b : bitset# -> bool)
+	const bsissubset	: (a : bitset#, b : bitset# -> bool)
 
 	const bsclear	: (bs : bitset# -> bitset#)
 ;;