Compare commits

...

2 commits

8 changed files with 146 additions and 38 deletions

View file

@ -3,16 +3,16 @@
```
morph_angle_as_degrees_to_turns_float ()
Angle ~ Degrees ~ ~ native.Float
--> Angle ~ Turns ~ ~ native.Float
Angle ~ Degrees ~ ~ native.Float32
--> Angle ~ Turns ~ ~ native.Float32
```
*dst = *src / 360.0;
return 0;
```
morph_angle_as_degrees_to_turns_double ()
Angle ~ Degrees ~ ~ native.Double
--> Angle ~ Turns ~ ~ native.Double
Angle ~ Degrees ~ ~ native.Float64
--> Angle ~ Turns ~ ~ native.Float64
```
*dst = *src / 360.0;
return 0;
@ -20,16 +20,16 @@ morph_angle_as_degrees_to_turns_double ()
morph_angle_as_turns_to_degrees_float ()
Angle ~ Turns ~ ~ native.Float
--> Angle ~ Degrees ~ ~ native.Float
Angle ~ Turns ~ ~ native.Float32
--> Angle ~ Degrees ~ ~ native.Float32
```
*dst = *src * 360.0;
return 0;
```
morph_angle_as_turns_to_degrees_double ()
Angle ~ Turns ~ ~ native.Double
--> Angle ~ Degrees ~ ~ native.Double
Angle ~ Turns ~ ~ native.Float64
--> Angle ~ Degrees ~ ~ native.Float64
```
*dst = *src * 360.0;
return 0;
@ -39,16 +39,16 @@ morph_angle_as_turns_to_degrees_double ()
morph_angle_as_radians_to_turns_float ()
Angle ~ Radians ~ ~ native.Float
--> Angle ~ Turns ~ ~ native.Float
Angle ~ Radians ~ ~ native.Float32
--> Angle ~ Turns ~ ~ native.Float32
```
*dst = *src / PHI;
return 0;
```
morph_angle_as_radians_to_turns_double ()
Angle ~ Radians ~ ~ native.Double
--> Angle ~ Turns ~ ~ native.Double
Angle ~ Radians ~ ~ native.Float64
--> Angle ~ Turns ~ ~ native.Float64
```
*dst = *src / PHI;
return 0;
@ -56,16 +56,16 @@ morph_angle_as_radians_to_turns_double ()
morph_angle_as_turns_to_radians_float ()
Angle ~ Turns ~ ~ native.Float
--> Angle ~ Radians ~ ~ native.Float
Angle ~ Turns ~ ~ native.Float32
--> Angle ~ Radians ~ ~ native.Float32
```
*dst = *src * PHI;
return 0;
```
morph_angle_as_degrees_to_radians_double ()
Angle ~ Turns ~ ~ native.Double
--> Angle ~ Radians ~ ~ native.Double
Angle ~ Turns ~ ~ native.Float64
--> Angle ~ Radians ~ ~ native.Float64
```
*dst = *src * PHI;
return 0;

View file

@ -4,7 +4,7 @@
morph_real_as_decimalstr_to_float ()
~ <PosInt 10 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 10>~Char~Ascii~native.UInt8>
--> ~ native.Float
--> ~ native.Float32
```
sscanf(src, "%f", dst);
return 0;
@ -12,14 +12,14 @@ morph_real_as_decimalstr_to_float ()
morph_real_as_decimalstr_to_double ()
~ <PosInt 10 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 10>~Char~Ascii~native.UInt8>
--> ~ native.Double
--> ~ native.Float64
```
sscanf(src, "%lf", dst);
return 0;
```
morph_real_as_float_to_decimalstr ()
~ native.Float
~ native.Float32
--> ~ <PosInt 10 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 10>~Char~Ascii~native.UInt8>
```
sprintf(dst, "%f", *src);
@ -27,7 +27,7 @@ morph_real_as_float_to_decimalstr ()
```
morph_real_as_double_to_decimalstr ()
~ native.Double
~ native.Float64
--> ~ <PosInt 10 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 10>~Char~Ascii~native.UInt8>
```
sprintf(dst, "%f", *src);
@ -36,16 +36,16 @@ morph_real_as_double_to_decimalstr ()
morph_real_as_float_to_double ()
~ native.Float
--> ~ native.Double
~ native.Float32
--> ~ native.Float64
```
*dst = *src;
return 0;
```
morph_real_as_double_to_float ()
~ native.Double
--> ~ native.Float
~ native.Float64
--> ~ native.Float32
```
fprintf(stderr, "Warning: morphin Double -> Float. Precision loss!");
*dst = *src;
@ -54,7 +54,7 @@ morph_real_as_double_to_float ()
morph_real_as_u64_to_float ()
~ ~ native.UInt64
--> ~ native.Float
--> ~ native.Float32
```
fprintf(stderr, "Warning: morphin UInt64 -> Float. Precision loss!");
*dst = *src;
@ -63,7 +63,7 @@ morph_real_as_u64_to_float ()
morph_real_as_u64_to_double ()
~ ~ native.UInt64
--> ~ native.Double
--> ~ native.Float64
```
fprintf(stderr, "Warning: morphin UInt64 -> Double. Precision loss!");
*dst = *src;
@ -72,14 +72,14 @@ morph_real_as_u64_to_double ()
morph_real_as_quantized_linear_to_float (Begin: , End: , Steps: )
~ <QuantizedLinear Begin End Steps> ~ ~ native.UInt64
--> ~ native.Float
--> ~ native.Float32
```
*dst = (float)Begin + ( *src * ((float)End - (float)Begin) ) / (float)Steps;
return 0;
```
morph_real_as_float_to_quantized_linear (Begin: , End: , Steps: )
~ native.Float
~ native.Float32
--> ~ <QuantizedLinear Begin End Steps> ~ ~ native.UInt64
```
*dst = ((*src - (float)Begin) * (float)Steps) / ((float)End - (float)Begin);
@ -90,14 +90,14 @@ morph_real_as_float_to_quantized_linear (Begin: , End: , Steps: )
morph_real_as_quantized_linear_to_double (Begin: , End: , Steps: )
~ <QuantizedLinear Begin End Steps> ~ ~ native.UInt64
--> ~ native.Double
--> ~ native.Float64
```
*dst = (double)Begin + ( *src * ((double)End - (double)Begin) ) / (double)Steps;
return 0;
```
morph_real_as_double_to_quantized_linear (Begin: , End: , Steps: )
~ native.Double
~ native.Float64
--> ~ <QuantizedLinear Begin End Steps> ~ ~ native.UInt64
```
*dst = ((*src - (double)Begin) * (double)Steps) / ((double)End - (double)Begin);

