Inheritance: System.Collections.Stack
示例#1
0
文件: typecheck.cs 项目: shugo/babel
 public override void VisitRoutine(RoutineDefinition routine)
 {
     currentRoutine = routine;
     localVariableStack = new RoutineLocalVariableStack();
     temporallyCount = 0;
     routine.StatementList.Accept(this);
     currentRoutine = null;
 }
示例#2
0
文件: codegen.cs 项目: shugo/babel
 public override void VisitRoutine(RoutineDefinition routine)
 {
     currentRoutine = routine;
     MethodBuilder methodBuilder = routine.MethodBuilder;
     ilGenerator = methodBuilder.GetILGenerator();
     returnLabel = ilGenerator.DefineLabel();
     localVariableStack = new RoutineLocalVariableStack();
     foreach (Argument arg in routine.Arguments) {
         if (arg.Mode == ArgumentMode.Out) {
             ilGenerator.Emit(OpCodes.Ldarg, arg.Index);
             Type argType = arg.RawType.GetElementType();
             EmitVoid(argType);
             EmitStind(argType);
         }
     }
     routine.StatementList.Accept(this);
     ilGenerator.MarkLabel(returnLabel);
     ilGenerator.Emit(OpCodes.Ret);
     if ((program.Target == Target.Exe ||
          program.Target == Target.WinExe) &&
         currentType.Name == "MAIN" &&
         methodBuilder.Name == "main") {
         MethodBuilder entryPoint =
             currentType.DefineMethod("Main",
                                      MethodAttributes.Public |
                                      MethodAttributes.Static,
                                      null, Type.EmptyTypes);
         ILGenerator il = entryPoint.GetILGenerator();
         il.Emit(OpCodes.Newobj, currentClass.Constructor);
         il.EmitCall(OpCodes.Call, methodBuilder, null);
         il.Emit(OpCodes.Ret);
         PEFileKinds kind;
         if (program.Target == Target.Exe)
             kind = PEFileKinds.ConsoleApplication;
         else
             kind = PEFileKinds.WindowApplication;
         program.Assembly.SetEntryPoint(entryPoint, kind);
     }
     currentRoutine = null;
 }
示例#3
0
文件: typecheck.cs 项目: shugo/babel
 public override void VisitIter(IterDefinition iter)
 {
     currentRoutine = currentIter = iter;
     localVariableStack = new IterLocalVariableStack(iter.TypeBuilder);
     localVariableStack.Push(iter.LocalVariables);
     foreach (Argument arg in iter.Arguments) {
         if (arg.Mode == ArgumentMode.Once)
             localVariableStack.AddLocal(arg.Name, arg.NodeType);
     }
     temporallyCount = 0;
     iter.StatementList.Accept(this);
     currentRoutine = currentIter = null;
 }
示例#4
0
文件: codegen.cs 项目: shugo/babel
        public override void VisitIter(IterDefinition iter)
        {
            currentRoutine = currentIter = iter;

            ilGenerator = iter.Constructor.GetILGenerator();
            ilGenerator.Emit(OpCodes.Ldarg_0);
            ilGenerator.Emit(OpCodes.Ldarg_1);
            ilGenerator.Emit(OpCodes.Stfld, iter.Self);
            int index = 2;
            foreach (Argument arg in iter.Arguments) {
                if (arg.Mode == ArgumentMode.Once) {
                    LocalVariable local =
                        (LocalVariable) iter.LocalVariables[arg.Name];
                    local.Declare(ilGenerator);
                    local.EmitStorePrefix(ilGenerator);
                    ilGenerator.Emit(OpCodes.Ldarg, index++);
                    local.EmitStore(ilGenerator);
                }
            }
            ilGenerator.Emit(OpCodes.Ldarg_0);
            ilGenerator.Emit(OpCodes.Ldc_I4_0);
            ilGenerator.Emit(OpCodes.Stfld, iter.CurrentPosition);
            ilGenerator.Emit(OpCodes.Ret);

            ilGenerator = iter.Creator.GetILGenerator();
            ilGenerator.Emit(OpCodes.Ldarg_0);
            index = 1;
            foreach (Argument arg in iter.Arguments) {
                if (arg.Mode == ArgumentMode.Once) {
                    ilGenerator.Emit(OpCodes.Ldarg, index++);
                }
            }
            ConstructorData constructor =
                (ConstructorData) iter.BoundType.Constructors[0];
            ilGenerator.Emit(OpCodes.Newobj, constructor.ConstructorInfo);
            ilGenerator.Emit(OpCodes.Ret);

            ilGenerator = iter.MethodBuilder.GetILGenerator();
            EmitVoid(iter.ReturnType.RawType);
            ilGenerator.Emit(OpCodes.Ret);

            foreach (MethodBuilder bridgeMethod in iter.BridgeMethods) {
                ilGenerator = bridgeMethod.GetILGenerator();
                ilGenerator.Emit(OpCodes.Jmp, iter.Creator);
            }

            ilGenerator = iter.MoveNext.GetILGenerator();
            returnLabel = ilGenerator.DefineLabel();
            localVariableStack = new IterLocalVariableStack(iter.TypeBuilder);
            localVariableStack.Push(iter.LocalVariables);
            foreach (Argument arg in iter.MoveNextArguments) {
                if (arg.Mode == ArgumentMode.Out) {
                    ilGenerator.Emit(OpCodes.Ldarg, arg.Index);
                    Type argType = arg.RawType.GetElementType();
                    EmitVoid(argType);
                    EmitStind(argType);
                }
            }
            Label[] resumePoints = new Label[iter.ResumePoints.Count];
            int i = 0;
            foreach (ResumePoint resumePoint in iter.ResumePoints) {
                resumePoint.Label = ilGenerator.DefineLabel();
                resumePoints[i++] = resumePoint.Label;
            }
            ilGenerator.Emit(OpCodes.Ldarg_0);
            ilGenerator.Emit(OpCodes.Ldfld, iter.CurrentPosition);
            ilGenerator.Emit(OpCodes.Switch, resumePoints);
            ilGenerator.MarkLabel(resumePoints[0]);
            iter.StatementList.Accept(this);
            ilGenerator.Emit(OpCodes.Ldc_I4_0);
            ilGenerator.MarkLabel(returnLabel);
            ilGenerator.Emit(OpCodes.Ret);

            if (iter.GetCurrent != null) {
                ilGenerator = iter.GetCurrent.GetILGenerator();
                ilGenerator.Emit(OpCodes.Ldarg_0);
                ilGenerator.Emit(OpCodes.Ldfld, iter.Current);
                ilGenerator.Emit(OpCodes.Ret);
            }

            nestedTypes.Add(iter.TypeBuilder);
            currentRoutine = currentIter = null;
        }