From bd264499c08c196aa2ce69702cba0829ab24788a Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Tue, 10 Jun 2008 16:52:52 +0200 Subject: Beginnings of a Lisp compiler. --- MLKLinkedList.m | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 MLKLinkedList.m (limited to 'MLKLinkedList.m') diff --git a/MLKLinkedList.m b/MLKLinkedList.m new file mode 100644 index 0000000..40174e0 --- /dev/null +++ b/MLKLinkedList.m @@ -0,0 +1,64 @@ +/* -*- mode: objc; coding: utf-8 -*- */ +/* Copyright 2008, Matthias Benkard. */ + +#import "MLKLinkedList.h" +#import "MLKCons.h" + + +@implementation MLKLinkedList +-(MLKLinkedList*) init +{ + _firstCons = nil; + return self; +} + +-(MLKLinkedList*) initWithCons:(MLKCons*)cons +{ + ASSIGN (_firstCons, cons); + return self; +} + +-(void) push: (id)object +{ + ASSIGN (_firstCons, [MLKCons cons:object with:_firstCons]); +} + +-(id) pop +{ + id retval = [_firstCons car]; + RETAIN (retval); + ASSIGN (_firstCons, [_firstCons cdr]); + AUTORELEASE (retval); + return retval; +} + +-(MLKCons*) firstCons +{ + return _firstCons; +} + +-(BOOL) null +{ + return !_firstCons; +} + +#ifdef __OBJC2__ +-(NSUInteger) countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len +{ + if (state->state == 0) + { + state->mutationsPtr = &_firstCons; + state->extra[0] = (unsigned long) &_firstCons; + } + + MLKCons *currentCons = (MLKCons*) state->extra[0]; + if (currentCons) + { + state->itemsPtr = [currentCons car]; + return 1; + } + else + return 0; +} +#endif +@end -- cgit v1.2.3