[gambit-list] Gambit and termite on an embedded system (Nintendo DS)?

Marc Feeley feeley at iro.umontreal.ca
Fri Oct 6 10:57:09 EDT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Andrew, that's a neat project!  For a long time I have been thinking  
of running Gambit "on the bare metal" and, although I have never  
tried to do it, the runtime system has been designed so that there  
are few dependencies on a specific OS.  The C code generated by the  
compiler is very plain (it only uses the header files limits.h,  
wchar.h, float.h, setjmp.h, and math.h).  The OS dependent stuff is  
mostly contained in the lib/os*.c files.  One important file is lib/ 
os.h.  It is there that the OS calls are selected based on the OS,  
for example in os.h you will find this ifdef cascade to select the OS  
function to get the most precise real time, based on the availability  
of certain functions (determined by the configure script):

/* Determine which function for getting real time is most precise.  */

#ifdef HAVE_CLOCK_GETTIME
#define USE_clock_gettime
#else
#ifdef HAVE_GETCLOCK
#define USE_getclock
#else
#ifdef HAVE_GETSYSTEMTIME
#define USE_GetSystemTime
#else
#ifdef HAVE_GETTIMEOFDAY
#define USE_gettimeofday
#else
#ifdef HAVE_FTIME
#define USE_ftime
#else
#ifdef HAVE_TIME
#define USE_time
#endif
#endif
#endif
#endif
#endif
#endif


and in lib/os_time.c the function to get the real time implements  
that functionality based on the USE_xxx symbols defined in os.h:


void ___time_get_current_time
    ___P((___time *tim),
         (tim)
___time *tim;)
{
#ifndef USE_clock_gettime
#ifndef USE_getclock
#ifndef USE_GetSystemTime
#ifndef USE_gettimeofday
#ifndef USE_ftime
#ifndef USE_time
#ifndef USE_CLASSIC_MACOS

   *tim = ___time_mod.time_neg_infinity;

#endif
#endif
#endif
#endif
#endif
#endif
#endif

#ifdef USE_clock_gettime

   /* The clock_gettime function is in POSIX.1b (realtime  
programming). */

   struct timespec ts;
   if (clock_gettime (CLOCK_REALTIME, &ts) == 0)
     ___time_from_nsecs (tim, ts.tv_sec-JAN_1(1970), ts.tv_nsec);
   else
     *tim = ___time_mod.time_neg_infinity;

#endif

#ifdef USE_getclock
   ...
#endif

#ifdef USE_GetSystemTime
   ...
#endif

#ifdef USE_gettimeofday
   ...
#endif

#ifdef USE_ftime
   ...
#endif

#ifdef USE_time
   ...
#endif

#ifdef USE_CLASSIC_MACOS
   ...
#endif
}


Some OS functionality is not strictly required by Gambit, for example  
the Gambit Scheme "rename-file" procedure is only defined for user  
programs, it is not used by the runtime system.  The C functions  
which implement such functionality return an error code of  
___UNIMPL_ERR (unimplemented function error) when the function is  
called.  For example, here is how ___os_rename_file is implemented in  
lib/os_files.c:


___SCMOBJ ___os_rename_file
    ___P((___SCMOBJ path1,
          ___SCMOBJ path2),
         (path1,
          path2)
___SCMOBJ path1;
___SCMOBJ path2;)
{
   ___SCMOBJ e;
   void *cpath1;
   void *cpath2;

#ifndef USE_rename
#ifndef USE_MoveFile

   e = ___FIX(___UNIMPL_ERR);

#endif
#endif

#ifdef USE_rename
   ...
#endif

#ifdef USE_MoveFile
   ...
#endif

   return e;
}


So for your project I think you should start with modifying lib/os.h  
to select a minimal set of OS functions that are provided by the  
Nintendo DS operating system.  Once you have something minimal  
working, you can tie in to more and more OS functionality as your  
needs grow.

Please keep me informed.  In beta 20, I have reorganize the lib/os*  
files so that porting Gambit to an embedded system is easier.  If you  
find other things that would help I would like to add them to the  
runtime system.

Marc


On 5-Oct-06, at 5:46 AM, Andrew Lentvorski wrote:

> I'd like to have a Gambit repl on an embedded system (Nintendo  
> DS).  I'm
> tired of not having a real language to program the thing.  :)
>
> The primary constraint is 4MB of working RAM.  A second constraint  
> would
> be to have the repl over a socket (I looked at web-repl, so that  
> doesn't
> look to be much of a problem).  I can access files from external  
> compact
> flash storage, but I would prefer to limit that as much as possible.
>
> I took a quick trip over to gmane to search the archives to see if
> someone else has tried this, but nothing obvious came up.
>
> I figured I'd ask for some pointers before running blindly down the
> wrong path.
>
> I'd also like to be running termite on this, eventually.  However, I
> figure that I'm going to have enough issues without complicating my  
> life
> like that at the start.
>
> Any pointers/advice would be deeply appreciated.
>
> Thanks,
> -a
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (Darwin)

iD8DBQFFJm7F//V9Zc2T/v4RAvIYAJ9JiKeyOYIj4mpurqJRlsiOdoCmpwCeJ2R+
M53R0lwx3vgKVJE0ZEG6gGA=
=ne4e
-----END PGP SIGNATURE-----



More information about the Gambit-list mailing list