Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
likecg committed Nov 18, 2023
1 parent 6da90d6 commit 83fd1cc
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 26 deletions.
9 changes: 7 additions & 2 deletions source/Core/MetaClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,13 @@ public virtual void ParseDefineComplete()
if(m_DefaultExpressNode == null && isTemplateClass == false )
{
MetaType mdt = new MetaType(this);
var cdf = new MetaFunctionCall( this, GetMetaMemberConstructDefaultFunction());
m_DefaultExpressNode = new MetaNewObjectExpressNode(mdt, this, null, cdf );
var defaultFunction = GetMetaMemberConstructDefaultFunction();
MetaFunctionCall mfc = null;
if (defaultFunction != null)
{
mfc = new MetaFunctionCall(this, GetMetaMemberConstructDefaultFunction());
}
m_DefaultExpressNode = new MetaNewObjectExpressNode(mdt, this, null, mfc);
}

List<MetaMemberFunction> addList = new List<MetaMemberFunction>();
Expand Down
11 changes: 11 additions & 0 deletions source/Core/MetaVariable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ public enum EVisitType
Link,
AT
}
public MetaVariable localMetaVariable => m_LocalMetaVariable;
public MetaVariable visitMetaVariable => m_VisitMetaVariable;

MetaVariable m_LocalMetaVariable = null;
private EVisitType m_VisitType = EVisitType.AT;
Expand All @@ -184,6 +186,15 @@ public VisitMetaVariable( MetaVariable lmv, MetaVariable target )
m_VisitMetaVariable = target;
m_DefineMetaType = target.metaDefineType;
}
public int GetIRMemberIndex()
{
var mmv = m_VisitMetaVariable as MetaMemberVariable;
if (mmv != null )
{
return mmv.ownerMetaClass.GetLocalMemberVariableIndex(mmv);
}
return -1;
}
public VisitMetaVariable(string _name, MetaClass mc, MetaBlockStatements mbs, MetaVariable lmv, MetaVariable vmv)
{
m_Name = _name;
Expand Down
18 changes: 18 additions & 0 deletions source/IR/IRCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ void Parse()
{
return;
}
if( !m_MetaFunctionCall.isStaticCall || m_MetaFunctionCall.isConstruction )
{
//IRLoadVariable irload = new IRLoadVariable(m_IRMethod, m_MetaFunctionCall.callerMetaVariable );
//AddIRRangeData(irload.IRDataList);
}
paramCount = m_MetaFunctionCall.metaInputParamCollection.count;
for (int j = 0; j < paramCount; j++)
{
Expand Down Expand Up @@ -207,6 +212,19 @@ public void ParseToIRDataList(IRMethod _irMethod)
IRLoadVariable irVar = new IRLoadVariable(IRManager.instance, mmv);
irList.Add(irVar);
}
else if( cnode.callNodeType == ECallNodeType.VisitVariable )
{
VisitMetaVariable vmv = cnode.GetMetaVariable() as VisitMetaVariable;
if( vmv != null )
{
IRLoadVariable irVar = new IRLoadVariable(IRManager.instance, vmv.visitMetaVariable as MetaMemberVariable );
irList.Add(irVar);
}
else
{
Console.WriteLine("Error convert VisitMetaVariable");
}
}
else if (cnode.callNodeType == ECallNodeType.FunctionName)
{
var mfc = cnode.GetMetaFunctionCall();
Expand Down
3 changes: 2 additions & 1 deletion source/IR/IRStatements/IRAssignStatements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ public override void ParseIRStatements()
{
if (m_FinalMetaExpress != null)
{
m_IRExpress = new IRExpress( irMethod, m_FinalMetaExpress);
m_IRExpress = new IRExpress(irMethod, m_FinalMetaExpress);
m_IRStatements.Add(m_IRExpress);
}

m_StoreVariable = new IRStoreVariable(irMethod, m_MetaVariable);
m_IRStatements.Add(m_StoreVariable);
}
Expand Down
56 changes: 41 additions & 15 deletions source/IR/IRVariable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public IRLoadVariable(IRManager _irManager, MetaMemberVariable mmv)
m_IRDataList.Add(data);
}
}

