Beispiel #1
0
        public static ModuleDefn CreateModule(ProgramDefn pd, ParseNode x, string sFileName)
        {
            ParseNode  nameNode = x.GetChild(0);
            ModuleDefn r        = new ModuleDefn(pd, nameNode.ToString(), sFileName);

            ParseNode bodyNode = x.GetChild(1);

            CreateModuleDefn(r, bodyNode);

            // Now store all of the types
            for (int i = 2; i < x.GetNumChildren(); ++i)
            {
                ParseNode child = x.GetChild(i);
                switch (child.Label)
                {
                case "class":
                    CreateClass(r, child);
                    break;

                case "interface":
                    CreateInterface(r, child);
                    break;

                case "enum":
                    CreateEnum(r, child);
                    break;

                default:
                    throw new Exception("Unrecognized module sub-element " + child.Label);
                }
            }

            return(r);
        }
Beispiel #2
0
 public ModuleDefn(ProgramDefn prog, string name, string sFileName)
     : base(null, name)
 {
     this.name = name;
     this.module = this;
     types.Add(name, this);
     this.fileName = sFileName;
     this.program = prog;
 }
Beispiel #3
0
 public ModuleDefn(ProgramDefn prog, string name, string sFileName)
     : base(null, name)
 {
     this.name   = name;
     this.module = this;
     types.Add(name, this);
     this.fileName = sFileName;
     this.program  = prog;
 }
Beispiel #4
0
        static public ModuleDefn ParseModule(ProgramDefn p, string s, string fileName)
        {
            ParseNode node = ParserState.Parse(HeronGrammar.Module, s);

            if (node == null)
            {
                return(null);
            }
            ModuleDefn r = CodeModelBuilder.CreateModule(p, node, fileName);

            return(r);
        }
Beispiel #5
0
        public void InitializeVM()
        {
            globalModule = new ModuleDefn(null, "_global_", "_internal_");
            RegisterPrimitives();
            program = new ProgramDefn("_program_", globalModule);

            // Clear all the frames
            frames.Clear();
            result = null;

            // Push an empty first frame and scope
            PushNewFrame(null, null, null);
            PushScope();
        }
Beispiel #6
0
        static public ModuleDefn ParseFile(ProgramDefn p, string sFileName)
        {
            ParseNode node;
            string    sFileContents = File.ReadAllText(sFileName);

            try
            {
                node = ParserState.Parse(HeronGrammar.File, sFileContents);
            }
            catch (ParsingException e)
            {
                Console.WriteLine("Parsing exception occured in file " + sFileName);
                Console.WriteLine("at character " + e.context.col + " of line " + e.context.row);
                Console.WriteLine(e.context.msg);
                Console.WriteLine(e.context.line);
                Console.WriteLine(e.context.ptr);
                throw;
            }

            if (node == null)
            {
                Console.WriteLine("Ill-formed Heron file " + sFileName);
                throw new Exception();
            }

            try
            {
                ModuleDefn r = CodeModelBuilder.CreateModule(p, node, sFileName);
                return(r);
            }
            catch (ParsingException e)
            {
                Console.WriteLine("Parsing exception occured in file " + sFileName);
                Console.WriteLine("at character " + e.context.col + " of line " + e.context.row);
                Console.WriteLine(e.context.msg);
                Console.WriteLine(e.context.line);
                Console.WriteLine(e.context.ptr);
                throw;
            }
            catch (Exception e)
            {
                Console.WriteLine("Error occured during construction of code model in file " + sFileName);
                Console.WriteLine(e.Message);
                throw;
            }
        }
Beispiel #7
0
        public void ResolveTypes(ProgramDefn prog, ModuleDefn global)
        {
            if (HasBaseClass())
            {
                string     s          = GetInheritedClassName();
                ModuleDefn baseModule = prog.GetModule(s);
                SetBaseClass(new TypeRef(baseModule));
            }

            foreach (InterfaceDefn i in GetInterfaces())
            {
                i.ResolveTypes(global, this);
            }
            foreach (ClassDefn c in GetClasses())
            {
                c.ResolveTypes(global, this);
            }

            base.ResolveTypes(global, this);
        }
Beispiel #8
0
        public void InitializeVM()
        {
            globalModule = new ModuleDefn(null, "_global_", "_internal_");
            RegisterPrimitives();
            program = new ProgramDefn("_program_", globalModule);

            // Clear all the frames
            frames.Clear();
            result = null;

            // Push an empty first frame and scope
            PushNewFrame(null, null, null);
            PushScope();
        }
Beispiel #9
0
        public void ResolveTypes(ProgramDefn prog, ModuleDefn global)
        {
            if (HasBaseClass())
            {
                string s = GetInheritedClassName();
                ModuleDefn baseModule = prog.GetModule(s);
                SetBaseClass(new TypeRef(baseModule));
            }

            foreach (InterfaceDefn i in GetInterfaces())
                i.ResolveTypes(global, this);
            foreach (ClassDefn c in GetClasses())
                c.ResolveTypes(global, this);

            base.ResolveTypes(global, this);
        }