Search code examples
compilationvalagenie

Is there any way to compile between Vala and Genie?


The relationship between Vala and Genie are much like that between js and CoffeeScript. js and cs can compile from each other with $ coffee -bc and $ js2coffee. How about Genie and Vala here?


Solution

  • You could use valac --dump-tree to convert from Genie to Vala. Converting from Vala to Genie is a bit more complicated since the Vala.CodeWriter class in libvala only outputs Vala, not Genie. It would probably be possible to create something which outputs Genie by subclassing Vala.CodeVisitor (just like Vala.CodeWriter does), but nobody has done so yet.

    That said, I have absolutely no idea why you would want to. You can freely mix Genie and Vala files within the same valac invocation.

    Modifying an example from http://live.gnome.org/Genie, put this in mix-genie.gs:

    [indent=4]
    
    class Foo : Object
        prop a : int
    
        init     
            print "foo is intitialized"
    
        final
            print "foo is being destroyed"
    
        /* only class properties may be set in creation methods */    
        construct (b : int)
            a = b
    
        /* only class properties may be set in creation methods */        
        construct with_bar (bar : int)
            a = bar
    

    And this in mix-vala.vala:

    private static int main (string[] args) {
      var foobar = new Foo (10);
      var foobar2 = new Foo.with_bar (10);
    
      return 0;
    }
    

    And compile with something like

    valac -o mix mix-genie.gs mix-vala.vala