static void Main(string[] args) { var sw = new Stopwatch(); sw.Start(); var parser = new Parser(); var rootAST = parser.ParseProgramAsync("src/hello.ryu").Result; var symTableManager = new SymbolTableManager(rootAST); symTableManager.GenerateSymbolTables(); var typeInferer = new TypeInferer(symTableManager); var typeChecker = new TypeChecker(symTableManager); var codeGen = new CodeGenVisitor(symTableManager); typeInferer.InferTypes(); typeChecker.TypeCheck(); codeGen.CodeGen(); sw.Stop(); Console.WriteLine(sw.ElapsedMilliseconds); Console.ReadKey(); }
internal static bool IsApplicableExtensionMethod(Type instanceType, Type extensionMethodThisType) { if (extensionMethodThisType.ContainsGenericParameters) { Dictionary <Type, Type> binding = new Dictionary <Type, Type>(); if (extensionMethodThisType.IsArray) { if (instanceType.IsArray) { extensionMethodThisType = extensionMethodThisType.GetElementType(); instanceType = instanceType.GetElementType(); var inferredType = TypeInferer.GetInferedType(extensionMethodThisType, extensionMethodThisType, instanceType, instanceType, binding); return(inferredType != null); } return(false); } Type[] genArgs = extensionMethodThisType.IsGenericParameter ? new[] { extensionMethodThisType } : extensionMethodThisType.GetGenericArguments(); Type[] inferredTypes = new Type[genArgs.Length]; for (int i = 0; i < genArgs.Length; i++) { if ((inferredTypes[i] = TypeInferer.GetInferedType(genArgs[i], extensionMethodThisType, instanceType, instanceType, binding)) == null) { inferredTypes = null; break; } } if (inferredTypes != null) { if (extensionMethodThisType.IsGenericParameter) { extensionMethodThisType = inferredTypes[0]; } else if (inferredTypes.Length > 0) { extensionMethodThisType = extensionMethodThisType.GetGenericTypeDefinition().MakeGenericType(inferredTypes); } } } return(extensionMethodThisType.IsAssignableFrom(instanceType)); }
public void Analyze() { var inferer = new TypeInferer(returnType); var sorted_nodes = cfg.ForwardOrder; // Propagate types over the CFG until a fixedpoint is reached // (i.e. when types do not change anymore) bool changed; do { var result = GetTypeInferenceResult(); for (var i = 0; i < sorted_nodes.Length; ++i) { var node = sorted_nodes[i]; inferer.Visit(node); } changed = !SameTypes(result); fixptCount++; }while (changed); }
static void run(IEnumerable<String> filePaths) { var p = new Parser(); var modules = new Dictionary<String, IReadOnlyList<IClassItem>>(); foreach (var path in filePaths.Reverse()) { Contract.Assume(path != null); var txt = File.ReadAllText(path); var items = p.Parse(txt, ValidationList); modules.Add(Path.GetFileNameWithoutExtension(path), items.Cast<IClassItem>().ToList()); } var preludeTxt = File.ReadAllText(libPath + "prelude.ef"); var preludeTxtItems = p.Parse(preludeTxt, ValidationList); var rw = new Rewriter(); var prog = rw.MakeProgram(preludeTxtItems.Cast<Declr>().ToList(), modules); var n = new Namer(); n.Name(prog, ValidationList); var ti = new TypeInferer(); ti.VisitDeclr(prog.GlobalModule); var i = new Interpreter(); var res = i.Run(prog, ValidationList); Console.Write("Result: "); Console.WriteLine(res.Accept(DefaultPrinter)); }
void GenerateCode(JSFunctionCode funcCode, ILGen.BaseILGenerator ilGen, bool enableSpeculation) { var cgInfo = new CodeGenerationInfo(this, funcCode, ilGen); ///This is where we are giong to make different decistions aboud different Phases and passes if (JSRuntime.Instance.Configuration.EnableLightCompiler) { CodeGeneratorLight.Execute(cgInfo); } else { if (JSRuntime.Instance.Configuration.EnableFunctionInlining) { FunctionInliner.Execute(cgInfo); } if (EnableTypeInference) { TypeInferer.Execute(cgInfo); } if (enableSpeculation && !IsBlackListed) { CodeGen.CodeGeneratorWithInlineCache.Execute(this); try { CodeGeneratorWithSpecialization.Execute(cgInfo); } catch (JSDeoptFailedException e) { IsBlackListed = true; ilGen = CreateStub(funcCode, false); cgInfo = new CodeGenerationInfo(this, funcCode, ilGen); funcCode.Profiler = null; if (EnableTypeInference) { TypeInferer.Execute(cgInfo); } CodeGenerator.Execute(cgInfo); } } else { if (this.EnableProfiling && !IsBlackListed) { CodeGeneratorWithProfiling.Execute(cgInfo); } else { CodeGenerator.Execute(cgInfo); } } var method = ilGen.EndJittedMethod(this, funcCode); if (enableSpeculation && !IsBlackListed) { funcCode.SpecializedMethod = method; } else { funcCode.GenericMethod = method; } } }