Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
3e2c911b
Commit
3e2c911b
authored
Jul 31, 2014
by
Chris Ramstad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement builtin function id()
Currently returns the address if the Box*
parent
2412b178
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
2 deletions
+21
-2
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+8
-0
src/runtime/types.cpp
src/runtime/types.cpp
+3
-0
src/runtime/types.h
src/runtime/types.h
+2
-2
test/tests/id.py
test/tests/id.py
+8
-0
No files found.
src/runtime/builtin_modules/builtins.cpp
View file @
3e2c911b
...
...
@@ -180,6 +180,12 @@ extern "C" Box* sum(Box* container, Box* initial) {
return
cur
;
}
extern
"C"
Box
*
id
(
Box
*
arg
)
{
i64
addr
=
(
i64
)(
arg
);
return
boxInt
(
addr
);
}
Box
*
open
(
Box
*
arg1
,
Box
*
arg2
)
{
assert
(
arg2
);
...
...
@@ -494,6 +500,8 @@ void setupBuiltins() {
builtins_module
->
giveAttr
(
"sum"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
sum
,
UNKNOWN
,
2
,
1
,
false
,
false
),
{
boxInt
(
0
)
}));
id_obj
=
new
BoxedFunction
(
boxRTFunction
((
void
*
)
id
,
BOXED_INT
,
1
));
builtins_module
->
giveAttr
(
"id"
,
id_obj
);
chr_obj
=
new
BoxedFunction
(
boxRTFunction
((
void
*
)
chr
,
STR
,
1
));
builtins_module
->
giveAttr
(
"chr"
,
chr_obj
);
ord_obj
=
new
BoxedFunction
(
boxRTFunction
((
void
*
)
ord
,
BOXED_INT
,
1
));
...
...
src/runtime/types.cpp
View file @
3e2c911b
...
...
@@ -405,6 +405,8 @@ extern "C" BoxedString* functionRepr(BoxedFunction* v) {
return
boxStrConstant
(
"<built-in function max>"
);
if
(
v
==
open_obj
)
return
boxStrConstant
(
"<built-in function open>"
);
if
(
v
==
id_obj
)
return
boxStrConstant
(
"<built-in function id>"
);
if
(
v
==
chr_obj
)
return
boxStrConstant
(
"<built-in function chr>"
);
if
(
v
==
ord_obj
)
...
...
@@ -422,6 +424,7 @@ Box* abs_obj = NULL;
Box
*
min_obj
=
NULL
;
Box
*
max_obj
=
NULL
;
Box
*
open_obj
=
NULL
;
Box
*
id_obj
=
NULL
;
Box
*
chr_obj
=
NULL
;
Box
*
ord_obj
=
NULL
;
Box
*
trap_obj
=
NULL
;
...
...
src/runtime/types.h
View file @
3e2c911b
...
...
@@ -81,8 +81,8 @@ extern const ObjectFlavor object_flavor, type_flavor, bool_flavor, int_flavor, f
}
extern
"C"
{
extern
Box
*
None
,
*
NotImplemented
,
*
True
,
*
False
;
}
extern
"C"
{
extern
Box
*
repr_obj
,
*
len_obj
,
*
hash_obj
,
*
range_obj
,
*
abs_obj
,
*
min_obj
,
*
max_obj
,
*
open_obj
,
*
chr_obj
,
*
ord
_obj
,
*
trap_obj
;
extern
Box
*
repr_obj
,
*
len_obj
,
*
hash_obj
,
*
range_obj
,
*
abs_obj
,
*
min_obj
,
*
max_obj
,
*
open_obj
,
*
id_obj
,
*
chr
_obj
,
*
ord_obj
,
*
trap_obj
;
}
// these are only needed for functionRepr, which is hacky
extern
"C"
{
extern
BoxedModule
*
sys_module
,
*
builtins_module
,
*
math_module
,
*
time_module
,
*
thread_module
;
}
...
...
test/tests/id.py
0 → 100644
View file @
3e2c911b
x
=
'Hi'
y
=
1
z
=
(
42
,
7
)
f
=
(
2
,)
+
z
id
(
x
)
id
(
y
)
id
(
z
)
id
(
f
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment