jckarter/clay — pull request #487 by galchinsky (2013-01-26 00:37:34+00:00)
Title: Pack global state

Every global, static and static-in-function variable is packed to CompilerState struct https://github.com/galchinsky/clay/blob/packGlobalState/compiler/clay.hpp#L996
It is passed like this: https://github.com/galchinsky/clay/blob/packGlobalState/compiler/evaluator.hpp#L53

Motivation:
I faced with lack of modularity when tried to implement several things.
The most important for me is implementation of JIT in compile-time. The idea is to run c code during compilation. This possibly allows to reduce the amount of primitives like staticError. This also could allow to get more access to the compiler from the program with `external` declarations.
It can't be implemented with global variables. The first problem is JIT polluted global llvmModule. @jckarter notes that problem becomes worse if cross-compile: JIT needs to use llvm-target of host machine (i.e. loader, types etc. etc.), but everything is globally set to different target. My idea is to use different CompilerStates for host and target.

Sometimes I used tricks to avoid explicit passing. For example, in codegen the state is passed inside CodegenContext. The same for Env and Type. All tests have been passed.