aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-11-15 14:33:15 -0500
committerBruce Hill <bruce@bruce-hill.com>2025-11-15 14:33:15 -0500
commit630f910563b6f27dd34a4a0496a43d32539eadcb (patch)
tree3670080722d53ff70a688cff395152e70273434e
parentfc91166ce8590e67404cde79a273d7022ec16f1c (diff)
Incremental fixes
-rw-r--r--src/compile/expressions.c16
-rw-r--r--src/stdlib/bigint.c8
-rw-r--r--src/stdlib/reals.c10
-rw-r--r--src/stdlib/text.h2
4 files changed, 18 insertions, 18 deletions
diff --git a/src/compile/expressions.c b/src/compile/expressions.c
index 28f91500..c28185ce 100644
--- a/src/compile/expressions.c
+++ b/src/compile/expressions.c
@@ -79,14 +79,14 @@ Text_t compile(env_t *env, ast_t *ast) {
case Num: {
// return Text$from_str(String(hex_double(Match(ast, Num)->n)));
Text_t original = Text$from_str(String(string_slice(ast->start, (size_t)(ast->end - ast->start))));
- Text_t roundtrip = Text$from_str(String(Match(ast, Num)->n));
- original = Text$replace(original, Text("_"), EMPTY_TEXT);
- original = Text$without_suffix(original, Text("."));
- if (Text$equal_values(original, roundtrip)) {
- return Texts("Real$from_float64(", Text$from_str(String(hex_double(Match(ast, Num)->n))), ")");
- } else {
- return Texts("Real$parse(Text(\"", original, "\"), NULL)");
- }
+ // Text_t roundtrip = Text$from_str(String(Match(ast, Num)->n));
+ // original = Text$replace(original, Text("_"), EMPTY_TEXT);
+ // original = Text$without_suffix(original, Text("."));
+ // if (Text$equal_values(original, roundtrip)) {
+ // return Texts("Real$from_float64(", Text$from_str(String(hex_double(Match(ast, Num)->n))), ")");
+ // } else {
+ return Texts("Real$parse(Text(\"", original, "\"), NULL)");
+ // }
}
case Not: {
ast_t *value = Match(ast, Not)->value;
diff --git a/src/stdlib/bigint.c b/src/stdlib/bigint.c
index 5e8986d1..41e8e6db 100644
--- a/src/stdlib/bigint.c
+++ b/src/stdlib/bigint.c
@@ -418,22 +418,22 @@ OptionalInt_t Int$parse(Text_t text, Text_t *remainder) {
const char *end = str + 2 + strspn(str + 2, "0123456789abcdefABCDEF");
if (remainder) *remainder = Text$from_str(end);
else if (*end != '\0') return NONE_INT;
- result = mpz_init_set_str(i, str + 2, 16);
+ result = mpz_init_set_str(i, String(string_slice(str + 2, (size_t)(end - (str + 2)))), 16);
} else if (strncmp(str, "0o", 2) == 0) {
const char *end = str + 2 + strspn(str + 2, "01234567");
if (remainder) *remainder = Text$from_str(end);
else if (*end != '\0') return NONE_INT;
- result = mpz_init_set_str(i, str + 2, 8);
+ result = mpz_init_set_str(i, String(string_slice(str + 2, (size_t)(end - (str + 2)))), 8);
} else if (strncmp(str, "0b", 2) == 0) {
const char *end = str + 2 + strspn(str + 2, "01");
if (remainder) *remainder = Text$from_str(end);
else if (*end != '\0') return NONE_INT;
- result = mpz_init_set_str(i, str + 2, 2);
+ result = mpz_init_set_str(i, String(string_slice(str + 2, (size_t)(end - (str + 2)))), 2);
} else {
const char *end = str + strspn(str, "0123456789");
if (remainder) *remainder = Text$from_str(end);
else if (*end != '\0') return NONE_INT;
- result = mpz_init_set_str(i, str, 10);
+ result = mpz_init_set_str(i, String(string_slice(str, (size_t)(end - str))), 10);
}
if (result != 0) {
if (remainder) *remainder = text;
diff --git a/src/stdlib/reals.c b/src/stdlib/reals.c
index 1c4be751..cfa027d1 100644
--- a/src/stdlib/reals.c
+++ b/src/stdlib/reals.c
@@ -67,13 +67,13 @@ static Int_t Real$compute_double(Real_t r, int64_t precision) {
public
OptionalReal_t Real$parse(Text_t text, Text_t *remainder) {
- Text_t decimal_onwards;
+ Text_t decimal_onwards = EMPTY_TEXT;
OptionalInt_t int_component = Int$parse(text, &decimal_onwards);
if (int_component.small == 0) int_component = I(0);
- Text_t fraction_text;
+ Text_t fraction_text = EMPTY_TEXT;
if (Text$starts_with(decimal_onwards, Text("."), &fraction_text)) {
fraction_text = Text$replace(fraction_text, Text("_"), EMPTY_TEXT);
- OptionalInt_t fraction = Int$parse(decimal_onwards, remainder);
+ OptionalInt_t fraction = Int$parse(fraction_text, remainder);
if (fraction.small == 0) return NONE_REAL;
int64_t shift = fraction_text.length;
Int_t scale = Int$power(I(10), I(shift));
@@ -106,9 +106,9 @@ double Real$as_float64(Real_t x) {
if (((orig_exp + exp_adj) & ~0x7fful) != 0) {
// overflow
if (scaled_int.d < 0.0) {
- return -INFINITY;
+ return (double)-INFINITY;
} else {
- return INFINITY;
+ return (double)INFINITY;
}
}
scaled_int.bits += exp_adj << 52;
diff --git a/src/stdlib/text.h b/src/stdlib/text.h
index 2046d667..37ed056a 100644
--- a/src/stdlib/text.h
+++ b/src/stdlib/text.h
@@ -44,7 +44,7 @@ static inline Text_t Text_from_text(Text_t t) { return t; }
int16_t: Int16$value_as_text, \
int32_t: Int32$value_as_text, \
int64_t: Int64$value_as_text, \
- double: Float64$value_as_text, \
+ double: Float64$value_as_text, \
float: Float32$value_as_text)(x)
Text_t Text$_concat(int n, Text_t items[n]);