From 446269ef596e30365eb01e930d525b845be7b9bf Mon Sep 17 00:00:00 2001 From: Matthias Benkard Date: Thu, 2 Oct 2008 12:28:43 +0200 Subject: LLVM compiler: Restore capability of building on Mac OS X 10.4. --- MLKLLVMCompiler.mm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MLKLLVMCompiler.mm b/MLKLLVMCompiler.mm index 5428927..da4710d 100644 --- a/MLKLLVMCompiler.mm +++ b/MLKLLVMCompiler.mm @@ -57,8 +57,10 @@ #include #ifdef MACOSX -#include #include +#if defined(OBJC_API_VERSION) && OBJC_API_VERSION >= 2 +#include +#endif #endif using namespace llvm; -- cgit v1.2.3 From 637efdc284d97ccb04edc676428ecda077f940f6 Mon Sep 17 00:00:00 2001 From: Matthias Benkard Date: Thu, 2 Oct 2008 12:29:51 +0200 Subject: Xcode project: Consolidate custom compiler flags as project-wide build settings. --- Toilet Lisp.xcodeproj/project.pbxproj | 259 ++++++++++++++++++---------------- 1 file changed, 135 insertions(+), 124 deletions(-) diff --git a/Toilet Lisp.xcodeproj/project.pbxproj b/Toilet Lisp.xcodeproj/project.pbxproj index a815bc7..4e04fb8 100644 --- a/Toilet Lisp.xcodeproj/project.pbxproj +++ b/Toilet Lisp.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 45; + objectVersion = 42; objects = { /* Begin PBXBuildFile section */ @@ -296,7 +296,7 @@ /* Begin PBXFileReference section */ A720D3670E5B1CB700734638 /* GNUmakefile */ = {isa = PBXFileReference; explicitFileType = sourcecode.make; fileEncoding = 4; languageSpecificationIdentifier = make; path = GNUmakefile; sourceTree = ""; }; A72BC6EE0E65DE4600486804 /* Toilet Lisp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Toilet Lisp.app"; sourceTree = BUILT_PRODUCTS_DIR; }; - A72BC6F00E65DE4600486804 /* Toilet Lisp-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Toilet Lisp-Info.plist"; sourceTree = ""; }; + A72BC6F00E65DE4600486804 /* Toilet Lisp-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "Toilet Lisp-Info.plist"; sourceTree = ""; }; A72BC6FC0E65E06200486804 /* MainMenu.nib */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; path = MainMenu.nib; sourceTree = ""; }; A72BC70A0E65EA1100486804 /* MLKListenerController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MLKListenerController.m; sourceTree = ""; }; A72BC70B0E65EA1100486804 /* MLKListenerController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MLKListenerController.h; sourceTree = ""; }; @@ -397,7 +397,7 @@ A7B6D0C00E22094F006F6A21 /* MLKStringOutputStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MLKStringOutputStream.h; sourceTree = ""; }; A7B6D0C10E22094F006F6A21 /* MLKStringOutputStream.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MLKStringOutputStream.m; sourceTree = ""; }; A7E5C3EB0E21689F00A01D81 /* ToiletKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ToiletKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - A7E5C3EC0E21689F00A01D81 /* ToiletKit-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "ToiletKit-Info.plist"; sourceTree = ""; }; + A7E5C3EC0E21689F00A01D81 /* ToiletKit-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "ToiletKit-Info.plist"; sourceTree = ""; }; A7E5C3F30E21690200A01D81 /* toilet */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = toilet; sourceTree = BUILT_PRODUCTS_DIR; }; A7E5C3F80E21695700A01D81 /* MLKBinding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MLKBinding.h; sourceTree = ""; }; A7E5C3F90E21695700A01D81 /* MLKBinding.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MLKBinding.m; sourceTree = ""; }; @@ -1107,13 +1107,14 @@ GCC_OPTIMIZATION_LEVEL = 0; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h"; + GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES; INFOPLIST_FILE = "Toilet Lisp-Info.plist"; INSTALL_PATH = "$(HOME)/Applications"; LIBRARY_SEARCH_PATHS = /opt/local/lib; + MACOSX_DEPLOYMENT_TARGET = ""; OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", + "$(inherited)", "-DUSE_LLVM", - "-DMACOSX", ); OTHER_LDFLAGS = ( "-framework", @@ -1162,13 +1163,14 @@ GCC_MODEL_TUNING = G5; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h"; + GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES; INFOPLIST_FILE = "Toilet Lisp-Info.plist"; INSTALL_PATH = "$(HOME)/Applications"; LIBRARY_SEARCH_PATHS = /opt/local/lib; + MACOSX_DEPLOYMENT_TARGET = ""; OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", + "$(inherited)", "-DUSE_LLVM", - "-DMACOSX", ); OTHER_LDFLAGS = ( "-framework", @@ -1218,13 +1220,14 @@ GCC_MODEL_TUNING = G5; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h"; + GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES; INFOPLIST_FILE = "Toilet Lisp-Info.plist"; INSTALL_PATH = "$(HOME)/Applications"; LIBRARY_SEARCH_PATHS = /opt/local/lib; + MACOSX_DEPLOYMENT_TARGET = ""; OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", + "$(inherited)", "-DUSE_LLVM", - "-DMACOSX", ); OTHER_LDFLAGS = ( "-framework", @@ -1275,13 +1278,14 @@ GCC_MODEL_TUNING = G5; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h"; + GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES; INFOPLIST_FILE = "Toilet Lisp-Info.plist"; INSTALL_PATH = "$(HOME)/Applications"; LIBRARY_SEARCH_PATHS = /opt/local/lib; + MACOSX_DEPLOYMENT_TARGET = ""; OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", + "$(inherited)", "-DUSE_LLVM", - "-DMACOSX", ); OTHER_LDFLAGS = ( "-framework", @@ -1330,13 +1334,14 @@ GCC_MODEL_TUNING = G5; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h"; + GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES; INFOPLIST_FILE = "Toilet Lisp-Info.plist"; INSTALL_PATH = "$(HOME)/Applications"; LIBRARY_SEARCH_PATHS = /opt/local/lib; + MACOSX_DEPLOYMENT_TARGET = ""; OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", + "$(inherited)", "-DUSE_LLVM", - "-DMACOSX", ); OTHER_LDFLAGS = ( "-framework", @@ -1386,13 +1391,14 @@ GCC_MODEL_TUNING = G5; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h"; + GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES; INFOPLIST_FILE = "Toilet Lisp-Info.plist"; INSTALL_PATH = "$(HOME)/Applications"; LIBRARY_SEARCH_PATHS = /opt/local/lib; + MACOSX_DEPLOYMENT_TARGET = ""; OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", + "$(inherited)", "-DUSE_LLVM", - "-DMACOSX", ); OTHER_LDFLAGS = ( "-framework", @@ -1447,16 +1453,15 @@ GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h"; HEADER_SEARCH_PATHS = /opt/local/include; INSTALL_PATH = /usr/local/lib; + MACOSX_DEPLOYMENT_TARGET = ""; OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", + "$(inherited)", "-DUSE_LLVM", "-DLLVM_MAJOR_VERSION=2", "-DLLVM_MINOR_VERSION=3", - "-DMACOSX", ); OTHER_CPLUSPLUSFLAGS = ( - "$(OTHER_CFLAGS)", - "-I/opt/local/include", + "$(inherited)", "-D_DEBUG", "-D_GNU_SOURCE", "-D__STDC_LIMIT_MACROS", @@ -1483,16 +1488,15 @@ GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h"; HEADER_SEARCH_PATHS = /opt/local/include; INSTALL_PATH = /usr/local/lib; + MACOSX_DEPLOYMENT_TARGET = ""; OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", + "$(inherited)", "-DUSE_LLVM", "-DLLVM_MAJOR_VERSION=2", "-DLLVM_MINOR_VERSION=3", - "-DMACOSX", ); OTHER_CPLUSPLUSFLAGS = ( - "$(OTHER_CFLAGS)", - "-I/opt/local/include", + "$(inherited)", "-D_DEBUG", "-D_GNU_SOURCE", "-D__STDC_LIMIT_MACROS", @@ -1520,16 +1524,15 @@ GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h"; HEADER_SEARCH_PATHS = /opt/local/include; INSTALL_PATH = /usr/local/lib; + MACOSX_DEPLOYMENT_TARGET = ""; OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", + "$(inherited)", "-DUSE_LLVM", "-DLLVM_MAJOR_VERSION=2", "-DLLVM_MINOR_VERSION=3", - "-DMACOSX", ); OTHER_CPLUSPLUSFLAGS = ( - "$(OTHER_CFLAGS)", - "-I/opt/local/include", + "$(inherited)", "-D_DEBUG", "-D_GNU_SOURCE", "-D__STDC_LIMIT_MACROS", @@ -1558,16 +1561,15 @@ GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h"; HEADER_SEARCH_PATHS = /opt/local/include; INSTALL_PATH = /usr/local/lib; + MACOSX_DEPLOYMENT_TARGET = ""; OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", + "$(inherited)", "-DUSE_LLVM", "-DLLVM_MAJOR_VERSION=2", "-DLLVM_MINOR_VERSION=3", - "-DMACOSX", ); OTHER_CPLUSPLUSFLAGS = ( - "$(OTHER_CFLAGS)", - "-I/opt/local/include", + "$(inherited)", "-D_DEBUG", "-D_GNU_SOURCE", "-D__STDC_LIMIT_MACROS", @@ -1594,16 +1596,15 @@ GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h"; HEADER_SEARCH_PATHS = /opt/local/include; INSTALL_PATH = /usr/local/lib; + MACOSX_DEPLOYMENT_TARGET = ""; OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", + "$(inherited)", "-DUSE_LLVM", "-DLLVM_MAJOR_VERSION=2", "-DLLVM_MINOR_VERSION=3", - "-DMACOSX", ); OTHER_CPLUSPLUSFLAGS = ( - "$(OTHER_CFLAGS)", - "-I/opt/local/include", + "$(inherited)", "-D_DEBUG", "-D_GNU_SOURCE", "-D__STDC_LIMIT_MACROS", @@ -1631,16 +1632,15 @@ GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h"; HEADER_SEARCH_PATHS = /opt/local/include; INSTALL_PATH = /usr/local/lib; + MACOSX_DEPLOYMENT_TARGET = ""; OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", + "$(inherited)", "-DUSE_LLVM", "-DLLVM_MAJOR_VERSION=2", "-DLLVM_MINOR_VERSION=3", - "-DMACOSX", ); OTHER_CPLUSPLUSFLAGS = ( - "$(OTHER_CFLAGS)", - "-I/opt/local/include", + "$(inherited)", "-D_DEBUG", "-D_GNU_SOURCE", "-D__STDC_LIMIT_MACROS", @@ -1673,10 +1673,8 @@ HEADER_SEARCH_PATHS = /opt/local/include; INSTALL_PATH = "$(HOME)/bin"; LIBRARY_SEARCH_PATHS = /opt/local/lib; - OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", - "-DMACOSX", - ); + MACOSX_DEPLOYMENT_TARGET = ""; + OTHER_CFLAGS = "$(inherited)"; OTHER_LDFLAGS = ( "-framework", Foundation, @@ -1710,10 +1708,8 @@ HEADER_SEARCH_PATHS = /opt/local/include; INSTALL_PATH = "$(HOME)/bin"; LIBRARY_SEARCH_PATHS = /opt/local/lib; - OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", - "-DMACOSX", - ); + MACOSX_DEPLOYMENT_TARGET = ""; + OTHER_CFLAGS = "$(inherited)"; OTHER_LDFLAGS = ( "-framework", Foundation, @@ -1748,10 +1744,8 @@ HEADER_SEARCH_PATHS = /opt/local/include; INSTALL_PATH = "$(HOME)/bin"; LIBRARY_SEARCH_PATHS = /opt/local/lib; - OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", - "-DMACOSX", - ); + MACOSX_DEPLOYMENT_TARGET = ""; + OTHER_CFLAGS = "$(inherited)"; OTHER_LDFLAGS = ( "-framework", Foundation, @@ -1788,10 +1782,8 @@ HEADER_SEARCH_PATHS = /opt/local/include; INSTALL_PATH = "$(HOME)/bin"; LIBRARY_SEARCH_PATHS = /opt/local/lib; - OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", - "-DMACOSX", - ); + MACOSX_DEPLOYMENT_TARGET = ""; + OTHER_CFLAGS = "$(inherited)"; OTHER_LDFLAGS = ( "-framework", Foundation, @@ -1829,10 +1821,8 @@ HEADER_SEARCH_PATHS = /opt/local/include; INSTALL_PATH = "$(HOME)/bin"; LIBRARY_SEARCH_PATHS = /opt/local/lib; - OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", - "-DMACOSX", - ); + MACOSX_DEPLOYMENT_TARGET = ""; + OTHER_CFLAGS = "$(inherited)"; OTHER_LDFLAGS = ( "-framework", Foundation, @@ -1871,10 +1861,8 @@ HEADER_SEARCH_PATHS = /opt/local/include; INSTALL_PATH = "$(HOME)/bin"; LIBRARY_SEARCH_PATHS = /opt/local/lib; - OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", - "-DMACOSX", - ); + MACOSX_DEPLOYMENT_TARGET = ""; + OTHER_CFLAGS = "$(inherited)"; OTHER_LDFLAGS = ( "-framework", Foundation, @@ -1913,14 +1901,8 @@ INSTALL_PATH = "$(HOME)/Library/Frameworks"; LIBRARY_SEARCH_PATHS = /opt/local/lib; MACOSX_DEPLOYMENT_TARGET = ""; - OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", - "-DMACOSX", - ); - OTHER_CPLUSPLUSFLAGS = ( - "$(OTHER_CFLAGS)", - "-I/opt/local/include", - ); + OTHER_CFLAGS = "$(inherited)"; + OTHER_CPLUSPLUSFLAGS = "$(inherited)"; OTHER_LDFLAGS = ( "-framework", Foundation, @@ -1953,10 +1935,10 @@ INSTALL_PATH = "$(HOME)/bin"; LIBRARY_SEARCH_PATHS = /opt/local/lib; OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", + "$(inherited)", "-DUSE_LLVM", - "-DMACOSX", ); + OTHER_CPLUSPLUSFLAGS = "$(inherited)"; OTHER_LDFLAGS = ( "-framework", Foundation, @@ -1996,6 +1978,16 @@ isa = XCBuildConfiguration; buildSettings = { COPY_PHASE_STRIP = NO; + OTHER_CFLAGS = ( + "$(inherited)", + "-DHAVE_FFI_FFI_H", + "-DMACOSX", + ); + OTHER_CPLUSPLUSFLAGS = ( + "$(inherited)", + "$(OTHER_CFLAGS)", + "-I/opt/local/include", + ); }; name = "Debug 10.4+ (fast)"; }; @@ -2022,14 +2014,8 @@ INSTALL_PATH = "$(HOME)/Library/Frameworks"; LIBRARY_SEARCH_PATHS = /opt/local/lib; MACOSX_DEPLOYMENT_TARGET = ""; - OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", - "-DMACOSX", - ); - OTHER_CPLUSPLUSFLAGS = ( - "$(OTHER_CFLAGS)", - "-I/opt/local/include", - ); + OTHER_CFLAGS = "$(inherited)"; + OTHER_CPLUSPLUSFLAGS = "$(inherited)"; OTHER_LDFLAGS = ( "-framework", Foundation, @@ -2063,10 +2049,10 @@ INSTALL_PATH = "$(HOME)/bin"; LIBRARY_SEARCH_PATHS = /opt/local/lib; OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", + "$(inherited)", "-DUSE_LLVM", - "-DMACOSX", ); + OTHER_CPLUSPLUSFLAGS = "$(inherited)"; OTHER_LDFLAGS = ( "-framework", Foundation, @@ -2106,6 +2092,16 @@ isa = XCBuildConfiguration; buildSettings = { COPY_PHASE_STRIP = NO; + OTHER_CFLAGS = ( + "$(inherited)", + "-DHAVE_FFI_FFI_H", + "-DMACOSX", + ); + OTHER_CPLUSPLUSFLAGS = ( + "$(inherited)", + "$(OTHER_CFLAGS)", + "-I/opt/local/include", + ); }; name = "Debug 10.4+ (fast + GC)"; }; @@ -2135,14 +2131,8 @@ INSTALL_PATH = "$(HOME)/Library/Frameworks"; LIBRARY_SEARCH_PATHS = /opt/local/lib; MACOSX_DEPLOYMENT_TARGET = ""; - OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", - "-DMACOSX", - ); - OTHER_CPLUSPLUSFLAGS = ( - "$(OTHER_CFLAGS)", - "-I/opt/local/include", - ); + OTHER_CFLAGS = "$(inherited)"; + OTHER_CPLUSPLUSFLAGS = "$(inherited)"; OTHER_LDFLAGS = ( "-framework", Foundation, @@ -2183,14 +2173,8 @@ INSTALL_PATH = "$(HOME)/Library/Frameworks"; LIBRARY_SEARCH_PATHS = /opt/local/lib; MACOSX_DEPLOYMENT_TARGET = ""; - OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", - "-DMACOSX", - ); - OTHER_CPLUSPLUSFLAGS = ( - "$(OTHER_CFLAGS)", - "-I/opt/local/include", - ); + OTHER_CFLAGS = "$(inherited)"; + OTHER_CPLUSPLUSFLAGS = "$(inherited)"; OTHER_LDFLAGS = ( "-framework", Foundation, @@ -2227,10 +2211,10 @@ INSTALL_PATH = "$(HOME)/bin"; LIBRARY_SEARCH_PATHS = /opt/local/lib; OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", + "$(inherited)", "-DUSE_LLVM", - "-DMACOSX", ); + OTHER_CPLUSPLUSFLAGS = "$(inherited)"; OTHER_LDFLAGS = ( "-framework", Foundation, @@ -2290,10 +2274,10 @@ INSTALL_PATH = "$(HOME)/bin"; LIBRARY_SEARCH_PATHS = /opt/local/lib; OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", + "$(inherited)", "-DUSE_LLVM", - "-DMACOSX", ); + OTHER_CPLUSPLUSFLAGS = "$(inherited)"; OTHER_LDFLAGS = ( "-framework", Foundation, @@ -2333,6 +2317,16 @@ isa = XCBuildConfiguration; buildSettings = { COPY_PHASE_STRIP = YES; + OTHER_CFLAGS = ( + "$(inherited)", + "-DHAVE_FFI_FFI_H", + "-DMACOSX", + ); + OTHER_CPLUSPLUSFLAGS = ( + "$(inherited)", + "$(OTHER_CFLAGS)", + "-I/opt/local/include", + ); }; name = "Release 10.4+ (fast)"; }; @@ -2340,6 +2334,16 @@ isa = XCBuildConfiguration; buildSettings = { COPY_PHASE_STRIP = YES; + OTHER_CFLAGS = ( + "$(inherited)", + "-DHAVE_FFI_FFI_H", + "-DMACOSX", + ); + OTHER_CPLUSPLUSFLAGS = ( + "$(inherited)", + "$(OTHER_CFLAGS)", + "-I/opt/local/include", + ); }; name = "Release 10.4+ (fast + GC)"; }; @@ -2347,6 +2351,16 @@ isa = XCBuildConfiguration; buildSettings = { COPY_PHASE_STRIP = NO; + OTHER_CFLAGS = ( + "$(inherited)", + "-DHAVE_FFI_FFI_H", + "-DMACOSX", + ); + OTHER_CPLUSPLUSFLAGS = ( + "$(inherited)", + "$(OTHER_CFLAGS)", + "-I/opt/local/include", + ); }; name = Debug; }; @@ -2354,6 +2368,16 @@ isa = XCBuildConfiguration; buildSettings = { COPY_PHASE_STRIP = YES; + OTHER_CFLAGS = ( + "$(inherited)", + "-DHAVE_FFI_FFI_H", + "-DMACOSX", + ); + OTHER_CPLUSPLUSFLAGS = ( + "$(inherited)", + "$(OTHER_CFLAGS)", + "-I/opt/local/include", + ); }; name = Release; }; @@ -2378,15 +2402,8 @@ INSTALL_PATH = /Library/Frameworks; LIBRARY_SEARCH_PATHS = /opt/local/lib; MACOSX_DEPLOYMENT_TARGET = ""; - OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", - "-DMACOSX", - "-fno-omit-frame-pointer", - ); - OTHER_CPLUSPLUSFLAGS = ( - "$(OTHER_CFLAGS)", - "-I/opt/local/include", - ); + OTHER_CFLAGS = "$(inherited)"; + OTHER_CPLUSPLUSFLAGS = "$(inherited)"; OTHER_LDFLAGS = ( "-framework", Foundation, @@ -2425,14 +2442,8 @@ INSTALL_PATH = "$(HOME)/Library/Frameworks"; LIBRARY_SEARCH_PATHS = /opt/local/lib; MACOSX_DEPLOYMENT_TARGET = ""; - OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", - "-DMACOSX", - ); - OTHER_CPLUSPLUSFLAGS = ( - "$(OTHER_CFLAGS)", - "-I/opt/local/include", - ); + OTHER_CFLAGS = "$(inherited)"; + OTHER_CPLUSPLUSFLAGS = "$(inherited)"; OTHER_LDFLAGS = ( "-framework", Foundation, @@ -2464,10 +2475,10 @@ INSTALL_PATH = "$(HOME)/bin"; LIBRARY_SEARCH_PATHS = /opt/local/lib; OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", + "$(inherited)", "-DUSE_LLVM", - "-DMACOSX", ); + OTHER_CPLUSPLUSFLAGS = "$(inherited)"; OTHER_LDFLAGS = ( "-framework", Foundation, @@ -2525,10 +2536,10 @@ INSTALL_PATH = "$(HOME)/bin"; LIBRARY_SEARCH_PATHS = /opt/local/lib; OTHER_CFLAGS = ( - "-DHAVE_FFI_FFI_H", + "$(inherited)", "-DUSE_LLVM", - "-DMACOSX", ); + OTHER_CPLUSPLUSFLAGS = "$(inherited)"; OTHER_LDFLAGS = ( "-framework", Foundation, -- cgit v1.2.3 From 9fef4e8498255fb72f654514321ffc1e8ca382b6 Mon Sep 17 00:00:00 2001 From: Matthias Benkard Date: Thu, 2 Oct 2008 15:09:25 +0200 Subject: Add a multiple-value return pointer argument to all compiled procedures. --- MLKCompiledClosure.m | 27 ++++++--- MLKLLVMCompiler.h | 4 +- MLKLLVMCompiler.mm | 96 +++++++++++++++++++----------- MLKLexicalContext-MLKLLVMCompilation.mm | 2 +- MLKRoot.m | 102 ++++++++++++++++---------------- 5 files changed, 136 insertions(+), 95 deletions(-) diff --git a/MLKCompiledClosure.m b/MLKCompiledClosure.m index b379dd3..4a59f7d 100644 --- a/MLKCompiledClosure.m +++ b/MLKCompiledClosure.m @@ -17,6 +17,7 @@ */ #import "MLKCompiledClosure.h" +#import "MLKCons.h" #import "functions.h" #import "globals.h" @@ -66,23 +67,28 @@ -(NSArray *) applyToArray:(NSArray *)arguments { - int argc = ([arguments count] + 2); + int argc = ([arguments count] + 3); ffi_cif cif; ffi_type *arg_types[argc]; ffi_status status; void *argv[argc]; - id argpointers[argc - 1]; + id argpointers[argc - 2]; ffi_arg return_value; int i; + id return_values = nil; + id *return_values_ptr = &return_values; arg_types[0] = &ffi_type_pointer; argv[0] = &m_data; + + arg_types[1] = &ffi_type_pointer; + argv[1] = &return_values_ptr; - for (i = 1; i < argc - 1; i++) + for (i = 2; i < argc - 1; i++) { arg_types[i] = &ffi_type_pointer; - argpointers[i-1] = denullify([arguments objectAtIndex:(i-1)]); - argv[i] = &argpointers[i-1]; + argpointers[i-2] = denullify([arguments objectAtIndex:(i-2)]); + argv[i] = &argpointers[i-2]; } arg_types[argc - 1] = &ffi_type_pointer; @@ -104,8 +110,15 @@ ffi_call (&cif, FFI_FN (m_code), &return_value, (void**)argv); // return_value = ((id (*)(void *, ...))_code) (_data, argpointers[0], argpointers[1], MLKEndOfArgumentsMarker); - // FIXME: multiple values - return [NSArray arrayWithObject:nullify((id)return_value)]; + if (return_values) + { + MLKCons *values = [return_values cdr]; + return (values ? [values array] : [NSArray array]); + } + else + { + return [NSArray arrayWithObject:nullify((id)return_value)]; + } } -(NSString *) description diff --git a/MLKLLVMCompiler.h b/MLKLLVMCompiler.h index 44f1b33..e0ff2d4 100644 --- a/MLKLLVMCompiler.h +++ b/MLKLLVMCompiler.h @@ -84,7 +84,7 @@ using namespace llvm; #ifdef __cplusplus @interface MLKForm (MLKLLVMCompilation) --(Value *) processForLLVM; --(Value *) reallyProcessForLLVM; +-(Value *) processForLLVMWithMultiValue:(Value *)multiValue; +-(Value *) reallyProcessForLLVMWithMultiValue:(Value *)multiValue; @end #endif diff --git a/MLKLLVMCompiler.mm b/MLKLLVMCompiler.mm index da4710d..e463a65 100644 --- a/MLKLLVMCompiler.mm +++ b/MLKLLVMCompiler.mm @@ -225,7 +225,7 @@ static Constant +(Value *) processForm:(MLKForm *)form { - return [form processForLLVM]; + return [form processForLLVMWithMultiValue:NULL]; } +(void) markVariablesForHeapAllocationInForm:(MLKForm *)form @@ -414,7 +414,7 @@ static Constant @implementation MLKForm (MLKLLVMCompilation) --(Value *) processForLLVM +-(Value *) processForLLVMWithMultiValue:(Value *)multiValue { #if 0 [_compiler insertTrace: @@ -422,7 +422,7 @@ static Constant @"Executing: %@", MLKPrintToString(_form)]]; #endif - Value *result = [self reallyProcessForLLVM]; + Value *result = [self reallyProcessForLLVMWithMultiValue:multiValue]; #if 0 [_compiler insertTrace: @@ -433,7 +433,7 @@ static Constant return result; } --(Value *) reallyProcessForLLVM +-(Value *) reallyProcessForLLVMWithMultiValue:(Value *)multiValue { NSLog (@"WARNING: Unrecognised form type: %@", self); return NULL; @@ -442,15 +442,21 @@ static Constant @implementation MLKProgNForm (MLKLLVMCompilation) --(Value *) reallyProcessForLLVM +-(Value *) reallyProcessForLLVMWithMultiValue:(Value *)multiValue { NSEnumerator *e = [_bodyForms objectEnumerator]; MLKForm *form; Value *value = ConstantPointerNull::get (VoidPointerTy); + int i; + i = 0; while ((form = [e nextObject])) { - value = [form processForLLVM]; + i++; + if (i == [_bodyForms count]) + value = [form processForLLVMWithMultiValue:multiValue]; + else + value = [form processForLLVMWithMultiValue:NULL]; } return value; @@ -459,7 +465,7 @@ static Constant @implementation MLKSimpleLoopForm (MLKLLVMCompilation) --(Value *) reallyProcessForLLVM +-(Value *) reallyProcessForLLVMWithMultiValue:(Value *)multiValue { NSEnumerator *e = [_bodyForms objectEnumerator]; MLKForm *form; @@ -474,7 +480,7 @@ static Constant while ((form = [e nextObject])) { - [form processForLLVM]; + [form processForLLVMWithMultiValue:NULL]; } builder.CreateBr (loopBlock); @@ -489,7 +495,7 @@ static Constant @implementation MLKSymbolForm (MLKLLVMCompilation) --(Value *) reallyProcessForLLVM +-(Value *) reallyProcessForLLVMWithMultiValue:(Value *)multiValue { Value *value; @@ -537,7 +543,7 @@ static Constant @implementation MLKFunctionCallForm (MLKLLVMCompilation) --(Value *) reallyProcessForLLVM +-(Value *) reallyProcessForLLVMWithMultiValue:(Value *)multiValue { Value *functionPtr; Value *closureDataPtr; @@ -582,7 +588,7 @@ static Constant Value *code = builder.CreateLoad (codeptr, "closure_code"); Value *data = builder.CreateLoad (dataptr, "closure_data"); - std::vector types (1, PointerPointerTy); + std::vector types (2, PointerPointerTy); functionPtr = builder.CreateBitCast (code, PointerType::get(FunctionType::get(VoidPointerTy, types, true), @@ -594,13 +600,17 @@ static Constant //[_compiler insertPointerTrace:functionPtr]; args.push_back (closureDataPtr); + if (multiValue) + args.push_back (multiValue); + else + args.push_back (ConstantPointerNull::get (PointerPointerTy)); NSEnumerator *e = [_argumentForms objectEnumerator]; MLKForm *form; while ((form = [e nextObject])) { - args.push_back ([form processForLLVM]); + args.push_back ([form processForLLVMWithMultiValue:NULL]); } //GlobalVariable *endmarker = module->getGlobalVariable ("MLKEndOfArgumentsMarker", false); @@ -649,7 +659,7 @@ build_simple_function_definition (MLKBodyForm *processed_form, MLKLexicalContext *_context = [processed_form context]; id _compiler = [MLKLLVMCompiler class]; - vector argtypes (1, PointerPointerTy); + vector argtypes (2, PointerPointerTy); FunctionType *ftype = FunctionType::get (VoidPointerTy, argtypes, true); function = Function::Create (ftype, Function::InternalLinkage, @@ -659,6 +669,9 @@ build_simple_function_definition (MLKBodyForm *processed_form, Function::arg_iterator args = function->arg_begin(); Value *closure_data_arg = args++; closure_data_arg->setName ("closure_data"); + + Value *functionMultiValue = args++; + functionMultiValue->setName ("function_multiple_value_return_pointer"); BasicBlock *outerBlock = builder.GetInsertBlock (); BasicBlock *initBlock = BasicBlock::Create ("init_function", function); @@ -803,10 +816,14 @@ build_simple_function_definition (MLKBodyForm *processed_form, value = ConstantPointerNull::get (VoidPointerTy); } + i = 0; while ((form = [e nextObject])) { - //NSLog (@"%LAMBDA: Processing subform."); - value = [form processForLLVM]; + i++; + if (i == [_bodyForms count]) + value = [form processForLLVMWithMultiValue:functionMultiValue]; + else + value = [form processForLLVMWithMultiValue:NULL]; } builder.CreateRet (value); @@ -830,7 +847,7 @@ build_simple_function_definition (MLKBodyForm *processed_form, @implementation MLKSimpleLambdaForm (MLKLLVMCompilation) --(Value *) reallyProcessForLLVM +-(Value *) reallyProcessForLLVMWithMultiValue:(Value *)multiValue { intptr_t closure_data_size; Function *function; @@ -858,7 +875,7 @@ build_simple_function_definition (MLKBodyForm *processed_form, @implementation MLKLetForm (MLKLLVMCompilation) --(Value *) reallyProcessForLLVM +-(Value *) reallyProcessForLLVMWithMultiValue:(Value *)multiValue { NSEnumerator *e = [_variableBindingForms objectEnumerator]; Value *value = ConstantPointerNull::get (VoidPointerTy); @@ -867,7 +884,7 @@ build_simple_function_definition (MLKBodyForm *processed_form, while ((binding_form = [e nextObject])) { - Value *binding_value = [[binding_form valueForm] processForLLVM]; + Value *binding_value = [[binding_form valueForm] processForLLVMWithMultiValue:NULL]; if ([_bodyContext variableHeapAllocationForSymbol:[binding_form name]]) { @@ -892,10 +909,15 @@ build_simple_function_definition (MLKBodyForm *processed_form, } } + int i = 0; e = [_bodyForms objectEnumerator]; while ((form = [e nextObject])) { - value = [form processForLLVM]; + i++; + if (i == [_bodyForms count]) + value = [form processForLLVMWithMultiValue:multiValue]; + else + value = [form processForLLVMWithMultiValue:NULL]; } return value; @@ -904,12 +926,13 @@ build_simple_function_definition (MLKBodyForm *processed_form, @implementation MLKSimpleFletForm (MLKLLVMCompilation) --(Value *) reallyProcessForLLVM +-(Value *) reallyProcessForLLVMWithMultiValue:(Value *)multiValue { NSEnumerator *e = [_functionBindingForms objectEnumerator]; Value *value = ConstantPointerNull::get (VoidPointerTy); MLKForm *form; MLKSimpleFunctionBindingForm *binding_form; + unsigned int i; while ((binding_form = [e nextObject])) { @@ -943,11 +966,16 @@ build_simple_function_definition (MLKBodyForm *processed_form, [_bodyContext setFunctionBindingValue:binding forSymbol:[binding_form name]]; } - + + i = 0; e = [_bodyForms objectEnumerator]; while ((form = [e nextObject])) { - value = [form processForLLVM]; + i++; + if (i == [_bodyForms count]) + value = [form processForLLVMWithMultiValue:multiValue]; + else + value = [form processForLLVMWithMultiValue:NULL]; } return value; @@ -956,7 +984,7 @@ build_simple_function_definition (MLKBodyForm *processed_form, @implementation MLKQuoteForm (MLKLLVMCompilation) --(Value *) reallyProcessForLLVM +-(Value *) reallyProcessForLLVMWithMultiValue:(Value *)multiValue { // FIXME: When to release _quotedData? At the same time the code is // released, probably... @@ -977,7 +1005,7 @@ build_simple_function_definition (MLKBodyForm *processed_form, @implementation MLKSelfEvaluatingForm (MLKLLVMCompilation) --(Value *) reallyProcessForLLVM +-(Value *) reallyProcessForLLVMWithMultiValue:(Value *)multiValue { // FIXME: When to release _form? At the same time the code is // released, probably... @@ -998,25 +1026,25 @@ build_simple_function_definition (MLKBodyForm *processed_form, @implementation MLKIfForm (MLKLLVMCompilation) --(Value *) reallyProcessForLLVM +-(Value *) reallyProcessForLLVMWithMultiValue:(Value *)multiValue { Function *function = builder.GetInsertBlock()->getParent(); BasicBlock *thenBlock = BasicBlock::Create ("if_then", function); BasicBlock *elseBlock = BasicBlock::Create ("if_else"); BasicBlock *joinBlock = BasicBlock::Create ("if_join"); - Value *test = builder.CreateICmpNE ([_conditionForm processForLLVM], + Value *test = builder.CreateICmpNE ([_conditionForm processForLLVMWithMultiValue:NULL], ConstantPointerNull::get (VoidPointerTy)); Value *value = builder.CreateAlloca (VoidPointerTy, NULL, "if_result"); builder.CreateCondBr (test, thenBlock, elseBlock); builder.SetInsertPoint (thenBlock); - builder.CreateStore ([_consequentForm processForLLVM], value); + builder.CreateStore ([_consequentForm processForLLVMWithMultiValue:multiValue], value); builder.CreateBr (joinBlock); builder.SetInsertPoint (elseBlock); function->getBasicBlockList().push_back (elseBlock); - builder.CreateStore ([_alternativeForm processForLLVM], value); + builder.CreateStore ([_alternativeForm processForLLVMWithMultiValue:multiValue], value); builder.CreateBr (joinBlock); builder.SetInsertPoint (joinBlock); @@ -1028,7 +1056,7 @@ build_simple_function_definition (MLKBodyForm *processed_form, @implementation MLKSetQForm (MLKLLVMCompilation) --(Value *) reallyProcessForLLVM +-(Value *) reallyProcessForLLVMWithMultiValue:(Value *)multiValue { NSEnumerator *var_e, *value_e; MLKForm *valueForm; @@ -1040,7 +1068,7 @@ build_simple_function_definition (MLKBodyForm *processed_form, while ((valueForm = [value_e nextObject])) { variable = [var_e nextObject]; - value = [valueForm processForLLVM]; + value = [valueForm processForLLVMWithMultiValue:NULL]; if (![_context variableIsLexical:variable]) { Value *mlkdynamiccontext = [_compiler insertClassLookup:@"MLKDynamicContext"]; @@ -1127,7 +1155,7 @@ build_simple_function_definition (MLKBodyForm *processed_form, @implementation MLKInPackageForm (MLKLLVMCompilation) --(Value *) reallyProcessForLLVM +-(Value *) reallyProcessForLLVMWithMultiValue:(Value *)multiValue { id package = [MLKPackage findPackage:stringify(_packageDesignator)]; @@ -1145,7 +1173,7 @@ build_simple_function_definition (MLKBodyForm *processed_form, @implementation MLKSimpleFunctionForm (MLKLLVMCompilation) --(Value *) reallyProcessForLLVM +-(Value *) reallyProcessForLLVMWithMultiValue:(Value *)multiValue { if ([_context functionIsGlobal:_functionName]) { @@ -1184,8 +1212,8 @@ build_simple_function_definition (MLKBodyForm *processed_form, @implementation MLKLambdaFunctionForm (MLKLLVMCompilation) --(Value *) reallyProcessForLLVM +-(Value *) reallyProcessForLLVMWithMultiValue:(Value *)multiValue { - return [_lambdaForm processForLLVM]; + return [_lambdaForm processForLLVMWithMultiValue:multiValue]; } @end \ No newline at end of file diff --git a/MLKLexicalContext-MLKLLVMCompilation.mm b/MLKLexicalContext-MLKLLVMCompilation.mm index b387f62..b2d95ea 100644 --- a/MLKLexicalContext-MLKLLVMCompilation.mm +++ b/MLKLexicalContext-MLKLLVMCompilation.mm @@ -55,7 +55,7 @@ id MLKDummyUseLLVMLexicalContext = nil; -(Instruction *) functionCellValueForSymbol:(id)name { - std::vector types (1, PointerType::get(PointerType::get(Type::Int8Ty, 0), 0)); + std::vector types (2, PointerType::get(PointerType::get(Type::Int8Ty, 0), 0)); return (new IntToPtrInst (ConstantInt::get(Type::Int64Ty, (uint64_t)[self functionCellForSymbol:name], false), diff --git a/MLKRoot.m b/MLKRoot.m index 7eb9f14..5bbabdf 100644 --- a/MLKRoot.m +++ b/MLKRoot.m @@ -63,39 +63,39 @@ static id truify (BOOL value) static id -car (id *_data, id cons, id _marker) +car (id *_data, id *_multireturn, id cons, id _marker) { return [cons car]; } static id -cdr (id *_data, id cons, id _marker) +cdr (id *_data, id *_multireturn, id cons, id _marker) { return [cons cdr]; } static id -rplaca (id *_data, id cons, id value, id _marker) +rplaca (id *_data, id *_multireturn, id cons, id value, id _marker) { [cons setCar:value]; return cons; } static id -rplacd (id *_data, id cons, id value, id _marker) +rplacd (id *_data, id *_multireturn, id cons, id value, id _marker) { [cons setCdr:value]; return cons; } static id -cons (id *_data, id car, id cdr, id _marker) +cons (id *_data, id *_multireturn, id car, id cdr, id _marker) { return [MLKCons cons:car with:cdr]; } static id -load (id *_data, NSString *fileName, id _marker) +load (id *_data, id *_multireturn, NSString *fileName, id _marker) { BOOL success; int l, i; @@ -161,22 +161,22 @@ load (id *_data, NSString *fileName, id _marker) } static id -require (id *_data, id moduleName, id _marker) +require (id *_data, id *_multireturn, id moduleName, id _marker) { NSBundle *toiletKit = [NSBundle bundleForClass:[MLKRoot class]]; NSString *path = [[toiletKit resourcePath] stringByAppendingPathComponent:stringify(moduleName)]; - return load (NULL, path, MLKEndOfArgumentsMarker); + return load (NULL, _multireturn, path, MLKEndOfArgumentsMarker); } static id -eq (id *_data, id x, id y, id _marker) +eq (id *_data, id *_multireturn, id x, id y, id _marker) { return truify (x == y); } static id -fixnum_eq (id *_data, id x, id y, id _marker) +fixnum_eq (id *_data, id *_multireturn, id x, id y, id _marker) { #ifdef NO_FIXNUMS return truify ([x isEqual:y]); @@ -186,95 +186,95 @@ fixnum_eq (id *_data, id x, id y, id _marker) } static id -symbolp (id *_data, id arg0, id _marker) +symbolp (id *_data, id *_multireturn, id arg0, id _marker) { return truify (MLKInstanceP(arg0) && (!arg0 || [arg0 isKindOfClass:[MLKSymbol class]])); } static id -listp (id *_data, id arg0, id _marker) +listp (id *_data, id *_multireturn, id arg0, id _marker) { return truify (MLKInstanceP(arg0) && (!arg0 || [arg0 isKindOfClass:[MLKCons class]])); } static id -consp (id *_data, id arg0, id _marker) +consp (id *_data, id *_multireturn, id arg0, id _marker) { return truify (MLKInstanceP(arg0) && [arg0 isKindOfClass:[MLKCons class]]); } static id -atom (id *_data, id arg0, id _marker) +atom (id *_data, id *_multireturn, id arg0, id _marker) { return truify (!MLKInstanceP(arg0) || ![arg0 isKindOfClass:[MLKCons class]]); } static id -null (id *_data, id arg0, id _marker) +null (id *_data, id *_multireturn, id arg0, id _marker) { return truify (!arg0); } static id -fixnump (id *_data, id arg0, id _marker) +fixnump (id *_data, id *_multireturn, id arg0, id _marker) { return truify (MLKFixnumP(arg0)); } static id -add (id *_data, MLKNumber *x, MLKNumber *y, id _marker) +add (id *_data, id *_multireturn, MLKNumber *x, MLKNumber *y, id _marker) { return [nullify(x) add:nullify(y)]; } static id -subtract (id *_data, MLKNumber *x, MLKNumber *y, id _marker) +subtract (id *_data, id *_multireturn, MLKNumber *x, MLKNumber *y, id _marker) { return [nullify(x) subtract:nullify(y)]; } static id -multiply (id *_data, MLKNumber *x, MLKNumber *y, id _marker) +multiply (id *_data, id *_multireturn, MLKNumber *x, MLKNumber *y, id _marker) { return [nullify(x) multiplyWith:nullify(y)]; } static id -divide (id *_data, MLKNumber *x, MLKNumber *y, id _marker) +divide (id *_data, id *_multireturn, MLKNumber *x, MLKNumber *y, id _marker) { return [nullify(x) divideBy:nullify(y)]; } static id -add_fixnums (id *_data, id x, id y, id _marker) +add_fixnums (id *_data, id *_multireturn, id x, id y, id _marker) { return MLKAddFixnums (x, y); } static id -subtract_fixnums (id *_data, id x, id y, id _marker) +subtract_fixnums (id *_data, id *_multireturn, id x, id y, id _marker) { return MLKSubtractFixnums (x, y); } static id -idivide_fixnums (id *_data, id x, id y, id _marker) +idivide_fixnums (id *_data, id *_multireturn, id x, id y, id _marker) { return MLKIDivideFixnums (x, y); } static id -multiply_fixnums (id *_data, id x, id y, id _marker) +multiply_fixnums (id *_data, id *_multireturn, id x, id y, id _marker) { return MLKMultiplyFixnums (x, y); } static id -list (id *_data, ...) +list (id *_data, id *_multireturn, ...) { id arg; va_list ap; @@ -282,7 +282,7 @@ list (id *_data, ...) cons = nil; tail = nil; - va_start (ap, _data); + va_start (ap, _multireturn); while ((arg = va_arg(ap, id)) != MLKEndOfArgumentsMarker) { @@ -308,7 +308,7 @@ list (id *_data, ...) : (id)({ id __tmp = ARG; ARG = va_arg(AP, id); __tmp; })) static id -macroexpand_1 (id *_data, id form, id arg, ...) +macroexpand_1 (id *_data, id *_multireturn, id form, id arg, ...) { va_list ap; @@ -341,7 +341,7 @@ macroexpand_1 (id *_data, id form, id arg, ...) } static id -shadow_ (id *_data, id symbols, id arg, ...) +shadow_ (id *_data, id *_multireturn, id symbols, id arg, ...) { va_list ap; @@ -365,7 +365,7 @@ shadow_ (id *_data, id symbols, id arg, ...) } static id -export (id *_data, id symbols, id arg, ...) +export (id *_data, id *_multireturn, id symbols, id arg, ...) { va_list ap; @@ -389,7 +389,7 @@ export (id *_data, id symbols, id arg, ...) } static id -unexport (id *_data, id symbols, id arg, ...) +unexport (id *_data, id *_multireturn, id symbols, id arg, ...) { va_list ap; @@ -413,7 +413,7 @@ unexport (id *_data, id symbols, id arg, ...) } static id -find_package (id *_data, id name, id _marker) +find_package (id *_data, id *_multireturn, id name, id _marker) { MLKPackage *package = [MLKPackage findPackage:stringify(name)]; @@ -431,13 +431,13 @@ find_package (id *_data, id name, id _marker) } static id -string (id *_data, id x, id _marker) +string (id *_data, id *_multireturn, id x, id _marker) { return stringify (x); } static id -gensym (id *_data, id arg, ...) +gensym (id *_data, id *_multireturn, id arg, ...) { va_list ap; @@ -479,13 +479,13 @@ gensym (id *_data, id arg, ...) } static id -make_symbol (id *_data, id name, id _marker) +make_symbol (id *_data, id *_multireturn, id name, id _marker) { return [MLKSymbol symbolWithName:name package:nil]; } static id -intern (id *_data, id name, id arg, ...) +intern (id *_data, id *_multireturn, id name, id arg, ...) { va_list ap; @@ -500,7 +500,7 @@ intern (id *_data, id name, id arg, ...) } static id -import (id *_data, id symbol, id arg, ...) +import (id *_data, id *_multireturn, id symbol, id arg, ...) { va_list ap; @@ -517,25 +517,25 @@ import (id *_data, id symbol, id arg, ...) } static id -objc_class_of (id *_data, id x, id _marker) +objc_class_of (id *_data, id *_multireturn, id x, id _marker) { return [x class]; } static id -objc_subclassp (id *_data, id x, id y, id _marker) +objc_subclassp (id *_data, id *_multireturn, id x, id y, id _marker) { return truify ([x isSubclassOfClass:y]); } static id -find_objc_class (id *_data, id x, id _marker) +find_objc_class (id *_data, id *_multireturn, id x, id _marker) { return NSClassFromString (x); } static id -ns_log (id *_data, id x, id _marker) +ns_log (id *_data, id *_multireturn, id x, id _marker) { NSString *description = MLKPrintToString(x); NSLog (@"%@", description); @@ -543,13 +543,13 @@ ns_log (id *_data, id x, id _marker) } static id -symbol_name (id *_data, id symbol, id _marker) +symbol_name (id *_data, id *_multireturn, id symbol, id _marker) { return (symbol ? (id)[symbol name] : (id)@"NIL"); } static id -primitive_type_of (id *_data, id object, id _marker) +primitive_type_of (id *_data, id *_multireturn, id object, id _marker) { if (!object) { return [cl intern:@"NULL"]; } @@ -589,7 +589,7 @@ primitive_type_of (id *_data, id object, id _marker) } static id -send_by_name (id *_data, id object, NSString *methodName, id arg, ...) +send_by_name (id *_data, id *_multireturn, id object, NSString *methodName, id arg, ...) { NSInvocation *invocation; SEL selector; @@ -670,7 +670,7 @@ as provided by method %@ of object %@", static id -declarations_and_doc_and_forms (id *_data, id bodyAndDecls, id _marker) +declarations_and_doc_and_forms (id *_data, id *_multireturn, id bodyAndDecls, id _marker) { id decls, doc, forms; @@ -683,7 +683,7 @@ declarations_and_doc_and_forms (id *_data, id bodyAndDecls, id _marker) static id -declarations_and_forms (id *_data, id bodyAndDecls, id _marker) +declarations_and_forms (id *_data, id *_multireturn, id bodyAndDecls, id _marker) { id decls, doc, forms; @@ -694,7 +694,7 @@ declarations_and_forms (id *_data, id bodyAndDecls, id _marker) } static id -compile (id *_data, id object, id _marker) +compile (id *_data, id *_multireturn, id object, id _marker) { if (!MLKDefaultCompiler) [NSException raise:@"MLKNotImplementedException" @@ -709,7 +709,7 @@ compile (id *_data, id object, id _marker) } static id -fset (id *_data, id symbol, id value, id _marker) +fset (id *_data, id *_multireturn, id symbol, id value, id _marker) { [[MLKLexicalContext globalContext] addFunction:symbol]; [[MLKLexicalEnvironment globalEnvironment] addFunction:value @@ -719,7 +719,7 @@ fset (id *_data, id symbol, id value, id _marker) } static id -set (id *_data, id symbol, id value, id _marker) +set (id *_data, id *_multireturn, id symbol, id value, id _marker) { MLKDynamicContext *dynamicContext = [MLKDynamicContext currentContext]; @@ -733,7 +733,7 @@ set (id *_data, id symbol, id value, id _marker) } static id -macroset (id *_data, id symbol, id value, id _marker) +macroset (id *_data, id *_multireturn, id symbol, id value, id _marker) { [[MLKLexicalContext globalContext] addMacro:value forSymbol:symbol]; @@ -742,7 +742,7 @@ macroset (id *_data, id symbol, id value, id _marker) } static id -apply (id *_data, id function, id arglist, id _marker) +apply (id *_data, id *_multireturn, id function, id arglist, id _marker) { // FIXME: Multiple values. @@ -760,7 +760,7 @@ apply (id *_data, id function, id arglist, id _marker) } static id -eval (id *_data, id evaluand, id _marker) +eval (id *_data, id *_multireturn, id evaluand, id _marker) { // FIXME: Multiple values. -- cgit v1.2.3 From 2009d6d234c6bdc871109cf6b35c3ac2070f8d11 Mon Sep 17 00:00:00 2001 From: Matthias Benkard Date: Thu, 2 Oct 2008 16:36:14 +0200 Subject: Interpreter: Implement MULTIPLE-VALUE-LIST instead of MULTIPLE-VALUE-CALL. --- MLKForm.h | 4 ++-- MLKForm.m | 15 +++++++-------- MLKInterpreter.m | 15 +++------------ control-flow.lisp | 8 ++++++-- special-symbols.h | 4 ++-- 5 files changed, 20 insertions(+), 26 deletions(-) diff --git a/MLKForm.h b/MLKForm.h index 60b5428..ff48e98 100644 --- a/MLKForm.h +++ b/MLKForm.h @@ -238,9 +238,9 @@ @end -@interface MLKMultipleValueCallForm : MLKBodyForm +@interface MLKMultipleValueListForm : MLKCompoundForm { - MLKForm *_functionForm; + MLKForm *_listForm; } @end diff --git a/MLKForm.m b/MLKForm.m index 30ae6ee..8e8bf02 100644 --- a/MLKForm.m +++ b/MLKForm.m @@ -185,7 +185,7 @@ else if (car == _FLET) return [MLKSimpleFletForm class]; else if (car == LET) return [MLKLetForm class]; else if (car == _LOOP) return [MLKSimpleLoopForm class]; - else if (car == MULTIPLE_VALUE_CALL) return [MLKMultipleValueCallForm class]; + else if (car == MULTIPLE_VALUE_LIST) return [MLKMultipleValueListForm class]; else if (car == PROGN) return [MLKProgNForm class]; else if (car == PROGV) return [MLKProgVForm class]; else if (car == QUOTE) return [MLKQuoteForm class]; @@ -898,25 +898,24 @@ @end -@implementation MLKMultipleValueCallForm +@implementation MLKMultipleValueListForm -(id) complete { self = [super complete]; - LASSIGN (_functionForm, [MLKForm formWithObject:[_tail car] - inContext:_context - forCompiler:_compiler]); - [self processBody:[_tail cdr]]; + LASSIGN (_listForm, [MLKForm formWithObject:[_tail car] + inContext:_context + forCompiler:_compiler]); return self; } -(NSArray *) subforms { - return [[super subforms] arrayByAddingObject:_functionForm]; + return [[super subforms] arrayByAddingObject:_listForm]; } -(void) dealloc { - LDESTROY (_functionForm); + LDESTROY (_listForm); [super dealloc]; } @end diff --git a/MLKInterpreter.m b/MLKInterpreter.m index 027e2f7..e7e95ba 100644 --- a/MLKInterpreter.m +++ b/MLKInterpreter.m @@ -473,20 +473,11 @@ PRIMARY (NSArray *array) @end -@implementation MLKMultipleValueCallForm (MLKInterpretation) +@implementation MLKMultipleValueListForm (MLKInterpretation) -(NSArray *) reallyInterpretWithEnvironment:(MLKLexicalEnvironment *)env { - NSMutableArray *results = [NSMutableArray array]; - int i; - id function = PRIMARY ([_functionForm interpretWithEnvironment:env]); - - for (i = 0; i < [_bodyForms count]; i++) - { - NSArray *values = [[_bodyForms objectAtIndex:i] interpretWithEnvironment:env]; - [results addObjectsFromArray:values]; - } - - return [function applyToArray:results]; + NSArray *results = [_listForm interpretWithEnvironment:env]; + return [NSArray arrayWithObject:[MLKCons listWithArray:results]]; } @end diff --git a/control-flow.lisp b/control-flow.lisp index bcd8e23..f429a1a 100644 --- a/control-flow.lisp +++ b/control-flow.lisp @@ -215,8 +215,12 @@ ,@body)) -(defmacro multiple-value-list (expression) - `(multiple-value-call #'list ,expression)) +(defmacro multiple-value-call (function-form &rest forms) + (let ((args `(mapcan 'identity (list ,@(mapcar (lambda (form) `(multiple-value-list ,form))))))) + `(apply ,function-form ,args))) + +;;(defmacro multiple-value-list (expression) +;; `(multiple-value-call #'list ,expression)) (defmacro multiple-value-bind ((&rest vars) expression &body forms) `(destructuring-bind ,vars (multiple-value-list ,expression) diff --git a/special-symbols.h b/special-symbols.h index 752e1e9..ebdcbb7 100644 --- a/special-symbols.h +++ b/special-symbols.h @@ -56,7 +56,7 @@ static MLKSymbol *COMPILE; static MLKSymbol *LOAD_TOPLEVEL; static MLKSymbol *LOAD; static MLKSymbol *EXECUTE; -static MLKSymbol *MULTIPLE_VALUE_CALL; +static MLKSymbol *MULTIPLE_VALUE_LIST; static MLKSymbol *INLINE; static MLKSymbol *NOTINLINE; static MLKSymbol *SPECIAL; @@ -106,7 +106,7 @@ ensure_symbols () _FOREIGN_LAMBDA = [sys intern:@"%FOREIGN-LAMBDA"]; _LAMBDA = [sys intern:@"%LAMBDA"]; V_INITP = [sys intern:@"*SYSTEM-INITIALISED-P*"]; - MULTIPLE_VALUE_CALL = [cl intern:@"MULTIPLE-VALUE-CALL"]; + MULTIPLE_VALUE_LIST = [cl intern:@"MULTIPLE-VALUE-LIST"]; INLINE = [cl intern:@"INLINE"]; NOTINLINE = [cl intern:@"NOTINLINE"]; SPECIAL = [cl intern:@"INLINE"]; -- cgit v1.2.3 From f805cbe8ac26baa444827e42e74a95bd473669a8 Mon Sep 17 00:00:00 2001 From: Matthias Benkard Date: Thu, 2 Oct 2008 16:36:48 +0200 Subject: LLVM compiler: Support MULTIPLE-VALUE-LIST. --- MLKLLVMCompiler.mm | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/MLKLLVMCompiler.mm b/MLKLLVMCompiler.mm index e463a65..2334f27 100644 --- a/MLKLLVMCompiler.mm +++ b/MLKLLVMCompiler.mm @@ -1216,4 +1216,50 @@ build_simple_function_definition (MLKBodyForm *processed_form, { return [_lambdaForm processForLLVMWithMultiValue:multiValue]; } -@end \ No newline at end of file +@end + + +@implementation MLKMultipleValueListForm (MLKLLVMCompilation) +-(Value *) reallyProcessForLLVMWithMultiValue:(Value *)multiValue +{ + Value *endmarker = builder.CreateIntToPtr (ConstantInt::get(Type::Int64Ty, + (uint64_t)MLKEndOfArgumentsMarker, + false), + VoidPointerTy); + Value *multi_tmp = builder.CreateAlloca (VoidPointerTy, NULL); + builder.CreateStore (endmarker, multi_tmp); + + Value *value = [_listForm processForLLVMWithMultiValue:multi_tmp]; + Value *return_value = builder.CreateAlloca (VoidPointerTy, NULL); + + Function *function = builder.GetInsertBlock()->getParent(); + BasicBlock *singleValueBlock = BasicBlock::Create ("single_value_block", function); + BasicBlock *multipleValueBlock = BasicBlock::Create ("multiple_value_block"); + BasicBlock *joinBlock = BasicBlock::Create ("join_block"); + + Value *multi_tmp_content = builder.CreateLoad (multi_tmp); + Value *isSingleValue = builder.CreateICmpEQ (multi_tmp_content, endmarker); + builder.CreateCondBr (isSingleValue, singleValueBlock, multipleValueBlock); + + builder.SetInsertPoint (singleValueBlock); + Value *mlkcons = [_compiler insertClassLookup:@"MLKCons"]; + vector argv; + argv.push_back (value); + argv.push_back (ConstantPointerNull::get (VoidPointerTy)); + Value *newList = [_compiler insertMethodCall:@"cons:with:" + onObject:mlkcons + withArgumentVector:&argv]; + builder.CreateStore (newList, return_value); + builder.CreateBr (joinBlock); + + function->getBasicBlockList().push_back (multipleValueBlock); + builder.SetInsertPoint (multipleValueBlock); + builder.CreateStore (multi_tmp_content, return_value); + builder.CreateBr (joinBlock); + + function->getBasicBlockList().push_back (joinBlock); + builder.SetInsertPoint (joinBlock); + + return builder.CreateLoad (return_value); +} +@end -- cgit v1.2.3 From a4a3054ddeeecbf7ec3b087b2db69bea192ebc8a Mon Sep 17 00:00:00 2001 From: Matthias Benkard Date: Thu, 2 Oct 2008 16:54:05 +0200 Subject: New journal entry. --- JOURNAL | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/JOURNAL b/JOURNAL index cf0c8d2..2417e33 100644 --- a/JOURNAL +++ b/JOURNAL @@ -18,6 +18,47 @@ Context: [[http://matthias.benkard.de/toilet][The Toilet Lisp Project]]. ---- +* 2008-10-02, 16:38:15 CEST + +** Multiple-Value Returns + +Multiple-value returns are now implemented in the most C-friendly way that I +can imagine. The way they work is: + + - Every compiled function gets an additional argument that points to a cell + which the caller has allocated. The cell may be set to point to a list + (i.e., either =nil= or an instance of =MLKCons=) by the callee, in which + case the caller will use the list as the list of return values. + + - The argument that points to the return value list cell may be =NULL=, in + which case the callee must assume a single-return convention. + + - Return-value setting may be delegated to a subform by simply passing the + pointer on. + + - The compiler always passes =NULL= as the list pointer when it neither uses + nor delegates the return values. + + - The compiler occasionally sets the =llvm:Value= that represents the list + pointer to =NULL=. It thereby communicates to itself that no + multiple-return value handling is needed in the current lexical context. + This should speed some things up. + + - A function implemented in C may choose to simply ignore the list pointer. + Similarly, it may choose to always pass a list pointer of =NULL= to callees + if it does not care about return values other than the primary one. + + - A function that does not return multiple values simply ignores the list + pointer, which is guaranteed to contain a value that the caller can + identify as signifying that no multiple-value return has occurred. + In the current implementation, this role is filled by the + =MLKEndOfArgumentsMarker=. + + - Regardless of multiple-value returns happening or not, the primary value of + a function call is always its normal return value. When there is no + primary value, =nil= is to be used. + + * 2008-08-11, 02:09:21 CEST ** Function Calling, 2nd Take -- cgit v1.2.3