Saturday, May 17, 2008

SML hacking tip: fix uncaught exception BadAnchor

Note: Narrowly targeted Google-food. Skip if you do not program in Standard ML.

If you use the Standard ML of New Jersey (smlnj) compilation manager (CM), then you will sometimes get error messages like this:

[bad plugin name: anchor $y-ext.cm not defined]

uncaught exception BadAnchor
  raised at: ../cm/paths/srcpath.sml:436.16-436.25
             ../cm/util/safeio.sml:41.55
             ../cm/util/safeio.sml:41.55
             ../cm/util/safeio.sml:41.55
             ../cm/parse/parse.sml:502.47
/usr/lib/smlnj/bin/sml: Fatal error -- Uncaught exception BadAnchor with 0
 raised at ../cm/paths/srcpath.sml:436.16-436.25

make: *** [default] Error 1

This is CM's way of telling you that it encountered a line in your *.cm that has an extension that it does not understand. In this case, it's a file with a .y extension.

The fix is to correct the file extension (if it was a typo), or perhaps to update to a version of CM that understands the file extension you're using.

In my case, I had been hacking with an ages-old version of SML/NJ, and recently updated to the version in Ubuntu 8.04 (a.k.a. Hardy). Apparently non-ancient versions of SML/NJ expect ML-Yacc files to be named with the extension .grm instead of .y. I renamed my Yacc file, updated sources.cm, and all was well.

2 comments:

  1. You hit my narrow target with this post. Thanks! It also seems that CM now uses ml-ulex instead of ml-lex, which has led to some incompatibilities in my build. I wonder if there's a way to force it use ml-lex instead of "ml-ulex --ml-lex-mode"?

    ReplyDelete
  2. Another fix (besides renaming), you can add the line
    y : suffix(mlyacc)
    above the line where your .cm file contains a foo.y

    ReplyDelete