public void ForGeneric() { var args = Array.Empty <TypedValue>(); var results = new TypedValue[1]; TestHelper.DoString( "local a = { x = 10, y = 20, 30, 40 } " + "local b = {} " + "for k, v in next, a do " + " b[k] = v " + "end " + "return b", TestHelper.DefaultEnv, args, results); Assert.AreEqual(LuaValueType.Table, results[0].ValueType); var table = results[0].TableVal; Assert.AreEqual(2, table.SequenceSize); Assert.True(table.GetRaw(TypedValue.MakeString("x"), out var val)); Assert.AreEqual(TypedValue.MakeInt(10), val); Assert.True(table.GetRaw(TypedValue.MakeString("y"), out val)); Assert.AreEqual(TypedValue.MakeInt(20), val); Assert.True(table.GetRaw(TypedValue.MakeInt(1), out val)); Assert.AreEqual(TypedValue.MakeInt(30), val); Assert.True(table.GetRaw(TypedValue.MakeInt(2), out val)); Assert.AreEqual(TypedValue.MakeInt(40), val); }
public LiteralExpressionGenerator(FunctionGenerator func, LiteralExpressionSyntaxNode expr) : base(0) { var type = expr.SpecializationType.GetVMSpecializationType(); var k = func.Constants; _constIndex = type switch { VMSpecializationType.Nil => k.GetUnspecializedNil(), VMSpecializationType.Bool => expr.BoolValue ? k.GetUnspecializedTrue() : k.GetUnspecializedFalse(), VMSpecializationType.Double => k.AddUnspecialized(TypedValue.MakeDouble(expr.DoubleValue)), VMSpecializationType.Int => k.AddUnspecialized(TypedValue.MakeInt(expr.Int32Value)), VMSpecializationType.String => k.AddUnspecialized(TypedValue.MakeString(expr.StringValue)), _ => throw new Exception(), //Internal exception. }; _type = type.Deoptimize(); }