exemplaric platform definitions

This commit is contained in:
Michael Sippel 2025-03-31 10:29:57 +02:00
parent bce52e9fcf
commit d98afc294d
Signed by: senvas
GPG key ID: F96CF119C34B64A6
5 changed files with 108 additions and 0 deletions

100
platforms/json.lt Normal file
View 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
View file

3
platforms/protobuf.lt Normal file
View 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
View file

5
platforms/x86.lt Normal file
View 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>;