Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Jako gets modules (sort of)

7 views
Skip to first unread message

Gregor N. Purdy

unread,
Jul 2, 2003, 11:52:25 PM7/2/03
to perl6-i...@perl.org
All --

I just checked in some changes to Jako that bring rudimentary
module support. Its rudimentary because for now, modules are
not referenced from separate files, but simply form handy
named groups of symbols within the single source file being
compiled.

Of course, this really becomes useful once I handle reading
modules from separate source files, so stay tuned...

However, this minimal functionality does permit some fun with
the examples/nci.jako example, which uses curses. The "external
function" declarations within the module can inherit the library
specification from the module properties, which makes for a
handy shortcut notation.

You can see the :fn
property attached to the subroutine declarations -- the function
name in the library defaults to the function name in the .jako
file, although it can be overridden like this:

:fn="foo"

An external function (with :fn property) without a :fnlib
property still needs an fnlib property to work. If it is
declared within a module, it inherits the module's fnlib
attribute (if any), making for handy bundling.

It is intended (but not yet tested) that you can combine
subs with and without :fn within a :fnlib module and have
things work out fine. This will be useful in the Curses
library because (at least on my system) the notional
box() function is actually a macro in the C file, and in
order to present a complete Curses interface in the Jako
module, we'd need to implement box() with the equivalent
call to one of the other :fn subs.

Here's the code from examples/nci.jako:


module Curses
:fnlib = "libcurses.so"
{
sub int initscr :fn ();
sub int endwin :fn ();
sub int curs_set :fn (int x);

sub int addstr :fn (str s);
sub int refresh :fn ();
sub int move :fn (int x, int y);

sub int getch :fn ();
sub int box :fn (int screen, int v, int h);
sub int hline :fn (int ch, int n);
}

var int foo; # Store result from above functions here.

var int screen;

screen = Curses::initscr();

foo = Curses::curs_set(0);
foo = Curses::box(screen, 42, 42);
foo = Curses::move(10, 20);
foo = Curses::addstr("Hello, world!");
foo = Curses::move(12, 15);
foo = Curses::addstr("(Press any key to exit)");

foo = Curses::move(8, 10);
foo = Curses::hline(42, 33);

foo = Curses::move(14, 10);
foo = Curses::hline(42, 33);

foo = Curses::refresh();

foo = Curses::getch();

foo = Curses::curs_set(1);
foo = Curses::endwin();

The code I just checked in includes a few *.jako files in
the languages/jako directory that are intended to eventually
be real usable Jako modules, some of them for ops (:op property)
and some for external libraries (such as Curses.jako).

In any case, if you've been watching Jako (like watching corn
grow, I know) or toying with it, this new update should add
some fun to your day...


Regards,

-- Gregor

--
Gregor Purdy gre...@focusresearch.com
Focus Research, Inc. http://www.focusresearch.com/

0 new messages