Skip to content

Commit

Permalink
Feature: cleanup runtime packages, update NS rendering, update RpDate…
Browse files Browse the repository at this point in the history
…Time. (#15)
  • Loading branch information
Caparow authored Aug 28, 2024
1 parent 306cdb7 commit ef36e7f
Show file tree
Hide file tree
Showing 8 changed files with 306 additions and 236 deletions.
1 change: 1 addition & 0 deletions src/main/scala/io/septimalmind/baboon/Baboon.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package io.septimalmind.baboon

import caseapp.*
import distage.Injector
import io.septimalmind.baboon.BaboonCompiler.CompilerOptions
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ object CSCodecTestsTranslator {
|using AutoFixture;
|using System.IO;
|using System;
|using Baboon.Runtime.Shared;
|using Baboon.Test.Runtime.Shared;
|
|[TestFixture]
|public class $testClassName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,25 @@ object CSDefnTools {
def makeMeta(defn: DomainMember.User,
version: Version): Seq[TextTree[CSValue]] = {
Seq(
q"""public static String BaboonDomainVersionValue = "${version.version}";
q"""public const String BaboonDomainVersionValue = "${version.version}";
|public String BaboonDomainVersion() => BaboonDomainVersionValue;
|""".stripMargin,
q"""public static String BaboonDomainIdentifierValue = "${defn.id.pkg.toString}";
q"""public const String BaboonDomainIdentifierValue = "${defn.id.pkg.toString}";
|public String BaboonDomainIdentifier() => BaboonDomainIdentifierValue;
|""".stripMargin,
q"""public static String BaboonTypeIdentifierValue = "${defn.id.toString}";
q"""public const String BaboonTypeIdentifierValue = "${defn.id.toString}";
|public String BaboonTypeIdentifier() => BaboonTypeIdentifierValue;
|""".stripMargin)
}

private def inNs(name: String,
tree: TextTree[CSValue]): TextTree[CSValue] = {
q"""namespace ${name} {
| ${tree.shift(4).trim}
|}""".stripMargin
}

def inNs(nss: Seq[String], tree: TextTree[CSValue]): TextTree[CSValue] = {
nss.foldRight(tree) {
case (ns, acc) =>
inNs(ns, acc)
if (nss.isEmpty) {
tree
} else {
q"""namespace ${nss.mkString(".")} {
| ${tree.shift(4).trim}
|}""".stripMargin
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ object CSDefnTranslator {
case class OutputExt(output: Output, codecReg: TextTree[CSValue])

val obsolete: CSType =
CSType(CSBaboonTranslator.systemPkg, "Obsolete", fq = false)
CSType(CSBaboonTranslator.csSystemPkg, "Obsolete", fq = false)

val serializable: CSType =
CSType(CSBaboonTranslator.systemPkg, "Serializable", fq = false)
CSType(CSBaboonTranslator.csSystemPkg, "Serializable", fq = false)

class CSDefnTranslatorImpl(options: CompilerOptions,
trans: CSTypeTranslator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class CSNSJsonCodecGenerator(trans: CSTypeTranslator,
ref: TextTree[CSValue]): TextTree[CSValue] = {
tpe.id match {
case TypeId.Builtins.tsu | TypeId.Builtins.tso =>
q"$csDateTimeFormats.ToString($ref)"
q"$baboonTimeFormats.ToString($ref)"
case _: TypeId.Builtin =>
q"$ref.ToString()"
case uid: TypeId.User =>
Expand Down Expand Up @@ -259,7 +259,7 @@ class CSNSJsonCodecGenerator(trans: CSTypeTranslator,
case TypeId.Builtins.uid =>
q"new $nsJValue($ref.ToString())"
case TypeId.Builtins.tsu | TypeId.Builtins.tso =>
q"new $nsJValue($csDateTimeFormats.ToString($ref))"
q"new $nsJValue($baboonTimeFormats.ToString($ref))"
case _: TypeId.BuiltinScalar =>
q"new $nsJValue($ref)"
case u: TypeId.User =>
Expand Down Expand Up @@ -323,7 +323,7 @@ class CSNSJsonCodecGenerator(trans: CSTypeTranslator,
case TypeId.Builtins.uid =>
q"$csGuid.Parse($fref.Value<$csString>()!)"
case TypeId.Builtins.tsu | TypeId.Builtins.tso =>
q"$csDateTimeFormats.FromString($fref.Value<$csString>()!)"
q"$baboonTimeFormats.FromString($fref.Value<$csString>()!)"
case o =>
throw new RuntimeException(s"BUG: Unexpected type: $o")
}
Expand Down Expand Up @@ -362,7 +362,7 @@ class CSNSJsonCodecGenerator(trans: CSTypeTranslator,
case TypeId.Builtins.uid =>
q"$csGuid.Parse($ref)"
case TypeId.Builtins.tsu | TypeId.Builtins.tso =>
q"$csDateTimeFormats.FromString($ref)"
q"$baboonTimeFormats.FromString($ref)"
case uid: TypeId.User =>
domain.defs.meta.nodes(uid) match {
case u: DomainMember.User =>
Expand Down Expand Up @@ -461,5 +461,5 @@ class CSNSJsonCodecGenerator(trans: CSTypeTranslator,
CodecMeta(member)
}

def metaField(): TextTree[CSValue] = q"IBaboonCodecAbstract json";
def metaField(): TextTree[CSValue] = q"IBaboonCodecData Json";
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package io.septimalmind.baboon.translator.csharp

import io.septimalmind.baboon.BaboonCompiler.CompilerOptions
import io.septimalmind.baboon.translator.csharp.CSTypeTranslator.{
baboonRuntime,
generics,
immutable,
system
}
import io.septimalmind.baboon.translator.csharp.CSBaboonTranslator.*
import io.septimalmind.baboon.translator.csharp.CSValue.{CSPackageId, CSType}
import io.septimalmind.baboon.typer.model.*
import izumi.fundamentals.collections.nonempty.NEList
Expand Down Expand Up @@ -78,39 +73,39 @@ class CSTypeTranslator() {
private def asCsTypeScalar(b: TypeId.BuiltinScalar) = {
b match {
case TypeId.Builtins.bit =>
CSValue.CSType(system, "Boolean", fq = false)
CSValue.CSType(csSystemPkg, "Boolean", fq = false)

case TypeId.Builtins.i08 =>
CSValue.CSType(system, "SByte", fq = false)
CSValue.CSType(csSystemPkg, "SByte", fq = false)
case TypeId.Builtins.i16 =>
CSValue.CSType(system, "Int16", fq = false)
CSValue.CSType(csSystemPkg, "Int16", fq = false)
case TypeId.Builtins.i32 =>
CSValue.CSType(system, "Int32", fq = false)
CSValue.CSType(csSystemPkg, "Int32", fq = false)
case TypeId.Builtins.i64 =>
CSValue.CSType(system, "Int64", fq = false)
CSValue.CSType(csSystemPkg, "Int64", fq = false)

case TypeId.Builtins.u08 =>
CSValue.CSType(system, "Byte", fq = false)
CSValue.CSType(csSystemPkg, "Byte", fq = false)
case TypeId.Builtins.u16 =>
CSValue.CSType(system, "UInt16", fq = false)
CSValue.CSType(csSystemPkg, "UInt16", fq = false)
case TypeId.Builtins.u32 =>
CSValue.CSType(system, "UInt32", fq = false)
CSValue.CSType(csSystemPkg, "UInt32", fq = false)
case TypeId.Builtins.u64 =>
CSValue.CSType(system, "UInt64", fq = false)
CSValue.CSType(csSystemPkg, "UInt64", fq = false)

case TypeId.Builtins.f32 =>
CSValue.CSType(system, "Single", fq = false)
CSValue.CSType(csSystemPkg, "Single", fq = false)
case TypeId.Builtins.f64 =>
CSValue.CSType(system, "Double", fq = false)
CSValue.CSType(csSystemPkg, "Double", fq = false)
case TypeId.Builtins.f128 =>
CSValue.CSType(system, "Decimal", fq = false)
CSValue.CSType(csSystemPkg, "Decimal", fq = false)

case TypeId.Builtins.str =>
CSValue.CSType(system, "String", fq = false)
CSValue.CSType(csSystemPkg, "String", fq = false)
case TypeId.Builtins.uid =>
CSValue.CSType(system, "Guid", fq = false)
CSValue.CSType(csSystemPkg, "Guid", fq = false)
case TypeId.Builtins.tso | TypeId.Builtins.tsu =>
CSValue.CSType(baboonRuntime, "RpDateTime", fq = false)
CSValue.CSType(baboonTimePkg, "RpDateTime", fq = false)
case _ =>
throw new IllegalArgumentException(s"Unexpected: $b")
}
Expand All @@ -130,22 +125,22 @@ class CSTypeTranslator() {

b match {
case TypeId.Builtins.map =>
CSValue.CSType(immutable, "ImmutableDictionary", fq = false)
CSValue.CSType(csCollectionsImmutablePkg, "ImmutableDictionary", fq = false)
case TypeId.Builtins.lst =>
CSValue.CSType(immutable, "ImmutableList", fq = false)
CSValue.CSType(csCollectionsImmutablePkg, "ImmutableList", fq = false)
case TypeId.Builtins.set =>
CSValue.CSType(immutable, "ImmutableHashSet", fq = false)
CSValue.CSType(csCollectionsImmutablePkg, "ImmutableHashSet", fq = false)
case _ =>
throw new IllegalArgumentException(s"Unexpected: $b")
}
} else {
b match {
case TypeId.Builtins.map =>
CSValue.CSType(generics, "Dictionary", fq = false)
CSValue.CSType(csCollectionsGenericPkg, "Dictionary", fq = false)
case TypeId.Builtins.lst =>
CSValue.CSType(generics, "List", fq = false)
CSValue.CSType(csCollectionsGenericPkg, "List", fq = false)
case TypeId.Builtins.set =>
CSValue.CSType(generics, "HashSet", fq = false)
CSValue.CSType(csCollectionsGenericPkg, "HashSet", fq = false)
case _ =>
throw new IllegalArgumentException(s"Unexpected: $b")
}
Expand Down Expand Up @@ -251,13 +246,3 @@ class CSTypeTranslator() {
}
}
}

object CSTypeTranslator {
private val system = CSValue.CSPackageId(NEList("System"))
private val generics =
CSValue.CSPackageId(NEList("System", "Collections", "Generic"))
private val immutable =
CSValue.CSPackageId(NEList("System", "Collections", "Immutable"))
private val baboonRuntime =
CSValue.CSPackageId(NEList("Baboon", "Runtime", "Shared"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class CSUEBACodecGenerator(trans: CSTypeTranslator,
q"""return new $name(
|${branches.map(_._2).join(",\n").shift(4)}
|);
""".stripMargin
|""".stripMargin
//val fdec = q"throw new $csNotImplementedException();"
(fenc, fdec)
}
Expand Down Expand Up @@ -258,7 +258,7 @@ class CSUEBACodecGenerator(trans: CSTypeTranslator,
case TypeId.Builtins.uid =>
q"$csGuid.Parse(wire.ReadString())"
case TypeId.Builtins.tsu | TypeId.Builtins.tso =>
q"$csDateTimeFormats.FromString(wire.ReadString())"
q"$baboonTimeFormats.FromString(wire.ReadString())"
case o =>
throw new RuntimeException(s"BUG: Unexpected type: $o")
}
Expand Down Expand Up @@ -357,7 +357,7 @@ class CSUEBACodecGenerator(trans: CSTypeTranslator,
case TypeId.Builtins.uid =>
q"writer.Write($ref.ToString())"
case TypeId.Builtins.tsu | TypeId.Builtins.tso =>
q"writer.Write($csDateTimeFormats.ToString($ref))"
q"writer.Write($baboonTimeFormats.ToString($ref))"
case o =>
throw new RuntimeException(s"BUG: Unexpected type: $o")
}
Expand Down Expand Up @@ -426,5 +426,5 @@ class CSUEBACodecGenerator(trans: CSTypeTranslator,
CodecMeta(member)
}

def metaField(): TextTree[CSValue] = q"IBaboonCodecAbstract ueba";
def metaField(): TextTree[CSValue] = q"IBaboonCodecData Ueba";
}

0 comments on commit ef36e7f

Please sign in to comment.