aboutsummaryrefslogtreecommitdiff
path: root/src/compile
diff options
context:
space:
mode:
Diffstat (limited to 'src/compile')
-rw-r--r--src/compile/integers.c15
-rw-r--r--src/compile/loops.c8
-rw-r--r--src/compile/statements.c4
3 files changed, 20 insertions, 7 deletions
diff --git a/src/compile/integers.c b/src/compile/integers.c
index 5f99afbd..0e89f3dd 100644
--- a/src/compile/integers.c
+++ b/src/compile/integers.c
@@ -7,9 +7,9 @@
#include "../stdlib/datatypes.h"
#include "../stdlib/integers.h"
#include "../stdlib/text.h"
-#include "../util.h"
#include "../typecheck.h"
#include "../types.h"
+#include "../util.h"
#include "compilation.h"
public
@@ -35,7 +35,11 @@ Text_t compile_int_to_type(env_t *env, ast_t *ast, type_t *target) {
if (int_val.small == 0) code_err(ast, "Failed to parse this integer");
mpz_t i;
- mpz_init_set_int(i, int_val);
+ if likely (int_val.small & 1L) {
+ mpz_init_set_si(i, int_val.small >> 2L);
+ } else {
+ mpz_init_set(i, int_val.big);
+ }
char *c_literal;
if (strncmp(literal, "0x", 2) == 0 || strncmp(literal, "0X", 2) == 0 || strncmp(literal, "0b", 2) == 0) {
@@ -86,7 +90,12 @@ Text_t compile_int(ast_t *ast) {
OptionalInt_t int_val = Int$from_str(str);
if (int_val.small == 0) code_err(ast, "Failed to parse this integer");
mpz_t i;
- mpz_init_set_int(i, int_val);
+ if likely (int_val.small & 1L) {
+ mpz_init_set_si(i, int_val.small >> 2L);
+ } else {
+ mpz_init_set(i, int_val.big);
+ }
+
if (mpz_cmpabs_ui(i, BIGGEST_SMALL_INT) <= 0) {
return Texts("I_small(", str, ")");
} else if (mpz_cmp_si(i, INT64_MAX) <= 0 && mpz_cmp_si(i, INT64_MIN) >= 0) {
diff --git a/src/compile/loops.c b/src/compile/loops.c
index 3ccf0416..d818bbe4 100644
--- a/src/compile/loops.c
+++ b/src/compile/loops.c
@@ -8,8 +8,8 @@
#include "../stdlib/datatypes.h"
#include "../stdlib/integers.h"
#include "../stdlib/text.h"
-#include "../util.h"
#include "../typecheck.h"
+#include "../util.h"
#include "compilation.h"
public
@@ -236,7 +236,11 @@ Text_t compile_for_loop(env_t *env, ast_t *ast) {
Int_t int_val = Int$from_str(str);
if (int_val.small == 0) code_err(for_->iter, "Failed to parse this integer");
mpz_t i;
- mpz_init_set_int(i, int_val);
+ if likely (int_val.small & 1L) {
+ mpz_init_set_si(i, int_val.small >> 2L);
+ } else {
+ mpz_init_set(i, int_val.big);
+ }
if (mpz_cmpabs_ui(i, BIGGEST_SMALL_INT) <= 0) n = Text$from_str(mpz_get_str(NULL, 10, i));
else goto big_n;
diff --git a/src/compile/statements.c b/src/compile/statements.c
index 7a2f1947..e1b20021 100644
--- a/src/compile/statements.c
+++ b/src/compile/statements.c
@@ -7,13 +7,13 @@
#include "../environment.h"
#include "../modules.h"
#include "../naming.h"
+#include "../print.h"
#include "../stdlib/datatypes.h"
#include "../stdlib/paths.h"
-#include "../stdlib/print.h"
#include "../stdlib/tables.h"
#include "../stdlib/text.h"
-#include "../util.h"
#include "../typecheck.h"
+#include "../util.h"
#include "compilation.h"
typedef ast_t *(*comprehension_body_t)(ast_t *, ast_t *);