|Help needed on SML compiler firstname.lastname@example.org (1991-03-25)|
|Help needed on SML compiler email@example.com (1991-03-28)|
|From:||firstname.lastname@example.org (Surendar Chandra )|
|Keywords:||ML, design, interpreter|
|Date:||Mon, 25 Mar 91 19:48:22 -0700|
I am new to this group and am not sure if this query is appropriate
in this group.
I am writing a subset of the Standard ML functional language as
part of my course project and am facing a few problems with functional
langauge implementation. I have used a SML intepreter which seems to work
okay in this case. . However when I try to think of compiling it, I have
some problems. Specifically, I'll take a small code section.
> val a = 1 ; /* Equate the variable a to 1 */
> val b = a ;
> fun a b = b * 2 ; /* Define a function a that takes one integer argument and
doubles it */
> val c = a 1 ;
> fun a ( b , c ) = b * c * 2 ;
> val d = a ( 1 , 2 ) ;
Now, I am very familiar with UNIX and 'C' and I couldn't think of
any way to generate code for this SML construct . If I were to create a
global variable 'a' and assign it to 'b' and when I try to redefine 'a' to
a function, how do I do that? How can I generate code for langauges were
both function definition and usage is mixed up?
I was thinking of two solutions
* Generate a shadow function file which will have code for the functions and
generate code for assignments in one file and let the link editor resolve
Problem: It still will give a Multiply defined symbol.. error.
* Internally generate names something like <User_defined_name>_<random_number>
so that the 'a' which you access changes dynamically with redefinition.
Problem: The problem is the function compiled in one file will never
be accessible in another file as there is no relation between what the
user gives and system generates.
Now, I tried to see if there is any SML compilers around and I couldn't
find any. I would really appreciate any help..
Thanks in advance,
[There are some ML compilers around, you can ftp one from princeton.edu. As
far as this problem goes, I'd suggest that the variables really be structures
with type tags and pointers that are dereferenced at run time. There is no
way in C to directly handle things whose type isn't known at compile time,
you have to handle it yourself. -John]
Return to the
Search the comp.compilers archives again.