Skip to content

Commit ee82fa1

Browse files
author
Nathan Ramella
committed
Changes to get the unix code compiling on OSX
* %llu vs %lu is an OSX vs Linux formatting issue * redefinition of structs is gnu11 * casting (machine_uint_t*) when necessary to avoid array warnings Haven't changed the nlrx86.s assembly, which is why I'm pushing this as a branch rather than a pull req to master
1 parent 5bbc3cd commit ee82fa1

File tree

5 files changed

+33
-27
lines changed

5 files changed

+33
-27
lines changed

py/asmx64.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,13 @@ struct _asm_x64_t {
8989
void *alloc_mem(uint req_size, uint *alloc_size, bool is_exec) {
9090
req_size = (req_size + 0xfff) & (~0xfff);
9191
int prot = PROT_READ | PROT_WRITE | (is_exec ? PROT_EXEC : 0);
92+
#ifdef __APPLE__
93+
void *ptr = mmap(NULL, req_size, prot, MAP_PRIVATE | MAP_ANON, -1, 0);
94+
#else
9295
void *ptr = mmap(NULL, req_size, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
96+
#endif
97+
98+
9399
if (ptr == MAP_FAILED) {
94100
assert(0);
95101
}

py/nlrx64.s

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
.text
55

66
# uint nlr_push(rdi=nlr_buf_t *nlr)
7-
.globl nlr_push
8-
.type nlr_push, @function
9-
nlr_push:
7+
.globl _nlr_push
8+
_nlr_push:
109
movq (%rsp), %rax # load return %rip
1110
movq %rax, 16(%rdi) # store %rip into nlr_buf
1211
movq %rbp, 24(%rdi) # store %rbp into nlr_buf
@@ -21,22 +20,18 @@ nlr_push:
2120
movq %rdi, nlr_top(%rip) # stor new nlr_buf (to make linked list)
2221
xorq %rax, %rax # return 0, normal return
2322
ret # return
24-
.size nlr_push, .-nlr_push
2523

2624
# void nlr_pop()
27-
.globl nlr_pop
28-
.type nlr_pop, @function
29-
nlr_pop:
25+
.globl _nlr_pop
26+
_nlr_pop:
3027
movq nlr_top(%rip), %rax # get nlr_top into %rax
3128
movq (%rax), %rax # load prev nlr_buf
3229
movq %rax, nlr_top(%rip) # store prev nlr_buf (to unlink list)
3330
ret # return
34-
.size nlr_pop, .-nlr_pop
3531

3632
# void nlr_jump(rdi=uint val)
37-
.globl nlr_jump
38-
.type nlr_jump, @function
39-
nlr_jump:
33+
.globl _nlr_jump
34+
_nlr_jump:
4035
movq %rdi, %rax # put return value in %rax
4136
movq nlr_top(%rip), %rdi # get nlr_top into %rdi
4237
movq %rax, 8(%rdi) # store return value
@@ -54,7 +49,5 @@ nlr_jump:
5449
xorq %rax, %rax # clear return register
5550
inc %al # increase to make 1, non-local return
5651
ret # return
57-
.size nlr_jump, .-nlr_jump
5852

59-
.local nlr_top
6053
.comm nlr_top,8,8

py/showbc.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
#include <string.h>
55
#include <assert.h>
66

7+
#ifdef __LP64__
8+
#define FMT_SIZE_T "llu"
9+
#else
10+
#define FMT_SIZE_T "lu"
11+
#endif
12+
713
#include "misc.h"
814
#include "mpconfig.h"
915
#include "bc0.h"
@@ -70,7 +76,7 @@ void mp_show_byte_code(const byte *ip, int len) {
7076

7177
case MP_BC_LOAD_FAST_N:
7278
DECODE_UINT;
73-
printf("LOAD_FAST_N %lu", unum);
79+
printf("LOAD_FAST_N %"FMT_SIZE_T, unum);
7480
break;
7581

7682
case MP_BC_LOAD_NAME:
@@ -111,7 +117,7 @@ void mp_show_byte_code(const byte *ip, int len) {
111117

112118
case MP_BC_STORE_FAST_N:
113119
DECODE_UINT;
114-
printf("STORE_FAST_N %lu", unum);
120+
printf("STORE_FAST_N %"FMT_SIZE_T, unum);
115121
break;
116122

117123
case MP_BC_STORE_NAME:
@@ -245,22 +251,22 @@ void mp_show_byte_code(const byte *ip, int len) {
245251

246252
case MP_BC_BINARY_OP:
247253
unum = *ip++;
248-
printf("BINARY_OP %lu", unum);
254+
printf("BINARY_OP %"FMT_SIZE_T, unum);
249255
break;
250256

251257
case MP_BC_COMPARE_OP:
252258
unum = *ip++;
253-
printf("COMPARE_OP %lu", unum);
259+
printf("COMPARE_OP %"FMT_SIZE_T, unum);
254260
break;
255261

256262
case MP_BC_BUILD_TUPLE:
257263
DECODE_UINT;
258-
printf("BUILD_TUPLE %lu", unum);
264+
printf("BUILD_TUPLE %"FMT_SIZE_T, unum);
259265
break;
260266

261267
case MP_BC_BUILD_LIST:
262268
DECODE_UINT;
263-
printf("BUILD_LIST %lu", unum);
269+
printf("BUILD_LIST %"FMT_SIZE_T, unum);
264270
break;
265271

266272
/*
@@ -305,22 +311,22 @@ void mp_show_byte_code(const byte *ip, int len) {
305311

306312
case MP_BC_UNPACK_SEQUENCE:
307313
DECODE_UINT;
308-
printf("UNPACK_SEQUENCE %lu", unum);
314+
printf("UNPACK_SEQUENCE %"FMT_SIZE_T, unum);
309315
break;
310316

311317
case MP_BC_MAKE_FUNCTION:
312318
DECODE_UINT;
313-
printf("MAKE_FUNCTION %lu", unum);
319+
printf("MAKE_FUNCTION %"FMT_SIZE_T, unum);
314320
break;
315321

316322
case MP_BC_CALL_FUNCTION:
317323
DECODE_UINT;
318-
printf("CALL_FUNCTION n=%lu nkw=%lu", unum & 0xff, (unum >> 8) & 0xff);
324+
printf("CALL_FUNCTION n=%"FMT_SIZE_T"nkw=%"FMT_SIZE_T, unum & 0xff, (unum >> 8) & 0xff);
319325
break;
320326

321327
case MP_BC_CALL_METHOD:
322328
DECODE_UINT;
323-
printf("CALL_METHOD n=%lu nkw=%lu", unum & 0xff, (unum >> 8) & 0xff);
329+
printf("CALL_METHOD n=%"FMT_SIZE_T" nkw=%"FMT_SIZE_T, unum & 0xff, (unum >> 8) & 0xff);
324330
break;
325331

326332
case MP_BC_RETURN_VALUE:

py/vm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ bool mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t **
6363

6464
// on the exception stack we store (ip, sp) for each block
6565
machine_uint_t exc_stack[8];
66-
machine_uint_t *volatile exc_sp = &exc_stack[-1]; // stack grows up, exc_sp points to top of stack
66+
machine_uint_t *volatile exc_sp = (machine_uint_t*) &exc_stack[-1]; // stack grows up, exc_sp points to top of stack
6767

6868
// outer exception handling loop
6969
for (;;) {
@@ -431,7 +431,7 @@ bool mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t **
431431
case MP_BC_RETURN_VALUE:
432432
nlr_pop();
433433
*sp_in_out = sp;
434-
assert(exc_sp == &exc_stack[-1]);
434+
assert(exc_sp == (machine_uint_t*) &exc_stack[-1]);
435435
return false;
436436

437437
case MP_BC_YIELD_VALUE:

unix/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PYSRC=../py
22
BUILD=build
33

44
CC = gcc
5-
CFLAGS = -I. -I$(PYSRC) -Wall -Werror -ansi -std=gnu99 -Os #-DNDEBUG
5+
CFLAGS = -I. -I$(PYSRC) -Wall -Werror -ansi -std=gnu11 -Os #-DNDEBUG
66
LDFLAGS = -lm
77

88
SRC_C = \
@@ -93,4 +93,5 @@ $(BUILD)/emitcpy.o: $(PYSRC)/emit.h
9393
$(BUILD)/emitbc.o: $(PYSRC)/emit.h
9494

9595
clean:
96-
/bin/rm -r $(BUILD)
96+
/bin/rm -rf ./$(BUILD)
97+
/bin/rm py

0 commit comments

Comments
 (0)