From 1dc0cdf8416eb0e98017d1f833ac1e9e6077fda5 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Tue, 2 Sep 2008 00:08:31 +0200 Subject: LLVM compiler: Allocate all variables that are free in some lambda form on the heap. --- MLKLLVMCompiler.mm | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'MLKLLVMCompiler.mm') diff --git a/MLKLLVMCompiler.mm b/MLKLLVMCompiler.mm index 071146a..17186e7 100644 --- a/MLKLLVMCompiler.mm +++ b/MLKLLVMCompiler.mm @@ -146,6 +146,7 @@ static Constant MLKForm *form = [MLKForm formWithObject:object inContext:context forCompiler:self]; + [self markVariablesForHeapAllocationInForm:form]; block = BasicBlock::Create ("entry", function); builder.SetInsertPoint (block); @@ -206,6 +207,33 @@ static Constant return [form processForLLVM]; } ++(void) markVariablesForHeapAllocationInForm:(MLKForm *)form +{ + NSArray *subforms = [form subforms]; + unsigned int i; + + for (i = 0; i < [subforms count]; i++) + { + MLKForm *subform = [subforms objectAtIndex:i]; + + [self markVariablesForHeapAllocationInForm:subform]; + + if ([subform isKindOfClass:[MLKSimpleLambdaForm class]] + || [subform isKindOfClass:[MLKLambdaForm class]]) + { + NSArray *freeVariables = [[subform freeVariables] allObjects]; + unsigned int j; + + for (j = 0; j < [freeVariables count]; j++) + { + id variable = [freeVariables objectAtIndex:j]; + [variable setVariableHeapAllocation:YES + forSymbol:variable]; + } + } + } +} + +(Value *) insertSelectorLookup:(NSString *)name { Constant *function = -- cgit v1.2.3