Help needed on SML compiler

surendar@enuxha.eas.asu.edu (Surendar Chandra )
Mon, 25 Mar 91 19:48:22 -0700

          From comp.compilers

Related articles
Help needed on SML compiler surendar@enuxha.eas.asu.edu (1991-03-25)
Help needed on SML compiler nick@lfcs.edinburgh.ac.uk (1991-03-28)
| List of all articles for this month |

Newsgroups: comp.compilers
From: surendar@enuxha.eas.asu.edu (Surendar Chandra )
Keywords: ML, design, interpreter
Organization: Compilers Central
Date: Mon, 25 Mar 91 19:48:22 -0700

Hi,
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
    references.
    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,
surendar
[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]
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.