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
c25abcd9
Commit
c25abcd9
authored
May 29, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #567 from undingen/bom
Add UTF8-BOM support, int.bit_length, function.func_doc, fix '(-1)**0'
parents
153fd1eb
4b40c012
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
45 additions
and
9 deletions
+45
-9
src/codegen/pypa-parser.cpp
src/codegen/pypa-parser.cpp
+6
-0
src/runtime/int.cpp
src/runtime/int.cpp
+31
-4
src/runtime/types.cpp
src/runtime/types.cpp
+1
-0
test/tests/decimal_test.py
test/tests/decimal_test.py
+0
-2
test/tests/functions.py
test/tests/functions.py
+5
-0
test/tests/intmethods.py
test/tests/intmethods.py
+2
-1
test/tests/parsing_bom.py
test/tests/parsing_bom.py
+0
-2
No files found.
src/codegen/pypa-parser.cpp
View file @
c25abcd9
...
...
@@ -1064,6 +1064,12 @@ std::string PystonSourceReader::get_line() {
break
;
line
.
push_back
(
c
);
}
while
(
c
!=
'\n'
&&
c
!=
'\x0c'
);
// check for UTF8 BOM
if
(
line_number
==
0
&&
line
[
0
]
==
'\xEF'
&&
line
[
1
]
==
'\xBB'
&&
line
[
2
]
==
'\xBF'
)
{
set_encoding
(
"utf-8"
);
line
.
erase
(
0
,
3
);
}
++
line_number
;
return
line
;
}
...
...
src/runtime/int.cpp
View file @
c25abcd9
...
...
@@ -338,11 +338,8 @@ extern "C" Box* pow_i64_i64(i64 lhs, i64 rhs) {
if
(
rhs
<
0
)
return
boxFloat
(
pow_float_float
(
lhs
,
rhs
));
if
(
rhs
==
0
)
{
if
(
lhs
<
0
)
return
boxInt
(
-
1
);
if
(
rhs
==
0
)
return
boxInt
(
1
);
}
assert
(
rhs
>
0
);
while
(
true
)
{
...
...
@@ -1035,6 +1032,34 @@ extern "C" Box* intNew(Box* _cls, Box* val, Box* base) {
return
new
(
cls
)
BoxedInt
(
n
->
n
);
}
static
const
unsigned
char
BitLengthTable
[
32
]
=
{
0
,
1
,
2
,
2
,
3
,
3
,
3
,
3
,
4
,
4
,
4
,
4
,
4
,
4
,
4
,
4
,
5
,
5
,
5
,
5
,
5
,
5
,
5
,
5
,
5
,
5
,
5
,
5
,
5
,
5
,
5
,
5
};
static
int
bits_in_ulong
(
unsigned
long
d
)
noexcept
{
int
d_bits
=
0
;
while
(
d
>=
32
)
{
d_bits
+=
6
;
d
>>=
6
;
}
d_bits
+=
(
int
)
BitLengthTable
[
d
];
return
d_bits
;
}
extern
"C"
Box
*
intBitLength
(
BoxedInt
*
v
)
{
if
(
!
isSubclass
(
v
->
cls
,
int_cls
))
raiseExcHelper
(
TypeError
,
"descriptor 'bit_length' requires a 'int' object but received a '%s'"
,
getTypeName
(
v
));
unsigned
long
n
;
if
(
v
->
n
<
0
)
/* avoid undefined behaviour when v->n == -LONG_MAX-1 */
n
=
0U
-
(
unsigned
long
)
v
->
n
;
else
n
=
(
unsigned
long
)
v
->
n
;
return
PyInt_FromLong
(
bits_in_ulong
(
n
));
}
static
void
_addFuncIntFloatUnknown
(
const
char
*
name
,
void
*
int_func
,
void
*
float_func
,
void
*
boxed_func
)
{
std
::
vector
<
ConcreteCompilerType
*>
v_ii
,
v_if
,
v_iu
;
assert
(
BOXED_INT
);
...
...
@@ -1131,6 +1156,8 @@ void setupInt() {
ParamNames
({
""
,
"x"
,
"base"
},
""
,
""
)),
{
boxInt
(
0
),
NULL
}));
int_cls
->
giveAttr
(
"bit_length"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
intBitLength
,
BOXED_INT
,
1
)));
int_cls
->
giveAttr
(
"real"
,
new
(
pyston_getset_cls
)
BoxedGetsetDescriptor
(
intInt
,
NULL
,
NULL
));
int_cls
->
giveAttr
(
"imag"
,
new
(
pyston_getset_cls
)
BoxedGetsetDescriptor
(
int0
,
NULL
,
NULL
));
int_cls
->
giveAttr
(
"conjugate"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
intInt
,
BOXED_INT
,
1
)));
...
...
src/runtime/types.cpp
View file @
c25abcd9
...
...
@@ -2616,6 +2616,7 @@ void setupRuntime() {
offsetof
(
BoxedFunction
,
modname
),
false
));
function_cls
->
giveAttr
(
"__doc__"
,
new
BoxedMemberDescriptor
(
BoxedMemberDescriptor
::
OBJECT
,
offsetof
(
BoxedFunction
,
doc
),
false
));
function_cls
->
giveAttr
(
"func_doc"
,
function_cls
->
getattr
(
"__doc__"
));
function_cls
->
giveAttr
(
"__globals__"
,
new
(
pyston_getset_cls
)
BoxedGetsetDescriptor
(
functionGlobals
,
NULL
,
NULL
));
function_cls
->
giveAttr
(
"__get__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
functionGet
,
UNKNOWN
,
3
)));
function_cls
->
giveAttr
(
"__call__"
,
...
...
test/tests/decimal_test.py
View file @
c25abcd9
# expected: fail
from
decimal
import
Decimal
for
d
in
(
Decimal
(
"0.5"
),
Decimal
(
"0"
),
Decimal
(
0
),
Decimal
(
1.0
)):
...
...
test/tests/functions.py
View file @
c25abcd9
def
f
():
"""very nice function"""
print
"f"
return
2
print
f
.
__call__
()
print
f
.
__doc__
print
f
.
func_doc
def
g
():
print
"g"
return
3
print
g
.
__doc__
print
type
(
f
).
__call__
(
f
)
print
type
(
f
).
__call__
(
g
)
...
...
test/tests/intmethods.py
View file @
c25abcd9
...
...
@@ -12,13 +12,14 @@ for i in xrange(1, 12):
print
1
**
0
print
0
**
0
print
-
1
**
0
print
-
1
**
0
,
(
-
1
)
**
0
,
(
-
5
)
**
0
print
(
11
).
__pow__
(
5
,
50
)
print
(
11
).
__pow__
(
32
,
50
)
print
(
11
).
__index__
()
for
i
in
(
-
10
,
10
,
0
,
-
15
):
print
i
,
i
.
__hex__
(),
i
.
__oct__
()
print
i
.
bit_length
()
# Testing int.__new__:
class
C
(
int
):
...
...
test/tests/parsing_bom.py
View file @
c25abcd9
# fail-if: '-x' not in EXTRA_JIT_ARGS
# I really don't understand all the intricacies of unicode parsing, but apparently in addition to
# Python-specific coding lines, you can put a unicode byte order mark to signify that the text
# is encoded.
...
...
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