summaryrefslogtreecommitdiff
path: root/unix
diff options
context:
space:
mode:
Diffstat (limited to 'unix')
-rw-r--r--unix/Makefile57
-rw-r--r--unix/gccollect.c12
-rw-r--r--unix/main.c2
-rw-r--r--unix/modos.c6
-rw-r--r--unix/modtime.c52
-rw-r--r--unix/mpconfigport.h1
-rw-r--r--unix/mphalport.h3
l---------unix/scripts/upip.py1
l---------unix/scripts/upip_utarfile.py1
9 files changed, 38 insertions, 97 deletions
diff --git a/unix/Makefile b/unix/Makefile
index 53ff4cb48..5e212ff70 100644
--- a/unix/Makefile
+++ b/unix/Makefile
@@ -1,6 +1,8 @@
-include mpconfigport.mk
include ../py/mkenv.mk
+FROZEN_DIR = scripts
+
# define main target
PROG = micropython
@@ -58,10 +60,14 @@ endif
# On OSX, 'gcc' is a symlink to clang unless a real gcc is installed.
# The unix port of micropython on OSX must be compiled with clang,
-# while cross-compile ports require gcc, so we test here for OSX and
+# while cross-compile ports require gcc, so we test here for OSX and
# if necessary override the value of 'CC' set in py/mkenv.mk
ifeq ($(UNAME_S),Darwin)
+ifeq ($(MICROPY_FORCE_32BIT),1)
+CC = clang -m32
+else
CC = clang
+endif
# Use clang syntax for map file
LDFLAGS_ARCH = -Wl,-map,$@.map -Wl,-dead_strip
else
@@ -144,17 +150,6 @@ SRC_C = \
fatfs_port.c \
$(SRC_MOD)
-# Include builtin package manager in the standard build (and coverage)
-ifeq ($(PROG),micropython)
-SRC_C += $(BUILD)/_frozen_upip.c
-else ifeq ($(PROG),micropython_coverage)
-SRC_C += $(BUILD)/_frozen_upip.c
-else ifeq ($(PROG), micropython_nanbox)
-SRC_C += $(BUILD)/_frozen_upip.c
-else ifeq ($(PROG), micropython_freedos)
-SRC_C += $(BUILD)/_frozen_upip.c
-endif
-
LIB_SRC_C = $(addprefix lib/,\
$(LIB_SRC_C_EXTRA) \
timeutils/timeutils.c \
@@ -180,26 +175,10 @@ SRC_QSTR_AUTO_DEPS +=
ifneq ($(FROZEN_MPY_DIR),)
# To use frozen bytecode, put your .py files in a subdirectory (eg frozen/) and
# then invoke make with FROZEN_MPY_DIR=frozen (be sure to build from scratch).
-MPY_CROSS = ../mpy-cross/mpy-cross
-MPY_TOOL = ../tools/mpy-tool.py
-FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR) -type f -name '*.py')
-FROZEN_MPY_MPY_FILES := $(addprefix $(BUILD)/,$(FROZEN_MPY_PY_FILES:.py=.mpy))
CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool
CFLAGS += -DMICROPY_MODULE_FROZEN_MPY
CFLAGS += -DMICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE=0 # not supported
CFLAGS += -DMPZ_DIG_SIZE=16 # force 16 bits to work on both 32 and 64 bit archs
-OBJ += $(BUILD)/$(BUILD)/frozen_mpy.o
-
-# to build .mpy files from .py files
-$(BUILD)/$(FROZEN_MPY_DIR)/%.mpy: $(FROZEN_MPY_DIR)/%.py
- @$(ECHO) "MPY $<"
- $(Q)$(MKDIR) -p $(dir $@)
- $(Q)$(MPY_CROSS) -o $@ -s $(^:$(FROZEN_MPY_DIR)/%=%) $^
-
-# to build frozen_mpy.c from all .mpy files
-$(BUILD)/frozen_mpy.c: $(FROZEN_MPY_MPY_FILES) $(BUILD)/genhdr/qstrdefs.generated.h
- @$(ECHO) "Creating $@"
- $(Q)$(PYTHON) $(MPY_TOOL) -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h $(FROZEN_MPY_MPY_FILES) > $@
endif
@@ -215,18 +194,14 @@ test: $(PROG) ../tests/run-tests
TARGET = micropython
PREFIX = $(DESTDIR)/usr/local
BINDIR = $(PREFIX)/bin
-PIPSRC = ../tools/pip-micropython
-PIPTARGET = pip-micropython
install: micropython
install -d $(BINDIR)
install $(TARGET) $(BINDIR)/$(TARGET)
- install $(PIPSRC) $(BINDIR)/$(PIPTARGET)
# uninstall micropython
uninstall:
-rm $(BINDIR)/$(TARGET)
- -rm $(BINDIR)/$(PIPTARGET)
# build synthetically fast interpreter for benchmarking
fast:
@@ -235,7 +210,7 @@ fast:
# build a minimal interpreter
minimal:
$(MAKE) COPT="-Os -DNDEBUG" CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_minimal.h>"' \
- BUILD=build-minimal PROG=micropython_minimal \
+ BUILD=build-minimal PROG=micropython_minimal FROZEN_DIR= \
MICROPY_PY_BTREE=0 MICROPY_PY_FFI=0 MICROPY_PY_SOCKET=0 MICROPY_PY_THREAD=0 \
MICROPY_PY_TERMIOS=0 MICROPY_PY_USSL=0 \
MICROPY_USE_READLINE=0 MICROPY_FATFS=0
@@ -272,22 +247,6 @@ coverage_test: coverage
gcov -o build-coverage/py ../py/*.c
gcov -o build-coverage/extmod ../extmod/*.c
-$(BUILD)/_frozen_upip.c: $(BUILD)/frozen_upip/upip.py
- $(MAKE_FROZEN) $(dir $^) > $@
-
-# Select latest upip version available
-UPIP_TARBALL := $(shell ls -1 -v ../tools/micropython-upip-*.tar.gz | tail -n1)
-
-$(BUILD)/frozen_upip/upip.py: $(UPIP_TARBALL)
- $(ECHO) "MISC Preparing upip as frozen module"
- $(Q)mkdir -p $(BUILD)
- $(Q)rm -rf $(BUILD)/micropython-upip-*
- $(Q)tar -C $(BUILD) -xz -f $^
- $(Q)rm -rf $(dir $@)
- $(Q)mkdir -p $(dir $@)
- $(Q)cp $(BUILD)/micropython-upip-*/upip*.py $(dir $@)
-
-
# Value of configure's --host= option (required for cross-compilation).
# Deduce it from CROSS_COMPILE by default, but can be overriden.
ifneq ($(CROSS_COMPILE),)
diff --git a/unix/gccollect.c b/unix/gccollect.c
index 397c4ffe1..4ec8c2bf5 100644
--- a/unix/gccollect.c
+++ b/unix/gccollect.c
@@ -80,6 +80,18 @@ STATIC void gc_helper_get_regs(regs_t arr) {
register long esi asm ("esi");
register long edi asm ("edi");
register long ebp asm ("ebp");
+#ifdef __clang__
+ // TODO:
+ // This is dirty workaround for Clang. It tries to get around
+ // uncompliant (wrt to GCC) behavior of handling register variables.
+ // Application of this patch here is random, and done only to unbreak
+ // MacOS build. Better, cross-arch ways to deal with Clang issues should
+ // be found.
+ asm("" : "=r"(ebx));
+ asm("" : "=r"(esi));
+ asm("" : "=r"(edi));
+ asm("" : "=r"(ebp));
+#endif
arr[0] = ebx;
arr[1] = esi;
arr[2] = edi;
diff --git a/unix/main.c b/unix/main.c
index a1c057400..482d1944e 100644
--- a/unix/main.c
+++ b/unix/main.c
@@ -461,7 +461,7 @@ MP_NOINLINE int main_(int argc, char **argv) {
#if defined(MICROPY_UNIX_COVERAGE)
{
- MP_DECLARE_CONST_FUN_OBJ(extra_coverage_obj);
+ MP_DECLARE_CONST_FUN_OBJ_0(extra_coverage_obj);
mp_store_global(QSTR_FROM_STR_STATIC("extra_coverage"), MP_OBJ_FROM_PTR(&extra_coverage_obj));
}
#endif
diff --git a/unix/modos.c b/unix/modos.c
index 36945720d..72f5d872e 100644
--- a/unix/modos.c
+++ b/unix/modos.c
@@ -43,9 +43,9 @@
// Can't include this, as FATFS structure definition is required,
// and FatFs header defining it conflicts with POSIX.
//#include "extmod/fsusermount.h"
-MP_DECLARE_CONST_FUN_OBJ(fsuser_mount_obj);
-MP_DECLARE_CONST_FUN_OBJ(fsuser_umount_obj);
-MP_DECLARE_CONST_FUN_OBJ(fsuser_mkfs_obj);
+MP_DECLARE_CONST_FUN_OBJ_KW(fsuser_mount_obj);
+MP_DECLARE_CONST_FUN_OBJ_1(fsuser_umount_obj);
+MP_DECLARE_CONST_FUN_OBJ_KW(fsuser_mkfs_obj);
extern const mp_obj_type_t mp_fat_vfs_type;
#ifdef __ANDROID__
diff --git a/unix/modtime.c b/unix/modtime.c
index 8d6d9f4d7..85d1f5532 100644
--- a/unix/modtime.c
+++ b/unix/modtime.c
@@ -37,6 +37,7 @@
#include "py/runtime.h"
#include "py/smallint.h"
#include "py/mphal.h"
+#include "extmod/utime_mphal.h"
#ifdef _WIN32
static inline int msec_sleep_tv(struct timeval *tv) {
@@ -76,29 +77,6 @@ STATIC mp_obj_t mod_time_time(void) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_time_time_obj, mod_time_time);
-STATIC mp_obj_t mod_time_ticks_us(void) {
- struct timeval tv;
- gettimeofday(&tv, NULL);
- mp_uint_t us = tv.tv_sec * 1000000 + tv.tv_usec;
- return MP_OBJ_NEW_SMALL_INT(us & MP_SMALL_INT_POSITIVE_MASK);
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_time_ticks_us_obj, mod_time_ticks_us);
-
-STATIC mp_obj_t mod_time_ticks_ms(void) {
- struct timeval tv;
- gettimeofday(&tv, NULL);
- mp_uint_t ms = tv.tv_sec * 1000 + tv.tv_usec / 1000;
- return MP_OBJ_NEW_SMALL_INT(ms & MP_SMALL_INT_POSITIVE_MASK);
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_time_ticks_ms_obj, mod_time_ticks_ms);
-
-STATIC mp_obj_t mod_time_ticks_diff(mp_obj_t oldval, mp_obj_t newval) {
- mp_uint_t old = MP_OBJ_SMALL_INT_VALUE(oldval);
- mp_uint_t new = MP_OBJ_SMALL_INT_VALUE(newval);
- return MP_OBJ_NEW_SMALL_INT((new - old) & MP_SMALL_INT_POSITIVE_MASK);
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_time_ticks_diff_obj, mod_time_ticks_diff);
-
// Note: this is deprecated since CPy3.3, but pystone still uses it.
STATIC mp_obj_t mod_time_clock(void) {
#if MICROPY_PY_BUILTINS_FLOAT
@@ -149,22 +127,6 @@ STATIC mp_obj_t mod_time_sleep(mp_obj_t arg) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_time_sleep_obj, mod_time_sleep);
-STATIC mp_obj_t mod_time_sleep_ms(mp_obj_t arg) {
- MP_THREAD_GIL_EXIT();
- usleep(mp_obj_get_int(arg) * 1000);
- MP_THREAD_GIL_ENTER();
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_time_sleep_ms_obj, mod_time_sleep_ms);
-
-STATIC mp_obj_t mod_time_sleep_us(mp_obj_t arg) {
- MP_THREAD_GIL_EXIT();
- usleep(mp_obj_get_int(arg));
- MP_THREAD_GIL_ENTER();
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_time_sleep_us_obj, mod_time_sleep_us);
-
STATIC mp_obj_t mod_time_strftime(size_t n_args, const mp_obj_t *args) {
time_t t;
if (n_args == 1) {
@@ -185,12 +147,14 @@ STATIC const mp_rom_map_elem_t mp_module_time_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) },
{ MP_ROM_QSTR(MP_QSTR_clock), MP_ROM_PTR(&mod_time_clock_obj) },
{ MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mod_time_sleep_obj) },
- { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mod_time_sleep_ms_obj) },
- { MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mod_time_sleep_us_obj) },
+ { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) },
+ { MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) },
{ MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&mod_time_time_obj) },
- { MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mod_time_ticks_ms_obj) },
- { MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mod_time_ticks_us_obj) },
- { MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mod_time_ticks_diff_obj) },
+ { MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj) },
+ { MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj) },
+ { MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_utime_ticks_cpu_obj) },
+ { MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj) },
+ { MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj) },
{ MP_ROM_QSTR(MP_QSTR_strftime), MP_ROM_PTR(&mod_time_strftime_obj) },
};
diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h
index 56cfaa2ac..f4f8d2d20 100644
--- a/unix/mpconfigport.h
+++ b/unix/mpconfigport.h
@@ -106,6 +106,7 @@
#define MICROPY_PY_OS_STATVFS (1)
#define MICROPY_PY_UTIME (1)
+#define MICROPY_PY_UTIME_MP_HAL (1)
#define MICROPY_PY_UERRNO (1)
#define MICROPY_PY_UCTYPES (1)
#define MICROPY_PY_UZLIB (1)
diff --git a/unix/mphalport.h b/unix/mphalport.h
index e440eafd4..00e79ec17 100644
--- a/unix/mphalport.h
+++ b/unix/mphalport.h
@@ -34,8 +34,11 @@ void mp_hal_set_interrupt_char(char c);
void mp_hal_stdio_mode_raw(void);
void mp_hal_stdio_mode_orig(void);
+// TODO: POSIX et al. define usleep() as guaranteedly capable only of 1s sleep:
+// "The useconds argument shall be less than one million."
static inline void mp_hal_delay_ms(mp_uint_t ms) { usleep((ms) * 1000); }
static inline void mp_hal_delay_us(mp_uint_t us) { usleep(us); }
+#define mp_hal_ticks_cpu() 0
#define RAISE_ERRNO(err_flag, error_val) \
{ if (err_flag == -1) \
diff --git a/unix/scripts/upip.py b/unix/scripts/upip.py
new file mode 120000
index 000000000..20d52a4ab
--- /dev/null
+++ b/unix/scripts/upip.py
@@ -0,0 +1 @@
+../../tools/upip.py \ No newline at end of file
diff --git a/unix/scripts/upip_utarfile.py b/unix/scripts/upip_utarfile.py
new file mode 120000
index 000000000..149886291
--- /dev/null
+++ b/unix/scripts/upip_utarfile.py
@@ -0,0 +1 @@
+../../tools/upip_utarfile.py \ No newline at end of file