Esempio n. 1
0
 public void AddParameter(FunctionParameter parameter)
 {
     foreach (FunctionParameter p in Parameters)
     {
         if (p.Name == parameter.Name)
             CompilerServices.AddError(parameter.Location, "Duplicate function parameter name");
     }
     f_parameters.Add(parameter);
 }
        public static void InitStdFunctions(L1Program program)
        {
            Dictionary<FunctionHeader, MethodInfo> stdlib = new Dictionary<FunctionHeader, MethodInfo>();
            Type runtimeContainer = typeof(L1Runtime.L1Stdlib);

            MethodInfo[] methods = runtimeContainer.GetMethods(BindingFlags.Static | BindingFlags.Public);

            foreach (MethodInfo mi in methods)
            {

                Attribute signatureAttrA = Attribute.GetCustomAttribute(mi, typeof(L1Runtime.SignatureAttribute), false);
                if (signatureAttrA != null)
                {
                    L1Runtime.SignatureAttribute signatureAttr = (L1Runtime.SignatureAttribute)signatureAttrA;
                    FunctionHeader fh = new FunctionHeader(mi.Name, GetVariableTypeByTypeId(signatureAttr.ReturnTypeId));

                    int i = 0;
                    foreach (L1Runtime.VariableTypeId typeId in signatureAttr.ParametersTypeIds)
                    {
                        FunctionParameter p =
                            new FunctionParameter("a"+i.ToString(), GetVariableTypeByTypeId(typeId));
                        System.Diagnostics.Debug.Assert(p.Type != null);
                        fh.AddParameter(p);
                        i++;
                    }

                    FunctionDefinition fdef = new FunctionDefinition();
                    fdef.Header = fh;
                    fdef.IsEmbedded = true;
                    fdef.Body = mi;
                    fdef.Location = new LexLocation();
                    fdef.Statements = new StatementList();

                    program.AddFunctionToForward(fdef);

                    stdlib.Add(fh, mi);
                }
            }

            EmitServices.DefineStandartFunctions(stdlib);
        }