Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Auto-generate all enums in Gtk/Gdk #62

Merged
merged 40 commits into from
Feb 15, 2014
Merged

Conversation

bfredl
Copy link
Contributor

@bfredl bfredl commented Feb 6, 2014

This enables auto-generation of the complete set of consts and enums in Gtk/Gdk (using gobject-introspection). The support code is in https://github.com/bfredl/GI.jl . However there are a few outstanding issues:

Gobject-introspection does work on windows (used for instance by pygtk as of gtk3) but the introspection data is not currently included in the WinRPM packages. I think this comes down to enable some configuration flags in the WinRPM build scripts; I will look into it later. As with cindex it is only a dependency for regenerating the cache, not for using the package.
As of #24 "_MASK" are stripped of the Gdk mask enum values. If we want to keep this convention this could be done systematically also in the geneated enums, since libgirepo contains info which enums are in fact masks. Right now the enums are in a submodule but when this is resolved they could all be put in the main Gtk namespace.
This PR replaces the EnumName.get symbol lookup functions with getfield, which probably is somewhat slower (cannot be constant folded I guess). If this is a problem EnumName.get could be generated as well (for all enums or a relevant subset of the enums).

Would people consider this useful? If so I will try fix the remaining issues, as needed.

tknopp added 30 commits January 24, 2014 08:24
allows to use GtkSourceBuffer

Added pagenumber function for GtkNotebook
And fix path_at_pos on 64 bit systems
and replace GtkTextBuffer by GtkTextBufferI in text.jl (GtkSourceBuffer
inherits from GtkTextBufferI)
@vtjnash
Copy link
Contributor

vtjnash commented Feb 7, 2014

Yes. I'm starting to realize this may be the way to go for a lot of stuff: cache auto-gen info from GI and eval it at startup

Let's keep them in Gtk.Constants, but add an export statement for all of the constants. (and a corresponding using .Constants in Gtk)

Any idea how long it takes to parse this? I've measured that GAccessors took 0.5 sec to parse, or 0.01 to read from the fast-cache. This can probably be appended to the same cache file.

I think we should either drop the usage of lowercase, or generate both symbols in the module, that should simplify the get_enum function (which may actually be faster than EnumName.get since it doesn't compile as many functions, and inference/codegen knows how to emit getfield efficiently. All it needs is a typeassert::Enum.

I still think stripping _MASK is the way to go, for keeping code concise.

@tknopp
Copy link
Collaborator

tknopp commented Feb 7, 2014

@bfredl Autogenerating enums seems great! But I am not totally sure: At which moment is GI required? Only once on your side and not on the Gtk.jl users side, rigtht?

@bfredl
Copy link
Contributor Author

bfredl commented Feb 7, 2014

@vtjnash a quick test gives 0.38 for the entire eval( ... include(constcache) ) stmt, of which 0.23s is only include(constache). I also think all generated code should be appended to the same binary cache.

Well, the introspection data actually contains the enum fields as lowercase, so I think a viable alternative is to only have the fields as lowercase. It's obvious imho that GtkJustification.left is an enum value. Having both is of course very convenient, but I think code will be more consistent and easier to read if one choice is enforced.
getfield being effective is good news, then auto-generated methods (the next step) could allow symbol values for all enum parameters.

@tknopp Correct, all cached code from GI.jl should not runtime-depend on the introspection library. It works the same as the cindex accessors in this respect.

tknopp and others added 2 commits February 8, 2014 09:45
List/Tree View Improvement / GtkToolbar / GtkScrolledWindow
@bfredl
Copy link
Contributor Author

bfredl commented Feb 8, 2014

Ok, I moved most of the generation code to Gtk.jl, so it's easier to special case stuff (like currently exclude GDK_KEY_* as these are almost more than the size of all other enums combined) and it only depends on the layer of GI.jl that I can let be api-stable right now.

lowercase generates quite some keyword conflicts (like end), so I have kept it uppercase-only for now.

Firstly, this interfaces allows us to pass around raw GList pointers without bothering to first box them (which should be nice for performance). Secondly, it creates a real GList type which can be instantiated to create (and gc-root) a real GList (which should be nice for usability enhancements, since we can now code the rest of the GList setter API against this)
end
constcache = joinpath(cachedir,"consts")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there no dependence on gtk_version?

@bfredl
Copy link
Contributor Author

bfredl commented Feb 11, 2014

Well, I thought constants were backwards compatible (as Gtk.jl has done well sofar with only one set of constants). It turns to be a few enums in gtk2 removed in gtk3, so I made it dependent on version. Seems like libgirepository cannot load both gtk2 and gtk3 in the same process, so one has to run the regeneration script twice.

@vtjnash vtjnash merged commit 4ae95b4 into JuliaGraphics:master Feb 15, 2014
@vtjnash
Copy link
Contributor

vtjnash commented Feb 15, 2014

I've merged this. I'm not sure which approach (GI or Clang) is necessarily better so I'll keep both at present. It's good for verification that they generate nearly the same thing.

Note: I removed get_enum(E, s), since it was functionally identical to E.(s)

@bfredl
Copy link
Contributor Author

bfredl commented Feb 15, 2014

Ah, I didn't know about the x.(y) syntax. That's very practical to know, thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants