diff --git a/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala b/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala index 8b155ca86..01df5f6dc 100644 --- a/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala +++ b/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala @@ -26,7 +26,8 @@ class TranslatorSpec extends AnyFunSpec { everybodyExcept("100000000000", "100000000000", ResultMap( CppCompiler -> "100000000000LL", GoCompiler -> "int64(100000000000)", - JavaCompiler -> "100000000000L" + JavaCompiler -> "100000000000L", + NimCompiler -> "100000000000'i64", )) } @@ -38,18 +39,21 @@ class TranslatorSpec extends AnyFunSpec { CppCompiler -> "2147483648UL", GoCompiler -> "uint32(2147483648)", JavaCompiler -> "2147483648L", + NimCompiler -> "2147483648'i64", )) // 0xffff_ffff everybodyExcept("4294967295", "4294967295", ResultMap( CppCompiler -> "4294967295UL", GoCompiler -> "uint32(4294967295)", JavaCompiler -> "4294967295L", + NimCompiler -> "4294967295'i64", )) // 0x1_0000_0000 everybodyExcept("4294967296", "4294967296", ResultMap( CppCompiler -> "4294967296LL", GoCompiler -> "int64(4294967296)", JavaCompiler -> "4294967296L", + NimCompiler -> "4294967296'i64", )) // -0x7fff_ffff @@ -65,6 +69,7 @@ class TranslatorSpec extends AnyFunSpec { CppCompiler -> "-2147483649LL", GoCompiler -> "int64(-2147483649)", JavaCompiler -> "-2147483649L", + NimCompiler -> "-2147483649'i64", )) // 0x7fff_ffff_ffff_ffff @@ -72,6 +77,7 @@ class TranslatorSpec extends AnyFunSpec { CppCompiler -> "9223372036854775807LL", GoCompiler -> "int64(9223372036854775807)", JavaCompiler -> "9223372036854775807L", + NimCompiler -> "9223372036854775807'i64", )) // 0x8000_0000_0000_0000 everybodyExcept("9223372036854775808", "9223372036854775808", ResultMap( @@ -79,6 +85,7 @@ class TranslatorSpec extends AnyFunSpec { GoCompiler -> "uint64(9223372036854775808)", JavaCompiler -> "0x8000000000000000L", LuaCompiler -> "0x8000000000000000", + NimCompiler -> "9223372036854775808'u64", PHPCompiler -> "-9223372036854775807 - 1", )) // 0xffff_ffff_ffff_ffff @@ -87,6 +94,7 @@ class TranslatorSpec extends AnyFunSpec { GoCompiler -> "uint64(18446744073709551615)", JavaCompiler -> "0xffffffffffffffffL", LuaCompiler -> "0xffffffffffffffff", + NimCompiler -> "18446744073709551615'u64", PHPCompiler -> "-1", )) // -0x7fff_ffff_ffff_ffff @@ -94,6 +102,7 @@ class TranslatorSpec extends AnyFunSpec { CppCompiler -> "-9223372036854775807LL", GoCompiler -> "int64(-9223372036854775807)", JavaCompiler -> "-9223372036854775807L", + NimCompiler -> "-9223372036854775807'i64", )) // -0x8000_0000_0000_0000 everybodyExcept("-9223372036854775808", "-9223372036854775808", ResultMap( @@ -101,6 +110,7 @@ class TranslatorSpec extends AnyFunSpec { GoCompiler -> "int64(-9223372036854775808)", JavaCompiler -> "-9223372036854775808L", LuaCompiler -> "-9223372036854775807 - 1", + NimCompiler -> "-9223372036854775808'i64", PHPCompiler -> "-9223372036854775807 - 1", )) } @@ -122,6 +132,7 @@ class TranslatorSpec extends AnyFunSpec { everybodyExcept("3 / 2", "3 / 2", ResultMap( JavaScriptCompiler -> "Math.floor(3 / 2)", LuaCompiler -> "math.floor(3 / 2)", + NimCompiler -> "3 div 2", PerlCompiler -> "int(3 / 2)", PHPCompiler -> "intval(3 / 2)", PythonCompiler -> "3 // 2" @@ -146,6 +157,7 @@ class TranslatorSpec extends AnyFunSpec { everybodyExcept("(1 + 2) / (7 * 8)", "(1 + 2) / (7 * 8)", ResultMap( JavaScriptCompiler -> "Math.floor((1 + 2) / (7 * 8))", LuaCompiler -> "math.floor((1 + 2) / (7 * 8))", + NimCompiler -> "(1 + 2) div (7 * 8)", PerlCompiler -> "int((1 + 2) / (7 * 8))", PHPCompiler -> "intval((1 + 2) / (7 * 8))", PythonCompiler -> "(1 + 2) // (7 * 8)" @@ -154,26 +166,38 @@ class TranslatorSpec extends AnyFunSpec { everybodyExcept("3 - ((1 + 2) / (7 * 8) + 5)", "3 - ((1 + 2) / (7 * 8) + 5)", ResultMap( JavaScriptCompiler -> "3 - (Math.floor((1 + 2) / (7 * 8)) + 5)", LuaCompiler -> "3 - (math.floor((1 + 2) / (7 * 8)) + 5)", + NimCompiler -> "3 - ((1 + 2) div (7 * 8) + 5)", PerlCompiler -> "3 - (int((1 + 2) / (7 * 8)) + 5)", PHPCompiler -> "3 - (intval((1 + 2) / (7 * 8)) + 5)", PythonCompiler -> "3 - ((1 + 2) // (7 * 8) + 5)" )) - everybody("1 + 2 << 5", "1 + 2 << 5") - everybody("(1 + 2) << 5", "1 + 2 << 5") - everybody("1 + (2 << 5)", "1 + (2 << 5)") + everybodyExcept("1 + 2 << 5", "1 + 2 << 5", ResultMap( + NimCompiler -> "1 + 2 shl 5", + )) + everybodyExcept("(1 + 2) << 5", "1 + 2 << 5", ResultMap( + NimCompiler -> "1 + 2 shl 5", + )) + everybodyExcept("1 + (2 << 5)", "1 + (2 << 5)", ResultMap( + NimCompiler -> "1 + (2 shl 5)", + )) everybodyExcept("~777", "~777", ResultMap( - GoCompiler -> "^777" + GoCompiler -> "^777", + NimCompiler -> "not 777", )) everybodyExcept("~(7+3)", "~(7 + 3)", ResultMap( - GoCompiler -> "^(7 + 3)" + GoCompiler -> "^(7 + 3)", + NimCompiler -> "not (7 + 3)", )) - everybody("(0b01 & 0b11) << 1", "(1 & 3) << 1") + everybodyExcept("(0b01 & 0b11) << 1", "(1 & 3) << 1", ResultMap( + NimCompiler -> "(1 and 3) shl 1", + )) everybodyExcept("(0b01 & 0b10) >> 1", "(1 & 2) >> 1", ResultMap( - JavaScriptCompiler -> "(1 & 2) >>> 1" + JavaScriptCompiler -> "(1 & 2) >>> 1", + NimCompiler -> "(1 and 2) shr 1", )) } @@ -191,6 +215,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "Long.toString(42)", JavaScriptCompiler -> "(42).toString()", LuaCompiler -> "tostring(42)", + NimCompiler -> "intToStr(int(42))", PerlCompiler -> "sprintf('%d', 42)", PHPCompiler -> "strval(42)", PythonCompiler -> "str(42)", @@ -204,6 +229,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "Long.toString(a() + 42)", JavaScriptCompiler -> "(this.a + 42).toString()", LuaCompiler -> "tostring(self.a + 42)", + NimCompiler -> "intToStr(int(this.a + 42))", PerlCompiler -> "sprintf('%d', $self->a() + 42)", PHPCompiler -> "strval($this->a() + 42)", PythonCompiler -> "str(self.a + 42)", @@ -217,6 +243,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "a() + Long.toString(42)", JavaScriptCompiler -> "this.a + (42).toString()", LuaCompiler -> "self.a .. tostring(42)", + NimCompiler -> "$this.a & $intToStr(int(42))", PerlCompiler -> "$self->a() . sprintf('%d', 42)", PHPCompiler -> "$this->a() . strval(42)", PythonCompiler -> "self.a + str(42)", @@ -240,6 +267,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "(2 < 3 ? \"foo\" : \"bar\")", JavaScriptCompiler -> "(2 < 3 ? \"foo\" : \"bar\")", LuaCompiler -> "utils.box_unwrap((2 < 3) and utils.box_wrap(\"foo\") or (\"bar\"))", + NimCompiler -> "if 2 < 3: \"foo\" else: \"bar\"", PerlCompiler -> "(2 < 3 ? \"foo\" : \"bar\")", PHPCompiler -> "(2 < 3 ? \"foo\" : \"bar\")", PythonCompiler -> "(u\"foo\" if 2 < 3 else u\"bar\")", @@ -267,6 +295,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "true", JavaScriptCompiler -> "true", LuaCompiler -> "true", + NimCompiler -> "true", PerlCompiler -> "1", PHPCompiler -> "true", PythonCompiler -> "True", @@ -280,6 +309,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "false", JavaScriptCompiler -> "false", LuaCompiler -> "false", + NimCompiler -> "false", PerlCompiler -> "0", PHPCompiler -> "false", PythonCompiler -> "False", @@ -300,6 +330,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "(someBool() ? 1 : 0)", JavaScriptCompiler -> "(this.someBool | 0)", LuaCompiler -> "(self.some_bool and 1 or 0)", + NimCompiler -> "if this.someBool: 1 else: 0", PerlCompiler -> "$self->some_bool()", PHPCompiler -> "intval($this->someBool())", PythonCompiler -> "int(self.some_bool)", @@ -315,6 +346,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "fooStr()", JavaScriptCompiler -> "this.fooStr", LuaCompiler -> "self.foo_str", + NimCompiler -> "this.fooStr", PerlCompiler -> "$self->foo_str()", PHPCompiler -> "$this->fooStr()", PythonCompiler -> "self.foo_str", @@ -328,6 +360,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "fooBlock()", JavaScriptCompiler -> "this.fooBlock", LuaCompiler -> "self.foo_block", + NimCompiler -> "this.fooBlock", PerlCompiler -> "$self->foo_block()", PHPCompiler -> "$this->fooBlock()", PythonCompiler -> "self.foo_block", @@ -341,6 +374,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "foo().bar()", JavaScriptCompiler -> "this.foo.bar", LuaCompiler -> "self.foo.bar", + NimCompiler -> "this.foo.bar", PerlCompiler -> "$self->foo()->bar()", PHPCompiler -> "$this->foo()->bar()", PythonCompiler -> "self.foo.bar", @@ -354,6 +388,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "foo().inner().baz()", JavaScriptCompiler -> "this.foo.inner.baz", LuaCompiler -> "self.foo.inner.baz", + NimCompiler -> "this.foo.inner.baz", PerlCompiler -> "$self->foo()->inner()->baz()", PHPCompiler -> "$this->foo()->inner()->baz()", PythonCompiler -> "self.foo.inner.baz", @@ -367,6 +402,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "_root().foo()", JavaScriptCompiler -> "this._root.foo", LuaCompiler -> "self._root.foo", + NimCompiler -> "TopClass_Block(this.root).foo", PerlCompiler -> "$self->_root()->foo()", PHPCompiler -> "$this->_root()->foo()", PythonCompiler -> "self._root.foo", @@ -380,6 +416,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> " ((a() != 2) && (a() != 5)) ", JavaScriptCompiler -> " ((this.a != 2) && (this.a != 5)) ", LuaCompiler -> " ((self.a ~= 2) and (self.a ~= 5)) ", + NimCompiler -> " ((this.a != 2) and (this.a != 5)) ", PerlCompiler -> " (($self->a() != 2) && ($self->a() != 5)) ", PHPCompiler -> " (($this->a() != 2) && ($this->a() != 5)) ", PythonCompiler -> " ((self.a != 2) and (self.a != 5)) ", @@ -395,6 +432,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "new ArrayList(Arrays.asList(0, 1, 100500))", JavaScriptCompiler -> "[0, 1, 100500]", LuaCompiler -> "{0, 1, 100500}", + NimCompiler -> "@[int(0), int(1), int(100500)]", PerlCompiler -> "[0, 1, 100500]", PHPCompiler -> "[0, 1, 100500]", PythonCompiler -> "[0, 1, 100500]", @@ -408,6 +446,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "new byte[] { 34, 0, 10, 64, 65, 66, 92 }", JavaScriptCompiler -> "new Uint8Array([34, 0, 10, 64, 65, 66, 92])", LuaCompiler -> "\"\\x22\\x00\\x0A\\x40\\x41\\x42\\x5C\"", + NimCompiler -> "@[34'u8, 0'u8, 10'u8, 64'u8, 65'u8, 66'u8, 92'u8]", PerlCompiler -> "pack('C*', (34, 0, 10, 64, 65, 66, 92))", PHPCompiler -> "\"\\x22\\x00\\x0A\\x40\\x41\\x42\\x5C\"", PythonCompiler -> "b\"\\x22\\x00\\x0A\\x40\\x41\\x42\\x5C\"", @@ -421,6 +460,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "new byte[] { -1, 0, -1 }", JavaScriptCompiler -> "new Uint8Array([255, 0, 255])", LuaCompiler -> "\"\\xFF\\x00\\xFF\"", + NimCompiler -> "@[255'u8, 0'u8, 255'u8]", PerlCompiler -> "pack('C*', (255, 0, 255))", PHPCompiler -> "\"\\xFF\\x00\\xFF\"", PythonCompiler -> "b\"\\xFF\\x00\\xFF\"", @@ -436,6 +476,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "new byte[] { 0, 1, 2 }.length", JavaScriptCompiler -> "new Uint8Array([0, 1, 2]).length", LuaCompiler -> "#\"\\x00\\x01\\x02\"", + NimCompiler -> "len(@[0'u8, 1'u8, 2'u8])", PerlCompiler -> "length(pack('C*', (0, 1, 2)))", PHPCompiler -> "strlen(\"\\x00\\x01\\x02\")", PythonCompiler -> "len(b\"\\x00\\x01\\x02\")", @@ -449,6 +490,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "a().get((int) 42)", JavaScriptCompiler -> "this.a[42]", LuaCompiler -> "self.a[42 + 1]", // TODO: self.a[43] + NimCompiler -> "this.a[42]", PerlCompiler -> "@{$self->a()}[42]", PHPCompiler -> "$this->a()[42]", PythonCompiler -> "self.a[42]", @@ -462,6 +504,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "a().get((int) (42 - 2))", JavaScriptCompiler -> "this.a[42 - 2]", LuaCompiler -> "self.a[42 - 2 + 1]", // TODO: self.a[41] + NimCompiler -> "this.a[42 - 2]", PerlCompiler -> "@{$self->a()}[42 - 2]", PHPCompiler -> "$this->a()[42 - 2]", PythonCompiler -> "self.a[42 - 2]", @@ -475,6 +518,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "a().get(0)", JavaScriptCompiler -> "this.a[0]", LuaCompiler -> "self.a[1]", + NimCompiler -> "this.a[0]", PerlCompiler -> "@{$self->a()}[0]", PHPCompiler -> "$this->a()[0]", PythonCompiler -> "self.a[0]", @@ -490,6 +534,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "a().get(a().size() - 1)", JavaScriptCompiler -> "this.a[this.a.length - 1]", LuaCompiler -> "self.a[#self.a]", + NimCompiler -> "this.a[^1]", PerlCompiler -> "@{$self->a()}[-1]", PHPCompiler -> "$this->a()[count($this->a()) - 1]", PythonCompiler -> "self.a[-1]", @@ -503,6 +548,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "a().size()", JavaScriptCompiler -> "this.a.length", LuaCompiler -> "#self.a", + NimCompiler -> "len(this.a)", PHPCompiler -> "count($this->a())", PerlCompiler -> "scalar(@{$self->a()})", PythonCompiler -> "len(self.a)", @@ -520,6 +566,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "\"str\"", JavaScriptCompiler -> "\"str\"", LuaCompiler -> "\"str\"", + NimCompiler -> "\"str\"", PerlCompiler -> "\"str\"", PHPCompiler -> "\"str\"", PythonCompiler -> "u\"str\"", @@ -533,6 +580,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "\"str\\nnext\"", JavaScriptCompiler -> "\"str\\nnext\"", LuaCompiler -> "\"str\\nnext\"", + NimCompiler -> "\"str\\nnext\"", PerlCompiler -> "\"str\\nnext\"", PHPCompiler -> "\"str\\nnext\"", PythonCompiler -> "u\"str\\nnext\"", @@ -546,6 +594,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "\"str\\nnext\"", JavaScriptCompiler -> "\"str\\nnext\"", LuaCompiler -> "\"str\\nnext\"", + NimCompiler -> "\"str\\nnext\"", PerlCompiler -> "\"str\\nnext\"", PHPCompiler -> "\"str\\nnext\"", PythonCompiler -> "u\"str\\nnext\"", @@ -559,6 +608,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "\"str\\000next\"", JavaScriptCompiler -> "\"str\\x00next\"", LuaCompiler -> "\"str\\x00next\"", + NimCompiler -> "\"str\\x00next\"", PerlCompiler -> "\"str\\x00next\"", PHPCompiler -> "\"str\\x00next\"", PythonCompiler -> "u\"str\\x00next\"", @@ -570,6 +620,7 @@ class TranslatorSpec extends AnyFunSpec { everybodyExcept("\"str1\" + \"str2\"", "\"str1\" + \"str2\"", ResultMap( CppCompiler -> "std::string(\"str1\") + std::string(\"str2\")", LuaCompiler -> "\"str1\" .. \"str2\"", + NimCompiler -> "$\"str1\" & $\"str2\"", PerlCompiler -> "\"str1\" . \"str2\"", PHPCompiler -> "\"str1\" . \"str2\"", PythonCompiler -> "u\"str1\" + u\"str2\"" @@ -609,6 +660,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "\"str\".length()", JavaScriptCompiler -> "\"str\".length", LuaCompiler -> "string.len(\"str\")", + NimCompiler -> "len(\"str\")", PerlCompiler -> "length(\"str\")", PHPCompiler -> "strlen(\"str\")", PythonCompiler -> "len(u\"str\")", @@ -622,6 +674,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "(foo() + bar()).length()", JavaScriptCompiler -> "(this.foo + this.bar).length", LuaCompiler -> "string.len(self.foo .. self.bar)", + NimCompiler -> "len($this.foo & $this.bar)", PerlCompiler -> "length($self->foo() . $self->bar())", PHPCompiler -> "strlen($this->foo() . $this->bar())", PythonCompiler -> "len(self.foo + self.bar)", @@ -635,6 +688,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "new StringBuilder(\"str\").reverse().toString()", JavaScriptCompiler -> "Array.from(\"str\").reverse().join('')", LuaCompiler -> "string.reverse(\"str\")", + NimCompiler -> "reversed(\"str\")", PerlCompiler -> "scalar(reverse(\"str\"))", PHPCompiler -> "strrev(\"str\")", PythonCompiler -> "(u\"str\")[::-1]", @@ -648,6 +702,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "new StringBuilder(foo() + bar()).reverse().toString()", JavaScriptCompiler -> "Array.from(this.foo + this.bar).reverse().join('')", LuaCompiler -> "string.reverse(self.foo .. self.bar)", + NimCompiler -> "reversed($this.foo & $this.bar)", PerlCompiler -> "scalar(reverse($self->foo() . $self->bar()))", PHPCompiler -> "strrev($this->foo() . $this->bar())", PythonCompiler -> "(self.foo + self.bar)[::-1]", @@ -666,6 +721,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "Long.parseLong(\"12345\", 10)", JavaScriptCompiler -> "Number.parseInt(\"12345\", 10)", LuaCompiler -> "tonumber(\"12345\")", + NimCompiler -> "\"12345\".parseInt(10)", PerlCompiler -> "\"12345\" + 0", PHPCompiler -> "intval(\"12345\", 10)", PythonCompiler -> "int(u\"12345\")", @@ -684,6 +740,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "Long.parseLong(\"1234fe\", 16)", JavaScriptCompiler -> "Number.parseInt(\"1234fe\", 16)", LuaCompiler -> "tonumber(\"1234fe\", 16)", + NimCompiler -> "\"1234fe\".parseInt(16)", PerlCompiler -> "hex(\"1234fe\")", PHPCompiler -> "intval(\"1234fe\", 16)", PythonCompiler -> "int(u\"1234fe\", 16)", @@ -698,6 +755,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "\"foobar\".substring(2, 4)", JavaScriptCompiler -> "\"foobar\".substring(2, 4)", LuaCompiler -> "string.sub(\"foobar\", 2 + 1, 4)", + NimCompiler -> "\"foobar\".substr(2, 4 - 1)", PerlCompiler -> "substr(\"foobar\", 2, 4 - 2)", PHPCompiler -> "\\Kaitai\\Struct\\Stream::substring(\"foobar\", 2, 4)", PythonCompiler -> "u\"foobar\"[2:4]", @@ -713,6 +771,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "(foo() + bar()).substring(2, 4)", JavaScriptCompiler -> "(this.foo + this.bar).substring(2, 4)", LuaCompiler -> "string.sub(self.foo .. self.bar, 2 + 1, 4)", + NimCompiler -> "($this.foo & $this.bar).substr(2, 4 - 1)", PerlCompiler -> "substr($self->foo() . $self->bar(), 2, 4 - 2)", PHPCompiler -> "\\Kaitai\\Struct\\Stream::substring($this->foo() . $this->bar(), 2, 4)", PythonCompiler -> "(self.foo + self.bar)[2:4]", @@ -728,6 +787,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "foo().substring(10 - 7, 10 - 3)", JavaScriptCompiler -> "this.foo.substring(10 - 7, 10 - 3)", LuaCompiler -> "string.sub(self.foo, (10 - 7) + 1, 10 - 3)", // TODO: LuaCompiler -> "string.sub(self.foo, 10 - 7 + 1, 10 - 3)", + NimCompiler -> "this.foo.substr(10 - 7, 10 - 3 - 1)", PerlCompiler -> "substr($self->foo(), 10 - 7, (10 - 3) - (10 - 7))", // TODO: PerlCompiler -> "substr($self->foo(), 10 - 7, 10 - 3 - (10 - 7))", PHPCompiler -> "\\Kaitai\\Struct\\Stream::substring($this->foo(), 10 - 7, 10 - 3)", PythonCompiler -> "self.foo[10 - 7:10 - 3]", @@ -743,6 +803,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "foo().substring(10 - 7, 10 << 2)", JavaScriptCompiler -> "this.foo.substring(10 - 7, 10 << 2)", LuaCompiler -> "string.sub(self.foo, (10 - 7) + 1, 10 << 2)", // TODO: LuaCompiler -> "string.sub(self.foo, 10 - 7 + 1, 10 << 2)", + NimCompiler -> "this.foo.substr(10 - 7, 10 shl 2 - 1)", PerlCompiler -> "substr($self->foo(), 10 - 7, (10 << 2) - (10 - 7))", PHPCompiler -> "\\Kaitai\\Struct\\Stream::substring($this->foo(), 10 - 7, 10 << 2)", PythonCompiler -> "self.foo[10 - 7:10 << 2]", @@ -758,6 +819,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "foo().substring(10 << 1, 42)", JavaScriptCompiler -> "this.foo.substring(10 << 1, 42)", LuaCompiler -> "string.sub(self.foo, (10 << 1) + 1, 42)", + NimCompiler -> "this.foo.substr(10 shl 1, 42 - 1)", PerlCompiler -> "substr($self->foo(), 10 << 1, 42 - (10 << 1))", PHPCompiler -> "\\Kaitai\\Struct\\Stream::substring($this->foo(), 10 << 1, 42)", PythonCompiler -> "self.foo[10 << 1:42]", @@ -775,6 +837,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "((TopClass.Block) (other())).bar()", JavaScriptCompiler -> "this.other.bar", LuaCompiler -> "self.other.bar", + NimCompiler -> "TopClass_Block(this.other).bar", PerlCompiler -> "$self->other()->bar()", PHPCompiler -> "$this->other()->bar()", PythonCompiler -> "self.other.bar", @@ -788,6 +851,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "((TopClass.Block.Innerblock) (other())).baz()", JavaScriptCompiler -> "this.other.baz", LuaCompiler -> "self.other.baz", + NimCompiler -> "TopClass_Block_Innerblock(this.other).baz", PerlCompiler -> "$self->other()->baz()", PHPCompiler -> "$this->other()->baz()", PythonCompiler -> "self.other.baz", @@ -803,6 +867,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "((short) (1 + 2))", JavaScriptCompiler -> "1 + 2", LuaCompiler -> "1 + 2", + NimCompiler -> "int16(1 + 2)", PerlCompiler -> "1 + 2", PHPCompiler -> "1 + 2", PythonCompiler -> "1 + 2", @@ -818,6 +883,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "new byte[] { }", JavaScriptCompiler -> "new Uint8Array([])", LuaCompiler -> "\"\"", + NimCompiler -> "@[]", PerlCompiler -> "pack('C*', ())", PHPCompiler -> "\"\"", PythonCompiler -> "b\"\"", @@ -831,6 +897,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "new ArrayList(Arrays.asList())", JavaScriptCompiler -> "[]", LuaCompiler -> "{}", + NimCompiler -> "@[]", PerlCompiler -> "[]", PHPCompiler -> "[]", PythonCompiler -> "[]", @@ -844,6 +911,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "new ArrayList(Arrays.asList())", JavaScriptCompiler -> "[]", LuaCompiler -> "{}", + NimCompiler -> "@[]", PerlCompiler -> "[]", PHPCompiler -> "[]", PythonCompiler -> "[]", @@ -860,6 +928,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "new byte[] { 0 + 1, 5 }", JavaScriptCompiler -> "new Uint8Array([0 + 1, 5])", LuaCompiler -> "string.char(0 + 1, 5)", + NimCompiler -> "@[0 + 1, 5]", PerlCompiler -> "pack('C*', (0 + 1, 5))", PHPCompiler -> "pack('C*', 0 + 1, 5)", PythonCompiler -> "struct.pack('2B', 0 + 1, 5)", @@ -873,6 +942,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "new ArrayList(Arrays.asList(0, 1, 2))", JavaScriptCompiler -> "[0, 1, 2]", LuaCompiler -> "{0, 1, 2}", + NimCompiler -> "@[uint8(0), uint8(1), uint8(2)]", PerlCompiler -> "[0, 1, 2]", PHPCompiler -> "[0, 1, 2]", PythonCompiler -> "[0, 1, 2]", @@ -928,6 +998,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> "\"abc\" + Long.toString(1) + \"%def\"", JavaScriptCompiler -> "\"abc\" + (1).toString() + \"%def\"", LuaCompiler -> "\"abc\" .. tostring(1) .. \"%def\"", + NimCompiler -> "\"abc\" & intToStr(int(1)) & \"%def\"", PerlCompiler -> "\"abc\" . sprintf('%d', 1) . \"\\%def\"", PHPCompiler -> "\"abc\" . strval(1) . \"%def\"", PythonCompiler -> "u\"abc\" + str(1) + u\"%def\"", @@ -959,6 +1030,7 @@ class TranslatorSpec extends AnyFunSpec { JavaCompiler -> new JavaTranslator(tp, new ImportList()), JavaScriptCompiler -> new JavaScriptTranslator(tp, new ImportList()), LuaCompiler -> new LuaTranslator(tp, new ImportList()), + NimCompiler -> new NimTranslator(tp, new ImportList()), PerlCompiler -> new PerlTranslator(tp, new ImportList()), PHPCompiler -> new PHPTranslator(tp, RuntimeConfig()), PythonCompiler -> new PythonTranslator(tp, new ImportList(), RuntimeConfig()),