Skip to content

Commit

Permalink
add support for initializing multi-dim arrays (dotnet#5011)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonerdo committed Jul 21, 2019
1 parent 002f528 commit c81e26a
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
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,25 @@ 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));
}
}
}
}

0 comments on commit c81e26a

Please sign in to comment.