Skip to content

Commit

Permalink
add support for initializing multi-dim array (dotnet#5011)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonerdo committed May 3, 2020
1 parent e4131da commit ed626d6
Showing 1 changed file with 23 additions and 1 deletion.
Expand Up @@ -313,7 +313,8 @@ public void InterpretMethod(ref CallInterceptorArgs callInterceptorArgs)
InterpretLoadConstant((string)_methodIL.GetObject(reader.ReadILToken()));
break;
case ILOpcode.newobj:
throw new NotImplementedException();
InterpretNewObj(reader.ReadILToken());
break;
case ILOpcode.castclass:
throw new NotImplementedException();
case ILOpcode.isinst:
Expand Down Expand Up @@ -2645,5 +2646,26 @@ private void InterpretCall(int token)
if (!signature.ReturnType.IsVoid)
_stack.Push(callInfo.ReturnValue);
}

private void InterpretNewObj(int token)
{
MethodDesc method = (MethodDesc)_methodIL.GetObject(token);
MethodSignature signature = method.Signature;
TypeDesc owningType = method.OwningType;

if (owningType.IsArray)
{
int[] lengths = new int[signature.Length];

for (int i = 0; i < signature.Length; i++)
{
lengths[i] = PopWithValidation().AsInt32();
}

Array array = RuntimeAugments.NewMultiDimArray(owningType.GetRuntimeTypeHandle(), lengths, null);
_stack.Push(StackItem.FromObjectRef(array));
return;
}
}
}
}

0 comments on commit ed626d6

Please sign in to comment.