summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--GNUmakefile17
-rw-r--r--MLKBinding.h42
-rw-r--r--MLKBinding.m85
3 files changed, 136 insertions, 8 deletions
diff --git a/GNUmakefile b/GNUmakefile
index 7d2eda3..31b6576 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -25,14 +25,15 @@ BUNDLE_NAME = Test
ADDITIONAL_OBJCFLAGS = -Wall
-ToiletKit_OBJC_FILES = MLKCharacter.m MLKCons.m MLKDoubleFloat.m \
- MLKDynamicContext.m MLKEndOfFileError.m \
- MLKEnvironment.m MLKError.m MLKFloat.m \
- MLKInteger.m MLKInterpreter.m MLKLinkedList.m \
- MLKLexicalContext.m MLKLexicalEnvironment.m \
- MLKLispValue.m MLKPackage.m MLKParenReader.m \
- MLKRatio.m MLKReader.m MLKReadtable.m \
- MLKReaderError.m MLKSingleFloat.m MLKStream.m \
+ToiletKit_OBJC_FILES = MLKCharacter.m MLKCons.m MLKBinding.m \
+ MLKDoubleFloat.m MLKDynamicContext.m \
+ MLKEndOfFileError.m MLKEnvironment.m MLKError.m \
+ MLKFloat.m MLKInteger.m MLKInterpreter.m \
+ MLKLinkedList.m MLKLexicalContext.m \
+ MLKLexicalEnvironment.m MLKLispValue.m \
+ MLKPackage.m MLKParenReader.m MLKRatio.m \
+ MLKReader.m MLKReadtable.m MLKReaderError.m \
+ MLKSingleFloat.m MLKStream.m \
MLKStringInputStream.m MLKSymbol.m \
MLKThrowException.m \
MLKUndefinedVariableException.m \
diff --git a/MLKBinding.h b/MLKBinding.h
new file mode 100644
index 0000000..8882200
--- /dev/null
+++ b/MLKBinding.h
@@ -0,0 +1,42 @@
+/* -*- mode: objc; coding: utf-8 -*- */
+/* Étoilisp/Mulklisp, 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 <Foundation/NSObject.h>
+
+
+@interface MLKBinding : NSObject
+{
+ id value;
+}
+
++(void) initialize;
+
+-(MLKBinding *) init;
+-(MLKBinding *) initWithValue:(id)something;
+
++(MLKBinding *) binding;
++(MLKBinding *) bindingWithValue:(id)something;
+
+-(void) setValue:(id)something;
+-(id) value;
+
+-(BOOL) boundp;
+-(void) makunbound;
+
+-(void) dealloc;
+@end
diff --git a/MLKBinding.m b/MLKBinding.m
new file mode 100644
index 0000000..b3e2826
--- /dev/null
+++ b/MLKBinding.m
@@ -0,0 +1,85 @@
+/* -*- mode: objc; coding: utf-8 -*- */
+/* Étoilisp/Mulklisp, 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 "MLKBinding.h"
+#import "runtime-compatibility.h"
+
+#import <Foundation/NSException.h>
+
+
+static id UNBOUND;
+
+
+@implementation MLKBinding
++(void) initialize
+{
+ UNBOUND = [[NSObject alloc] init];
+}
+
+-(MLKBinding *) init
+{
+ return [self initWithValue:UNBOUND];
+}
+
+-(MLKBinding *) initWithValue:(id)something
+{
+ self = [super init];
+ ASSIGN (value, something);
+ return self;
+}
+
++(MLKBinding *) binding
+{
+ return AUTORELEASE ([[self alloc] init]);
+}
+
++(MLKBinding *) bindingWithValue:(id)something
+{
+ return AUTORELEASE ([[self alloc] initWithValue:something]);
+}
+
+-(void) setValue:(id)something
+{
+ ASSIGN (value, something);
+}
+
+-(id) value
+{
+ if (value == UNBOUND)
+ [NSException raise:@"MLKUnboundVariableError"
+ format:@""];
+
+ return value;
+}
+
+-(BOOL) boundp
+{
+ return !(value == UNBOUND);
+}
+
+-(void) makunbound
+{
+ ASSIGN (value, UNBOUND);
+}
+
+-(void) dealloc
+{
+ RELEASE (value);
+ [super dealloc];
+}
+@end