Пример #1
0
 public Function(string name, Type returnType, FuncParam[] parameters, Block body, MethodBuilder info)
 {
     Name = name;
     ReturnType = returnType;
     Params = parameters;
     Body = body;
     Info = info;
     ILGenerator = info.GetILGenerator();
 }
Пример #2
0
        public FuncDeclaration(Terminal returnType, Id name, ParamDeclaration[] parameters, Block body)
        {
            ReturnType = returnType;
            Params = parameters;
            Body = body;
            Name = name;

            AddAttribute(new TypeAttr(returnType));
            AddAttribute(new IdAttr(name));
            AddAttribute(parameters);
            AddChild(body);
        }
Пример #3
0
 private void CodeBlock(Block block, List<LocalVariable> locals, List<GlobalVariable> globals, FuncParam[] parameters, ILGenerator il,
     Stack<Label> breaks, List<Function> allFuncs, LocalBuilder tmpVar)
 {
     foreach (var statement in block.Statements)
         CodeStatement(statement, locals, globals, parameters, il, breaks, allFuncs, tmpVar);
 }
Пример #4
0
        private List<LocalVariable> DeclareAllLocalVariables(Block block, ILGenerator il)
        {
            var list = new List<LocalVariable>();
            foreach (var varDeclaration in block.VarDeclarations)
            {
                var name = GetVariableName(varDeclaration);
                var type = GetVarType(varDeclaration);
                var info = il.DeclareLocal(type);

                if (varDeclaration is ArrayDeclaration)
                {
                    var array = varDeclaration as ArrayDeclaration;
                    il.Emit(OpCodes.Ldc_I4, array.Size.Value);
                    il.Emit(OpCodes.Newarr, type);
                    il.Emit(OpCodes.Stloc, info);
                }

                list.Add(new LocalVariable(name, info, type));
            }
            foreach (var s in block.Statements)
            {
                if (s is Block)
                    list.AddRange(DeclareAllLocalVariables(s as Block, il));
                else if (s is IfStatement)
                {
                    var f = s as IfStatement;
                    if (f.TrueStatement is Block)
                        list.AddRange(DeclareAllLocalVariables(f.TrueStatement as Block, il));
                    if (f.FalseStatement is Block)
                        list.AddRange(DeclareAllLocalVariables(f.FalseStatement as Block, il));
                }
                else if (s is WhileStatement)
                {
                    var w = s as WhileStatement;
                    if (w.Statement is Block)
                        list.AddRange(DeclareAllLocalVariables(w.Statement as Block, il));
                }
            }
            return list;
        }