public IEnumerable<string> SpecializeCodeForContext(Instruction i, Type[] stack) { foreach (var s in code) { var t = s.Contains("%imm") ? s.Replace("%imm", i.GetImmediateValue().ToString()) : s; // todo: more substitutions yield return t; } }
public static Type[] EvalTypesInContext(string s, Instruction i, Type[] stack) { s = s.Trim().Replace(" ", ""); if (s.Contains(',')) return s.Split(',').SelectMany( f => EvalTypesInContext(f, i, stack)).ToArray(); if (s.Contains("%imm")) s = s.Replace("%imm", i.GetImmediateValue().ToString()); if (s == "%top") return new Type[] { stack.LastOrDefault() }; if (s == "()") return new Type[] { }; if (s == "I4") return new Type[] { typeof(int) }; if (s == "Ref") return new Type[] { typeof(object) }; for (int j = 0; j < i.resolver.GetNumArgs(); j++) if (s == "%arg_type[" + j + "]") return new Type[] { i.resolver.GetArgType(j) }; for (int j = 0; j < i.resolver.GetNumLocals(); j++) if (s == "%local_type[" + j + "]") return new Type[] { i.resolver.GetLocalType(j) }; if (s == "%tok_ret") return new Type[] { i.GetMethodReturnType() }; if (s == "%tok_args") return i.GetMethodArgs(); if (s == "%tok_decltype") return new Type[] { i.GetTokenDeclaringType() }; if (s == "%tok_type") return new Type[] { i.GetTokenType() }; throw new NotImplementedException(); }