aboutsummaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-08-23 11:38:54 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-08-23 11:38:54 -0400
commitdceb9255736c69538293ee551272cda1b03a9fd3 (patch)
treefdb4e6947b80db01fa85b6de0c15670dddf83c52 /compile.c
parentad51b208b4924d04f1d6a804178a67994b4f9e59 (diff)
Bugfix for parsing ints
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/compile.c b/compile.c
index 219173b7..15045d6d 100644
--- a/compile.c
+++ b/compile.c
@@ -1314,7 +1314,7 @@ CORD compile_int_to_type(env_t *env, ast_t *ast, type_t *target)
}
int64_t target_bits = (int64_t)Match(target, IntType)->bits;
- Int_t int_val = Int$from_text(Match(ast, Int)->str);
+ Int_t int_val = Int$from_text(Match(ast, Int)->str, NULL);
mpz_t i;
mpz_init_set_int(i, int_val);
@@ -1354,7 +1354,7 @@ CORD compile_arguments(env_t *env, ast_t *call_ast, arg_t *spec_args, arg_ast_t
if (spec_arg->type->tag == IntType && call_arg->value->tag == Int) {
value = compile_int_to_type(env, call_arg->value, spec_arg->type);
} else if (spec_arg->type->tag == NumType && call_arg->value->tag == Int) {
- Int_t int_val = Int$from_text(Match(call_arg->value, Int)->str);
+ Int_t int_val = Int$from_text(Match(call_arg->value, Int)->str, NULL);
double n = Int_to_Num(int_val);
value = CORD_asprintf(Match(spec_arg->type, NumType)->bits == TYPE_NBITS64
? "N64(%.20g)" : "N32(%.10g)", n);
@@ -1382,7 +1382,7 @@ CORD compile_arguments(env_t *env, ast_t *call_ast, arg_t *spec_args, arg_ast_t
if (spec_arg->type->tag == IntType && call_arg->value->tag == Int) {
value = compile_int_to_type(env, call_arg->value, spec_arg->type);
} else if (spec_arg->type->tag == NumType && call_arg->value->tag == Int) {
- Int_t int_val = Int$from_text(Match(call_arg->value, Int)->str);
+ Int_t int_val = Int$from_text(Match(call_arg->value, Int)->str, NULL);
double n = Int_to_Num(int_val);
value = CORD_asprintf(Match(spec_arg->type, NumType)->bits == TYPE_NBITS64
? "N64(%.20g)" : "N32(%.10g)", n);
@@ -1513,7 +1513,7 @@ CORD compile(env_t *env, ast_t *ast)
}
case Int: {
const char *str = Match(ast, Int)->str;
- Int_t int_val = Int$from_text(str);
+ Int_t int_val = Int$from_text(str, NULL);
mpz_t i;
mpz_init_set_int(i, int_val);
@@ -1524,7 +1524,7 @@ CORD compile(env_t *env, ast_t *ast)
} else if (mpz_cmp_si(i, INT64_MAX) <= 0 && mpz_cmp_si(i, INT64_MIN) >= 0) {
return CORD_asprintf("Int64_to_Int(%s)", str);
} else {
- return CORD_asprintf("Int$from_text(\"%s\")", str);
+ return CORD_asprintf("Int$from_text(\"%s\", NULL)", str);
}
case IBITS64:
if ((mpz_cmp_si(i, INT64_MAX) < 0) && (mpz_cmp_si(i, INT64_MIN) > 0))
@@ -3037,7 +3037,18 @@ CORD compile_cli_arg_call(env_t *env, CORD fn_name, type_t *fn_type)
"}\n");
break;
}
- case IntType: case BigIntType: case NumType: {
+ case BigIntType: {
+ CORD type_name = type_to_cord(t);
+ code = CORD_all(code, "else if (pop_flag(argv, &i, \"", flag, "\", &flag)) {\n",
+ "if (flag == CORD_EMPTY)\n"
+ "USAGE_ERR(\"No value provided for '--", flag, "'\\n\", usage);\n"
+ "$", arg->name, " = ", type_name, "$from_text(flag, &", arg->name, "$is_set);\n"
+ "if (!", arg->name, "$is_set)\n"
+ "USAGE_ERR(\"Invalid value provided for '--", flag, "'\\n\", usage);\n",
+ "}\n");
+ break;
+ }
+ case IntType: case NumType: {
CORD type_name = type_to_cord(t);
code = CORD_all(code, "else if (pop_flag(argv, &i, \"", flag, "\", &flag)) {\n",
"if (flag == CORD_EMPTY)\n"