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
f49316ac
Commit
f49316ac
authored
Apr 23, 2015
by
Travis Hance
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builtin format
parent
fb499bc7
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
51 additions
and
2 deletions
+51
-2
from_cpython/Objects/floatobject.c
from_cpython/Objects/floatobject.c
+2
-1
from_cpython/Objects/stringobject.c
from_cpython/Objects/stringobject.c
+30
-0
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+10
-0
src/runtime/float.cpp
src/runtime/float.cpp
+3
-1
src/runtime/str.cpp
src/runtime/str.cpp
+2
-0
test/tests/builtins.py
test/tests/builtins.py
+4
-0
No files found.
from_cpython/Objects/floatobject.c
View file @
f49316ac
...
@@ -1995,7 +1995,8 @@ float_getzero(PyObject *v, void *closure)
...
@@ -1995,7 +1995,8 @@ float_getzero(PyObject *v, void *closure)
return
PyFloat_FromDouble
(
0
.
0
);
return
PyFloat_FromDouble
(
0
.
0
);
}
}
static
PyObject
*
// pyston change: make not static
PyObject
*
float__format__
(
PyObject
*
self
,
PyObject
*
args
)
float__format__
(
PyObject
*
self
,
PyObject
*
args
)
{
{
PyObject
*
format_spec
;
PyObject
*
format_spec
;
...
...
from_cpython/Objects/stringobject.c
View file @
f49316ac
...
@@ -364,3 +364,33 @@ PyObject *string_join(PyStringObject *self, PyObject *orig)
...
@@ -364,3 +364,33 @@ PyObject *string_join(PyStringObject *self, PyObject *orig)
Py_DECREF
(
seq
);
Py_DECREF
(
seq
);
return
res
;
return
res
;
}
}
PyObject
*
string__format__
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
format_spec
;
PyObject
*
result
=
NULL
;
PyObject
*
tmp
=
NULL
;
/* If 2.x, convert format_spec to the same type as value */
/* This is to allow things like u''.format('') */
if
(
!
PyArg_ParseTuple
(
args
,
"O:__format__"
,
&
format_spec
))
goto
done
;
if
(
!
(
PyString_Check
(
format_spec
)
||
PyUnicode_Check
(
format_spec
)))
{
PyErr_Format
(
PyExc_TypeError
,
"__format__ arg must be str "
"or unicode, not %s"
,
Py_TYPE
(
format_spec
)
->
tp_name
);
goto
done
;
}
tmp
=
PyObject_Str
(
format_spec
);
if
(
tmp
==
NULL
)
goto
done
;
format_spec
=
tmp
;
result
=
_PyBytes_FormatAdvanced
(
self
,
PyString_AS_STRING
(
format_spec
),
PyString_GET_SIZE
(
format_spec
));
done:
Py_XDECREF
(
tmp
);
return
result
;
}
src/runtime/builtin_modules/builtins.cpp
View file @
f49316ac
...
@@ -1095,6 +1095,14 @@ Box* builtinApply(Box* func, Box* args, Box* keywords) {
...
@@ -1095,6 +1095,14 @@ Box* builtinApply(Box* func, Box* args, Box* keywords) {
return
runtimeCall
(
func
,
ArgPassSpec
(
0
,
0
,
true
,
keywords
!=
NULL
),
args
,
keywords
,
NULL
,
NULL
,
NULL
);
return
runtimeCall
(
func
,
ArgPassSpec
(
0
,
0
,
true
,
keywords
!=
NULL
),
args
,
keywords
,
NULL
,
NULL
,
NULL
);
}
}
Box
*
builtinFormat
(
Box
*
value
,
Box
*
format_spec
)
{
Box
*
res
=
PyObject_Format
(
value
,
format_spec
);
if
(
!
res
)
{
throwCAPIException
();
}
return
res
;
}
void
setupBuiltins
()
{
void
setupBuiltins
()
{
builtins_module
builtins_module
=
createModule
(
"__builtin__"
,
NULL
,
"Built-in functions, exceptions, and other objects.
\n\n
Noteworthy: None is "
=
createModule
(
"__builtin__"
,
NULL
,
"Built-in functions, exceptions, and other objects.
\n\n
Noteworthy: None is "
...
@@ -1330,5 +1338,7 @@ void setupBuiltins() {
...
@@ -1330,5 +1338,7 @@ void setupBuiltins() {
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
input
,
UNKNOWN
,
1
,
1
,
false
,
false
),
"input"
,
{
NULL
}));
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
input
,
UNKNOWN
,
1
,
1
,
false
,
false
),
"input"
,
{
NULL
}));
builtins_module
->
giveAttr
(
"cmp"
,
builtins_module
->
giveAttr
(
"cmp"
,
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
builtinCmp
,
UNKNOWN
,
2
),
"cmp"
));
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
builtinCmp
,
UNKNOWN
,
2
),
"cmp"
));
builtins_module
->
giveAttr
(
"format"
,
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
builtinFormat
,
UNKNOWN
,
2
),
"format"
));
}
}
}
}
src/runtime/float.cpp
View file @
f49316ac
...
@@ -29,6 +29,7 @@ extern "C" PyObject* float_hex(PyObject* v) noexcept;
...
@@ -29,6 +29,7 @@ extern "C" PyObject* float_hex(PyObject* v) noexcept;
extern
"C"
PyObject
*
float_fromhex
(
PyObject
*
cls
,
PyObject
*
arg
)
noexcept
;
extern
"C"
PyObject
*
float_fromhex
(
PyObject
*
cls
,
PyObject
*
arg
)
noexcept
;
extern
"C"
PyObject
*
float_as_integer_ratio
(
PyObject
*
v
,
PyObject
*
unused
)
noexcept
;
extern
"C"
PyObject
*
float_as_integer_ratio
(
PyObject
*
v
,
PyObject
*
unused
)
noexcept
;
extern
"C"
PyObject
*
float_is_integer
(
PyObject
*
v
)
noexcept
;
extern
"C"
PyObject
*
float_is_integer
(
PyObject
*
v
)
noexcept
;
extern
"C"
PyObject
*
float__format__
(
PyObject
*
v
)
noexcept
;
namespace
pyston
{
namespace
pyston
{
...
@@ -1434,7 +1435,8 @@ static PyMethodDef float_methods[] = { { "hex", (PyCFunction)float_hex, METH_NOA
...
@@ -1434,7 +1435,8 @@ static PyMethodDef float_methods[] = { { "hex", (PyCFunction)float_hex, METH_NOA
{
"fromhex"
,
(
PyCFunction
)
float_fromhex
,
METH_O
|
METH_CLASS
,
NULL
},
{
"fromhex"
,
(
PyCFunction
)
float_fromhex
,
METH_O
|
METH_CLASS
,
NULL
},
{
"as_integer_ratio"
,
(
PyCFunction
)
float_as_integer_ratio
,
METH_NOARGS
,
NULL
},
{
"as_integer_ratio"
,
(
PyCFunction
)
float_as_integer_ratio
,
METH_NOARGS
,
NULL
},
{
"is_integer"
,
(
PyCFunction
)
float_is_integer
,
METH_NOARGS
,
NULL
}
};
{
"is_integer"
,
(
PyCFunction
)
float_is_integer
,
METH_NOARGS
,
NULL
},
{
"__format__"
,
(
PyCFunction
)
float__format__
,
METH_VARARGS
,
NULL
}
};
void
setupFloat
()
{
void
setupFloat
()
{
_addFunc
(
"__add__"
,
BOXED_FLOAT
,
(
void
*
)
floatAddFloat
,
(
void
*
)
floatAddInt
,
(
void
*
)
floatAdd
);
_addFunc
(
"__add__"
,
BOXED_FLOAT
,
(
void
*
)
floatAddFloat
,
(
void
*
)
floatAddInt
,
(
void
*
)
floatAdd
);
...
...
src/runtime/str.cpp
View file @
f49316ac
...
@@ -44,6 +44,7 @@ extern "C" PyObject* string_index(PyStringObject* self, PyObject* args) noexcept
...
@@ -44,6 +44,7 @@ extern "C" PyObject* string_index(PyStringObject* self, PyObject* args) noexcept
extern
"C"
PyObject
*
string_rindex
(
PyStringObject
*
self
,
PyObject
*
args
)
noexcept
;
extern
"C"
PyObject
*
string_rindex
(
PyStringObject
*
self
,
PyObject
*
args
)
noexcept
;
extern
"C"
PyObject
*
string_rfind
(
PyStringObject
*
self
,
PyObject
*
args
)
noexcept
;
extern
"C"
PyObject
*
string_rfind
(
PyStringObject
*
self
,
PyObject
*
args
)
noexcept
;
extern
"C"
PyObject
*
string_splitlines
(
PyStringObject
*
self
,
PyObject
*
args
)
noexcept
;
extern
"C"
PyObject
*
string_splitlines
(
PyStringObject
*
self
,
PyObject
*
args
)
noexcept
;
extern
"C"
PyObject
*
string__format__
(
PyStringObject
*
self
,
PyObject
*
args
)
noexcept
;
// from cpython's stringobject.c:
// from cpython's stringobject.c:
#define LEFTSTRIP 0
#define LEFTSTRIP 0
...
@@ -2652,6 +2653,7 @@ static PyMethodDef string_methods[] = {
...
@@ -2652,6 +2653,7 @@ static PyMethodDef string_methods[] = {
{
"expandtabs"
,
(
PyCFunction
)
string_expandtabs
,
METH_VARARGS
,
NULL
},
{
"expandtabs"
,
(
PyCFunction
)
string_expandtabs
,
METH_VARARGS
,
NULL
},
{
"splitlines"
,
(
PyCFunction
)
string_splitlines
,
METH_VARARGS
,
NULL
},
{
"splitlines"
,
(
PyCFunction
)
string_splitlines
,
METH_VARARGS
,
NULL
},
{
"zfill"
,
(
PyCFunction
)
string_zfill
,
METH_VARARGS
,
NULL
},
{
"zfill"
,
(
PyCFunction
)
string_zfill
,
METH_VARARGS
,
NULL
},
{
"__format__"
,
(
PyCFunction
)
string__format__
,
METH_VARARGS
,
NULL
},
};
};
void
setupStr
()
{
void
setupStr
()
{
...
...
test/tests/builtins.py
View file @
f49316ac
...
@@ -117,3 +117,7 @@ print bytearray(xrange(256))
...
@@ -117,3 +117,7 @@ print bytearray(xrange(256))
l
=
[
2
,
1
,
3
]
l
=
[
2
,
1
,
3
]
print
apply
(
sorted
,
[
l
])
print
apply
(
sorted
,
[
l
])
print
apply
(
sorted
,
[
l
],
{
"reverse"
:
True
})
print
apply
(
sorted
,
[
l
],
{
"reverse"
:
True
})
print
format
(
5.0
,
'+'
)
print
format
(
5.011111111111
,
'+.6'
)
print
format
(
"abc"
,
''
)
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