+2003-05-02 Alp Toker <alp@atoker.com>
+
+ * cilc.cs: Print usage info
+
2003-05-01 Alp Toker <alp@atoker.com>
* cilc.cs: Support arguments, clean up some gcc warnings
test: cilc.exe Test.dll
rm -rf generated
mkdir generated
- mono cilc.exe Test.dll
- gcc -Wall -fpic -shared `pkg-config --cflags --libs glib-2.0 mono` -lpthread generated/*.c -o generated/libtest.so
- gcc -Wall `pkg-config --cflags --libs glib-2.0 mono` -Igenerated -Lgenerated -ltest demo.c -o generated/demo
+ mono cilc.exe Test.dll generated
+ $(MAKE) -C generated
+ gcc -Wall `pkg-config --cflags --libs glib-2.0 mono` -Igenerated -Lgenerated -ldemo demo.c -o generated/demo
cp Test.dll generated
cilc.exe: cilc.cs
$ make test
$ cd generated
$ ./demo
-$ make test
-$ cd generated
-$ ./demo
-c# static method invoked
-c# ctor invoked
-c# instance method invoked
-c# method with an unusual name invoked
--
Alp Toker <alp@atoker.com>
TODO
====
-Support return values
-
---
-
-Make cilc.exe installable and provide a man page in mono/man
-
---
+Support return values and ref/out parameters
Complete GObject support including macros and GType, taking into account
inheritance etc.
---
-
Enums, delegates, events etc.
---
-
generate autoconf/automake build files. set AC_VERSION using the assembly's
version attribute
---
-
Automatically generate inline API documentation using documentation in the
Monodoc format. The GTK+ API documentation generator can then be used to create
documentation familiar to GTK+ developers.
---
-
-<lupus> my plan is to do something like that in the future, but smarter
-<lupus> basically, have the jit create the thunk
-<lupus> so you would not have to generate code for the assemblies
-<lupus> just header files, basically
-
---
-
-<lupus> note that glib-allocated memory is not scammed by the GC, so you'll have to deal with that somehow
-<alp> something like overriding glib's malloc with something from libgc?
-<lupus> would work, but I wouldn't reccomend that
-<lupus> you may need to play with weak references
-<lupus> or storing the objects in something like a MonoGHashTable or something like that
-
---
-
-<rachel> I would give the implementor extra points if they handled passing in wrapped objects automatically (pass in a GtkWidget*, managed gets Gtk.Widget)
+Resolve GC issues using weak references or storing objects in something like a
+MonoGHashTable
+Wish: pass in a GtkWidget*, managed gets Gtk.Widget
set { title = value; }
}
- public void Method3 (string arg1string)
+ public void Echo (string arg1string)
{
Console.WriteLine ("string: " + arg1string);
}
public static CodeWriter C, H, Cindex, Hindex;
static string ns, dllname;
static string cur_class;
+ static string target_dir;
static ArrayList funcs_done;
- public static void Main(string[] args)
+ public static int Main(string[] args)
{
+ if (args.Length != 2) {
+ Console.WriteLine ("Mono CIL-to-C binding generator");
+ Console.WriteLine ("Usage: cilc [options] assembly target");
+ return 1;
+ }
+
ns = "Unnamed";
- Generate (args[0]);
+ Generate (args[0], args[1]);
+
+ return 0;
}
- static void Generate (string assembly)
+ static void Generate (string assembly, string target)
{
+ target_dir = target + Path.DirectorySeparatorChar;
+ if (!Directory.Exists (target_dir)) Directory.CreateDirectory (target_dir);
+
Assembly a = Assembly.LoadFrom (assembly);
dllname = Path.GetFileName (assembly);
AssemblyGen (a);
+
+ //create a makefile
+ CodeWriter makefile = new CodeWriter (target_dir + "Makefile");
+ makefile.Indenter = "\t";
+ makefile.WriteLine ("all: lib" + ns.ToLower () + ".so");
+ makefile.LineBreak ();
+ makefile.WriteLine ("lib" + ns.ToLower () + ".so: *.c");
+ makefile.Indent ();
+ makefile.WriteLine ("gcc -Wall -fpic -shared `pkg-config --cflags --libs glib-2.0 mono` -lpthread *.c -o lib" + ns.ToLower () + ".so");
+ makefile.Close ();
}
static void AssemblyGen (Assembly a)
Type[] types = a.GetTypes ();
ns = types[0].Namespace;
- Hindex = new CodeWriter (ns.ToLower () + ".h");
- Cindex = new CodeWriter (ns.ToLower () + ".c");
+ Hindex = new CodeWriter (target_dir + ns.ToLower () + ".h");
+ Cindex = new CodeWriter (target_dir + ns.ToLower () + ".c");
string Hindex_id = "__" + ns.ToUpper () + "_H__";
Hindex.WriteLine ("#ifndef " + Hindex_id);
//ns = t.Namespace;
string fname = ns.ToLower () + t.Name.ToLower ();
- C = new CodeWriter (fname + ".c");
- H = new CodeWriter (fname + ".h");
+ C = new CodeWriter (target_dir + fname + ".c");
+ H = new CodeWriter (target_dir + fname + ".h");
Hindex.WriteLine ("#include <" + fname + ".h" + ">");
public CodeWriter (string fname)
{
- FileStream fs = new FileStream ("generated/" + fname, FileMode.OpenOrCreate, FileAccess.Write);
+ FileStream fs = new FileStream (fname, FileMode.OpenOrCreate, FileAccess.Write);
w = new StreamWriter (fs);
}
demo_test_add_number (my_test, 2);
//run an instance method with arguments
- demo_test_set_title (my_test, "hello from c");
+ demo_test_echo (my_test, "hello from c");
+
+ //run a property set accessor
+ demo_test_set_title (my_test, "set property from c");
//TODO: return value
//g_printf ("returned string: %s\n", demo_test_get_title (my_test));