Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sven Gestegård Robertz
LabComm
Commits
9b70aa01
Commit
9b70aa01
authored
Feb 26, 2015
by
Anders Blomdell
Browse files
Removed some redundancy from generated python code, made
list of samples immutable (tuple instead of list).
parent
84f40041
Changes
3
Hide whitespace changes
Inline
Side-by-side
compiler/2014/Python_CodeGen.jrag
View file @
9b70aa01
...
...
@@ -91,13 +91,13 @@ aspect Python_CodeGen {
//}
//env.unindent();
//env.println("]");
env.println("sample = [");
env.println("sample =
tuple(
[");
env.indent();
for (int i = 0 ; i < getNumDecl() ; i++) {
getDecl(i).Python_genSampleListEntry(env);
}
env.unindent();
env.println("]");
env.println("]
)
");
}
}
...
...
@@ -211,7 +211,7 @@ aspect PythonTypes {
}
public void SampleDecl.Python_genSampleListEntry(Python_env env) {
env.println(
"('" +
getName()
+ "
', " + getName() + ".signature)
,");
env.println(getName()+ ",");
}
public String Exp.Python_getValue() {
...
...
lib/python/labcomm/LabComm.py
View file @
9b70aa01
...
...
@@ -219,10 +219,16 @@ class length_encoder:
def
indent
(
i
,
s
):
return
(
"
\n
%s"
%
(
" "
*
i
)).
join
(
s
.
split
(
"
\n
"
))
#
# Base type for all decl's
#
class
type_decl
(
object
):
pass
#
# Primitive types
#
class
primitive
(
obj
ec
t
):
class
primitive
(
type_d
ec
l
):
def
decode_decl
(
self
,
decoder
):
return
self
...
...
@@ -383,7 +389,7 @@ class SAMPLE(primitive):
#
# Aggregate types
#
class
sample_def_or_ref
(
obj
ec
t
):
class
sample_def_or_ref
(
type_d
ec
l
):
def
__init__
(
self
,
name
=
None
,
decl
=
None
):
self
.
name
=
name
self
.
decl
=
decl
...
...
@@ -460,7 +466,7 @@ class sample_ref(sample_def_or_ref):
def
add_index
(
self
,
decoder
,
index
,
decl
):
decoder
.
add_ref
(
decl
,
index
)
class
array
(
obj
ec
t
):
class
array
(
type_d
ec
l
):
def
__init__
(
self
,
indices
,
decl
):
self
.
indices
=
tuple
(
indices
)
self
.
decl
=
decl
...
...
@@ -587,7 +593,7 @@ class array(object):
return
"labcomm.array(%s,
\n
%s)"
%
(
self
.
indices
,
indent
(
4
,
self
.
decl
.
__repr__
()))
class
struct
:
class
struct
(
type_decl
)
:
def
__init__
(
self
,
field
):
self
.
field
=
tuple
(
field
)
...
...
@@ -759,6 +765,8 @@ class Encoder(Codec):
self
.
writer
.
write
(
packer
.
pack
(
format
,
*
args
))
def
add_decl
(
self
,
decl
,
index
=
0
):
if
not
isinstance
(
decl
,
type_decl
):
decl
=
decl
.
signature
if
index
==
0
:
self
.
writer
.
mark_begin
(
decl
,
None
)
if
super
(
Encoder
,
self
).
add_decl
(
decl
,
index
):
...
...
@@ -766,6 +774,8 @@ class Encoder(Codec):
self
.
writer
.
mark_end
(
decl
,
None
)
def
add_ref
(
self
,
decl
,
index
=
0
):
if
not
isinstance
(
decl
,
type_decl
):
decl
=
decl
.
signature
ref
=
sample_ref
(
name
=
decl
.
name
,
decl
=
decl
.
decl
,
sample
=
decl
)
if
index
==
0
:
self
.
writer
.
mark_begin
(
decl
,
None
)
...
...
@@ -777,6 +787,8 @@ class Encoder(Codec):
if
decl
==
None
:
name
=
self
.
type_to_name
[
object
.
__class__
]
decl
=
self
.
name_to_decl
[
name
]
if
not
isinstance
(
decl
,
type_decl
):
decl
=
decl
.
signature
self
.
writer
.
mark_begin
(
decl
,
object
)
self
.
encode_type_number
(
decl
)
with
length_encoder
(
self
)
as
e
:
...
...
test/test_encoder_decoder.py
View file @
9b70aa01
...
...
@@ -37,7 +37,7 @@ def get_signatures(path):
with
fp
as
fp
:
m
=
imp
.
load_module
(
'signatures'
,
fp
,
pathname
,
description
)
pass
return
m
.
sample
return
map
(
lambda
s
:
s
.
signature
,
m
.
sample
)
class
Test
:
...
...
@@ -117,7 +117,7 @@ class Test:
return
[
'string'
,
u
'sträng'
]
elif
decl
.
__class__
==
labcomm
.
SAMPLE
:
return
[
s
for
n
,
s
in
self
.
signatures
]
return
self
.
signatures
print
>>
sys
.
stderr
,
decl
raise
Exception
(
"unhandled decl %s"
%
decl
.
__class__
)
...
...
@@ -154,14 +154,14 @@ class Test:
decoder
=
threading
.
Thread
(
target
=
self
.
decode
,
args
=
(
p
.
stdout
,))
decoder
.
start
()
encoder
=
labcomm
.
Encoder
(
labcomm
.
StreamWriter
(
p
.
stdin
))
for
name
,
signature
in
self
.
signatures
:
for
signature
in
self
.
signatures
:
encoder
.
add_decl
(
signature
)
pass
if
self
.
uses_refs
(
[
s
for
n
,
s
in
self
.
signatures
]
):
for
name
,
signature
in
self
.
signatures
:
if
self
.
uses_refs
(
self
.
signatures
):
for
signature
in
self
.
signatures
:
encoder
.
add_ref
(
signature
)
for
name
,
signature
in
self
.
signatures
:
print
>>
sys
.
stderr
,
"Checking"
,
name
,
for
signature
in
self
.
signatures
:
print
>>
sys
.
stderr
,
"Checking"
,
signature
.
name
,
for
decl
,
value
in
self
.
generate
(
signature
):
sys
.
stderr
.
write
(
'.'
)
#print name,decl,value,value.__class__
...
...
Write
Preview
Supports
Markdown
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