Page 1 of 26

Vala and Genie programming

Posted: Thu 12 Mar 2009, 12:41
by Lobster
In my desperate and futile attempts to program
I have been exploring the vala/genie programming language
used in Woof

http://live.gnome.org/Genie

I have been able to compile some of Barrys examples
http://puppylinux.com/genie/

now this:

Code: Select all

init
	a:array of string = {"abc", "def", "xyz"}
	for s in a
		print(s)
gives me
# valac v5.gs
v5.c: In function '_main':
v5.c:34: error: stray '\' in program
v5.c:34:40: warning: missing terminating " character
v5.c:34: error: missing terminating " character
v5.c:34: error: 'n' undeclared (first use in this function)
v5.c:34: error: (Each undeclared identifier is reported only once
v5.c:34: error: for each function it appears in.)
v5.c:35: error: expected ')' before '_tmp2'
v5.c:37: error: expected ')' before '}' token
v5.c:37: error: expected ';' before '}' token
error: cc exited with status 256
Compilation failed: 1 error(s), 0 warning(s)
#
which is more errors then I can cope with . . . :?
I am pretty sure it is something to do with the tab
ending the program (python does this too)
but can not solve it.

HELP!

Posted: Thu 12 Mar 2009, 15:28
by MU
be sure to use tabs, not spaces in the beginning of the lines.

I just copied your example via copy&paste in Opera to leafpad, and it compiles fine here (newyearspup02 with devx).


Mark

Posted: Thu 12 Mar 2009, 15:31
by MU
you also may compile:
valac -C v5.gs

This just creates v5.c and v5.h.
Pleae copy&paste them here.

Maybe the difference to mine show, what goes wrong for you.

Mark

Posted: Thu 12 Mar 2009, 15:34
by Lobster
:shock:

tried in leafpad
will have another go
- it is the space thing - yes
I am using 4.2 rc2
and a 64 bit processor
(and I am stupid)

v5.c

Code: Select all

#include "v5.h"




static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);



void _main (char** args, int args_length1) {
	char** _tmp1;
	gint a_size;
	gint a_length1;
	char** _tmp0;
	char** a;
	_tmp1 = NULL;
	_tmp0 = NULL;
	a = (_tmp1 = (_tmp0 = g_new0 (char*, 3 + 1), _tmp0[0] = g_strdup ("abc"), _tmp0[1] = g_strdup ("def"), _tmp0[2] = g_strdup ("xyz"), _tmp0), a_length1 = 3, a_size = a_length1, _tmp1);
	{
		char** s_collection;
		int s_collection_length1;
		int s_it;
		s_collection = a;
		s_collection_length1 = a_length1;
		for (s_it = 0; s_it < a_length1; s_it = s_it + 1) {
			const char* _tmp3;
			char* s;
			_tmp3 = NULL;
			s = (_tmp3 = s_collection[s_it], (_tmp3 == NULL) ? NULL : g_strdup (_tmp3));
			{
				char* _tmp2;
				_tmp2 = NULL;
				g_print (_tmp2 = g_strconcat (s, \n", NULL));
				_tmp2 = (g_free (_tmp2), NULL);
				s = (g_free (s), NULL);
			}
		}
	}
	a = (_vala_array_free (a, a_length1, (GDestroyNotify) g_free), NULL);
}


int main (int argc, char ** argv) {
	g_type_init ();
	_main (argv, argc);
	return 0;
}


static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
	g_free (array);
}
and v5.h

Code: Select all

#ifndef __V5_H__
#define __V5_H__

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>

G_BEGIN_DECLS



void _main (char** args, int args_length1);


G_END_DECLS

#endif

Thanks Mark :)

Posted: Fri 13 Mar 2009, 09:53
by MUguest
Lob,

I get the same error trying to compile it in WinowsXP, using 0.5.7.

At home in Puppy I had used 0.5.1:
http://distro.ibiblio.org/pub/linux/dis ... 1-i486.pet

The problem is the generated C code, line 34:

Code: Select all

				g_print (_tmp2 = g_strconcat (s, \n", NULL));
should be:

Code: Select all

				g_print (_tmp2 = g_strconcat (s, "\n", NULL));
So there missed a quotation mark.

Maybe with 0.5.1 you will have success.
Mark

Posted: Fri 13 Mar 2009, 10:12
by MUguest
yes, with 0.5.1 the example compiles fine also in WinXP.
In 0.5.6 it does not.
So this is a bug in newer versions, or the syntax for the "for" loop changed.
Mark

Posted: Fri 13 Mar 2009, 10:46
by Lobster
yes, with 0.5.1 the example compiles

Yep works for me too in 0.5.1
Thanks Mark :)
Now to program my own masterpiece . . .
:oops:

Posted: Fri 13 Mar 2009, 11:08
by Lobster
:? stuck again

been looking for a list of reserved words
in particular functions . . .

Am trying to find and use a rnd or random function.
Any clues?

Posted: Fri 13 Mar 2009, 13:29
by MUguest
You can use the random method from GLib.
http://valadoc.org/?pkg=glib-2.0&element=GLib.Random


Example:

Code: Select all

init

	// return a random value from 1 to 9
	a:int
	a = GLib.Random.int_range(1,10)
	print("%d" , a)
	


------------------------------------------
references

http://valadoc.org/?

http://www.vala-project.org/doc/vala/
http://live.gnome.org/Vala
http://live.gnome.org/Vala/Tutorial
http://library.gnome.org/devel/glib/

Mark

Posted: Sat 14 Mar 2009, 09:18
by MU
I attach a pet made from the Archlinux package of the vala-IDE.
http://www.valaide.org/doku.php

It requires Gtksourceview:
http://dotpups.de/puppy3/dotpups/Librar ... 2-i486.pet

I did not try, if it works in Puppy.
I tested it in NYP 02rc7, that has updated Gtk libraries (based on Ultrapup).

The homepage says, it requires vala 0.5.7, but it seems to work fine with 0.5.1.

Mark

Posted: Sat 14 Mar 2009, 09:49
by Lobster
I could not get the random code to work - will try again later
Hey thanks for the IDE :) that looks useful . . .
only . . .
this is what I got in Deep Thought 4.20 rc3

