diff --git a/ChangeLog b/ChangeLog index 1df3297..927231b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2003 Aug 6 + + * Frameworks: new directory + * Changed StepTalk from library to framework + 2003 Aug 5 Stefan Urbanek * Added STScriptObject and STMethod. diff --git a/Documentation/Reference/STEngine.gsdoc b/Documentation/Reference/STEngine.gsdoc index 15b39fb..e10ba09 100644 --- a/Documentation/Reference/STEngine.gsdoc +++ b/Documentation/Reference/STEngine.gsdoc @@ -65,6 +65,30 @@ language engine. + + executeMethod: + aMethod + forReceiver: + anObject + withArguments: + args + inEnvironment: + env + + Description forthcoming. + + + + methodFromSource: + sourceString + forReceiver: + receiver + inEnvironment: + env + + Description forthcoming. + + setDefaultEnvironment: anEnvironment diff --git a/Documentation/Reference/STEngine.html b/Documentation/Reference/STEngine.html index ea93f31..62581f5 100644 --- a/Documentation/Reference/STEngine.html +++ b/Documentation/Reference/STEngine.html @@ -9,9 +9,7 @@

STEngine class documentation

Authors

-
Stefan Urbanek( - urbanek@host.sk - )
+
Stefan Urbanek (urbanek@host.sk)
@@ -43,6 +41,10 @@
  • -defaultEnvironment
  • -executeCode:
  • -executeCode:inEnvironment:
  • +
  • -executeMethod:forReceiver:withArguments:inEnvironment:
  • +
  • -executeMethod:forScriptObject:
  • +
  • -methodFromSource:forReceiver:inEnvironment:
  • +
  • -methodFromSource:forScriptObject:
  • -setDefaultEnvironment:
  • -understandsCode:
  • @@ -93,6 +95,22 @@ Subclasses should override this method.
    has to be implemented by those who are writing a language engine. +

    +
    +

    executeMethod:forReceiver:withArguments:inEnvironment:

    + - (id) executeMethod: (id<STMethod>)aMethod forReceiver: (id)anObject withArguments: (NSArray*)args inEnvironment: (STEnvironment*)env;
    +

    + + Description forthcoming. + +

    +
    +

    methodFromSource:forReceiver:inEnvironment:

    + - (STMethod*) methodFromSource: (NSString*)sourceString forReceiver: (id)receiver inEnvironment: (STEnvironment*)env;
    +

    + + Description forthcoming. +


    setDefaultEnvironment:

    diff --git a/Documentation/Reference/StepTalk.igsdoc b/Documentation/Reference/StepTalk.igsdoc index d640ce2..e5ebc11 100644 --- a/Documentation/Reference/StepTalk.igsdoc +++ b/Documentation/Reference/StepTalk.igsdoc @@ -22,8 +22,10 @@ STEngine = STEngine; STEnvironment = STEnvironment; STLanguage = STLanguage; + STMethod = STMethod; STObjectReference = STObjectReference; STScript = STScript; + STScriptObject = STScriptObject; STScriptsManager = STScriptsManager; STSelector = STSelector; STUndefinedObject = STUndefinedObject; @@ -119,6 +121,9 @@ "-addClassesWithNames:" = { STEnvironment = STEnvironment; }; + "-addMethod:" = { + STScriptObject = STScriptObject; + }; "-addNamedObjectsFromDictionary:" = { STEnvironment = STEnvironment; }; @@ -152,6 +157,12 @@ "-executeCode:inEnvironment:" = { STEngine = STEngine; }; + "-executeMethod:forReceiver:withArguments:inEnvironment:" = { + STEngine = STEngine; + }; + "-executeMethod:forScriptObject:" = { + STEngine = STEngine; + }; "-fileName" = { STScript = STScript; }; @@ -185,12 +196,18 @@ "-initWithFile:" = { STScript = STScript; }; + "-initWithInstanceVariableNames:" = { + STScriptObject = STScriptObject; + }; "-initWithObjectName:pool:" = { STObjectReference = STObjectReference; }; "-initWithSelector:" = { STSelector = STSelector; }; + "-instanceVariableNames" = { + STScriptObject = STScriptObject; + }; "-isClass" = { "(STScripting)" = STScripting; }; @@ -207,7 +224,9 @@ STScript = STScript; }; "-languageName" = { + "(STMethod)" = STMethod; STLanguage = STLanguage; + STMethod = STMethod; }; "-loadModule:" = { STEnvironment = STEnvironment; @@ -215,6 +234,25 @@ "-localizedName" = { STScript = STScript; }; + "-methodDictionary" = { + STScriptObject = STScriptObject; + }; + "-methodFromSource:forReceiver:inEnvironment:" = { + STEngine = STEngine; + }; + "-methodFromSource:forScriptObject:" = { + STEngine = STEngine; + }; + "-methodName" = { + "(STMethod)" = STMethod; + STMethod = STMethod; + }; + "-methodNames" = { + STScriptObject = STScriptObject; + }; + "-methodWithName:" = { + STScriptObject = STScriptObject; + }; "-namedObjects" = { STBundleInfo = STBundleInfo; }; @@ -227,6 +265,9 @@ "-objectDictionary" = { STEnvironment = STEnvironment; }; + "-objectForVariable:" = { + STScriptObject = STScriptObject; + }; "-objectName" = { STObjectReference = STObjectReference; }; @@ -251,6 +292,12 @@ "-registerObjectFinderNamed:" = { STEnvironment = STEnvironment; }; + "-removeMethod:" = { + STScriptObject = STScriptObject; + }; + "-removeMethodWithName:" = { + STScriptObject = STScriptObject; + }; "-removeObjectFinderWithName:" = { STEnvironment = STEnvironment; }; @@ -299,6 +346,9 @@ "-setObject:forName:" = { STEnvironment = STEnvironment; }; + "-setObject:forVariable:" = { + STScriptObject = STScriptObject; + }; "-setObjectName:" = { STObjectReference = STObjectReference; }; @@ -312,6 +362,8 @@ STScriptsManager = STScriptsManager; }; "-source" = { + "(STMethod)" = STMethod; + STMethod = STMethod; STScript = STScript; }; "-stringValue" = { @@ -352,6 +404,9 @@ Headers/StepTalk/STLanguage.h = ( ../Documentation/Reference/STLanguage.gsdoc ); + Headers/StepTalk/STMethod.h = ( + ../Documentation/Reference/STMethod.gsdoc + ); Headers/StepTalk/STObjCRuntime.h = ( ../Documentation/Reference/STObjCRuntime.gsdoc ); @@ -361,6 +416,9 @@ Headers/StepTalk/STScript.h = ( ../Documentation/Reference/STScript.gsdoc ); + Headers/StepTalk/STScriptObject.h = ( + ../Documentation/Reference/STScriptObject.gsdoc + ); Headers/StepTalk/STScripting.h = ( ../Documentation/Reference/STScripting.gsdoc ); @@ -375,6 +433,7 @@ ); }; protocol = { + "(STMethod)" = STMethod; "(STScripting)" = STScripting; }; source = { @@ -402,6 +461,9 @@ Headers/StepTalk/STLanguage.h = ( STLanguage.m ); + Headers/StepTalk/STMethod.h = ( + STMethod.m + ); Headers/StepTalk/STObjCRuntime.h = ( STObjCRuntime.m ); @@ -411,6 +473,9 @@ Headers/StepTalk/STScript.h = ( STScript.m ); + Headers/StepTalk/STScriptObject.h = ( + STScriptObject.m + ); Headers/StepTalk/STScripting.h = ( STScripting.m ); @@ -429,8 +494,10 @@ STEngine = NSObject; STEnvironment = NSObject; STLanguage = NSBundle; + STMethod = NSObject; STObjectReference = NSObject; STScript = NSObject; + STScriptObject = NSObject; STScriptsManager = NSObject; STSelector = NSObject; STUndefinedObject = NSObject; @@ -444,9 +511,11 @@ STExterns = "STExterns autogsdoc generated documentation"; STFunctions = "STFunctions autogsdoc generated documentation"; STLanguage = "STLanguage class documentation"; + STMethod = "STMethod autogsdoc generated documentation"; STObjCRuntime = "STObjCRuntime autogsdoc generated documentation"; STObjectReference = "STObjectReference class documentation"; STScript = "STScript class documentation"; + STScriptObject = "STScriptObject class documentation"; STScripting = "STScripting protocol documentation"; STScriptsManager = "STScriptsManager class documentation"; STSelector = "STSelector class documentation"; @@ -454,6 +523,11 @@ StepTalk = "StepTalk Documentation"; }; unitmethods = { + "(STMethod)" = { + "-languageName" = STMethod; + "-methodName" = STMethod; + "-source" = STMethod; + }; "(STScripting)" = { "+classForScripting" = STScripting; "+className" = STScripting; @@ -495,6 +569,10 @@ "-defaultEnvironment" = STEngine; "-executeCode:" = STEngine; "-executeCode:inEnvironment:" = STEngine; + "-executeMethod:forReceiver:withArguments:inEnvironment:" = STEngine; + "-executeMethod:forScriptObject:" = STEngine; + "-methodFromSource:forReceiver:inEnvironment:" = STEngine; + "-methodFromSource:forScriptObject:" = STEngine; "-setDefaultEnvironment:" = STEngine; "-understandsCode:" = STEngine; }; @@ -536,6 +614,11 @@ "-engine" = STLanguage; "-languageName" = STLanguage; }; + STMethod = { + "-languageName" = STMethod; + "-methodName" = STMethod; + "-source" = STMethod; + }; STObjectReference = { "-initWithObjectName:pool:" = STObjectReference; "-object" = STObjectReference; @@ -556,6 +639,18 @@ "-scriptName" = STScript; "-source" = STScript; }; + STScriptObject = { + "-addMethod:" = STScriptObject; + "-initWithInstanceVariableNames:" = STScriptObject; + "-instanceVariableNames" = STScriptObject; + "-methodDictionary" = STScriptObject; + "-methodNames" = STScriptObject; + "-methodWithName:" = STScriptObject; + "-objectForVariable:" = STScriptObject; + "-removeMethod:" = STScriptObject; + "-removeMethodWithName:" = STScriptObject; + "-setObject:forVariable:" = STScriptObject; + }; STScriptsManager = { "+defaultManager" = STScriptsManager; "-allScripts" = STScriptsManager; diff --git a/Frameworks/GNUmakefile b/Frameworks/GNUmakefile new file mode 100644 index 0000000..f96ccf1 --- /dev/null +++ b/Frameworks/GNUmakefile @@ -0,0 +1,33 @@ +# +# Main Makefile for the StepTalk +# +# Copyright (C) 2000 Stefan Urbanek +# +# Written by: Stefan Urbanek +# +# This file is part of the StepTalk +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library 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 +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public +# License along with this library; if not, write to the Free +# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA +# + +include $(GNUSTEP_MAKEFILES)/common.make + +SUBPROJECTS = \ + StepTalk + +-include GNUMakefile.preamble +include $(GNUSTEP_MAKEFILES)/aggregate.make +-include GNUMakefile.postamble + diff --git a/Source/Environments/AppKit.stenv b/Frameworks/StepTalk/Environments/AppKit.stenv similarity index 100% rename from Source/Environments/AppKit.stenv rename to Frameworks/StepTalk/Environments/AppKit.stenv diff --git a/Frameworks/StepTalk/Environments/Common.stenv b/Frameworks/StepTalk/Environments/Common.stenv new file mode 100644 index 0000000..0a95bb1 --- /dev/null +++ b/Frameworks/StepTalk/Environments/Common.stenv @@ -0,0 +1,17 @@ +/** Common.stenv + * Common scripting environment description + */ + +{ + Name = "Common"; + + Bundles = (CommonEnvironment); + + Import = ( "SymbolicSelectors", + "Foundation", + "AppKit", + "StepTalk" + ); + + Applications = ( All ); +} diff --git a/Source/Environments/Distributed.stenv b/Frameworks/StepTalk/Environments/Distributed.stenv similarity index 100% rename from Source/Environments/Distributed.stenv rename to Frameworks/StepTalk/Environments/Distributed.stenv diff --git a/Source/Environments/Foundation-operators.stenv b/Frameworks/StepTalk/Environments/Foundation-operators.stenv similarity index 100% rename from Source/Environments/Foundation-operators.stenv rename to Frameworks/StepTalk/Environments/Foundation-operators.stenv diff --git a/Source/Environments/Foundation.stenv b/Frameworks/StepTalk/Environments/Foundation.stenv similarity index 100% rename from Source/Environments/Foundation.stenv rename to Frameworks/StepTalk/Environments/Foundation.stenv diff --git a/Source/Environments/Safe.stenv b/Frameworks/StepTalk/Environments/Safe.stenv similarity index 100% rename from Source/Environments/Safe.stenv rename to Frameworks/StepTalk/Environments/Safe.stenv diff --git a/Source/Environments/Standard.stenv b/Frameworks/StepTalk/Environments/Standard.stenv similarity index 100% rename from Source/Environments/Standard.stenv rename to Frameworks/StepTalk/Environments/Standard.stenv diff --git a/Source/Environments/StepTalk.stenv b/Frameworks/StepTalk/Environments/StepTalk.stenv similarity index 100% rename from Source/Environments/StepTalk.stenv rename to Frameworks/StepTalk/Environments/StepTalk.stenv diff --git a/Source/Environments/SymbolicSelectors.stenv b/Frameworks/StepTalk/Environments/SymbolicSelectors.stenv similarity index 100% rename from Source/Environments/SymbolicSelectors.stenv rename to Frameworks/StepTalk/Environments/SymbolicSelectors.stenv diff --git a/Frameworks/StepTalk/GNUmakefile b/Frameworks/StepTalk/GNUmakefile new file mode 100644 index 0000000..f78f3d5 --- /dev/null +++ b/Frameworks/StepTalk/GNUmakefile @@ -0,0 +1,106 @@ +# +# GNUmakefile +# +# Copyright (C) 2000 Stefan Urbanek +# +# This file is part of the StepTalk. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library 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 +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public +# License along with this library; if not, write to the Free +# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. + +include $(GNUSTEP_MAKEFILES)/common.make + +include ../Version + +LIBRARY_NAME = libStepTalk + +libStepTalk_OBJC_FILES = \ + NSInvocation+additions.m \ + STBehaviourInfo.m \ + STBundleInfo.m \ + STClassInfo.m \ + STEngine.m \ + STEnvironment.m \ + STEnvironmentDescription.m \ + STExterns.m \ + STFunctions.m \ + STLanguage.m \ + STObjCRuntime.m \ + STObjectReference.m \ + STScript.m \ + STScriptsManager.m \ + STScripting.m \ + STMethod.m \ + STScriptObject.m \ + STSelector.m \ + STStructure.m \ + STUndefinedObject.m \ + NSNumber+additions.m \ + NSObject+additions.m + +STEPTALK_HEADER_FILES = \ + STBundleInfo.h \ + STEngine.h \ + STEnvironment.h \ + STExterns.h \ + STFunctions.h \ + STLanguage.h \ + STObjCRuntime.h \ + STObjectReference.h \ + STMethod.h \ + STScriptObject.h \ + STScript.h \ + STScriptsManager.h \ + STScripting.h \ + STSelector.h \ + STUndefinedObject.h \ + NSInvocation+additions.h \ + NSObject+additions.h + +libStepTalk_HEADER_FILES = $(STEPTALK_HEADER_FILES) \ + StepTalk.h +libStepTalk_HEADER_FILES_DIR = Headers/StepTalk + +libStepTalk_HEADER_FILES_INSTALL_DIR = StepTalk + +STEPTALK_LIBRARY_DIR = $(GNUSTEP_INSTALLATION_DIR)/Library/StepTalk +STEPTALK_ENVDEFS_DIR = $(STEPTALK_LIBRARY_DIR)/Environments + +ADDITIONAL_INCLUDE_DIRS += -I./Headers + +ADDITIONAL_CPPFLAGS += -pipe +ADDITIONAL_OBJCFLAGS = -Wno-import -DSTEPTALK_VERSION=$(STEPTALK_VERSION) + +DOCUMENT_NAME = StepTalk + +StepTalk_DOC_INSTALL_DIR = Developer + +StepTalk_HEADER_FILES_DIR = $(HEADER_DIR) +StepTalk_AGSDOC_FILES = StepTalk.gsdoc $(STEPTALK_HEADER_FILES) +StepTalk_AGSDOC_FLAGS = \ + -HeaderDirectory Headers/StepTalk \ + -Up StepTalk \ + -Declared StepTalk \ + -DocumentationDirectory ../Documentation/Reference + +ifeq ($(GNUSTEP_TARGET_OS),mingw32) + libStepTalk_LIBRARIES_DEPEND_UPON += -lgnustep-base -lobjc +endif + +-include GNUmakefile.preamble + +include $(GNUSTEP_MAKEFILES)/library.make +include $(GNUSTEP_MAKEFILES)/documentation.make + +-include GNUmakefile.postamble diff --git a/Frameworks/StepTalk/GNUmakefile.postamble b/Frameworks/StepTalk/GNUmakefile.postamble new file mode 100644 index 0000000..10efca9 --- /dev/null +++ b/Frameworks/StepTalk/GNUmakefile.postamble @@ -0,0 +1,74 @@ +# +# GNUmakefile.postamble +# +# Copyright (C) 2000 Stefan Urbanek +# +# This file is part of the StepTalk +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library 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 +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public +# License along with this library; see the file COPYING.LIB. +# If not, write to the Free Software Foundation, +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# Project specific makefile rules +# +# Uncomment the targets you want. +# The double colons (::) are important, do not make them single colons +# otherwise the normal makefile rules will not be performed. +# + +# Things to do before compiling +# before-all:: + +# Things to do after compiling +# after-all:: + +# Things to do before installing +before-install:: + $(MKDIRS) $(STEPTALK_LIBRARY_DIR) + $(MKDIRS) $(STEPTALK_ENVDEFS_DIR) + +# Things to do after installing +after-install:: + @(echo Copying scripting environments...; \ + cd Environments;\ + for file in *.stenv; do \ + $(INSTALL_DATA) $$file $(STEPTALK_ENVDEFS_DIR)/$$file ; \ + done;\ + ) + +# Things to do before uninstalling +# before-uninstall:: + +# Things to do after uninstalling +after-uninstall:: + rm -rf $(STEPTALK_ENVDEFS_DIR) + +# Things to do before cleaning +# before-clean:: + +# Things to do after cleaning +# after-clean:: + +# Things to do before distcleaning +# before-distclean:: + +# Things to do after distcleaning +# after-distclean:: + +# Things to do before checking +# before-check:: + +# Things to do after checking +# after-check:: + diff --git a/Frameworks/StepTalk/NSInvocation+additions.h b/Frameworks/StepTalk/NSInvocation+additions.h new file mode 100644 index 0000000..a1e2d30 --- /dev/null +++ b/Frameworks/StepTalk/NSInvocation+additions.h @@ -0,0 +1,40 @@ +/** + NSInvocation+additions.h + Various NSInvocation additions + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of the StepTalk project. + + 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 2 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02111, USA. + + */ + +#import + +void STGetValueOfTypeFromObject(void *value, const char *type, id anObject); +id STObjectFromValueOfType(void *value, const char *type); + +@interface NSInvocation(STAdditions) ++ invocationWithTarget:(id)target selectorName:(NSString *)selectorName; + +- (void)setArgumentAsObject:(id)anObject atIndex:(int)anIndex; +- (id)getArgumentAsObjectAtIndex:(int)anIndex; +- (id)returnValueAsObject; +@end + diff --git a/Frameworks/StepTalk/NSInvocation+additions.m b/Frameworks/StepTalk/NSInvocation+additions.m new file mode 100644 index 0000000..d53ab9c --- /dev/null +++ b/Frameworks/StepTalk/NSInvocation+additions.m @@ -0,0 +1,325 @@ +/** + NSInvocation+additions + Various NSInvocation additions + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of the StepTalk project. + + 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 2 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02111, USA. + + NSInvocation class additions + + */ + +#import + +#import +#import +#import + +#import +#import +#import +#import +#import + +#if 0 +static Class NSNumber_class = nil; +static Class NSString_class = nil; +static Class NSValue_class = nil; +#endif + +#define CASE_NUMBER_TYPE(otype,type,msgtype)\ + case otype: object = [NSNumber numberWith##msgtype:*((type *)value)];\ + NSDebugLLog(@"STStructure",\ + @" is number value '%@'", object);\ + break + +id STObjectFromValueOfType(void *value, const char *type) +{ + id object; + + NSDebugLLog(@"STStructure", + @"object from value %p of of type '%c'",value,*type); + + switch(*type) + { + case _C_ID: + case _C_CLASS: + object = *((id *)value); + NSDebugLLog(@"STStructure", + @" is object value %p", object); + break; + CASE_NUMBER_TYPE(_C_CHR,char,Char); + CASE_NUMBER_TYPE(_C_UCHR,unsigned char, UnsignedChar); + CASE_NUMBER_TYPE(_C_SHT,short,Short); + CASE_NUMBER_TYPE(_C_USHT,unsigned short,UnsignedShort); + CASE_NUMBER_TYPE(_C_INT,int,Int); + CASE_NUMBER_TYPE(_C_UINT,unsigned int,UnsignedInt); + CASE_NUMBER_TYPE(_C_LNG,long,Long); + CASE_NUMBER_TYPE(_C_ULNG,unsigned long,UnsignedLong); + CASE_NUMBER_TYPE(_C_LNG_LNG,long long,LongLong); + CASE_NUMBER_TYPE(_C_ULNG_LNG,unsigned long long,UnsignedLongLong); + CASE_NUMBER_TYPE(_C_FLT,float,Float); + CASE_NUMBER_TYPE(_C_DBL,double,Double); + case _C_PTR: + object = [NSValue valueWithPointer:*((void **)value)]; + NSDebugLLog(@"STStructure", + @" is pointer value %p", *((void **)value)); + break; + case _C_CHARPTR: + object = [NSString stringWithCString:*((char **)value)]; + NSDebugLLog(@"STStructure", + @" is string value '%s'", *((char **)value)); + break; + case _C_VOID: + object = nil; + break; + case _C_STRUCT_B: + object = [[STStructure alloc] initWithValue:value + type:type]; + AUTORELEASE(object); + break; + case _C_SEL: + object = [[STSelector alloc] initWithSelector:*((SEL *)value)]; + AUTORELEASE(object); + break; + case _C_BFLD: + case _C_UNDEF: + case _C_ATOM: + case _C_ARY_B: + case _C_ARY_E: + case _C_UNION_B: + case _C_UNION_E: + case _C_STRUCT_E: + default: + [NSException raise:STInvalidArgumentException + format:@"unhandled ObjC type '%s'", + type]; + + } + return object; +} + +#define CASE_TYPE(otype,type,msgtype)\ + case otype:(*((type *)value)) = [anObject msgtype##Value];\ + NSDebugLLog(@"STStructure",\ + @" is number value '%@'", anObject);\ + break + +void STGetValueOfTypeFromObject(void *value, const char *type, id anObject) +{ + NSDebugLLog(@"STStructure", + @"value at %p from object '%@' of type '%c'", + value,anObject,*type); + + switch(*type) + { + case _C_ID: + case _C_CLASS: + NSDebugLLog(@"STStructure", + @" is object value"); + (*(id *)value) = anObject; + break; + CASE_TYPE(_C_CHR,char,char); + CASE_TYPE(_C_UCHR,unsigned char,unsignedChar); + CASE_TYPE(_C_SHT,short,short); + CASE_TYPE(_C_USHT,unsigned short,unsignedShort); + CASE_TYPE(_C_INT,int,int); + CASE_TYPE(_C_UINT,unsigned int,unsignedInt); + CASE_TYPE(_C_LNG,long,long); + CASE_TYPE(_C_ULNG,unsigned long,unsignedLong); + CASE_TYPE(_C_LNG_LNG,long long,longLong); + CASE_TYPE(_C_ULNG_LNG,unsigned long long,unsignedLongLong); + CASE_TYPE(_C_FLT,float,float); + CASE_TYPE(_C_DBL,double,double); + CASE_TYPE(_C_PTR,void *,pointer); + case _C_CHARPTR: /* FIXME: check if this is good (copy/no copy)*/ + (*((const char **)value)) = [[anObject stringValue] cString]; + NSDebugLLog(@"STStructure", + @" is cstring '%@'", [anObject stringValue]); + break; + case _C_STRUCT_B: + /* FIXME: chech for struct compatibility */ + NSDebugLLog(@"STStructure", + @" is structure"); + [(STStructure*)anObject getValue:value]; + break; + + case _C_SEL: + (*((SEL *)value)) = [anObject selectorValue]; + break; + + case _C_BFLD: + case _C_VOID: + case _C_UNDEF: + case _C_ATOM: + case _C_ARY_B: + case _C_ARY_E: + case _C_UNION_B: + case _C_UNION_E: + case _C_STRUCT_E: + default: + [NSException raise:STInvalidArgumentException + format:@"unhandled ObjC type '%s'", + type]; + } +} + + +@implementation NSInvocation(STAdditions) +#if 0 +/* with this method it does not work, it is not posiible to create an + invocation*/ ++ (void)initialize +{ + NSNumber_class = [NSNumber class]; + NSString_class = [NSString class]; + NSValue_class = [NSValue class]; +} +#endif + ++ invocationWithTarget:(id)target selectorName:(NSString *)selectorName +{ + NSMethodSignature *signature; + NSInvocation *invocation; + SEL sel; + BOOL requiresRegistration = NO; + + // NSLog(@"GETTING SELECTOR %@", selectorName); + sel = NSSelectorFromString(selectorName); + + if(!sel) + { + // NSLog(@"REGISTERING SELECTOR"); + char *name = [selectorName cString]; + + sel = sel_register_name(name); + + if(!sel) + { + [NSException raise:STInternalInconsistencyException + format:@"Unable to register selector '%@'", + selectorName]; + return nil; + } + requiresRegistration = YES; + } + + signature = [target methodSignatureForSelector:sel]; + + /* FIXME: this is workaround for gnustep DO bug (hight priority) */ + + if(requiresRegistration) + { + // NSLog(@"REGISTERING SELECTOR TYPES"); + sel = sel_register_typed_name([selectorName cString], [signature methodReturnType]); + // NSLog(@"REGISTERED %@", NSStringFromSelector(sel)); + + } + + if(!signature) + { + [NSException raise:STInternalInconsistencyException + format:@"No method signature for selector '%@' for " + @"receiver of type %@", + selectorName,[target className]]; + return nil; + } + + invocation = [NSInvocation invocationWithMethodSignature:signature]; + + [invocation setSelector:sel]; + [invocation setTarget:target]; + + return invocation; +} + +- (void)setArgumentAsObject:(id)anObject atIndex:(int)anIndex +{ + const char *type; + void *value; + + type = [[self methodSignature] getArgumentTypeAtIndex:anIndex]; + value = NSZoneMalloc(STMallocZone,objc_sizeof_type(type)); + + STGetValueOfTypeFromObject(value, type, anObject); + + [self setArgument:(void *)value atIndex:anIndex]; + NSZoneFree(STMallocZone,value); +} +- (id)getArgumentAsObjectAtIndex:(int)anIndex +{ + const char *type; + void *value; + id object; + + type = [[self methodSignature] getArgumentTypeAtIndex:anIndex]; + + value = NSZoneMalloc(STMallocZone,objc_sizeof_type(type)); + [self getArgument:value atIndex:anIndex]; + + object = STObjectFromValueOfType(value,type); + + NSZoneFree(STMallocZone,value); + + return object; +} +- (id)returnValueAsObject +{ + const char *type; + int returnLength; + void *value; + id returnObject = nil; + + NSMethodSignature *signature = [self methodSignature]; + + type = [signature methodReturnType]; + returnLength = [signature methodReturnLength]; + + NSDebugLLog(@"STSending", + @" return type '%s', buffer length %i",type,returnLength); + + if(returnLength!=0) + { + value = NSZoneMalloc(STMallocZone,returnLength); + [self getReturnValue:value]; + + if( *type == _C_VOID ) + { + returnObject = [self target]; + } + else + { + returnObject = STObjectFromValueOfType(value, type); + } + + NSZoneFree(STMallocZone,value); + NSDebugLLog(@"STSending", + @" returned object %@",returnObject); + } + else + { + returnObject = [self target]; + } + + return returnObject; +} +@end + diff --git a/Frameworks/StepTalk/NSNumber+additions.h b/Frameworks/StepTalk/NSNumber+additions.h new file mode 100644 index 0000000..6d474c4 --- /dev/null +++ b/Frameworks/StepTalk/NSNumber+additions.h @@ -0,0 +1,52 @@ +/** + NSNumber-additions.h + Various methods for NSNumber + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + +#import + +@interface NSNumber (STAdditions) +- add:(NSNumber *)number; +- subtract:(NSNumber *)number; +- multiply:(NSNumber *)number; +- divide:(NSNumber *)number; +- (unsigned int)isLessThan:(NSNumber *)number; +- (BOOL)isGreatherThan:(NSNumber *)number; +- (BOOL)isLessOrEqualThan:(NSNumber *)number; +- (BOOL)isGreatherOrEqualThan:(NSNumber *)number; +@end + + +@interface NSNumber (STLogicOperations) +- (unsigned int)or:(NSNumber *)number; +- (unsigned int)and:(NSNumber *)number; +- (unsigned int)not; +@end + +@interface NSNumber (STStructure) +- rangeWith:(int)length; +- pointWith:(float)y; +- sizeWith:(float)h; +@end diff --git a/Frameworks/StepTalk/NSNumber+additions.m b/Frameworks/StepTalk/NSNumber+additions.m new file mode 100644 index 0000000..0aab532 --- /dev/null +++ b/Frameworks/StepTalk/NSNumber+additions.m @@ -0,0 +1,133 @@ +/** + NSNumber-additions.h + Various methods for NSNumber + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of the StepTalk project. + + 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 2 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02111, USA. + + */ + +#import + +#import +#import + +#import + +#include + +@implementation NSNumber (STAdditions) +- add:(NSNumber *)number +{ + return [NSNumber numberWithDouble:([self doubleValue] + + [number doubleValue])]; +} +- subtract:(NSNumber *)number +{ + return [NSNumber numberWithDouble:([self doubleValue] + - [number doubleValue])]; +} +- multiply:(NSNumber *)number +{ + return [NSNumber numberWithDouble:([self doubleValue] + * [number doubleValue])]; +} +- divide:(NSNumber *)number +{ + if([number doubleValue] == 0.0) + { + [NSException raise:STGenericException + format:@"Division by zero"]; + return self; + } + + + return [NSNumber numberWithDouble:([self doubleValue] + / [number doubleValue])]; +} + +- modulo:(NSNumber *)number +{ + if([number doubleValue] == 0.0) + { + [NSException raise:STGenericException + format:@"Division by zero"]; + return self; + } + + + return [NSNumber numberWithDouble:(fmod([self doubleValue], + [number doubleValue]))]; +} +- (unsigned int)isLessThan:(NSNumber *)number +{ + return ([self doubleValue] < [number doubleValue]); +} + +- (BOOL)isGreatherThan:(NSNumber *)number +{ + return ([self doubleValue] > [number doubleValue]); +} + +- (BOOL)isLessOrEqualThan:(NSNumber *)number +{ + return ([self doubleValue] <= [number doubleValue]); +} +- (BOOL)isGreatherOrEqualThan:(NSNumber *)number +{ + return ([self doubleValue] >= [number doubleValue]); +} +@end + + +@implementation NSNumber (STLogicOperations) +- (unsigned int)or:(NSNumber *)number +{ + return ([self intValue] | [number intValue]); +} + +- (unsigned int)and:(NSNumber *)number +{ + return ([self intValue] & [number intValue]); +} + +- (unsigned int)not +{ + /* FIXME */ + return ![self intValue]; +} + +@end + +@implementation NSNumber (STStructure) +- rangeWith:(int)length +{ + return [STStructure structureWithRange:NSMakeRange([self intValue], length)]; +} +- pointWith:(float)y +{ + return [STStructure structureWithPoint:NSMakePoint([self floatValue], y)]; +} +- sizeWith:(float)h +{ + return [STStructure structureWithSize:NSMakeSize([self floatValue], h)]; +} +@end diff --git a/Frameworks/StepTalk/NSObject+additions.h b/Frameworks/StepTalk/NSObject+additions.h new file mode 100644 index 0000000..58ab9ba --- /dev/null +++ b/Frameworks/StepTalk/NSObject+additions.h @@ -0,0 +1,31 @@ +/** + NSObject-additions.h + Various methods for NSObject + + Copyright (c) 2002 Free Software Foundation + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + +#import + +@interface NSObject (STAdditions) +- (BOOL)isSame:(id)anObject; +- (BOOL)isNil; +- (BOOL)notNil; +@end diff --git a/Frameworks/StepTalk/NSObject+additions.m b/Frameworks/StepTalk/NSObject+additions.m new file mode 100644 index 0000000..6ed6e01 --- /dev/null +++ b/Frameworks/StepTalk/NSObject+additions.m @@ -0,0 +1,27 @@ +/** + NSObject-additions.m + Various methods for NSObject + + Copyright (c) 2002 Free Software Foundation + + This file is part of the StepTalk project. + + */ + +#import + +@implementation NSObject (STAdditions) +- (BOOL)isSame:(id)anObject +{ + return self == anObject; +} +- (BOOL)isNil +{ + return NO; +} +- (BOOL)notNil +{ + return YES; +} +@end + diff --git a/Frameworks/StepTalk/STBehaviourInfo.h b/Frameworks/StepTalk/STBehaviourInfo.h new file mode 100644 index 0000000..af3a834 --- /dev/null +++ b/Frameworks/StepTalk/STBehaviourInfo.h @@ -0,0 +1,66 @@ +/** + STBehaviourInfo.h + Scripting definition: behaviour information + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + +#include + +@class NSString; +@class NSDictionary; +@class NSMutableDictionary; +@class NSMutableSet; +@class NSSet; + +@interface STBehaviourInfo:NSObject +{ + NSString *name; + + NSMutableDictionary *selectorMap; + + NSMutableSet *allowMethods; + NSMutableSet *denyMethods; +} +- initWithName:(NSString *)aString; + +- (NSString*)behaviourName; + +- (void)setTranslation:(NSString *)aSelector + forSelector:(NSString *)aString; + +- (void)removeTranslationForSelector:(NSString *)aString; +- (NSDictionary *)selectorMap; +- (void)addTranslationsFromDictionary:(NSDictionary *)map; + +- (void)allowMethods:(NSSet *)set; +- (void)denyMethods:(NSSet *)set; + +- (void)allowMethod:(NSString *)methodName; +- (void)denyMethod:(NSString *)methodName; + +- (NSSet *)allowedMethods; +- (NSSet *)deniedMethods; + +- (void)adopt:(STBehaviourInfo *)info; +@end diff --git a/Frameworks/StepTalk/STBehaviourInfo.m b/Frameworks/StepTalk/STBehaviourInfo.m new file mode 100644 index 0000000..6d5233f --- /dev/null +++ b/Frameworks/StepTalk/STBehaviourInfo.m @@ -0,0 +1,137 @@ +/** + STBehaviourInfo.m + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + +#import + +#import +#import +#import +#import +#import +#import +#import + +@implementation STBehaviourInfo +- initWithName:(NSString *)aString +{ + self = [super init]; + selectorMap = [[NSMutableDictionary alloc] init]; + allowMethods = [[NSMutableSet alloc] init]; + denyMethods = [[NSMutableSet alloc] init]; + + name = RETAIN(aString); + + return self; +} + +- (void)dealloc +{ + RELEASE(selectorMap); + RELEASE(allowMethods); + RELEASE(denyMethods); + RELEASE(name); + + [super dealloc]; +} + +- (NSString*)behaviourName +{ + return name; +} + +- (void)adopt:(STBehaviourInfo *)info +{ + [self addTranslationsFromDictionary:[info selectorMap]]; + [self allowMethods:[info allowedMethods]]; + [self denyMethods:[info deniedMethods]]; +} + +- (NSDictionary *)selectorMap +{ + return selectorMap; +} + +- (void)removeTranslationForSelector:(NSString *)aString +{ + [selectorMap removeObjectForKey:aString]; +} + +- (void)setTranslation:(NSString *)translation + forSelector:(NSString *)selector +{ + [selectorMap setObject:translation forKey:selector]; +} + +- (void)addMethodsFromArray:(NSArray *)methods +{ + NSEnumerator *enumerator; + NSString *sel; + + enumerator = [methods objectEnumerator]; + while( (sel = [enumerator nextObject]) ) + { + [self setTranslation:sel forSelector:sel]; + } +} + +- (void)addTranslationsFromDictionary:(NSDictionary *)map +{ + [selectorMap addEntriesFromDictionary:map]; +} +- (void)allowMethods:(NSSet *)set +{ + [allowMethods unionSet:set]; + [denyMethods minusSet:allowMethods]; +} + +- (void)denyMethods:(NSSet *)set; +{ + [denyMethods unionSet:set]; + [allowMethods minusSet:denyMethods]; +} + +- (void)allowMethod:(NSString *)methodName; +{ + [allowMethods addObject:methodName]; + [denyMethods removeObject:methodName]; +} + +- (void)denyMethod:(NSString *)methodName; +{ + [denyMethods addObject:methodName]; + [allowMethods removeObject:methodName]; +} + +- (NSSet *)allowedMethods +{ + return AUTORELEASE([allowMethods copy]); +} + +- (NSSet *)deniedMethods +{ + return AUTORELEASE([denyMethods copy]); +} +@end diff --git a/Frameworks/StepTalk/STBundleInfo.h b/Frameworks/StepTalk/STBundleInfo.h new file mode 100644 index 0000000..95155c6 --- /dev/null +++ b/Frameworks/StepTalk/STBundleInfo.h @@ -0,0 +1,61 @@ +/** + STBundleInfo.h + Bundle scripting information + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2003 Jan 22 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + +#import + +@class NSArray; + +@interface STBundleInfo:NSObject +{ + NSBundle *bundle; + BOOL useAllClasses; + NSArray *publicClasses; + NSArray *allClasses; + NSDictionary *objectReferenceDictionary; + NSString *scriptingInfoClassName; + Class scriptingInfoClass; +} ++ infoForBundle:(NSBundle *)aBundle; +- initWithBundle:(NSBundle *)aBundle; + +- (NSDictionary *)objectReferenceDictionary; + +- (NSDictionary *)namedObjects; + +- (NSArray *)publicClassNames; +- (NSArray *)allClassNames; +@end + +@interface NSBundle(STAdditions) ++ (NSArray *)stepTalkBundleNames; ++ stepTalkBundleWithName:(NSString *)moduleName; +- (NSDictionary *)scriptingInfoDictionary; + ++ (NSArray *)allFrameworkNames; ++ (NSString *)pathForFrameworkWithName:(NSString *)aName; ++ (NSBundle *)bundleForFrameworkWithName:(NSString *)aName; +@end diff --git a/Frameworks/StepTalk/STBundleInfo.m b/Frameworks/StepTalk/STBundleInfo.m new file mode 100644 index 0000000..ccaa439 --- /dev/null +++ b/Frameworks/StepTalk/STBundleInfo.m @@ -0,0 +1,387 @@ +/** + STBundleInfo.h + Bundle scripting information + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2003 Jan 22 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + +#import + +#import +#import + +#import +#import +#import +#import +#import +#import +#import + +static NSMutableDictionary *bundleInfoDict; + +@protocol STScriptingInfoClass ++ (NSDictionary *)namedObjectsForScripting; +@end + +@interface STBundleInfo(STPrivateMethods) +- (void) _bundleDidLoad:(NSNotification *)notif; +- (void)_initializeScriptingInfoClass; +@end + +@implementation NSBundle(STAdditions) +/** Get list of all StepTalk bundles from Library/StepTalk/Bundles */ ++ (NSArray *)stepTalkBundleNames +{ + NSArray *bundles; + NSEnumerator *enumerator; + NSString *path; + NSMutableArray *names = [NSMutableArray array]; + NSString *name; + + bundles = STFindAllResources(@"Bundles", STModuleExtension); + + enumerator = [bundles objectEnumerator]; + + while( (path = [enumerator nextObject]) ) + { + name = [path lastPathComponent]; + name = [name stringByDeletingPathExtension]; + [names addObject:name]; + } + + bundles = STFindAllResources(@"Modules", STModuleExtension); + + enumerator = [bundles objectEnumerator]; + + while( (path = [enumerator nextObject]) ) + { + name = [path lastPathComponent]; + name = [name stringByDeletingPathExtension]; + [names addObject:name]; + } + + return AUTORELEASE([NSArray arrayWithArray:names]); +} + ++ stepTalkBundleWithName:(NSString *)moduleName +{ + NSString *file = STFindResource(moduleName, @"Bundles", + @"bundle"); + if(!file) + { + file = STFindResource(moduleName, STModulesDirectory, + STModuleExtension); + + if(!file) + { + NSLog(@"Could not find bundle with name '%@'", moduleName); + return nil; + } + } + + return AUTORELEASE([[self alloc] initWithPath:file]); +} +- (NSDictionary *)scriptingInfoDictionary +{ + NSFileManager *manager = [NSFileManager defaultManager]; + NSString *file; + + file = [self pathForResource:@"ScriptingInfo" ofType:@"plist"]; + + if([manager fileExistsAtPath:file]) + { + return [NSDictionary dictionaryWithContentsOfFile:file]; + } + else + { + return nil; + } +} +/** Return names of all available frameworks in the system. */ ++ (NSArray *)allFrameworkNames +{ + NSMutableArray *names = [NSMutableArray array]; + NSFileManager *manager = [NSFileManager defaultManager]; + NSArray *paths; + NSEnumerator *fenum; + NSEnumerator *penum; + NSString *path; + NSString *file; + NSString *name; + + paths = NSStandardLibraryPaths(); + + penum = [paths objectEnumerator]; + + while( (path = [penum nextObject]) ) + { + + path = [path stringByAppendingPathComponent:@"Frameworks"]; + + fenum = [[manager directoryContentsAtPath:path] objectEnumerator]; + + if( ![manager fileExistsAtPath:path isDirectory:NO] ) + { + continue; + } + + while( (file = [fenum nextObject]) ) + { + if( [[file pathExtension] isEqualToString:@"framework"] ) + { + name = [[file lastPathComponent] stringByDeletingPathExtension]; + [names addObject:name]; + } + } + } + + return names; +} + +/** Return path for framework with name aName. */ ++ (NSString *)pathForFrameworkWithName:(NSString *)aName +{ + NSMutableArray *names = [NSMutableArray array]; + NSFileManager *manager = [NSFileManager defaultManager]; + NSArray *paths; + NSEnumerator *fenum; + NSEnumerator *penum; + NSString *path; + NSString *file; + NSString *name; + + paths = NSStandardLibraryPaths(); + + penum = [paths objectEnumerator]; + + while( (path = [penum nextObject]) ) + { + + path = [path stringByAppendingPathComponent:@"Frameworks"]; + + fenum = [[manager directoryContentsAtPath:path] objectEnumerator]; + + if( ![manager fileExistsAtPath:path isDirectory:NO] ) + { + continue; + } + + while( (file = [fenum nextObject]) ) + { + if( [[file pathExtension] isEqualToString:@"framework"] ) + { + name = [[file lastPathComponent] stringByDeletingPathExtension]; + if([name isEqualToString:aName]) + { + return [path stringByAppendingPathComponent:file]; + } + } + } + } + + return nil; +} + +/** Return bundle for framework with name aName. */ ++ (NSBundle *)bundleForFrameworkWithName:(NSString *)aName +{ + return [self bundleWithPath:[self pathForFrameworkWithName:aName]];; +} + +@end + +@implementation STBundleInfo ++ infoForBundle:(NSBundle *)aBundle +{ + return AUTORELEASE([[self alloc] initWithBundle:aBundle]); +} +/** Initialize info with bundle aBundle. + + +*/ +- initWithBundle:(NSBundle *)aBundle +{ + STBundleInfo *info; + NSString *flagString; + NSDictionary *dict; + if(!aBundle) + { + [NSException raise:@"STBundleException" + format:@"Nil bundle specified"]; + [self dealloc]; + return nil; + } + + info = [bundleInfoDict objectForKey:[aBundle bundlePath]]; + + if(info) + { + [self dealloc]; + return RETAIN(info); + } + + dict = [aBundle scriptingInfoDictionary]; + + if(!dict) + { + NSLog(@"Warning: Bundle '%@' does not provide scripting capabilities.", + [aBundle bundlePath]); + [self dealloc]; + return nil; + } + + ASSIGN(bundle, aBundle); + +#if 0 + /* FIXME: remove observer somewhere */ + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector(_bundleDidLoad:) + name:NSBundleDidLoadNotification + object:self]; +#endif + + flagString = [dict objectForKey:@"UseAllClasses"]; + flagString = [flagString lowercaseString]; + + useAllClasses = [flagString isEqualToString:@"yes"]; + + if([dict objectForKey: @"STClasses"]) + { + NSLog(@"WARNING: Use 'Classes' instead of 'STClasses' in " + @"ScriptingInfo.plist for bundle '%@'", [aBundle bundlePath]); + + publicClasses = [dict objectForKey:@"STClasses"]; + } + else + { + publicClasses = [dict objectForKey:@"Classes"]; + } + RETAIN(publicClasses); + + + if([dict objectForKey: @"STScriptingInfoClass"]) + { + NSLog(@"WARNING: Use 'ScriptingInfoClass' instead of 'STScriptingInfoClass' in " + @"ScriptingInfo.plist for bundle '%@'", [aBundle bundlePath]); + + scriptingInfoClassName = [dict objectForKey:@"STScriptingInfoClass"]; + } + else + { + scriptingInfoClassName = [dict objectForKey:@"ScriptingInfoClass"]; + } + RETAIN(scriptingInfoClassName); + + objectReferenceDictionary = [dict objectForKey:@"Objects"]; + + if(!bundleInfoDict) + { + bundleInfoDict = [[NSMutableDictionary alloc] init]; + } + + [bundleInfoDict setObject:self forKey:[bundle bundlePath]]; + + return self; +} + +- (void) _bundleDidLoad:(NSNotification *)notif +{ + NSLog(@"Module '%@' loaded", [bundle bundlePath]); + + if([notif object] != self) + { + NSLog(@"STBundle: That's not me!"); + return; + } + + allClasses = [[notif userInfo] objectForKey:NSLoadedClasses]; + RETAIN(allClasses); + + NSLog(@"All classes are %@"); +} + +- (NSArray *)publicClassNames +{ + if(useAllClasses) + { + if(!allClasses) + { + [self _initializeScriptingInfoClass]; + } + return allClasses; + } + else + { + return publicClasses; + } +} + +/** Return an array of all class names. */ +- (NSArray *)allClassNames +{ + /* FIXME: not implemented; */ + NSLog(@"Warning: All bundle classes requested, using public classes only."); + return publicClasses; +} + +/** Return a dictionary of named objects. Named objects are get from scripting + info class specified in ScriptingInfo.plist.*/ +- (NSDictionary *)namedObjects +{ + if(!scriptingInfoClass) + { + [self _initializeScriptingInfoClass]; + } + + return [(id)scriptingInfoClass namedObjectsForScripting]; +} + +- (void)_initializeScriptingInfoClass +{ + scriptingInfoClass = [bundle classNamed:scriptingInfoClassName]; + + if(!scriptingInfoClass) + { + NSDebugLog(@"No scripting info class for bundle '%@'",[bundle bundlePath]); +#if 0 + [NSException raise:@"STBundleException" + format:@"Unable to get scripting info class '%@' for " + @"bundle '%@'", + scriptingInfoClassName, [bundle bundlePath]]; + +#endif + } +} + +/** This method is for application scripting support. Return dictionary + containing object references where a key is name of an object and + value is a path to the object relative to application delegate. +*/ +- (NSDictionary *)objectReferenceDictionary +{ + return objectReferenceDictionary; +} + +@end diff --git a/Frameworks/StepTalk/STClassInfo.h b/Frameworks/StepTalk/STClassInfo.h new file mode 100644 index 0000000..9500294 --- /dev/null +++ b/Frameworks/StepTalk/STClassInfo.h @@ -0,0 +1,51 @@ +/** + STClassInfo.h + Objective-C class wrapper + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + +#import + +@class NSString; +@class NSMutableDictionary; + +@interface STClassInfo:STBehaviourInfo +{ + STClassInfo *superclass; + NSString *superclassName; + BOOL allowAll; + + NSMutableDictionary *selectorCache; +} +- (NSString *)translationForSelector:(NSString *)aString; + +- (void)setSuperclassInfo:(STClassInfo *)classInfo; +- (STClassInfo *)superclassInfo; + +- (void)setSuperclassName:(NSString *)aString; +- (NSString *)superclassName; + +- (void)setAllowAllMethods:(BOOL)flag; +- (BOOL)allowAllMethods; +@end diff --git a/Frameworks/StepTalk/STClassInfo.m b/Frameworks/StepTalk/STClassInfo.m new file mode 100644 index 0000000..00ba1f2 --- /dev/null +++ b/Frameworks/StepTalk/STClassInfo.m @@ -0,0 +1,140 @@ +/** + STClassInfo.m + Objective-C class wrapper + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + +#import + +#import + +#import +#import +#import +#import +#import + +@implementation STClassInfo +- initWithName:(NSString *)aString + +{ + [super initWithName:aString]; + + selectorCache = [[NSMutableDictionary alloc] init]; + + return self; +} + +- (void)dealloc +{ + RELEASE(selectorCache); + [super dealloc]; +} + +- (void)setSuperclassInfo:(STClassInfo *)classInfo +{ + ASSIGN(superclass,classInfo); +} + +- (STClassInfo *)superclassInfo +{ + return superclass; +} +- (void) setSuperclassName:(NSString *)aString +{ + ASSIGN(superclassName,aString); +} +- (NSString *)superclassName +{ + return superclassName; +} + +- (NSString *)translationForSelector:(NSString *)aString +{ + + NSString *sel; + + NSDebugLLog(@"STSending",@"Translate '%@' in %@:%@. (%i)", + aString, [self behaviourName],superclassName, allowAll); + + sel = [selectorCache objectForKey:aString]; + + if(sel) + { + return sel; + } + + sel = [selectorMap objectForKey:aString]; + + if(!sel) + { + /* Lookup for super selector maping */ + if(superclass) + { + sel = [superclass translationForSelector:aString]; + + if(sel && + ([denyMethods containsObject:sel] || + (!allowAll && ![allowMethods containsObject:sel]))) + { + sel = nil; + } + else if([allowMethods containsObject:aString]) + { + sel = aString; + } + } + else if(allowAll || [allowMethods containsObject:aString]) + { + sel = aString; + } + + NSDebugLLog(@"STSending",@" translated '%@' deny %i allow %i all %i", + sel, [denyMethods containsObject:sel], + [allowMethods containsObject:sel], + allowAll); + + } + + NSDebugLLog(@"STSending",@" Return '%@' (%@)", + sel, [self behaviourName]); + if(sel) + { + [selectorCache setObject:sel forKey:aString]; + } + + return sel; +} + +- (void)setAllowAllMethods:(BOOL)flag +{ + allowAll = flag; +} + +- (BOOL)allowAllMethods +{ + return allowAll; +} +@end + diff --git a/Frameworks/StepTalk/STEngine.h b/Frameworks/StepTalk/STEngine.h new file mode 100644 index 0000000..6273fc8 --- /dev/null +++ b/Frameworks/StepTalk/STEngine.h @@ -0,0 +1,64 @@ +/** + STEngine.h + Scripting engine + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + +#import +#import + +@class STEnvironment; +@class STLanguageEngine; +@class STMethod; + +/** STEngine is abstract class for language engines used to intepret scripts.*/ +@interface STEngine:NSObject +{ + STEnvironment *defaultEnvironment; +} + +/** Instance creation */ ++ (STEngine *) engineForLanguageWithName:(NSString *)name; ++ (STEngine *) engineForFileType:(NSString *)fileType; + +/** Scripting Environment */ +- (STEnvironment *)defaultEnvironment; +- (void) setDefaultEnvironment:(STEnvironment *)anEnvironment; + +- (id) executeCode:(NSString *)code; + +- (id) executeCode:(NSString *)code + inEnvironment:(STEnvironment *)env; + +- (BOOL)understandsCode:(NSString *)code; + +/* Methods */ +- (STMethod *)methodFromSource:(NSString *)sourceString + forReceiver:(id)receiver + inEnvironment:(STEnvironment *)env; +- (id) executeMethod:(id )aMethod + forReceiver:(id)anObject + withArguments:(NSArray *)args + inEnvironment:(STEnvironment *)env; +@end diff --git a/Frameworks/StepTalk/STEngine.m b/Frameworks/StepTalk/STEngine.m new file mode 100644 index 0000000..5375421 --- /dev/null +++ b/Frameworks/StepTalk/STEngine.m @@ -0,0 +1,149 @@ +/** + STEngine.m + Scripting engine + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + +#import + +#import +#import +#import +#import +#import + +#import +#import + +NSZone *STMallocZone = NULL; + +void _STInitMallocZone(void) +{ + if(!STMallocZone) + { + STMallocZone = NSCreateZone(NSPageSize(),NSPageSize(),NO); + } + +} + +@implementation STEngine ++ (void)initialize +{ + _STInitMallocZone(); + + if(!STNil) + { + STNil = (STUndefinedObject *)NSAllocateObject([STUndefinedObject class], + 0, STMallocZone); + } +} + +/** + Return a scripting engine for the language used in files of type + fileType +*/ ++ (STEngine *) engineForFileType:(NSString *)fileType +{ + STLanguage *language = [STLanguage languageForFileType:fileType]; + + return [language engine]; +} + +/** + Return a scripting engine for language with specified name. +*/ ++ (STEngine *) engineForLanguageWithName:(NSString *)name +{ + if(!name) + { + NSLog(@"No language name given"); + return NULL; + } + + return [[STLanguage languageWithName:name] engine]; +} + +- (void)dealloc +{ + RELEASE(defaultEnvironment); + + [super dealloc]; +} + +/** Return the default scripting environment for the engine. */ +- (STEnvironment *)defaultEnvironment +{ + return defaultEnvironment; +} + +/** Set the default scripting environment for the engine. */ +- (void) setDefaultEnvironment:(STEnvironment *)anEnvironment +{ + ASSIGN(defaultEnvironment,anEnvironment); +} + +/** Execude source code code in default scripting environment. */ +- (id) executeCode:(NSString *)code +{ + return [self executeCode:code + inEnvironment:defaultEnvironment]; +} + +/** Execude source code code in an environment env. + This is the method, that has to be implemented by those who are writing + a language engine. + +*/ +- (id) executeCode:(NSString *)code + inEnvironment:(STEnvironment *)env +{ + [self subclassResponsibility:_cmd]; + + return nil; +} + +- (BOOL)understandsCode:(NSString *)code +{ + [self subclassResponsibility:_cmd]; + + return NO; +} + +- (STMethod *)methodFromSource:(NSString *)sourceString + forReceiver:(id)receiver + inEnvironment:(STEnvironment *)env +{ + [self subclassResponsibility:_cmd]; + return nil; +} +- (id) executeMethod:(id )aMethod + forReceiver:(id)anObject + withArguments:(NSArray *)args + inEnvironment:(STEnvironment *)env; +{ + [self subclassResponsibility:_cmd]; + return nil; +} + +@end diff --git a/Frameworks/StepTalk/STEnvironment.h b/Frameworks/StepTalk/STEnvironment.h new file mode 100644 index 0000000..9e3e2f1 --- /dev/null +++ b/Frameworks/StepTalk/STEnvironment.h @@ -0,0 +1,104 @@ +/** + STEnvironment + Scripting environment + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + STEnvironment class reference + + */ + +#import + +@class NSBundle; +@class NSDictionary; +@class NSMutableDictionary; +@class NSMutableArray; +@class NSMutableSet; + +@class STObjectReference; +@class STEnvironmentDescription; + +@interface STEnvironment:NSObject +{ + NSMutableDictionary *defaultPool; + + STEnvironmentDescription *description; + NSMutableDictionary *classes; /* from description */ + + BOOL fullScripting; + BOOL createsUnknownObjects; + + NSMutableDictionary *infoCache; + + NSMutableDictionary *objectFinders; + + NSMutableArray *loadedBundles; +} +/** Creating environment */ ++ (STEnvironment *)defaultScriptingEnvironment; + ++ environmentWithDescriptionName:(NSString *)descName; ++ environmentWithDescription:(STEnvironmentDescription *)aDescription; + +- initDefault; +- initWithDescriptionName:(NSString *)descName; +- initWithDescription:(STEnvironmentDescription *)aDescription; + +/** Full scripting */ + +- (void)setFullScriptingEnabled:(BOOL)flag; +- (BOOL)fullScriptingEnabled; + +-(void)setCreatesUnknownObjects:(BOOL)flag; +-(BOOL)createsUnknownObjects; + +/** Modules */ + +- (void)loadModule:(NSString *)moduleName; + +- (void)includeFramework:(NSString *)frameworkName; +- (BOOL)includeBundle:(NSBundle *)aBundle; + +- (void)addClassesWithNames:(NSArray *)names; + +/** Named objects and object references */ + +- (NSMutableDictionary *)objectDictionary; +- (void)setObject:(id)anObject + forName:(NSString *)objName; +- (void)removeObjectWithName:(NSString *)objName; +- (void)addNamedObjectsFromDictionary:(NSDictionary *)dict; +- (id)objectWithName:(NSString *)objName; + +- (STObjectReference *)objectReferenceForObjectWithName:(NSString *)name; + +/** Distributed objects */ +- (void)registerObjectFinder:(id)finder name:(NSString*)name; +- (void)registerObjectFinderNamed:(NSString *)name; +- (void)removeObjectFinderWithName:(NSString *)name; +- (NSArray *)knownObjectNames; + +/** Selector translation */ + +- (NSString *)translateSelector:(NSString *)aString forReceiver:(id)anObject; +@end diff --git a/Frameworks/StepTalk/STEnvironment.m b/Frameworks/StepTalk/STEnvironment.m new file mode 100644 index 0000000..ed69b89 --- /dev/null +++ b/Frameworks/StepTalk/STEnvironment.m @@ -0,0 +1,617 @@ +/** + STEnvironment + Scripting environment + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + STEnvironment class reference + + */ + +#import + +#import +#import +#import +#import +#import +#import +#import +#import +#import + +#import +#import +#import +#import +#import +#import +#import +#import + +@interface STEnvironment(STPrivateMethods) +- (STClassInfo *)findClassInfoForObject:(id)anObject; +@end + +@implementation STEnvironment +/** + Creates and initialises scripting environment using standard description. + */ ++ (STEnvironment *)defaultScriptingEnvironment +{ + NSString *name; + + name = [STEnvironmentDescription defaultEnvironmentDescriptionName]; + + return [self environmentWithDescriptionName:name]; +} + +/** + Creates and initialises scripting environment using description with name + descName. + */ ++ environmentWithDescriptionName:(NSString *)descName +{ + return AUTORELEASE([[self alloc] initWithDescriptionName:descName]); +} + +/** + Creates and initialises scripting environment using environment description + description. + */ ++ environmentWithDescription:(STEnvironmentDescription *)aDescription +{ + return AUTORELEASE([[self alloc] initWithDescription:aDescription]); +} + +/** + Initialises scripting environment using default description. + + + */ +- initDefault +{ + NSString *name; + + name = [STEnvironmentDescription defaultEnvironmentDescriptionName]; + + return [self initWithDescriptionName:name]; +} +/** + Initialises scripting environment using description with name + descName. + + + */ +- initWithDescriptionName:(NSString *)descName +{ + return [self initWithDescription: + [STEnvironmentDescription descriptionWithName:descName]]; +} + +/** + Initialises scripting environment using scripting description + aDescription. + */ +- initWithDescription:(STEnvironmentDescription *)aDescription +{ + NSEnumerator *enumerator; + NSString *name; + + self = [super init]; + + defaultPool = [[NSMutableDictionary alloc] init]; + infoCache = [[NSMutableDictionary alloc] init]; + + description = RETAIN(aDescription); + classes = [description classes]; + + /* Load modules */ + enumerator = [[description modules] objectEnumerator]; + + while( (name = [enumerator nextObject]) ) + { + [self loadModule:name]; + } + + /* Register finders */ + enumerator = [[description objectFinders] objectEnumerator]; + + while( (name = [enumerator nextObject]) ) + { + [self registerObjectFinderNamed:name]; + } + + RETAIN(description); + + return self; +} + +- (void)dealloc +{ + RELEASE(defaultPool); + RELEASE(description); + + RELEASE(infoCache); + RELEASE(objectFinders); + RELEASE(loadedBundles); + + [super dealloc]; +} + +/** + Enable or disable full scripting. When full scripting is enabled, + you may send any message to any object. + */ +- (void)setFullScriptingEnabled:(BOOL)flag +{ + fullScripting = flag; +} + +/** + Returns YES if full scripting is enabled. + */ +- (BOOL)fullScriptingEnabled +{ + return fullScripting; +} + +/** +

    + Enable or disable creation of unknown objects. Normally you get nil if you + request for non-existant object. If flag is YES + then by requesting non-existant object, name for that object is created + and it is set no STNil. +

    +

    + Note: This method will be probably removed (moved to Smalltalk language bundle). +

    + */ +-(void)setCreatesUnknownObjects:(BOOL)flag +{ + createsUnknownObjects = flag; +} + +/** + Returns YES if unknown objects are being created. + */ +-(BOOL)createsUnknownObjects +{ + return createsUnknownObjects; +} + +/** + Add classes specified by the names in the names array. + This method is used internally to add classes provided by modules. +*/ +- (void)addClassesWithNames:(NSArray *)names +{ + [self addNamedObjectsFromDictionary:STClassDictionaryWithNames(names)]; +} + +/** + Load StepTalk module with the name moduleName. Modules are stored + in the Library/StepTalk/Modules directory. + */ + +- (void) loadModule:(NSString *)moduleName +{ + NSBundle *bundle; + + bundle = [NSBundle stepTalkBundleWithName:moduleName]; + + [self includeBundle:bundle]; +} + +/** + Include scripting capabilities advertised by the framework with name + frameworkName. If the framework is already loaded, nothing + happens. +*/ +- (BOOL)includeFramework:(NSString *)frameworkName +{ + NSBundle *bundle; + + bundle = [NSBundle bundleForFrameworkWithName:frameworkName]; + + if(!bundle) + { + return NO; + } + + return [self includeBundle:bundle]; +} + +/** + Include scripting capabilities advertised by the bundle + aBundle. If the bundle is already loaded, nothing + happens. +*/ +- (BOOL)includeBundle:(NSBundle *)aBundle +{ + STBundleInfo *info; + + /* Ignore already included bundles. */ + if([loadedBundles containsObject:[aBundle bundlePath]]) + { + NSDebugLog(@"Bundle '%@' already included.", [aBundle bundlePath]); + return; + } + + info = [STBundleInfo infoForBundle:aBundle]; + + if(!info) + { + return NO; + } + + [self addNamedObjectsFromDictionary:[info namedObjects]]; + + [self addClassesWithNames:[info publicClassNames]]; + + if(!loadedBundles) + { + loadedBundles = [[NSMutableArray alloc] init]; + } + + /* FIXME: is this sufficient? */ + [loadedBundles addObject:[aBundle bundlePath]]; + + return YES; +} + +/** + Returns a dictionary of all named objects in the environment. +*/ +- (NSMutableDictionary *)objectDictionary +{ + return defaultPool; +} + +/* ----------------------------------------------------------------------- + Objects + ----------------------------------------------------------------------- */ + +/** + Register object anObject with name objName. + */ + +- (void)setObject:(id)anObject + forName:(NSString *)objName +{ + if(anObject) + { + [defaultPool setObject:anObject forKey:objName]; + } + else + { + [defaultPool setObject:STNil forKey:objName]; + } +} + +/** + Remove object named objName. + */ +- (void)removeObjectWithName:(NSString *)objName +{ + [defaultPool removeObjectForKey:objName]; +} + +/** + + */ +- (void)addNamedObjectsFromDictionary:(NSDictionary *)dict +{ + [defaultPool addEntriesFromDictionary:dict]; +} + +/** + Return object with name objName. If object is not found int the + object dictionary, then object finders are used to try to find the object. + If object is found by an object finder, then it is put into the object + dicitonary. If there is no object with given name, nil is + returned. + */ + +- (id)objectWithName:(NSString *)objName +{ + NSEnumerator *enumerator; + id obj; + id finder; + + obj = [defaultPool objectForKey:objName]; + + if(!obj) + { + enumerator = [objectFinders objectEnumerator]; + while( (finder = [enumerator nextObject]) ) + { + obj = [finder objectWithName:objName]; + if(obj) + { + [defaultPool setObject:obj forKey:objName]; + break; + } + } + } + + return obj; +} + +- (STObjectReference *)objectReferenceForObjectWithName:(NSString *)name +{ + STObjectReference *ref; + id pool = defaultPool; + + if( ![self objectWithName:name] ) + { + if([[self knownObjectNames] containsObject:name]) + { + pool = nil; + } + else if(createsUnknownObjects) + { + [defaultPool setObject:STNil forKey:name]; + } + } + + ref = [STObjectReference alloc]; + + [ref initWithObjectName:name + pool:defaultPool]; + + return AUTORELEASE(ref); +} + +/* FIXME: rewrite, it is too sloooooow */ +- (STClassInfo *)findClassInfoForObject:(id)anObject +{ + STClassInfo *info = nil; + NSString *className; + NSString *origName; + Class class; + + if(!anObject) + { + anObject = STNil; + } + + /* FIXME: temporary solution */ + if( [anObject isProxy] ) + { + NSDebugLog(@"FIXME: receiver is a distant object"); + info = [classes objectForKey:@"NSProxy"]; + + if(!info) + { + return [classes objectForKey:@"All"]; + } + + return info; + } + + if([anObject respondsToSelector:@selector(classForScripting)]) + { + class = [anObject classForScripting]; + } + else + { + class = [anObject class]; + } + + className = [anObject className]; + + if([anObject isClass]) + { + origName = className = [className stringByAppendingString:@" class"]; + + NSDebugLLog(@"STSending", + @"Looking for class info '%@'...", + className); + + info = [infoCache objectForKey:className]; + + if(info) + { + return info; + } + + while( !(info = [classes objectForKey:className]) ) + { + class = [class superclass]; + + if(!class) + { + break; + } + + className = [[class className] stringByAppendingString:@" class"]; + NSDebugLLog(@"STSending", + @" ... %@?",className); + } + } + else + { + origName = className; + + NSDebugLLog(@"STSending", + @"Looking for class info '%@' (instance)...", + className); + + info = [infoCache objectForKey:className]; + if(info) + { + return info; + } + + while( !(info = [classes objectForKey:className]) ) + { + class = [class superclass]; + if(!class) + { + break; + } + className = [class className]; + NSDebugLLog(@"STSending", + @" ... %@?",className); + } + } + + if(!info) + { + NSDebugLLog(@"STSending", + @"No class info '%@'", + className); + return nil; + } + + NSDebugLLog(@"STSending", + @"Found class info '%@'", + className); + + [infoCache setObject:info forKey:origName]; + return info; +} + +- (NSString *)translateSelector:(NSString *)aString forReceiver:(id)anObject +{ + STClassInfo *class; + NSString *selector; + + class = [self findClassInfoForObject:anObject]; + + NSDebugLLog(@"STSending", + @"Lookup selector '%@' class %@", aString, [class behaviourName]); + + selector = [class translationForSelector:aString]; + + NSDebugLLog(@"STSending", + @"Found selector '%@'",selector); + +#ifdef DEBUG + if(! [selector isEqualToString:aString]) + { + NSDebugLLog(@"STSending", + @"using selector '%@' instead of '%@'", + selector,aString); + } +#endif + + if(!selector && fullScripting ) + { + NSDebugLLog(@"STSending", + @"using selector '%@' (full scriptig)", + aString); + + selector = AUTORELEASE([aString copy]); + } + + if(!selector) + { + [NSException raise:STScriptingException + format:@"Receiver of type %@ denies selector '%@'", + [anObject className],aString]; + + /* if exception is ignored, then try to use original selector */ + selector = AUTORELEASE([aString copy]); + } + + + return selector; +} + +- (NSArray *)knownObjectNames +{ + NSMutableArray *array = [NSMutableArray array]; + NSEnumerator *enumerator; + id finder; + + [array addObjectsFromArray:[defaultPool allKeys]]; + + enumerator = [objectFinders objectEnumerator]; + while( (finder = [enumerator nextObject]) ) + { + [array addObjectsFromArray:[finder knownObjectNames]]; + } + + return [NSArray arrayWithArray:array]; +} + +/** Register object finder finder under the name name */ +- (void)registerObjectFinder:(id)finder name:(NSString*)name +{ + if(!objectFinders) + { + objectFinders = [[NSMutableDictionary alloc] init]; + } + + [objectFinders setObject:finder forKey:name]; +} + +/** Register object finder named name. This method will try to find + an object finder bundle in Library/StepTalk/Finders directories. +*/ +- (void)registerObjectFinderNamed:(NSString *)name +{ + NSBundle *bundle; + NSString *path; + id finder; + + if([objectFinders objectForKey:name]) + { + return; + } + + path = STFindResource(name, @"Finders", @"bundle"); + + if(!path) + { + NSLog(@"Unknown object finder with name '%@'", name); + return; + } + + NSDebugLog(@"Finder '%@'", path); + + bundle = [NSBundle bundleWithPath:path]; + if(!bundle) + { + NSLog(@"Unable to load object finder bundle '%@'", path); + return; + } + + finder = [[[bundle principalClass] alloc] init]; + if(!finder) + { + NSLog(@"Unable to create object finder from '%@'", path); + return; + } + + [self registerObjectFinder:finder name:name]; +} + +/** Remove object finder with name name */ +- (void)removeObjectFinderWithName:(NSString *)name +{ + [objectFinders removeObjectForKey:name]; +} + +@end diff --git a/Frameworks/StepTalk/STEnvironmentDescription.h b/Frameworks/StepTalk/STEnvironmentDescription.h new file mode 100644 index 0000000..8e56126 --- /dev/null +++ b/Frameworks/StepTalk/STEnvironmentDescription.h @@ -0,0 +1,66 @@ +/** + STEnvironmentDescription.h + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 Jun 16 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + +#import + +enum +{ + STUndefinedRestriction, + STAllowAllRestriction, + STDenyAllRestriction +}; + +@class NSDictionary; +@class NSMutableArray; +@class NSMutableDictionary; + +@interface STEnvironmentDescription:NSObject +{ + NSMutableArray *usedDefs; + NSMutableDictionary *classes; + NSMutableDictionary *behaviours; + NSMutableDictionary *aliases; + NSMutableArray *modules; + NSMutableArray *finders; + + int restriction; +} ++ (NSString *)defaultEnvironmentDescriptionName; + ++ descriptionWithName:(NSString *)descriptionName; ++ descriptionFromDictionary:(NSDictionary *)dictionary; + +- initWithName:(NSString *)defName; +- initFromDictionary:(NSDictionary *)def; + +- (void)updateFromDictionary:(NSDictionary *)def; +- (void)updateClassWithName:(NSString *)className description:(NSDictionary *)def; + +- (NSMutableDictionary *)classes; +- (NSArray *)modules; +- (NSArray *)objectFinders; +@end + diff --git a/Frameworks/StepTalk/STEnvironmentDescription.m b/Frameworks/StepTalk/STEnvironmentDescription.m new file mode 100644 index 0000000..885b3c0 --- /dev/null +++ b/Frameworks/StepTalk/STEnvironmentDescription.m @@ -0,0 +1,495 @@ +/** + STEnvironmentDescription.m + Compiled scripting environment description + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 Jun 16 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + +#import + +#import +#import +#import +#import + +#import +#import +#import +#import +#import +#import +#import + +static NSDictionary *dictForDescriptionWithName(NSString *defName) +{ + NSString *file; + NSDictionary *dict; + + file = STFindResource(defName, + STScriptingEnvironmentsDirectory, + STScriptingEnvironmentExtension); + + if(!file) + { + [NSException raise:STGenericException + format: @"Could not find " + @"environment description with name '%@'.", + defName]; + return nil; + } + + dict = [NSDictionary dictionaryWithContentsOfFile:file]; + + if(!dict) + { + [NSException raise:STGenericException + format:@"Error while opening " + @"environment description with name '%@'.", + defName]; + + return nil; + } + + return dict; +} + +@interface STEnvironmentDescription(PrivateMethods) +- (void)updateFromDictionary:(NSDictionary *)def; +- (void)updateUseListFromDictionary:(NSDictionary *)def; +- (void)updateBehavioursFromDictionary:(NSDictionary *)aDict; +- (void)updateBehaviour:(STBehaviourInfo *)behInfo + description:(NSDictionary *)def; +- (void)updateClassesFromDictionary:(NSDictionary *)def; +- (void)updateClassWithName:(NSString *)className description:(NSDictionary *)def; +- (void)updateAliasesFromDictionary:(NSDictionary *)def; +- (void)fixupScriptingDescription; +- (void)resolveSuperclasses; + +- (void)updateUseList:(NSArray *)array; +- (void)updateModuleList:(NSArray *)array; +- (void)updateFinderList:(NSArray *)array; +@end + +@implementation STEnvironmentDescription ++ (NSString *)defaultEnvironmentDescriptionName +{ + NSUserDefaults *defs; + NSString *name; + + defs = [NSUserDefaults standardUserDefaults]; + name = [defs objectForKey:@"STDefaultEnvironmentDescriptionName"]; + + if(!name || [name isEqualToString:@""]) + { + name = [NSString stringWithString:@"Standard"]; + } + + return name; +} + ++ descriptionWithName:(NSString *)descriptionName +{ + return AUTORELEASE([[self alloc] initWithName:descriptionName]); +} ++ descriptionFromDictionary:(NSDictionary *)dictionary +{ + return AUTORELEASE([[self alloc] initFromDictionary:dictionary]); +} +- (void)dealloc +{ + RELEASE(usedDefs); + RELEASE(classes); + RELEASE(behaviours); + RELEASE(aliases); + RELEASE(modules); + RELEASE(finders); + + [super dealloc]; +} + +- initWithName:(NSString *)defName; +{ + return [self initFromDictionary:dictForDescriptionWithName(defName)]; +} + +- initFromDictionary:(NSDictionary *)def +{ + if(!def) + { + [self dealloc]; + return nil; + } + + [self updateFromDictionary:def]; + [self fixupScriptingDescription]; + + return self; +} + +- (void)updateFromDictionary:(NSDictionary *)def +{ + NSString *str; + BOOL saveFlag = restriction; + + if(!def) + { + NSLog(@"Warning: nil dictionary for environmet description update"); + return; + }; + + str = [def objectForKey:@"DefaultRestriction"]; + + if(str) + { + str = [str lowercaseString]; + + if([str isEqualToString:@"allowall"]) + { + restriction = STAllowAllRestriction; + } + else if([str isEqualToString:@"denyall"]) + { + restriction = STDenyAllRestriction; + } + else + { + [NSException raise:STGenericException + format:@"Invalid default restriction rule '%@'.", + str]; + return; + } + } + + [self updateUseList:[def objectForKey:@"Use"]]; + [self updateModuleList:[def objectForKey:@"Modules"]]; + [self updateFinderList:[def objectForKey:@"Finders"]]; + [self updateBehavioursFromDictionary:[def objectForKey:@"Behaviours"]]; + [self updateClassesFromDictionary:[def objectForKey:@"Classes"]]; + [self updateAliasesFromDictionary:[def objectForKey:@"Aliases"]]; + + restriction = saveFlag; +} + +- (void)updateUseList:(NSArray *)array +{ + NSEnumerator *enumerator; + NSString *str; + + enumerator = [array objectEnumerator]; + + while( (str = [enumerator nextObject]) ) + { + if(!usedDefs) + { + usedDefs = [[NSMutableArray alloc] init]; + } + + if( ![usedDefs containsObject:str] ) + { + [usedDefs addObject:str]; + [self updateFromDictionary:dictForDescriptionWithName(str)]; + } + + } +} + +- (void)updateModuleList:(NSArray *)array +{ + NSEnumerator *enumerator; + NSString *str; + + enumerator = [array objectEnumerator]; + + while( (str = [enumerator nextObject]) ) + { + if(!modules) + { + modules = [[NSMutableArray alloc] init]; + } + + if( ![modules containsObject:str] ) + { + [modules addObject:str]; + } + } +} + +- (void)updateFinderList:(NSArray *)array +{ + NSEnumerator *enumerator; + NSString *str; + + enumerator = [array objectEnumerator]; + + while( (str = [enumerator nextObject]) ) + { + if(!finders) + { + finders = [[NSMutableArray alloc] init]; + } + + if( ![finders containsObject:str] ) + { + [finders addObject:str]; + } + } +} + +- (void)updateBehavioursFromDictionary:(NSDictionary *)dict +{ + NSEnumerator *enumerator; + NSString *name; + + STBehaviourInfo *behInfo; + + enumerator = [dict keyEnumerator]; + + while( (name = [enumerator nextObject]) ) + { + if([behaviours objectForKey:name]) + { + [NSException raise:STGenericException + format:@"Behaviour '%@' defined more than once.", + name]; + return; + } + + if(!behaviours) + { + behaviours = [[NSMutableDictionary alloc] init]; + } + + behInfo = [[STBehaviourInfo alloc] initWithName:name]; + [behaviours setObject:behInfo forKey:name]; + + [self updateBehaviour:behInfo description:[dict objectForKey:name]]; + } + +} + +- (void)updateBehaviour:(STBehaviourInfo *)behInfo + description:(NSDictionary *)def +{ + NSString *str; + NSEnumerator *enumerator; + STBehaviourInfo *useInfo; + + + enumerator = [[def objectForKey:@"Use"] objectEnumerator]; + while( (str = [enumerator nextObject]) ) + { + useInfo = [behaviours objectForKey:str]; + if(!useInfo) + { + [NSException raise:STGenericException + format:@"Undefined behaviour '%@'.", + str]; + return; + } + + [behInfo adopt:useInfo]; + } + + [behInfo allowMethods:[NSSet setWithArray:[def objectForKey:@"AllowMethods"]]]; + [behInfo denyMethods:[NSSet setWithArray:[def objectForKey:@"DenyMethods"]]]; + + [behInfo addTranslationsFromDictionary:[def objectForKey:@"SymbolicSelectors"]]; + + [behInfo addTranslationsFromDictionary:[def objectForKey:@"Aliases"]]; +} + +- (void)updateClassesFromDictionary:(NSDictionary *)dict +{ + NSEnumerator *enumerator; + NSString *str; + + enumerator = [dict keyEnumerator]; + + while( (str = [enumerator nextObject]) ) + { + [self updateClassWithName:str + description:[dict objectForKey:str]]; + } + +} + +- (void)updateClassWithName:(NSString *)className description:(NSDictionary *)def +{ + STClassInfo *class; + NSString *superName; + NSString *flag; + NSString *str; + + BOOL newClass = NO; + + if(!classes) + { + classes = [[NSMutableDictionary alloc] init]; + } + + class = [classes objectForKey:className]; + + if( !class ) + { + class = [[STClassInfo alloc] initWithName:className]; + [classes setObject:class forKey:className]; + newClass = YES; + } + + str = [def objectForKey:@"Super"]; + superName = [class superclassName]; + + if(str && (![str isEqualToString:superName])) + { + if(newClass | (superName == nil)) + { + [class setSuperclassName:str]; + } + else + { + [NSException raise:STGenericException + format:@"Trying to change superclass of '%@' " + @"from '%@' to '%@'", + className,[class superclassName],str]; + return; + } + } + + [self updateBehaviour:class description:def]; + + flag = [def objectForKey:@"Restriction"]; + + NSDebugLLog(@"STEnvironment", @"Class %@ restriction %@ (default %i)", + className, flag, restriction); + + if(flag) + { + flag = [flag lowercaseString]; + + if([flag isEqualToString:@"allowall"]) + { + [class setAllowAllMethods:YES]; + } + else if([flag isEqualToString:@"denyall"]) + { + [class setAllowAllMethods:NO]; + } + else + { + [NSException raise:STGenericException + format:@"Invalid method restriction rule '%@'.", + flag]; + return; + } + } + else + { + if(restriction == STAllowAllRestriction) + { + [class setAllowAllMethods:YES]; + } + else if (restriction == STDenyAllRestriction) + { + [class setAllowAllMethods:NO]; + } + } +} + +- (void)updateAliasesFromDictionary:(NSDictionary *)dict +{ + NSEnumerator *enumerator; + NSString *str; + + enumerator = [dict keyEnumerator]; + + while( (str = [enumerator nextObject]) ) + { + [aliases setObject:str forKey:[dict objectForKey:str]]; + } +} + +- (NSMutableDictionary *)classes +{ + return classes; +} + +- (NSArray *)modules +{ + return [NSArray arrayWithArray:modules]; +} + +- (NSArray *)objectFinders +{ + return [NSArray arrayWithArray:finders]; +} + + +- (void)fixupScriptingDescription +{ + [self resolveSuperclasses]; +} + +- (void)resolveSuperclasses +{ + NSEnumerator *enumerator; + STClassInfo *superclass; + STClassInfo *class; + NSString *className; + + enumerator = [classes objectEnumerator]; + + while( (class = [enumerator nextObject]) ) + { + if([[class behaviourName] isEqualToString:@"All"]) + { + continue; + } + + className = [class superclassName]; + + if( (className == nil) || [className isEqualToString:@"nil"] ) + { + superclass = [classes objectForKey:@"All"]; + + if(!superclass) + { + continue; + } + } + else + { + superclass = [classes objectForKey:className]; + } + + if(!superclass) + { + [NSException raise:STGenericException + format:@"Resolving superclasses: " + @"Could not find class '%@'.", className]; + return; + } + + [class setSuperclassInfo:superclass]; + } +} +@end diff --git a/Frameworks/StepTalk/STExterns.h b/Frameworks/StepTalk/STExterns.h new file mode 100644 index 0000000..3a5f376 --- /dev/null +++ b/Frameworks/StepTalk/STExterns.h @@ -0,0 +1,57 @@ +/** + STExterns.h + Misc. variables + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +@class NSString; +@class STUndefinedObject; + +extern STUndefinedObject *STNil; + +/* exceptions */ + +extern NSString *STGenericException; /* can be ignored */ +extern NSString *STInvalidArgumentException; +extern NSString *STInternalInconsistencyException; /* not recoverable */ +extern NSString *STScriptingException; + +extern NSString *STLibraryDirectory; + +extern NSString *STScriptExtension; +extern NSString *STScriptsDirectory; + +extern NSString *STScriptingEnvironmentsDirectory; +extern NSString *STScriptingEnvironmentExtension; + +extern NSString *STModulesDirectory; +extern NSString *STModuleExtension; + +extern NSString *STLanguageBundlesDirectory; +extern NSString *STLanguageBundleExtension; + +extern NSString *STLanguagesConfigFile; + +/* malloc zone */ +extern NSZone *STMallocZone; + diff --git a/Frameworks/StepTalk/STExterns.m b/Frameworks/StepTalk/STExterns.m new file mode 100644 index 0000000..d8ea6db --- /dev/null +++ b/Frameworks/StepTalk/STExterns.m @@ -0,0 +1,55 @@ +/** + STExterns.m + Misc. variables + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of the StepTalk project. + + 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 2 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02111, USA. + */ +#import + +NSString *STGenericException = @"STGenericException"; +NSString *STInvalidArgumentException = @"STInvalidArgumentException"; +NSString *STInternalInconsistencyException = @"STInternalInconsistencyException"; +NSString *STRangeException = @"STRangeException"; +NSString *STScriptingException = @"STScriptingException"; + +NSString *STCompilerSyntaxException = @"STCompilerSyntaxException"; +NSString *STCompilerGenericException = @"STCompilerGenericException"; +NSString *STCompilerInconsistencyException = @"STCompilerInconsistencyException"; + +NSString *STInterpreterGenericException = @"STInterpreterGenericException"; +NSString *STInvalidBytecodeException = @"STInterpreterInvalidBytecodeException"; +NSString *STInterpreterInconsistencyException = @"STInterpreterInconsistencyException"; + + +NSString *STLibraryDirectory = @"StepTalk"; +NSString *STScriptsDirectory = @"Scripts"; + +NSString *STModulesDirectory = @"Modules"; +NSString *STModuleExtension = @"bundle"; + +NSString *STScriptingEnvironmentsDirectory = @"Environments"; +NSString *STScriptingEnvironmentExtension = @"stenv"; + +NSString *STLanguageBundlesDirectory = @"Languages"; +NSString *STLanguageBundleExtension = @"stlanguage"; + +NSString *STLanguagesConfigFile = @"Languages.plist"; diff --git a/Frameworks/StepTalk/STFunctions.h b/Frameworks/StepTalk/STFunctions.h new file mode 100644 index 0000000..08b8746 --- /dev/null +++ b/Frameworks/StepTalk/STFunctions.h @@ -0,0 +1,38 @@ +/** + STFunctions.h + Misc. functions + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + + +#import + +@class NSString; + +NSArray *STFindAllResources(NSString *resourceDir, NSString *extension); +NSString *STFindResource(NSString *name, + NSString *resourceDir, + NSString *extension); +NSString *STUserConfigPath(void); + diff --git a/Frameworks/StepTalk/STFunctions.m b/Frameworks/StepTalk/STFunctions.m new file mode 100644 index 0000000..b7c46b4 --- /dev/null +++ b/Frameworks/StepTalk/STFunctions.m @@ -0,0 +1,130 @@ +/** + STFunctions.m + Misc. functions + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + +#import + +#import + +#import +#import +#import +#import +#import + + +NSString *STFindResource(NSString *name, + NSString *resourceDir, + NSString *extension) +{ + NSFileManager *manager = [NSFileManager defaultManager]; + NSArray *paths; + NSEnumerator *enumerator; + NSString *path; + NSString *file; + + paths = NSStandardLibraryPaths(); + + enumerator = [paths objectEnumerator]; + + while( (path = [enumerator nextObject]) ) + { + + file = [path stringByAppendingPathComponent:STLibraryDirectory]; + file = [file stringByAppendingPathComponent:resourceDir]; + file = [file stringByAppendingPathComponent:name]; + + if( [manager fileExistsAtPath:file isDirectory:NO] ) + { + return file; + } + + file = [file stringByAppendingPathExtension:extension]; + + if( [manager fileExistsAtPath:file isDirectory:NO] ) + { + return file; + } + } + return nil; +} + +NSArray *STFindAllResources(NSString *resourceDir, NSString *extension) +{ + NSFileManager *manager = [NSFileManager defaultManager]; + NSDirectoryEnumerator *dirs; + + NSArray *paths; + NSEnumerator *enumerator; + NSString *path; + NSString *file; + NSMutableArray *resources = [NSMutableArray array]; + + paths = NSStandardLibraryPaths(); + + enumerator = [paths objectEnumerator]; + + while( (path = [enumerator nextObject]) ) + { + path = [path stringByAppendingPathComponent:STLibraryDirectory]; + path = [path stringByAppendingPathComponent:resourceDir]; + + if( ![manager fileExistsAtPath:path] ) + { + continue; + } + + dirs = [manager enumeratorAtPath:path]; + + while( (file = [dirs nextObject]) ) + { + if( [[[dirs directoryAttributes] fileType] + isEqualToString:NSFileTypeDirectory] + && [[file pathExtension] isEqualToString:extension]) + { + file = [path stringByAppendingPathComponent:file]; + [resources addObject:file]; + } + } + } + + return [NSArray arrayWithArray:resources]; +} + +NSString *STUserConfigPath(void) +{ + NSString *path = nil; + NSArray *paths; + + paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, + NSUserDomainMask, YES); + path = [paths objectAtIndex: 0]; + + path = [path stringByAppendingPathComponent:STLibraryDirectory]; + path = [path stringByAppendingPathComponent:@"Configuration"]; + + return path; +} diff --git a/Frameworks/StepTalk/STLanguage.h b/Frameworks/StepTalk/STLanguage.h new file mode 100644 index 0000000..ddcb10f --- /dev/null +++ b/Frameworks/StepTalk/STLanguage.h @@ -0,0 +1,46 @@ +/** + STLanguage.h + StepTalk language bundle + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2001 Oct 24 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + +#import + +@class STEngine; + +@interface STLanguage:NSBundle ++ (NSArray *)allLanguageNames; ++ (NSString *)defaultLanguageName; ++ (NSArray *)allKnownFileTypes; + ++ languageWithName:(NSString *)languageName; ++ languageWithPath:(NSString *)path; + ++ (NSString *)languageNameForFileType:(NSString *)fileType; ++ (STLanguage *)languageForFileType:(NSString *)fileType; + +- (NSString *)languageName; + +- (STEngine *)engine; +@end diff --git a/Frameworks/StepTalk/STLanguage.m b/Frameworks/StepTalk/STLanguage.m new file mode 100644 index 0000000..8deff38 --- /dev/null +++ b/Frameworks/StepTalk/STLanguage.m @@ -0,0 +1,224 @@ +/** + STLanguage.m + StepTalk language bundle + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2001 Oct 24 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + +#import + +#import +#import +#import + +#import +#import +#import +#import +#import +#import +#import +#import + +static NSDictionary *fileTypeDictionary = nil; + +@implementation STLanguage +/** Returns an array containing the names of all available languages*/ ++ (NSArray *)allLanguageNames +{ + NSArray *bundles; + NSEnumerator *enumerator; + NSString *path; + NSMutableArray *languages = [NSMutableArray array]; + STLanguage *lang; + + bundles = STFindAllResources(STLanguageBundlesDirectory, + STLanguageBundleExtension); + + enumerator = [bundles objectEnumerator]; + + while( (path = [enumerator nextObject]) ) + { + lang = [STLanguage languageWithPath:path]; + + [languages addObject:[lang languageName]]; + } + + return AUTORELEASE([languages copy]); +} + +/** Returns the name of default scripting language specified by the + STDefaultLanguageName default. If there is no such default in user's + defaults database, then Smalltalk is used. */ + ++ (NSString *)defaultLanguageName +{ + NSUserDefaults *defs = [NSUserDefaults standardUserDefaults]; + NSString *name= [defs objectForKey:@"STDefaultLanguageName"]; + + if(!name) + { + return @"Smalltalk"; + } + else + { + return name; + } +} + +/** Returns language bundle for a language with name languageName */ ++ languageWithName:(NSString *)languageName +{ + NSString *file = STFindResource(languageName, STLanguageBundlesDirectory, + STLanguageBundleExtension); + if(!file) + { + NSLog(@"Could not find language with name '%@'", languageName); + return nil; + } + + return [self languageWithPath:file]; + +} + +/** Returns language bundle for language with name languageName. */ ++ languageWithPath:(NSString *)path +{ + if(!path) + { + return nil; + } + + return AUTORELEASE([[STLanguage alloc] initWithPath:path]); +} +/** Update information about handling various files with StepTalk. */ ++ (NSDictionary *)updateFileTypeDictionary +{ + NSString *path = STUserConfigPath(); + NSFileManager *fm = [NSFileManager defaultManager]; + NSTask *task; + NSDictionary *dict; + + RELEASE(fileTypeDictionary); + + path = [path stringByAppendingPathComponent:STLanguagesConfigFile]; + + if( ![fm fileExistsAtPath:path]) + { + NSLog(@"Creating lanugages configuration file..."); + task = [NSTask launchedTaskWithLaunchPath:@"stupdate_languages" + arguments:nil]; + [task waitUntilExit]; + } + + if( ![fm fileExistsAtPath:path]) + { + [NSException raise:STGenericException + format:@"Unable to get languages configuration file"]; + return nil; + } + + dict = [NSDictionary dictionaryWithContentsOfFile:path]; + fileTypeDictionary = [dict objectForKey:@"STFileTypes"]; + + RETAIN(fileTypeDictionary); +} +/** Returns name of a language used by files of type fileType. */ ++ (NSString *)languageNameForFileType:(NSString *)fileType +{ + if(!fileTypeDictionary) + { + [self updateFileTypeDictionary]; + } + + return [fileTypeDictionary objectForKey:fileType]; +} + +/** Return all known types (extensions) of StepTalk script files */ ++ (NSArray *)allKnownFileTypes +{ + if(!fileTypeDictionary) + { + [self updateFileTypeDictionary]; + } + + return [fileTypeDictionary allKeys]; +} + +/** Returns the language bundle for a language used by files of type + fileType. */ ++ (STLanguage *)languageForFileType:(NSString *)fileType +{ + NSString *langName = [STLanguage languageNameForFileType:fileType]; + + if(langName) + { + return [STLanguage languageWithName:langName]; + } + + [NSException raise:STGenericException + format:@"Unknown language for file type '%@'", fileType]; + + return nil; +} + +/** Returns the name of the language */ +- (NSString *)languageName +{ + NSString *name; + + name = [[self infoDictionary] objectForKey:@"STLanguageName"]; + + if(!name) + { + + name = [[self bundlePath] lastPathComponent]; + name = [name stringByDeletingPathExtension]; + } + + return name; +} + +/** Returns a scripting engine provided by the language. */ +- (STEngine *)engine +{ + NSString *className =[[self infoDictionary] objectForKey:@"STEngine"]; + Class engineClass = nil; + STEngine *engine; + + if(className) + { + engineClass = [self classNamed:className]; + } + + if(!engineClass) + { + engineClass = [self principalClass]; + } + + engine = [[engineClass alloc] init]; + + return AUTORELEASE(engine); +} + +@end diff --git a/Frameworks/StepTalk/STMethod.h b/Frameworks/StepTalk/STMethod.h new file mode 100644 index 0000000..21e12ac --- /dev/null +++ b/Frameworks/StepTalk/STMethod.h @@ -0,0 +1,33 @@ +/** + STMethod + + Copyright (c) 2003 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2003 Aug 6 + + This file is part of the StepTalk project. + + 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 2 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02111, USA. + + */ + +#import + +@protocol STMethod +- (NSString *)source; +- (NSString *)methodName; +- (NSString *)languageName; +@end diff --git a/Frameworks/StepTalk/STMethod.m b/Frameworks/StepTalk/STMethod.m new file mode 100644 index 0000000..d281c65 --- /dev/null +++ b/Frameworks/StepTalk/STMethod.m @@ -0,0 +1,29 @@ +/** + STMethod + + Copyright (c) 2003 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2003 Aug 6 + + This file is part of the StepTalk project. + + 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 2 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02111, USA. + + */ + +#import + +/* Nothig here */ diff --git a/Frameworks/StepTalk/STObjCRuntime.h b/Frameworks/StepTalk/STObjCRuntime.h new file mode 100644 index 0000000..0d0649b --- /dev/null +++ b/Frameworks/StepTalk/STObjCRuntime.h @@ -0,0 +1,44 @@ +/** + STObjCRuntime.m + Objective C runtime additions + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of the StepTalk project. + + 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 2 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02111, USA. + + */ + +#import + +@class NSMutableDictionary; +@class NSString; +@class NSValue; +@class NSMethodSignature; + +extern NSMutableDictionary *STAllObjectiveCClasses(void); +extern NSMutableDictionary *STGetFoundationConstants(void); +extern NSDictionary *STClassDictionaryWithNames(NSArray *classNames); +extern NSArray *STAllObjectiveCSelectors(void); + +extern NSValue *STValueFromSelector(SEL sel); +extern SEL STSelectorFromValue(NSValue *val); +extern SEL STSelectorFromString(NSString *aString); +extern NSMethodSignature *STMethodSignatureForSelector(SEL sel); + diff --git a/Frameworks/StepTalk/STObjCRuntime.m b/Frameworks/StepTalk/STObjCRuntime.m new file mode 100644 index 0000000..43412f1 --- /dev/null +++ b/Frameworks/StepTalk/STObjCRuntime.m @@ -0,0 +1,262 @@ +/** + STObjCRuntime.m + Objective C runtime additions + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of the StepTalk project. + + 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 2 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02111, USA. + + */ + +#import +#import + +#import +#import +#import +#import +#import +#import +#import +#import + +#define SELECTOR_TYPES_COUNT 6 + +static const char *selector_types[] = + { + "@8@0:4", + "@12@0:4@8", + "@16@0:4@8@12", + "@20@0:4@8@12@16", + "@24@0:4@8@12@16@20", + "@28@0:4@8@12@16@20@24" + }; + +NSMutableDictionary *STAllObjectiveCClasses(void) +{ + NSString *name; + NSMutableDictionary *dict; + void *state = NULL; + Class class; + + dict = [NSMutableDictionary dictionary]; + + while( (class = objc_next_class(&state)) ) + { + name = [NSString stringWithCString:class_get_class_name(class)]; + + [dict setObject:class forKey:name]; + } + +// NSLog(@"%i Objective-C classes found",[dict count]); + + return dict; +} + +NSDictionary *STClassDictionaryWithNames(NSArray *classNames) +{ + NSEnumerator *enumerator = [classNames objectEnumerator]; + NSString *className; + NSMutableDictionary *dict = [NSMutableDictionary dictionary]; + Class class; + + while( (className = [enumerator nextObject]) ) + { + class = NSClassFromString(className); + if(class) + { + [dict setObject:NSClassFromString(className) forKey:className]; + } + else + { + NSLog(@"Warning: Class with name '%@' not found", className); + } + } + + return [NSDictionary dictionaryWithDictionary:dict]; +} + +NSValue *STValueFromSelector(SEL sel) +{ + return [NSValue value:&sel withObjCType:@encode(SEL)]; +} + +SEL STSelectorFromValue(NSValue *val) +{ + SEL sel; + [val getValue:&sel]; + return sel; +} + +SEL STSelectorFromString(NSString *aString) +{ + const char *name = [aString cString]; + const char *ptr; + int argc = 0; + + SEL sel; + + sel = NSSelectorFromString(aString); + if(!sel) + { + + ptr = name; + + while(*ptr) + { + if(*ptr == ':') + { + argc ++; + } + ptr++; + } + + if( argc < SELECTOR_TYPES_COUNT ) + { + NSDebugLLog(@"STSending", + @"registering selector '%s' " + @"with %i arguments, types:'%s'", + name,argc,selector_types[argc]); + + sel = sel_register_typed_name(name, selector_types[argc]); + } + + if(!sel) + { + [NSException raise:STInternalInconsistencyException + format:@"Unable to register selector '%@'", + aString]; + return NULL; + } + } + else + { + /* FIXME: temporary hack */ + } + + return sel; +} + +SEL STCreateTypedSelector(SEL sel) +{ + const char *name = sel_get_name(sel); + const char *ptr; + int argc = 0; + + SEL newSel; + + ptr = name; + + while(*ptr) + { + if(*ptr == ':') + { + argc ++; + } + ptr++; + } + + if( argc < SELECTOR_TYPES_COUNT ) + { + NSDebugLLog(@"STSending", + @"registering selector '%s' " + @"with %i arguments, types:'%s'", + name,argc,selector_types[argc]); + + newSel = sel_register_typed_name(name, selector_types[argc]); + } + + if(!newSel) + { + [NSException raise:STInternalInconsistencyException + format:@"Unable to register typed selector '%s'", + name]; + return NULL; + } + + return newSel; +} + +NSMethodSignature *STMethodSignatureForSelector(SEL sel) +{ + char *types; + + types = sel_get_type(sel); + + if(!types) + { + sel = STCreateTypedSelector(sel); + types = sel_get_type(sel); + } + return [NSMethodSignature signatureWithObjCTypes:types]; +} + + +static NSArray *selectors_from_list(struct objc_method_list *methods) +{ + NSMutableArray *array = [NSMutableArray array]; + int count = methods->method_count; + int i; + + for(i=0;imethod_list[i].method_name)]; + } + + if(methods->method_next) + { + [array addObjectsFromArray:selectors_from_list(methods->method_next)]; + } + + return array; +} + + +NSArray *STAllObjectiveCSelectors(void) +{ + NSMutableArray *array; + NSArray *methods; + Class class; + void *state = NULL; + + array = [[NSMutableArray alloc] init]; + + while( (class = objc_next_class(&state)) ) + { + if(class->methods) + { + methods = selectors_from_list(class->methods); + [array addObjectsFromArray:methods]; + } + class = class->class_pointer; + + if(class->methods) + { + methods = selectors_from_list(class->methods); + [array addObjectsFromArray:methods]; + } + } + + /* get rid of duplicates */ + array = (NSMutableArray *)[[NSSet setWithArray:(NSArray *)array] allObjects]; + array = (NSMutableArray *)[array sortedArrayUsingSelector:@selector(compare:)]; + + return array; +} diff --git a/Frameworks/StepTalk/STObjectReference.h b/Frameworks/StepTalk/STObjectReference.h new file mode 100644 index 0000000..874fe6a --- /dev/null +++ b/Frameworks/StepTalk/STObjectReference.h @@ -0,0 +1,50 @@ +/** + STObjectReference.h + Reference to object in NSDictionary. + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of StepTalk. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#import + +@class NSString; +@class NSMutableDictionary; + +@interface STObjectReference:NSObject +{ + NSString *key; + NSMutableDictionary *pool; +} + +- initWithObjectName:(NSString *)name + pool:(NSMutableDictionary *)aPool; + +- (void)setObject:anObject; +- object; + +- (NSString *)objectName; +- (void)setObjectName:(NSString *)newName; + +- (NSMutableDictionary *) pool; +- (void)setPool:(NSMutableDictionary *) aDict; +@end + diff --git a/Frameworks/StepTalk/STObjectReference.m b/Frameworks/StepTalk/STObjectReference.m new file mode 100644 index 0000000..00ee39b --- /dev/null +++ b/Frameworks/StepTalk/STObjectReference.m @@ -0,0 +1,90 @@ +/** + STObjectReference.m + Reference to object in NSDictionary. + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of StepTalk. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#import + +#import + +#import +#import +#import +#import + +@implementation STObjectReference +- initWithObjectName:(NSString *)name pool:(NSMutableDictionary *)aPool +{ + self = [super init]; + + key = RETAIN(name); + pool = RETAIN(aPool); + + return self; +} + +- (void)dealloc +{ + RELEASE(key); + RELEASE(pool); + + [super dealloc]; +} + +- (void)setObject:anObject +{ + if(anObject) + { + [pool setObject:anObject forKey:key]; + } + else + { + [pool setObject:STNil forKey:key]; + } +} + +- object +{ + return [pool objectForKey:key]; +} + +- (NSString *)objectName +{ + return key; +} +- (void)setObjectName:(NSString *)newName +{ + ASSIGN(key,newName); +} + +- (NSMutableDictionary *) pool +{ + return pool; +} +- (void)setPool:(NSMutableDictionary *) aDict +{ + ASSIGN(pool,aDict); +} +@end + diff --git a/Frameworks/StepTalk/STScript.h b/Frameworks/StepTalk/STScript.h new file mode 100644 index 0000000..695e113 --- /dev/null +++ b/Frameworks/StepTalk/STScript.h @@ -0,0 +1,47 @@ +/** + STScript + + Copyright (c) 2002 Stefan Urbanek + + Written by: Stefan Urbanek + Date: 2002 Mar 10 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + +#import + +@interface STScript:NSObject +{ + NSString *fileName; + NSString *localizedName; + NSString *menuKey; + NSString *description; + NSString *language; +} ++ scriptWithFile:(NSString *)file; + +- initWithFile:(NSString *)aFile; +- (NSString *)fileName; +- (NSString *)source; +- (NSString *)scriptName; +- (NSString *)localizedName; +- (NSString *)scriptDescription; +- (NSString *)language; +- (NSComparisonResult)compareByLocalizedName:(STScript *)aScript; +@end diff --git a/Frameworks/StepTalk/STScript.m b/Frameworks/StepTalk/STScript.m new file mode 100644 index 0000000..5d55ee9 --- /dev/null +++ b/Frameworks/StepTalk/STScript.m @@ -0,0 +1,186 @@ +/** + STScript + + Copyright (c) 2002 Stefan Urbanek + + Written by: Stefan Urbanek + Date: 2002 Mar 10 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + +#import + +#import + +#import +#import +#import +#import +#import + +@interface NSDictionary(LocalizedKey) +- (id)localizedObjectForKey:(NSString *)key; +@end + +@implementation NSDictionary(LocalizedKey) +- (id)localizedObjectForKey:(NSString *)key +{ + NSEnumerator *enumerator; + NSDictionary *dict;; + NSString *language; + NSArray *languages; + id obj = nil; + + languages = [NSUserDefaults userLanguages]; + + enumerator = [languages objectEnumerator]; + + while( (language = [enumerator nextObject]) ) + { + dict = [self objectForKey:language]; + obj = [dict objectForKey:key]; + + if(obj) + { + return obj; + } + } + + return [[self objectForKey:@"Default"] objectForKey:key]; +} +@end + +@implementation STScript ++ scriptWithFile:(NSString *)file +{ + STScript *script; + + script = [[STScript alloc] initWithFile:file]; + + return AUTORELEASE(script); +} +/** + Create a new script from file aFile>. Script information will + be read from 'aFile.stinfo' file containing a dictionary property list. +*/ + +- initWithFile:(NSString *)aFile +{ + NSFileManager *manager = [NSFileManager defaultManager]; + NSDictionary *info = nil; + NSString *infoFile; + BOOL isDir; + + // infoFile = [aFile stringByDeletingPathExtension]; + infoFile = [aFile stringByAppendingPathExtension: @"stinfo"]; + + if([manager fileExistsAtPath:infoFile isDirectory:&isDir] && !isDir ) + { + info = [NSDictionary dictionaryWithContentsOfFile:infoFile]; + } + + self = [super init]; + + fileName = RETAIN(aFile); + + localizedName = [info localizedObjectForKey:@"Name"]; + + if(!localizedName) + { + localizedName = [[fileName lastPathComponent] + stringByDeletingPathExtension]; + } + + RETAIN(localizedName); + + menuKey = RETAIN([info localizedObjectForKey:@"MenuKey"]); + description = RETAIN([info localizedObjectForKey:@"Description"]); + language = [info localizedObjectForKey:@"Language"]; + + if(!language) + { + language = [STLanguage languageNameForFileType:[fileName pathExtension]]; + } + if(!language) + { + language = @"Unknown"; + } + + RETAIN(language); + + return self; +} + +- (void)dealloc +{ + RELEASE(fileName); + RELEASE(localizedName); + RELEASE(menuKey); + RELEASE(description); + RELEASE(language); + [super dealloc]; +} + +/** Return file name of the receiver. */ +- (NSString *)fileName +{ + return fileName; +} + +/** Return menu item key equivalent for receiver. */ +- (NSString *)menuKey +{ + return menuKey; +} + +/** Returns source string of the receiver script.*/ +- (NSString *)source +{ + return [NSString stringWithContentsOfFile:fileName]; +} + +/** Returns a script name by which the script is identified */ +- (NSString *)scriptName +{ + return fileName; +} + +/** Returns localized name of the receiver script. */ +- (NSString *)localizedName +{ + return localizedName; +} + +/** Returns localized description of the script. */ +- (NSString *)scriptDescription +{ + return description; +} +/** Returns language of the script. */ +- (NSString *)language +{ + return language; +} + +/** Compare scripts by localized name. */ +- (NSComparisonResult)compareByLocalizedName:(STScript *)aScript +{ + return [localizedName caseInsensitiveCompare:[aScript localizedName]]; +} +@end diff --git a/Frameworks/StepTalk/STScriptObject.h b/Frameworks/StepTalk/STScriptObject.h new file mode 100644 index 0000000..25a2edf --- /dev/null +++ b/Frameworks/StepTalk/STScriptObject.h @@ -0,0 +1,28 @@ +/* 2003 Aug 5 */ + +#import + +@class NSMutableDictionary; +@class NSDictionary; +@class NSArray; +@class STMethod; + +@interface STScriptObject:NSObject +{ + NSMutableDictionary *ivars; + NSMutableDictionary *methods; +} +- initWithInstanceVariableNames:(NSString *)names; + +- (void)setObject:(id)anObject forVariable:(NSString *)aName; +- (id)objectForVariable:(NSString *)aName; + +- (NSArray *)instanceVariableNames; + +- (void)addMethod:(STMethod *)aMethod; +- (STMethod *)methodWithName:(NSString *)aName; +- (void)removeMethod:(STMethod *)aMethod; +- (void)removeMethodWithName:(NSString *)aName; +- (NSArray *)methodNames; +- (NSDictionary *)methodDictionary; +@end diff --git a/Frameworks/StepTalk/STScriptObject.m b/Frameworks/StepTalk/STScriptObject.m new file mode 100644 index 0000000..dfddbe2 --- /dev/null +++ b/Frameworks/StepTalk/STScriptObject.m @@ -0,0 +1,59 @@ +/* 2003 Aug 5 */ + +#import "StepTalk/STScriptObject.h" + +@implementation STScriptObject +- initWithInstanceVariableNames:(NSString *)names +{ + self = [super init]; + + methods = [[NSMutableDictionary alloc] init]; + + return self; +} +- (void)dealloc +{ + RELEASE(methods); + RELEASE(ivars); + [super dealloc]; +} + +- (void)setObject:(id)anObject forVariable:(NSString *)aName +{ + [self _notImplemented:_cmd]; +} +- (id)objectForVariable:(NSString *)aName +{ + [self _notImplemented:_cmd]; +} + +- (NSArray *)instanceVariableNames +{ + [self _notImplemented:_cmd]; +} + +- (void)addMethod:(STMethod *)aMethod +{ + [methods setObject:aMethod forKey:[aMethod methodName]]; +} +- (STMethod *)methodWithName:(NSString *)aName +{ + return [methods objectForKey:aName]; +} +- (void)removeMethod:(STMethod *)aMethod +{ + [self _notImplemented:_cmd]; +} +- (void)removeMethodWithName:(NSString *)aName +{ + [methods removeObjectForKey:aName]; +} +- (NSArray *)methodNames +{ + return [methods allKeys]; +} +- (NSDictionary *)methodDictionary +{ + return [NSDictionary dictionaryWithDictionary:methods]; +} +@end diff --git a/Frameworks/StepTalk/STScripting.h b/Frameworks/StepTalk/STScripting.h new file mode 100644 index 0000000..66ffe0e --- /dev/null +++ b/Frameworks/StepTalk/STScripting.h @@ -0,0 +1,43 @@ +/** + STScripting.h + Scripting protocol + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + +#import + +@class STEnvironment; + +@protocol STScripting +- (BOOL)isClass; ++ (BOOL)isClass; +- (NSString *)className; ++ (NSString *)className; +- (Class) classForScripting; ++ (Class) classForScripting; +@end + + +@interface NSObject (STScripting) +@end diff --git a/Frameworks/StepTalk/STScripting.m b/Frameworks/StepTalk/STScripting.m new file mode 100644 index 0000000..abaf52f --- /dev/null +++ b/Frameworks/StepTalk/STScripting.m @@ -0,0 +1,66 @@ +/** + STScripting.m + Scripting protocol + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + STScripting protocol documentation + + */ + +#import + +@implementation NSObject (STScripting) +/* +- (id)replacementForScriptingInEnvironment:(STEnvironment *)env +{ + return self; +} +*/ +- (BOOL)isClass +{ + return NO; +} ++ (BOOL)isClass +{ + return YES; +} + ++ (NSString *)className +{ + return NSStringFromClass(self); +} +- (NSString *)className +{ + return [[self class] className]; +} + +/*Subclasses should override this method to force use of another class */ +- (Class) classForScripting +{ + return [self class]; +} ++ (Class) classForScripting +{ + return [self class]; +} +@end diff --git a/Frameworks/StepTalk/STScriptsManager.h b/Frameworks/StepTalk/STScriptsManager.h new file mode 100644 index 0000000..0e11884 --- /dev/null +++ b/Frameworks/StepTalk/STScriptsManager.h @@ -0,0 +1,51 @@ +/** + STScriptsManager + + Copyright (c)2002 Stefan Urbanek + + Written by: Stefan Urbanek + Date: 2002 Mar 10 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + +#import + +@class NSArray; +@class STScript; + +@interface STScriptsManager:NSObject +{ + NSString *scriptsDomainName; + NSArray *scriptSearchPaths; +} ++ defaultManager; + +- initWithDomainName:(NSString *)name; + +- (NSString *)scriptsDomainName; + +- (void)setScriptSearchPathsToDefaults; +- (NSArray *)scriptSearchPaths; +- (void)setScriptSearchPaths:(NSArray *)anArray; + +- (NSArray *)validScriptSearchPaths; +- (STScript *)scriptWithName:(NSString*)aString; + +- (NSArray *)allScripts; +@end diff --git a/Frameworks/StepTalk/STScriptsManager.m b/Frameworks/StepTalk/STScriptsManager.m new file mode 100644 index 0000000..00818e1 --- /dev/null +++ b/Frameworks/StepTalk/STScriptsManager.m @@ -0,0 +1,294 @@ +/** + STScriptsManager + + Copyright (c)2002 Stefan Urbanek + + Written by: Stefan Urbanek + Date: 2002 Mar 10 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + +#import + +#import +#import +#import + +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import + +static STScriptsManager *sharedScriptsManager = nil; + +@interface STScriptsManager (STPriavteMethods) +- (NSArray *)_scriptsAtPath:(NSString *)path; +@end + +@implementation STScriptsManager + +/** Return default domain name for scripts. Usually this is application or +process name.*/ ++ (NSString *)defaultScriptsDomainName +{ + return [[NSProcessInfo processInfo] processName]; +} + +/** Returns default scripts manager for current process (application or tool). */ ++ defaultManager +{ + if(!sharedScriptsManager) + { + sharedScriptsManager = [[STScriptsManager alloc] init]; + } + + return sharedScriptsManager; +} + +- init +{ + return [self initWithDomainName:nil]; +} + +/** + Initializes the receiver to be used with domain named name. + If name is nil, default scripts domain name will be used. + + +*/ +- initWithDomainName:(NSString *)name +{ + self = [super init]; + + if(!name) + { + name = [STScriptsManager defaultScriptsDomainName]; + } + + scriptsDomainName = RETAIN(name); + + return self; +} + +- (void)dealloc +{ + RELEASE(scriptsDomainName); + [super dealloc]; +} + + +/** Return name of script manager domain. */ +- (NSString *)scriptsDomainName +{ + return scriptsDomainName; +} + +/* Sets script search paths to defaults. Default paths are (in this order): + /StepTalk/Scripts/. + /StepTalk/Scripts/Shared and + paths to Resource/Scripts in all loaded bundles including the main bundle.*/ + +- (void)setScriptSearchPathsToDefaults +{ + NSMutableArray *scriptPaths = [NSMutableArray array]; + NSEnumerator *enumerator; + NSString *path; + NSString *str; + NSArray *paths; + NSBundle *bundle; + + paths = NSStandardLibraryPaths(); + + enumerator = [paths objectEnumerator]; + + while( (path = [enumerator nextObject]) ) + { + path = [path stringByAppendingPathComponent:STLibraryDirectory]; + path = [path stringByAppendingPathComponent:@"Scripts"]; + + str = [path stringByAppendingPathComponent: scriptsDomainName]; + [scriptPaths addObject:str]; + + str = [path stringByAppendingPathComponent:@"Shared"]; + [scriptPaths addObject:str]; + } + + enumerator = [[NSBundle allBundles] objectEnumerator]; + + while( (bundle = [enumerator nextObject]) ) + { + path = [bundle resourcePath]; + path = [path stringByAppendingPathComponent:@"Scripts"]; + [scriptPaths addObject:path]; + } + + RELEASE(scriptSearchPaths); + scriptSearchPaths = [[NSArray alloc] initWithArray:scriptPaths]; +} + +/** + Retrun an array of script search paths. Scripts are searched + in Library/StepTalk/Scripts/scriptsDomainName, + Library/StepTalk/Scripts/Shared and in all loaded bundles in + bundlePath/Resources/Scripts. +*/ + +- (NSArray *)scriptSearchPaths +{ + if(!scriptSearchPaths) + { + [self setScriptSearchPathsToDefaults]; + } + + return scriptSearchPaths; +} + +/** Set script search paths to anArray. */ +- (void)setScriptSearchPaths:(NSArray *)anArray +{ + ASSIGN(scriptSearchPaths, anArray); +} + +/** Return script search paths that are valid. That means that path exists and + is a directory. */ +- (NSArray *)validScriptSearchPaths +{ + NSMutableArray *scriptPaths = [NSMutableArray array]; + NSFileManager *manager = [NSFileManager defaultManager]; + NSEnumerator *enumerator; + NSString *path; + NSArray *paths; + BOOL isDir; + + paths = [self scriptSearchPaths]; + + enumerator = [paths objectEnumerator]; + + while( (path = [enumerator nextObject]) ) + { + if( [manager fileExistsAtPath:path isDirectory:&isDir] && isDir ) + { + [scriptPaths addObject:path]; + } + } + + return [NSArray arrayWithArray:scriptPaths]; +} + +/** + Get a script with name aString for current scripting domain. +*/ +- (STScript *)scriptWithName:(NSString*)aString +{ + NSFileManager *manager = [NSFileManager defaultManager]; + NSEnumerator *pEnumerator; + NSEnumerator *sEnumerator; + NSString *path; + NSString *file; + NSString *str; + NSArray *paths; + + paths = [self validScriptSearchPaths]; + + pEnumerator = [paths objectEnumerator]; + + while( (path = [pEnumerator nextObject]) ) + { + sEnumerator = [[manager directoryContentsAtPath:path] objectEnumerator]; + + while( (file = [sEnumerator nextObject]) ) + { + + if( ! [[file pathExtension] isEqualToString:@"stinfo"] ) + { + NSDebugLLog(@"STScriptManager", @"Script %@", file); + + str = [file lastPathComponent]; + str = [str stringByDeletingPathExtension]; + + if([str isEqualToString:aString]) + { + return [STScript scriptWithFile: + [path stringByAppendingPathComponent:file]]; + } + } + } + + } + + return nil; +} + +- (NSArray *)_scriptsAtPath:(NSString *)path +{ + NSMutableArray *scripts = [NSMutableArray array]; + NSFileManager *manager = [NSFileManager defaultManager]; + NSEnumerator *enumerator; + NSString *file; + NSString *str; + NSString *ext; + NSArray *paths; + NSSet *types; + + types = [NSSet setWithArray:[STLanguage allKnownFileTypes]]; + + enumerator = [[manager directoryContentsAtPath:path] objectEnumerator]; + + while( (file = [enumerator nextObject]) ) + { + + ext = [file pathExtension]; + if( [types containsObject:ext] ) + { + STScript *script; + NSLog(@"Found script %@", file); + + script = [STScript scriptWithFile: + [path stringByAppendingPathComponent:file]]; + [scripts addObject:script]; + } + } + + return [NSArray arrayWithArray:scripts]; +} + +/** Return list of all scripts for managed domain. */ +- (NSArray *)allScripts +{ + NSMutableArray *scripts = [NSMutableArray array]; + NSEnumerator *enumerator; + NSString *path; + + enumerator = [[self validScriptSearchPaths] objectEnumerator]; + + while( (path = [enumerator nextObject]) ) + { + [scripts addObjectsFromArray:[self _scriptsAtPath:path]]; + } + + return [NSArray arrayWithArray:scripts]; +} +@end diff --git a/Frameworks/StepTalk/STSelector.h b/Frameworks/StepTalk/STSelector.h new file mode 100644 index 0000000..3b769a1 --- /dev/null +++ b/Frameworks/StepTalk/STSelector.h @@ -0,0 +1,38 @@ +/* + STSelector + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2002 Feb 4 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + +#import + +@interface STSelector:NSObject +{ + SEL sel; +} +- initWithSelector:(SEL)aSel; + +- (SEL)selectorValue; +- (NSString *)stringValue; +@end + diff --git a/Frameworks/StepTalk/STSelector.m b/Frameworks/StepTalk/STSelector.m new file mode 100644 index 0000000..9c3e697 --- /dev/null +++ b/Frameworks/StepTalk/STSelector.m @@ -0,0 +1,51 @@ +/* + STSelector + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2002 Feb 4 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + +#import + +@implementation STSelector +- initWithSelector:(SEL)aSel +{ + [super init]; + sel = aSel; + return self; +} + +- (SEL)selectorValue +{ + return sel; +} + +- (NSString *)description +{ + return NSStringFromSelector(sel); +} + +- (NSString *)stringValue +{ + return NSStringFromSelector(sel); +} +@end diff --git a/Frameworks/StepTalk/STStructure.h b/Frameworks/StepTalk/STStructure.h new file mode 100644 index 0000000..b1f40bb --- /dev/null +++ b/Frameworks/StepTalk/STStructure.h @@ -0,0 +1,90 @@ +/** + STStructure.h + C structure wrapper + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of StepTalk. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#import +#import +#import + +// @class STRange; +// @class STPoint; +// @class STRect; +@class NSString; +@class NSMutableArray; + +@interface STStructure:NSObject +{ + NSString *structType; + NSString *name; + NSMutableArray *fields; +} ++ structureWithValue:(void *)value type:(const char*)type; ++ structureWithRange:(NSRange)range; ++ structureWithPoint:(NSPoint)point; ++ structureWithRect:(NSRect)rect; ++ structureWithSize:(NSSize)size; + +- initWithValue:(void *)value type:(const char*)type; +- (const char *)type; +- (NSString *)structureName; + +- (void)getValue:(void *)value; + +- (NSRange)rangeValue; +- (NSPoint)pointValue; +- (NSRect)rectValue; +- (NSSize)sizeValue; + +- valueAtIndex:(unsigned)index; +- (void)setValue:anObject atIndex:(unsigned)index; + +- (int)intValueAtIndex:(unsigned)index; +- (float)floatValueAtIndex:(unsigned)index; +@end + +/* +@interface STRange:STStructure +- rangeWithLocation:(int)loc length:(int)length; +- (int)location; +- (int)length; +@end + +@interface STPoint:STStructure +- pointWithX:(float)x y:(float)y; +- (float)x; +- (float)y; +@end + +@interface STRect:STStructure +- rectWithX:(float)x y:(float)y width:(float)w heigth:(float)h; +- rectWithOrigin:(NSPoint)origin size:(NSPoint)size; +- (float)x; +- (float)y; +- (float)width; +- (float)height; +- (NSPoint)origin; +- (NSPoint)size; +@end +*/ diff --git a/Frameworks/StepTalk/STStructure.m b/Frameworks/StepTalk/STStructure.m new file mode 100644 index 0000000..65f45d1 --- /dev/null +++ b/Frameworks/StepTalk/STStructure.m @@ -0,0 +1,309 @@ +/** + STStructure.m + C structure wrapper + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of StepTalk. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#import + +#import +#import +#import +#import +#import +#import +#import + +@implementation STStructure ++ structureWithValue:(void *)value type:(const char*)type +{ + STStructure *str; + str = [[self alloc] initWithValue:value type:type]; + return AUTORELEASE(str); +} ++ structureWithRange:(NSRange)range +{ + STStructure *str; + str = [[self alloc] initWithValue:&range type:@encode(NSRange)]; + return AUTORELEASE(str); +} + ++ structureWithPoint:(NSPoint)point +{ + STStructure *str; + str = [[self alloc] initWithValue:&point type:@encode(NSPoint)]; + return AUTORELEASE(str); +} ++ structureWithSize:(NSSize)size +{ + STStructure *str; + str = [[self alloc] initWithValue:&size type:@encode(NSSize)]; + return AUTORELEASE(str); +} + ++ structureWithRect:(NSRect)rect +{ + STStructure *str; + str = [[self alloc] initWithValue:&rect type:@encode(NSRect)]; + return AUTORELEASE(str); +} + +- initWithValue:(void *)value type:(const char*)type +{ + const char *nameBeg; + int offset = 0; + int align; + int rem; + + + self = [super init]; + + NSDebugLLog(@"STStructure", + @"creating structure of type '%s' value ptr %p",type,value); + + structType = [[NSString alloc] initWithCString:type]; + + fields = [[NSMutableArray alloc] init]; + + type++; + + nameBeg = type; + while (*type != _C_STRUCT_E && *type++ != '='); + name = [[NSString alloc] initWithCString:nameBeg length:type-nameBeg]; + + while(*type != _C_STRUCT_E) + { + [fields addObject:STObjectFromValueOfType(((char *)value)+offset,type)]; + + offset += objc_sizeof_type(type); + type = objc_skip_typespec(type); + + if(*type == _C_STRUCT_E) + { + break; + } + + align = objc_alignof_type(type); + rem = offset % align; + if(rem != 0) + { + offset += align - rem; + } + } + + return self; +} +- (void)dealloc +{ + RELEASE(fields); + RELEASE(structType); + RELEASE(name); + [super dealloc]; +} + +- (void)getValue:(void *)value +{ + const char *type = [structType cString]; + int offset=0; + int align; + int rem; + int i = 0; + + type++; + while (*type != _C_STRUCT_E && *type++ != '='); + + while(*type != _C_STRUCT_E) + { + STGetValueOfTypeFromObject((void *)((char*)value+offset), + type, + [fields objectAtIndex:i++]); + + offset += objc_sizeof_type(type); + type = objc_skip_typespec(type); + + if(*type == _C_STRUCT_E) + { + break; + } + align = objc_alignof_type(type); + rem = offset % align; + if(rem != 0) + { + offset += align - rem; + } + } +} + +- (const char *)type +{ + return [structType cString]; +} +- (NSString *)structureName +{ + return name; +} +- (const char *)typeOfFieldAtIndex:(unsigned)index +{ + const char *type = [structType cString]; + + for(type += 1; *type != _C_STRUCT_E && index>0; index--) + { + type = objc_skip_argspec(type); + } + + if(*type == _C_STRUCT_E) + { + [NSException raise:STInternalInconsistencyException + format:@"invalid structure field index"]; + return 0; + } + return type; +} +- (NSRange)rangeValue +{ + /* FIXME: do some checking */ + return NSMakeRange([self intValueAtIndex:0],[self intValueAtIndex:1]); +} + +- (NSPoint)pointValue +{ + /* FIXME: do some checking */ + return NSMakePoint([self floatValueAtIndex:0],[self floatValueAtIndex:1]); +} + +- (NSSize)sizeValue +{ + /* FIXME: do some checking */ + return NSMakeSize([self floatValueAtIndex:0],[self floatValueAtIndex:1]); +} + +- (NSRect)rectValue +{ + NSPoint origin = [[fields objectAtIndex:0] pointValue]; + NSSize size = [[fields objectAtIndex:1] sizeValue]; + NSRect rect; + + /* FIXME: do some checking */ + rect.origin = origin; + rect.size = size; + return rect; +} + +- valueAtIndex:(unsigned)index +{ + return [fields objectAtIndex:index]; +} +- (void)setValue:anObject atIndex:(unsigned)index +{ + [fields replaceObjectAtIndex:index withObject:anObject]; +} + +- (int)intValueAtIndex:(unsigned)index +{ + return (int)[[fields objectAtIndex:index] intValue]; +} +- (float)floatValueAtIndex:(unsigned)index +{ + return (float)[[fields objectAtIndex:index] floatValue]; +} + +/* NSRange */ + +- (int)location +{ + return [[fields objectAtIndex:0] intValue]; +} + +- (int)length +{ + return [[fields objectAtIndex:1] intValue]; +} + +- (void)setLocation:(int)location +{ + [fields replaceObjectAtIndex:0 withObject: [NSNumber numberWithInt:location]]; +} + +- (void)setLength:(int)length +{ + [fields replaceObjectAtIndex:1 withObject: [NSNumber numberWithInt:length]]; +} + +/* NSPoint */ + +- (float)x +{ + return [[fields objectAtIndex:0] floatValue]; +} + +- (void)setX:(float)x +{ + [fields replaceObjectAtIndex:0 withObject: [NSNumber numberWithFloat:x]]; +} + +- (float)y +{ + return [[fields objectAtIndex:1] floatValue]; +} + +- (void)setY:(float)y +{ + [fields replaceObjectAtIndex:1 withObject: [NSNumber numberWithFloat:y]]; +} + +/* NSSize */ + +- (float)width +{ + return [[fields objectAtIndex:0] floatValue]; +} + +- (float)height +{ + return [[fields objectAtIndex:1] floatValue]; +} + +- (void)setWidth:(float)width +{ + [fields replaceObjectAtIndex:0 withObject: [NSNumber numberWithFloat:width]]; +} +- (void)setHeight:(float)height +{ + [fields replaceObjectAtIndex:1 withObject: [NSNumber numberWithFloat:height]]; +} + +/* NSRect */ + +- (id)origin +{ + NSLog(@"Origin %@", [fields objectAtIndex:0]); + return [fields objectAtIndex:0]; +} + +- (id)size +{ + NSLog(@"Size %@", [fields objectAtIndex:1]); + return [fields objectAtIndex:1] ; +} + +@end diff --git a/Frameworks/StepTalk/STUndefinedObject.h b/Frameworks/StepTalk/STUndefinedObject.h new file mode 100644 index 0000000..c6735b1 --- /dev/null +++ b/Frameworks/StepTalk/STUndefinedObject.h @@ -0,0 +1,31 @@ +/** + STUndefinedObject.h + Wrapper for nil object + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ +#import +#import + +@interface STUndefinedObject:NSObject +@end diff --git a/Frameworks/StepTalk/STUndefinedObject.m b/Frameworks/StepTalk/STUndefinedObject.m new file mode 100644 index 0000000..5793e03 --- /dev/null +++ b/Frameworks/StepTalk/STUndefinedObject.m @@ -0,0 +1,101 @@ +/** + STUndefinedObject.m + Wrapper for nil object + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2000 + + This file is part of the StepTalk project. + + 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 2 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02111, USA. + + */ +#import + +#import +#import + +#import + +STUndefinedObject *STNil = nil; + +@implementation STUndefinedObject ++ (id) alloc +{ + return STNil; +} + ++ (id) allocWithZone: (NSZone*)z +{ + return STNil; +} + ++ (id) autorelease +{ + return self; +} + +- (void) dealloc +{ + NSLog(@"Warning: Trying to dealloc STNil object"); +} + +- (NSMethodSignature *)methodSignatureForSelector:(SEL)sel +{ + NSMethodSignature *signature = nil; + + signature = [super methodSignatureForSelector:sel]; + + if(!signature) + { + signature = STMethodSignatureForSelector(sel); + } + + return signature; +} + +- (void) forwardInvocation: (NSInvocation*)anInvocation +{ + /* this object is deaf */ +} + +- (BOOL) isEqual: (id)anObject +{ + return ( (self == anObject) || (anObject == nil) ); +} + +- (void) release +{ + /* do nothing */ +} + +- (id) retain +{ + return self; +} + +- (BOOL)isNil +{ + return YES; +} + +- (BOOL)notNil +{ + return NO; +} +@end + diff --git a/Frameworks/StepTalk/StepTalk.gsdoc b/Frameworks/StepTalk/StepTalk.gsdoc new file mode 100644 index 0000000..a156eba --- /dev/null +++ b/Frameworks/StepTalk/StepTalk.gsdoc @@ -0,0 +1,39 @@ + + + + + + StepTalk Documentation + + + + + + + 0.7.1 + + 2003 Apr 22 + + + + + +Introduction + +

    + + StepTalk is a scripting framework for creating scriptable servers or + applications. StepTalk, when combined with the dynamism that the + Objective-C language provides, goes way beyond mere scripting. intro + +

    +
    + + + + + + + + +
    diff --git a/Frameworks/StepTalk/StepTalk.h b/Frameworks/StepTalk/StepTalk.h new file mode 100644 index 0000000..6c42036 --- /dev/null +++ b/Frameworks/StepTalk/StepTalk.h @@ -0,0 +1,39 @@ +/** + StepTalk.h + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2001 Nov 1 + + This file is part of the StepTalk project. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import + +#import diff --git a/GNUmakefile b/GNUmakefile index 250d770..d01a6a0 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -35,7 +35,7 @@ ifeq ($(appkit),no) endif SUBPROJECTS = \ - Source \ + Frameworks \ Languages \ Finders \ Modules \ diff --git a/Languages/Smalltalk/STBytecodeInterpreter.m b/Languages/Smalltalk/STBytecodeInterpreter.m index c681202..5eca123 100644 --- a/Languages/Smalltalk/STBytecodeInterpreter.m +++ b/Languages/Smalltalk/STBytecodeInterpreter.m @@ -65,8 +65,6 @@ - (void)returnValue:(id)value; @end -static STBytecodeInterpreter *sharedInterpreter = nil; - static SEL sendSelectorAtIndexSel; static IMP sendSelectorAtIndexImp; static SEL pushSel; @@ -89,16 +87,17 @@ static Class NSInvocation_class = nil; NSInvocation_class = [NSInvocation class]; } - -+ (STBytecodeInterpreter *)sharedInterpreter ++ interpreterWithEnvrionment:(STEnvironment *)env { - if(!sharedInterpreter) - { - sharedInterpreter = [[self alloc] init]; - } - return sharedInterpreter; + return AUTORELEASE([[self alloc] initWithEnvironment:env]); } +- initWithEnvironment:(STEnvironment *)env +{ + self = [super init]; + environment = RETAIN(env); + return self; +} - (void)setEnvironment:(STEnvironment *)env { ASSIGN(environment,env); diff --git a/Languages/Smalltalk/STCompiledMethod.h b/Languages/Smalltalk/STCompiledMethod.h index ef6a463..3fe1576 100644 --- a/Languages/Smalltalk/STCompiledMethod.h +++ b/Languages/Smalltalk/STCompiledMethod.h @@ -22,9 +22,11 @@ #import "STCompiledCode.h" +#import + @class STMessage; -@interface STCompiledMethod:STCompiledCode +@interface STCompiledMethod:STCompiledCode { NSString *selector; short argCount; diff --git a/Languages/Smalltalk/STCompiler.h b/Languages/Smalltalk/STCompiler.h index 01a53e5..82fa1fc 100644 --- a/Languages/Smalltalk/STCompiler.h +++ b/Languages/Smalltalk/STCompiler.h @@ -57,10 +57,6 @@ typedef struct _STParserContext /*" Get source reader from parser context "*/ #define STParserContextGetReader(context)\ (((STParserContext *)context)->reader) -#define STParserContextGetResult(context)\ - (((STParserContext *)context)->result) -#define STParserContextSetResult(context, c)\ - ( ASSIGN(((STParserContext *)(context))->result, (c)) ) /*" Initialize parser context "*/ #define STParserContextInit(context,aCompiler,aReader) \ @@ -76,13 +72,16 @@ typedef struct _STParserContext STSourceReader *reader; STParserContext context; + STCompiledScript *resultScript; + STCompiledMethod *resultMethod; + NSMutableData *byteCodes; NSMutableArray *tempVars; NSMutableArray *externVars; NSMutableArray *receiverVars; NSMutableArray *literals; - STCompiledScript *script; + BOOL isSingleMethod; unsigned stackSize; /* Required stack size */ unsigned stackPos; /* Current stack pointer */ @@ -97,6 +96,8 @@ typedef struct _STParserContext Class realNumberLiteralClass; /* default: NSNumber */ Class symbolLiteralClass; /* default: NSString */ } ++ compilerWithEnvironment:(STEnvironment *)env; +- initWithEnvironment:(STEnvironment *)env; /*" Environment "*/ - (void)setEnvironment:(STEnvironment *)env; - (STSourceReader *)sourceReader; diff --git a/Languages/Smalltalk/STCompiler.m b/Languages/Smalltalk/STCompiler.m index e906d2c..9f6cd07 100644 --- a/Languages/Smalltalk/STCompiler.m +++ b/Languages/Smalltalk/STCompiler.m @@ -47,6 +47,31 @@ extern int STCparse(void *context); +/* FIXME: rewrite parser + + We need three kinds of grammars: + + 1. = | + + 2. = '[|' ']' + = | '!' + = | + + 3. = + = | + + Parser 1. are 2. are for scripts. Parser 3. is for script object + methods. Because majority of the grammar is reused in all three + parsers we use only one grammar definition. There is no problem + in haveng 1. and 2. in one file. To be able to have 3. in the same + file we do a hack: we add a prefix '!!' for method source. Then + we diferentiate it in grammar file by changin the rule: + + 3. = '!' '!' + + See STGrammar.y +*/ + @interface STCompiler(STCompilerPrivate) - (void)compile; - (void)initializeContext; @@ -94,6 +119,17 @@ extern int STCparse(void *context); #define MAX(a,b) (((a)>(b))?(a):(b)) @implementation STCompiler ++ compilerWithEnvironment:(STEnvironment *)env +{ + return AUTORELEASE([[self alloc] initWithEnvironment:env]); +} +- initWithEnvironment:(STEnvironment *)env +{ + self = [self init]; + [self setEnvironment:env]; + return self; +} + - init { [super init]; @@ -113,7 +149,20 @@ extern int STCparse(void *context); [super dealloc]; } +- (BOOL)beginScript +{ + if(isSingleMethod) + { + [NSException raise:@"STCompilerException" + format:@"Script source given for single method"]; + return NO; + } + else + { + return YES; + } +} /* --------------------------------------------------------------------------- * Compilation * --------------------------------------------------------------------------- @@ -124,6 +173,74 @@ extern int STCparse(void *context); ASSIGN(environment,env); } +- (STCompiledMethod *)compileMethodFromSource:(NSString *)aString + forReceiver:(id)receiver +{ + STCompiledMethod *result; + NSString *hackedSource; + NSString *exceptionFmt = @"Syntax error at line %i near '%@', " + @"reason: %@."; + int parsRetval = 0; + + + // NSDebugLLog(@"STCompiler", @"Compile method", aString); + NSLog(@"Compile method"); + + if(!environment) + { + [NSException raise:STCompilerGenericException + format:@"Compilation environment is not initialized"]; + return nil; + } + + hackedSource = [@"!!" stringByAppendingString:aString]; + reader = [[STSourceReader alloc] initWithString:hackedSource]; + receiverVars = [[NSArray alloc] + initWithArray:[receiver instanceVariableNames]]; + + isSingleMethod = YES; + STParserContextInit(&context,self,reader); + + NS_DURING + { + // extern int STCdebug; + // STCdebug = 1; + parsRetval = STCparse(&context); + } + NS_HANDLER + { + if ([[localException name] isEqualToString: STCompilerSyntaxException]) + { + NSString *tokenString; + int line; + + tokenString = [reader tokenString]; + line = [reader currentLine]; + RELEASE(reader); + RELEASE(receiverVars); + + receiverVars = nil; + reader = nil; + + [NSException raise:STCompilerSyntaxException + format:exceptionFmt, + line, + tokenString, + [localException reason]]; + + } + [localException raise]; + } + NS_ENDHANDLER + + RELEASE(receiverVars); + RELEASE(reader); + + result = AUTORELEASE(resultMethod); + resultMethod = nil; + + return result; +} - (STCompiledScript *)compileString:(NSString *)aString { @@ -135,6 +252,8 @@ extern int STCparse(void *context); NSDebugLLog(@"STCompiler", @"Compile string", aString); + isSingleMethod = NO; + if(!environment) { [NSException raise:STCompilerGenericException @@ -182,10 +301,10 @@ extern int STCparse(void *context); RELEASE(receiverVars); RELEASE(reader); - result = script; - script = nil; + result = AUTORELEASE(resultScript); + resultScript = nil; - return AUTORELEASE(result); + return result; } - (void)compileMethod:(STCMethod *)method @@ -194,15 +313,6 @@ extern int STCparse(void *context); STCompiledCode *code; STMessage *messagePattern; - if(!script) - { - NSDebugLLog(@"STCompiler", - @"Creating script with %i variables",[receiverVars count]); - - script = [[STCompiledScript alloc] initWithVariableCount: - [receiverVars count]]; - } - /* FIXME: unite STCMessage and STMessage */ messagePattern = (STMessage *)[method messagePattern]; @@ -221,7 +331,41 @@ extern int STCparse(void *context); compiledMethod = [STCompiledMethod methodWithCode:AUTORELEASE(code) messagePattern:messagePattern]; - [script addMethod:compiledMethod]; + if(!isSingleMethod) + { + + if(resultMethod) + { + [NSException raise:@"STCompilerException" + format:@"Method is present when compiling a script"]; + return; + } + if(!resultScript) + { + NSDebugLLog(@"STCompiler", + @"Creating script with %i variables",[receiverVars count]); + + resultScript = [[STCompiledScript alloc] initWithVariableCount: + [receiverVars count]]; + } + [resultScript addMethod:compiledMethod]; + } + else + { + if(resultMethod) + { + [NSException raise:@"STCompilerException" + format:@"More than one method compiled for single method request"]; + return; + } + if(resultScript) + { + [NSException raise:@"STCompilerException" + format:@"Compiled script is present when compiling single method"]; + return; + } + resultMethod = RETAIN(compiledMethod); + } } - (STCompiledCode *)compileStatements:(STCStatements *)statements diff --git a/Languages/Smalltalk/STGrammar.m b/Languages/Smalltalk/STGrammar.m index 09a1861..9ae18f8 100644 --- a/Languages/Smalltalk/STGrammar.m +++ b/Languages/Smalltalk/STGrammar.m @@ -264,18 +264,18 @@ union yyalloc #endif /* YYFINAL -- State number of the termination state. */ -#define YYFINAL 48 +#define YYFINAL 50 /* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 242 +#define YYLAST 244 /* YYNTOKENS -- Number of terminals. */ #define YYNTOKENS 23 /* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 36 +#define YYNNTS 37 /* YYNRULES -- Number of rules. */ -#define YYNRULES 81 +#define YYNRULES 83 /* YYNRULES -- Number of states. */ -#define YYNSTATES 116 +#define YYNSTATES 120 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ #define YYUNDEFTOK 2 @@ -322,56 +322,57 @@ static const unsigned char yytranslate[] = YYRHS. */ static const unsigned char yyprhs[] = { - 0, 0, 3, 4, 6, 11, 13, 16, 17, 21, - 23, 25, 29, 32, 36, 38, 41, 43, 46, 50, - 54, 56, 59, 62, 66, 72, 75, 79, 82, 84, - 87, 92, 94, 98, 100, 103, 105, 108, 110, 113, - 115, 118, 121, 124, 127, 131, 133, 136, 138, 140, - 142, 144, 147, 151, 154, 157, 161, 163, 165, 167, - 169, 171, 173, 175, 179, 181, 183, 185, 187, 189, - 191, 193, 195, 197, 201, 202, 204, 206, 209, 212, - 214, 216 + 0, 0, 3, 4, 6, 10, 11, 17, 19, 22, + 23, 27, 29, 31, 35, 38, 42, 44, 47, 49, + 52, 56, 60, 62, 65, 68, 72, 78, 81, 85, + 88, 90, 93, 98, 100, 104, 106, 109, 111, 114, + 116, 119, 121, 124, 127, 130, 133, 137, 139, 142, + 144, 146, 148, 150, 153, 157, 160, 163, 167, 169, + 171, 173, 175, 177, 179, 181, 185, 187, 189, 191, + 193, 195, 197, 199, 201, 203, 207, 208, 210, 212, + 215, 218, 220, 222 }; /* YYRHS -- A `-1'-separated list of the rules' RHS. */ static const yysigned_char yyrhs[] = { - 24, 0, -1, -1, 25, -1, 8, 4, 26, 9, - -1, 36, -1, 32, 36, -1, -1, 35, 27, 28, - -1, 28, -1, 29, -1, 28, 3, 29, -1, 30, - 36, -1, 30, 32, 36, -1, 53, -1, 54, 52, - -1, 31, -1, 55, 52, -1, 31, 55, 52, -1, - 4, 33, 4, -1, 52, -1, 33, 52, -1, 8, - 9, -1, 8, 36, 9, -1, 8, 35, 4, 36, - 9, -1, 12, 52, -1, 35, 12, 52, -1, 14, - 38, -1, 37, -1, 37, 11, -1, 37, 11, 14, - 38, -1, 38, -1, 37, 11, 38, -1, 51, -1, - 39, 51, -1, 44, -1, 39, 44, -1, 41, -1, - 39, 41, -1, 40, -1, 39, 40, -1, 52, 5, - -1, 44, 42, -1, 13, 43, -1, 42, 13, 43, - -1, 53, -1, 54, 49, -1, 48, -1, 45, -1, - 46, -1, 47, -1, 49, 53, -1, 50, 54, 49, - -1, 50, 48, -1, 55, 50, -1, 48, 55, 50, - -1, 51, -1, 45, -1, 49, -1, 46, -1, 52, - -1, 56, -1, 34, -1, 6, 38, 7, -1, 15, - -1, 15, -1, 16, -1, 17, -1, 18, -1, 19, - -1, 20, -1, 21, -1, 22, -1, 10, 57, 7, - -1, -1, 56, -1, 58, -1, 57, 56, -1, 57, - 58, -1, 15, -1, 54, -1, 17, -1 + 24, 0, -1, -1, 26, -1, 3, 3, 30, -1, + -1, 8, 4, 25, 27, 9, -1, 37, -1, 33, + 37, -1, -1, 36, 28, 29, -1, 29, -1, 30, + -1, 29, 3, 30, -1, 31, 37, -1, 31, 33, + 37, -1, 54, -1, 55, 53, -1, 32, -1, 56, + 53, -1, 32, 56, 53, -1, 4, 34, 4, -1, + 53, -1, 34, 53, -1, 8, 9, -1, 8, 37, + 9, -1, 8, 36, 4, 37, 9, -1, 12, 53, + -1, 36, 12, 53, -1, 14, 39, -1, 38, -1, + 38, 11, -1, 38, 11, 14, 39, -1, 39, -1, + 38, 11, 39, -1, 52, -1, 40, 52, -1, 45, + -1, 40, 45, -1, 42, -1, 40, 42, -1, 41, + -1, 40, 41, -1, 53, 5, -1, 45, 43, -1, + 13, 44, -1, 43, 13, 44, -1, 54, -1, 55, + 50, -1, 49, -1, 46, -1, 47, -1, 48, -1, + 50, 54, -1, 51, 55, 50, -1, 51, 49, -1, + 56, 51, -1, 49, 56, 51, -1, 52, -1, 46, + -1, 50, -1, 47, -1, 53, -1, 57, -1, 35, + -1, 6, 39, 7, -1, 15, -1, 15, -1, 16, + -1, 17, -1, 18, -1, 19, -1, 20, -1, 21, + -1, 22, -1, 10, 58, 7, -1, -1, 57, -1, + 59, -1, 58, 57, -1, 58, 59, -1, 15, -1, + 55, -1, 17, -1 }; /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const unsigned short yyrline[] = { - 0, 69, 69, 74, 79, 84, 89, 99, 98, 104, - 107, 111, 117, 122, 131, 136, 141, 144, 149, 156, - 160, 165, 172, 176, 180, 186, 191, 198, 203, 209, - 214, 223, 228, 234, 239, 245, 246, 251, 252, 258, - 263, 270, 273, 279, 284, 290, 295, 300, 303, 304, - 305, 307, 316, 325, 332, 337, 343, 344, 346, 347, - 349, 353, 357, 361, 366, 368, 370, 372, 375, 377, - 379, 381, 383, 385, 388, 389, 391, 393, 394, 396, - 398, 400 + 0, 69, 69, 74, 79, 86, 85, 93, 98, 108, + 107, 113, 116, 120, 126, 131, 140, 145, 150, 153, + 158, 165, 169, 174, 181, 185, 189, 195, 200, 207, + 212, 218, 223, 232, 237, 243, 248, 254, 255, 260, + 261, 267, 272, 279, 282, 288, 293, 299, 304, 309, + 312, 313, 314, 316, 325, 334, 341, 346, 352, 353, + 355, 356, 358, 362, 366, 370, 375, 377, 379, 381, + 384, 386, 388, 390, 392, 394, 397, 398, 400, 402, + 403, 405, 407, 409 }; #endif @@ -385,7 +386,7 @@ static const char *const yytname[] = "TK_ARRAY_OPEN", "TK_DOT", "TK_COLON", "TK_SEMICOLON", "TK_RETURN", "TK_IDENTIFIER", "TK_BINARY_SELECTOR", "TK_KEYWORD", "TK_INTNUMBER", "TK_REALNUMBER", "TK_SYMBOL", "TK_STRING", "TK_CHARACTER", "$accept", - "source", "single_method", "methods", "@1", "method_list", "method", + "source", "@1", "plain_code", "methods", "@2", "method_list", "method", "message_pattern", "keyword_list", "temporaries", "variable_list", "block", "block_var_list", "statements", "expressions", "expression", "assignments", "assignment", "cascade", "cascade_list", "cascade_item", @@ -410,29 +411,29 @@ static const unsigned short yytoknum[] = /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ static const unsigned char yyr1[] = { - 0, 23, 24, 24, 24, 25, 25, 27, 26, 26, - 28, 28, 29, 29, 30, 30, 30, 31, 31, 32, - 33, 33, 34, 34, 34, 35, 35, 36, 36, 36, - 36, 37, 37, 38, 38, 38, 38, 38, 38, 39, - 39, 40, 41, 42, 42, 43, 43, 43, 44, 44, - 44, 45, 46, 47, 48, 48, 49, 49, 50, 50, - 51, 51, 51, 51, 52, 53, 54, 55, 56, 56, - 56, 56, 56, 56, 57, 57, 57, 57, 57, 58, - 58, 58 + 0, 23, 24, 24, 24, 25, 24, 26, 26, 28, + 27, 27, 29, 29, 30, 30, 31, 31, 31, 32, + 32, 33, 34, 34, 35, 35, 35, 36, 36, 37, + 37, 37, 37, 38, 38, 39, 39, 39, 39, 39, + 39, 40, 40, 41, 42, 43, 43, 44, 44, 44, + 45, 45, 45, 46, 47, 48, 49, 49, 50, 50, + 51, 51, 52, 52, 52, 52, 53, 54, 55, 56, + 57, 57, 57, 57, 57, 57, 58, 58, 58, 58, + 58, 59, 59, 59 }; /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ static const unsigned char yyr2[] = { - 0, 2, 0, 1, 4, 1, 2, 0, 3, 1, - 1, 3, 2, 3, 1, 2, 1, 2, 3, 3, - 1, 2, 2, 3, 5, 2, 3, 2, 1, 2, - 4, 1, 3, 1, 2, 1, 2, 1, 2, 1, - 2, 2, 2, 2, 3, 1, 2, 1, 1, 1, - 1, 2, 3, 2, 2, 3, 1, 1, 1, 1, - 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 3, 0, 1, 1, 2, 2, 1, - 1, 1 + 0, 2, 0, 1, 3, 0, 5, 1, 2, 0, + 3, 1, 1, 3, 2, 3, 1, 2, 1, 2, + 3, 3, 1, 2, 2, 3, 5, 2, 3, 2, + 1, 2, 4, 1, 3, 1, 2, 1, 2, 1, + 2, 1, 2, 2, 2, 2, 3, 1, 2, 1, + 1, 1, 1, 2, 3, 2, 2, 3, 1, 1, + 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 3, 0, 1, 1, 2, + 2, 1, 1, 1 }; /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state @@ -440,136 +441,136 @@ static const unsigned char yyr2[] = means the default is an error. */ static const unsigned char yydefact[] = { - 2, 0, 0, 0, 74, 0, 64, 68, 69, 70, - 71, 72, 0, 3, 0, 62, 5, 28, 31, 0, - 39, 37, 35, 48, 49, 50, 58, 0, 33, 60, - 61, 0, 20, 0, 0, 0, 22, 0, 0, 0, - 79, 66, 81, 80, 75, 0, 76, 27, 1, 6, - 29, 40, 38, 36, 34, 0, 42, 65, 51, 67, - 53, 0, 0, 41, 19, 21, 63, 0, 9, 10, - 0, 16, 7, 14, 0, 0, 25, 0, 0, 23, - 73, 77, 78, 0, 32, 43, 47, 45, 0, 0, - 0, 57, 52, 56, 60, 59, 54, 4, 0, 0, - 12, 0, 0, 15, 17, 0, 26, 30, 46, 44, - 55, 11, 13, 18, 8, 24 + 2, 0, 0, 0, 0, 76, 0, 66, 70, 71, + 72, 73, 74, 0, 3, 0, 64, 7, 30, 33, + 0, 41, 39, 37, 50, 51, 52, 60, 0, 35, + 62, 63, 0, 0, 22, 0, 0, 5, 24, 0, + 0, 0, 81, 68, 83, 82, 77, 0, 78, 29, + 1, 8, 31, 42, 40, 38, 36, 0, 44, 67, + 53, 69, 55, 0, 0, 43, 4, 0, 18, 16, + 0, 0, 21, 23, 65, 0, 27, 0, 0, 25, + 75, 79, 80, 0, 34, 45, 49, 47, 0, 0, + 0, 59, 54, 58, 62, 61, 56, 0, 14, 0, + 17, 19, 0, 11, 12, 9, 0, 28, 32, 48, + 46, 57, 15, 20, 6, 0, 0, 26, 13, 10 }; /* YYDEFGOTO[NTERM-NUM]. */ static const yysigned_char yydefgoto[] = { - -1, 12, 13, 67, 102, 68, 69, 70, 71, 14, - 31, 15, 38, 39, 17, 18, 19, 20, 21, 56, - 85, 22, 23, 24, 25, 86, 26, 27, 28, 29, - 58, 61, 62, 30, 45, 46 + -1, 13, 75, 14, 102, 116, 103, 104, 67, 68, + 15, 33, 16, 40, 41, 18, 19, 20, 21, 22, + 58, 85, 23, 24, 25, 26, 86, 27, 28, 29, + 30, 69, 70, 71, 31, 47, 48 }; /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing STATE-NUM. */ -#define YYPACT_NINF -58 +#define YYPACT_NINF -60 static const short yypact[] = { - 117, -4, 204, 98, 3, 204, -58, -58, -58, -58, - -58, -58, 17, -58, 170, -58, -58, 23, -58, 204, - -58, -58, 15, 28, 49, -58, 31, 66, 47, 43, - -58, 11, -58, 153, 68, 42, -58, -4, 27, 71, - -58, -58, -58, -58, -58, 220, -58, -58, -58, -58, - 187, -58, -58, 15, 47, 53, 72, -58, -58, -58, - 39, 204, 204, -58, -58, -58, -58, 79, 88, -58, - 136, 39, 80, -58, -4, -4, -58, 170, -4, -58, - -58, -58, -58, 204, -58, -58, 39, -58, 204, 53, - 204, -58, 31, -58, -58, -58, 77, -58, 53, 170, - -58, -4, 53, -58, -58, 87, -58, -58, 31, -58, - 77, -58, -58, -58, 88, -58 + 104, 11, 0, 38, 123, 222, 38, -60, -60, -60, + -60, -60, -60, 17, -60, 176, -60, -60, 9, -60, + 38, -60, -60, 8, 34, 10, -60, 18, 50, 78, + 49, -60, 100, 7, -60, 159, 54, -60, -60, 0, + 12, 55, -60, -60, -60, -60, -60, 209, -60, -60, + -60, -60, 193, -60, -60, 8, 78, 100, 60, -60, + -60, -60, 57, 38, 38, -60, -60, 142, 57, -60, + 0, 0, -60, -60, -60, 13, -60, 176, 0, -60, + -60, -60, -60, 38, -60, -60, 57, -60, 38, 100, + 38, -60, 18, -60, -60, -60, 64, 176, -60, 0, + -60, -60, 67, 79, -60, 71, 81, -60, -60, 18, + -60, 64, -60, -60, -60, 100, 100, -60, -60, 79 }; /* YYPGOTO[NTERM-NUM]. */ static const yysigned_char yypgoto[] = { - -58, -58, -58, -58, -58, -5, 0, -58, -58, 33, - -58, -58, 70, 2, -58, 1, -58, 90, 92, -58, - 25, 96, -53, -57, -58, 95, -47, -52, -12, -1, - -8, -3, -31, 8, -58, 81 + -60, -60, -60, -60, -60, -60, -28, -30, -60, -60, + 29, -60, -60, 22, 4, -60, 3, -60, 80, 82, + -60, 20, 84, -51, -59, -60, 83, -45, -56, 15, + -1, -17, -5, -21, -2, -60, 52 }; /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If positive, shift that token. If negative, reduce the rule which number is the opposite. If zero, do what YYDEFACT says. If YYTABLE_NINF, syntax error. */ -#define YYTABLE_NINF -60 +#define YYTABLE_NINF -62 static const yysigned_char yytable[] = { - 32, 43, 16, 34, 75, 95, 47, 54, 91, 91, - 96, 6, 44, 4, 92, 64, 49, 48, 40, 41, - 42, 7, 8, 9, 10, 11, 6, 73, 55, 90, - 65, 77, 74, 95, 50, 91, 76, 91, 110, 78, - 101, 108, 43, -57, -57, -57, 57, 87, 63, 93, - 93, 84, 88, 81, 37, 90, 59, 57, 41, 59, - 94, 94, -56, -56, -56, -59, -59, 75, 57, 41, - 59, 75, 100, 103, 104, 66, 93, 106, 93, 105, - 79, 87, 41, 59, 107, 89, 88, 94, 97, 94, - 73, 98, 78, 41, 73, 74, 115, 114, 111, 74, - 113, 112, 35, 99, 2, 72, 33, 36, 4, 51, - 37, 52, 5, 6, 109, 53, 7, 8, 9, 10, - 11, 1, 60, 2, 0, 3, 82, 4, 0, 0, - 0, 5, 6, 0, 0, 7, 8, 9, 10, 11, - 1, 0, 2, 0, 33, 0, 4, 0, 0, 0, - 5, 6, 0, 0, 7, 8, 9, 10, 11, 2, - 0, 33, 36, 4, 0, 37, 0, 5, 6, 0, - 0, 7, 8, 9, 10, 11, 2, 0, 33, 0, - 4, 0, 0, 0, 5, 6, 0, 0, 7, 8, - 9, 10, 11, 2, 0, 33, 0, 4, 0, 0, - 0, 83, 6, 0, 0, 7, 8, 9, 10, 11, - 2, 0, 33, 0, 4, 0, 0, 0, 0, 6, - 0, 0, 7, 8, 9, 10, 11, 80, 0, 0, - 4, 0, 0, 0, 0, 40, 41, 42, 7, 8, - 9, 10, 11 + 45, 34, 66, 46, 17, 95, 36, 64, 96, 49, + 60, 72, 91, 91, 32, 7, 77, 50, 92, 51, + 52, 57, 7, 63, 78, 39, -61, -61, 59, 43, + 61, 95, 73, 59, 111, 56, 64, 91, 76, 91, + 87, 90, 45, 109, 3, 81, 35, 99, 5, -59, + -59, -59, 88, 7, 65, 84, 8, 9, 10, 11, + 12, 74, 94, 94, 79, 90, 43, 61, 64, 100, + 101, 98, 87, 89, 61, 60, 114, 107, 93, 93, + 43, 106, 115, 78, 88, 118, 108, 94, 119, 94, + 117, 63, 60, -58, -58, -58, 97, 105, 113, 82, + 53, 112, 54, 93, 55, 93, 63, 1, 2, 110, + 3, 62, 4, 0, 5, 59, 43, 61, 6, 7, + 0, 0, 8, 9, 10, 11, 12, 37, 0, 3, + 0, 35, 38, 5, 0, 39, 0, 6, 7, 0, + 0, 8, 9, 10, 11, 12, 2, 0, 3, 0, + 35, 0, 5, 0, 0, 0, 6, 7, 0, 0, + 8, 9, 10, 11, 12, 3, 0, 35, 38, 5, + 0, 39, 0, 6, 7, 0, 0, 8, 9, 10, + 11, 12, 3, 0, 35, 0, 5, 0, 0, 0, + 6, 7, 0, 0, 8, 9, 10, 11, 12, 3, + 0, 35, 0, 5, 0, 0, 0, 83, 7, 0, + 0, 8, 9, 10, 11, 12, 80, 0, 0, 5, + 0, 0, 0, 0, 42, 43, 44, 8, 9, 10, + 11, 12, 5, 0, 0, 0, 0, 42, 43, 44, + 8, 9, 10, 11, 12 }; static const yysigned_char yycheck[] = { - 1, 4, 0, 2, 35, 62, 5, 19, 61, 62, - 62, 15, 4, 10, 61, 4, 14, 0, 15, 16, - 17, 18, 19, 20, 21, 22, 15, 35, 13, 60, - 31, 4, 35, 90, 11, 88, 37, 90, 90, 12, - 71, 88, 45, 15, 16, 17, 15, 55, 5, 61, - 62, 50, 55, 45, 12, 86, 17, 15, 16, 17, - 61, 62, 15, 16, 17, 16, 17, 98, 15, 16, - 17, 102, 70, 74, 75, 7, 88, 78, 90, 77, - 9, 89, 16, 17, 83, 13, 89, 88, 9, 90, - 98, 3, 12, 16, 102, 98, 9, 102, 98, 102, - 101, 99, 4, 70, 6, 35, 8, 9, 10, 19, - 12, 19, 14, 15, 89, 19, 18, 19, 20, 21, - 22, 4, 27, 6, -1, 8, 45, 10, -1, -1, - -1, 14, 15, -1, -1, 18, 19, 20, 21, 22, - 4, -1, 6, -1, 8, -1, 10, -1, -1, -1, - 14, 15, -1, -1, 18, 19, 20, 21, 22, 6, + 5, 2, 32, 5, 0, 64, 3, 28, 64, 6, + 27, 4, 63, 64, 3, 15, 4, 0, 63, 15, + 11, 13, 15, 28, 12, 12, 16, 17, 15, 16, + 17, 90, 33, 15, 90, 20, 57, 88, 39, 90, + 57, 62, 47, 88, 6, 47, 8, 68, 10, 15, + 16, 17, 57, 15, 5, 52, 18, 19, 20, 21, + 22, 7, 63, 64, 9, 86, 16, 17, 89, 70, + 71, 67, 89, 13, 17, 92, 9, 78, 63, 64, + 16, 77, 3, 12, 89, 115, 83, 88, 116, 90, + 9, 96, 109, 15, 16, 17, 67, 75, 99, 47, + 20, 97, 20, 88, 20, 90, 111, 3, 4, 89, + 6, 28, 8, -1, 10, 15, 16, 17, 14, 15, + -1, -1, 18, 19, 20, 21, 22, 4, -1, 6, -1, 8, 9, 10, -1, 12, -1, 14, 15, -1, - -1, 18, 19, 20, 21, 22, 6, -1, 8, -1, - 10, -1, -1, -1, 14, 15, -1, -1, 18, 19, - 20, 21, 22, 6, -1, 8, -1, 10, -1, -1, - -1, 14, 15, -1, -1, 18, 19, 20, 21, 22, - 6, -1, 8, -1, 10, -1, -1, -1, -1, 15, - -1, -1, 18, 19, 20, 21, 22, 7, -1, -1, - 10, -1, -1, -1, -1, 15, 16, 17, 18, 19, - 20, 21, 22 + -1, 18, 19, 20, 21, 22, 4, -1, 6, -1, + 8, -1, 10, -1, -1, -1, 14, 15, -1, -1, + 18, 19, 20, 21, 22, 6, -1, 8, 9, 10, + -1, 12, -1, 14, 15, -1, -1, 18, 19, 20, + 21, 22, 6, -1, 8, -1, 10, -1, -1, -1, + 14, 15, -1, -1, 18, 19, 20, 21, 22, 6, + -1, 8, -1, 10, -1, -1, -1, 14, 15, -1, + -1, 18, 19, 20, 21, 22, 7, -1, -1, 10, + -1, -1, -1, -1, 15, 16, 17, 18, 19, 20, + 21, 22, 10, -1, -1, -1, -1, 15, 16, 17, + 18, 19, 20, 21, 22 }; /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing symbol of state STATE-NUM. */ static const unsigned char yystos[] = { - 0, 4, 6, 8, 10, 14, 15, 18, 19, 20, - 21, 22, 24, 25, 32, 34, 36, 37, 38, 39, - 40, 41, 44, 45, 46, 47, 49, 50, 51, 52, - 56, 33, 52, 8, 38, 4, 9, 12, 35, 36, - 15, 16, 17, 54, 56, 57, 58, 38, 0, 36, - 11, 40, 41, 44, 51, 13, 42, 15, 53, 17, - 48, 54, 55, 5, 4, 52, 7, 26, 28, 29, - 30, 31, 35, 53, 54, 55, 52, 4, 12, 9, - 7, 56, 58, 14, 38, 43, 48, 53, 54, 13, - 55, 45, 49, 51, 52, 46, 50, 9, 3, 32, - 36, 55, 27, 52, 52, 36, 52, 38, 49, 43, - 50, 29, 36, 52, 28, 9 + 0, 3, 4, 6, 8, 10, 14, 15, 18, 19, + 20, 21, 22, 24, 26, 33, 35, 37, 38, 39, + 40, 41, 42, 45, 46, 47, 48, 50, 51, 52, + 53, 57, 3, 34, 53, 8, 39, 4, 9, 12, + 36, 37, 15, 16, 17, 55, 57, 58, 59, 39, + 0, 37, 11, 41, 42, 45, 52, 13, 43, 15, + 54, 17, 49, 55, 56, 5, 30, 31, 32, 54, + 55, 56, 4, 53, 7, 25, 53, 4, 12, 9, + 7, 57, 59, 14, 39, 44, 49, 54, 55, 13, + 56, 46, 50, 52, 53, 47, 51, 33, 37, 56, + 53, 53, 27, 29, 30, 36, 37, 53, 39, 50, + 44, 51, 37, 53, 9, 3, 28, 9, 30, 29 }; #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) @@ -1193,16 +1194,30 @@ yyreduce: ;} break; + case 4: +#line 80 "STGrammar.y" + { + [COMPILER compileMethod:yyvsp[-2]]; + ;} + break; + case 5: -#line 85 "STGrammar.y" +#line 86 "STGrammar.y" + { + [COMPILER beginScript]; + ;} + break; + + case 7: +#line 94 "STGrammar.y" { yyval = [STCMethod methodWithPattern:nil /**/ statements:yyvsp[0]]; ;} break; - case 6: -#line 90 "STGrammar.y" + case 8: +#line 99 "STGrammar.y" { [yyvsp[0] setTemporaries:yyvsp[-1]]; yyval = [STCMethod methodWithPattern:nil @@ -1210,37 +1225,37 @@ yyreduce: ;} break; - case 7: -#line 99 "STGrammar.y" + case 9: +#line 108 "STGrammar.y" { [COMPILER setReceiverVariables:yyvsp[0]]; ;} break; - case 10: -#line 108 "STGrammar.y" - { - [COMPILER compileMethod:yyvsp[0]]; - ;} - break; - - case 11: -#line 112 "STGrammar.y" - { - [COMPILER compileMethod:yyvsp[0]]; - ;} - break; - case 12: -#line 118 "STGrammar.y" +#line 117 "STGrammar.y" + { + [COMPILER compileMethod:yyvsp[0]]; + ;} + break; + + case 13: +#line 121 "STGrammar.y" + { + [COMPILER compileMethod:yyvsp[0]]; + ;} + break; + + case 14: +#line 127 "STGrammar.y" { yyval = [STCMethod methodWithPattern:yyvsp[-1] /**/ statements:yyvsp[0]]; ;} break; - case 13: -#line 123 "STGrammar.y" + case 15: +#line 132 "STGrammar.y" { [yyvsp[0] setTemporaries:yyvsp[-1]]; yyval = [STCMethod methodWithPattern:yyvsp[-2] @@ -1248,123 +1263,123 @@ yyreduce: ;} break; - case 14: -#line 132 "STGrammar.y" + case 16: +#line 141 "STGrammar.y" { yyval = [STCMessage message]; [yyval addKeyword:yyvsp[0] object:nil]; ;} break; - case 15: -#line 137 "STGrammar.y" - { - yyval = [STCMessage message]; - [yyval addKeyword:yyvsp[-1] object:yyvsp[0]]; - ;} - break; - case 17: -#line 145 "STGrammar.y" +#line 146 "STGrammar.y" { yyval = [STCMessage message]; [yyval addKeyword:yyvsp[-1] object:yyvsp[0]]; ;} break; - case 18: -#line 150 "STGrammar.y" + case 19: +#line 154 "STGrammar.y" + { + yyval = [STCMessage message]; + [yyval addKeyword:yyvsp[-1] object:yyvsp[0]]; + ;} + break; + + case 20: +#line 159 "STGrammar.y" { [yyvsp[-2] addKeyword:yyvsp[-1] object:yyvsp[0]]; yyval = yyvsp[-2]; ;} break; - case 19: -#line 157 "STGrammar.y" + case 21: +#line 166 "STGrammar.y" { yyval = yyvsp[-1]; ;} break; - case 20: -#line 161 "STGrammar.y" + case 22: +#line 170 "STGrammar.y" { yyval = [NSMutableArray array]; [yyval addObject:yyvsp[0]]; ;} break; - case 21: -#line 166 "STGrammar.y" + case 23: +#line 175 "STGrammar.y" { yyval = yyvsp[-1]; [yyval addObject:yyvsp[0]]; ;} break; - case 22: -#line 173 "STGrammar.y" + case 24: +#line 182 "STGrammar.y" { yyval = [STCStatements statements]; ;} break; - case 23: -#line 177 "STGrammar.y" + case 25: +#line 186 "STGrammar.y" { yyval = yyvsp[-1]; ;} break; - case 24: -#line 181 "STGrammar.y" + case 26: +#line 190 "STGrammar.y" { yyval = yyvsp[-1]; [yyval setTemporaries:yyvsp[-3]]; ;} break; - case 25: -#line 187 "STGrammar.y" + case 27: +#line 196 "STGrammar.y" { yyval = [NSMutableArray array]; [yyval addObject:yyvsp[0]]; ;} break; - case 26: -#line 192 "STGrammar.y" + case 28: +#line 201 "STGrammar.y" { yyval = yyvsp[-2]; [yyval addObject:yyvsp[0]]; ;} break; - case 27: -#line 199 "STGrammar.y" + case 29: +#line 208 "STGrammar.y" { yyval = [STCStatements statements]; [yyval setReturnExpression:yyvsp[0]]; ;} break; - case 28: -#line 204 "STGrammar.y" + case 30: +#line 213 "STGrammar.y" { yyval = [STCStatements statements]; [yyval setExpressions:yyvsp[0]]; ;} break; - case 29: -#line 210 "STGrammar.y" + case 31: +#line 219 "STGrammar.y" { yyval = [STCStatements statements]; [yyval setExpressions:yyvsp[-1]]; ;} break; - case 30: -#line 215 "STGrammar.y" + case 32: +#line 224 "STGrammar.y" { yyval = [STCStatements statements]; [yyval setReturnExpression:yyvsp[0]]; @@ -1372,118 +1387,118 @@ yyreduce: ;} break; - case 31: -#line 223 "STGrammar.y" + case 33: +#line 232 "STGrammar.y" { yyval = [NSMutableArray array]; [yyval addObject:yyvsp[0]]; ;} break; - case 32: -#line 229 "STGrammar.y" + case 34: +#line 238 "STGrammar.y" { yyval = yyvsp[-2]; [yyval addObject:yyvsp[0]]; ;} break; - case 33: -#line 235 "STGrammar.y" + case 35: +#line 244 "STGrammar.y" { yyval = [STCExpression /**/ primaryExpressionWithObject:yyvsp[0]]; ;} break; - case 34: -#line 240 "STGrammar.y" - { - yyval = [STCExpression - /**/ primaryExpressionWithObject:yyvsp[0]]; - [yyval setAssignments:yyvsp[-1]]; - ;} - break; - case 36: -#line 247 "STGrammar.y" +#line 249 "STGrammar.y" { - yyval = yyvsp[0]; + yyval = [STCExpression + /**/ primaryExpressionWithObject:yyvsp[0]]; [yyval setAssignments:yyvsp[-1]]; ;} break; case 38: -#line 253 "STGrammar.y" +#line 256 "STGrammar.y" { yyval = yyvsp[0]; [yyval setAssignments:yyvsp[-1]]; ;} break; - case 39: -#line 259 "STGrammar.y" + case 40: +#line 262 "STGrammar.y" + { + yyval = yyvsp[0]; + [yyval setAssignments:yyvsp[-1]]; + ;} + break; + + case 41: +#line 268 "STGrammar.y" { yyval = [NSMutableArray array]; [yyval addObject:yyvsp[0]]; ;} break; - case 40: -#line 264 "STGrammar.y" + case 42: +#line 273 "STGrammar.y" { yyval = yyvsp[-1]; [yyval addObject:yyvsp[0]]; ;} break; - case 41: -#line 271 "STGrammar.y" + case 43: +#line 280 "STGrammar.y" { yyval = yyvsp[-1];;} break; - case 42: -#line 274 "STGrammar.y" + case 44: +#line 283 "STGrammar.y" { /* FIXME: check if this is this OK */ [yyval setCascade:yyvsp[0]]; ;} break; - case 43: -#line 280 "STGrammar.y" + case 45: +#line 289 "STGrammar.y" { yyval = [NSMutableArray array]; [yyval addObject:yyvsp[0]]; ;} break; - case 44: -#line 285 "STGrammar.y" + case 46: +#line 294 "STGrammar.y" { yyval = yyvsp[-2]; [yyval addObject:yyvsp[0]]; ;} break; - case 45: -#line 291 "STGrammar.y" + case 47: +#line 300 "STGrammar.y" { yyval = [STCMessage message]; [yyval addKeyword:yyvsp[0] object:nil]; ;} break; - case 46: -#line 296 "STGrammar.y" + case 48: +#line 305 "STGrammar.y" { yyval = [STCMessage message]; [yyval addKeyword:yyvsp[-1] object:yyvsp[0]]; ;} break; - case 51: -#line 308 "STGrammar.y" + case 53: +#line 317 "STGrammar.y" { STCMessage *message = [STCMessage message]; [message addKeyword:yyvsp[0] object:nil]; @@ -1493,8 +1508,8 @@ yyreduce: ;} break; - case 52: -#line 317 "STGrammar.y" + case 54: +#line 326 "STGrammar.y" { STCMessage *message = [STCMessage message]; [message addKeyword:yyvsp[-1] object:yyvsp[0]]; @@ -1504,8 +1519,8 @@ yyreduce: ;} break; - case 53: -#line 326 "STGrammar.y" + case 55: +#line 335 "STGrammar.y" { yyval = [STCExpression /**/ messageExpressionWithTarget:yyvsp[-1] @@ -1513,119 +1528,119 @@ yyreduce: ;} break; - case 54: -#line 333 "STGrammar.y" + case 56: +#line 342 "STGrammar.y" { yyval = [STCMessage message]; [yyval addKeyword:yyvsp[-1] object:yyvsp[0]]; ;} break; - case 55: -#line 338 "STGrammar.y" + case 57: +#line 347 "STGrammar.y" { yyval = yyvsp[-2]; [yyval addKeyword:yyvsp[-1] object:yyvsp[0]]; ;} break; - case 60: -#line 350 "STGrammar.y" + case 62: +#line 359 "STGrammar.y" { yyval = [STCPrimary primaryWithVariable:yyvsp[0]]; ;} break; - case 61: -#line 354 "STGrammar.y" + case 63: +#line 363 "STGrammar.y" { yyval = [STCPrimary primaryWithLiteral:yyvsp[0]]; ;} break; - case 62: -#line 358 "STGrammar.y" + case 64: +#line 367 "STGrammar.y" { yyval = [STCPrimary primaryWithBlock:yyvsp[0]]; ;} break; - case 63: -#line 362 "STGrammar.y" + case 65: +#line 371 "STGrammar.y" { yyval = [STCPrimary primaryWithExpression:yyvsp[-1]]; ;} break; - case 68: -#line 376 "STGrammar.y" + case 70: +#line 385 "STGrammar.y" { yyval = [COMPILER createIntNumberLiteralFrom:yyvsp[0]]; ;} break; - case 69: -#line 378 "STGrammar.y" + case 71: +#line 387 "STGrammar.y" { yyval = [COMPILER createRealNumberLiteralFrom:yyvsp[0]]; ;} break; - case 70: -#line 380 "STGrammar.y" + case 72: +#line 389 "STGrammar.y" { yyval = [COMPILER createSymbolLiteralFrom:yyvsp[0]]; ;} break; - case 71: -#line 382 "STGrammar.y" + case 73: +#line 391 "STGrammar.y" { yyval = [COMPILER createStringLiteralFrom:yyvsp[0]]; ;} break; - case 72: -#line 384 "STGrammar.y" + case 74: +#line 393 "STGrammar.y" { yyval = [COMPILER createCharacterLiteralFrom:yyvsp[0]]; ;} break; - case 73: -#line 386 "STGrammar.y" + case 75: +#line 395 "STGrammar.y" { yyval = [COMPILER createArrayLiteralFrom:yyvsp[-1]]; ;} break; - case 74: -#line 388 "STGrammar.y" + case 76: +#line 397 "STGrammar.y" { yyval = [NSMutableArray array]; ;} break; - case 75: -#line 389 "STGrammar.y" + case 77: +#line 398 "STGrammar.y" { yyval = [NSMutableArray array]; [yyval addObject:yyvsp[0]]; ;} break; - case 76: -#line 391 "STGrammar.y" + case 78: +#line 400 "STGrammar.y" { yyval = [NSMutableArray array]; [yyval addObject:yyvsp[0]]; ;} break; - case 77: -#line 393 "STGrammar.y" - { yyval = yyvsp[-1]; [yyval addObject:yyvsp[0]]; ;} - break; - - case 78: -#line 394 "STGrammar.y" - { yyval = yyvsp[-1]; [yyval addObject:yyvsp[0]]; ;} - break; - case 79: -#line 397 "STGrammar.y" - { yyval = [COMPILER createSymbolLiteralFrom:yyvsp[0]]; ;} +#line 402 "STGrammar.y" + { yyval = yyvsp[-1]; [yyval addObject:yyvsp[0]]; ;} break; case 80: -#line 399 "STGrammar.y" - { yyval = [COMPILER createSymbolLiteralFrom:yyvsp[0]]; ;} +#line 403 "STGrammar.y" + { yyval = yyvsp[-1]; [yyval addObject:yyvsp[0]]; ;} break; case 81: -#line 401 "STGrammar.y" +#line 406 "STGrammar.y" + { yyval = [COMPILER createSymbolLiteralFrom:yyvsp[0]]; ;} + break; + + case 82: +#line 408 "STGrammar.y" + { yyval = [COMPILER createSymbolLiteralFrom:yyvsp[0]]; ;} + break; + + case 83: +#line 410 "STGrammar.y" { yyval = [COMPILER createSymbolLiteralFrom:yyvsp[0]]; ;} break; @@ -1633,7 +1648,7 @@ yyreduce: } /* Line 999 of yacc.c. */ -#line 1637 "STGrammar.m" +#line 1652 "STGrammar.m" yyvsp -= yylen; yyssp -= yylen; @@ -1827,7 +1842,7 @@ yyreturn: } -#line 403 "STGrammar.y" +#line 412 "STGrammar.y" int STCerror(const char *str) diff --git a/Languages/Smalltalk/STGrammar.y b/Languages/Smalltalk/STGrammar.y index a3d23c8..7fac837 100644 --- a/Languages/Smalltalk/STGrammar.y +++ b/Languages/Smalltalk/STGrammar.y @@ -71,17 +71,26 @@ source: /* empty string */ { } - | single_method { + | plain_code { [COMPILER compileMethod:$1]; } + /* FIXME: this is a hack */ + | TK_SEPARATOR TK_SEPARATOR method + { + [COMPILER compileMethod:$1]; + } + | TK_BLOCK_OPEN TK_BAR + { + [COMPILER beginScript]; + } methods - TK_BLOCK_CLOSE + TK_BLOCK_CLOSE ; -single_method: statements +plain_code: statements { $$ = [STCMethod methodWithPattern:nil /**/ statements:$1]; diff --git a/Languages/Smalltalk/STSmalltalkScriptObject.m b/Languages/Smalltalk/STSmalltalkScriptObject.m index f5594e5..007a85c 100644 --- a/Languages/Smalltalk/STSmalltalkScriptObject.m +++ b/Languages/Smalltalk/STSmalltalkScriptObject.m @@ -128,8 +128,7 @@ NSDebugLLog(@"STEngine", @"creating new interpreter for script '%@'", name); - interpreter = [[STBytecodeInterpreter alloc] init]; - [interpreter setEnvironment:environment]; + interpreter = [[STBytecodeInterpreter alloc] initWithEnvironment:environment]; } diff --git a/Languages/Smalltalk/SmalltalkEngine.m b/Languages/Smalltalk/SmalltalkEngine.m index dc328f6..e218fb3 100644 --- a/Languages/Smalltalk/SmalltalkEngine.m +++ b/Languages/Smalltalk/SmalltalkEngine.m @@ -29,8 +29,10 @@ #import "STCompiler.h" #import "STCompiledCode.h" #import "STCompiledScript.h" +#import "STBytecodeInterpreter.h" #import +#import #import #import @@ -77,4 +79,33 @@ return retval; } + +- (id )methodFromSource:(NSString *)sourceString + forReceiver:(id)receiver + inEnvironment:(STEnvironment *)env +{ + STCompiler *compiler; + STCompiledMethod *method; + + compiler = [STCompiler compilerWithEnvironment:env]; + + method = [compiler compileMethodFromSource:sourceString + forReceiver:receiver]; + + return method; +} +- (id) executeMethod:(id )aMethod + forReceiver:(id)anObject + withArguments:(NSArray *)args + inEnvironment:(STEnvironment *)env +{ + STBytecodeInterpreter *interpreter; + id result; + interpreter = [STBytecodeInterpreter interpreterWithEnvrionment:env]; + + result = [interpreter interpretMethod:aMethod + forReceiver:anObject + arguments:args]; + return result; +} @end diff --git a/Source/.cvsignore b/Source/.cvsignore deleted file mode 100644 index 862e5dc..0000000 --- a/Source/.cvsignore +++ /dev/null @@ -1,7 +0,0 @@ -*.app -*.debug -*.profile -shared_*obj -*.bundle -*.stmodule -*.stlanguage diff --git a/TODO b/TODO index ed7c850..c0cc71d 100644 --- a/TODO +++ b/TODO @@ -13,3 +13,5 @@ TODO list 14 Add framework list into environment description 15 Change Modules to Framework 16 Remove StepTalk modules +17 Fill implementation of STScriptObject, STMethod and related STEngine methods +18 Rewrite Smalltalk compiler (grammar)