summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--GNUmakefile3
-rw-r--r--MLKDynamicContext.m24
-rw-r--r--MLKFileHandleStream.h35
-rw-r--r--MLKFileHandleStream.m78
-rw-r--r--MLKStreamStream.h2
5 files changed, 136 insertions, 6 deletions
diff --git a/GNUmakefile b/GNUmakefile
index 7aaa0f0..1990162 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -67,7 +67,8 @@ ToiletKit_OBJC_FILES = functions.m globals.m MLKArray.m \
MLKCommaReader.m MLKCompiledClosure.m MLKCons.m \
MLKDoubleFloat.m \
MLKDispatchingMacroCharacterReader.m \
- MLKDynamicContext.m MLKEnvironment.m MLKFloat.m \
+ MLKDynamicContext.m MLKEnvironment.m \
+ MLKFileHandleStream.m MLKFloat.m \
MLKForeignProcedure.m MLKForm.m MLKInteger.m \
MLKInterpretedClosure.m MLKInterpreter.m \
MLKLexicalContext.m MLKLexicalEnvironment.m \
diff --git a/MLKDynamicContext.m b/MLKDynamicContext.m
index 015af47..70979cf 100644
--- a/MLKDynamicContext.m
+++ b/MLKDynamicContext.m
@@ -25,11 +25,14 @@
#import <Foundation/NSThread.h>
#import "MLKBackquoteReader.h"
+#import "MLKBinaryStreamCharacterStream.h"
+#import "MLKCharacterStream.h"
#import "MLKCommaReader.h"
#import "MLKCons.h"
#import "MLKDispatchingMacroCharacterReader.h"
#import "MLKDynamicContext.h"
#import "MLKEnvironment.h"
+#import "MLKFileHandleStream.h"
#import "MLKPackage.h"
#import "MLKParenReader.h"
#import "MLKQuoteReader.h"
@@ -213,6 +216,21 @@ static MLKDynamicContext *global_context;
// FIXME: Initialise stuff.
#define INIT(VARNAME, VALUE) [vars setObject:VALUE forKey:[cl intern:VARNAME]]
+ MLKFileHandleStream *ferrstream, *foutstream;
+ MLKCharacterStream *errstream, *outstream;
+ ferrstream = [[MLKFileHandleStream alloc]
+ initWithFileHandle:[NSFileHandle fileHandleWithStandardError]];
+ foutstream = [[MLKFileHandleStream alloc]
+ initWithFileHandle:[NSFileHandle fileHandleWithStandardOutput]];
+ errstream = [[MLKBinaryStreamCharacterStream alloc]
+ initWithBinaryStream:ferrstream];
+ outstream = [[MLKBinaryStreamCharacterStream alloc]
+ initWithBinaryStream:foutstream];
+ LAUTORELEASE (ferrstream);
+ LAUTORELEASE (foutstream);
+ LAUTORELEASE (errstream);
+ LAUTORELEASE (outstream);
+
INIT(@"*BREAK-ON-SIGNALS*", NIL);
INIT(@"*COMPILE-FILE-PATHNAME*", NIL);
INIT(@"*COMPILE-FILE-TRUENAME*", NIL);
@@ -221,7 +239,7 @@ static MLKDynamicContext *global_context;
// INIT(@"*DEBUG-IO*", );
INIT(@"*DEBUGGER-HOOK*", NIL);
// INIT(@"*DEFAULT-PATHNAME-DEFAULTS*", );
- // INIT(@"*ERROR-OUTPUT*", );
+ INIT(@"*ERROR-OUTPUT*", errstream);
INIT(@"*FEATURES*", [MLKCons
cons:[keyword intern:@"ETOILET"]
with:[MLKCons
@@ -260,9 +278,9 @@ static MLKDynamicContext *global_context;
INIT(@"*READ-SUPPRESS*", NIL); //FIXME: Support in reader
INIT(@"*READTABLE*", readtable);
// INIT(@"*STANDARD-INPUT*", );
- // INIT(@"*STANDARD-OUTPUT*", );
+ INIT(@"*STANDARD-OUTPUT*", outstream);
// INIT(@"*TERMINAL-IO*", );
- // INIT(@"*TRACE-OUTPUT* ", );
+ INIT(@"*TRACE-OUTPUT* ", outstream);
[vars setObject:NIL forKey:[[MLKPackage findPackage:@"TOILET-SYSTEM"]
intern:@"*SYSTEM-INITIALISED-P*"]];
diff --git a/MLKFileHandleStream.h b/MLKFileHandleStream.h
new file mode 100644
index 0000000..9d5de5f
--- /dev/null
+++ b/MLKFileHandleStream.h
@@ -0,0 +1,35 @@
+/* -*- 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 "MLKBinaryStream.h"
+
+#import <Foundation/NSFileHandle.h>
+
+@interface MLKFileHandleStream : MLKBinaryStream
+{
+ NSFileHandle *_fileHandle;
+ BOOL _closeWhenDone;
+}
+
+-(id) initWithFileHandle:(NSFileHandle *)fileHandle;
+-(id) initWithFileHandle:(NSFileHandle *)fileHandle
+ closeWhenDone:(BOOL)closeWhenDone;
+
+-(uint8_t) readOctet;
+-(void) writeOctet:(uint8_t)octet;
+@end
diff --git a/MLKFileHandleStream.m b/MLKFileHandleStream.m
new file mode 100644
index 0000000..2376dc0
--- /dev/null
+++ b/MLKFileHandleStream.m
@@ -0,0 +1,78 @@
+/* -*- 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 "MLKFileHandleStream.h"
+#import "runtime-compatibility.h"
+#import "util.h"
+
+#import <Foundation/NSData.h>
+#import <Foundation/NSException.h>
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+@implementation MLKFileHandleStream
+-(id) initWithFileHandle:(NSFileHandle *)fileHandle
+{
+ return [self initWithFileHandle:fileHandle
+ closeWhenDone:NO];
+}
+
+-(id) initWithFileHandle:(NSFileHandle *)fileHandle
+ closeWhenDone:(BOOL)closeWhenDone
+{
+ self = [super init];
+ LASSIGN (_fileHandle, fileHandle);
+ _closeWhenDone = closeWhenDone;
+ return self;
+}
+
+-(uint8_t) readOctet
+{
+ NSData *data;
+
+ data = [_fileHandle readDataOfLength:1];
+
+ if ([data length] == 0)
+ {
+ [NSException raise:@"MLKStreamError"
+ format:@"Tried to read beyond end of file."];
+ }
+
+ return *(uint8_t*)[data bytes];
+}
+
+-(void) writeOctet:(uint8_t)octet
+{
+ [_fileHandle writeData:[NSData dataWithBytesNoCopy:&octet
+ length:1
+ freeWhenDone:NO]];
+}
+
+-(void) dealloc
+{
+ if (_closeWhenDone)
+ {
+ [_fileHandle close];
+ }
+ LDESTROY (_fileHandle);
+ [super dealloc];
+}
+@end
diff --git a/MLKStreamStream.h b/MLKStreamStream.h
index 3bd4f1b..6fabb50 100644
--- a/MLKStreamStream.h
+++ b/MLKStreamStream.h
@@ -19,13 +19,11 @@
#import "MLKBinaryStream.h"
#import <Foundation/NSStream.h>
-#import <Foundation/NSString.h>
@interface MLKStreamStream : MLKBinaryStream
{
NSInputStream *_input;
NSOutputStream *_output;
- NSStringEncoding _encoding;
BOOL _closeInputWhenDone;
BOOL _closeOutputWhenDone;
}