Exemplo n.º 1
0
        private static IEnumerable<Error> ResolveArgs(Invoke inv, Procedure proc)
        {
            var errors = new List<Error>();
            var p = new List<Variable>();
            if (proc != null)
                p = proc.GetSpecifiedChildren<Variable>().Where(x => x.VarSemantics == VarType.Parameter).ToList();
            var index = 0;
            foreach (var arg in inv.Args)
            {
                IType type;
                errors.AddRange(IdentifierResolver.ResloveIdentifierType(inv.GetParent(), arg, out type));
                if (proc != null)
                {
                    if (index >= p.Count)
                        errors.Add(new Error(inv.GetSourceIdentifier(), inv.Name,
                                             string.Format(ErrorMessages.InvalidSignature, inv.Name.Text)));
                    else
                    {
                        if (type.ToString() != p[index].Type.ToString())
                            errors.Add(new Error(inv.GetSourceIdentifier(), inv.Name,
                                                 string.Format(ErrorMessages.InvalidSignature, inv.Name.Text)));
                    }
                }
                index++;
            }

            return errors;
        }
Exemplo n.º 2
0
 private static void Emit(Procedure proc)
 {
     Source += "public static void " + proc.Name.Text + "(";
     EmitLocalParam(proc);
     Source += ")\n{\n";
     EmitLocalVariable(proc);
     EmitBody(proc.GetSpecifiedChildren<Body>().First());
     Source += "}\n";
 }
Exemplo n.º 3
0
        private static void EmitProcedure(TypeBuilder tb, Procedure proc)
        {
            LocalSym = new Dictionary<Variable, LocalBuilder>();

            var actual = proc.GetSpecifiedChildren<Variable>()
                             .Where(x => x.VarSemantics == VarType.Parameter)
                             .ToArray();
            var methodBuilder = tb.DefineMethod(proc.Name.Text, MethodAttributes.Public, null,
                                                actual.Select(x => GetType(x.Type)).ToArray());
            for (var i = 0; i < actual.Length; ++i)
                methodBuilder.DefineParameter(i + 1, ParameterAttributes.In, actual[i].Name.Text);

            var il = methodBuilder.GetILGenerator();

            foreach (var variable in proc.GetSpecifiedChildren<Variable>()
                             .Where(x => x.VarSemantics == VarType.Variable)
                             .ToArray())
            {
                var a = il.DeclareLocal(GetType(variable.Type));
                LocalSym.Add(variable, a);
            }

            EmitBody(methodBuilder, proc.GetSpecifiedChildren<Body>().First());

            il.Emit(OpCodes.Ret);
        }