Skip to content

Commit

Permalink
Release version v1.0.9-alpha (#30)
Browse files Browse the repository at this point in the history
V1.0.9 alpha
  • Loading branch information
atrexus authored Jan 22, 2024
2 parents de59e4f + d3ffe3d commit 1c5ce93
Show file tree
Hide file tree
Showing 14 changed files with 430 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/Unluau.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Unluau.CLI
{
class Program
{
private static string Version = "0.0.8-alpha";
private static string Version = "1.0.9-alpha";

/// <summary>
/// Avalible options for the Unluau decompiler/dissasembler.
Expand Down
Binary file added src/Unluau.Test/Binary/GenericForLoopPairs.luau
Binary file not shown.
Binary file added src/Unluau.Test/Binary/NegativeNumbers.luau
Binary file not shown.
Binary file added src/Unluau.Test/Binary/NumericForLoop.luau
Binary file not shown.
12 changes: 12 additions & 0 deletions src/Unluau.Test/Expect/GenericForLoopPairs.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
for var3 in pairs(t) do
print(var3)
end
for var9, var10 in ipairs(t) do
print(var9, var10)
end
for var17, var18 in next, t do
print(var17, var18)
end
for var28 in { "a", "b", "c" } do
print(var28)
end
3 changes: 3 additions & 0 deletions src/Unluau.Test/Expect/NumericForLoop.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for var0 = 10, 1, -1 do
print(var0)
end
12 changes: 12 additions & 0 deletions src/Unluau.Test/UnluauTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,17 @@ public void Test_RepeatUntil()
{
GetAndAssert("Binary/RepeatUntil01.luau", "Expect/RepeatUntil01.lua");
}

[TestMethod]
public void Test_NumericForLoop()
{
GetAndAssert("Binary/NumericForLoop.luau", "Expect/NumericForLoop.lua");
}

[TestMethod]
public void Test_GenericForLoopPairs()
{
GetAndAssert("Binary/GenericForLoopPairs.luau", "Expect/GenericForLoopPairs.lua");
}
}
}
2 changes: 1 addition & 1 deletion src/Unluau/Deserializer/Models/Instruction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public int D
=> (int)_value >> 16;

public int E
=> (int)(_value >> 8);
=> (int)_value >> 8;

public OpCode Code
{
Expand Down
173 changes: 173 additions & 0 deletions src/Unluau/Lifter/Builtin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
// Copyright (c) Valence. All Rights Reserved.
// Licensed under the Apache License, Version 2.0

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Unluau
{
// Note: Ported from Luau source code.
public enum BuiltinFunction : byte
{
NONE = 0,

// assert()
ASSERT,

// math.
MATH_ABS,
MATH_ACOS,
MATH_ASIN,
MATH_ATAN2,
MATH_ATAN,
MATH_CEIL,
MATH_COSH,
MATH_COS,
MATH_DEG,
MATH_EXP,
MATH_FLOOR,
MATH_FMOD,
MATH_FREXP,
MATH_LDEXP,
MATH_LOG10,
MATH_LOG,
MATH_MAX,
MATH_MIN,
MATH_MODF,
MATH_POW,
MATH_RAD,
MATH_SINH,
MATH_SIN,
MATH_SQRT,
MATH_TANH,
MATH_TAN,

// bit32.
BIT32_ARSHIFT,
BIT32_BAND,
BIT32_BNOT,
BIT32_BOR,
BIT32_BXOR,
BIT32_BTEST,
BIT32_EXTRACT,
BIT32_LROTATE,
BIT32_LSHIFT,
BIT32_REPLACE,
BIT32_RROTATE,
BIT32_RSHIFT,

// type()
TYPE,

// string.
STRING_BYTE,
STRING_CHAR,
STRING_LEN,

// typeof()
TYPEOF,

// string.
STRING_SUB,

// math.
MATH_CLAMP,
MATH_SIGN,
MATH_ROUND,

// raw*
RAWSET,
RAWGET,
RAWEQUAL,

// table.
TABLE_INSERT,
TABLE_UNPACK,

// vector ctor
VECTOR,

// bit32.count
BIT32_COUNTLZ,
BIT32_COUNTRZ,

// select(_, ...)
SELECT_VARARG,

// rawlen
RAWLEN,

// bit32.extract(_, k, k)
BIT32_EXTRACTK,

// get/setmetatable
GETMETATABLE,
SETMETATABLE,

// tonumber/tostring
TONUMBER,
TOSTRING,

// bit32.byteswap(n)
BIT32_BYTESWAP,

// buffer.
BUFFER_READI8,
BUFFER_READU8,
BUFFER_WRITEU8,
BUFFER_READI16,
BUFFER_READU16,
BUFFER_WRITEU16,
BUFFER_READI32,
BUFFER_READU32,
BUFFER_WRITEU32,
BUFFER_READF32,
BUFFER_WRITEF32,
BUFFER_READF64,
BUFFER_WRITEF64,
}

public class Builtin
{
public BuiltinFunction Function { get; set; }
public Expression Expression { get; set; }

private Builtin(BuiltinFunction function, Expression expression)
{
Function = function;
Expression = expression;
}

public static Builtin FromId(byte id)
{
var function = (BuiltinFunction)id;

return new(function, ToExpression(function));
}

private static Expression ToExpression(BuiltinFunction function)
{
switch (function)
{
case BuiltinFunction.VECTOR:
return new NameIndex(new Global("Vector3"), "new");

default:
{
string[] names = function.ToString().ToLower().Split('_');

Expression expression = new Global(names[0]);

for (int i = 1; i < names.Length; i++)
expression = new NameIndex(expression, names[i]);

return expression;
}
}
}
}
}
7 changes: 5 additions & 2 deletions src/Unluau/Lifter/Expressions/ExpressionList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ public override void Write(Output output)
{
for (int i = 0; i < Expressions.Count; ++i)
{
Expressions[i].Write(output);
if (Expressions[i] == null)
continue;

if (i != Expressions.Count - 1)
if (i != 0)
output.Write(", ");

Expressions[i].Write(output);
}
}
}
Expand Down
Loading

0 comments on commit 1c5ce93

Please sign in to comment.