ref: 4b77bda908dec8620abde1e452a1f2bac29f1252
parent: 7ea39f801622858865e2fb06768a9f44f81b5bf8
author: Ori Bernstein <[email protected]>
date: Wed Aug 7 13:50:54 EDT 2013
Parse negative numbers correctly. We seem to munge them when returning. Oops.
--- a/libstd/intparse.myr
+++ b/libstd/intparse.myr
@@ -2,6 +2,7 @@
use "strcmp.use"
use "types.use"
use "utf.use"
+use "fmt.use"
pkg std =
generic intparsebase : (s : byte[:], base : int -> @a::(tcint,tcnum,tctest))
@@ -9,15 +10,16 @@
/* FIXME: fix hidden exports */
generic charval
+ generic doparse
;;
generic intparse = {s
var isneg
- isneg = 0
+ isneg = false
if hasprefix(s, "-")
s = s[1:]
- isneg = 1
+ isneg = true
;;
if hasprefix(s, "0x")
@@ -27,7 +29,7 @@
elif hasprefix(s, "0b")
-> doparse(s[2:], isneg, 2)
else
- -> doparse(s[2:], isneg, 10)
+ -> doparse(s, isneg, 10)
;;
}
@@ -34,10 +36,10 @@
generic intparsebase = {s, base -> @a::(tcint,tcnum,tctest)
var isneg
- isneg = 0
+ isneg = false
if hasprefix(s, "-")
s = s[1:]
- isneg = 1
+ isneg = true
;;
-> doparse(s, isneg, base)
@@ -47,7 +49,6 @@
var v : @a::(tcint,tcnum,tctest)
var c
- assert(base <= 36, "Base for parsing values is too big")
v = 0
while s.len != 0
(c, s) = striter(s)
@@ -56,9 +57,9 @@
;;
if isneg
- -> v
- else
-> -v
+ else
+ -> v
;;
}
@@ -74,7 +75,7 @@
;;
if v < 0 || v > (base castto(@a::(tcint,tcnum,tctest)))
- die("Character out of range for base when parsing integer")
+ fatal(1, "Character %c out of range", c)
;;
-> v
}
--- a/libstd/strcmp.myr
+++ b/libstd/strcmp.myr
@@ -1,5 +1,6 @@
use "extremum.use"
use "types.use"
+use "fmt.use"
pkg std =
type comparison
@@ -48,8 +49,9 @@
}
const hasprefix = {s, pre
- if strncmp(s, pre, pre.len) == `Equal
- -> true
+ match strncmp(s, pre, pre.len)
+ `Equal: -> true;;
+ _: -> false;;
;;
}