Exemplo n.º 1
0
 //For use with already-defined functions, like Console.WriteLine. Allows you to alias them for use inside the language.
 public Function(String funcName, MethodInfo mi)
 {
     fns.Add(funcName, this);
     this.mi = mi;
     ec = new ExecutionContext(null);
     var parInfos = mi.GetParameters();
     Parameter[] pars = new Parameter[parInfos.Length];
     for (int i = 0; i < pars.Length; i++)
         pars[i] = new Parameter(parInfos[i].ParameterType, parInfos[i].Name);
     ec.SetParameters(pars);
 }
Exemplo n.º 2
0
 public Function(Identifier returnType, Identifier name, Sequence<Parameter> pars, Sequence<Statement> stmts)
 {
     Type[] tar = Parameter.ConvertSequenceToTypeArray(pars);
     var mb = CodeGenerator.CreateFunction(name.Value, TypeChecker.ConvertStringToType(returnType.Value), tar);
     mi = mb;
     this.stmts = stmts;
     if (fns.ContainsKey(name.Value))
     {
         throw new Exception("Function redeclared. Note: overloaded functions are not supported at this time.");
     }
     fns.Add(name.Value, this);
     int count = 1; //parameters start at index 1 - 0 is the return. not sure on GetParameters() though - more testing is needed, but i don't think it includes the returntype as there is a separate way to get that
     foreach (Parameter p in pars)
     {
         mb.DefineParameter(count++, ParameterAttributes.None, p.Name);
     }
     ec = new ExecutionContext(null);
     ec.SetParameters(pars.ToArray());
 }