|
@@ -50,7 +50,6 @@ internal class Function : IPoolNode<Function>
|
|
|
pool.TryPush(this);
|
|
pool.TryPush(this);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public const int OprMinus = 0;
|
|
public const int OprMinus = 0;
|
|
|
|
|
|
|
|
public const int OprNot = 1;
|
|
public const int OprNot = 1;
|
|
@@ -97,7 +96,6 @@ internal class Function : IPoolNode<Function>
|
|
|
|
|
|
|
|
public const int OprNoBinary = 15;
|
|
public const int OprNoBinary = 15;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void OpenFunction(int line)
|
|
public void OpenFunction(int line)
|
|
|
{
|
|
{
|
|
|
var newProto = PrototypeBuilder.Get(P.Scanner.Source);
|
|
var newProto = PrototypeBuilder.Get(P.Scanner.Source);
|
|
@@ -114,7 +112,6 @@ internal class Function : IPoolNode<Function>
|
|
|
P.Function.EnterBlock(false);
|
|
P.Function.EnterBlock(false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public ExprDesc CloseFunction()
|
|
public ExprDesc CloseFunction()
|
|
|
{
|
|
{
|
|
|
var e = P.Function.Previous!.ExpressionToNextRegister(MakeExpression(Kind.Relocatable, Previous!.EncodeABx(OpCode.Closure, 0, Previous!.Proto.PrototypeList.Length - 1)));
|
|
var e = P.Function.Previous!.ExpressionToNextRegister(MakeExpression(Kind.Relocatable, Previous!.EncodeABx(OpCode.Closure, 0, Previous!.Proto.PrototypeList.Length - 1)));
|
|
@@ -127,7 +124,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return e;
|
|
return e;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void EnterBlock(bool isLoop)
|
|
public void EnterBlock(bool isLoop)
|
|
|
{
|
|
{
|
|
|
var b = Block.Get(Block, P.ActiveLabels.Length, P.PendingGotos.Length, ActiveVariableCount, false, isLoop);
|
|
var b = Block.Get(Block, P.ActiveLabels.Length, P.PendingGotos.Length, ActiveVariableCount, false, isLoop);
|
|
@@ -135,7 +131,6 @@ internal class Function : IPoolNode<Function>
|
|
|
Assert(FreeRegisterCount == ActiveVariableCount);
|
|
Assert(FreeRegisterCount == ActiveVariableCount);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void UndefinedGotoError(Label g)
|
|
public void UndefinedGotoError(Label g)
|
|
|
{
|
|
{
|
|
|
if (Scanner.IsReserved(g.Name))
|
|
if (Scanner.IsReserved(g.Name))
|
|
@@ -148,14 +143,12 @@ internal class Function : IPoolNode<Function>
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public ref LocalVariable LocalVariable(int i)
|
|
public ref LocalVariable LocalVariable(int i)
|
|
|
{
|
|
{
|
|
|
var index = P.ActiveVariables[FirstLocal + i];
|
|
var index = P.ActiveVariables[FirstLocal + i];
|
|
|
return ref Proto.LocalVariablesList[index];
|
|
return ref Proto.LocalVariablesList[index];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void AdjustLocalVariables(int n)
|
|
public void AdjustLocalVariables(int n)
|
|
|
{
|
|
{
|
|
|
for (ActiveVariableCount += n; n != 0; n--)
|
|
for (ActiveVariableCount += n; n != 0; n--)
|
|
@@ -164,7 +157,6 @@ internal class Function : IPoolNode<Function>
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void RemoveLocalVariables(int level)
|
|
public void RemoveLocalVariables(int level)
|
|
|
{
|
|
{
|
|
|
for (var i = level; i < ActiveVariableCount; i++)
|
|
for (var i = level; i < ActiveVariableCount; i++)
|
|
@@ -176,7 +168,6 @@ internal class Function : IPoolNode<Function>
|
|
|
ActiveVariableCount = level;
|
|
ActiveVariableCount = level;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void MakeLocalVariable(string name)
|
|
public void MakeLocalVariable(string name)
|
|
|
{
|
|
{
|
|
|
var r = Proto.LocalVariablesList.Length;
|
|
var r = Proto.LocalVariablesList.Length;
|
|
@@ -185,21 +176,18 @@ internal class Function : IPoolNode<Function>
|
|
|
P.ActiveVariables.Add(r);
|
|
P.ActiveVariables.Add(r);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void MakeGoto(string name, int line, int pc)
|
|
public void MakeGoto(string name, int line, int pc)
|
|
|
{
|
|
{
|
|
|
P.PendingGotos.Add(new() { Name = name, Line = line, Pc = pc, ActiveVariableCount = ActiveVariableCount });
|
|
P.PendingGotos.Add(new() { Name = name, Line = line, Pc = pc, ActiveVariableCount = ActiveVariableCount });
|
|
|
FindLabel((P.PendingGotos.Length - 1));
|
|
FindLabel((P.PendingGotos.Length - 1));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public int MakeLabel(string name, int line)
|
|
public int MakeLabel(string name, int line)
|
|
|
{
|
|
{
|
|
|
P.ActiveLabels.Add(new() { Name = name, Line = line, Pc = Proto.CodeList.Length, ActiveVariableCount = ActiveVariableCount });
|
|
P.ActiveLabels.Add(new() { Name = name, Line = line, Pc = Proto.CodeList.Length, ActiveVariableCount = ActiveVariableCount });
|
|
|
return (P.ActiveLabels.Length - 1);
|
|
return (P.ActiveLabels.Length - 1);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void CloseGoto(int i, Label l)
|
|
public void CloseGoto(int i, Label l)
|
|
|
{
|
|
{
|
|
|
var g = P.PendingGotos[i];
|
|
var g = P.PendingGotos[i];
|
|
@@ -213,7 +201,6 @@ internal class Function : IPoolNode<Function>
|
|
|
P.PendingGotos.RemoveAtSwapBack(i);
|
|
P.PendingGotos.RemoveAtSwapBack(i);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public int FindLabel(int i)
|
|
public int FindLabel(int i)
|
|
|
{
|
|
{
|
|
|
var g = P.PendingGotos[i];
|
|
var g = P.PendingGotos[i];
|
|
@@ -235,7 +222,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void CheckRepeatedLabel(string name)
|
|
public void CheckRepeatedLabel(string name)
|
|
|
{
|
|
{
|
|
|
foreach (var l in P.ActiveLabels.AsSpan().Slice(Block.FirstLabel))
|
|
foreach (var l in P.ActiveLabels.AsSpan().Slice(Block.FirstLabel))
|
|
@@ -247,7 +233,6 @@ internal class Function : IPoolNode<Function>
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void FindGotos(int label)
|
|
public void FindGotos(int label)
|
|
|
{
|
|
{
|
|
|
for (var i = Block.FirstGoto; i < P.PendingGotos.Length;)
|
|
for (var i = Block.FirstGoto; i < P.PendingGotos.Length;)
|
|
@@ -280,7 +265,6 @@ internal class Function : IPoolNode<Function>
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void LeaveBlock()
|
|
public void LeaveBlock()
|
|
|
{
|
|
{
|
|
|
var b = Block;
|
|
var b = Block;
|
|
@@ -313,7 +297,6 @@ internal class Function : IPoolNode<Function>
|
|
|
b.Release();
|
|
b.Release();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public static int Not(int b) => b == 0 ? 1 : 0;
|
|
public static int Not(int b) => b == 0 ? 1 : 0;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -326,7 +309,6 @@ internal class Function : IPoolNode<Function>
|
|
|
P.Scanner.SyntaxError(message);
|
|
P.Scanner.SyntaxError(message);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void BreakLabel() => FindGotos(MakeLabel("break", 0));
|
|
public void BreakLabel() => FindGotos(MakeLabel("break", 0));
|
|
|
|
|
|
|
|
[Conditional("DEBUG")]
|
|
[Conditional("DEBUG")]
|
|
@@ -356,13 +338,11 @@ internal class Function : IPoolNode<Function>
|
|
|
Proto.LineInfoList.Pop();
|
|
Proto.LineInfoList.Pop();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public int EncodeABC(OpCode op, int a, int b, int c)
|
|
public int EncodeABC(OpCode op, int a, int b, int c)
|
|
|
{
|
|
{
|
|
|
return Encode(CreateABC(op, a, b, c));
|
|
return Encode(CreateABC(op, a, b, c));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public int EncodeABx(OpCode op, int a, int bx) => Encode(CreateABx(op, a, bx));
|
|
public int EncodeABx(OpCode op, int a, int bx) => Encode(CreateABx(op, a, bx));
|
|
|
|
|
|
|
|
|
|
|
|
@@ -380,7 +360,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return pc;
|
|
return pc;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public ExprDesc EncodeString(string s) => MakeExpression(Kind.Constant, StringConstant(s));
|
|
public ExprDesc EncodeString(string s) => MakeExpression(Kind.Constant, StringConstant(s));
|
|
|
|
|
|
|
|
|
|
|
|
@@ -408,7 +387,6 @@ internal class Function : IPoolNode<Function>
|
|
|
EncodeABC(OpCode.LoadNil, from, n - 1, 0);
|
|
EncodeABC(OpCode.LoadNil, from, n - 1, 0);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public int Jump()
|
|
public int Jump()
|
|
|
{
|
|
{
|
|
|
Assert(IsJumpListWalkable(JumpPc));
|
|
Assert(IsJumpListWalkable(JumpPc));
|
|
@@ -432,7 +410,6 @@ internal class Function : IPoolNode<Function>
|
|
|
SetReturns(e, MultipleReturns);
|
|
SetReturns(e, MultipleReturns);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void Return(ExprDesc e, int resultCount)
|
|
public void Return(ExprDesc e, int resultCount)
|
|
|
{
|
|
{
|
|
|
if (e.HasMultipleReturns())
|
|
if (e.HasMultipleReturns())
|
|
@@ -456,14 +433,12 @@ internal class Function : IPoolNode<Function>
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public int ConditionalJump(OpCode op, int a, int b, int c)
|
|
public int ConditionalJump(OpCode op, int a, int b, int c)
|
|
|
{
|
|
{
|
|
|
EncodeABC(op, a, b, c);
|
|
EncodeABC(op, a, b, c);
|
|
|
return Jump();
|
|
return Jump();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void FixJump(int pc, int dest)
|
|
public void FixJump(int pc, int dest)
|
|
|
{
|
|
{
|
|
|
Assert(IsJumpListWalkable(pc));
|
|
Assert(IsJumpListWalkable(pc));
|
|
@@ -480,7 +455,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return LastTarget;
|
|
return LastTarget;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public int Jump(int pc)
|
|
public int Jump(int pc)
|
|
|
{
|
|
{
|
|
|
Assert(IsJumpListWalkable(pc));
|
|
Assert(IsJumpListWalkable(pc));
|
|
@@ -490,7 +464,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return NoJump;
|
|
return NoJump;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public bool IsJumpListWalkable(int list)
|
|
public bool IsJumpListWalkable(int list)
|
|
|
{
|
|
{
|
|
|
if (list == NoJump)
|
|
if (list == NoJump)
|
|
@@ -501,7 +474,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return offset == NoJump || IsJumpListWalkable(list + 1 + offset);
|
|
return offset == NoJump || IsJumpListWalkable(list + 1 + offset);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public ref Instruction JumpControl(int pc)
|
|
public ref Instruction JumpControl(int pc)
|
|
|
{
|
|
{
|
|
|
if (pc >= 1 && TestTMode(Proto.CodeList[pc - 1].OpCode))
|
|
if (pc >= 1 && TestTMode(Proto.CodeList[pc - 1].OpCode))
|
|
@@ -509,7 +481,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return ref Proto.CodeList[pc];
|
|
return ref Proto.CodeList[pc];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public bool NeedValue(int list)
|
|
public bool NeedValue(int list)
|
|
|
{
|
|
{
|
|
|
Assert(IsJumpListWalkable(list));
|
|
Assert(IsJumpListWalkable(list));
|
|
@@ -522,7 +493,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public bool PatchTestRegister(int node, int register)
|
|
public bool PatchTestRegister(int node, int register)
|
|
|
{
|
|
{
|
|
|
ref var i = ref JumpControl(node);
|
|
ref var i = ref JumpControl(node);
|
|
@@ -544,7 +514,6 @@ internal class Function : IPoolNode<Function>
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void PatchListHelper(int list, int target, int register, int defaultTarget)
|
|
public void PatchListHelper(int list, int target, int register, int defaultTarget)
|
|
|
{
|
|
{
|
|
|
Assert(IsJumpListWalkable(list));
|
|
Assert(IsJumpListWalkable(list));
|
|
@@ -597,7 +566,6 @@ internal class Function : IPoolNode<Function>
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void PatchToHere(int list)
|
|
public void PatchToHere(int list)
|
|
|
{
|
|
{
|
|
|
Assert(IsJumpListWalkable(list));
|
|
Assert(IsJumpListWalkable(list));
|
|
@@ -640,7 +608,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return index;
|
|
return index;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public unsafe int NumberConstant(double n)
|
|
public unsafe int NumberConstant(double n)
|
|
|
{
|
|
{
|
|
|
if (n == 0.0 || double.IsNaN(n))
|
|
if (n == 0.0 || double.IsNaN(n))
|
|
@@ -664,14 +631,12 @@ internal class Function : IPoolNode<Function>
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void ReserveRegisters(int n)
|
|
public void ReserveRegisters(int n)
|
|
|
{
|
|
{
|
|
|
CheckStack(n);
|
|
CheckStack(n);
|
|
|
FreeRegisterCount += n;
|
|
FreeRegisterCount += n;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void FreeRegister(int r)
|
|
public void FreeRegister(int r)
|
|
|
{
|
|
{
|
|
|
if (!IsConstant(r) && r >= ActiveVariableCount)
|
|
if (!IsConstant(r) && r >= ActiveVariableCount)
|
|
@@ -689,7 +654,6 @@ internal class Function : IPoolNode<Function>
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public int StringConstant(string s)
|
|
public int StringConstant(string s)
|
|
|
{
|
|
{
|
|
|
return AddConstant(s, s);
|
|
return AddConstant(s, s);
|
|
@@ -811,7 +775,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return e;
|
|
return e;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public ExprDesc DischargeToAnyRegister(ExprDesc e)
|
|
public ExprDesc DischargeToAnyRegister(ExprDesc e)
|
|
|
{
|
|
{
|
|
|
if (e.Kind != Kind.NonRelocatable)
|
|
if (e.Kind != Kind.NonRelocatable)
|
|
@@ -823,14 +786,12 @@ internal class Function : IPoolNode<Function>
|
|
|
return e;
|
|
return e;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public int EncodeLabel(int a, int b, int jump)
|
|
public int EncodeLabel(int a, int b, int jump)
|
|
|
{
|
|
{
|
|
|
Label();
|
|
Label();
|
|
|
return EncodeABC(OpCode.LoadBool, a, b, jump);
|
|
return EncodeABC(OpCode.LoadBool, a, b, jump);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public ExprDesc ExpressionToRegister(ExprDesc e, int r)
|
|
public ExprDesc ExpressionToRegister(ExprDesc e, int r)
|
|
|
{
|
|
{
|
|
|
e = DischargeToRegister(e, r);
|
|
e = DischargeToRegister(e, r);
|
|
@@ -863,7 +824,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return e;
|
|
return e;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public ExprDesc ExpressionToNextRegister(ExprDesc e)
|
|
public ExprDesc ExpressionToNextRegister(ExprDesc e)
|
|
|
{
|
|
{
|
|
|
e = DischargeVariables(e);
|
|
e = DischargeVariables(e);
|
|
@@ -872,7 +832,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return ExpressionToRegister(e, FreeRegisterCount - 1);
|
|
return ExpressionToRegister(e, FreeRegisterCount - 1);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public ExprDesc ExpressionToAnyRegister(ExprDesc e)
|
|
public ExprDesc ExpressionToAnyRegister(ExprDesc e)
|
|
|
{
|
|
{
|
|
|
e = DischargeVariables(e);
|
|
e = DischargeVariables(e);
|
|
@@ -889,7 +848,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return ExpressionToNextRegister(e);
|
|
return ExpressionToNextRegister(e);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public ExprDesc ExpressionToAnyRegisterOrUpValue(ExprDesc e)
|
|
public ExprDesc ExpressionToAnyRegisterOrUpValue(ExprDesc e)
|
|
|
{
|
|
{
|
|
|
if (e.Kind != Kind.UpValue || e.HasJumps())
|
|
if (e.Kind != Kind.UpValue || e.HasJumps())
|
|
@@ -900,14 +858,12 @@ internal class Function : IPoolNode<Function>
|
|
|
return e;
|
|
return e;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public ExprDesc ExpressionToValue(ExprDesc e)
|
|
public ExprDesc ExpressionToValue(ExprDesc e)
|
|
|
{
|
|
{
|
|
|
if (e.HasJumps()) return ExpressionToAnyRegister(e);
|
|
if (e.HasJumps()) return ExpressionToAnyRegister(e);
|
|
|
return DischargeVariables(e);
|
|
return DischargeVariables(e);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public (ExprDesc, int) ExpressionToRegisterOrConstant(ExprDesc e)
|
|
public (ExprDesc, int) ExpressionToRegisterOrConstant(ExprDesc e)
|
|
|
{
|
|
{
|
|
|
e = ExpressionToValue(e);
|
|
e = ExpressionToValue(e);
|
|
@@ -949,7 +905,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return (e, e.Info);
|
|
return (e, e.Info);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void StoreVariable(ExprDesc v, ExprDesc e)
|
|
public void StoreVariable(ExprDesc v, ExprDesc e)
|
|
|
{
|
|
{
|
|
|
switch (v.Kind)
|
|
switch (v.Kind)
|
|
@@ -976,7 +931,6 @@ internal class Function : IPoolNode<Function>
|
|
|
FreeExpression(e);
|
|
FreeExpression(e);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public ExprDesc Self(ExprDesc e, ExprDesc key)
|
|
public ExprDesc Self(ExprDesc e, ExprDesc key)
|
|
|
{
|
|
{
|
|
|
e = ExpressionToAnyRegister(e);
|
|
e = ExpressionToAnyRegister(e);
|
|
@@ -990,7 +944,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void InvertJump(int pc)
|
|
public void InvertJump(int pc)
|
|
|
{
|
|
{
|
|
|
ref var i = ref JumpControl(pc);
|
|
ref var i = ref JumpControl(pc);
|
|
@@ -998,7 +951,6 @@ internal class Function : IPoolNode<Function>
|
|
|
i.A = Not(i.A);
|
|
i.A = Not(i.A);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public int JumpOnCondition(ExprDesc e, int cond)
|
|
public int JumpOnCondition(ExprDesc e, int cond)
|
|
|
{
|
|
{
|
|
|
if (e.Kind == Kind.Relocatable)
|
|
if (e.Kind == Kind.Relocatable)
|
|
@@ -1016,7 +968,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return ConditionalJump(OpCode.TestSet, NoRegister, e.Info, cond);
|
|
return ConditionalJump(OpCode.TestSet, NoRegister, e.Info, cond);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public ExprDesc GoIfTrue(ExprDesc e)
|
|
public ExprDesc GoIfTrue(ExprDesc e)
|
|
|
{
|
|
{
|
|
|
var pc = NoJump;
|
|
var pc = NoJump;
|
|
@@ -1042,7 +993,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return e;
|
|
return e;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public ExprDesc GoIfFalse(ExprDesc e)
|
|
public ExprDesc GoIfFalse(ExprDesc e)
|
|
|
{
|
|
{
|
|
|
var pc = NoJump;
|
|
var pc = NoJump;
|
|
@@ -1066,7 +1016,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return e;
|
|
return e;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public ExprDesc EncodeNot(ExprDesc e)
|
|
public ExprDesc EncodeNot(ExprDesc e)
|
|
|
{
|
|
{
|
|
|
e = DischargeVariables(e);
|
|
e = DischargeVariables(e);
|
|
@@ -1102,7 +1051,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return e;
|
|
return e;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public ExprDesc Indexed(ExprDesc t, ExprDesc k)
|
|
public ExprDesc Indexed(ExprDesc t, ExprDesc k)
|
|
|
{
|
|
{
|
|
|
Assert(!t.HasJumps());
|
|
Assert(!t.HasJumps());
|
|
@@ -1155,7 +1103,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return (e1, true);
|
|
return (e1, true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public ExprDesc EncodeArithmetic(OpCode op, ExprDesc e1, ExprDesc e2, int line)
|
|
public ExprDesc EncodeArithmetic(OpCode op, ExprDesc e1, ExprDesc e2, int line)
|
|
|
{
|
|
{
|
|
|
var (e, folded) = FoldConstants(op, e1, e2);
|
|
var (e, folded) = FoldConstants(op, e1, e2);
|
|
@@ -1185,7 +1132,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return e1;
|
|
return e1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public ExprDesc Prefix(int op, ExprDesc e, int line)
|
|
public ExprDesc Prefix(int op, ExprDesc e, int line)
|
|
|
{
|
|
{
|
|
|
switch (op)
|
|
switch (op)
|
|
@@ -1207,7 +1153,6 @@ internal class Function : IPoolNode<Function>
|
|
|
throw new("unreachable");
|
|
throw new("unreachable");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public ExprDesc Infix(int op, ExprDesc e)
|
|
public ExprDesc Infix(int op, ExprDesc e)
|
|
|
{
|
|
{
|
|
|
switch (op)
|
|
switch (op)
|
|
@@ -1238,7 +1183,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return e;
|
|
return e;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public ExprDesc EncodeComparison(OpCode op, int cond, ExprDesc e1, ExprDesc e2)
|
|
public ExprDesc EncodeComparison(OpCode op, int cond, ExprDesc e1, ExprDesc e2)
|
|
|
{
|
|
{
|
|
|
(e1, var o1) = ExpressionToRegisterOrConstant(e1);
|
|
(e1, var o1) = ExpressionToRegisterOrConstant(e1);
|
|
@@ -1253,7 +1197,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return MakeExpression(Kind.Jump, ConditionalJump(op, cond, o1, o2));
|
|
return MakeExpression(Kind.Jump, ConditionalJump(op, cond, o1, o2));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public ExprDesc Postfix(int op, ExprDesc e1, ExprDesc e2, int line)
|
|
public ExprDesc Postfix(int op, ExprDesc e1, ExprDesc e2, int line)
|
|
|
{
|
|
{
|
|
|
switch (op)
|
|
switch (op)
|
|
@@ -1299,7 +1242,6 @@ internal class Function : IPoolNode<Function>
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void FixLine(int line) => Proto.LineInfoList[Proto.CodeList.Length - 1] = line;
|
|
public void FixLine(int line) => Proto.LineInfoList[Proto.CodeList.Length - 1] = line;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1329,7 +1271,6 @@ internal class Function : IPoolNode<Function>
|
|
|
FreeRegisterCount = @base + 1;
|
|
FreeRegisterCount = @base + 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public unsafe void CheckConflict(AssignmentTarget tv, ExprDesc e)
|
|
public unsafe void CheckConflict(AssignmentTarget tv, ExprDesc e)
|
|
|
{
|
|
{
|
|
|
var extra = FreeRegisterCount;
|
|
var extra = FreeRegisterCount;
|
|
@@ -1372,7 +1313,6 @@ internal class Function : IPoolNode<Function>
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void AdjustAssignment(int variableCount, int expressionCount, ExprDesc e)
|
|
public void AdjustAssignment(int variableCount, int expressionCount, ExprDesc e)
|
|
|
{
|
|
{
|
|
|
var extra = variableCount - expressionCount;
|
|
var extra = variableCount - expressionCount;
|
|
@@ -1406,7 +1346,6 @@ internal class Function : IPoolNode<Function>
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public int MakeUpValue(string name, ExprDesc e)
|
|
public int MakeUpValue(string name, ExprDesc e)
|
|
|
{
|
|
{
|
|
|
P.CheckLimit(Proto.UpValuesList.Length + 1, MaxUpValue, "upvalues");
|
|
P.CheckLimit(Proto.UpValuesList.Length + 1, MaxUpValue, "upvalues");
|
|
@@ -1414,7 +1353,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return Proto.UpValuesList.Length - 1;
|
|
return Proto.UpValuesList.Length - 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public static (ExprDesc, bool) SingleVariableHelper(Function? f, string name, bool b)
|
|
public static (ExprDesc, bool) SingleVariableHelper(Function? f, string name, bool b)
|
|
|
{
|
|
{
|
|
|
static Block owningBlock(Block b1, int level)
|
|
static Block owningBlock(Block b1, int level)
|
|
@@ -1493,7 +1431,6 @@ internal class Function : IPoolNode<Function>
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public ExprDesc SingleVariable(string name)
|
|
public ExprDesc SingleVariable(string name)
|
|
|
{
|
|
{
|
|
|
var (e, found) = SingleVariableHelper(this, name, true);
|
|
var (e, found) = SingleVariableHelper(this, name, true);
|
|
@@ -1507,7 +1444,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return e;
|
|
return e;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public (int pc, ExprDesc t) OpenConstructor()
|
|
public (int pc, ExprDesc t) OpenConstructor()
|
|
|
{
|
|
{
|
|
|
var pc = EncodeABC(OpCode.NewTable, 0, 0, 0);
|
|
var pc = EncodeABC(OpCode.NewTable, 0, 0, 0);
|
|
@@ -1515,7 +1451,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return (pc, t);
|
|
return (pc, t);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void FlushFieldToConstructor(int tableRegister, int freeRegisterCount, ExprDesc k, Func<ExprDesc> v)
|
|
public void FlushFieldToConstructor(int tableRegister, int freeRegisterCount, ExprDesc k, Func<ExprDesc> v)
|
|
|
{
|
|
{
|
|
|
(_, var rk) = ExpressionToRegisterOrConstant(k);
|
|
(_, var rk) = ExpressionToRegisterOrConstant(k);
|
|
@@ -1524,7 +1459,6 @@ internal class Function : IPoolNode<Function>
|
|
|
FreeRegisterCount = freeRegisterCount;
|
|
FreeRegisterCount = freeRegisterCount;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public int FlushToConstructor(int tableRegister, int pending, int arrayCount, ExprDesc e)
|
|
public int FlushToConstructor(int tableRegister, int pending, int arrayCount, ExprDesc e)
|
|
|
{
|
|
{
|
|
|
ExpressionToNextRegister(e);
|
|
ExpressionToNextRegister(e);
|
|
@@ -1537,7 +1471,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return pending;
|
|
return pending;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void CloseConstructor(int pc, int tableRegister, int pending, int arrayCount, int hashCount, ExprDesc e)
|
|
public void CloseConstructor(int pc, int tableRegister, int pending, int arrayCount, int hashCount, ExprDesc e)
|
|
|
{
|
|
{
|
|
|
if (pending != 0)
|
|
if (pending != 0)
|
|
@@ -1563,7 +1496,6 @@ internal class Function : IPoolNode<Function>
|
|
|
Proto.CodeList[pc].C = (((hashCount)));
|
|
Proto.CodeList[pc].C = (((hashCount)));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public int OpenForBody(int @base, int n, bool isNumeric)
|
|
public int OpenForBody(int @base, int n, bool isNumeric)
|
|
|
{
|
|
{
|
|
|
var prep = isNumeric ? EncodeAsBx(OpCode.ForPrep, @base, NoJump) : Jump();
|
|
var prep = isNumeric ? EncodeAsBx(OpCode.ForPrep, @base, NoJump) : Jump();
|
|
@@ -1573,7 +1505,6 @@ internal class Function : IPoolNode<Function>
|
|
|
return prep;
|
|
return prep;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void CloseForBody(int prep, int @base, int line, int n, bool isNumeric)
|
|
public void CloseForBody(int prep, int @base, int line, int n, bool isNumeric)
|
|
|
{
|
|
{
|
|
|
LeaveBlock();
|
|
LeaveBlock();
|
|
@@ -1594,14 +1525,12 @@ internal class Function : IPoolNode<Function>
|
|
|
FixLine(line);
|
|
FixLine(line);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void OpenMainFunction()
|
|
public void OpenMainFunction()
|
|
|
{
|
|
{
|
|
|
EnterBlock(false);
|
|
EnterBlock(false);
|
|
|
MakeUpValue("_ENV", MakeExpression(Kind.Local, 0));
|
|
MakeUpValue("_ENV", MakeExpression(Kind.Local, 0));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public Function CloseMainFunction()
|
|
public Function CloseMainFunction()
|
|
|
{
|
|
{
|
|
|
ReturnNone();
|
|
ReturnNone();
|