Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!decwrl!world!iecc!compilers-sender From: surendar@enuxha.eas.asu.edu (Surendar Chandra ) Newsgroups: comp.compilers Subject: Help needed on SML compiler Keywords: ML, design, interpreter Message-ID: <9103260248.AA22854@enuxha.eas.asu.edu> Date: 26 Mar 91 02:48:22 GMT Sender: compilers-sender@iecc.cambridge.ma.us Reply-To: surendar@enuxha.eas.asu.edu (Surendar Chandra ) Organization: Compilers Central Lines: 47 Approved: compilers@iecc.cambridge.ma.us 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 _ 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] -- Send compilers articles to compilers@iecc.cambridge.ma.us or {ima | spdcc | world}!iecc!compilers. Meta-mail to compilers-request.