summaryrefslogtreecommitdiff
path: root/MLKLLVMCompiler.mm
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <matthias@benkard.de>2008-08-18 11:38:56 +0200
committerMatthias Andreas Benkard <matthias@benkard.de>2008-08-18 11:41:15 +0200
commit4447563e79bb32bbda14641733049fe544392917 (patch)
treed1d4cdd5498b988817d386a855887b403896eb6f /MLKLLVMCompiler.mm
parent60993a5e474244a3f4f623bb81d5191f2ec50993 (diff)
LLVM compiler: Implement dynamic variable access.
Diffstat (limited to 'MLKLLVMCompiler.mm')
-rw-r--r--MLKLLVMCompiler.mm46
1 files changed, 42 insertions, 4 deletions
diff --git a/MLKLLVMCompiler.mm b/MLKLLVMCompiler.mm
index a7efa12..e7dc660 100644
--- a/MLKLLVMCompiler.mm
+++ b/MLKLLVMCompiler.mm
@@ -132,6 +132,8 @@ static Constant
verifyFunction (*function);
fpm->run (*function);
+ //function->dump();
+
// JIT-compile.
fn = (id (*)()) execution_engine->getPointerToFunction (function);
//module->dump();
@@ -377,9 +379,26 @@ static Constant
{
Value *value;
- if ([_context variableHeapAllocationForSymbol:_form])
+ if (![_context variableIsLexical:_form])
+ {
+ Value *mlkdynamiccontext = [_compiler insertClassLookup:@"MLKCons"];
+ Value *dynctx = [_compiler insertMethodCall:@"currentContext"
+ onObject:mlkdynamiccontext];
+
+ LRETAIN (_form); // FIXME: release
+ Value *symbolV = builder.CreateIntToPtr (ConstantInt::get(Type::Int64Ty,
+ (uint64_t)_form,
+ false),
+ PointerTy);
+
+ std::vector<Value *> args (1, symbolV);
+ value = [_compiler insertMethodCall:@"valueForSymbol:"
+ onObject:dynctx
+ withArgumentVector:&args];
+ }
+ else if ([_context variableHeapAllocationForSymbol:_form])
{
- Value *binding = builder.CreateLoad ([_context bindingValueForSymbol:_form]);
+ Value *binding = builder.CreateLoad (builder.Insert ([_context bindingCellValueForSymbol:_form]));
value = [_compiler insertMethodCall:@"value" onObject:binding];
}
else
@@ -732,10 +751,29 @@ static Constant
{
variable = [var_e nextObject];
value = [valueForm processForLLVM];
+ if (![_context variableIsLexical:variable])
+ {
+ Value *mlkdynamiccontext = [_compiler insertClassLookup:@"MLKCons"];
+ Value *dynctx = [_compiler insertMethodCall:@"currentContext"
+ onObject:mlkdynamiccontext];
+
+ LRETAIN (variable); // FIXME: release
+ Value *symbolV = builder.CreateIntToPtr (ConstantInt::get(Type::Int64Ty,
+ (uint64_t)variable,
+ false),
+ PointerTy);
+
+ std::vector<Value *> args;
+ args.push_back (value);
+ args.push_back (symbolV);
+ [_compiler insertMethodCall:@"setValue:forSymbol:"
+ onObject:dynctx
+ withArgumentVector:&args];
+ }
if ([_context variableHeapAllocationForSymbol:variable])
{
- Value *binding = builder.CreateLoad ([_context
- bindingValueForSymbol:variable]);
+ Value *binding = builder.CreateLoad (builder.Insert ([_context
+ bindingCellValueForSymbol:variable]));
std::vector<Value *> args (1, value);
[_compiler insertVoidMethodCall:@"setValue:"