diff options
author | Matthias Andreas Benkard <matthias@benkard.de> | 2008-08-17 22:43:25 +0200 |
---|---|---|
committer | Matthias Andreas Benkard <matthias@benkard.de> | 2008-08-18 01:21:41 +0200 |
commit | d86ccf58d5b462100d1f4ec5d016024543ec7f53 (patch) | |
tree | 857892d893278f2f405d7b0280cb65f96c940899 | |
parent | 79b29bf6e41ca122d469040cd671d43ce81bd6df (diff) |
Replace special operator %DEFMACRO with intrinsic function %MACROSET.
-rw-r--r-- | MLKForm.h | 8 | ||||
-rw-r--r-- | MLKForm.m | 26 | ||||
-rw-r--r-- | MLKInterpreter.m | 40 | ||||
-rw-r--r-- | MLKPackage.m | 2 | ||||
-rw-r--r-- | MLKRoot.m | 11 | ||||
-rw-r--r-- | util.lisp | 11 |
6 files changed, 23 insertions, 75 deletions
@@ -134,14 +134,6 @@ @end -@interface MLKSimpleDefmacroForm : MLKDeclaringForm -{ - MLKSymbol *_lambdaListName; - MLKSymbol *_name; -} -@end - - @interface MLKEvalWhenForm : MLKBodyForm { BOOL _compileToplevel; @@ -130,7 +130,6 @@ if (car == APPLY) return [MLKFunctionCallForm class]; else if (car == CATCH) return [MLKCatchForm class]; - else if (car == _DEFMACRO) return [MLKSimpleDefmacroForm class]; else if (car == EVAL) return [MLKFunctionCallForm class]; else if (car == EVAL_WHEN) return [MLKEvalWhenForm class]; else if (car == _FOREIGN_LAMBDA) return [MLKForeignLambdaForm class]; @@ -332,31 +331,6 @@ @end -@implementation MLKSimpleDefmacroForm --(id) complete -{ - MLKLexicalContext *newContext; - - self = [super complete]; - - LASSIGN (_name, [_tail car]); - LASSIGN (_lambdaListName, [[_tail cdr] car]); - newContext = [MLKLexicalContext contextWithParent:_context - variables:[NSSet setWithObject:_lambdaListName] - functions:nil - goTags:nil - macros:nil - compilerMacros:nil - symbolMacros:nil - declarations:[self declarationsWithForms:[[_tail cdr] cdr]]]; - - [self processBody:[[_tail cdr] cdr] - inContext:newContext]; - return self; -} -@end - - @implementation MLKEvalWhenForm -(id) complete { diff --git a/MLKInterpreter.m b/MLKInterpreter.m index 21adaea..3f91814 100644 --- a/MLKInterpreter.m +++ b/MLKInterpreter.m @@ -289,46 +289,6 @@ return nil; } - else if (car == _DEFMACRO) - { - // No real lambda lists here. This SYS::%DEFMACRO is - // really as low-level as it gets. - id name = [[program cdr] car]; - id lambdaListAndBody = [[program cdr] cdr]; - - id <MLKFuncallable> function; - - if (expandOnly) - { - id lambdaList = [lambdaListAndBody car]; - id body = [lambdaListAndBody cdr]; - id body_expansion = - denullify([[self eval:[MLKCons cons:PROGN with:body] - inLexicalContext:context - withEnvironment:lexenv - expandOnly:expandOnly] - objectAtIndex:0]); - RETURN_VALUE ([MLKCons - cons:_DEFMACRO - with:[MLKCons - cons:name - with:[MLKCons - cons:lambdaList - with:[MLKCons - cons:body_expansion - with:nil]]]]); - } - - function = denullify([[self eval:[MLKCons cons:_LAMBDA with:lambdaListAndBody] - inLexicalContext:context - withEnvironment:lexenv - expandOnly:expandOnly] - objectAtIndex:0]); - - [context addMacro:function forSymbol:name]; - - RETURN_VALUE (name); - } else if (car == EVAL) { NSArray *evaluand = denullify([[self eval:[[program cdr] car] diff --git a/MLKPackage.m b/MLKPackage.m index 9bae8fe..c86f8a6 100644 --- a/MLKPackage.m +++ b/MLKPackage.m @@ -105,10 +105,10 @@ static NSMutableDictionary *packages = nil; [cl export:[cl intern:@"MULTIPLE-VALUE-CALL"]]; [cl export:[cl intern:@"EVAL-WHEN"]]; - [sys export:[sys intern:@"%DEFMACRO"]]; [sys export:[sys intern:@"%LAMBDA"]]; [sys export:[sys intern:@"%FSET"]]; [sys export:[sys intern:@"%FSETQ"]]; + [sys export:[sys intern:@"%MACROSET"]]; [sys export:[sys intern:@"%LOOP"]]; [sys export:[sys intern:@"%FLET"]]; [sys export:[sys intern:@"%MACROLET"]]; @@ -746,4 +746,15 @@ as provided by method %@ of object %@", RETURN_VALUE (value); } + ++(NSArray *) macroset:(NSArray *)args +{ + id symbol = denullify ([args objectAtIndex:0]); + id value = denullify ([args objectAtIndex:1]); + + [[MLKLexicalContext globalContext] addMacro:value + forSymbol:symbol]; + + RETURN_VALUE (value); +} @end @@ -22,6 +22,17 @@ otherwise unless when eq boundp)) +(%macroset '%defmacro + (%lambda args + (let ((form (car args))) + (let ((name (car (cdr form))) + (lambda-list-name (car (cdr (cdr form)))) + (body (cdr (cdr (cdr form))))) + (list '%macroset + (list 'quote name) + (cons '%lambda + (cons lambda-list-name body))))))) + (%defmacro %defun args (list '%fset (list 'quote (car (cdr (car args)))) |