public VMException(FunctionDefn defn, string filename, Statement st, Exception inner)
     : base("", inner)
 {
     this.defn     = defn;
     this.st       = st;
     this.filename = filename;
 }
Exemple #2
0
        public static InterfaceDefn CreateInterface(ModuleDefn m, ParseNode x)
        {
            string        name = x.GetChild("name").ToString();
            InterfaceDefn r    = new InterfaceDefn(m, name);

            ParseNode inherits = x.GetChild("inherits");

            if (inherits != null)
            {
                foreach (ParseNode node in inherits.Children)
                {
                    r.AddBaseInterface(CreateTypeRef(node));
                }
            }

            ParseNode methods = x.GetChild("methods");

            if (methods != null)
            {
                foreach (ParseNode node in methods.Children)
                {
                    FunctionDefn f = CreateMethod(node, r);
                    r.AddMethod(f);
                }
            }

            m.AddInterface(r);
            return(r);
        }
Exemple #3
0
        public bool SupportsFunction(FunctionDefn f)
        {
            HeronValue v = GetFieldOrMethod(f.name);

            if (v == null)
            {
                return(false);
            }

            if (v is DotNetMethodValue)
            {
                var emv = v as DotNetMethodValue;
                return(f.Matches(emv.GetMethodInfo()));
            }
            else if (v is FunDefnListValue)
            {
                var fdlv = v as FunDefnListValue;
                foreach (FunctionDefn fd in fdlv.GetDefns())
                {
                    if (fd.Matches(f))
                    {
                        return(true);
                    }
                }
            }

            // Unrecognized value type.
            return(false);
        }
Exemple #4
0
 public bool HasFunction(FunctionDefn f)
 {
     foreach (FunctionDefn g in GetMethods(f.name))
     {
         if (g.Matches(f))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #5
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="f"></param>
 /// <param name="self"></param>
 public Frame(FunctionDefn f, ClassInstance self, ModuleInstance mi)
 {
     this.function  = f;
     this.self      = self;
     moduleInstance = mi;
     if (self != null)
     {
         moduleDef = self.Type.GetModule();
     }
     AddScope(new Scope());
 }
 private FunctionDefn GetFunction()
 {
     if (function == null)
     {
         function         = new FunctionDefn(null);
         function.formals = formals;
         function.body    = body;
         function.rettype = rettype;
     }
     return(function);
 }
Exemple #7
0
        public bool ImplementsMethod(FunctionDefn f)
        {
            List <FunctionDefn> matches = new List <FunctionDefn>(GetMethods(f.name));

            foreach (FunctionDefn fd in matches)
            {
                if (fd.Matches(f))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #8
0
        public static FunctionDefn CreateMethod(ParseNode x, HeronType parent)
        {
            ModuleDefn   module = parent.GetModule();
            FunctionDefn r      = new FunctionDefn(parent);

            r.annotations = CreateAnnotations(x);
            r.node        = x;
            ParseNode fundecl = x.GetChild("fundecl");

            r.name    = fundecl.GetChild("name").ToString();
            r.formals = CreateFormalArgs(fundecl.GetChild("arglist"));
            ParseNode rt = x.GetChild("typedecl");

            r.rettype = CreateTypeRef(rt);
            ParseNode codeblock = x.GetChild("codeblock");

            r.body = CreateCodeBlock(codeblock);
            return(r);
        }
Exemple #9
0
        public static ClassDefn CreateClass(ModuleDefn m, ParseNode x)
        {
            string    name = x.GetChild("name").ToString();
            ClassDefn r    = new ClassDefn(m, name);

            ParseNode inherits = x.GetChild("inherits");

            if (inherits != null)
            {
                if (inherits.GetNumChildren() != 1)
                {
                    throw new Exception("A class can only inherit from exactly one other class");
                }
                ParseNode type = inherits.GetChild(0);
                r.SetBaseClass(CreateTypeRef(type));
            }

            ParseNode implements = x.GetChild("implements");

            if (implements != null)
            {
                foreach (ParseNode node in implements.Children)
                {
                    r.AddImplementedInterface(CreateTypeRef(node));
                }
            }

            ParseNode methods = x.GetChild("methods");

            if (methods != null)
            {
                foreach (ParseNode node in methods.Children)
                {
                    FunctionDefn f = CreateMethod(node, r);
                    r.AddMethod(f);
                }
            }

            ProcessFields(x, r);

            m.AddClass(r);
            return(r);
        }
Exemple #10
0
        private static void CreateModuleDefn(ModuleDefn m, ParseNode x)
        {
            ParseNode imports = x.GetChild("imports");

            if (imports != null)
            {
                foreach (ParseNode import in imports.Children)
                {
                    string         modAlias   = import.GetChild(0).ToString();
                    string         modDefName = import.GetChild(1).ToString().RemoveInternalWSpace();
                    ExpressionList args       = CreateCompoundExpr(import.GetChild(2));
                    m.AddImport(modAlias, modDefName, args);
                }
            }

            ParseNode inherits = x.GetChild("inherits");

            if (inherits != null)
            {
                if (inherits.GetNumChildren() != 1)
                {
                    throw new Exception("A module can only inherit from exactly one other module");
                }
                m.SetBaseClass(CreateTypeRef(inherits.GetChild(0)));
            }

            ParseNode methods = x.GetChild("methods");

            if (methods != null)
            {
                foreach (ParseNode node in methods.Children)
                {
                    FunctionDefn f = CreateMethod(node, m);
                    m.AddMethod(f);
                }
            }

            ProcessFields(x, m);
        }
        public bool Matches(FunctionDefn f)
        {
            if (f.name != name)
            {
                return(false);
            }
            int n = formals.Count;

            if (f.formals.Count != n)
            {
                return(false);
            }
            for (int i = 0; i < n; ++i)
            {
                FormalArg arg1 = formals[i];
                FormalArg arg2 = f.formals[i];
                if (arg1.type != arg2.type)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #12
0
 public ClassDefn(ModuleDefn m, string name)
     : base(m, typeof(ClassDefn), name)
 {
     autoCtor = new FunctionDefn(this, "_Constructor_");
 }
Exemple #13
0
 public void AddMethod(FunctionDefn x)
 {
     methods.Add(x);
 }
Exemple #14
0
 /// <summary>
 /// Creates a new frame, and returns a frame manager, which will release the frame
 /// on Dispose.
 /// </summary>
 /// <param name="fun"></param>
 /// <param name="classInstance"></param>
 /// <returns></returns>
 public DisposableFrame CreateFrame(FunctionDefn fun, ClassInstance classInstance, ModuleInstance mi)
 {
     return(new DisposableFrame(this, fun, classInstance, mi));
 }
Exemple #15
0
 /// <summary>
 /// Called when a new function execution starts.
 /// </summary>
 /// <param name="f"></param>
 /// <param name="self"></param>
 public void PushNewFrame(FunctionDefn f, ClassInstance self, ModuleInstance mi)
 {
     frames.Add(new Frame(f, self, mi));
 }
Exemple #16
0
 public DisposableFrame(VM vm, FunctionDefn def, ClassInstance ci, ModuleInstance mi)
 {
     this.vm = vm;
     vm.PushNewFrame(def, ci, mi);
 }
 public FunctionValue(HeronValue self, FunctionDefn f)
 {
     this.self = self;
     fun       = f;
 }