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
Anders Blomdell
LabComm
Commits
86728095
Commit
86728095
authored
Oct 25, 2014
by
Sven Gestegård Robertz
Browse files
migrated example from metadata branch. commented out broken python encoder
parent
dbcb1907
Changes
10
Hide whitespace changes
Inline
Side-by-side
doc/pragma-skiss.txt
View file @
86728095
...
...
@@ -21,9 +21,9 @@ TODO:
my_lc_some_pragma sp;
sp.some_refs = {&labcomm_signature_my_lc_foo,
&labcomm_signature_my_lc_bar};
sp.some_refs = {&labcomm_signature_my_lc_foo,
&labcomm_signature_my_lc_bar};
labcomm_encode_my_lc_some_pragma(enc, &sp);
This is to avoid exposing local_to_remote and remote_to_local
...
...
examples/simple/compile.sh
View file @
86728095
...
...
@@ -5,7 +5,7 @@
(
cd
../..
;
make all
)
mkdir
-p
gen
java
-jar
../../compiler/lab
C
omm.jar
--java
=
gen
--c
=
gen/simple.c
--h
=
gen/simple.h
--python
=
gen/simple.py simple.lc
java
-jar
../../compiler/lab
c
omm
_compiler
.jar
--java
=
gen
--c
=
gen/simple.c
--h
=
gen/simple.h
--python
=
gen/simple.py simple.lc
javac
-cp
../../lib/java/labcomm20141009.jar:. gen/
*
.java Encoder.java Decoder.java
...
...
@@ -20,7 +20,7 @@ gcc -Wall -Werror -I . -I ../../lib/c -L../../lib/c \
# For version 2006
mkdir
-p
gen06
java
-jar
../../compiler/lab
C
omm.jar
--ver
=
2006
--java
=
gen06
--c
=
gen06/simple.c
--h
=
gen06/simple.h
--python
=
gen06/simple.py simple.lc
java
-jar
../../compiler/lab
c
omm
_compiler
.jar
--ver
=
2006
--java
=
gen06
--c
=
gen06/simple.c
--h
=
gen06/simple.h
--python
=
gen06/simple.py simple.lc
javac
-cp
../../lib/java/labcomm2006.jar:. gen06/
*
.java Encoder06.java Decoder06.java
...
...
examples/user_types/Decoder.java
View file @
86728095
...
...
@@ -5,7 +5,7 @@ import java.io.InputStream;
import
se.lth.control.labcomm.DecoderChannel
;
public
class
Decoder
implements
twoLines
.
Handler
implements
twoLines
.
Handler
,
theint
.
Handler
,
Comment
.
Handler
//, Typedef.Handler
{
...
...
@@ -16,6 +16,9 @@ public class Decoder
{
decoder
=
new
DecoderChannel
(
in
);
twoLines
.
register
(
decoder
,
this
);
theint
.
register
(
decoder
,
this
);
Comment
.
register
(
decoder
,
this
);
//Typedef.register(decoder, this);
try
{
System
.
out
.
println
(
"Running decoder."
);
...
...
@@ -39,6 +42,20 @@ public class Decoder
System
.
out
.
println
(
" Line l2: "
+
genLine
(
d
.
l2
));
}
public
void
handle_theint
(
int
d
)
throws
java
.
io
.
IOException
{
System
.
out
.
println
(
"Got theint: "
+
d
);
}
public
void
handle_Comment
(
Comment
c
)
throws
java
.
io
.
IOException
{
System
.
out
.
print
(
"Decoder got Comment: "
);
System
.
out
.
println
(
"id: "
+
c
.
id
);
System
.
out
.
println
(
"comment: "
+
c
.
comment
);
}
//public void handle_Typedef(Typedef t) throws java.io.IOException {
// System.out.print("Decoder got Typedef: ");
// t.dump();
//}
public
static
void
main
(
String
[]
arg
)
throws
Exception
{
Decoder
example
=
new
Decoder
(
...
...
examples/user_types/Encoder.java
View file @
86728095
...
...
@@ -5,18 +5,31 @@ import java.io.OutputStream;
import
se.lth.control.labcomm.EncoderChannel
;
/**
* Simple encoder
* Simple encoder
*/
public
class
Encoder
public
class
Encoder
{
EncoderChannel
encoder
;
public
Encoder
(
OutputStream
out
)
throws
Exception
public
Encoder
(
OutputStream
out
)
throws
Exception
{
encoder
=
new
EncoderChannel
(
out
);
twoLines
.
register
(
encoder
);
theint
.
register
(
encoder
);
//LabCommEncoder.MetaDataTransaction t = encoder.beginMetaData(twoLines.class);
////LabCommEncoder.MetaDataTransaction t = encoder.beginMetaData();
//Comment.register(t, false);
//Comment c = new Comment();
//c.id = encoder.getTypeId(twoLines.class);
//c.comment = "Test comment";
//Comment.encode(t,c);
//t.commit();
//t = encoder.beginMetaData(null);
//afoo.register(t, false);
//afoo.encode(t, new foo());
//t.commit();
}
public
void
doEncode
()
throws
java
.
io
.
IOException
{
...
...
@@ -31,7 +44,7 @@ public class Encoder
p11
.
y
=
c11y
;
l1
.
start
=
p11
;
point
p12
=
new
point
();
coord
c12x
=
new
coord
();
coord
c12y
=
new
coord
();
...
...
@@ -52,7 +65,7 @@ public class Encoder
p21
.
y
=
c21y
;
l2
.
start
=
p21
;
point
p22
=
new
point
();
coord
c22x
=
new
coord
();
coord
c22y
=
new
coord
();
...
...
@@ -74,6 +87,8 @@ public class Encoder
System
.
out
.
println
(
"Encoding theTwoLines"
);
twoLines
.
encode
(
encoder
,
x
);
theint
.
encode
(
encoder
,
1337
);
}
...
...
examples/user_types/Makefile
View file @
86728095
all
:
LCDIR
=
../..
LCCJAR
=
${LCDIR}
/compiler/labcomm_compiler.jar
# the LabComm compiler
LCLJAR
=
${LCDIR}
/lib/java/labcomm.jar
# the LabComm library
EXECUTABLES
=
example_encoder example_decoder Encoder.class Decoder.class Encoder.exe Decoder.exe
include
${LCDIR}/lib/c/os_compat.mk
GENDIR
=
gen
.PHONY
:
all cleanbuild clean distclean build run allall buildcs runwcs
all
:
cleanbuild run
allall
:
clean build buildcs runwcs
###############################################
### dependencies and parts ####################
###############################################
LCC
=
java
-jar
${LCCJAR}
CLASSPATH
=
.:
${LCLJAR}
${LCCJAR}
:
$MAKE
-C
${LCDIR}
make-compiler
${LCLJAR}
:
$MAKE
-C
${LCDIR}
labcomm.jar
cleanbuild
:
clean build
labcomm.dll
:
ln
-sf
../../lib/csharp/labcomm.dll
$@
Encoder.exe
:
Encoder.cs gen/test.cs labcomm.dll Makefile
mcs
-out
:
$@
$(
filter
%.cs,
$^
)
-lib
:../../lib/csharp/
-r
:labcomm
chmod
a+x
$@
Decoder.exe
:
Decoder.cs gen/test.cs labcomm.dll Makefile
mcs
-out
:
$@
$(
filter
%.cs,
$^
)
-lib
:../../lib/csharp/
-r
:labcomm
chmod
a+x
$@
build
:
mkdir
-p
${GENDIR}
java
-jar
${LCDIR}
/compiler/labcomm_compiler.jar
--java
=
${GENDIR}
--c
=
${GENDIR}
/test.c
--h
=
${GENDIR}
/test.h
--python
=
${GENDIR}
/test.py
--cs
=
${GENDIR}
/test.cs test.lc
javac -cp ${LCDIR}/lib/java/labcomm.jar
:
. ${GENDIR}/*.java Encoder.java Decoder.java
${CC}
${CFLAGS}
${LDFLAGS}
-Wall
-Werror
-Wno-unused-function
\
-I.
-I${LCDIR}/lib/c
-L${LCDIR}/lib/c
\
-o
example_encoder
example_encoder.c
${GENDIR}/test.c
\
-llabcomm20141009
${CC}
${CFLAGS}
${LDFLAGS}
-Wall
-Werror
-I
.
-I
${LCDIR}/lib/c
-L${LCDIR}/lib/c
\
-o
example_decoder
example_decoder.c
${GENDIR}/test.c
\
-llabcomm20141009
buildcs
:
Encoder.exe Decoder.exe
run
:
export
LD_LIBRARY_PATH
=
${LCDIR}
/lib/c/
@
echo
@
echo
"********************************************"
@
echo
"*** ************ running example for version 2014 ***"
@
echo
"********************************************"
@
echo
@java -cp .
:
${LCDIR}/lib/java/labcomm.jar:${GENDIR} Encoder encoded_data_j
@echo "************ running Java decoder
:
*****************"
@
java
-cp
.:
${LCDIR}
/lib/java/labcomm.jar:
${GENDIR}
Decoder encoded_data_j
@echo "************ running C decoder
:
*****************"
@
./example_decoder encoded_data_j
@echo "************ running python decoder (from wiki_example)
:
"
@
PYTHONPATH
=
${LCDIR}
/lib/python ../wiki_example/example_decoder.py encoded_data_j LabComm20141009
@echo "************ running C encoder
:
*****************"
@
./example_encoder encoded_data_c
@echo "************ running Java decoder
:
*****************"
@
java
-cp
.:
${LCDIR}
/lib/java/labcomm.jar:
${GENDIR}
Decoder encoded_data_c
@echo "************ running C decoder
:
*****************"
@
./example_decoder encoded_data_c
@echo "************ running python decoder (from wiki_example)
:
"
@
PYTHONPATH
=
${LCDIR}
/lib/python ../wiki_example/example_decoder.py encoded_data_c LabComm20141009
# @echo "************ running python encoder: *****************"
# @PYTHONPATH=${LCDIR}/lib/python:${GENDIR} ./example_encoder.py encoded_data_p LabComm20141009
@echo "************ running Java decoder
:
*****************"
@
java
-cp
.:
${LCDIR}
/lib/java/labcomm.jar:
${GENDIR}
Decoder encoded_data_p
@echo "************ running C decoder
:
*****************"
@
./example_decoder encoded_data_p
@echo "************ running python decoder (from wiki_example)
:
"
PYTHONPATH
=
${LCDIR}
/lib/python ../wiki_example/example_decoder.py encoded_data_p LabComm20141009
runwcs
:
Encoder.exe Decoder.exe
export
LD_LIBRARY_PATH
=
${LCDIR}
/lib/c/
@
echo
@
echo
"********************************************"
@
echo
"*** ************ running example for version 2014 ***"
@
echo
"********************************************"
@
echo
@java -cp .
:
${LCDIR}/lib/java/labcomm.jar:${GENDIR} Encoder encoded_data_j
@echo "************ running Java decoder
:
*****************"
@
java
-cp
.:
${LCDIR}
/lib/java/labcomm.jar:
${GENDIR}
Decoder encoded_data_j
@echo "************ running C decoder
:
*****************"
@
./example_decoder encoded_data_j
@echo "************ running python decoder (from wiki_example)
:
"
@
PYTHONPATH
=
${LCDIR}
/lib/python ../wiki_example/example_decoder.py encoded_data_j LabComm2014
@echo "************ running C# decoder
:
*****************"
@
./Decoder.exe encoded_data_j
@echo "************ running C encoder
:
*****************"
@
./example_encoder encoded_data_c
@echo "************ running Java decoder
:
*****************"
@
java
-cp
.:
${LCDIR}
/lib/java/labcomm.jar:
${GENDIR}
Decoder encoded_data_c
@echo "************ running C decoder
:
*****************"
@
./example_decoder encoded_data_c
@echo "************ running python decoder (from wiki_example)
:
"
@
PYTHONPATH
=
${LCDIR}
/lib/python ../wiki_example/example_decoder.py encoded_data_c LabComm20141009
@echo "************ running C# decoder
:
*****************"
@
./Decoder.exe encoded_data_c
# @echo "************ running python encoder: *****************"
# @PYTHONPATH=${LCDIR}/lib/python:${GENDIR} ./example_encoder.py encoded_data_p LabComm20141009
@echo "************ running Java decoder
:
*****************"
@
java
-cp
.:
${LCDIR}
/lib/java/labcomm.jar:
${GENDIR}
Decoder encoded_data_p
@echo "************ running C decoder
:
*****************"
@
./example_decoder encoded_data_p
@echo "************ running python decoder (from wiki_example)
:
"
PYTHONPATH
=
${LCDIR}
/lib/python ../wiki_example/example_decoder.py encoded_data_p LabComm20141009
@echo "************ running C# decoder
:
*****************"
@
./Decoder.exe encoded_data_p
@echo "************ running C# encoder
:
*****************"
@
./Encoder.exe encoded_data_cs
@echo "************ running Java decoder
:
*****************"
@
java
-cp
.:
${LCDIR}
/lib/java/labcomm.jar:
${GENDIR}
Decoder encoded_data_cs
@echo "************ running C decoder
:
*****************"
@
./example_decoder encoded_data_cs
@echo "************ running python decoder (from wiki_example)
:
"
@
PYTHONPATH
=
${LCDIR}
/lib/python ../wiki_example/example_decoder.py encoded_data_cs LabComm20141009
@echo "************ running C# decoder
:
*****************"
@
./Decoder.exe encoded_data_cs
clean
:
rm
-rf
${GENDIR}
distclean
:
rm
-rf
gen
rm
-f
encoded_data
distclean
:
clean
rm
-f
${EXECUTABLES}
examples/user_types/compile.sh
deleted
100644 → 0
View file @
dbcb1907
### Example compile script, showing the steps required to build a labcomm application
### (including compiler and libs).
# For current version (2013)
(
cd
../..
;
make all
)
mkdir
-p
gen
java
-jar
../../compiler/labComm.jar
--java
=
gen
--c
=
gen/test.c
--h
=
gen/test.h
--python
=
gen/test.py test.lc
javac
-cp
../../lib/java/labcomm20141009.jar:. gen/
*
.java Encoder.java Decoder.java
# for macOS, add -DLABCOMM_COMPAT=\"labcomm_compat_osx.h\" \
gcc
-Wall
-Werror
-Wno-unused-function
\
-I
.
-I
../../lib/c
-L
../../lib/c
\
-o
example_encoder example_encoder.c gen/test.c
\
-llabcomm20141009
gcc
-Wall
-Werror
-I
.
-I
../../lib/c
-L
../../lib/c
\
-o
example_decoder example_decoder.c gen/test.c
\
-llabcomm20141009
#-Tlabcomm.linkscript
examples/user_types/example_decoder.c
View file @
86728095
...
...
@@ -15,6 +15,14 @@ static void handle_test_twoLines(test_twoLines *v,void *context) {
v
->
l2
.
end
.
x
.
val
,
v
->
l2
.
end
.
y
.
val
);
}
static
void
handle_test_theint
(
test_theint
*
v
,
void
*
context
)
{
printf
(
"Got theint. %d
\n
"
,
*
v
);
}
static
void
handle_test_Comment
(
test_Comment
*
v
,
void
*
context
)
{
printf
(
"Got comment (0x%x): %s
\n
"
,
v
->
id
,
v
->
comment
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
fd
;
struct
labcomm_decoder
*
decoder
;
...
...
@@ -34,6 +42,8 @@ int main(int argc, char *argv[]) {
}
labcomm_decoder_register_test_twoLines
(
decoder
,
handle_test_twoLines
,
context
);
labcomm_decoder_register_test_theint
(
decoder
,
handle_test_theint
,
context
);
labcomm_decoder_register_test_Comment
(
decoder
,
handle_test_Comment
,
context
);
printf
(
"Decoding:
\n
"
);
labcomm_decoder_run
(
decoder
);
...
...
examples/user_types/example_encoder.c
View file @
86728095
...
...
@@ -8,6 +8,7 @@
#include
"gen/test.h"
#include
<stdio.h>
extern
struct
labcomm_signature
labcomm_signature_test_twoLines
;
int
main
(
int
argc
,
char
*
argv
[])
{
int
fd
;
struct
labcomm_encoder
*
encoder
;
...
...
@@ -22,6 +23,16 @@ int main(int argc, char *argv[]) {
labcomm_default_scheduler
);
labcomm_encoder_register_test_twoLines
(
encoder
);
#ifdef OLD_METADATA
struct
labcomm_encoder
*
mdt
=
labcomm_metadata_begin
(
encoder
,
&
labcomm_signature_test_twoLines
);
labcomm_encoder_register_test_Comment
(
mdt
);
test_Comment
comment
;
comment
.
id
=
17
;
comment
.
comment
=
"This is a metadata comment..."
;
labcomm_encode_test_Comment
(
mdt
,
&
comment
);
labcomm_metadata_end
(
mdt
);
#endif
test_twoLines
tl
;
tl
.
l1
.
start
.
x
.
val
=
11
;
...
...
examples/user_types/run.sh
deleted
100644 → 0
View file @
dbcb1907
export
LD_LIBRARY_PATH
=
../../lib/c/
echo
echo
"********************************************"
echo
"*** Running example for version 2013 ***"
echo
"********************************************"
echo
java
-cp
.:../../lib/java/labcomm20141009.jar:gen Encoder encoded_data
echo
"running Java decoder:"
java
-cp
.:../../lib/java/labcomm20141009.jar:gen Decoder encoded_data
echo
"running C decoder:"
./example_decoder encoded_data
echo
"running python decoder (from wiki_example):"
PYTHONPATH
=
../../lib/python ../wiki_example/example_decoder.py encoded_data LabComm20141009
echo
"running C encoder:"
./example_encoder encoded_data
echo
"running Java decoder:"
java
-cp
.:../../lib/java/labcomm20141009.jar:gen Decoder encoded_data
echo
"running C decoder:"
./example_decoder encoded_data
echo
"running python decoder (from wiki_example):"
PYTHONPATH
=
../../lib/python ../wiki_example/example_decoder.py encoded_data LabComm20141009
echo
"running python encoder:"
PYTHONPATH
=
../../lib/python:gen ./example_encoder.py encoded_data2
echo
"running Java decoder:"
java
-cp
.:../../lib/java/labcomm20141009.jar:gen Decoder encoded_data2
echo
"running C decoder:"
./example_decoder encoded_data2
examples/user_types/test.lc
View file @
86728095
...
...
@@ -12,14 +12,34 @@ typedef struct {
point end;
} line;
typedef int anint;
typedef struct {
int a;
int b;
an
int a;
an
int b;
boolean c;
} foo;
sample anint theint;
sample struct {
line l1;
line l2;
foo f;
} twoLines;
sample line fixedLineArray[2];
sample line varLineArray[_];
sample struct {
int x;
int y;
} structArray[2];
sample struct {
int id;
string comment;
} Comment; // For use in metadata
sample foo afoo; // to test unregistered metadata
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