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
88fd6101
Commit
88fd6101
authored
Aug 24, 2015
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
return correct type for unary float ops
parent
646f321a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
4 deletions
+32
-4
src/analysis/type_analysis.cpp
src/analysis/type_analysis.cpp
+12
-4
src/codegen/compvars.cpp
src/codegen/compvars.cpp
+17
-0
test/tests/float.py
test/tests/float.py
+3
-0
No files found.
src/analysis/type_analysis.cpp
View file @
88fd6101
...
@@ -225,7 +225,7 @@ private:
...
@@ -225,7 +225,7 @@ private:
return
rtn
;
return
rtn
;
}
}
bool
hasFixed
Bino
ps
(
CompilerType
*
type
)
{
bool
hasFixed
O
ps
(
CompilerType
*
type
)
{
// This is non-exhaustive:
// This is non-exhaustive:
return
type
==
STR
||
type
==
INT
||
type
==
FLOAT
||
type
==
LIST
||
type
==
DICT
;
return
type
==
STR
||
type
==
INT
||
type
==
FLOAT
||
type
==
LIST
||
type
==
DICT
;
}
}
...
@@ -233,7 +233,7 @@ private:
...
@@ -233,7 +233,7 @@ private:
void
*
visit_augbinop
(
AST_AugBinOp
*
node
)
override
{
void
*
visit_augbinop
(
AST_AugBinOp
*
node
)
override
{
CompilerType
*
left
=
getType
(
node
->
left
);
CompilerType
*
left
=
getType
(
node
->
left
);
CompilerType
*
right
=
getType
(
node
->
right
);
CompilerType
*
right
=
getType
(
node
->
right
);
if
(
!
hasFixed
Binops
(
left
)
||
!
hasFixedBino
ps
(
right
))
if
(
!
hasFixed
Ops
(
left
)
||
!
hasFixedO
ps
(
right
))
return
UNKNOWN
;
return
UNKNOWN
;
// TODO this isn't the exact behavior
// TODO this isn't the exact behavior
...
@@ -262,7 +262,7 @@ private:
...
@@ -262,7 +262,7 @@ private:
void
*
visit_binop
(
AST_BinOp
*
node
)
override
{
void
*
visit_binop
(
AST_BinOp
*
node
)
override
{
CompilerType
*
left
=
getType
(
node
->
left
);
CompilerType
*
left
=
getType
(
node
->
left
);
CompilerType
*
right
=
getType
(
node
->
right
);
CompilerType
*
right
=
getType
(
node
->
right
);
if
(
!
hasFixed
Binops
(
left
)
||
!
hasFixedBino
ps
(
right
))
if
(
!
hasFixed
Ops
(
left
)
||
!
hasFixedO
ps
(
right
))
return
UNKNOWN
;
return
UNKNOWN
;
// TODO this isn't the exact behavior
// TODO this isn't the exact behavior
...
@@ -508,12 +508,20 @@ private:
...
@@ -508,12 +508,20 @@ private:
void
*
visit_unaryop
(
AST_UnaryOp
*
node
)
override
{
void
*
visit_unaryop
(
AST_UnaryOp
*
node
)
override
{
CompilerType
*
operand
=
getType
(
node
->
operand
);
CompilerType
*
operand
=
getType
(
node
->
operand
);
if
(
!
hasFixedOps
(
operand
))
return
UNKNOWN
;
// TODO this isn't the exact behavior
// TODO this isn't the exact behavior
BoxedString
*
name
=
getOpName
(
node
->
op_type
);
BoxedString
*
name
=
getOpName
(
node
->
op_type
);
CompilerType
*
attr_type
=
operand
->
getattrType
(
name
,
true
);
CompilerType
*
attr_type
=
operand
->
getattrType
(
name
,
true
);
if
(
attr_type
==
UNDEF
)
attr_type
=
UNKNOWN
;
std
::
vector
<
CompilerType
*>
arg_types
;
std
::
vector
<
CompilerType
*>
arg_types
;
return
attr_type
->
callType
(
ArgPassSpec
(
0
),
arg_types
,
NULL
);
CompilerType
*
rtn_type
=
attr_type
->
callType
(
ArgPassSpec
(
0
),
arg_types
,
NULL
);
rtn_type
=
unboxedType
(
rtn_type
->
getConcreteType
());
return
rtn_type
;
}
}
void
*
visit_yield
(
AST_Yield
*
)
override
{
return
UNKNOWN
;
}
void
*
visit_yield
(
AST_Yield
*
)
override
{
return
UNKNOWN
;
}
...
...
src/codegen/compvars.cpp
View file @
88fd6101
...
@@ -1294,6 +1294,14 @@ public:
...
@@ -1294,6 +1294,14 @@ public:
return
boolFromI1
(
emitter
,
cmp
);
return
boolFromI1
(
emitter
,
cmp
);
}
}
ConcreteCompilerVariable
*
unaryop
(
IREmitter
&
emitter
,
const
OpInfo
&
info
,
ConcreteCompilerVariable
*
var
,
AST_TYPE
::
AST_TYPE
op_type
)
override
{
ConcreteCompilerVariable
*
converted
=
var
->
makeConverted
(
emitter
,
BOXED_FLOAT
);
auto
rtn
=
converted
->
unaryop
(
emitter
,
info
,
op_type
);
converted
->
decvref
(
emitter
);
return
rtn
;
}
CompilerVariable
*
getitem
(
IREmitter
&
emitter
,
const
OpInfo
&
info
,
VAR
*
var
,
CompilerVariable
*
slice
)
override
{
CompilerVariable
*
getitem
(
IREmitter
&
emitter
,
const
OpInfo
&
info
,
VAR
*
var
,
CompilerVariable
*
slice
)
override
{
ConcreteCompilerVariable
*
converted
=
var
->
makeConverted
(
emitter
,
BOXED_FLOAT
);
ConcreteCompilerVariable
*
converted
=
var
->
makeConverted
(
emitter
,
BOXED_FLOAT
);
CompilerVariable
*
rtn
=
converted
->
getitem
(
emitter
,
info
,
slice
);
CompilerVariable
*
rtn
=
converted
->
getitem
(
emitter
,
info
,
slice
);
...
@@ -1885,6 +1893,15 @@ public:
...
@@ -1885,6 +1893,15 @@ public:
ConcreteCompilerVariable
*
unaryop
(
IREmitter
&
emitter
,
const
OpInfo
&
info
,
ConcreteCompilerVariable
*
var
,
ConcreteCompilerVariable
*
unaryop
(
IREmitter
&
emitter
,
const
OpInfo
&
info
,
ConcreteCompilerVariable
*
var
,
AST_TYPE
::
AST_TYPE
op_type
)
override
{
AST_TYPE
::
AST_TYPE
op_type
)
override
{
BoxedString
*
attr
=
getOpName
(
op_type
);
bool
no_attribute
=
false
;
ConcreteCompilerVariable
*
called_constant
=
tryCallattrConstant
(
emitter
,
info
,
var
,
attr
,
true
,
ArgPassSpec
(
0
,
0
,
0
,
0
),
{},
NULL
,
&
no_attribute
);
if
(
called_constant
&&
!
no_attribute
)
return
called_constant
;
return
UNKNOWN
->
unaryop
(
emitter
,
info
,
var
,
op_type
);
return
UNKNOWN
->
unaryop
(
emitter
,
info
,
var
,
op_type
);
}
}
...
...
test/tests/float.py
View file @
88fd6101
...
@@ -108,3 +108,6 @@ for lhs in all_args:
...
@@ -108,3 +108,6 @@ for lhs in all_args:
import
sys
import
sys
print
sys
.
float_info
print
sys
.
float_info
if
1
:
x
=
-
2.0
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