| Age | Commit message (Collapse) | Author | Lines |
|
|
|
The compiler now accepts options on the command-line, such as whether to
interpret or compile, or what kind of output is desired.
Instead of mallocing (and creating a memory leak), generated code now
uses the Boehm garbage collector to allocate memory for boxes. I'm not
entirely sure how the GC works, but it does seem to be working (tested
by setting the environment variable GC_PRINT_STATS when running a
compiled program that calculates a Fibonacci number). More testing
relating to the GC should be created.
The basics for an interpreted mode has been started, but getting it to
work fully would be difficult: it would require figuring out how to
dynamically link LLVM modules/object files into the LLVM execution
engine, both for calling wrapper functions and for using the GC.
Removed -Weverything because it was finding problems in the GC code
despite it being included as a system library.
The main function of an inter program has been renamed to inter_main.
The GC requires GC_INIT is invoked at initialisation on some systems, so
common.c now contains the real main function, which runs GC_INIT
followed by inter_main. GC_INIT is a macro, so it cannot be called
easily from LLVMIR.
|
|
Everything now gets reduced to an i8*, either through placing on the
heap (in the case of primitives) or just through a simple pointer cast.
In the case of primitives, boxing might be avoided by casting the
primitive to an i8*, however this would only work for primitives with
sizes less than or equal to the size of a pointer on the system.
Boxing increases the generated LLVMIR size dramatically, so it is
probably worth looking into ways to reduce the frequency of boxing. One
option is to keep track of whether or not a value has been boxed, and
only boxing/unboxing it when necessary instead of all the time.
The current implementation uses LLVMBuildMalloc, which allocates memory,
but does not ever free this memory. Freeing boxes once its value is
extracted may be safe, though I'm not certain. It may be worth looking
into LLVM's garbage collection support at this point.
|
|
Functions can now be defined using the "def" construct. A "main"
function has to be defined for LLVM to compile the program.
Recursive function definitions are not supported, since all values are
eagerly evaluated, causing infinite recursion of the non-base case.
Recursive definitions can be supported either by including an if
primitive that does not evaluate both sides, or by implementing support
for lazy evalution. I'm interested in exploring the latter, but will
probably implement the former for now.
Similar to the if primitive above, the def primitive is currently an
implementation which could potentially be altered into a function that
manipulates meta-variables at compile time. This would require
compile-time evaluation of functions, which would be really cool, but is
also superfluous to the current goal. I might return to this idea after
I'm happy with the base implementation of the language.
|
|
|