Esempio n. 1
0
        public P5Code GenerateAndLoad(CompilationUnit cu)
        {
            P5Code main = null;

            foreach (var sub in cu.Subroutines)
            {
                if (sub.IsRegex)
                    mod_generator.GenerateRegex(sub);
                else
                {
                    P5Code code = mod_generator.GenerateSub(sub);

                    if (sub.IsMain)
                        main = code;
                }
            }

            return main;
        }
Esempio n. 2
0
        public static CompilationUnit ReadCompilationUnit(Runtime runtime,
                                                          string file_name)
        {
            CompilationUnit cu;

            using (var fs = File.Open(file_name, FileMode.Open))
            {
                BinaryReader reader = new BinaryReader(fs);
                files = new List<string>();

                int count = reader.ReadInt32();
                int has_data = reader.ReadInt32();
                cu = new CompilationUnit(file_name, count);

                for (int i = 0; i < count; ++i)
                    cu.Subroutines[i] = new Subroutine();

                for (int i = 0; i < count; ++i)
                    ReadSubroutine(reader, cu.Subroutines, cu.Subroutines[i]);

                if (has_data != 0)
                {
                    var name = ReadString(reader);
                    var value = ReadString(reader);
                    var glob = runtime.SymbolTable.GetGlob(runtime, name + "::DATA", true);
                    var input = new System.IO.StringReader(value);

                    glob.Handle = new P5Handle(runtime, input, null);
                }
            }
            files = null;

            return cu;
        }
Esempio n. 3
0
        public P5Code end_code_generation()
        {
            var main_int = _to_ir("generate_bytecode",
                                  new P5Scalar(new P5NetWrapper(pending)));
            var subs = main_int.DereferenceArray(parser_runtime);
            var sub_count = subs.GetCount(parser_runtime);
            var cu = new CompilationUnit(file_name, sub_count);

            for (int i = 0; i < sub_count; ++i)
                cu.Subroutines[i] = (Subroutine)NetGlue.UnwrapValue(subs.GetItem(parser_runtime, i), typeof(Subroutine));

            pending = null;

            return GenerateAndLoad(cu);
        }