Compare commits
1 Commits
Author | SHA1 | Date |
---|---|---|
Nathan Ramella | ee82fa1cf5 |
|
@ -89,7 +89,13 @@ struct _asm_x64_t {
|
|||
void *alloc_mem(uint req_size, uint *alloc_size, bool is_exec) {
|
||||
req_size = (req_size + 0xfff) & (~0xfff);
|
||||
int prot = PROT_READ | PROT_WRITE | (is_exec ? PROT_EXEC : 0);
|
||||
#ifdef __APPLE__
|
||||
void *ptr = mmap(NULL, req_size, prot, MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
#else
|
||||
void *ptr = mmap(NULL, req_size, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
#endif
|
||||
|
||||
|
||||
if (ptr == MAP_FAILED) {
|
||||
assert(0);
|
||||
}
|
||||
|
|
19
py/nlrx64.s
19
py/nlrx64.s
|
@ -4,9 +4,8 @@
|
|||
.text
|
||||
|
||||
# uint nlr_push(rdi=nlr_buf_t *nlr)
|
||||
.globl nlr_push
|
||||
.type nlr_push, @function
|
||||
nlr_push:
|
||||
.globl _nlr_push
|
||||
_nlr_push:
|
||||
movq (%rsp), %rax # load return %rip
|
||||
movq %rax, 16(%rdi) # store %rip into nlr_buf
|
||||
movq %rbp, 24(%rdi) # store %rbp into nlr_buf
|
||||
|
@ -21,22 +20,18 @@ nlr_push:
|
|||
movq %rdi, nlr_top(%rip) # stor new nlr_buf (to make linked list)
|
||||
xorq %rax, %rax # return 0, normal return
|
||||
ret # return
|
||||
.size nlr_push, .-nlr_push
|
||||
|
||||
# void nlr_pop()
|
||||
.globl nlr_pop
|
||||
.type nlr_pop, @function
|
||||
nlr_pop:
|
||||
.globl _nlr_pop
|
||||
_nlr_pop:
|
||||
movq nlr_top(%rip), %rax # get nlr_top into %rax
|
||||
movq (%rax), %rax # load prev nlr_buf
|
||||
movq %rax, nlr_top(%rip) # store prev nlr_buf (to unlink list)
|
||||
ret # return
|
||||
.size nlr_pop, .-nlr_pop
|
||||
|
||||
# void nlr_jump(rdi=uint val)
|
||||
.globl nlr_jump
|
||||
.type nlr_jump, @function
|
||||
nlr_jump:
|
||||
.globl _nlr_jump
|
||||
_nlr_jump:
|
||||
movq %rdi, %rax # put return value in %rax
|
||||
movq nlr_top(%rip), %rdi # get nlr_top into %rdi
|
||||
movq %rax, 8(%rdi) # store return value
|
||||
|
@ -54,7 +49,5 @@ nlr_jump:
|
|||
xorq %rax, %rax # clear return register
|
||||
inc %al # increase to make 1, non-local return
|
||||
ret # return
|
||||
.size nlr_jump, .-nlr_jump
|
||||
|
||||
.local nlr_top
|
||||
.comm nlr_top,8,8
|
||||
|
|
26
py/showbc.c
26
py/showbc.c
|
@ -4,6 +4,12 @@
|
|||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef __LP64__
|
||||
#define FMT_SIZE_T "llu"
|
||||
#else
|
||||
#define FMT_SIZE_T "lu"
|
||||
#endif
|
||||
|
||||
#include "misc.h"
|
||||
#include "mpconfig.h"
|
||||
#include "bc0.h"
|
||||
|
@ -70,7 +76,7 @@ void mp_show_byte_code(const byte *ip, int len) {
|
|||
|
||||
case MP_BC_LOAD_FAST_N:
|
||||
DECODE_UINT;
|
||||
printf("LOAD_FAST_N %lu", unum);
|
||||
printf("LOAD_FAST_N %"FMT_SIZE_T, unum);
|
||||
break;
|
||||
|
||||
case MP_BC_LOAD_NAME:
|
||||
|
@ -111,7 +117,7 @@ void mp_show_byte_code(const byte *ip, int len) {
|
|||
|
||||
case MP_BC_STORE_FAST_N:
|
||||
DECODE_UINT;
|
||||
printf("STORE_FAST_N %lu", unum);
|
||||
printf("STORE_FAST_N %"FMT_SIZE_T, unum);
|
||||
break;
|
||||
|
||||
case MP_BC_STORE_NAME:
|
||||
|
@ -245,22 +251,22 @@ void mp_show_byte_code(const byte *ip, int len) {
|
|||
|
||||
case MP_BC_BINARY_OP:
|
||||
unum = *ip++;
|
||||
printf("BINARY_OP %lu", unum);
|
||||
printf("BINARY_OP %"FMT_SIZE_T, unum);
|
||||
break;
|
||||
|
||||
case MP_BC_COMPARE_OP:
|
||||
unum = *ip++;
|
||||
printf("COMPARE_OP %lu", unum);
|
||||
printf("COMPARE_OP %"FMT_SIZE_T, unum);
|
||||
break;
|
||||
|
||||
case MP_BC_BUILD_TUPLE:
|
||||
DECODE_UINT;
|
||||
printf("BUILD_TUPLE %lu", unum);
|
||||
printf("BUILD_TUPLE %"FMT_SIZE_T, unum);
|
||||
break;
|
||||
|
||||
case MP_BC_BUILD_LIST:
|
||||
DECODE_UINT;
|
||||
printf("BUILD_LIST %lu", unum);
|
||||
printf("BUILD_LIST %"FMT_SIZE_T, unum);
|
||||
break;
|
||||
|
||||
/*
|
||||
|
@ -305,22 +311,22 @@ void mp_show_byte_code(const byte *ip, int len) {
|
|||
|
||||
case MP_BC_UNPACK_SEQUENCE:
|
||||
DECODE_UINT;
|
||||
printf("UNPACK_SEQUENCE %lu", unum);
|
||||
printf("UNPACK_SEQUENCE %"FMT_SIZE_T, unum);
|
||||
break;
|
||||
|
||||
case MP_BC_MAKE_FUNCTION:
|
||||
DECODE_UINT;
|
||||
printf("MAKE_FUNCTION %lu", unum);
|
||||
printf("MAKE_FUNCTION %"FMT_SIZE_T, unum);
|
||||
break;
|
||||
|
||||
case MP_BC_CALL_FUNCTION:
|
||||
DECODE_UINT;
|
||||
printf("CALL_FUNCTION n=%lu nkw=%lu", unum & 0xff, (unum >> 8) & 0xff);
|
||||
printf("CALL_FUNCTION n=%"FMT_SIZE_T"nkw=%"FMT_SIZE_T, unum & 0xff, (unum >> 8) & 0xff);
|
||||
break;
|
||||
|
||||
case MP_BC_CALL_METHOD:
|
||||
DECODE_UINT;
|
||||
printf("CALL_METHOD n=%lu nkw=%lu", unum & 0xff, (unum >> 8) & 0xff);
|
||||
printf("CALL_METHOD n=%"FMT_SIZE_T" nkw=%"FMT_SIZE_T, unum & 0xff, (unum >> 8) & 0xff);
|
||||
break;
|
||||
|
||||
case MP_BC_RETURN_VALUE:
|
||||
|
|
4
py/vm.c
4
py/vm.c
|
@ -63,7 +63,7 @@ bool mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t **
|
|||
|
||||
// on the exception stack we store (ip, sp) for each block
|
||||
machine_uint_t exc_stack[8];
|
||||
machine_uint_t *volatile exc_sp = &exc_stack[-1]; // stack grows up, exc_sp points to top of stack
|
||||
machine_uint_t *volatile exc_sp = (machine_uint_t*) &exc_stack[-1]; // stack grows up, exc_sp points to top of stack
|
||||
|
||||
// outer exception handling loop
|
||||
for (;;) {
|
||||
|
@ -431,7 +431,7 @@ bool mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t **
|
|||
case MP_BC_RETURN_VALUE:
|
||||
nlr_pop();
|
||||
*sp_in_out = sp;
|
||||
assert(exc_sp == &exc_stack[-1]);
|
||||
assert(exc_sp == (machine_uint_t*) &exc_stack[-1]);
|
||||
return false;
|
||||
|
||||
case MP_BC_YIELD_VALUE:
|
||||
|
|
|
@ -2,7 +2,7 @@ PYSRC=../py
|
|||
BUILD=build
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -I. -I$(PYSRC) -Wall -Werror -ansi -std=gnu99 -Os #-DNDEBUG
|
||||
CFLAGS = -I. -I$(PYSRC) -Wall -Werror -ansi -std=gnu11 -Os #-DNDEBUG
|
||||
LDFLAGS = -lm
|
||||
|
||||
SRC_C = \
|
||||
|
@ -93,4 +93,5 @@ $(BUILD)/emitcpy.o: $(PYSRC)/emit.h
|
|||
$(BUILD)/emitbc.o: $(PYSRC)/emit.h
|
||||
|
||||
clean:
|
||||
/bin/rm -r $(BUILD)
|
||||
/bin/rm -rf ./$(BUILD)
|
||||
/bin/rm py
|
||||
|
|
Loading…
Reference in New Issue