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
9b00dad7
Commit
9b00dad7
authored
11 years ago
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
long int: Implement more operations.
parent
ddf1aa92
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
py/objint.c
+7
-0
7 additions, 0 deletions
py/objint.c
py/objint.h
+1
-0
1 addition, 0 deletions
py/objint.h
py/objint_longlong.c
+37
-4
37 additions, 4 deletions
py/objint_longlong.c
tests/basics/int-long.py
+39
-0
39 additions, 0 deletions
tests/basics/int-long.py
with
84 additions
and
4 deletions
py/objint.c
+
7
−
0
View file @
9b00dad7
...
...
@@ -51,6 +51,12 @@ void int_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj
}
}
// This is called only for non-SMALL_INT
mp_obj_t
int_unary_op
(
int
op
,
mp_obj_t
o_in
)
{
assert
(
0
);
return
mp_const_none
;
}
// 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
);
...
...
@@ -96,5 +102,6 @@ const mp_obj_type_t int_type = {
"int"
,
.
print
=
int_print
,
.
make_new
=
int_make_new
,
.
unary_op
=
int_unary_op
,
.
binary_op
=
int_binary_op
,
};
This diff is collapsed.
Click to expand it.
py/objint.h
+
1
−
0
View file @
9b00dad7
...
...
@@ -6,4 +6,5 @@ typedef struct _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_print_kind_t
kind
);
mp_obj_t
int_unary_op
(
int
op
,
mp_obj_t
o_in
);
mp_obj_t
int_binary_op
(
int
op
,
mp_obj_t
lhs_in
,
mp_obj_t
rhs_in
);
This diff is collapsed.
Click to expand it.
py/objint_longlong.c
+
37
−
4
View file @
9b00dad7
...
...
@@ -32,6 +32,17 @@ void int_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj
}
}
mp_obj_t
int_unary_op
(
int
op
,
mp_obj_t
o_in
)
{
mp_obj_int_t
*
o
=
o_in
;
switch
(
op
)
{
case
RT_UNARY_OP_NOT
:
return
MP_BOOL
(
o
->
val
!=
0
);
// TODO: implements RT_UNARY_OP_BOOL
case
RT_UNARY_OP_POSITIVE
:
return
o_in
;
case
RT_UNARY_OP_NEGATIVE
:
return
mp_obj_new_int_from_ll
(
-
o
->
val
);
case
RT_UNARY_OP_INVERT
:
return
mp_obj_new_int_from_ll
(
~
o
->
val
);
default:
return
NULL
;
// op not supported
}
}
mp_obj_t
int_binary_op
(
int
op
,
mp_obj_t
lhs_in
,
mp_obj_t
rhs_in
)
{
mp_obj_int_t
*
lhs
=
lhs_in
;
mp_obj_int_t
*
rhs
=
rhs_in
;
...
...
@@ -50,13 +61,23 @@ mp_obj_t int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
return
mp_obj_new_int_from_ll
(
lhs
->
val
+
rhs_val
);
case
RT_BINARY_OP_SUBTRACT
:
return
mp_obj_new_int_from_ll
(
lhs
->
val
-
rhs_val
);
case
RT_BINARY_OP_MULTIPLY
:
return
mp_obj_new_int_from_ll
(
lhs
->
val
*
rhs_val
);
case
RT_BINARY_OP_FLOOR_DIVIDE
:
return
mp_obj_new_int_from_ll
(
lhs
->
val
/
rhs_val
);
case
RT_BINARY_OP_MODULO
:
return
mp_obj_new_int_from_ll
(
lhs
->
val
%
rhs_val
);
case
RT_BINARY_OP_INPLACE_ADD
:
lhs
->
val
+=
rhs_val
;
return
lhs
;
lhs
->
val
+=
rhs_val
;
return
lhs
;
case
RT_BINARY_OP_INPLACE_SUBTRACT
:
lhs
->
val
-=
rhs_val
;
return
lhs
;
lhs
->
val
-=
rhs_val
;
return
lhs
;
case
RT_BINARY_OP_INPLACE_MULTIPLY
:
lhs
->
val
*=
rhs_val
;
return
lhs
;
case
RT_BINARY_OP_INPLACE_FLOOR_DIVIDE
:
lhs
->
val
/=
rhs_val
;
return
lhs
;
case
RT_BINARY_OP_INPLACE_MODULO
:
lhs
->
val
%=
rhs_val
;
return
lhs
;
case
RT_BINARY_OP_AND
:
return
mp_obj_new_int_from_ll
(
lhs
->
val
&
rhs_val
);
...
...
@@ -65,11 +86,23 @@ mp_obj_t int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
case
RT_BINARY_OP_XOR
:
return
mp_obj_new_int_from_ll
(
lhs
->
val
^
rhs_val
);
case
RT_BINARY_OP_INPLACE_AND
:
lhs
->
val
&=
rhs_val
;
return
lhs
;
case
RT_BINARY_OP_INPLACE_OR
:
lhs
->
val
|=
rhs_val
;
return
lhs
;
case
RT_BINARY_OP_INPLACE_XOR
:
lhs
->
val
^=
rhs_val
;
return
lhs
;
case
RT_BINARY_OP_LSHIFT
:
return
mp_obj_new_int_from_ll
(
lhs
->
val
<<
(
int
)
rhs_val
);
case
RT_BINARY_OP_RSHIFT
:
return
mp_obj_new_int_from_ll
(
lhs
->
val
>>
(
int
)
rhs_val
);
case
RT_BINARY_OP_INPLACE_LSHIFT
:
lhs
->
val
<<=
(
int
)
rhs_val
;
return
lhs
;
case
RT_BINARY_OP_INPLACE_RSHIFT
:
lhs
->
val
>>=
(
int
)
rhs_val
;
return
lhs
;
case
RT_COMPARE_OP_LESS
:
return
MP_BOOL
(
lhs
->
val
<
rhs_val
);
case
RT_COMPARE_OP_MORE
:
...
...
This diff is collapsed.
Click to expand it.
tests/basics/int-long.py
0 → 100644
+
39
−
0
View file @
9b00dad7
# This tests long ints for 32-bit machine
a
=
0x1ffffffff
b
=
0x100000000
print
(
a
)
print
(
b
)
print
(
a
+
b
)
print
(
a
-
b
)
print
(
b
-
a
)
# overflows long long implementation
#print(a * b)
print
(
a
//
b
)
print
(
a
%
b
)
print
(
a
&
b
)
print
(
a
|
b
)
print
(
a
^
b
)
print
(
a
<<
3
)
print
(
a
>>
1
)
a
+=
b
print
(
a
)
a
-=
123456
print
(
a
)
a
*=
257
print
(
a
)
a
//=
257
print
(
a
)
a
%=
b
print
(
a
)
a
^=
b
print
(
a
)
a
|=
b
print
(
a
)
a
&=
b
print
(
a
)
a
<<=
5
print
(
a
)
a
>>=
1
print
(
a
)
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