本文整理汇总了C#中Emitter.EmitNewArray方法的典型用法代码示例。如果您正苦于以下问题:C# Emitter.EmitNewArray方法的具体用法?C# Emitter.EmitNewArray怎么用?C# Emitter.EmitNewArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Emitter
的用法示例。
在下文中一共展示了Emitter.EmitNewArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compile
public override void Compile(Emitter.Emitter emitter)
{
var args = new[] { Parameters.Count == 1 ? typeof(object) : typeof(IEnumerable<dynamic>), typeof(bool) };
var printMethod = emitter.AssemblyImport(typeof(MirelleStdlib.Printer).GetMethod("Print", args));
if (Parameters.Count == 1)
{
var currType = Parameters[0].GetExpressionType(emitter);
Parameters[0].Compile(emitter);
if (currType.IsAnyOf("int", "bool", "float", "complex"))
emitter.EmitBox(emitter.ResolveType(currType));
}
else
{
var objType = emitter.AssemblyImport(typeof(object));
var arrType = new ArrayType(objType);
var tmpVariable = emitter.CurrentMethod.Scope.Introduce("object[]", arrType);
// load count & create
emitter.EmitLoadInt(Parameters.Count);
emitter.EmitNewArray(objType);
emitter.EmitSaveVariable(tmpVariable);
int idx = 0;
foreach (var curr in Parameters)
{
var currType = curr.GetExpressionType(emitter);
emitter.EmitLoadVariable(tmpVariable);
emitter.EmitLoadInt(idx);
curr.Compile(emitter);
if (currType.IsAnyOf("int", "bool", "float", "complex"))
emitter.EmitBox(emitter.ResolveType(currType));
emitter.EmitSaveIndex("object");
idx++;
}
// return the created array
emitter.EmitLoadVariable(tmpVariable);
}
emitter.EmitLoadBool(PrintLine);
emitter.EmitCall(printMethod);
}
示例2: Compile
public override void Compile(Emitter.Emitter emitter)
{
var typeName = Values[0].GetExpressionType(emitter);
if (typeName == "null")
Error(Resources.errArrayItemNull, Values[0].Lexem);
if (typeName.IsAnyOf("", "void"))
Error(Resources.errVoidExpression, Values[0].Lexem);
TypeReference type;
try
{
type = emitter.ResolveType(typeName);
}
catch (CompilerException ex)
{
ex.AffixToLexem(Values[0].Lexem);
throw;
}
var tmpVariable = emitter.CurrentMethod.Scope.Introduce(typeName, emitter.ResolveType(typeName + "[]"));
// load count & create
emitter.EmitLoadInt(Values.Count);
emitter.EmitNewArray(type);
emitter.EmitSaveVariable(tmpVariable);
int idx = 0;
foreach (var curr in Values)
{
var currType = curr.GetExpressionType(emitter);
if (currType != typeName)
Error(String.Format(Resources.errArrayTypeMismatch, currType, typeName), curr.Lexem);
emitter.EmitLoadVariable(tmpVariable);
emitter.EmitLoadInt(idx);
curr.Compile(emitter);
emitter.EmitSaveIndex(typeName);
idx++;
}
// return the created array
emitter.EmitLoadVariable(tmpVariable);
}