2

I have seen one other answer link but what I don't understand is what is basis.cm and what's it's use?

Community
  • 1
  • 1
Hans Solo
  • 53
  • 8
  • If your code is 'standard' `Standard ML`, you could use `MLton` to produce executable binary. – barti_ddu Dec 01 '15 at 09:59
  • @barti_ddu so this is want I want to do. An SML-NJ stand alone should be executed. I followed the above link that was mentioned and I used the SMLload parameter. Is it the best way or is there any other way to do it and if this way will lead to any problems? – Hans Solo Dec 01 '15 at 10:03
  • `MLton` is the optimizing compiler for `SML` and is not related to `SML/NJ` (I made a premise, that by 'compiling SML/NJ' you mean 'compiling SML', actually :)); just visit http://mlton.org, read its description and see if it fits. – barti_ddu Dec 01 '15 at 10:19
  • @SaiKiran: You're still not being very precise about whether you want a stand-alone executable provided by any SML compiler, or strictly by the SML/NJ compiler. I assume you want the latter, since Jesper Reenberg's guide that you link to already provides the final recipe for generating a stand-alone executable with MLton. – sshine Dec 01 '15 at 13:15
  • Maybe not quite a standalone executable -- but I have found `SMLofNJ.exportFn ` relatively easy to use. I've used together with 3 or 4 line VBScripts to make clickable icons for launching SML programs. I'd give a link, but currently the SML/NJ web site seems to be under maintenance. – John Coleman Dec 02 '15 at 02:38
  • @SimonShine I want a stand-alone executable provided strictly by the SML/NJ compiler. – Hans Solo Dec 03 '15 at 19:35

1 Answers1

4

You are asking two questions.

What is basis.cm and what's it's use?

This is the Basis library. It allows the use of built-in functions.

How to compile and execute a stand-alone SML-NJ executable

Assuming you followed Jesper Reenberg's tutorial on how to execute a heap image, the next thing you need in order to have SML/NJ produce a stand-alone executable is to convert this heap image. One should hypothetically be able to do this using heap2exec, a tool that takes the heap image, e.g. the .x86-linux file generated on my system, and generates an .asm file that can be assembled and linked.

Unfortunately, this tool is not very well-maintained, so you have to

  1. Go to the smlnj.org page and fix the download-link by removing 'www.' (this page and the SourceForge page don't contain the same explanations or assumptions about argument count, and neither page's download link work).
  2. Download and extract this tool, and fix the 'build' script so it points to your ml-build tool
  3. Fix the tool's argument use by changing [inf, outf] to [_, inf, outf]
  4. Run ./build which generates 'heap2asm.x86-linux' on my system
  5. For example, in order to generate an .asm file for the heap2asm program itself, run

    sml @SMLload heap2asm.x86-linux heap2asm.x86-linux heap2asm.s
    
  6. At this point, I have unfortunately been unable to produce an executable that works. E.g. if you run gcc -c heap2asm.s and ld heap2asm.o, you get a warning of a missing _start label. The resulting executable segfaults even if you rename the existing _sml_heap_image label to _start. That is, it seems that a piece of entry code that the runtime environment normally delivers is missing here.

  7. At this point, discard SML/NJ and use MLton for producing stand-alone binaries.

sshine
  • 15,635
  • 1
  • 41
  • 66
  • let's suppose i have a file main.sml and main.cm has basis.cm which allows us to use the built in functions. i was wondering what other files can be added to support all the functions, like in C++ we can use #include to include all the header files. Is there something like that in SML-NJ – Hans Solo Dec 07 '15 at 13:31