Running cupid
Run the interpreter: the prompt, a program, or the compiler for foreign imports.
Synopsis
cupid [option ...]
cupid [option ...] file [argument ...]
cupid [option ...] -i file-or-module ...
cupid [option ...] --ffi file [compiler-argument ...]Description
cupid chooses what to do from its arguments.
With no file, cupid loads the Prelude and shows the prompt, as
described in Interpreter commands. It still reads
commands from standard input when that is not a terminal.
With a file, cupid loads file, which must contain a Main
module, runs main, and exits with the exit code of the action. The
interpreter's own output about loading is suppressed. An error in
loading goes to standard error, headed cupid: Error occurred. An
exception that main does not catch is printed on standard output
after Program error:. Either gives an exit code of 1. A file without
a Main module is an error:
cupid: can't find "Main" module; to load the file at the prompt instead, use cupid -i FILE
Modules that file imports are found first in the directory of file, then on the search path.
With -i, cupid loads each file-or-module at the prompt without
running main, and shows the prompt. The last one loaded is the
current module. Several may be given.
With --ffi, cupid loads file and, for the module in it,
writes a C file with the same base name containing a stub for each
foreign import. It then compiles that file with the C compiler Cupid
was built with, producing Module.so (Module.dll on Windows) next to
the source. Module stands for the base name of file. When cupid
later loads the module it loads the object as well.
The compile command is
cc -shared -fPIC -D__CUPID__ -I$CUPIDDIR/include -o Module.so Module.c compiler-argument ...
with the compiler and flags substituted for the target. On failure the whole command is printed.
Modules imported by file are loaded first, so a module with foreign imports must have been compiled before any module that imports it is.
A foreign import string of the form "header.h name" adds
#include "header.h" to the generated C. The generated code calls a
named function directly, and C23 does not allow implicit declarations,
so an import of a named function needs a header that declares it, unless
it is in <stdlib.h>, which the generated C always includes. wrapper
and dynamic imports name no function.
-i and --ffi count only among the options before file, and are
read from the command line only: in CUPIDFLAGS or after :set the
word -i is an unknown toggle and gives a warning. Giving both is an
error:
cupid: -i and --ffi cannot be used togetherArguments
| Position | Meaning |
|---|---|
Before file, beginning with + or - | Options for the interpreter, as in Options, and the mode flags -i and --ffi |
| file | The first argument that does not begin with + or - |
| After file | With no mode flag: arguments for the program, which getArgs returns. With --ffi: passed unchanged to the C compiler, such as extra sources, -I, -l, -L |
With -i every argument that does not begin with + or - is a file
or module to load.
When a program runs, getProgName returns file.
Exit status
| Status | Condition |
|---|---|
| 0 | main completed, or the prompt was left, or the stubs were compiled |
| 1 | The file could not be loaded, or main raised an error, or the file has no Main module, or the C compiler failed |
| n | main called exitWith (ExitFailure n) |
Environment
CUPIDFLAGS, CUPIDDIR and HOME; see
Environment variables.
Files
| File | Role |
|---|---|
Module.c | Stubs generated by --ffi; overwritten on each run |
Module.so | The compiled object that Cupid loads with the module |
$CUPIDDIR/include/HsFFI.h | Types and the interpreter API used by the stubs |
Examples
Run a program with two arguments:
cupid Main.hs a b
Run a script with a bigger heap:
cupid -h4M myscript
Load two files at the prompt instead of running them:
cupid -i Stats.hs Main.hs
As the interpreter of an executable file, with one option:
#! /usr/local/bin/cupid -h4M
or with several options in one argument:
#! /usr/local/bin/cupid -X+o -h4M
Compile the stubs of a module, with an extra C source and the maths library:
cupid --ffi Hyp.hs clib.c -lmSee also
- Interpreter commands for the prompt
- Write a script that runs with cupid
- Call C functions from Haskell
- How Cupid runs a program
- The language Cupid accepts for the supported calling conventions and import forms