Exemple #1
0
        /// <summary>
        /// 構文解析の行われた TopNode に対して、ILコードの発行を行う
        /// 結果は、Codes に得られる
        /// </summary>
        public NakoILCodeList WriteIL()
        {
            var writer = new NakoILWriter();

            writer.Write(this.topNode);
            codes = writer.Result;
            for (int i = 0; i < this.GlobalVar.Count(); i++)  //interpreterで使えるように関数定義が保存されている変数をアドレスに変換
            {
                NakoVariable v = this.GlobalVar.GetVar(i);
                if (v.Body is NakoNodeDefFunction)
                {
                    NakoVariable   setVar = new NakoVariable();
                    string         label  = "FUNC_" + ((NakoNodeDefFunction)v.Body).func.name;
                    NakoILCodeList cl     = writer.Result;
                    for (int j = 0; j < cl.Count; j++)
                    {
                        NakoILCode c = cl [j];
                        if (c.value is string && (string)c.value == label)
                        {
                            setVar.SetBody(j, NakoVarType.Int);
                            break;
                        }
                    }
                    this.GlobalVar.SetVar(i, setVar);
                }
            }
            codes.globalVar = this.GlobalVar;
            return(Codes);
        }
Exemple #2
0
        /// <summary>
        /// 構文解析の行われた TopNode に対して、ILコードの発行を行う
        /// 結果は、Codes に得られる
        /// </summary>
        public NakoILCodeList WriteIL()
        {
            var writer = new NakoILWriter();

            writer.Write(this.topNode);
            codes           = writer.Result;
            codes.globalVar = this.GlobalVar;
            return(Codes);
        }
Exemple #3
0
        public void TestNakoILWriter1()
        {
            NakoCompiler ns     = new NakoCompiler();
            NakoILWriter writer = new NakoILWriter(null);
            bool         r;

            // (1)
            ns.source = "1+2*3";
            ns.Tokenize();
            ns.ParseOnlyValue();
            writer.Write(ns.TopNode);
            r = writer.Result.CheckTypes(new NakoILType[] {
                NakoILType.NOP,
                NakoILType.LD_CONST_INT,
                NakoILType.LD_CONST_INT,
                NakoILType.LD_CONST_INT,
                NakoILType.MUL,
                NakoILType.ADD
            });
            Assert.IsTrue(r);
        }