View file

@ -2,32 +2,32 @@
```
morph_celsius_to_kelvin ()
Temperature ~ Celsius ~ ~ native.Float
--> Temperature ~ Kelvin ~ ~ native.Float
Temperature ~ Celsius ~ ~ native.Float32
--> Temperature ~ Kelvin ~ ~ native.Float32
```
*dst = *src + 273.15;
return 0;
```
morph_kelvin_to_celsius ()
Temperature ~ Kelvin ~ ~ native.Float
--> Temperature ~ Celsius ~ ~ native.Float
Temperature ~ Kelvin ~ ~ native.Float32
--> Temperature ~ Celsius ~ ~ native.Float32
```
*dst = *src - 273.15;
return 0;
```
morph_celsius_to_fahrenheit ()
Temperature ~ Celsius ~ ~ native.Float
--> Temperature ~ Fahrenheit ~ ~ native.Float
Temperature ~ Celsius ~ ~ native.Float32
--> Temperature ~ Fahrenheit ~ ~ native.Float32
```
*dst = (*src * 9.0 / 5.0) + 32.0;
return 0;
```
morph_fahrenheit_to_celsius ()
Temperature ~ Fahrenheit ~ ~ native.Float
--> Temperature ~ Celsius ~ ~ native.Float
Temperature ~ Fahrenheit ~ ~ native.Float32
--> Temperature ~ Celsius ~ ~ native.Float32
```
*dst = (*src - 32.0) * 5.0 / 9.0;
return 0;

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>;