From 9878485e4798afedbdedad0df840dc08f6f2047d Mon Sep 17 00:00:00 2001 From: Stefanos Mandalas Date: Sun, 14 Nov 2021 14:56:10 +0200 Subject: [PATCH] fixed instance caching logic --- .../main/scala/io/kaitai/struct/NimClassCompiler.scala | 2 +- .../scala/io/kaitai/struct/languages/NimCompiler.scala | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/shared/src/main/scala/io/kaitai/struct/NimClassCompiler.scala b/shared/src/main/scala/io/kaitai/struct/NimClassCompiler.scala index 07da3f25b..a3f308dfc 100644 --- a/shared/src/main/scala/io/kaitai/struct/NimClassCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/NimClassCompiler.scala @@ -106,7 +106,7 @@ class NimClassCompiler( lang.attrParse(pi, instName, endian) } - lang.instanceCheckCacheAndReturn(instName, dataType) + lang.instanceReturn(instName, dataType) lang.instanceFooter } diff --git a/shared/src/main/scala/io/kaitai/struct/languages/NimCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/NimCompiler.scala index 10c880038..aaa253f57 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/NimCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/NimCompiler.scala @@ -224,12 +224,9 @@ class NimCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) handleAssignmentSimple(instName, cast) } override def instanceCheckCacheAndReturn(instName: InstanceIdentifier, dataType: DataType): Unit = { - //out.puts(s"if not ${privateMemberName(instanceFlagIdentifier(instName))}:") - val flag = instanceFlagIdentifier(instName) - out.puts(s"if not this.$flag:") + out.puts(s"if this.${instanceFlagIdentifier(instName)}:") out.inc - out.puts(s"this.$flag = true") - instanceReturn(instName, dataType) + out.puts(s"return ${privateMemberName(instName)}") out.dec } override def instanceHeader(className: List[String], instName: InstanceIdentifier, dataType: DataType, isNullable: Boolean): Unit = { @@ -241,6 +238,7 @@ class NimCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) out.puts } override def instanceReturn(instName: InstanceIdentifier, attrType: DataType): Unit = { + out.puts(s"this.${instanceFlagIdentifier(instName)} = true") out.puts(s"return ${privateMemberName(instName)}") } // def normalIO: String = ???