public boolean createInstruction( ExpressRunner aCompile, InstructionSet result, Stack<ForRelBreakContinue> forStack, ExpressNode node, boolean isRoot) throws Exception { ExpressNode[] children = node.getChildren(); String macroName = children[0].getValue(); ExpressNode macroRoot = new ExpressNode( aCompile.getNodeTypeManager().findNodeType("FUNCTION_DEFINE"), "macro-" + macroName); for (ExpressNode tempNode : children[1].getChildren()) { macroRoot.addLeftChild(tempNode); } InstructionSet macroInstructionSet = aCompile.createInstructionSet(macroRoot, InstructionSet.TYPE_MARCO); result.addMacroDefine( macroName, new FunctionInstructionSet(macroName, "macro", macroInstructionSet)); return false; }
public boolean createInstruction( ExpressRunner aCompile, InstructionSet result, Stack<ForRelBreakContinue> forStack, ExpressNode node, boolean isRoot) throws Exception { boolean returnVal = false; ExpressNode[] children = node.getChildren(); int[] finishPoint = new int[children.length]; for (int i = 0; i < children.length; i++) { ExpressNode tmpNode = children[i]; boolean tmpHas = aCompile.createInstructionSetPrivate(result, forStack, tmpNode, false); returnVal = returnVal || tmpHas; finishPoint[i] = result.getCurrentPoint(); } if (node.isTypeEqualsOrChild("return")) { result.addInstruction(new InstructionReturn(children.length > 0)); } else { OperatorBase op = aCompile.getOperatorFactory().newInstance(node); result.addInstruction(new InstructionOperator(op, children.length)); if (node.isTypeEqualsOrChild("&&") && aCompile.isShortCircuit()) { result.insertInstruction( finishPoint[0] + 1, new InstructionGoToWithCondition( false, result.getCurrentPoint() - finishPoint[0] + 1, false)); } else if (node.isTypeEqualsOrChild("||") && aCompile.isShortCircuit()) { result.insertInstruction( finishPoint[0] + 1, new InstructionGoToWithCondition( true, result.getCurrentPoint() - finishPoint[0] + 1, false)); } else if (node.isTypeEqualsOrChild("nor")) { result.insertInstruction( finishPoint[0] + 1, new InstructionGoToWithNotNull(result.getCurrentPoint() - finishPoint[0] + 1, false)); } else if (node.isTypeEqualsOrChild("def") || node.isTypeEqualsOrChild("alias")) { returnVal = true; } else if (node.isTypeEqualsOrChild("exportDef")) { // 添加对外的变量声明 result.addExportDef(new ExportItem(children[1].toString(), ExportItem.TYPE_DEF, "还没有实现")); } else if (node.isTypeEqualsOrChild("exportAlias")) { result.addExportDef(new ExportItem(children[0].toString(), ExportItem.TYPE_ALIAS, "还没有实现")); } } return returnVal; }