Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
x-RPySOM
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mu
x-RPySOM
Commits
de1f0fd7
Commit
de1f0fd7
authored
Sep 21, 2013
by
Stefan Marr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved StringStream to rlib
Signed-off-by:
Stefan Marr
<
git@stefan-marr.de
>
parent
d3e822d9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
41 deletions
+43
-41
src/rlib/string_stream.py
src/rlib/string_stream.py
+38
-0
src/som/compiler/sourcecode_compiler.py
src/som/compiler/sourcecode_compiler.py
+5
-41
No files found.
src/rlib/string_stream.py
0 → 100644
View file @
de1f0fd7
from
rpython.rlib.streamio
import
Stream
,
StreamError
class
StringStream
(
Stream
):
def
__init__
(
self
,
string
):
self
.
_string
=
string
self
.
pos
=
0
self
.
max
=
len
(
string
)
-
1
def
write
(
self
,
data
):
raise
StreamError
(
"StringStream is not writable"
)
def
truncate
(
self
,
size
):
raise
StreamError
(
"StringStream is immutable"
)
def
peek
(
self
):
if
self
.
pos
<
self
.
max
:
return
self
.
_string
[
self
.
pos
:]
else
:
return
''
def
tell
(
self
):
return
self
.
pos
def
seek
(
self
,
offset
,
whence
):
if
whence
==
0
:
self
.
pos
=
max
(
0
,
offset
)
elif
whence
==
1
:
self
.
pos
=
max
(
0
,
self
.
pos
+
offset
)
elif
whence
==
2
:
self
.
pos
=
max
(
0
,
self
.
max
+
offset
)
else
:
raise
StreamError
(
"seek(): whence must be 0, 1 or 2"
)
def
read
(
self
,
n
):
assert
isinstance
(
n
,
int
)
end
=
self
.
pos
+
n
data
=
self
.
_string
[
self
.
pos
:
end
]
self
.
pos
+=
len
(
data
)
return
data
\ No newline at end of file
src/som/compiler/sourcecode_compiler.py
View file @
de1f0fd7
import
os
from
rpython.rlib.streamio
import
open_file_as_stream
,
Stream
,
StreamError
from
rpython.rlib.streamio
import
open_file_as_stream
from
rlib.string_stream
import
StringStream
from
som.compiler.parser
import
Parser
from
som.compiler.class_generation_context
import
ClassGenerationContext
class
_StringStream
(
Stream
):
def
__init__
(
self
,
string
):
self
.
_string
=
string
self
.
pos
=
0
self
.
max
=
len
(
string
)
-
1
def
write
(
self
,
data
):
raise
StreamError
(
"StringStream is not writable"
)
def
truncate
(
self
,
size
):
raise
StreamError
(
"StringStream is immutable"
)
def
peek
(
self
):
if
self
.
pos
<
self
.
max
:
return
self
.
_string
[
self
.
pos
:]
else
:
return
''
def
tell
(
self
):
return
self
.
pos
def
seek
(
self
,
offset
,
whence
):
if
whence
==
0
:
self
.
pos
=
max
(
0
,
offset
)
elif
whence
==
1
:
self
.
pos
=
max
(
0
,
self
.
pos
+
offset
)
elif
whence
==
2
:
self
.
pos
=
max
(
0
,
self
.
max
+
offset
)
else
:
raise
StreamError
(
"seek(): whence must be 0, 1 or 2"
)
def
read
(
self
,
n
):
assert
isinstance
(
n
,
int
)
end
=
self
.
pos
+
n
data
=
self
.
_string
[
self
.
pos
:
end
]
self
.
pos
+=
len
(
data
)
return
data
def
compile_class_from_file
(
path
,
filename
,
system_class
,
universe
):
return
_SourcecodeCompiler
().
compile
(
path
,
filename
,
system_class
,
universe
)
...
...
@@ -64,7 +28,7 @@ class _SourcecodeCompiler(object):
result
=
self
.
_compile
(
system_class
,
universe
)
finally
:
input_file
.
close
()
except
OSError
as
e
:
except
OSError
:
raise
IOError
()
cname
=
result
.
get_name
()
...
...
@@ -76,7 +40,7 @@ class _SourcecodeCompiler(object):
return
result
def
compile_class_string
(
self
,
stream
,
system_class
,
universe
):
self
.
_parser
=
Parser
(
_
StringStream
(
stream
),
universe
)
self
.
_parser
=
Parser
(
StringStream
(
stream
),
universe
)
result
=
self
.
_compile
(
system_class
,
universe
)
return
result
...
...
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