public override void Compile(CompilerBase state) { var cid = Guid.NewGuid(); var beginLabel = $"{cid}-begin"; var endLabel = $"{cid}-end"; var indexName = string.IsNullOrEmpty(IndexName)?$"<{cid}-index>": IndexName; state.EnterLoop(beginLabel, endLabel); state.VariableDefine(indexName); state.InsertLC(new IntegerValue(0)); state.InsertSD(indexName); state.InsertLabel(beginLabel); state.InsertLD(indexName); mCount.Compile(state); state.InsertLT(); state.InsertJMPN(endLabel); mLoopBlock.Compile(state); state.InsertLD(indexName); state.InsertLC(new IntegerValue(1)); state.InsertADD(); state.InsertSD(indexName); state.InsertJMP(beginLabel); state.InsertLabel(endLabel); state.ExitLoop(); }
public override void Compile(CompilerBase state) { var cid = Guid.NewGuid(); var beginLabel = $"{cid}-begin"; var endLabel = $"{cid}-end"; state.EnterLoop(beginLabel, endLabel); state.InsertLabel(beginLabel); mConditional.Compile(state); state.InsertJMPN(endLabel); mLoopBlock.Compile(state); state.InsertJMP(beginLabel); state.InsertLabel(endLabel); state.ExitLoop(); }
public override void Compile(CompilerBase state) { var cid = Guid.NewGuid(); var falseLabel = $"{cid}-false"; var endLabel = $"{cid}-end"; mConditional.Compile(state); if (mFalseBlock != null) { state.InsertJMPN(falseLabel); } else { state.InsertJMPN(endLabel); } mTrueBlock.Compile(state); state.InsertJMP(endLabel); if (mFalseBlock != null) { state.InsertLabel(falseLabel); mFalseBlock.Compile(state); } state.InsertLabel(endLabel); }