Code: Select all

# ./valide
./valide: error while loading shared libraries: libgio-2.0.so.0: cannot open shared object file: No such file or directory
# 

Posted: Sat 14 Mar 2009, 21:39
by muggins

Posted: Sun 15 Mar 2009, 03:54
by Lobster
thanks Muggins :)
now in rc3 of 4.2
added those pets and now getting . . .

Code: Select all

# ./valide
./valide: symbol lookup error: /usr/lib/libvalide-0.0.so: undefined symbol: g_dgettext
# 

Posted: Sun 15 Mar 2009, 17:26
by Lobster
Hey Mark,

Thanks for the random prog - got that working ok :)

I am using it to train an infinite number of monkeys on virtual typewriters to write this (to start with)

Code: Select all

while myLine != "in the"	
Soon (a few billion years) they will type out the Bible and the Complete Works of Shakespeare

. . . what am I missing?

Code: Select all

// Infinite Monkey Theorem, Lobster and Shadow, March 2009 
init
	myChars:array of string = {" ", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
	myLine:string = ""
	myCount:int = 6
	while myLine != "in the"
		for i:int = 1 to myCount
			myLine = myLine.concat(myChars[GLib.Random.int_range(0,myChars.length)])
		print(myLine)
rather than using a string array - is there not some sort of more efficient string pointer?

Posted: Sun 15 Mar 2009, 22:05
by MU
Lobster, sorry no answer, but a request:
please do not edit your messages to add new content.
I just saw your monkey example by accident, when I looked up something in this thread.
That also had happened before, so that I replied very late.

The best is to add a new message, so that I can see it in my "View posts since last visit".

Mark

Posted: Mon 16 Mar 2009, 08:36
by Lobster
but a request
:) Will try and bear that in mind.
I quite often miss posts, lose threads (and my mind on special occasions) etc.

Shadow my programming buddy was very impressed with Genie
(as usual he had mastered and gone beyond what I could do in aprox 10 minutes)
I too like it and want to get the IDE working or linking it to the Glade system in the devxx

If we adopt what is in effect 3 languages (the Python like Genie, the C++ like Vala and of course C) all interlinked with a potential IDE and mashable
Add the odd bit of Bash script, we really have something with vast potential.
The generation of C code in particular makes us more processor independent as the ARM chip is likely to increase in importance as phone and netbooks begin to merge . . .
(am I ranting again)

Anyway what I would like to suggest is (this is up to Barry too)
we create the future tutorials here
http://puppylinux.org/ (oh boy that is down - but the wiki section)
or on the old wiki

or even a page here:
http://tmxxine.com/wik/wikka.php?wakka=LinuxTmxxine10

Posted: Mon 16 Mar 2009, 10:42
by MUguest
Here is a new PET of the Valaide.
It includes in an own subfolder /usr/local/glib2.18/ some newer systemlibraries.

They do NOT replace Puppys files, so there is no danger to corrupt something.
These files are only needed for the IDE, not for Vala itself.

http://dotpups.de/puppy4/dotpups/Programming/Vala/

Problem description:
The IDE depends on libgio.so.
But this was not built for Puppys Glib 2.14.2, but is part of newer versions of Glib.
So despite the IDE starts with libgio.so from Muggins, it crashes soon, as Puppys glib is too old.
So I now added a newer glib and Gtk (only what was needed, not the full stuff).
As Puppy could break compatibility with other programs, if we would replace existing files, I include them from the seperate folder.
They will be used automatically by "validestart" or by running the IDE from the menu.

Note: the IDE does not have a grafical designer.
To use Glade, we need to create an example project, that is able to use Glade XML files.
It seems that the IDE itself was created using Glade, so it should be not too difficult.
I will have a look when I find some time.

Mark

Posted: Mon 16 Mar 2009, 11:34
by Lobster
Valide is working fine in 4.2 rc3 :)

Posted: Mon 16 Mar 2009, 12:37
by Lobster
:oops: just found out that the official Genie site is editable
Just register . . .

http://live.gnome.org/Genie

What requirements are needed to make Geany (our text editor)
have support for Genie? (I should know this)

Posted: Mon 16 Mar 2009, 13:01
by MUguest
I attach a Glade example.
I created it from:
http://live.gnome.org/Vala/GladeSample

I had to add some changes, to be able to use it in the IDE.
I attach a screenshot, that makes it easier to understand the following text.


Extract the attached archive to your valide project-folder.

Then set up the IDE preferences, so that you see the filebrowser in the left panel.
(you must click on the small folder there, to see it).

Also set up the IDE, to see the bottom area, where you get info about compilation, and see output from your testprograms.

Doubleclick main.vala, to open it in the inbuilt editor.
Also doubleclick gladesample.glade, to see it.

In addition, open gladesample.glade in Glade.

To be able to compile, I had to modifiy Glade1/Glade1.vide.
I added these lines:

Code: Select all

<pkg>libglade-2.0</pkg>
<pkg>gmodule</pkg>
This simulates the compileroptions from the original example.

I also created a new project in Glade.
A window with two buttons.
I had to set the window to "visible".
And I had to set three custom signalhandlers, when you click on the buttons, or close the window.

When you compile and execute the example, you will not see anything in the area at bottom of the IDE, until you close the examplewindow.
Then the messages appear, that show, which button was clicked.

Mark