summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Benkard <mulk@minimulk.mst-plus>2008-09-20 13:44:25 +0200
committerMatthias Benkard <mulk@minimulk.mst-plus>2008-09-20 13:44:25 +0200
commit7e5a799a46f6aca1525efa2df38026a1917f3edd (patch)
treeef4a7a50300e07643a863b501f60115cf724bf1d
parent5dc8e497315ba791c8a8de021f3d2d292566fb56 (diff)
Add class MLKContinuation.
-rw-r--r--GNUmakefile1
-rw-r--r--MLKContinuation.h37
-rw-r--r--MLKContinuation.m55
-rw-r--r--Toilet Lisp.xcodeproj/project.pbxproj8
-rw-r--r--globals.h2
-rw-r--r--globals.m4
6 files changed, 106 insertions, 1 deletions
diff --git a/GNUmakefile b/GNUmakefile
index 41d8fb1..8ed21d7 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -65,6 +65,7 @@ ToiletKit_OBJC_FILES = functions.m globals.m MLKArray.m \
MLKBinaryStreamCharacterStream.m MLKBinding.m \
MLKCharacter.m MLKCharacterStream.m \
MLKCommaReader.m MLKCompiledClosure.m MLKCons.m \
+ MLKContinuation.m \
MLKDoubleFloat.m \
MLKDispatchingMacroCharacterReader.m \
MLKDynamicContext.m MLKEnvironment.m \
diff --git a/MLKContinuation.h b/MLKContinuation.h
new file mode 100644
index 0000000..ca97f61
--- /dev/null
+++ b/MLKContinuation.h
@@ -0,0 +1,37 @@
+/* -*- mode: objc; coding: utf-8 -*- */
+/* Toilet Lisp, a Common Lisp subset for the Étoilé runtime.
+ * Copyright (C) 2008 Matthias Andreas Benkard.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#import "MLKFuncallable.h"
+#import "SCM/continue.h"
+
+#import <Foundation/Foundation.h>
+
+
+@interface MLKContinuation : NSObject <MLKFuncallable>
+{
+ CONTINUATION *_continuation;
+}
+
+- (id)init;
++ (id)continuation;
++ (NSArray *)callWithCurrentContinuation:(id <MLKFuncallable>)function;
+
+- (NSArray *)applyToArray:(NSArray *)arguments;
+
+- (void)dealloc;
+@end
diff --git a/MLKContinuation.m b/MLKContinuation.m
new file mode 100644
index 0000000..e253370
--- /dev/null
+++ b/MLKContinuation.m
@@ -0,0 +1,55 @@
+/* -*- mode: objc; coding: utf-8 -*- */
+/* Toilet Lisp, a Common Lisp subset for the Étoilé runtime.
+ * Copyright (C) 2008 Matthias Andreas Benkard.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#import "MLKContinuation.h"
+#import "globals.h"
+#import "util.h"
+
+
+@implementation MLKContinuation
+- (id)init
+{
+ self = [super init];
+ _continuation = make_continuation (MLKRootContinuation);
+ setjump (_continuation->jmpbuf);
+}
+
++ (id)continuation
+{
+ return LAUTORELEASE ([[self alloc] init]);
+}
+
++ (NSArray *)callWithCurrentContinuation:(id <MLKFuncallable>)function
+{
+ id cont = [self continuation];
+ return [function applyToArray:[NSArray arrayWithObject:cont]];
+}
+
+- (NSArray *)applyToArray:(NSArray *)arguments
+{
+ throw_to_continuation (_continuation, (long)arguments, MLKRootContinuation);
+ return nil;
+}
+
+- (void)dealloc
+{
+ // ... _continuation->other ... (only if CONTINUATION_OTHER is defined in scmflags.h)
+ free_continuation (_continuation);
+ [super dealloc];
+}
+@end
diff --git a/Toilet Lisp.xcodeproj/project.pbxproj b/Toilet Lisp.xcodeproj/project.pbxproj
index 59d2770..1f79085 100644
--- a/Toilet Lisp.xcodeproj/project.pbxproj
+++ b/Toilet Lisp.xcodeproj/project.pbxproj
@@ -173,6 +173,8 @@
A7E5C4A10E216C0F00A01D81 /* MLKNumber.m in Sources */ = {isa = PBXBuildFile; fileRef = A7E5C49F0E216C0F00A01D81 /* MLKNumber.m */; };
A7E5C55C0E21740C00A01D81 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7E5C55B0E21740C00A01D81 /* Foundation.framework */; };
A7E5C55D0E21740C00A01D81 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7E5C55B0E21740C00A01D81 /* Foundation.framework */; };
+ A7EE013F0E850E010024E903 /* MLKContinuation.h in Headers */ = {isa = PBXBuildFile; fileRef = A7EE013D0E850E010024E903 /* MLKContinuation.h */; };
+ A7EE01400E850E010024E903 /* MLKContinuation.m in Sources */ = {isa = PBXBuildFile; fileRef = A7EE013E0E850E010024E903 /* MLKContinuation.m */; };
A7EEFFD30E84FF650024E903 /* continue.c in Sources */ = {isa = PBXBuildFile; fileRef = A7EEFFD20E84FF650024E903 /* continue.c */; };
A7EEFFD90E84FF7C0024E903 /* continue.h in Headers */ = {isa = PBXBuildFile; fileRef = A7EEFFD40E84FF7C0024E903 /* continue.h */; };
A7EEFFDA0E84FF7C0024E903 /* scm.h in Headers */ = {isa = PBXBuildFile; fileRef = A7EEFFD50E84FF7C0024E903 /* scm.h */; };
@@ -464,6 +466,8 @@
A7E5C49E0E216C0F00A01D81 /* MLKNumber.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MLKNumber.h; sourceTree = "<group>"; };
A7E5C49F0E216C0F00A01D81 /* MLKNumber.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MLKNumber.m; sourceTree = "<group>"; };
A7E5C55B0E21740C00A01D81 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
+ A7EE013D0E850E010024E903 /* MLKContinuation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MLKContinuation.h; sourceTree = "<group>"; };
+ A7EE013E0E850E010024E903 /* MLKContinuation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MLKContinuation.m; sourceTree = "<group>"; };
A7EEFFD20E84FF650024E903 /* continue.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = continue.c; path = SCM/continue.c; sourceTree = "<group>"; };
A7EEFFD40E84FF7C0024E903 /* continue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = continue.h; path = SCM/continue.h; sourceTree = "<group>"; };
A7EEFFD50E84FF7C0024E903 /* scm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = scm.h; path = SCM/scm.h; sourceTree = "<group>"; };
@@ -751,6 +755,8 @@
A7E5C4390E21695800A01D81 /* NSObject-MLKPrinting.m */,
A7E5C43B0E21695800A01D81 /* NSString-MLKPrinting.m */,
A72BC70A0E65EA1100486804 /* MLKListenerController.m */,
+ A7EE013D0E850E010024E903 /* MLKContinuation.h */,
+ A7EE013E0E850E010024E903 /* MLKContinuation.m */,
);
name = "Source Files";
sourceTree = "<group>";
@@ -831,6 +837,7 @@
A7EEFFDB0E84FF7C0024E903 /* scmfig.h in Headers */,
A7EEFFDC0E84FF7C0024E903 /* scmflags.h in Headers */,
A7EEFFDD0E84FF7C0024E903 /* setjump.h in Headers */,
+ A7EE013F0E850E010024E903 /* MLKContinuation.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1043,6 +1050,7 @@
A7A862970E6E776000021916 /* MLKUnboundVariableError.m in Sources */,
A7EEFFD30E84FF650024E903 /* continue.c in Sources */,
A7EEFFED0E85025A0024E903 /* toilet-scm.c in Sources */,
+ A7EE01400E850E010024E903 /* MLKContinuation.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/globals.h b/globals.h
index 3dbda38..bd7ca5e 100644
--- a/globals.h
+++ b/globals.h
@@ -17,9 +17,11 @@
*/
#import <Foundation/NSObject.h>
+#import "SCM/continue.h"
extern id MLKEndOfArgumentsMarker;
+extern CONTINUATION *MLKRootContinuation;
extern id MLKDefaultCompiler;
extern BOOL MLKLoadCompilesP;
diff --git a/globals.m b/globals.m
index 8781620..e97ff56 100644
--- a/globals.m
+++ b/globals.m
@@ -20,8 +20,8 @@
#import <Foundation/NSObject.h>
-
id MLKEndOfArgumentsMarker;
+CONTINUATION *MLKRootContinuation;
id MLKDefaultCompiler = nil;
BOOL MLKLoadCompilesP = NO;
@@ -34,6 +34,8 @@ BOOL MLKLoadCompilesP = NO;
@implementation MLKGlobalManager
+(void) load
{
+ STACKITEM i;
MLKEndOfArgumentsMarker = [[NSObject alloc] init];
+ MLKRootContinuation = make_root_continuation (&i);
}
@end