-
Notifications
You must be signed in to change notification settings - Fork 0
Script Mode
Derek Snider edited this page Jul 23, 2026
·
1 revision
You don't need main(). A .mad file can be just statements, top to bottom —
madc synthesizes main(argc, argv) around them and runs the file like a
script:
printf("hello from script mode: %d\n", 6 * 7);$ madc hello.mad
hello from script mode: 42No #include, no main, no build step. (Auto-header inclusion
resolved printf automatically.)
Make scripts directly executable:
#!/usr/bin/env madc
printf("running as an executable script\n");chmod +x hello.mad
./hello.mad#include <ns_madc> gives you the madc::sys system object — madc's take on
Python's import sys:
#!/usr/bin/env madc
#include <iostream>
#include <ns_madc>
using namespace std;
for ( int i = 0; i < madc::sys.argv.count(); ++i )
cout << i << ": " << madc::sys.argv[i] << endl;$ madc args.mad alpha beta
0: args.mad
1: alpha
2: betaClassic int main(int argc, char **argv) continues to work exactly as in C —
script mode only kicks in for files with top-level statements.
- Top-level statements execute in order, as the body of the synthesized
main - Global variables with non-constant initializers are initialized dynamically before the first statement runs
- The script's exit status is the value of the last reached
exit()/return, with full parity between JIT and native runs - Script-mode files compile to native executables too:
madc -o hello hello.madworks on a main-less script
-
Your First Program — the classic
main()workflow - CLI Reference — flags, native output, C emission
- ← Back to Home