Skip to content

Commit d839a3f

Browse files
committed
Merge branch 'min-int'
2 parents 01ac716 + c13ca99 commit d839a3f

6 files changed

Lines changed: 8 additions & 22 deletions

File tree

documentation/docs/versions/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ A few things remain before 1.0:
2323

2424
### `v0.20251130`
2525

26+
Add a `MIN_INTEGER` global.
27+
2628
Add a `MAX_INTEGER` global, and a `pow` function.
2729

2830
Support `-2^63` as a literal value.

jnc/emitter.jn

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ char* TMPL_MAIN = " _main:\n bl __j_main\n
2424
char* WIDTH_BYTE = ".byte";
2525
char* WIDTH_QUAD = ".quad";
2626
char* TMPL_GLOBAL_NUM = " .data\n __j_%s: %s %i\n .text\n";
27-
# todo: this is silly - fix printf?!
28-
char* TMPL_GLOBAL_MIN_INTEGER = " .data\n __j_%s: %s 0x8000000000000000\n .text ; %i\n";
2927
char* TMPL_GLOBAL_CHAR = " .data\n __j_%s: %s '%c'\n .text\n";
3028
char* TMPL_GLOBAL_STRING = " .data\n __j_%s: .asciz %c%s%c\n .text\n";
3129

@@ -103,9 +101,7 @@ char* TMPL_BIN_COMPARE = " cmp x0, x1\n b.%s expr_
103101
char* TMPL_VALUE_STRING = " .data\n _j_str_%i: .asciz %c%s%c\n .text\n adrp x0, _j_str_%i@PAGE\n add x0, x0, _j_str_%i@PAGEOFF\n";
104102
char* TMPL_VALUE_INT = " mov x0, #%i\n";
105103
char* TMPL_VALUE_Xi_INT = " mov x%i, #%i\n";
106-
char* TMPL_VALUE_INT_LARGE = " .data\n _j_int_%i: .quad %x ; %i\n .text\n adrp x0, _j_int_%i@PAGE\n add x0, x0, _j_int_%i@PAGEOFF\n ldr x0, [x0]\n";
107-
# todo: this is silly - fix printf?!
108-
char* TMPL_VALUE_MIN_INTEGER = " .data\n _j_int_%i: .quad 0x8000000000000000 ; %x / %i\n .text\n adrp x0, _j_int_%i@PAGE\n add x0, x0, _j_int_%i@PAGEOFF\n ldr x0, [x0]\n";
104+
char* TMPL_VALUE_INT_LARGE = " .data\n _j_int_%i: .quad %x ; %i\n .text\n adrp x0, _j_int_%i@PAGE\n add x0, x0, _j_int_%i@PAGEOFF\n ldr x0, [x0]\n";
109105
char* TMPL_VALUE_OF_LOCAL = " ldr x0, [fp, -%x]\n";
110106

111107
# "add-a-negative" so it matches the addressing offsets
@@ -267,17 +263,14 @@ fn decl_global(void* self, Token* nameT, void* expr, Symbol* symbol) {
267263
} else {
268264
width = WIDTH_QUAD;
269265
}
270-
void val = Emitter_eval_const(self, expr);
271266
char* tmpl;
272267
if val_type == T_CHAR {
273268
tmpl = TMPL_GLOBAL_CHAR;
274-
} else if (val & 0x7fffffffffffffff) == 0 && val != 0 {
275-
# todo: it's MIN_INTEGER, which printf can't handle - like literals
276-
tmpl = TMPL_GLOBAL_MIN_INTEGER;
277269
} else {
278270
tmpl = TMPL_GLOBAL_NUM;
279271
}
280-
printf(tmpl, name, width, val);
272+
expr = Emitter_eval_const(self, expr);
273+
printf(tmpl, name, width, expr);
281274
}
282275

283276
pub fn Emitter_do_fn_intro(void* self, void* nameT, int lbytes, void* args) {
@@ -857,10 +850,6 @@ fn Emitter_do_value_integer(void* self, int i) {
857850
fn Emitter_do_value_integer_large(void* self, int i) {
858851
int seq = Emitter_seqnum(self);
859852
char* tmpl = TMPL_VALUE_INT_LARGE;
860-
if (i & 0x7fffffffffffffff) == 0 && i != 0 {
861-
# todo: it's MIN_INTEGER, which printf can't handle - like globals
862-
tmpl = TMPL_VALUE_MIN_INTEGER;
863-
}
864853
printf(tmpl, seq, i, i, seq, seq);
865854
}
866855

jnc/tests/literals.jn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# a MIN_INTEGER by any other name...
12
int ITTY_BITTY = 0x8000000000000000;
23

34
pub fn main() {

jstdlib/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ OBJECTS = \
1414
$(LIB)/io.jn.o \
1515
$(LIB)/io.o \
1616
$(LIB)/math.jn.o \
17-
$(LIB)/math.o \
1817
$(LIB)/string.jn.o \
1918
$(LIB)/sys.jn.o \
2019
$(LIB)/sys.o \

jstdlib/math.jn

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
# Various mathematical utilities. Johann only speaks integers, so it's pretty
22
# limited.
33

4-
# The maximum representable integer: `2^63 - 1`. A matching `MIN_INTEGER`
5-
# constant _is_ present, but you have to declare (not define) it yourself, as
6-
# `jnc` can't yet emit that value.
4+
# The maximum representable integer: `2^63 - 1`.
75
pub int MAX_INTEGER = 0x7fffffffffffffff;
86

97
# The minimum representable integer: `-2^63`.
10-
pub int MIN_INTEGER; # todo: move to math.jn
8+
pub int MIN_INTEGER = 0x8000000000000000;
119

1210
# I return the absolute value of the passed `int`.
1311
pub fn abs(int i) {

jstdlib/math.s

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)