exemplaric platform definitions
This commit is contained in:
parent
bce52e9fcf
commit
d98afc294d
5 changed files with 108 additions and 0 deletions
100
platforms/json.lt
Normal file
100
platforms/json.lt
Normal file
|
@ -0,0 +1,100 @@
|
|||
|
||||
type UTF8-String = <Seq Char~Unicode> ~ UTF-8 ~ <Seq~<ValueTerminated 0> native.UInt8> ;
|
||||
|
||||
type SerializedJson.Value = json.Value
|
||||
~ <Enum
|
||||
<Null json.Null ~ SerializedJson.Null >
|
||||
<String json.String ~ SerializedJson.String >
|
||||
<Number json.Number ~ SerializedJson.Number >
|
||||
<Bool json.Bool ~ SerializedJson.Bool >
|
||||
<Array json.Array ~ SerializedJson.Array >
|
||||
<Object json.Object ~ SerializedJson.Object >>
|
||||
~ <Seq Char> ;
|
||||
|
||||
type SerializedJson.Null = < Struct~<Seq Char> "\"null\"" > ;
|
||||
|
||||
type SerializedJson.String = <Seq Char>
|
||||
~ <Struct~<Seq Char> "\"" <Seq Char> "\"">
|
||||
~ <Seq Char> ;
|
||||
|
||||
type SerializedJson.Number = ℝ
|
||||
~ <PosInt 10 BigEndian>
|
||||
~ <Seq <Digit 10> ~ Char> ;
|
||||
|
||||
type SerializedJson.Bool = Bool
|
||||
~ <Enum~<Seq Char>
|
||||
<True~"\"true\"" <>>
|
||||
<False~"\"false\"" <>>>
|
||||
~ <Seq Char> ;
|
||||
|
||||
type SerializedJson.Array = <Struct~<Seq Char>
|
||||
"["
|
||||
<Seq json.Value>
|
||||
~ <ValueSep ',' Char>
|
||||
~ <Seq Char>
|
||||
"]" >
|
||||
~ <Seq Char> ;
|
||||
|
||||
type SerializedJson.Object = <Struct~<Seq Char>
|
||||
"{"
|
||||
<members <Seq
|
||||
<Struct~<Seq Char>
|
||||
<key json.String>
|
||||
":"
|
||||
<value json.Value>>>>
|
||||
"}"
|
||||
>
|
||||
~ <Seq Char>;
|
||||
|
||||
type parsedJson.Value = json.Value ~ <Enum~native.UInt8
|
||||
< parsedJson_Null~0 <> >
|
||||
< parsedJson_String~1 <Ref UTF8-String> ~ native.Address >
|
||||
< parsedJson_Int~2 ℝ~ℕ~native.UInt64 >
|
||||
< parsedJson_Float~2 ℝ~native.Float64 >
|
||||
< parsedJson_Bool~3 Bool ~ native.UInt8 >
|
||||
|
||||
< parsedJson_Array~4 <Ref <Seq ~ <LengthPrefix native.UInt64>
|
||||
parsedJsonValue
|
||||
>
|
||||
>
|
||||
~ native.Address >
|
||||
|
||||
< parsedJson_Object~5 <Ref <Seq ~ <LengthPrefix native.UInt64>
|
||||
<Struct
|
||||
<key <Ref UTF8-String> ~ native.Address>
|
||||
<val parsedJsonValue>
|
||||
>
|
||||
>
|
||||
~ native.Address >>
|
||||
~ <Struct
|
||||
<tag native.UInt8>
|
||||
native.UInt64 >;
|
||||
|
||||
parse_json_value ()
|
||||
json.Value ~ UTF8-String
|
||||
--> json.Value ~ parsedJsonValue
|
||||
```
|
||||
|
||||
{
|
||||
dst->tag = PARSED_JSON_NULL;
|
||||
dst->parsedJson_Null;
|
||||
}
|
||||
|
||||
{
|
||||
dst->tag = PARSED_JSON_STRING;
|
||||
dst->parsedJson_String = malloc(len);
|
||||
strncpy(dst->parsedJson_String, src, len);
|
||||
src += len;
|
||||
}
|
||||
|
||||
{
|
||||
dst->tag = PARSED_JSON_NUMBER;
|
||||
|
||||
MORPH(
|
||||
"ℝ ~ ℕ ~ <PosInt 10 BigEndian> ~ <Seq <Digit 10> ~ Char> ~ UTF8-String",
|
||||
"ℝ ~ ℕ ~ native.UInt64",
|
||||
src,
|
||||
&dst->parsedJson_Number
|
||||
);
|
||||
}
|
||||
```
|
0
platforms/json5.lt
Normal file
0
platforms/json5.lt
Normal file
3
platforms/protobuf.lt
Normal file
3
platforms/protobuf.lt
Normal file
|
@ -0,0 +1,3 @@
|
|||
|
||||
type protobuf.Varint = ℕ ~ <PosInt 128 LittleEndian> ~ <Seq~MsbCont <Digit 128> ~ ℤ_128 ~ native.UInt8> ;
|
||||
type protobuf.String = <Seq Char ~ Unicode> ~ UTF-8 ~ <Seq ~ <LengthPrefix protobuf.Varint> Byte> ;
|
0
platforms/spapod.lt
Normal file
0
platforms/spapod.lt
Normal file
5
platforms/x86.lt
Normal file
5
platforms/x86.lt
Normal file
|
@ -0,0 +1,5 @@
|
|||
|
||||
type x86.UInt64 = ℤ_2/\64 ~ <PosInt 256 LittleEndian> ~ <Seq~<StaticLength 8> <Digit 256> ~ x86.UInt8 >;
|
||||
type x86.UInt32 = ℤ_2/\32 ~ <PosInt 256 LittleEndian> ~ <Seq~<StaticLength 4> <Digit 256> ~ x86.UInt8 >;
|
||||
type x86.UInt16 = ℤ_2^16 ~ <PosInt 256 LittleEndian> ~ <Seq~<StaticLength 2> <Digit 256> ~ x86.UInt8 >;
|
||||
type x86.UInt8 = ℤ_256 ~ <Posint 2 BigEndian> ~ <Seq~<StaticLength 8> <Digit 2> ~ Bit>;
|
Loading…
Add table
Reference in a new issue