81 lines
2.6 KiB
C#
81 lines
2.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace TLang.VM
|
|
{
|
|
public class TClassInstance : TObject
|
|
{
|
|
TVMFile file;
|
|
Class classEntry;
|
|
TLangEnvironment oGenv;
|
|
public TClassInstance(TVMFile file,Class classEntry,TLangEnvironment env)
|
|
{
|
|
this.file = file;
|
|
this.classEntry = classEntry;
|
|
this.oGenv = env;
|
|
}
|
|
public List<string> InheritenceTree {get;}=new List<string>();
|
|
public Dictionary<string,ClassMethod> Methods {get;} = new Dictionary<string, ClassMethod>();
|
|
|
|
|
|
|
|
public void Init(params TObject[] args)
|
|
{
|
|
Environment = new ClassEnvironment(oGenv,this);
|
|
|
|
foreach(var item in classEntry.ClassEntries)
|
|
{
|
|
|
|
}
|
|
var cE = classEntry;
|
|
var aC =oGenv.GetRootEnvironment().AvailableClasses;
|
|
//we need to check inheritence
|
|
while(cE.InheritsFrom != "object")
|
|
{
|
|
InheritenceTree.Add(cE.InheritsFrom);
|
|
if(aC.ContainsKey(cE.InheritsFrom))
|
|
{
|
|
var aC2 = aC[cE.InheritsFrom];
|
|
cE = aC2.ToClass(cE.InheritsFrom);
|
|
foreach(var item in cE.ClassEntries)
|
|
{
|
|
if(!Methods.ContainsKey(item.Name) && item.Method)
|
|
{
|
|
if(item.Abstract) throw new Exception("Method is abstract");
|
|
ClassMethod meth=new ClassMethod();
|
|
meth.File = aC2.File;
|
|
meth.Chunk = aC2.File.Chunks[item.ChunkId];
|
|
meth.Private = item.Private;
|
|
meth.Protected = item.Protected;
|
|
meth.Public = item.Public;
|
|
Methods.Add(item.Name,meth);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public TLangEnvironment Environment {get; private set;}
|
|
public void SetField(bool inside,string className,string key,TObject obj)
|
|
{
|
|
|
|
}
|
|
public TObject GetField(string className,string key)
|
|
{
|
|
|
|
return new TUndefined();
|
|
}
|
|
public TObject CallMethod(string className,string key,params TObject[] args)
|
|
{
|
|
if(Methods.ContainsKey(key))
|
|
{
|
|
var method=Methods[key];
|
|
if(method.Private && className != classEntry.Name) return new TUndefined();
|
|
|
|
}
|
|
|
|
return new TUndefined();
|
|
}
|
|
|
|
|
|
}
|
|
} |