Programming in C with an Assembler…
Early on in my programming career I heard rumors of people programming in Java from Prolog. Having come full circle I now find myself writing C code from LM.
Why target C?
C was originally marketed as a cross-platform assembler. True to its name it does a pretty good job at that. LM is an assembler, originally targeting x86-linux only. After stabilizing the LM compiler I was noticing that a lot of the generated code was structured identical to how C code is structured.
Here are some things that LM was working with that C brings straight out of the box:
memory alignment
register allocation
calculate offsets of local variables
function calling conventions
moving data to/from local variables, global variables, stack variables
constant folding
instruction selection
determining numerical opcodes for each instruction
calculating relative jumps
These are things that C compilers already do very well across a large number of platforms. Surprisingly the more advanced features of LM are mostly inconsequential to this level of code generation.
So, to quickly add support for a large number of platforms with good interoperability and performance we are now working on a compilation target to ANSI C.
What does LM bring to C?
Programming in LM is quickly becoming more practical. Here are a few things that LM will bring to the table for systems programming:
a simple yet modern type system
function templating
syntax macros
functional style programming
object-oriented style programming
resource lifetime tracking (no manual malloc or free)
Expression Fragments (this is a whole new idiom)
easy integration with formal proof carrying code
There is no need to reinvent the wheel. LM development should always focus on doing things that are hard to do in other languages. The initial hypothesis that “System F<: with Specialization” is good for systems programming has been demonstrated to be true now. The next steps will focus on bringing that experience to more programmers in more problem domains.