public IRLoadVariable(IRMethod _irMethod, MetaVariable mv) : base(_irMethod)
{
if (mv.isArgument)
Expand Down Expand Up @@ -64,29 +65,54 @@ public override string ToIRString()
public class IRStoreVariable : IRBase
{
public IRData data = new IRData();
public IRStoreVariable( IRMethod _irMethod, MetaMemberVariable mmv)
{
IRExpress irexp = new IRExpress(_irMethod, mmv.express);
m_IRDataList.AddRange(irexp.IRDataList);

data.opCode = EIROpCode.StoreNotStaticField;
data.index = mmv.ownerMetaClass.GetLocalMemberVariableIndex(mmv);
m_IRDataList.Add(data);
}
public IRStoreVariable(IRMethod _irMethod, MetaVariable mv) : base(_irMethod)
{
if (mv.isArgument)
var vmv = mv as VisitMetaVariable;
var mmv = mv as MetaMemberVariable;
if (vmv != null)
{
data.opCode = EIROpCode.LoadArgument;
data.index = m_IRMethod.GetArgumentIndex(mv);
var localVariable = vmv.localMetaVariable;
if (localVariable is MetaVariable)
{
if (localVariable is VisitMetaVariable)
{
IRStoreVariable parentIRStore = new IRStoreVariable(_irMethod, localVariable as VisitMetaVariable);
m_IRDataList.AddRange(parentIRStore.IRDataList);
}
else
{
IRLoadVariable irload = new IRLoadVariable(_irMethod, localVariable as MetaVariable);
m_IRDataList.AddRange(irload.IRDataList);
}
}
data.opCode = EIROpCode.StoreNotStaticField;
data.index = vmv.GetIRMemberIndex();
m_IRDataList.Add(data);
}
else
else if (mmv != null)
{
data.opCode = EIROpCode.StoreLocal;
data.index = m_IRMethod.GetLocalVariableIndex(mv);
//IRExpress irexp = new IRExpress(_irMethod, mmv.express);
//m_IRDataList.AddRange(irexp.IRDataList);

data.opCode = EIROpCode.StoreNotStaticField;
data.index = mmv.ownerMetaClass.GetLocalMemberVariableIndex(mmv);
m_IRDataList.Add(data);
}
else
{
if (mv.isArgument)
{
data.opCode = EIROpCode.LoadArgument;
data.index = m_IRMethod.GetArgumentIndex(mv);
m_IRDataList.Add(data);
}
else
{
data.opCode = EIROpCode.StoreLocal;
data.index = m_IRMethod.GetLocalVariableIndex(mv);
m_IRDataList.Add(data);
}
}
}
public override string ToIRString()
{
Expand Down
10 changes: 8 additions & 2 deletions source/VM/InnerCLRRuntime/RuntimeMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,20 @@ public unsafe void RunInstruction( IRData iri )
{
(v.sobject as ClassObject).GetMemberVariableSValue(iri.index, ref m_ValueStack[m_ValueIndex-1]);
}
m_ValueIndex--;
}
break;
case EIROpCode.StoreNotStaticField:
{
var v = m_ValueStack[m_ValueIndex - 2];
// -2在存储的值 -1表示要存储的对象 0位表示要存储的位置
var v = m_ValueStack[m_ValueIndex - 1];
if (v.eType == EType.Class)
{
(v.sobject as ClassObject).SetMemberVariableSValue(iri.index, m_ValueStack[m_ValueIndex - 1]);
(v.sobject as ClassObject).SetMemberVariableSValue(iri.index, m_ValueStack[m_ValueIndex - 2]);
}
else
{
Console.WriteLine("Error StoreNotStaticField Path:" + iri.debugInfo.path + " Line: " + iri.debugInfo.beginLine );
}
m_ValueIndex-=2;
}
Expand Down
113 changes: 108 additions & 5 deletions source/VM/Object/ClassObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public SObject GetMemberVariable(int index)
public void SetValue(ClassObject val )
{
m_Object = val;
val.refCount++;
}
public void GetMemberVariableSValue( int index, ref SValue svalue )
{
Expand Down Expand Up @@ -174,13 +175,115 @@ public void SetMemberVariableSValue( int index, SValue svalue)
break;
case EType.Class:
{
ClassObject classObj = m_MemberVariableArray[index] as ClassObject;
if (classObj == null)
var mva = m_MemberVariableArray[index];
if (mva.eType == EType.Byte)
{
Console.WriteLine("该类型不是Int32类型!!");
return;

ByteObject byteObj = mva as ByteObject;
if (byteObj == null)
{
Console.WriteLine("该类型不是Int32类型!!");
return;
}
byteObj.SetValue(svalue.int8Value);
}
else if (mva.eType == EType.SByte)
{

SByteObject sbyteObj = mva as SByteObject;
if (sbyteObj == null)
{
Console.WriteLine("该类型不是Int32类型!!");
return;
}
sbyteObj.SetValue(svalue.sint8Value);
}
else if (mva.eType == EType.Int16)
{

Int16Object int16Obj = mva as Int16Object;
if (int16Obj == null)
{
Console.WriteLine("该类型不是Int16类型!!");
return;
}
int16Obj.SetValue(svalue.int16Value);
}
else if (mva.eType == EType.UInt16)
{

UInt32Object uint32Obj = mva as UInt32Object;
if (uint32Obj == null)
{
Console.WriteLine("该类型不是UInt32类型!!");
return;
}
uint32Obj.SetValue(svalue.uint32Value);
}
else if (mva.eType == EType.Int32)
{
Int32Object int32Obj = mva as Int32Object;
if (int32Obj == null)
{
Console.WriteLine("该类型不是Int32类型!!");
return;
}
int32Obj.SetValue(svalue.int32Value);
}
else if (mva.eType == EType.UInt32)
{

UInt32Object uint32Obj = mva as UInt32Object;
if (uint32Obj == null)
{
Console.WriteLine("该类型不是Int32类型!!");
return;
}
uint32Obj.SetValue(svalue.uint32Value);
}
else if (mva.eType == EType.Int64)
{

Int64Object int64Obj = mva as Int64Object;
if (int64Obj == null)
{
Console.WriteLine("该类型不是Int64类型!!");
return;
}
int64Obj.SetValue(svalue.int64Value);
}
else if (mva.eType == EType.UInt64)
{

UInt64Object uint64Obj = mva as UInt64Object;
if (uint64Obj == null)
{
Console.WriteLine("该类型不是Int64类型!!");
return;
}
uint64Obj.SetValue(svalue.uint64Value);
}
else if (mva.eType == EType.String)
{

StringObject stringObj = mva as StringObject;
if (stringObj == null)
{
Console.WriteLine("该类型不是stringObj类型!!");
return;
}
stringObj.SetValue(svalue.stringValue);
}
else
{
ClassObject classObj = m_MemberVariableArray[index] as ClassObject;
if (classObj == null)
{
Console.WriteLine("该类型不是Int32类型!!");
return;
}
classObj.SetValue(svalue.sobject as ClassObject);
}
classObj.SetValue(svalue.sobject as ClassObject);
}
break;
}
Expand Down
5 changes: 4 additions & 1 deletion source/VM/Object/ObjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ public class ObjectManager

public static void AddClassObject( ClassObject cl )
{

if( !classObjectDict.ContainsKey(cl.GetHashCode() ) )
{
classObjectDict.Add(cl.GetHashCode(), cl);
}
}
public static SValue CreateValueByDefineType(MetaType mdt)
{
Expand Down
1 change: 1 addition & 0 deletions source/VM/Object/SObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class SObject
protected EType m_Etype = EType.Class;
public bool m_IsNull = false;
public bool m_IsVoid = false;
public int refCount { get; set; } = 0;
protected SObject()
{

Expand Down

0 comments on commit 83fd1cc

Please sign in to comment.