Skip to content

Commit d8b08cf

Browse files
committed
unix: Add option to build 64-bit NaN-boxing interpreter.
Build using: make nanbox
1 parent ff133cd commit d8b08cf

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

unix/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ ifeq ($(PROG),micropython)
126126
SRC_C += $(BUILD)/_frozen_upip.c
127127
else ifeq ($(PROG),micropython_coverage)
128128
SRC_C += $(BUILD)/_frozen_upip.c
129+
else ifeq ($(PROG), micropython_nanbox)
130+
SRC_C += $(BUILD)/_frozen_upip.c
129131
else ifeq ($(PROG), micropython_freedos)
130132
SRC_C += $(BUILD)/_frozen_upip.c
131133
endif
@@ -171,6 +173,15 @@ fast:
171173
minimal:
172174
$(MAKE) COPT="-Os -DNDEBUG" CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_minimal.h>"' BUILD=build-minimal PROG=micropython_minimal MICROPY_PY_TIME=0 MICROPY_PY_TERMIOS=0 MICROPY_PY_SOCKET=0 MICROPY_PY_FFI=0 MICROPY_USE_READLINE=0
173175

176+
# build interpreter with nan-boxing as object model
177+
nanbox:
178+
$(MAKE) \
179+
CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_nanbox.h>"' \
180+
BUILD=build-nanbox \
181+
PROG=micropython_nanbox \
182+
MICROPY_FORCE_32BIT=1 \
183+
MICROPY_PY_FFI=0
184+
174185
freedos:
175186
$(MAKE) \
176187
CC=i586-pc-msdosdjgpp-gcc \

unix/mpconfigport.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ extern const struct _mp_obj_module_t mp_module_jni;
182182

183183
// type definitions for the specific machine
184184

185+
// assume that if we already defined the obj repr then we also defined types
186+
#ifndef MICROPY_OBJ_REPR
185187
#ifdef __LP64__
186188
typedef long mp_int_t; // must be pointer size
187189
typedef unsigned long mp_uint_t; // must be pointer size
@@ -191,6 +193,7 @@ typedef unsigned long mp_uint_t; // must be pointer size
191193
typedef int mp_int_t; // must be pointer size
192194
typedef unsigned int mp_uint_t; // must be pointer size
193195
#endif
196+
#endif
194197

195198
#define BYTES_PER_WORD sizeof(mp_int_t)
196199

unix/mpconfigport_nanbox.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2016 Damien P. George
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
// select nan-boxing object model
28+
#define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_D)
29+
30+
// native emitters don't work with nan-boxing
31+
#define MICROPY_EMIT_X86 (0)
32+
#define MICROPY_EMIT_X64 (0)
33+
#define MICROPY_EMIT_THUMB (0)
34+
#define MICROPY_EMIT_ARM (0)
35+
36+
#include <stdint.h>
37+
38+
typedef int64_t mp_int_t;
39+
typedef uint64_t mp_uint_t;
40+
#define UINT_FMT "%llu"
41+
#define INT_FMT "%lld"
42+
43+
#include <mpconfigport.h>

0 commit comments

Comments
 (0)