site  contact  subhomenews

Genie language

November 22, 2008 — BarryK
Now we're cooking with gas! I have been frequently browsing, investigating Python-lookalike languages. Well, it's the Python-like syntax that mostly interests me.

Today I discovered two amazing and very new languages, Delight and Genie. I'll report on Delight soon. Right now, here is info and initial impressions on Genie...

I had read briefly about Vala, a language that makes it easy to write GTK applications. It's syntax however follows the C-family (close to C#), which put me off. So, I never looked closely at it, but now I have done and it is really promising -- very efficient code generation, a true compiler, no runtime interpreter -- and just the plain old libc library. The compiler can also generate a C file.

Anyway, today I stumbled across this language called Genie, which is actually in the Vala package, and offers an alternative Python-like syntax. So, I downloaded Vala 0.5.1, compiled it, then created this "Hello world" application:

init

print "Hello world"

...that's it, just two lines.
Note: tabs are used for indentation, not spaces!
I then compiled like this:

# valac hello.gs


Hey man, the executable is 2924 bytes (under 3KB)! Apart from libc, it also links in the 'libglib' and 'libgobject' libraries, which themselves only have 'libc' as a dependency.

What about a "Hello world" GTK GUI application? Yes, here it is:

[indent=4]

/* GTK+ Genie Sample Code - compile with valac --pkg gtk+-2.0 genie-gtk.gs */
uses
Gtk

init
Gtk.init (ref args)
var test = new TestWindow ()
test.show_all ()
Gtk.main ();


class TestWindow : Window

init
title = "Test Window"
default_height = 250
default_width = 250
window_position = WindowPosition.CENTER

destroy += Gtk.main_quit

var button = new Button.with_label ("Click Me")

button.clicked += def (btn)
title = "Hello World"
btn.label = "Hello World"

add (button)


...the first line means to use 4 spaces per tab.
Comment: that sure is simple code to create a GTK app.
I compiled it like this:

# valac --pkg gtk+-2.0 hello-gtk.gs

The app has a button, click it and "Hello world" appears. The size? -- just 5896 bytes (under 6KB). It requires all the usual GTK shared libs -- no binding libs needed!!!!

Yeah, I'm impressed. Read more:
Genie home: http://live.gnome.org/Genie
Jamie McCracken blog: http://jamiemcc.livejournal.com/
Vala home: http://live.gnome.org/Vala

Want to play? I have uploaded a PET package for Puppy4 here (1MB):
http://puptrix.org/puppylinux/vala/vala-0.5.1-i486.pet

Comments

Genie and libc
Username: BarryK
I thought that probably the C libc functions are available, so tried this: [code]init print "hello world" stdout.printf("Hello again\n") # valac -C hello.gs The generated C code: #include "hello.h" #include <stdio.h> void _main (char** args, int args_length1) { g_print ("hello world\n"); fprintf (stdout, "Hello again\n"); } int main (int argc, char ** argv) { g_type_init (); _main (argv, argc); return 0; } [/code] ...yeah, works! Need to read the Vala docs to find out more about this.

More Vala info
Username: BarryK
"Online api docs: http://valadoc.org/ Newsgroup: http://news.gmane.org/gmane.comp.programming.vala

genie 4 genie
Username: lobster
"Saving in windows format with auto line feed at end of file eventually allowed me to compile the second example and it was tiny. The python syntax + the smallness and speed of C code - sound good to me. Keep us informed of any code you write :cool:

cooking with gas...
Username: cb88
"so.. that isn't an Americanism? heh... and i though it was pretty much restricted to my area in the US

Cooking with gas
Username: BarryK
"Heh heh, I thought it was an Aussie saying!


Tags: woof