diff --git a/ddl/Generate.hs b/ddl/Generate.hs index a2e2191..3bdad9d 100644 --- a/ddl/Generate.hs +++ b/ddl/Generate.hs @@ -19,6 +19,7 @@ import Definitions import Language instance Unquote [Field] +instance Unquote [ConstructorDef] instance Unquote [Char] instance Quote [Char] instance Quote [Instance] @@ -31,6 +32,8 @@ main = do dataSwift <- eitherParseFile "templates/data.swift.ede" dataJava <- eitherParseFile "templates/data.java.ede" jsonJava <- eitherParseFile "templates/json.java.ede" + dataKt <- eitherParseFile "templates/data.kt.ede" + jsonKt <- eitherParseFile "templates/json.kt.ede" dataHpp <- eitherParseFile "templates/data.hpp.ede" dataHpp2 <- eitherParseFile "templates/data.hpp2.ede" dataCpp <- eitherParseFile "templates/data.cpp.ede" @@ -52,6 +55,7 @@ main = do mylib :: HashMap Text Term mylib = HashMap.fromList [ "hasFieldNames" @: hasFieldNames + , "nonSingular" @: nonSingular , "parens" @: parens , "constType" @: constType , "hsType" @: hsType aliasMap @@ -60,6 +64,7 @@ main = do , "csType" @: csType name aliasMap , "typeEnum" @: typeEnum aliasMap , "javaType" @: javaType aliasMap + , "ktType" @: ktType aliasMap , "swiftType" @: swiftType aliasMap , "hasEnumConstructor" @: hasEnumConstructor , "psInstances" @: filterInstances PureScript @@ -99,6 +104,9 @@ main = do fname = "out/java/" ++ toPath name ++ "/" ++ dataName d ++ ".java" either error (\x -> writeFileIfDiffer fname $ LText.unpack x) $ dataJava >>= (\t -> eitherRenderWith mylib t env) either error (\x -> writeFileIfDiffer ("out/java/" ++ toPath name ++ "/JSON.java") $ LText.unpack x) $ jsonJava >>= (\t -> eitherRenderWith mylib t env) + -- Kotlin + either error (\x -> writeFileIfDiffer ("out/kotlin/" ++ name ++ ".kt") $ LText.unpack x) $ dataKt >>= (\t -> eitherRenderWith mylib t env) + either error (\x -> writeFileIfDiffer "out/kotlin/JSON.kt" $ LText.unpack x) $ jsonKt >>= (\t -> eitherRenderWith mylib t env) -- C# either error (\x -> writeFileIfDiffer ("out/csharp/" ++ name ++ ".cs") $ LText.unpack x) $ dataCs >>= (\t -> eitherRenderWith mylib t env) -- Swift diff --git a/ddl/Language.hs b/ddl/Language.hs index 9701023..6f0c34d 100644 --- a/ddl/Language.hs +++ b/ddl/Language.hs @@ -268,6 +268,48 @@ javaType aliasMap a = case normalize aliasMap a of Maybe t -> "Maybe<" ++ parens (javaType aliasMap t) ++ ">" x -> error $ "javaType: " ++ show x +ktType :: AliasMap -> Type -> String +ktType aliasMap = \case + Int -> "Int" + Int32 -> "Int" + Word -> "Int" + Word32 -> "Int" + Float -> "Float" + Bool -> "Bool" + String -> "String" + + V2 Int -> "V2I" + V2 Word -> "V2U" + V2 Float -> "V2F" + V2 Bool -> "V2B" + V2 (V2 Float) -> "M22F" + V2 (V3 Float) -> "M32F" + V2 (V4 Float) -> "M42F" + + V3 Int -> "V3I" + V3 Word -> "V3U" + V3 Float -> "V3F" + V3 Bool -> "V3B" + V3 (V2 Float) -> "M23F" + V3 (V3 Float) -> "M33F" + V3 (V4 Float) -> "M43F" + + V4 Int -> "V4I" + V4 Word -> "V4U" + V4 Float -> "V4F" + V4 Bool -> "V4B" + V4 (V2 Float) -> "M24F" + V4 (V3 Float) -> "M34F" + V4 (V4 Float) -> "M44F" + + Array t -> "Array<" ++ parens (ktType aliasMap t) ++ ">" + List t -> "List<" ++ ktType aliasMap t ++ ">" + Maybe t -> parens (ktType aliasMap t) ++ "?" + Map k v -> "Map<" ++ parens (ktType aliasMap k) ++ ", " ++ parens (hsType aliasMap v) ++ ">" + -- user defined + Data t -> t + x -> error $ "unknown type: " ++ show x + typeEnum :: AliasMap -> Type -> String typeEnum aliasMap a = case normalize aliasMap a of Data t -> t @@ -354,6 +396,11 @@ hasFieldNames :: [Field] -> Bool hasFieldNames [] = False hasFieldNames l = all (not . null . fieldName) l +nonSingular :: [ConstructorDef] -> Bool +nonSingular [] = False +nonSingular (_:[]) = False +nonSingular (_:_:_) = True + constType :: DataDef -> String constType = head . words . show @@ -449,4 +496,4 @@ a #:: b = Field a b serialization: json: encode/decode other? --} \ No newline at end of file +-} diff --git a/ddl/lib/RT.kt b/ddl/lib/RT.kt new file mode 100644 index 0000000..f7edc2b --- /dev/null +++ b/ddl/lib/RT.kt @@ -0,0 +1,28 @@ +package RT; + +data class V2(val x: A, val y: A) +data class V3(val x: A, val y: A, val z: A) +data class V4(val x: A, val y: A, val z: A, val w: A) + +typealias M22F = V2 +typealias M23F = V3 +typealias M24F = V4 +typealias M32F = V2 +typealias M33F = V3 +typealias M34F = V4 +typealias M42F = V2 +typealias M43F = V3 +typealias M44F = V4 + +typealias V2F = V2 +typealias V3F = V3 +typealias V4F = V4 +typealias V2I = V2 +typealias V3I = V3 +typealias V4I = V4 +typealias V2U = V2 +typealias V3U = V3 +typealias V4U = V4 +typealias V2B = V2 +typealias V3B = V3 +typealias V4B = V4 diff --git a/ddl/out/kotlin/JSON.kt b/ddl/out/kotlin/JSON.kt new file mode 100644 index 0000000..8440a8b --- /dev/null +++ b/ddl/out/kotlin/JSON.kt @@ -0,0 +1,292 @@ +// generated file, do not modify! +// 2020-05-21T23:35:27.114328Z + +package TestData + +import org.json.* +import RT.* + +import LambdaCube.IR.* +import LambdaCube.Mesh.* +import LambdaCube.PipelineSchema.* + +object JSON { + + enum class Type { + Int, + Float, + String, + Array_Int, + Array_Float, + Array_String, + Array_Frame, + Array_Mesh, + Array_PipelineInfo, + Array_Scene, + Map_String_Int, + Map_String_Array_Int, + Map_String_Value, + Backend, + ClientInfo, + Frame, + FrameResult, + Mesh, + Pipeline, + PipelineInfo, + PipelineSchema, + RenderJob, + RenderJobResult, + Scene, + Value, + } + + @Throws(JSONException::class, Exception::class) + fun fromJSON(Type type, Object rawObj): Object { + when (type) { + Type.Int -> return (rawObj as Number).intValue() + Type.Float -> return (rawObj as Number).floatValue() + Type.String -> return rawObj as String + Type.Array_Int -> { + val obj = rawObj as JSONArray + return Array(obj.length()) { ind: Int -> + fromJSON(Type.Int, obj.get(ind)) as Int + } + } + Type.Array_Float -> { + val obj = rawObj as JSONArray + return Array(obj.length()) { ind: Int -> + fromJSON(Type.Float, obj.get(ind)) as Float + } + } + Type.Array_String -> { + val obj = rawObj as JSONArray + return Array(obj.length()) { ind: Int -> + fromJSON(Type.String, obj.get(ind)) as String + } + } + Type.Array_Frame -> { + val obj = rawObj as JSONArray + return Array(obj.length()) { ind: Int -> + fromJSON(Type.Frame, obj.get(ind)) as Frame + } + } + Type.Array_Mesh -> { + val obj = rawObj as JSONArray + return Array(obj.length()) { ind: Int -> + fromJSON(Type.Mesh, obj.get(ind)) as Mesh + } + } + Type.Array_PipelineInfo -> { + val obj = rawObj as JSONArray + return Array(obj.length()) { ind: Int -> + fromJSON(Type.PipelineInfo, obj.get(ind)) as PipelineInfo + } + } + Type.Array_Scene -> { + val obj = rawObj as JSONArray + return Array(obj.length()) { ind: Int -> + fromJSON(Type.Scene, obj.get(ind)) as Scene + } + } + Type.Map_String_Int -> { + val obj = rawObj as JSONObject + Map map = Map() + val keyIt = obj.keys() + while(keyIt.hasNext()) { + String key = keyIt.next() + map.put(key, fromJSON(Type.Int, obj.get(key)) as Int) + } + return map + } + Type.Map_String_Array_Int -> { + val obj = rawObj as JSONObject + Map map = Map() + val keyIt = obj.keys() + while(keyIt.hasNext()) { + String key = keyIt.next() + map.put(key, fromJSON(Type.Array_Int, obj.get(key)) as Array) + } + return map + } + Type.Map_String_Value -> { + val obj = rawObj as JSONObject + Map map = Map() + val keyIt = obj.keys() + while(keyIt.hasNext()) { + String key = keyIt.next() + map.put(key, fromJSON(Type.Value, obj.get(key)) as Value) + } + return map + } + + Type.ClientInfo -> { + val obj = rawObj as JSONObject + val tag = obj.getString("tag") + when (tag) { + "ClientInfo" -> { + return ClientInfo( + clientName = fromJSON(Type.String, obj.get("clientName")) as String, + clientBackend = fromJSON(Type.Backend, obj.get("clientBackend")) as Backend, + ) + } + } + } + Type.Frame -> { + val obj = rawObj as JSONObject + val tag = obj.getString("tag") + when (tag) { + "Frame" -> { + return Frame( + renderCount = fromJSON(Type.Int, obj.get("renderCount")) as Int, + frameUniforms = fromJSON(Type.Map_String_Value, obj.get("frameUniforms")) as Map, + frameTextures = fromJSON(Type.Map_String_Int, obj.get("frameTextures")) as Map, + ) + } + } + } + Type.Scene -> { + val obj = rawObj as JSONObject + val tag = obj.getString("tag") + when (tag) { + "Scene" -> { + return Scene( + objectArrays = fromJSON(Type.Map_String_Array_Int, obj.get("objectArrays")) as Map, + renderTargetWidth = fromJSON(Type.Int, obj.get("renderTargetWidth")) as Int, + renderTargetHeight = fromJSON(Type.Int, obj.get("renderTargetHeight")) as Int, + frames = fromJSON(Type.Array_Frame, obj.get("frames")) as Array, + ) + } + } + } + Type.PipelineInfo -> { + val obj = rawObj as JSONObject + val tag = obj.getString("tag") + when (tag) { + "PipelineInfo" -> { + return PipelineInfo( + pipelineName = fromJSON(Type.String, obj.get("pipelineName")) as String, + pipeline = fromJSON(Type.Pipeline, obj.get("pipeline")) as Pipeline, + ) + } + } + } + Type.RenderJob -> { + val obj = rawObj as JSONObject + val tag = obj.getString("tag") + when (tag) { + "RenderJob" -> { + return RenderJob( + meshes = fromJSON(Type.Array_Mesh, obj.get("meshes")) as Array, + textures = fromJSON(Type.Array_String, obj.get("textures")) as Array, + schema = fromJSON(Type.PipelineSchema, obj.get("schema")) as PipelineSchema, + scenes = fromJSON(Type.Array_Scene, obj.get("scenes")) as Array, + pipelines = fromJSON(Type.Array_PipelineInfo, obj.get("pipelines")) as Array, + ) + } + } + } + Type.FrameResult -> { + val obj = rawObj as JSONObject + val tag = obj.getString("tag") + when (tag) { + "FrameResult" -> { + return FrameResult( + frRenderTimes = fromJSON(Type.Array_Float, obj.get("frRenderTimes")) as Array, + frImageWidth = fromJSON(Type.Int, obj.get("frImageWidth")) as Int, + frImageHeight = fromJSON(Type.Int, obj.get("frImageHeight")) as Int, + ) + } + } + } + Type.RenderJobResult -> { + val obj = rawObj as JSONObject + val tag = obj.getString("tag") + when (tag) { + "RenderJobResult" -> { + return _RenderJobResult( + _0 = fromJSON(Type.FrameResult, obj.get("arg0")) as FrameResult, + ) + } + "RenderJobError" -> { + return _RenderJobError( + _0 = fromJSON(Type.String, obj.get("arg0")) as String, + ) + } + } + } + } + } + + @Throws(JSONException::class, Exception::class) + fn toJSON(Type type, Object rawObj): Object { + when (type) { + Type.ClientInfo -> { + val v = rawObj as ClientInfo + val obj = JSONObject() + when (v) { + is ClientInfo -> { + obj.put("tag", "ClientInfo") + } + } + } + Type.Frame -> { + val v = rawObj as Frame + val obj = JSONObject() + when (v) { + is Frame -> { + obj.put("tag", "Frame") + } + } + } + Type.Scene -> { + val v = rawObj as Scene + val obj = JSONObject() + when (v) { + is Scene -> { + obj.put("tag", "Scene") + } + } + } + Type.PipelineInfo -> { + val v = rawObj as PipelineInfo + val obj = JSONObject() + when (v) { + is PipelineInfo -> { + obj.put("tag", "PipelineInfo") + } + } + } + Type.RenderJob -> { + val v = rawObj as RenderJob + val obj = JSONObject() + when (v) { + is RenderJob -> { + obj.put("tag", "RenderJob") + } + } + } + Type.FrameResult -> { + val v = rawObj as FrameResult + val obj = JSONObject() + when (v) { + is FrameResult -> { + obj.put("tag", "FrameResult") + } + } + } + Type.RenderJobResult -> { + val v = rawObj as RenderJobResult + val obj = JSONObject() + when (v) { + is RenderJobResult -> { + obj.put("tag", "RenderJobResult") + } + is RenderJobError -> { + obj.put("tag", "RenderJobError") + } + } + } + } + } + +} diff --git a/ddl/out/kotlin/LambdaCube.IR.kt b/ddl/out/kotlin/LambdaCube.IR.kt new file mode 100644 index 0000000..6fcba73 --- /dev/null +++ b/ddl/out/kotlin/LambdaCube.IR.kt @@ -0,0 +1,583 @@ +// generated file, do not modify! +// 2020-05-21T20:25:27.552277Z + +package LambdaCube.IR + +import RT.* + + +typealias StreamName = Int + +typealias ProgramName = Int + +typealias TextureName = Int + +typealias SamplerName = Int + +typealias UniformName = String + +typealias SlotName = Int + +typealias FrameBufferComponent = Int + +typealias TextureUnit = Int + +typealias RenderTargetName = Int + +typealias TextureUnitMapping = Map + +sealed class ArrayValue() +data class _VBoolArray( + val _0 : Array, +) : ArrayValue() +data class _VIntArray( + val _0 : Array, +) : ArrayValue() +data class _VWordArray( + val _0 : Array, +) : ArrayValue() +data class _VFloatArray( + val _0 : Array, +) : ArrayValue() + +sealed class Value() +data class _VBool( + val _0 : Bool, +) : Value() +data class _VV2B( + val _0 : V2B, +) : Value() +data class _VV3B( + val _0 : V3B, +) : Value() +data class _VV4B( + val _0 : V4B, +) : Value() +data class _VWord( + val _0 : Int, +) : Value() +data class _VV2U( + val _0 : V2U, +) : Value() +data class _VV3U( + val _0 : V3U, +) : Value() +data class _VV4U( + val _0 : V4U, +) : Value() +data class _VInt( + val _0 : Int, +) : Value() +data class _VV2I( + val _0 : V2I, +) : Value() +data class _VV3I( + val _0 : V3I, +) : Value() +data class _VV4I( + val _0 : V4I, +) : Value() +data class _VFloat( + val _0 : Float, +) : Value() +data class _VV2F( + val _0 : V2F, +) : Value() +data class _VV3F( + val _0 : V3F, +) : Value() +data class _VV4F( + val _0 : V4F, +) : Value() +data class _VM22F( + val _0 : M22F, +) : Value() +data class _VM23F( + val _0 : M23F, +) : Value() +data class _VM24F( + val _0 : M24F, +) : Value() +data class _VM32F( + val _0 : M32F, +) : Value() +data class _VM33F( + val _0 : M33F, +) : Value() +data class _VM34F( + val _0 : M34F, +) : Value() +data class _VM42F( + val _0 : M42F, +) : Value() +data class _VM43F( + val _0 : M43F, +) : Value() +data class _VM44F( + val _0 : M44F, +) : Value() + +sealed class InputType() +object _Bool : InputType() +object _V2B : InputType() +object _V3B : InputType() +object _V4B : InputType() +object _Word : InputType() +object _V2U : InputType() +object _V3U : InputType() +object _V4U : InputType() +object _Int : InputType() +object _V2I : InputType() +object _V3I : InputType() +object _V4I : InputType() +object _Float : InputType() +object _V2F : InputType() +object _V3F : InputType() +object _V4F : InputType() +object _M22F : InputType() +object _M23F : InputType() +object _M24F : InputType() +object _M32F : InputType() +object _M33F : InputType() +object _M34F : InputType() +object _M42F : InputType() +object _M43F : InputType() +object _M44F : InputType() +object _STexture1D : InputType() +object _STexture2D : InputType() +object _STextureCube : InputType() +object _STexture1DArray : InputType() +object _STexture2DArray : InputType() +object _STexture2DRect : InputType() +object _FTexture1D : InputType() +object _FTexture2D : InputType() +object _FTexture3D : InputType() +object _FTextureCube : InputType() +object _FTexture1DArray : InputType() +object _FTexture2DArray : InputType() +object _FTexture2DMS : InputType() +object _FTexture2DMSArray : InputType() +object _FTextureBuffer : InputType() +object _FTexture2DRect : InputType() +object _ITexture1D : InputType() +object _ITexture2D : InputType() +object _ITexture3D : InputType() +object _ITextureCube : InputType() +object _ITexture1DArray : InputType() +object _ITexture2DArray : InputType() +object _ITexture2DMS : InputType() +object _ITexture2DMSArray : InputType() +object _ITextureBuffer : InputType() +object _ITexture2DRect : InputType() +object _UTexture1D : InputType() +object _UTexture2D : InputType() +object _UTexture3D : InputType() +object _UTextureCube : InputType() +object _UTexture1DArray : InputType() +object _UTexture2DArray : InputType() +object _UTexture2DMS : InputType() +object _UTexture2DMSArray : InputType() +object _UTextureBuffer : InputType() +object _UTexture2DRect : InputType() + +sealed class PointSpriteCoordOrigin() +object _LowerLeft : PointSpriteCoordOrigin() +object _UpperLeft : PointSpriteCoordOrigin() + +sealed class PointSize() +data class _PointSize( + val _0 : Float, +) : PointSize() +object _ProgramPointSize : PointSize() + +sealed class PolygonOffset() +object _NoOffset : PolygonOffset() +data class _Offset( + val _0 : Float, + val _1 : Float, +) : PolygonOffset() + +sealed class FrontFace() +object _CCW : FrontFace() +object _CW : FrontFace() + +sealed class PolygonMode() +data class _PolygonPoint( + val _0 : PointSize, +) : PolygonMode() +data class _PolygonLine( + val _0 : Float, +) : PolygonMode() +object _PolygonFill : PolygonMode() + +sealed class ProvokingVertex() +object _FirstVertex : ProvokingVertex() +object _LastVertex : ProvokingVertex() + +sealed class CullMode() +object _CullNone : CullMode() +data class _CullFront( + val _0 : FrontFace, +) : CullMode() +data class _CullBack( + val _0 : FrontFace, +) : CullMode() + +sealed class ComparisonFunction() +object _Never : ComparisonFunction() +object _Less : ComparisonFunction() +object _Equal : ComparisonFunction() +object _Lequal : ComparisonFunction() +object _Greater : ComparisonFunction() +object _Notequal : ComparisonFunction() +object _Gequal : ComparisonFunction() +object _Always : ComparisonFunction() + +typealias DepthFunction = ComparisonFunction + +sealed class StencilOperation() +object _OpZero : StencilOperation() +object _OpKeep : StencilOperation() +object _OpReplace : StencilOperation() +object _OpIncr : StencilOperation() +object _OpIncrWrap : StencilOperation() +object _OpDecr : StencilOperation() +object _OpDecrWrap : StencilOperation() +object _OpInvert : StencilOperation() + +sealed class BlendEquation() +object _FuncAdd : BlendEquation() +object _FuncSubtract : BlendEquation() +object _FuncReverseSubtract : BlendEquation() +object _Min : BlendEquation() +object _Max : BlendEquation() + +sealed class BlendingFactor() +object _Zero : BlendingFactor() +object _One : BlendingFactor() +object _SrcColor : BlendingFactor() +object _OneMinusSrcColor : BlendingFactor() +object _DstColor : BlendingFactor() +object _OneMinusDstColor : BlendingFactor() +object _SrcAlpha : BlendingFactor() +object _OneMinusSrcAlpha : BlendingFactor() +object _DstAlpha : BlendingFactor() +object _OneMinusDstAlpha : BlendingFactor() +object _ConstantColor : BlendingFactor() +object _OneMinusConstantColor : BlendingFactor() +object _ConstantAlpha : BlendingFactor() +object _OneMinusConstantAlpha : BlendingFactor() +object _SrcAlphaSaturate : BlendingFactor() + +sealed class LogicOperation() +object _Clear : LogicOperation() +object _And : LogicOperation() +object _AndReverse : LogicOperation() +object _Copy : LogicOperation() +object _AndInverted : LogicOperation() +object _Noop : LogicOperation() +object _Xor : LogicOperation() +object _Or : LogicOperation() +object _Nor : LogicOperation() +object _Equiv : LogicOperation() +object _Invert : LogicOperation() +object _OrReverse : LogicOperation() +object _CopyInverted : LogicOperation() +object _OrInverted : LogicOperation() +object _Nand : LogicOperation() +object _Set : LogicOperation() + +data class StencilOps( + val frontStencilOp : StencilOperation, + val backStencilOp : StencilOperation, +) + +data class StencilTest( + val stencilComparision : ComparisonFunction, + val stencilReference : Int, + val stencilMask : Int, +) + +data class StencilTests( + val _0 : StencilTest, + val _1 : StencilTest, +) + +sealed class FetchPrimitive() +object _Points : FetchPrimitive() +object _Lines : FetchPrimitive() +object _Triangles : FetchPrimitive() +object _LinesAdjacency : FetchPrimitive() +object _TrianglesAdjacency : FetchPrimitive() + +sealed class OutputPrimitive() +object _TrianglesOutput : OutputPrimitive() +object _LinesOutput : OutputPrimitive() +object _PointsOutput : OutputPrimitive() + +sealed class ColorArity() +object _Red : ColorArity() +object _RG : ColorArity() +object _RGB : ColorArity() +object _RGBA : ColorArity() + +sealed class Blending() +object _NoBlending : Blending() +data class _BlendLogicOp( + val _0 : LogicOperation, +) : Blending() +data class _Blend( + val colorEqSrc : BlendEquation, + val alphaEqSrc : BlendEquation, + val colorFSrc : BlendingFactor, + val colorFDst : BlendingFactor, + val alphaFSrc : BlendingFactor, + val alphaFDst : BlendingFactor, + val color : V4F, +) : Blending() + +sealed class RasterContext() +data class _PointCtx( + val _0 : PointSize, + val _1 : Float, + val _2 : PointSpriteCoordOrigin, +) : RasterContext() +data class _LineCtx( + val _0 : Float, + val _1 : ProvokingVertex, +) : RasterContext() +data class _TriangleCtx( + val _0 : CullMode, + val _1 : PolygonMode, + val _2 : PolygonOffset, + val _3 : ProvokingVertex, +) : RasterContext() + +sealed class FragmentOperation() +data class _DepthOp( + val _0 : DepthFunction, + val _1 : Bool, +) : FragmentOperation() +data class _StencilOp( + val _0 : StencilTests, + val _1 : StencilOps, + val _2 : StencilOps, +) : FragmentOperation() +data class _ColorOp( + val _0 : Blending, + val _1 : Value, +) : FragmentOperation() + +data class AccumulationContext( + val accViewportName : String?, + val accOperations : List, +) + +sealed class TextureDataType() +data class _FloatT( + val _0 : ColorArity, +) : TextureDataType() +data class _IntT( + val _0 : ColorArity, +) : TextureDataType() +data class _WordT( + val _0 : ColorArity, +) : TextureDataType() +object _ShadowT : TextureDataType() + +sealed class TextureType() +data class _Texture1D( + val _0 : TextureDataType, + val _1 : Int, +) : TextureType() +data class _Texture2D( + val _0 : TextureDataType, + val _1 : Int, +) : TextureType() +data class _Texture3D( + val _0 : TextureDataType, +) : TextureType() +data class _TextureCube( + val _0 : TextureDataType, +) : TextureType() +data class _TextureRect( + val _0 : TextureDataType, +) : TextureType() +data class _Texture2DMS( + val _0 : TextureDataType, + val _1 : Int, + val _2 : Int, + val _3 : Bool, +) : TextureType() +data class _TextureBuffer( + val _0 : TextureDataType, +) : TextureType() + +sealed class MipMap() +data class _Mip( + val _0 : Int, + val _1 : Int, +) : MipMap() +object _NoMip : MipMap() +data class _AutoMip( + val _0 : Int, + val _1 : Int, +) : MipMap() + +sealed class Filter() +object _Nearest : Filter() +object _Linear : Filter() +object _NearestMipmapNearest : Filter() +object _NearestMipmapLinear : Filter() +object _LinearMipmapNearest : Filter() +object _LinearMipmapLinear : Filter() + +sealed class EdgeMode() +object _Repeat : EdgeMode() +object _MirroredRepeat : EdgeMode() +object _ClampToEdge : EdgeMode() +object _ClampToBorder : EdgeMode() + +sealed class ImageSemantic() +object _Depth : ImageSemantic() +object _Stencil : ImageSemantic() +object _Color : ImageSemantic() + +sealed class ImageRef() +data class _TextureImage( + val _0 : TextureName, + val _1 : Int, + val _2 : Int?, +) : ImageRef() +data class _Framebuffer( + val _0 : ImageSemantic, +) : ImageRef() + +data class ClearImage( + val imageSemantic : ImageSemantic, + val clearValue : Value, +) + +sealed class Command() +data class _SetRasterContext( + val _0 : RasterContext, +) : Command() +data class _SetAccumulationContext( + val _0 : AccumulationContext, +) : Command() +data class _SetRenderTarget( + val _0 : RenderTargetName, +) : Command() +data class _SetProgram( + val _0 : ProgramName, +) : Command() +data class _SetSamplerUniform( + val _0 : UniformName, + val _1 : TextureUnit, +) : Command() +data class _SetTexture( + val _0 : TextureUnit, + val _1 : TextureName, +) : Command() +data class _SetSampler( + val _0 : TextureUnit, + val _1 : SamplerName?, +) : Command() +data class _RenderSlot( + val _0 : SlotName, +) : Command() +data class _RenderStream( + val _0 : StreamName, +) : Command() +data class _ClearRenderTarget( + val _0 : Array, +) : Command() +data class _GenerateMipMap( + val _0 : TextureUnit, +) : Command() +data class _SaveImage( + val _0 : FrameBufferComponent, + val _1 : ImageRef, +) : Command() +data class _LoadImage( + val _0 : ImageRef, + val _1 : FrameBufferComponent, +) : Command() + +data class SamplerDescriptor( + val samplerWrapS : EdgeMode, + val samplerWrapT : EdgeMode?, + val samplerWrapR : EdgeMode?, + val samplerMinFilter : Filter, + val samplerMagFilter : Filter, + val samplerBorderColor : Value, + val samplerMinLod : Float?, + val samplerMaxLod : Float?, + val samplerLodBias : Float, + val samplerCompareFunc : ComparisonFunction?, +) + +data class TextureDescriptor( + val textureType : TextureType, + val textureSize : Value, + val textureSemantic : ImageSemantic, + val textureSampler : SamplerDescriptor, + val textureBaseLevel : Int, + val textureMaxLevel : Int, +) + +data class Parameter( + val name : String, + val ty : InputType, +) + +data class Program( + val programUniforms : Map, + val programStreams : Map, + val programInTextures : Map, + val programOutput : Array, + val vertexShader : String, + val geometryShader : String?, + val fragmentShader : String, +) + +data class Slot( + val slotName : String, + val slotStreams : Map, + val slotUniforms : Map, + val slotPrimitive : FetchPrimitive, + val slotPrograms : Array, +) + +data class StreamData( + val streamData : Map, + val streamType : Map, + val streamPrimitive : FetchPrimitive, + val streamPrograms : Array, +) + +data class TargetItem( + val targetSemantic : ImageSemantic, + val targetRef : ImageRef?, +) + +data class RenderTarget( + val renderTargets : Array, +) + +sealed class Backend() +object _WebGL1 : Backend() +object _OpenGL33 : Backend() + +data class Pipeline( + val info : String, + val backend : Backend, + val textures : Array, + val samplers : Array, + val targets : Array, + val programs : Array, + val slots : Array, + val streams : Array, + val commands : Array, +) + diff --git a/ddl/out/kotlin/LambdaCube.Mesh.kt b/ddl/out/kotlin/LambdaCube.Mesh.kt new file mode 100644 index 0000000..bcc676a --- /dev/null +++ b/ddl/out/kotlin/LambdaCube.Mesh.kt @@ -0,0 +1,53 @@ +// generated file, do not modify! +// 2020-05-21T20:25:27.766405Z + +package LambdaCube.Mesh + +import RT.* + + +sealed class MeshAttribute() +data class _A_Float( + val _0 : Array, +) : MeshAttribute() +data class _A_V2F( + val _0 : Array, +) : MeshAttribute() +data class _A_V3F( + val _0 : Array, +) : MeshAttribute() +data class _A_V4F( + val _0 : Array, +) : MeshAttribute() +data class _A_M22F( + val _0 : Array, +) : MeshAttribute() +data class _A_M33F( + val _0 : Array, +) : MeshAttribute() +data class _A_M44F( + val _0 : Array, +) : MeshAttribute() +data class _A_Int( + val _0 : Array, +) : MeshAttribute() +data class _A_Word( + val _0 : Array, +) : MeshAttribute() + +sealed class MeshPrimitive() +object _P_Points : MeshPrimitive() +object _P_TriangleStrip : MeshPrimitive() +object _P_Triangles : MeshPrimitive() +data class _P_TriangleStripI( + val _0 : Array, +) : MeshPrimitive() +data class _P_TrianglesI( + val _0 : Array, +) : MeshPrimitive() + +data class Mesh( + val mAttributes : Map, + val mPrimitive : MeshPrimitive, +) + diff --git a/ddl/out/kotlin/LambdaCube.PipelineSchema.kt b/ddl/out/kotlin/LambdaCube.PipelineSchema.kt new file mode 100644 index 0000000..3a589ad --- /dev/null +++ b/ddl/out/kotlin/LambdaCube.PipelineSchema.kt @@ -0,0 +1,42 @@ +// generated file, do not modify! +// 2020-05-21T20:25:27.753757Z + +package LambdaCube.PipelineSchema + +import RT.* + +import LambdaCube.IR.* + +sealed class StreamType() +object _Attribute_Word : StreamType() +object _Attribute_V2U : StreamType() +object _Attribute_V3U : StreamType() +object _Attribute_V4U : StreamType() +object _Attribute_Int : StreamType() +object _Attribute_V2I : StreamType() +object _Attribute_V3I : StreamType() +object _Attribute_V4I : StreamType() +object _Attribute_Float : StreamType() +object _Attribute_V2F : StreamType() +object _Attribute_V3F : StreamType() +object _Attribute_V4F : StreamType() +object _Attribute_M22F : StreamType() +object _Attribute_M23F : StreamType() +object _Attribute_M24F : StreamType() +object _Attribute_M32F : StreamType() +object _Attribute_M33F : StreamType() +object _Attribute_M34F : StreamType() +object _Attribute_M42F : StreamType() +object _Attribute_M43F : StreamType() +object _Attribute_M44F : StreamType() + +data class ObjectArraySchema( + val primitive : FetchPrimitive, + val attributes : Map, +) + +data class PipelineSchema( + val objectArrays : Map, + val uniforms : Map, +) + diff --git a/ddl/out/kotlin/LambdaCube.TypeInfo.kt b/ddl/out/kotlin/LambdaCube.TypeInfo.kt new file mode 100644 index 0000000..4a09d36 --- /dev/null +++ b/ddl/out/kotlin/LambdaCube.TypeInfo.kt @@ -0,0 +1,46 @@ +// generated file, do not modify! +// 2020-05-21T20:25:27.786125Z + +package LambdaCube.TypeInfo + +import RT.* + +import LambdaCube.IR.* + +data class Range( + val startLine : Int, + val startColumn : Int, + val endLine : Int, + val endColumn : Int, +) + +data class TypeInfo( + val range : Range, + val text : String, +) + +data class WarningInfo( + val wRange : Range, + val wText : String, +) + +data class ErrorInfo( + val eRange : Range, + val eText : String, +) + +sealed class CompileResult() +data class _CompileError( + val _0 : String, + val _1 : Array, + val _2 : Array, + val _3 : Array, +) : CompileResult() +data class _Compiled( + val _0 : String, + val _1 : String, + val _2 : Pipeline, + val _3 : Array, + val _4 : Array, +) : CompileResult() + diff --git a/ddl/out/kotlin/TestData.kt b/ddl/out/kotlin/TestData.kt new file mode 100644 index 0000000..5e904ee --- /dev/null +++ b/ddl/out/kotlin/TestData.kt @@ -0,0 +1,56 @@ +// generated file, do not modify! +// 2020-05-21T20:25:27.802172Z + +package TestData + +import RT.* + +import LambdaCube.IR.* +import LambdaCube.Mesh.* +import LambdaCube.PipelineSchema.* + +data class ClientInfo( + val clientName : String, + val clientBackend : Backend, +) + +data class Frame( + val renderCount : Int, + val frameUniforms : Map, + val frameTextures : Map, +) + +data class Scene( + val objectArrays : Map, + val renderTargetWidth : Int, + val renderTargetHeight : Int, + val frames : Array, +) + +data class PipelineInfo( + val pipelineName : String, + val pipeline : Pipeline, +) + +data class RenderJob( + val meshes : Array, + val textures : Array, + val schema : PipelineSchema, + val scenes : Array, + val pipelines : Array, +) + +data class FrameResult( + val frRenderTimes : Array, + val frImageWidth : Int, + val frImageHeight : Int, +) + +sealed class RenderJobResult() +data class _RenderJobResult( + val _0 : FrameResult, +) : RenderJobResult() +data class _RenderJobError( + val _0 : String, +) : RenderJobResult() + diff --git a/ddl/templates/data.kt.ede b/ddl/templates/data.kt.ede new file mode 100644 index 0000000..8ec0822 --- /dev/null +++ b/ddl/templates/data.kt.ede @@ -0,0 +1,32 @@ +// generated file, do not modify! +// {{ dateTime }} + +package {{ moduleName }} + +import RT.* + +{% for m in imports %} +import {{ m.value }}.* +{% endfor %} + +{% for t in dataAndType %} +{% case t.value | constType %} +{% when "DataDef" %} +{% if t.value.constructors | nonSingular %} +sealed class {{ t.value.dataName }}() +{% endif %} +{% for c in t.value.constructors %} +{% if c.value.fields | empty %} +object {% if t.value.constructors | nonSingular %}_{% endif %}{{ c.value.name }}{% if t.value.constructors | nonSingular %} : {{ t.value.dataName }}(){% endif %} +{% else %} +data class {% if t.value.constructors | nonSingular %}_{% endif %}{{ c.value.name }}({% for f in c.value.fields %}{% if c.value.fields | hasFieldNames %} + val {{ f.value.fieldName }} : {{ f.value.fieldType | ktType }},{% else %} + val _{{ f.index0 }} : {{ f.value.fieldType | ktType }},{% endif %}{% endfor %} +){% if t.value.constructors | nonSingular %} : {{ t.value.dataName }}(){% endif %} +{% endif %} +{% endfor %} +{% when "TypeAlias" %} +typealias {{ t.value.aliasName }} = {{ t.value.aliasType | ktType }} +{% endcase %} + +{% endfor %} \ No newline at end of file diff --git a/ddl/templates/json.kt.ede b/ddl/templates/json.kt.ede new file mode 100644 index 0000000..3e26bd2 --- /dev/null +++ b/ddl/templates/json.kt.ede @@ -0,0 +1,142 @@ +// generated file, do not modify! +// {{ dateTime }} + +package {{ moduleName }} + +import org.json.* +import RT.* + +{% for m in imports %} +import {{ m.value }}.* +{% endfor %} + +object JSON { + + enum class Type { {% for t in usedTypes %} + {{ t.value | typeEnum }},{% endfor %} + } + + @Throws(JSONException::class, Exception::class) + fun fromJSON(Type type, Object rawObj): Object { + when (type) { + {% for t in usedTypes %} + {% case t.value.tag %} + {% when "Data" %} + {% when "V2" %} + Type.{{ t.value | typeEnum }} -> { + val obj = rawObj as JSONObject + return {{ t.value | ktType }}( + fromJSON(Type.{{ t.value.type_ | typeEnum }}, obj.get("x")) as {{ t.value.type_ | ktType }}, + fromJSON(Type.{{ t.value.type_ | typeEnum }}, obj.get("y")) as {{ t.value.type_ | ktType }} + ) + } + {% when "V3" %} + Type.{{ t.value | typeEnum }} -> { + val obj = rawObj as JSONObject + return {{ t.value | ktType }}( + fromJSON(Type.{{ t.value.type_ | typeEnum }}, obj.get("x")) as {{ t.value.type_ | ktType }}, + fromJSON(Type.{{ t.value.type_ | typeEnum }}, obj.get("y")) as {{ t.value.type_ | ktType }}, + fromJSON(Type.{{ t.value.type_ | typeEnum }}, obj.get("z")) as {{ t.value.type_ | ktType }} + ) + } + {% when "V4" %} + Type.{{ t.value | typeEnum }} -> { + val obj = rawObj as JSONObject + return {{ t.value | ktType }}( + fromJSON(Type.{{ t.value.type_ | typeEnum }}, obj.get("x")) as {{ t.value.type_ | ktType }}, + fromJSON(Type.{{ t.value.type_ | typeEnum }}, obj.get("y")) as {{ t.value.type_ | ktType }}, + fromJSON(Type.{{ t.value.type_ | typeEnum }}, obj.get("z")) as {{ t.value.type_ | ktType }}, + fromJSON(Type.{{ t.value.type_ | typeEnum }}, obj.get("w")) as {{ t.value.type_ | ktType }} + ) + } + {% when "Map" %} + Type.{{ t.value | typeEnum }} -> { + val obj = rawObj as JSONObject + {{ t.value | ktType }} map = {{ t.value | ktType }}() + val keyIt = obj.keys() + while(keyIt.hasNext()) { + String key = keyIt.next() + map.put(key, fromJSON(Type.{{ t.value.value_ | typeEnum }}, obj.get(key)) as {{ t.value.value_ | ktType }}) + } + return map + } + {% when "Array" %} + Type.{{ t.value | typeEnum }} -> { + val obj = rawObj as JSONArray + return {{ t.value | ktType }}(obj.length()) { ind: Int -> + fromJSON(Type.{{ t.value.type_ | typeEnum }}, obj.get(ind)) as {{ t.value.type_ | ktType }} + } + } + {% when "List" %} + Type.{{ t.value | typeEnum }} -> { + val obj = rawObj as JSONArray + return {{ t.value | ktType }}(obj.length()) { ind: Int -> + fromJSON(Type.{{ t.value.type_ | typeEnum }}, obj.get(ind)) as {{ t.value.type_ | ktType }} + } + } + {% when "Maybe" %} + Type.{{ t.value | typeEnum }} -> { + return if(rawObj == null || rawObj = JSONObject.NULL) { + null + } else { + fromJSON(Type.{{ t.value.type_ | typeEnum }}, rawObj as JSONObject) as {{ t.value.type_ | ktType }} + } + } + {% when "Int" %} + Type.{{ t.value | typeEnum }} -> return (rawObj as Number).intValue() + {% when "Int32" %} + Type.{{ t.value | typeEnum }} -> return (rawObj as Number).intValue() + {% when "Word" %} + Type.{{ t.value | typeEnum }} -> return (rawObj as Number).intValue() + {% when "Word32" %} + Type.{{ t.value | typeEnum }} -> return (rawObj as Number).intValue() + {% when "Float" %} + Type.{{ t.value | typeEnum }} -> return (rawObj as Number).floatValue() + {% else %} + Type.{{ t.value | typeEnum }} -> return rawObj as {{ t.value | ktType }} + {% endcase %} + {% endfor %} + + {% for t in definitions %} + Type.{{ t.value.dataName }} -> { + val obj = rawObj as JSONObject + val tag = obj.getString("tag") + when (tag) { + {% for c in t.value.constructors %} + "{{ c.value.name }}" -> { + return {% if c.value.fields | empty %} + {% if t.value.constructors | nonSingular %}_{% endif %}{{c.value.name}} + {% else %} + {% if t.value.constructors | nonSingular %}_{% endif %}{{c.value.name}}({% for f in c.value.fields %}{% if c.value.fields | hasFieldNames %} + {{ f.value.fieldName }} = fromJSON(Type.{{ f.value.fieldType | typeEnum }}, obj.get("{{ f.value.fieldName }}")) as {{ f.value.fieldType | ktType }}{% else %} + _{{ f.index0 }} = fromJSON(Type.{{ f.value.fieldType | typeEnum }}, obj.get("arg{{ f.index0 }}")) as {{ f.value.fieldType | ktType }}{% endif %},{% endfor %} + ) + {% endif %} + } + {% endfor %} + } + } + {% endfor %} + } + } + + @Throws(JSONException::class, Exception::class) + fn toJSON(Type type, Object rawObj): Object { + when (type) { + {% for t in definitions %} + Type.{{ t.value.dataName }} -> { + val v = rawObj as {{ t.value.dataName }} + val obj = JSONObject() + when (v) { + {% for c in t.value.constructors %} + is {{ c.value.name }} -> { + obj.put("tag", "{{ c.value.name }}") + } + {% endfor %} + } + } + {% endfor %} + } + } + +}