epsilon-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [epsilon-devel] News about Savannah and IRC


From: Luca Saiu
Subject: Re: [epsilon-devel] News about Savannah and IRC
Date: Thu, 11 Dec 2003 00:36:46 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i586; en-US; rv:1.3a) Gecko/20021212

  Hi Matteo.

Matteo Golfarini wrote:
sorry, but i haven't access of irc in university .....
If we need to chat I can set up a talk daemon on stallman (a machine here in my house); I am sure you have at least telnet or ssh access. However we'll talk about this when we actually need it.

for new snapshot you can send me from email and if you want i 've some space on internet,
I can also attach a snapshot to a message sent to this list; however the modifications I made can also wait a week :-); I think it won't take too long for Savannah to bee restored. The Savannah guys seem to be working even harder than usual.
  The modifications you don't know are:
  * fixed infix operators in the current ugly compiler written in C.
  * implemented bignums, with infix operators (Cooool :-)).
* Added an option --verbose-gc, which toggles verbose garbage collector output, for the evm and for all the binary programs generated by epsilonc. * added some little examples (a Sierpinski triangle, and an interpreter which I'm taling you about below).

sorry but now i'm busy, just a little bit, but form next week-end i can start again to implement something
Ok, don't spend time with epsilon when you have to study. Don't behave like me :-).

if you want i can try to :

1 make a logo-machine
Stop-stop-stop! I wrote a nice minimal interpreter for a simple turtle-graphic language; it's only *graphics*, as it completely lacks variables, iteration, recursion, arithmetic expressions (!) and the like. But you can nicely add all of these things; you can use the interpreter I sent to this list as an example (the non-lazy version is slightly simpler). Of course it's still an interpreter: not easy if you just use your fantasy :-), but entirely doable if you use some good reference documentation. Chapter 4 of SICP is very good for this, and you could also use the syllabus from the course "Programmazione 1", if you can still find it on the web. I guess you would like to make the language imperative, as Logo. I have never written a real imperative interpreter in epsilon, but this is the very next thing I will do (this night), to show it to you as an example.

2 try to ,if you give me some tips, repair the repl
No :-). The REPL itself is simple, but it needs the parser and the epsilon meta-interpreter, which aren't :-).

3 do what you need ?????
Some more graphic primitives, by now (ask me any detail if you have doubts). The library could be extended in many other ways, but I have been lazy and I have not yet finished the documentation of C libraries, so you can't work on it yet. List of things that you can't do yet because of my lazyness (so that you can remind me of it; you are authorized to wildly insult me if the documentation won't be online in a week): We need wrappers to sleep(), system(), readline(), maybe fork(), the socket operators, a ncurses binding, rational numbers from gmp... And some of the code which is now in the C library including sdl.c is *not* safe: probably you have already noticed that displaying a pixel whose coordinates are out of the screen can make the program crash, which is A Bad Thing. We need to add some tests and to throw exceptions on failure.
  Ok, now I'm going to write the sample imperative interpreter.
  Bye.

--
Luca Saiu, maintainer of GNU epsilon
http://www.gnu.org/software/epsilon
/* This file is part of GNU epsilon, a functional language implementation

Copyright (C) 2003 Luca Saiu

GNU epsilon is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 2, or (at your
option) any later version.

GNU epsilon is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with epsilon; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */


import simple_graphics;
import floats;
import random;

define w = 640;
define h = 480;

define synonym type state =
  float * // x
  float * // y
  float *   // angle
  boolean;  // down?

define pencolor = 255, 255, 0;

define initial_state = (integer_to_float w) /f 2.0,
                       (integer_to_float h) /f 2.0,
                       (pi /f 2.0),
                       true;

define state_to_x = \ s . s ^ 1;
define state_to_y = \ s . s ^ 2;
define state_to_angle = \ s . s ^ 3;
define state_to_down = \ s . s ^ 4;

define set_x = \ x . \ s .
  x, s ^ 2, s ^ 3, s ^ 4;
define set_y = \ y . \ s .
  s ^ 1, y, s ^ 3, s ^ 4;
define set_angle = \ angle . \ s .
  s ^ 1, s ^ 2, angle, s ^ 4;
define set_down = \ down . \ s .
  s ^ 1, s ^ 2, s ^ 3, down;
define set_xy = \ x . \ y . \ s .
  x, y, s ^ 3, s ^ 4;

define concrete type program = 
  HOME
| UP
| DOWN
| FW of integer
| BW of integer
| L of integer
| R of integer
| SEQ of list of program
| FOREVER of program;

define initialize = begin
  initialize_graphics w h;
  make_io initial_state;
end;

define rad_to_deg = \ r . float_to_integer (r *f 180. /f pi);
define deg_to_rad = \ d . (integer_to_float d) /f 180. *f pi;

define exception error;

define eval = fix \ f . \ p . \ s .
  match p with
    HOME ->  make_io (set_xy (state_to_x initial_state)
                             (state_to_y initial_state)
                             s)
  | UP ->    make_io (set_down false s)
  | DOWN ->  make_io (set_down true s)
  | FW(i) -> let angle be
               state_to_angle s
             in let new_x be
                (state_to_x s) -f (integer_to_float i) *f (cos angle)
             in let new_y be
                (state_to_y s) -f (integer_to_float i) *f (sin angle)
             in begin
/*
               assign r := random_integer_from_to 0 255;
               assign g := random_integer_from_to 0 255;
               assign b := random_integer_from_to 0 255;
               assign pencolor := make_io (r, g, b); */
               if state_to_down s then
                 show_line (float_to_integer (state_to_x s))
                           (float_to_integer (state_to_y s))
                           (float_to_integer new_x)
                           (float_to_integer new_y)
                           pencolor
               else
                 skip;
               make_io (set_xy new_x new_y s);
             end
  | BW(i) -> f FW(- i) s // a 'lazy' solution for me :-)
  | R(i) -> let new_angle be
              (state_to_angle s) +f (deg_to_rad i)
            in
              make_io (set_angle new_angle s)
  | L(i) -> f R(- i) s // lazy again
  | SEQ(ps) -> if empty ps then
                 make_io s
               else begin
                 assign new_s := f (head ps) s;
                 f SEQ(tail ps) new_s;
               end
  | FOREVER(p1) -> begin
                     assign new_s := f p1 s;
                     f p new_s;
                   end;

define run_program = \ p . begin
  assign s := initialize;
  eval p s;
end;

define p1 =
  FOREVER(
    SEQ([
      FW(1);
      L(3);
    ])
  );

define p2 =
  FOREVER(
    SEQ([
    FW(230);
    BW(230);
    R(1);
    ])
  );

define p3 =
SEQ([
  SEQ([
    L(30);
    FW(100);
    BW(100);
    R(30);
    FW(100);
  ]);
  FOREVER(L(1));
]);

define p = p1;

define main = begin
  run_program p;
end;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]