add example C program which generates (de)marshaling with ldmc
This commit is contained in:
parent
27ea365755
commit
1116457bcc
3 changed files with 38 additions and 0 deletions
examples/01-uint-example
1
examples/01-uint-example/.gitignore
vendored
Normal file
1
examples/01-uint-example/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
build/
|
14
examples/01-uint-example/main.c
Normal file
14
examples/01-uint-example/main.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include "morphisms.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if( argc > 1 ) {
|
||||
uint64_t value;
|
||||
demarshal( argv[1], &value );
|
||||
|
||||
uint64_t result = value * value;
|
||||
|
||||
char buf[256];
|
||||
marshal( &result, buf );
|
||||
printf("%s\n", buf);
|
||||
}
|
||||
}
|
23
examples/01-uint-example/makefile
Normal file
23
examples/01-uint-example/makefile
Normal file
|
@ -0,0 +1,23 @@
|
|||
all: build/square
|
||||
.PHONY: build clean
|
||||
|
||||
build:
|
||||
mkdir -p build
|
||||
|
||||
build/morphisms.h: build
|
||||
ldmc \
|
||||
-m "marshal: \
|
||||
ℕ ~ native.UInt64 \
|
||||
--> ℕ ~ <PosInt 10 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 10>~Char~Ascii~native.UInt8>" \
|
||||
\
|
||||
-m "demarshal: \
|
||||
ℕ ~ <PosInt 10 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 10>~Char~Ascii~native.UInt8> \
|
||||
--> ℕ ~ native.UInt64 " \
|
||||
\
|
||||
>| build/morphisms.h
|
||||
|
||||
build/square: build build/morphisms.h
|
||||
gcc -Os -I../../morphisms/runtime/include/ -Ibuild main.c -o build/square
|
||||
|
||||
clean:
|
||||
rm build/ -rf
|
Loading…
Add table
Add a link
Reference in a new issue