Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
48b3572f
Commit
48b3572f
authored
Jan 12, 2014
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
Add framework to support alternative implementations of long int Python type.
parent
80f60e1a
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
py/mpconfig.h
+12
-0
12 additions, 0 deletions
py/mpconfig.h
py/obj.h
+2
-0
2 additions, 0 deletions
py/obj.h
py/objint.c
+42
-2
42 additions, 2 deletions
py/objint.c
with
56 additions
and
2 deletions
py/mpconfig.h
+
12
−
0
View file @
48b3572f
...
@@ -62,6 +62,18 @@
...
@@ -62,6 +62,18 @@
#define MICROPY_ENABLE_LEXER_UNIX (0)
#define MICROPY_ENABLE_LEXER_UNIX (0)
#endif
#endif
// Long int implementation
#define MICROPY_LONGINT_IMPL_NONE (0)
#define MICROPY_LONGINT_IMPL_LONGLONG (1)
#ifndef MICROPY_LONGINT_IMPL
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_NONE)
#endif
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG
typedef
long
long
mp_longint_impl_t
;
#endif
// Whether to support float and complex types
// Whether to support float and complex types
#ifndef MICROPY_ENABLE_FLOAT
#ifndef MICROPY_ENABLE_FLOAT
#define MICROPY_ENABLE_FLOAT (0)
#define MICROPY_ENABLE_FLOAT (0)
...
...
This diff is collapsed.
Click to expand it.
py/obj.h
+
2
−
0
View file @
48b3572f
...
@@ -198,6 +198,8 @@ mp_obj_t mp_obj_new_none(void);
...
@@ -198,6 +198,8 @@ mp_obj_t mp_obj_new_none(void);
mp_obj_t
mp_obj_new_bool
(
bool
value
);
mp_obj_t
mp_obj_new_bool
(
bool
value
);
mp_obj_t
mp_obj_new_cell
(
mp_obj_t
obj
);
mp_obj_t
mp_obj_new_cell
(
mp_obj_t
obj
);
mp_obj_t
mp_obj_new_int
(
machine_int_t
value
);
mp_obj_t
mp_obj_new_int
(
machine_int_t
value
);
mp_obj_t
mp_obj_new_int_from_uint
(
machine_uint_t
value
);
mp_obj_t
mp_obj_new_int_from_long_str
(
const
char
*
s
);
mp_obj_t
mp_obj_new_str
(
qstr
qstr
);
mp_obj_t
mp_obj_new_str
(
qstr
qstr
);
#if MICROPY_ENABLE_FLOAT
#if MICROPY_ENABLE_FLOAT
mp_obj_t
mp_obj_new_float
(
mp_float_t
val
);
mp_obj_t
mp_obj_new_float
(
mp_float_t
val
);
...
...
This diff is collapsed.
Click to expand it.
py/objint.c
+
42
−
2
View file @
48b3572f
...
@@ -11,8 +11,16 @@
...
@@ -11,8 +11,16 @@
typedef
struct
_mp_obj_int_t
{
typedef
struct
_mp_obj_int_t
{
mp_obj_base_t
base
;
mp_obj_base_t
base
;
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
mp_longint_impl_t
val
;
#endif
}
mp_obj_int_t
;
}
mp_obj_int_t
;
void
int_print
(
void
(
*
print
)(
void
*
env
,
const
char
*
fmt
,
...),
void
*
env
,
mp_obj_t
self_in
);
mp_obj_t
int_binary_op
(
int
op
,
mp_obj_t
lhs_in
,
mp_obj_t
rhs_in
);
// This dispatcher function is expected to be independent of the implementation
// of long int
static
mp_obj_t
int_make_new
(
mp_obj_t
type_in
,
int
n_args
,
const
mp_obj_t
*
args
)
{
static
mp_obj_t
int_make_new
(
mp_obj_t
type_in
,
int
n_args
,
const
mp_obj_t
*
args
)
{
switch
(
n_args
)
{
switch
(
n_args
)
{
case
0
:
case
0
:
...
@@ -20,7 +28,7 @@ static mp_obj_t int_make_new(mp_obj_t type_in, int n_args, const mp_obj_t *args)
...
@@ -20,7 +28,7 @@ static mp_obj_t int_make_new(mp_obj_t type_in, int n_args, const mp_obj_t *args)
case
1
:
case
1
:
// TODO allow string as arg and parse it
// TODO allow string as arg and parse it
return
MP_OBJ_NEW_SMALL_INT
(
mp_obj_get_int
(
args
[
0
]));
return
mp_obj_new_int
(
mp_obj_get_int
(
args
[
0
]));
//case 2:
//case 2:
// TODO, parse with given base
// TODO, parse with given base
...
@@ -33,9 +41,41 @@ static mp_obj_t int_make_new(mp_obj_t type_in, int n_args, const mp_obj_t *args)
...
@@ -33,9 +41,41 @@ static mp_obj_t int_make_new(mp_obj_t type_in, int n_args, const mp_obj_t *args)
const
mp_obj_type_t
int_type
=
{
const
mp_obj_type_t
int_type
=
{
{
&
mp_const_type
},
{
&
mp_const_type
},
"int"
,
"int"
,
.
print
=
int_print
,
.
make_new
=
int_make_new
,
.
make_new
=
int_make_new
,
.
binary_op
=
int_binary_op
,
};
};
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE
// This is called only for non-SMALL_INT
void
int_print
(
void
(
*
print
)(
void
*
env
,
const
char
*
fmt
,
...),
void
*
env
,
mp_obj_t
self_in
)
{
}
// This is called only for non-SMALL_INT
mp_obj_t
int_binary_op
(
int
op
,
mp_obj_t
lhs_in
,
mp_obj_t
rhs_in
)
{
assert
(
0
);
}
// This is called only with strings whose value doesn't fit in SMALL_INT
mp_obj_t
mp_obj_new_int_from_long_str
(
const
char
*
s
)
{
assert
(
0
);
}
mp_obj_t
mp_obj_new_int_from_uint
(
machine_uint_t
value
)
{
// SMALL_INT accepts only signed numbers, of one bit less size
// then word size, which totals 2 bits less for unsigned numbers.
if
((
value
&
(
WORD_MSBIT_HIGH
|
(
WORD_MSBIT_HIGH
>>
1
)))
==
0
)
{
return
MP_OBJ_NEW_SMALL_INT
(
value
);
}
// TODO: Raise exception
assert
(
0
);
}
mp_obj_t
mp_obj_new_int
(
machine_int_t
value
)
{
mp_obj_t
mp_obj_new_int
(
machine_int_t
value
)
{
if
(
MP_OBJ_FITS_SMALL_INT
(
value
))
{
return
MP_OBJ_NEW_SMALL_INT
(
value
);
return
MP_OBJ_NEW_SMALL_INT
(
value
);
}
}
// TODO: Raise exception
assert
(
0
);
}
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment