From 27c4ecaab8b08c235e593434d71fda8f21bc10db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petri=20H=C3=A4kkinen?= Date: Thu, 9 Nov 2023 13:02:43 +0200 Subject: [PATCH] Dump vector constants when outputting bytecode as text --- Common/include/Luau/Bytecode.h | 2 +- Compiler/src/BytecodeBuilder.cpp | 3 +++ tests/Compiler.test.cpp | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Common/include/Luau/Bytecode.h b/Common/include/Luau/Bytecode.h index 65542e93..88e422f2 100644 --- a/Common/include/Luau/Bytecode.h +++ b/Common/include/Luau/Bytecode.h @@ -70,7 +70,7 @@ enum LuauOpcode // D: value (-32768..32767) LOP_LOADN, - // LOADK: sets register to an entry from the constant table from the proto (number/string) + // LOADK: sets register to an entry from the constant table from the proto (number/vector/string) // A: target register // D: constant table index (0..32767) LOP_LOADK, diff --git a/Compiler/src/BytecodeBuilder.cpp b/Compiler/src/BytecodeBuilder.cpp index de5f2658..44fd99bf 100644 --- a/Compiler/src/BytecodeBuilder.cpp +++ b/Compiler/src/BytecodeBuilder.cpp @@ -1681,6 +1681,9 @@ void BytecodeBuilder::dumpConstant(std::string& result, int k) const case Constant::Type_Number: formatAppend(result, "%.17g", data.valueNumber); break; + case Constant::Type_Vector: + formatAppend(result, "%.17g, %.17g, %.17g", data.valueVector[0], data.valueVector[1], data.valueVector[2]); + break; case Constant::Type_String: { const StringRef& str = debugStrings[data.valueString - 1]; diff --git a/tests/Compiler.test.cpp b/tests/Compiler.test.cpp index 0e7de2bb..0e4f24f3 100644 --- a/tests/Compiler.test.cpp +++ b/tests/Compiler.test.cpp @@ -4497,13 +4497,13 @@ L0: RETURN R0 -1 TEST_CASE("VectorLiterals") { CHECK_EQ("\n" + compileFunction("return Vector3.new(1, 2, 3)", 0, 2, true), R"( -LOADK R0 K0 [] +LOADK R0 K0 [1, 2, 3] RETURN R0 1 )"); CHECK_EQ("\n" + compileFunction("print(Vector3.new(1, 2, 3))", 0, 2, true), R"( GETIMPORT R0 1 [print] -LOADK R1 K2 [] +LOADK R1 K2 [1, 2, 3] CALL R0 1 0 RETURN R0 0 )");