[Aldor-l] Compiling setup

Ralf Hemmecke ralf at hemmecke.de
Sat Aug 12 12:32:49 EDT 2006


Christian's mail was quite hard to read due to strange line breaks, but 
I think he made an important point. If the compiler sees something like

   "blah"

in general it is even impossible to guess the type of that thing.

See my posts to axiom-developer from
14-Feb-2005 (Subject: "The symbol 4 (was Re: Aldor and Axiom)") and
22-Feb-2006 (Subject: "1: %").

Or simply let me repeat the program...

---file crazy.as--
#include "aldor"
CrazyInteger: IntegerType with {string: Literal -> %} == Integer add {
     Rep == Integer;
     import from Rep;
     integer(l: Literal): % == per(integer(l)$Integer + 1);
     string(l: Literal): % == per 42;
}

main(): () == {
     import from TextWriter, Character;
     import from CrazyInteger;
     stdout << "This is crazy :" << space << 1 << newline;
     stdout << "This is crazy :" << space << 2 << newline;
     stdout << "Fourtytwo" + 4 << newline;
}

main();
---end crazy.as

For me it says.
 >aldor -grun -laldor crazy.as
42 1
42 3
47

I cannot believe that Christian meant:
 >   local litA: Literal := "abcdefghij";    -- (*)
should be translated to
 >   char * litA = "abcdefghij";

First of all, the line (*) does not compile at all with libaldor. And I 
even don't know of a way to create a thing of type Literal.
And also the C code is probably not right.

As I see it, the things of type Literal are the true constants, since 
they cannot change as they are character strings that appear in the .as 
file. The type String, however, is a library thing (as Christian pointed 
out). Now, how a literal constant appears as a string is completely up 
to the library. So I guess, we are actually talking about whether or not
things of type Literal should be put into a non-writable data section by 
the compiler.

You should not be misled by the fact that a library (like libaldor) 
provides a type String. And the Aldor library, makes it implicitly clear 
that strings are writeable, by providing a function

   set!: (String, MachineInteger, Character) -> String

So if the (future) compiler puts literals into read-only memory, then 
the library definition

   string(l:Literal):% == string(l pretend Pointer);

is the bug and must be changed.

Ralf



More information about the Aldor-l mailing list