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
9a79b92c
Commit
9a79b92c
authored
May 21, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Start working on that gcj test
Added some string functions and fixed a couple bugs.
parent
ac5c2a3c
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
86 additions
and
11 deletions
+86
-11
src/analysis/type_analysis.cpp
src/analysis/type_analysis.cpp
+2
-0
src/codegen/compvars.cpp
src/codegen/compvars.cpp
+12
-0
src/codegen/irgen/irgenerator.cpp
src/codegen/irgen/irgenerator.cpp
+9
-0
src/core/ast.cpp
src/core/ast.cpp
+2
-1
src/core/cfg.cpp
src/core/cfg.cpp
+6
-3
src/core/cfg.h
src/core/cfg.h
+1
-4
src/jit.cpp
src/jit.cpp
+2
-2
src/runtime/str.cpp
src/runtime/str.cpp
+45
-0
test/tests/gcj_2014_1c_b.py
test/tests/gcj_2014_1c_b.py
+2
-1
test/tests/str_functions.py
test/tests/str_functions.py
+5
-0
No files found.
src/analysis/type_analysis.cpp
View file @
9a79b92c
...
...
@@ -54,6 +54,8 @@ static ConcreteCompilerType* unboxedType(ConcreteCompilerType* t) {
return
INT
;
if
(
t
==
BOXED_FLOAT
)
return
FLOAT
;
if
(
t
==
BOXED_BOOL
)
return
BOOL
;
return
t
;
}
...
...
src/codegen/compvars.cpp
View file @
9a79b92c
...
...
@@ -1154,6 +1154,18 @@ public:
return
new
ConcreteCompilerVariable
(
other_type
,
boxed
,
true
);
}
virtual
CompilerType
*
getattrType
(
const
std
::
string
*
attr
,
bool
cls_only
)
{
return
BOXED_BOOL
->
getattrType
(
attr
,
cls_only
);
}
virtual
CompilerVariable
*
getattr
(
IREmitter
&
emitter
,
const
OpInfo
&
info
,
VAR
*
var
,
const
std
::
string
*
attr
,
bool
cls_only
)
{
ConcreteCompilerVariable
*
converted
=
var
->
makeConverted
(
emitter
,
BOXED_BOOL
);
CompilerVariable
*
rtn
=
converted
->
getattr
(
emitter
,
info
,
attr
,
cls_only
);
converted
->
decvref
(
emitter
);
return
rtn
;
}
virtual
ConcreteCompilerType
*
getBoxType
()
{
return
BOXED_BOOL
;
}
};
ConcreteCompilerType
*
BOOL
=
new
BoolType
();
...
...
src/codegen/irgen/irgenerator.cpp
View file @
9a79b92c
...
...
@@ -572,6 +572,10 @@ private:
boxed_left
->
decvref
(
emitter
);
boxed_right
->
decvref
(
emitter
);
if
(
type
==
AST_TYPE
::
In
||
type
==
AST_TYPE
::
NotIn
||
type
==
AST_TYPE
::
Is
||
type
==
AST_TYPE
::
IsNot
)
{
return
unboxVar
(
BOXED_BOOL
,
rtn
,
true
);
}
return
new
ConcreteCompilerVariable
(
UNKNOWN
,
rtn
,
true
);
}
...
...
@@ -937,6 +941,11 @@ private:
ConcreteCompilerVariable
*
rtn
=
new
ConcreteCompilerVariable
(
FLOAT
,
unboxed
,
true
);
return
rtn
;
}
if
(
t
==
BOXED_BOOL
)
{
llvm
::
Value
*
unboxed
=
emitter
.
getBuilder
()
->
CreateCall
(
g
.
funcs
.
unboxBool
,
v
);
ConcreteCompilerVariable
*
rtn
=
new
ConcreteCompilerVariable
(
BOOL
,
unboxed
,
true
);
return
rtn
;
}
return
new
ConcreteCompilerVariable
(
t
,
v
,
grabbed
);
}
...
...
src/core/ast.cpp
View file @
9a79b92c
...
...
@@ -12,13 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "core/ast.h"
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <stdint.h>
#include <cassert>
#include "core/ast.h"
#include "core/cfg.h"
#define FUTURE_DIVISION 0
...
...
src/core/cfg.cpp
View file @
9a79b92c
...
...
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "core/cfg.h"
#include <algorithm>
#include <cstdio>
#include <cassert>
...
...
@@ -20,7 +22,6 @@
#include "core/options.h"
#include "core/ast.h"
#include "core/cfg.h"
//#undef VERBOSITY
//#define VERBOSITY(x) 2
...
...
@@ -1096,6 +1097,7 @@ public:
curblock
=
test_block
;
AST_Branch
*
br
=
makeBranch
(
remapExpr
(
node
->
test
));
CFGBlock
*
test_block_end
=
curblock
;
push_back
(
br
);
// We need a reference to this block early on so we can break to it,
...
...
@@ -1107,7 +1109,8 @@ public:
CFGBlock
*
body
=
cfg
->
addBlock
();
body
->
info
=
"while_body_start"
;
br
->
iftrue
=
body
;
test_block
->
connectTo
(
body
);
test_block_end
->
connectTo
(
body
);
curblock
=
body
;
for
(
int
i
=
0
;
i
<
node
->
body
.
size
();
i
++
)
{
node
->
body
[
i
]
->
accept
(
this
);
...
...
@@ -1123,7 +1126,7 @@ public:
CFGBlock
*
orelse
=
cfg
->
addBlock
();
orelse
->
info
=
"while_orelse_start"
;
br
->
iffalse
=
orelse
;
test_block
->
connectTo
(
orelse
);
test_block
_end
->
connectTo
(
orelse
);
curblock
=
orelse
;
for
(
int
i
=
0
;
i
<
node
->
orelse
.
size
();
i
++
)
{
node
->
orelse
[
i
]
->
accept
(
this
);
...
...
src/core/cfg.h
View file @
9a79b92c
...
...
@@ -29,16 +29,13 @@
#include <vector>
#include "core/ast.h"
#include "core/common.h"
namespace
pyston
{
class
AST_stmt
;
namespace
AST_TYPE
{
enum
AST_TYPE
;
}
class
CFG
;
class
CFGBlock
{
private:
...
...
src/jit.cpp
View file @
9a79b92c
...
...
@@ -138,9 +138,9 @@ int main(int argc, char** argv) {
m
=
parse
(
fn
);
if
(
VERBOSITY
()
>=
1
)
{
fprintf
(
stderr
,
"Parsed code; ast:
\n
"
);
printf
(
"Parsed code; ast:
\n
"
);
print_ast
(
m
);
fprintf
(
stderr
,
"==============
\n
"
);
printf
(
"==============
\n
"
);
}
try
{
...
...
src/runtime/str.cpp
View file @
9a79b92c
...
...
@@ -383,6 +383,49 @@ Box* strSplit2(BoxedString* self, BoxedString* sep) {
}
}
Box
*
strStrip
(
BoxedString
*
self
)
{
assert
(
self
->
cls
==
str_cls
);
const
std
::
string
&
s
=
self
->
s
;
int
n
=
s
.
size
();
int
strip_beginning
=
0
;
while
(
strip_beginning
<
n
)
{
char
c
=
s
[
strip_beginning
];
if
(
c
==
' '
||
c
==
'\t'
||
c
==
'\n'
||
c
==
'\r'
||
c
==
'\f'
||
c
==
'\v'
)
strip_beginning
++
;
else
break
;
}
if
(
strip_beginning
==
n
)
return
boxStrConstant
(
""
);
int
strip_end
=
0
;
while
(
strip_end
<
n
)
{
char
c
=
s
[
n
-
strip_end
-
1
];
if
(
c
==
' '
||
c
==
'\t'
||
c
==
'\n'
||
c
==
'\r'
||
c
==
'\f'
||
c
==
'\v'
)
strip_end
++
;
else
break
;
}
return
new
BoxedString
(
s
.
substr
(
strip_beginning
,
n
-
strip_beginning
-
strip_end
));
}
Box
*
strContains
(
BoxedString
*
self
,
Box
*
elt
)
{
assert
(
self
->
cls
==
str_cls
);
if
(
elt
->
cls
!=
str_cls
)
raiseExcHelper
(
TypeError
,
"'in <string>' requires string as left operand, not %s"
,
getTypeName
(
elt
)
->
c_str
());
BoxedString
*
sub
=
static_cast
<
BoxedString
*>
(
elt
);
size_t
found_idx
=
self
->
s
.
find
(
sub
->
s
);
if
(
found_idx
==
std
::
string
::
npos
)
return
False
;
return
True
;
}
extern
"C"
Box
*
strGetitem
(
BoxedString
*
self
,
Box
*
slice
)
{
if
(
slice
->
cls
==
int_cls
)
{
...
...
@@ -419,6 +462,8 @@ void setupStr() {
str_cls
->
giveAttr
(
"__nonzero__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
strNonzero
,
NULL
,
1
,
false
)));
str_cls
->
giveAttr
(
"lower"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
strLower
,
STR
,
1
,
false
)));
str_cls
->
giveAttr
(
"strip"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
strStrip
,
STR
,
1
,
false
)));
str_cls
->
giveAttr
(
"__contains__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
strContains
,
BOXED_BOOL
,
2
,
false
)));
str_cls
->
giveAttr
(
"__add__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
strAdd
,
NULL
,
2
,
false
)));
str_cls
->
giveAttr
(
"__mod__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
strMod
,
NULL
,
2
,
false
)));
...
...
test/tests/gcj_2014_1
a
_b.py
→
test/tests/gcj_2014_1
c
_b.py
View file @
9a79b92c
...
...
@@ -12,7 +12,8 @@ def compact(s):
i
+=
1
return
s
class
NotPossible
(
Exception
):
# TODO This should be a subclass of Exception not object:
class
NotPossible
(
object
):
pass
P
=
1000000007
...
...
test/tests/str_functions.py
View file @
9a79b92c
...
...
@@ -19,3 +19,8 @@ print map(bool, ["hello", "", "world"])
if
""
:
print
"bad"
print
repr
(
"
\
t
\
n
\
v
\
f
test
\
t
\
n
\
v
\
f
"
.
strip
())
for
pattern
in
[
"hello"
,
"o w"
,
"nope"
]:
print
pattern
in
"hello world"
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