/// <summary> /// ラベルを生成する /// </summary> /// <param name="labelName"></param> /// <returns></returns> protected NakoILCode createLABEL(string labelName) { NakoILCode r = NakoILCode.newNop(); r.value = labelName; labels[r] = -1; return(r); }
/// <summary> /// 中間コードを書き出す /// </summary> /// <param name="node"></param> protected void Write_r(NakoNode node) { if (node == null) { return; } switch (node.type) { case NakoNodeType.NOP: result.Add(NakoILCode.newNop()); break; case NakoNodeType.CALC: newCalc((NakoNodeCalc)node); return; case NakoNodeType.INT: result.Add(new NakoILCode(NakoILType.LD_CONST_INT, node.value)); return; case NakoNodeType.NUMBER: result.Add(new NakoILCode(NakoILType.LD_CONST_REAL, node.value)); return; case NakoNodeType.STRING: result.Add(new NakoILCode(NakoILType.LD_CONST_STR, node.value)); return; case NakoNodeType.POP: result.Add(new NakoILCode(NakoILType.POP)); return; case NakoNodeType.PRINT: _print(node); return; case NakoNodeType.ST_VARIABLE: _setVariable((NakoNodeVariable)node); return; case NakoNodeType.LET: _let((NakoNodeLet)node); return; case NakoNodeType.LD_VARIABLE: _getVariable((NakoNodeVariable)node); return; case NakoNodeType.IF: _if((NakoNodeIf)node); return; case NakoNodeType.WHILE: _while((NakoNodeWhile)node); return; case NakoNodeType.FOR: _for((NakoNodeFor)node); return; case NakoNodeType.BREAK: addNewILCode(NakoILType.NOP, "BREAK"); return; case NakoNodeType.CONTINUE: addNewILCode(NakoILType.NOP, "CONTINUE"); return; case NakoNodeType.RETURN: addNewILCode(NakoILType.NOP, "RETURN"); return; case NakoNodeType.REPEAT_TIMES: _repeat_times((NakoNodeRepeatTimes)node); return; case NakoNodeType.FOREACH: _foreachUseIterator((NakoNodeForeach)node); //_foreach((NakoNodeForeach)node); return; case NakoNodeType.CALL_FUNCTION: _call_function((NakoNodeCallFunction)node); return; case NakoNodeType.DEF_FUNCTION: _def_function((NakoNodeDefFunction)node); return; case NakoNodeType.JUMP: _jump((NakoNodeJump)node); return; //TODO case NakoNodeType.LET_VALUE: addNewILCode(NakoILType.NOP, "LET_VALUE"); break; case NakoNodeType.TRY: _try((NakoNodeTry)node); return; case NakoNodeType.THROW: _throw((NakoNodeThrow)node); return; default: throw new NakoCompilerException("未定義のノードタイプ: " + node.type.ToString()); } // --- if (!node.hasChildren()) { return; } Write_list(node.Children); }