Example #1
0
            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();
            }
Example #2
0
            public override void Compile(CompilerBase state)
            {
                var cid = Guid.NewGuid();
                var end = $"{cid}-function-end";

                state.InsertJMP(end);
                state.FunctionDefine(Name, Parameters.Length, 0);
                state.EnterFunction(Name);
                state.InsertLabel($"<{Name}>");
                var iadstk = state.InsertALLOCDSTK();

                foreach (var p in Parameters)
                {
                    state.VariableDefine(p);
                }
                foreach (var p in Parameters)
                {
                    state.InsertSD(p);
                }

                mBlockStatement.Compile(state);
                state.InsertLC(new BooleanValue(false));
                state.InsertRET();
                iadstk.Size = state.CurrentScopeVariableCount;
                state.ExitFunction();
                state.InsertLabel(end);
            }
Example #3
0
 public override void Compile(CompilerBase state)
 {
     Row.Compile(state);
     Col.Compile(state);
     state.InsertLC(Value);
     state.InsertARRAYMAKE();
 }
Example #4
0
 public override void Compile(CompilerBase state)
 {
     if (mExpression != null)
     {
         mExpression.Compile(state);
     }
     else
     {
         state.InsertLC(new BooleanValue(false));
     }
     state.InsertRET();
 }
Example #5
0
            public void Compile(CompilerBase state)
            {
                state.EnterFunction("<Program>");
                var iadstk = state.InsertALLOCDSTK();

                foreach (var s in mStatements)
                {
                    s.Compile(state);
                }
                state.InsertLC(new BooleanValue(false));
                state.InsertRET();
                iadstk.Size = state.CurrentScopeVariableCount;
                state.ExitFunction();
            }
Example #6
0
 public override void Compile(CompilerBase state)
 {
     state.InsertLC(Value);
 }