Skip to content

Commit b9f574b

Browse files
danicamporadpgeorge
authored andcommitted
py: Automatically detect cpu architechure when building mpextern.
Also add "mp_obj_get_int" to "mp_ext_table".
1 parent e06aed4 commit b9f574b

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

py/mpextern.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ STATIC const mp_ext_table_t mp_ext_table = {
8989
.mp_store_global = mp_store_global,
9090
.mp_obj_new_list = mp_obj_new_list,
9191
.mp_binary_op = mp_binary_op,
92+
.mp_obj_get_int = mp_obj_get_int,
9293
};
9394

9495
void mp_extern_load(const char *ext_name, mp_obj_dict_t *globals) {

py/mpextern.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* The MIT License (MIT)
55
*
66
* Copyright (c) 2015 Damien P. George
7+
* Copyright (c) 2015 Daniel Campora
78
*
89
* Permission is hereby granted, free of charge, to any person obtaining a copy
910
* of this software and associated documentation files (the "Software"), to deal
@@ -28,17 +29,25 @@
2829

2930
#include "py/runtime0.h"
3031
#include "py/runtime.h"
32+
#include "py/mpconfig.h"
3133

3234
#define MP_EXT_VERSION_MAJOR (0)
3335
#define MP_EXT_VERSION_MINOR (0)
3436
#define MP_EXT_VERSION_SUBMINOR (1)
3537
#define MP_EXT_ARCH_X86 (1)
3638
#define MP_EXT_ARCH_X64 (2)
37-
#define MP_EXT_ARCH_ARM (3)
38-
#define MP_EXT_ARCH_THUMB2 (4)
39+
#define MP_EXT_ARCH_THUMB2 (3)
40+
#define MP_EXT_ARCH_ARM (4)
3941

40-
// TODO auto-detect current arch
42+
#if defined(__i386__)
4143
#define MP_EXT_ARCH_CURRENT (MP_EXT_ARCH_X86)
44+
#elif defined(__x86_64__)
45+
#define MP_EXT_ARCH_CURRENT (MP_EXT_ARCH_X64)
46+
#elif defined(__thumb2__)
47+
#define MP_EXT_ARCH_CURRENT (MP_EXT_ARCH_THUMB2)
48+
#elif defined(__arm__)
49+
#define MP_EXT_ARCH_CURRENT (MP_EXT_ARCH_ARM)
50+
#endif
4251

4352
#define MP_EXT_HEADER \
4453
__attribute__((section(".mpyheader"))) \
@@ -60,6 +69,7 @@ typedef struct _mp_ext_table_t {
6069
void (*mp_store_global)(qstr qst, mp_obj_t obj);
6170
mp_obj_t (*mp_obj_new_list)(mp_uint_t n, mp_obj_t *items);
6271
mp_obj_t (*mp_binary_op)(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs);
72+
mp_int_t (*mp_obj_get_int)(mp_const_obj_t arg);
6373
} mp_ext_table_t;
6474

6575
void mp_extern_load(const char *ext_name, mp_obj_dict_t *globals);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy