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

Re: Reducing exe size?



In article 
<Pine.GSO.4.21.0112131243560.3709-100000@godzilla.ce.chalmers.se>, 
Robert Feldt <feldt@ce.chalmers.se> wrote:

> On Fri, 14 Dec 2001, Bruce Hoult wrote:
> 
> > Hmm.  Andreas Bogk just checked in a new d2c mode that allows you to 
> > compile a bare Dylan file into a single C file.  It might be possible 
> > to 
> > (semi?) manually go through one of those and find out what is and isn't 
> > needed as a test case.  Well, maybe a Perl script or something :-)
> > 
> This got me thinking: You don't consider Dylan suitable for scripting
> tasks like fiddling with libraries and files etc a la Perl et al?

Dylan the language is suitable.  d2c the compiler doesn't currently have 
the OS or regexp libraries or the fast turn-around time necessary for 
real scripting.

A key strength of Dylan is that you can develop your program in a 
"scripting" sort of way, making maximum use of the dynamism available, 
and then selectively tighten down the parts of the program which need 
greater speed.  That this already works pretty well is apparent in our 
ability to do well at the ICFP contest, but we really need a good IDE 
and the compiler to be faster (or perhaps incremental) to take full 
advantage.  FunO is much better in that regard, but we're still a long 
way from the standards of the various Common Lisp (or Smalltalk) systems 
for interactive development.


> I think one of the strengths of
> Ruby (another language, ruby-lang.org) is that it can be used both for
> smaller tasks and then scale nicely to larger apps. However, no
> multimethods, compilation or type annotations there so I'm checking out
> Dylan.

I read the Ruby book.  My reaction was "why not just use Smalltalk?"  
That may be unfair, but it really seemed to want to be Smalltalk when it 
grew up.  It did look better than Perl or even Python for "real" 
programming using a scripting language.

 
> Could you give me some pointers to the functions/libraries relevant for
> listing the files in a dir and copying and renaming files? Just want to
> try it out and couldn't find simple example programs on the web. And the
> Dylan books I've ordered haven't arrived yet.

You need to use the appropriate operating system calls.  d2c comes with 
a program (Melange) which can read C header files and generate Dylan 
code to access them.  Or you can write interface code yourself.  The 
easiest way to get started is probably to grep the d2c sources for uses 
of "call-out".  There are examples of using memcpy, memmove, fputc, 
fflush, getenv, system, exit in the runtime library, and many hundreds 
in platform/carbon (interfacing to MacOS) and platform/gtk+.

I could show you how to list directories and copy/rename files on Unix, 
but I don't know how to do it on Windows.  In any case you need to use 
the same calls as from C e.g. rename("oldname", "newname"), which would 
be translated to Dylan as:

define method rename(oldname :: <byte-string>, newname :: <byte-string>)
 => res :: <integer>;
  call-out("rename",
           int:, // result type
           ptr:, export-string(oldname),
           ptr:, export-string(newname));
end method;

rename("oldname", "newname");


See src/d2c/runtime/dylan/system.dylan for the "getenv", "system" etc 
examples.

-- Bruce



Follow-Ups: References: