1 import subprocess as sub
7 return "typeof (" + typ + ")\n"
10 return "TypeBucket.Foo <TypeBucket." + one + ", TypeBucket." + two + ">.CallMe ();\n"
12 def bucketCall (filePrefix):
13 return "TypeBucket." + filePrefix + ".CallMe ();\n"
16 return "public struct " + name + " {\t\n public int inner; \t\n}\n"
20 child = sub.Popen (cmd, shell=True)
22 error = child.returncode
24 raise Exception ("Compilation error " + str(error))
26 def typeBucketInst (types, filePrefix):
27 accum = "\npublic class " + filePrefix + "{\n"
28 accum += "\tpublic static void CallMe () {\n"
31 accum += inst (t1, t2)
35 def makeGenericDef (fileName):
37 using System.Runtime.CompilerServices;
39 namespace TypeBucket {
40 public class Foo <S, P> {
41 public static void CallMe () {
49 [MethodImplAttribute (MethodImplOptions.NoInlining)]
50 public static void A () {
52 [MethodImplAttribute (MethodImplOptions.NoInlining)]
53 public static void B () {
55 [MethodImplAttribute (MethodImplOptions.NoInlining)]
56 public static void C () {
58 [MethodImplAttribute (MethodImplOptions.NoInlining)]
59 public static void D () {
61 [MethodImplAttribute (MethodImplOptions.NoInlining)]
62 public static void E () {
68 csName = fileName + ".cs"
69 with open(csName, 'w') as f:
70 f.write (fileTemplate);
71 cmd = commands ["mcs"] + " -t:library " + csName
74 def makeFile (prefix, insts, files, genericDefDll):
76 fileName = prefix + "TypeBucket"
77 csName = fileName + ".cs"
78 templatePrefix = "using TypeBucket;\n\tnamespace TypeBucket {\n"
79 with open(csName, 'w') as f:
80 f.write (templatePrefix)
82 name = "classy" + prefix + str(i)
83 f.write (classDef (name))
85 f.write(typeBucketInst (types, fileName))
88 insts.append(bucketCall (fileName))
90 cmd = commands ["mcs"] + " -t:library " + csName + " -r:" + genericDefDll
93 files.append (fileName)
100 public static void Main () {
108 def main (bin_prefix):
109 commands ["mono"] = "MONO_PATH=. " + bin_prefix + "/bin/mono "
110 commands ["mcs"] = "MONO_PATH=. " + bin_prefix + "/bin/mcs "
112 generic_def_file = "Foo"
113 makeGenericDef (generic_def_file)
116 files = [generic_def_file]
117 for prefix in ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"]:
118 makeFile (prefix, insts, files, generic_def_file + ".dll")
120 template = template_head + "\n\t".join(insts) + template_tail
122 f = open("Hello.cs", 'w')
126 cmd = commands ["mcs"] + " Hello.cs"
128 cmd = cmd + " -r:" + f + ".dll"
132 run (commands ["mono"] + "--aot=full " + "Hello.exe")
134 files.append ("mscorlib")
136 run (commands ["mono"] + "--aot=full " + f + ".dll")
138 if __name__ == "__main__":