From c2c2d222545031527b9aaf0f2f301a909028025b Mon Sep 17 00:00:00 2001 From: Adam Fedor Date: Mon, 13 May 2002 22:13:06 +0000 Subject: [PATCH] Initial revision git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/steptalk/trunk@13642 72102866-910b-0410-8b05-ffd578937521 --- .dist-ignore | 3 + COPYING | 340 ++++ COPYING.LIB | 504 ++++++ ChangeLog | 138 ++ Documentation/ApplicationScripting.txt | 17 + Documentation/Defaults.txt | 15 + Documentation/Environment.txt | 57 + Documentation/HowTo.txt | 28 + Documentation/Languages.txt | 21 + Documentation/ObjCTypes.txt | 7 + Documentation/Old/DESIGN | 183 +++ Documentation/Smalltalk.txt | 174 ++ Examples/AppKit/listFonts.st | 45 + Examples/AppKit/openPanel.st | 7 + Examples/AppKit/panel.st | 12 + Examples/AppKit/pb.st | 8 + Examples/AppKit/printers.st | 11 + Examples/AppKit/rtf2text.st | 29 + Examples/AppKit/text.st | 22 + Examples/ReadMe.txt | 69 + Examples/Server/GNUmakefile | 35 + Examples/Server/Server.m | 65 + Examples/Server/talkToServer.st | 20 + Examples/Smalltalk/createFile.st | 17 + Examples/Smalltalk/exception.st | 29 + Examples/Smalltalk/extern.st | 16 + Examples/Smalltalk/hello.st | 19 + Examples/Smalltalk/listDir.st | 26 + Examples/Smalltalk/math.st | 5 + Examples/Smalltalk/notification.st | 24 + Examples/Smalltalk/pldes.st | 58 + Examples/Smalltalk/plparse.st | 79 + Examples/Smalltalk/range.st | 27 + Examples/Smalltalk/scope.st | 63 + Examples/Smalltalk/selector.st | 27 + GNUmakefile | 43 + GNUmakefile.postamble | 66 + Languages/GNUmakefile | 38 + Languages/Guile/GNUmakefile | 46 + Languages/Guile/GuileEngine.h | 32 + Languages/Guile/GuileEngine.m | 90 ++ Languages/Guile/GuileInfo.plist | 3 + Languages/Guile/Tests/hello.scm | 2 + Languages/Guile/Tests/transcript.scm | 1 + Languages/Smalltalk/ChangeLog | 49 + Languages/Smalltalk/Externs.h | 15 + Languages/Smalltalk/Externs.m | 15 + Languages/Smalltalk/GNUmakefile | 67 + Languages/Smalltalk/NSArray+additions.h | 35 + Languages/Smalltalk/NSArray+additions.m | 127 ++ Languages/Smalltalk/NSNumber+additions.h | 40 + Languages/Smalltalk/NSNumber+additions.m | 83 + Languages/Smalltalk/NSObject+additions.h | 30 + Languages/Smalltalk/NSObject+additions.m | 24 + Languages/Smalltalk/STBlock.h | 61 + Languages/Smalltalk/STBlock.m | 228 +++ Languages/Smalltalk/STBlockContext.h | 44 + Languages/Smalltalk/STBlockContext.m | 117 ++ Languages/Smalltalk/STBytecodeInterpreter.h | 69 + Languages/Smalltalk/STBytecodeInterpreter.m | 656 ++++++++ Languages/Smalltalk/STBytecodes.h | 91 ++ Languages/Smalltalk/STBytecodes.m | 270 ++++ Languages/Smalltalk/STCompiledCode.h | 50 + Languages/Smalltalk/STCompiledCode.m | 83 + Languages/Smalltalk/STCompiledMethod.h | 46 + Languages/Smalltalk/STCompiledMethod.m | 120 ++ Languages/Smalltalk/STCompiledScript.h | 45 + Languages/Smalltalk/STCompiledScript.m | 153 ++ Languages/Smalltalk/STCompiler.h | 130 ++ Languages/Smalltalk/STCompiler.m | 944 +++++++++++ Languages/Smalltalk/STCompilerUtils.h | 184 +++ Languages/Smalltalk/STCompilerUtils.m | 366 +++++ Languages/Smalltalk/STExecutionContext.h | 64 + Languages/Smalltalk/STExecutionContext.m | 124 ++ Languages/Smalltalk/STGrammar.m | 1437 +++++++++++++++++ Languages/Smalltalk/STGrammar.m.h | 23 + Languages/Smalltalk/STGrammar.y | 453 ++++++ Languages/Smalltalk/STLiterals.h | 49 + Languages/Smalltalk/STLiterals.m | 86 + Languages/Smalltalk/STMessage.h | 43 + Languages/Smalltalk/STMessage.m | 71 + Languages/Smalltalk/STMethodContext.h | 61 + Languages/Smalltalk/STMethodContext.m | 200 +++ Languages/Smalltalk/STScriptObject.h | 46 + Languages/Smalltalk/STScriptObject.m | 170 ++ Languages/Smalltalk/STSelector+additions.h | 30 + Languages/Smalltalk/STSelector+additions.m | 34 + Languages/Smalltalk/STSourceReader.h | 48 + Languages/Smalltalk/STSourceReader.m | 488 ++++++ Languages/Smalltalk/STStack.h | 45 + Languages/Smalltalk/STStack.m | 128 ++ Languages/Smalltalk/STTokenTypes.h | 56 + .../Smalltalk/STUndefinedObject+additions.h | 36 + .../Smalltalk/STUndefinedObject+additions.m | 54 + Languages/Smalltalk/SmalltalkEngine.h | 32 + Languages/Smalltalk/SmalltalkEngine.m | 80 + Languages/Smalltalk/SmalltalkInfo.plist | 3 + Modules/AppKit/AppKitConstants.list | 460 ++++++ Modules/AppKit/AppKitConstants.m | 430 +++++ Modules/AppKit/AppKitEvents.list | 135 ++ Modules/AppKit/AppKitEvents.m | 197 +++ Modules/AppKit/AppKitExceptions.list | 38 + Modules/AppKit/AppKitExceptions.m | 106 ++ Modules/AppKit/AppKitInfo.plist | 143 ++ Modules/AppKit/AppKitNotifications.list | 82 + Modules/AppKit/AppKitNotifications.m | 119 ++ Modules/AppKit/Functions.h | 41 + Modules/AppKit/Functions.m | 56 + Modules/AppKit/GNUmakefile | 62 + Modules/AppKit/NSApplication+additions.h | 46 + Modules/AppKit/NSApplication+additions.m | 62 + Modules/AppKit/STAppKitModule.h | 34 + Modules/AppKit/STAppKitModule.m | 57 + Modules/AppKit/create_constants.awk | 5 + Modules/AppKit/footer.m | 5 + Modules/AppKit/header.m | 65 + Modules/Foundation/FoundationConstants.list | 170 ++ Modules/Foundation/FoundationConstants.m | 178 ++ Modules/Foundation/FoundationInfo.plist | 93 ++ Modules/Foundation/Functions.h | 41 + Modules/Foundation/Functions.m | 56 + Modules/Foundation/GNUmakefile | 55 + Modules/Foundation/STFoundationModule.h | 34 + Modules/Foundation/STFoundationModule.m | 45 + Modules/Foundation/create_constants.awk | 5 + Modules/Foundation/footer.m | 5 + Modules/Foundation/header.m | 75 + Modules/GNUmakefile | 45 + Modules/SimpleTranscript/GNUmakefile | 46 + Modules/SimpleTranscript/SimpleTranscript.h | 34 + Modules/SimpleTranscript/SimpleTranscript.m | 84 + .../SimpleTranscriptInfo.plist | 4 + .../SimpleTranscript/SimpleTranscriptModule.h | 32 + .../SimpleTranscript/SimpleTranscriptModule.m | 41 + NEWS | 61 + README | 90 ++ .../Environments/Foundation-operators.stenv | 123 ++ Source/Environments/Foundation.stenv | 44 + Source/Environments/Safe.stenv | 67 + Source/Environments/Standard.stenv | 11 + Source/Environments/StepTalk.stenv | 41 + Source/Environments/SymbolicSelectors.stenv | 42 + Source/GNUmakefile | 96 ++ Source/GNUmakefile.postamble | 74 + .../Headers/StepTalk/NSInvocation+additions.h | 40 + Source/Headers/StepTalk/NSNumber+additions.h | 52 + Source/Headers/StepTalk/STBehaviourInfo.h | 66 + Source/Headers/StepTalk/STClassInfo.h | 51 + Source/Headers/StepTalk/STEngine.h | 59 + Source/Headers/StepTalk/STEnvironment.h | 105 ++ .../StepTalk/STEnvironmentDescription.h | 65 + Source/Headers/StepTalk/STExterns.h | 57 + Source/Headers/StepTalk/STFunctions.h | 38 + Source/Headers/StepTalk/STLanguage.h | 46 + Source/Headers/StepTalk/STModule.h | 45 + Source/Headers/StepTalk/STObjCRuntime.h | 42 + Source/Headers/StepTalk/STObjectReference.h | 54 + Source/Headers/StepTalk/STScripting.h | 45 + Source/Headers/StepTalk/STSelector.h | 38 + Source/Headers/StepTalk/STStructure.h | 90 ++ Source/Headers/StepTalk/STUndefinedObject.h | 31 + Source/Headers/StepTalk/StepTalk.h | 38 + Source/NSInvocation+additions.m | 279 ++++ Source/NSNumber+additions.m | 120 ++ Source/STBehaviourInfo.m | 137 ++ Source/STClassInfo.m | 140 ++ Source/STEngine.m | 116 ++ Source/STEnvironment.m | 535 ++++++ Source/STEnvironmentDescription.m | 454 ++++++ Source/STExterns.m | 56 + Source/STFunctions.m | 128 ++ Source/STLanguage.m | 197 +++ Source/STModule.m | 101 ++ Source/STObjCRuntime.m | 159 ++ Source/STObjectReference.m | 106 ++ Source/STScripting.m | 66 + Source/STSelector.m | 51 + Source/STStructure.m | 307 ++++ Source/STUndefinedObject.m | 101 ++ Testing/Smalltalk/block_test.st | 7 + Testing/Smalltalk/extern.st | 8 + Testing/Smalltalk/local.st | 10 + Testing/Smalltalk/nil.st | 1 + Testing/Smalltalk/test.st | 38 + Tools/GNUmakefile | 53 + Tools/GNUmakefile.preamble | 63 + Tools/STExecutor.h | 68 + Tools/STExecutor.m | 375 +++++ Tools/stalk.m | 175 ++ Tools/stexec.m | 141 ++ Tools/stupdate_languages.m | 119 ++ Version | 11 + 192 files changed, 19443 insertions(+) create mode 100644 .dist-ignore create mode 100644 COPYING create mode 100644 COPYING.LIB create mode 100644 ChangeLog create mode 100644 Documentation/ApplicationScripting.txt create mode 100644 Documentation/Defaults.txt create mode 100644 Documentation/Environment.txt create mode 100644 Documentation/HowTo.txt create mode 100644 Documentation/Languages.txt create mode 100644 Documentation/ObjCTypes.txt create mode 100644 Documentation/Old/DESIGN create mode 100644 Documentation/Smalltalk.txt create mode 100644 Examples/AppKit/listFonts.st create mode 100644 Examples/AppKit/openPanel.st create mode 100644 Examples/AppKit/panel.st create mode 100644 Examples/AppKit/pb.st create mode 100644 Examples/AppKit/printers.st create mode 100644 Examples/AppKit/rtf2text.st create mode 100644 Examples/AppKit/text.st create mode 100644 Examples/ReadMe.txt create mode 100644 Examples/Server/GNUmakefile create mode 100644 Examples/Server/Server.m create mode 100644 Examples/Server/talkToServer.st create mode 100644 Examples/Smalltalk/createFile.st create mode 100644 Examples/Smalltalk/exception.st create mode 100644 Examples/Smalltalk/extern.st create mode 100644 Examples/Smalltalk/hello.st create mode 100644 Examples/Smalltalk/listDir.st create mode 100644 Examples/Smalltalk/math.st create mode 100644 Examples/Smalltalk/notification.st create mode 100644 Examples/Smalltalk/pldes.st create mode 100644 Examples/Smalltalk/plparse.st create mode 100644 Examples/Smalltalk/range.st create mode 100644 Examples/Smalltalk/scope.st create mode 100644 Examples/Smalltalk/selector.st create mode 100644 GNUmakefile create mode 100644 GNUmakefile.postamble create mode 100644 Languages/GNUmakefile create mode 100644 Languages/Guile/GNUmakefile create mode 100644 Languages/Guile/GuileEngine.h create mode 100644 Languages/Guile/GuileEngine.m create mode 100644 Languages/Guile/GuileInfo.plist create mode 100644 Languages/Guile/Tests/hello.scm create mode 100644 Languages/Guile/Tests/transcript.scm create mode 100644 Languages/Smalltalk/ChangeLog create mode 100644 Languages/Smalltalk/Externs.h create mode 100644 Languages/Smalltalk/Externs.m create mode 100644 Languages/Smalltalk/GNUmakefile create mode 100644 Languages/Smalltalk/NSArray+additions.h create mode 100644 Languages/Smalltalk/NSArray+additions.m create mode 100644 Languages/Smalltalk/NSNumber+additions.h create mode 100644 Languages/Smalltalk/NSNumber+additions.m create mode 100644 Languages/Smalltalk/NSObject+additions.h create mode 100644 Languages/Smalltalk/NSObject+additions.m create mode 100644 Languages/Smalltalk/STBlock.h create mode 100644 Languages/Smalltalk/STBlock.m create mode 100644 Languages/Smalltalk/STBlockContext.h create mode 100644 Languages/Smalltalk/STBlockContext.m create mode 100644 Languages/Smalltalk/STBytecodeInterpreter.h create mode 100644 Languages/Smalltalk/STBytecodeInterpreter.m create mode 100644 Languages/Smalltalk/STBytecodes.h create mode 100644 Languages/Smalltalk/STBytecodes.m create mode 100644 Languages/Smalltalk/STCompiledCode.h create mode 100644 Languages/Smalltalk/STCompiledCode.m create mode 100644 Languages/Smalltalk/STCompiledMethod.h create mode 100644 Languages/Smalltalk/STCompiledMethod.m create mode 100644 Languages/Smalltalk/STCompiledScript.h create mode 100644 Languages/Smalltalk/STCompiledScript.m create mode 100644 Languages/Smalltalk/STCompiler.h create mode 100644 Languages/Smalltalk/STCompiler.m create mode 100644 Languages/Smalltalk/STCompilerUtils.h create mode 100644 Languages/Smalltalk/STCompilerUtils.m create mode 100644 Languages/Smalltalk/STExecutionContext.h create mode 100644 Languages/Smalltalk/STExecutionContext.m create mode 100644 Languages/Smalltalk/STGrammar.m create mode 100644 Languages/Smalltalk/STGrammar.m.h create mode 100644 Languages/Smalltalk/STGrammar.y create mode 100644 Languages/Smalltalk/STLiterals.h create mode 100644 Languages/Smalltalk/STLiterals.m create mode 100644 Languages/Smalltalk/STMessage.h create mode 100644 Languages/Smalltalk/STMessage.m create mode 100644 Languages/Smalltalk/STMethodContext.h create mode 100644 Languages/Smalltalk/STMethodContext.m create mode 100644 Languages/Smalltalk/STScriptObject.h create mode 100644 Languages/Smalltalk/STScriptObject.m create mode 100644 Languages/Smalltalk/STSelector+additions.h create mode 100644 Languages/Smalltalk/STSelector+additions.m create mode 100644 Languages/Smalltalk/STSourceReader.h create mode 100644 Languages/Smalltalk/STSourceReader.m create mode 100644 Languages/Smalltalk/STStack.h create mode 100644 Languages/Smalltalk/STStack.m create mode 100644 Languages/Smalltalk/STTokenTypes.h create mode 100644 Languages/Smalltalk/STUndefinedObject+additions.h create mode 100644 Languages/Smalltalk/STUndefinedObject+additions.m create mode 100644 Languages/Smalltalk/SmalltalkEngine.h create mode 100644 Languages/Smalltalk/SmalltalkEngine.m create mode 100644 Languages/Smalltalk/SmalltalkInfo.plist create mode 100644 Modules/AppKit/AppKitConstants.list create mode 100644 Modules/AppKit/AppKitConstants.m create mode 100644 Modules/AppKit/AppKitEvents.list create mode 100644 Modules/AppKit/AppKitEvents.m create mode 100644 Modules/AppKit/AppKitExceptions.list create mode 100644 Modules/AppKit/AppKitExceptions.m create mode 100644 Modules/AppKit/AppKitInfo.plist create mode 100644 Modules/AppKit/AppKitNotifications.list create mode 100644 Modules/AppKit/AppKitNotifications.m create mode 100644 Modules/AppKit/Functions.h create mode 100644 Modules/AppKit/Functions.m create mode 100644 Modules/AppKit/GNUmakefile create mode 100644 Modules/AppKit/NSApplication+additions.h create mode 100644 Modules/AppKit/NSApplication+additions.m create mode 100644 Modules/AppKit/STAppKitModule.h create mode 100644 Modules/AppKit/STAppKitModule.m create mode 100644 Modules/AppKit/create_constants.awk create mode 100644 Modules/AppKit/footer.m create mode 100644 Modules/AppKit/header.m create mode 100644 Modules/Foundation/FoundationConstants.list create mode 100644 Modules/Foundation/FoundationConstants.m create mode 100644 Modules/Foundation/FoundationInfo.plist create mode 100644 Modules/Foundation/Functions.h create mode 100644 Modules/Foundation/Functions.m create mode 100644 Modules/Foundation/GNUmakefile create mode 100644 Modules/Foundation/STFoundationModule.h create mode 100644 Modules/Foundation/STFoundationModule.m create mode 100644 Modules/Foundation/create_constants.awk create mode 100644 Modules/Foundation/footer.m create mode 100644 Modules/Foundation/header.m create mode 100644 Modules/GNUmakefile create mode 100644 Modules/SimpleTranscript/GNUmakefile create mode 100644 Modules/SimpleTranscript/SimpleTranscript.h create mode 100644 Modules/SimpleTranscript/SimpleTranscript.m create mode 100644 Modules/SimpleTranscript/SimpleTranscriptInfo.plist create mode 100644 Modules/SimpleTranscript/SimpleTranscriptModule.h create mode 100644 Modules/SimpleTranscript/SimpleTranscriptModule.m create mode 100644 NEWS create mode 100644 README create mode 100644 Source/Environments/Foundation-operators.stenv create mode 100644 Source/Environments/Foundation.stenv create mode 100644 Source/Environments/Safe.stenv create mode 100644 Source/Environments/Standard.stenv create mode 100644 Source/Environments/StepTalk.stenv create mode 100644 Source/Environments/SymbolicSelectors.stenv create mode 100644 Source/GNUmakefile create mode 100644 Source/GNUmakefile.postamble create mode 100644 Source/Headers/StepTalk/NSInvocation+additions.h create mode 100644 Source/Headers/StepTalk/NSNumber+additions.h create mode 100644 Source/Headers/StepTalk/STBehaviourInfo.h create mode 100644 Source/Headers/StepTalk/STClassInfo.h create mode 100644 Source/Headers/StepTalk/STEngine.h create mode 100644 Source/Headers/StepTalk/STEnvironment.h create mode 100644 Source/Headers/StepTalk/STEnvironmentDescription.h create mode 100644 Source/Headers/StepTalk/STExterns.h create mode 100644 Source/Headers/StepTalk/STFunctions.h create mode 100644 Source/Headers/StepTalk/STLanguage.h create mode 100644 Source/Headers/StepTalk/STModule.h create mode 100644 Source/Headers/StepTalk/STObjCRuntime.h create mode 100644 Source/Headers/StepTalk/STObjectReference.h create mode 100644 Source/Headers/StepTalk/STScripting.h create mode 100644 Source/Headers/StepTalk/STSelector.h create mode 100644 Source/Headers/StepTalk/STStructure.h create mode 100644 Source/Headers/StepTalk/STUndefinedObject.h create mode 100644 Source/Headers/StepTalk/StepTalk.h create mode 100644 Source/NSInvocation+additions.m create mode 100644 Source/NSNumber+additions.m create mode 100644 Source/STBehaviourInfo.m create mode 100644 Source/STClassInfo.m create mode 100644 Source/STEngine.m create mode 100644 Source/STEnvironment.m create mode 100644 Source/STEnvironmentDescription.m create mode 100644 Source/STExterns.m create mode 100644 Source/STFunctions.m create mode 100644 Source/STLanguage.m create mode 100644 Source/STModule.m create mode 100644 Source/STObjCRuntime.m create mode 100644 Source/STObjectReference.m create mode 100644 Source/STScripting.m create mode 100644 Source/STSelector.m create mode 100644 Source/STStructure.m create mode 100644 Source/STUndefinedObject.m create mode 100644 Testing/Smalltalk/block_test.st create mode 100644 Testing/Smalltalk/extern.st create mode 100644 Testing/Smalltalk/local.st create mode 100644 Testing/Smalltalk/nil.st create mode 100644 Testing/Smalltalk/test.st create mode 100644 Tools/GNUmakefile create mode 100644 Tools/GNUmakefile.preamble create mode 100644 Tools/STExecutor.h create mode 100644 Tools/STExecutor.m create mode 100644 Tools/stalk.m create mode 100644 Tools/stexec.m create mode 100644 Tools/stupdate_languages.m create mode 100644 Version diff --git a/.dist-ignore b/.dist-ignore new file mode 100644 index 0000000..0d32cbf --- /dev/null +++ b/.dist-ignore @@ -0,0 +1,3 @@ +New +Ignore +.snap-ignore diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..5b6e7c6 --- /dev/null +++ b/COPYING @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/COPYING.LIB b/COPYING.LIB new file mode 100644 index 0000000..223ede7 --- /dev/null +++ b/COPYING.LIB @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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 + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..a2553bc --- /dev/null +++ b/ChangeLog @@ -0,0 +1,138 @@ +2002 Apr 20 + + * COPYING: updated + * STExterns: Removed unused exceptions + * STStructure: Changed exception to STInternalIncosistencyException + +2002 Apr 13 + + * Modules/GNUmakefile: added option that disables making of appkit support + Use make appkit=no. + * Separated AppTalk + +2002 Mar 21 + + * STEnvironment: removed pools + +2002 Mar 17 + + * STEngine: removed executeScript: methods and use only executeSource: + engine does not make difference between script and statements anymore + * Tools: removed --expressions option + * Examples: fixed Smalltalk examples to use new grammar + * STLanguage: new method languageNameForFileType: + +2002 Mar 13 + + * AppKit module: removed old AppKit constants and renamed MiddleButton + events to OtherButton. + +2002 Feb 14 + + * added make option 'appkit'. if you set it to 'no' (make appkit=no), + no appkit stuff will be compiled. + +2002 Feb 5 + + * StepTalk 0.5.0 released + +2002 Feb 5 + + * STSelector: new file + * NSInvocation+additions: handle SEL type with STSelector + * Examples: added selector.st, notification.st, scope.st and pldes.st + +2002 Feb 3 + + * Testing: new directory + +2002 Jan 30 + + * STEnvironment: Removed unused variables, + +2002 Jan 23 + + * NSNumber+additions: moved from Smalltalk, added methods for creation of + range, point and size + +2002 Jan 21 + + * StepTalk 0.4.1 released + +2002 Jan 21 + + * Removed Foundation constants to separate module + * stexec: load Foundation module instead of loading all ObjC classes + +2002 Jan 13 + + * Guile: new language bundle + +2002 Jan 9 + + * StepTalk 0.4.0 released + +2002 Jan 9 + + * STFunctions: new function STUserConfigPath + * STLanguage: new method languageForFileType: + * new tool stupdate_languages to create/update languages configuration file + +2001 Dec 8 + + * NSInvocation+addition: return receiver (target) when return type is void + +2001 Nov 19 + + * STModule: New method -classNames; returns array of names of exported + classes + +2001 Nov 14 + + * removed force of use of users home directory for installation + * new module AppKit + * STEnvironment: new method -addAllClasses to add all Objective-C classes + +2001 Nov 10 + + * StepTalk 0.3.0 released + +2001 Nov 10 + + * Added scriptable server example. + +2001 Nov 9 + + * STExecutor: new options: --list-objects, --list-classes and + --list-all-objects + * Tools/stalk.m: resurected + * Tools/GNUmakefile: uncommented stalk tool + * moved initialization of STNil from STUndefinedObject to STEngine + +2001 Nov 6 + + * STProtocolInfo: removed + * STBehaviourInfo, STClassInfo, STEnvironmentDescription: rewritten + * Environment description files changed + +2001 Nov 5 + + * Tools/stexec: fixed bug, that caused segfault (reported by + Nicola Pero ) + * Examples: new directory with Smalltalk script examples + * STEnvironment: fixed restricted/full scripting. + translateSelector:forReceiver: now raises an exception if selector is not + allowed for receiver; standardScriptingEnvironemnt renamed to + defaultScriptingEnvironment and calls + STEnvironmentDescription defaultEnvironmentDescriptionName + * STEnvrionmentDescription: New method +defaultEnvironmentDescriptionName. + +2001 Nov 3 + + * Tools: implemented --environment switch to use environment description + with name. + +2001 Nov 1 + + * New ChangeLog started. Rewritten and redesigned. + * Added support for multiple languages. Created Smalltalk language bundle. diff --git a/Documentation/ApplicationScripting.txt b/Documentation/ApplicationScripting.txt new file mode 100644 index 0000000..11da0f9 --- /dev/null +++ b/Documentation/ApplicationScripting.txt @@ -0,0 +1,17 @@ +Application Scripting +--------------------- + +To make your applications scriptable, you have to make and install AppTalk +library. + + +See documents in AppTalk/Documentation where you may find more information +about: + + Installing AppTalk + Creating a scriptable application in a few minutes + Scripts locations + +You may find AppTalk sources at the same place as StepTalk + + http://steptalk.host.sk diff --git a/Documentation/Defaults.txt b/Documentation/Defaults.txt new file mode 100644 index 0000000..2e29be9 --- /dev/null +++ b/Documentation/Defaults.txt @@ -0,0 +1,15 @@ +StepTalk Defaults +----------------- + +StepTalk uses defaults domain with name 'StepTalk'. + +For example, to set default language name: + + > defaults write StepTalk DefaultLanguageName Smalltalk + + +Name: DefaultLanguageName +Type: String + +Name: DefaultEnvironmentDescriptionName +Type: String diff --git a/Documentation/Environment.txt b/Documentation/Environment.txt new file mode 100644 index 0000000..bbf15c7 --- /dev/null +++ b/Documentation/Environment.txt @@ -0,0 +1,57 @@ +Scripting environment descriptions +---------------------------------- + +Property list containing dictionary with keys: + +Name + Name of scripting description + +Use + Array of scripting descriptions to include. + +Behaviours + Dictionary of behaviour descriptions, that can be adopted by a class or + another behaviour. + +Classes + Dictionary of class descriptions. + +DefaultRestriction + + +Aliases object name aliases (not impl.) + + +Behaviours +---------- +Use + Adopt behaviour + +SymbolicSelectors + Map of symbolic selectors. + +Aliases + Method name aliases. + +AllowMethods + List of allowed methods. + +DenyMethods + List of denied methods. + + + +Classes +------- +(Same items as in Behaviours) + +Super + Super class name. + +Restriction + Values: DenyAll, AllowAll + + "DenyAll" deny all methods except those in "AllowMethods" list or + in "Aliases" + "AllowAll" allow all methods except those in "DenyMehods" list. + diff --git a/Documentation/HowTo.txt b/Documentation/HowTo.txt new file mode 100644 index 0000000..68893f6 --- /dev/null +++ b/Documentation/HowTo.txt @@ -0,0 +1,28 @@ +StepTalk HowTo +---------------------- + +Here are some references where you may find how to use StepTalk: + +How to create scripting environment? + + Tools/stalk.m + -createEnvironment + +How to execute code? + + Tools/STExecutor.m + -executeScripts + -executeScript:withArguments: + +How to create a language bundle? + + Languages/Smalltalk/LanguageEngine.m + Languages/Smalltalk/LanguageEngine.h + + Languages/Smalltalk/STBytecodeInterpreter.m + - sendSelectorAtIndex:withArgCount: + + +How to create a scriptable server? + + see Examples/Server diff --git a/Documentation/Languages.txt b/Documentation/Languages.txt new file mode 100644 index 0000000..8a059df --- /dev/null +++ b/Documentation/Languages.txt @@ -0,0 +1,21 @@ +Languages +--------- + +How to create a language bundle? + +In directory Languages/Smalltalk/ see files + + SmalltalkEngine.[hm] + SmalltalkInfo.plist + +and in STBytecodeInterpreter.m see method - sendSelectorAtIndex:withArgCount: + + +LanguageInfo.plist +------------------ +STLanguageName + Language name that will be used instead of bundle name. + +STEngine; + Engine class name. If there is no such class, then princicpial class + will be used. diff --git a/Documentation/ObjCTypes.txt b/Documentation/ObjCTypes.txt new file mode 100644 index 0000000..8ca0ad5 --- /dev/null +++ b/Documentation/ObjCTypes.txt @@ -0,0 +1,7 @@ +Conversion between objects and Objective-C types +------------------------------------------------ + +Number types - NSNumber +char * - NSString +id, class - no conversion +structures - STStructure diff --git a/Documentation/Old/DESIGN b/Documentation/Old/DESIGN new file mode 100644 index 0000000..85a61d0 --- /dev/null +++ b/Documentation/Old/DESIGN @@ -0,0 +1,183 @@ +There was an idea to create general - language independent scripting +framework for GNUstep. Here is a sketch of such framework. + +Idea is to have applications, that can execute scripts or just one-line +statements in any available scripting language. + +Scripting Environment +--------------------- + +An application will prepare scripting environment by making some of apps +objects available by some name. + +ex.: + STEnvironment *env; + + [env addObject:mail withName:@"mail"]; + [env addObject:[mail subject] withName:@"subject"]; + [env addObject:[mail receiver] withName:@"receiver"]; + + + +Environment is something like language context, where script is being +executed. There are objects registered by name, so you can use them from your +script. Your application can have several environments. For example, one for +each document, mail... + +ex. (Example is going to be a mail filter. Let mail filter by a association +between mailbox and a expression. Whe expression is true, mail goes to that +mailbox.): + + receiver == 'gnustep-dicuss@gnu.org' + +or something like this: + + addressBook emailAddressesForGroupWithName:'firends' + contains:receiver + +Also, scripting environment contains method name alias/restriction. For +example, I've used method aliases to map Smalltalk bynary selectors to +gnustep methods, like when sending selector '@' to NSArray, it is translated +to 'objectAtIndex:'. With method restriction, you can deny some methods to a +class. This can be used to prevent creating script viruses. Your application +just denies methods of some classes not available for scripting. For example, +you can deny method for deleting files, allocating some kinds of objects... +This can be enabled or disabled, when it is disabled, I call it full +scripting - you can send any message to any kind of object. Application can +have environment description(s) in a file (example attached) or it can +allow/deny by 'hand' using STEnvironments: + + - denySelector:forObjectsOfType: + - allowSelector:forObjectsOfType: + - denyAllSelectorsForObjectOfType: + - allowAllSelectorsForObjectOfType: + +Scripting Engine +---------------- + +Scripting engine is used for executing scripts. + +ex.: + + STEgnine *engine /* say we already have this */; + ... + + engine = [STEngine engineForLanguage:@"Smalltalk"]; + + [engine executeCode:filter + inEnvironment:[activeMail scriptingEnvironment]]; + ... + + +Engine and Languages +-------------------- +The idea was, as also Lyndon mentioned before, to have "bundled languages". +Engine will load appropriate bundle for language, that is actualy needed. + +Application does not have to know anything about scripting languages. It is +the matter of user. But, user has to be able to specify the language used for +scripting in application. Or...there sould be a language autodetection. + +The interface between Engine and backend (bundled language) + +- executeCode:inEnvironment: + +- understandsCode: /* can be used for language auto-detection when language is +nil or @"" or @"auto"... */ + +Scripting framework does not care, if the language is compiled, or directly +interpreted. + +Language backend will just execute a script and send messages to objects. It +can use environment to get the real selector: + + STEnvironment *environment; /* we have this ... */ + id target; /* ... and also this */ + NSString *selector; + ... + selector = [environment translateSelector:selector forReceiver:target]; + + + invocation = [NSInvocation invocationWithTarget:target + selectorName:selector]; + + ... /* set arguments */ ... + [invocation invoke]; + +For larger example see source STBytecodeInterpreter.m in Smalltalk language +module, method: + - (void)sendSelectorAtIndex:(unsigned)selIndex + withArgCount:(unsigned)argCount + + +In StepTalk there already some additions, that can be used: + +NSInvocation +- (void)setArgumentAsObject:(id)anObject atIndex:(int)anIndex +- (id)getArgumentAsObjectAtIndex:(int)anIndex +- (id)returnValueAsObject + +These two methods are converting between GNUstep objects (NSNumber, +NSString,...) and simple C types (int, char *, ...) + + +Languages and Language Bundles +------------------------------ + +Language bundles can be stored in + +*_GNUSTEP_ROOT/Library/Scripting/Languages + +It will be good, if there will be some kind of description of that language, +language aliases (objc, objective-c, objectivec,...) + +Defaults +-------- +Suggested defaults: + +STFullScripting (bool) - enable full scripting by default for all apps +STDefaultsScriptingLanguage - default scripting language + + +Remote scripting +----------------- +The idea is to script application/server remotely. You connect to scripted +object, where an new scripting environment is created. Script is executed in +that environment. Application may customize the environment depending on the +caller or may limit number of scripting connections, etc... + +The method should be +- remoteScriptingEngine +or there should be some authentification of caller. + +Summary +------- +Application developers: + + STEnvironment interface + - addObject:anObject withName:(NSString *)name + + - denySelector:forObjectsOfType: + - allowSelector:forObjectsOfType: + - denyAllSelectorsForObjectOfType: + - allowAllSelectorsForObjectOfType: + + OR + + environment description file(s) + + STEngine interface + + + engineForLanguageWithName:(NSString *)name + + - executeCode:(NSString *)code + inEnvironment:(STScriptingEnvironment *) env + +Language backend developers: + + STEnvironment interface + - translateSelector:forReceiver: + + They have to implement theese methods: + - executeCode:inEnvironment: + - understandsCode: diff --git a/Documentation/Smalltalk.txt b/Documentation/Smalltalk.txt new file mode 100644 index 0000000..a5d27bb --- /dev/null +++ b/Documentation/Smalltalk.txt @@ -0,0 +1,174 @@ +Smalltalk language extensions to NSObjects +------------------------------------------ + +Contents: + 1. Source + 2. Symbolic Selectors + 3. Iterators and cycles + 4. Exception handling + +1. Source +--------- + +Smalltalk script can be list of methods or just list of statements. List of +statements is like single method without method name. + +List of methods +--------------- + +Source begins with '[|' (left square bracket) and is followed by optional list +of script variables. Methods are separated by '!' and are encoles by ']' (right +square bracket). + +Example without vars: +[| + main + self other. + ^self + ! + other + Transcript showLine:'This is other'. + ! + ] + +Example with vars: + +[| :var1 :var2 + + main + "Your code here...". + ^self + ! + other + "Your code here...". + ^self + ! + ] + + +Simple script (statements) +-------------------------- + +Simple script is just list of smalltalk statements. It is like contents of one +method. + + +Why source begins with '[|' and not just '['? +--------------------------------------------- +Look at this example: + + [one two three] + +It has more meanings. It can be: + + - list of methods with one method named 'one'. 'two' is target object and + 'three' is a message. + + or + + - simple statement with block. 'one' is target object and 'two' and 'three' + are messages. + + + +2. Symbolic selectors +--------------------- + +In StepTalk symbolic selectors are mapped to normal selectors. + +Comparison operators (NSObject) +------------------------------- + + + Symb. sel. Real sel. + ------------------------------------- + = isEqual: + == isSame: + ~= notEqual: + ~~ notSame: + < isLessThan: + > isGreatherThan: + <= isLessOrEqualThan: + >= isGreatherOrEqualThan: + + +Target type Selector Argument Type Real Selector +----------------------------------------------------------------------- +NSArray @ NSNumber objectAtIndex: +NSArray , any arrayByAddingObject: +NSArray + any arrayByAddingObject: +NSMutableArray += any addObject: +NSMutableArray -= any removeObject: + +NSDictionary @ any objectForKey: +NSUserDefaults @ any objectForKey: + +NSString , NSString stringByAppendingString: +NSString / NSString stringByAppendingPathComponent: +NSString @ NSNumber characterAtIndex: +NSMutableString += NSString appendString: + +NSSet < NSSet isSubsetOfSet: +NSMutableSet += any addObject: +NSMutableSet -= any removeObject: + +NSDate - NSDate timeIntervalSinceDate: + +NSNumber +,-,*,/ NSNumber add:,subtract:,multiply:,divide: + + + +Special selectors to create objects from two NSNumbers + +Symb.sel. Real sel. Result Methods +------------------------------------------------------- +<> rangeWith: range location, length +@ pointWith: point x, y +@@ sizeWith: size width, height + +Examples: + str := 'This is string.'. + substr := str substringWithRange: (8 <> 3) + range := str rangeOfString: 'str'. + newRange := ( (range location) <> 6). + +3. Iterator and cycles +---------------------- +Cycles +------ +To create a cycle, you may use whileTrue: or whileFalse: on NSBlock + + conditionBlock whileTrue: toDoBlock. + +To use a sequence of numbers, you may use to:do: or to:step:do: on NSNumber + + min to: max do: block + min to: max step: step do: block + +Array iterators +--------------- + +Following methods will iterate through all objects in receiver. + +Selector Description +------------------------------------------------------------------------------- +do: Evaluate block for each object in array and return last evaluated + expression +select: Create new array which will contain those objects from receiver, + for which value of block was true +reject: Create new array which will contain those objects from receiver, + for which value of block was false +collect: Create new array from block return values. +detect: Return first object for which block evaluation result is true. + Othervise return nil. + + +4. Exception handling +--------------------- + +If you want to handle an exception, you may do so by using blocks. You send +handler: message to guarded block. + + guardedBlock handler: handlerBlock. + +If exception occures in guarded block, then handler block is evaluated. diff --git a/Examples/AppKit/listFonts.st b/Examples/AppKit/listFonts.st new file mode 100644 index 0000000..c062f5e --- /dev/null +++ b/Examples/AppKit/listFonts.st @@ -0,0 +1,45 @@ +" listFonts.st + + Example that will create a 'rtf file containing smaples of all available + fonts. + +" + +[| :text + +main + + | fontManager | + + Environment loadModule:'AppKit'. + + text := NSTextView alloc initWithFrame:NSNullRect. + text setRichText:YES. + + fontManager := NSFontManager sharedFontManager. + + (fontManager availableFontFamilies) + do: [ :font | + self addFontSample:font + ]. + + text writeRTFDToFile:'Fonts.rtf' atomically:YES. + + ^nil +! + +addFontSample:fontName + + | attr | + + attr := NSMutableDictionary dictionary. + attr setObject:(NSFont fontWithName:fontName size:0) + forKey:NSFontAttributeName. + + text setTypingAttributes:attr. + text insertText:(fontName,'\n'). + + ^self + + +] diff --git a/Examples/AppKit/openPanel.st b/Examples/AppKit/openPanel.st new file mode 100644 index 0000000..15b39c6 --- /dev/null +++ b/Examples/AppKit/openPanel.st @@ -0,0 +1,7 @@ +Environment loadModule:'AppKit'. + +panel := NSOpenPanel openPanel. + +runResult := panel runModal. + +Transcript showLine: (panel filename). diff --git a/Examples/AppKit/panel.st b/Examples/AppKit/panel.st new file mode 100644 index 0000000..6c38c23 --- /dev/null +++ b/Examples/AppKit/panel.st @@ -0,0 +1,12 @@ +| app | + +Environment loadModule:'AppKit'. + +app := NSApplication sharedApplication. + +app runAlertPanelWithTitle: 'Test' + message: 'Alert panel test' + defaultButton: 'OK' + alternateButton: nil + otherButton: nil. + diff --git a/Examples/AppKit/pb.st b/Examples/AppKit/pb.st new file mode 100644 index 0000000..b838cda --- /dev/null +++ b/Examples/AppKit/pb.st @@ -0,0 +1,8 @@ +" Print available Pasteboard types " +| pb | + +Environment loadModule:'AppKit'. + +pb := NSPasteboard generalPasteboard. + +Transcript showLine: (pb types). diff --git a/Examples/AppKit/printers.st b/Examples/AppKit/printers.st new file mode 100644 index 0000000..20f974b --- /dev/null +++ b/Examples/AppKit/printers.st @@ -0,0 +1,11 @@ +"List all available printers" + +| printers | + +Environment loadModule:'AppKit'. + +printers := NSPrinter printerTypes. +printers do: +[ :printer | + Transcript showLine: printer. +] diff --git a/Examples/AppKit/rtf2text.st b/Examples/AppKit/rtf2text.st new file mode 100644 index 0000000..4a06257 --- /dev/null +++ b/Examples/AppKit/rtf2text.st @@ -0,0 +1,29 @@ +" + rtf2text.st + + Convert RTF document to plain text. + + ussage: stexec rtf2text infile outfile + +" + +| infile outfile rtfString | + +Environment loadModule:'AppKit'. + +((Args count) < 2) +ifTrue: +[ + Transcript showLine:'rtf2text: Please specify input and output filename'. +] +ifFalse: +[ + infile := Args @ 0. + outfile := Args @ 1. + + rtfString := (NSAttributedString alloc) + initWithPath:infile documentAttributes:nil. + + (rtfString string) writeToFile:outfile atomically:YES. + +] diff --git a/Examples/AppKit/text.st b/Examples/AppKit/text.st new file mode 100644 index 0000000..ddbf1df --- /dev/null +++ b/Examples/AppKit/text.st @@ -0,0 +1,22 @@ +"NSText test" + +Environment loadModule:'AppKit'. + +tattr := NSMutableDictionary dictionary. +tattr setObject:(NSFont fontWithName:'Times' size:10) + forKey:NSFontAttributeName. + +hattr := NSMutableDictionary dictionary. +hattr setObject:(NSFont fontWithName:'Helvetica' size:10) + forKey:NSFontAttributeName. + +text := NSTextView alloc initWithFrame:NSNullRect. +text setRichText:YES. + +text setTypingAttributes:tattr. +text insertText:'This is Times\n'. + +text setTypingAttributes:hattr. +text insertText:'This is Helvetica\n'. + +text writeRTFDToFile:'Test.rtf' atomically:YES. diff --git a/Examples/ReadMe.txt b/Examples/ReadMe.txt new file mode 100644 index 0000000..a7d40f0 --- /dev/null +++ b/Examples/ReadMe.txt @@ -0,0 +1,69 @@ +Smalltalk examples +------------------ + + Smalltalk examples are included in Smalltalk directory. + + + math.st + Simple example. + + > stexec math.st + + + hello.st + Example to show block closures, symbolic selectors and ussage of arguments. + + > stexec hello.st + > stexec hello.st World + + + createFile.st + + Try to create a file. Example to show how the restricted scriptiong works. + + This will work fine: + > stexec createFile.st + + This would not: + > stexec --environment Safe createFile.st + + + exception.st + + Same as createFile.st but handles the exception. + + This will work fine: + > stexec exception.st + + This will end with handled exception: + > stexec --environment Safe exception.st + + listDir.st + + List content of current directory. + + > stexec listDir.st + + plparse.st, pldes.st + + GNUstep tools written in smalltalk + + > stexec plparse.st file1 file2 ... + + + +Scriptable server example +------------------------- + + To compile type + + > make + + Then run server + + > opentool Server + + Then from same directory, but in another terminal try + + > stalk Server talkToServer.st + > stalk Server talkToServer.st "Hi there!" diff --git a/Examples/Server/GNUmakefile b/Examples/Server/GNUmakefile new file mode 100644 index 0000000..50a5478 --- /dev/null +++ b/Examples/Server/GNUmakefile @@ -0,0 +1,35 @@ +# +# StepTalk examples +# +# 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., 675 Mass Ave, Cambridge, MA 02111, USA. +# + +GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles + +include $(GNUSTEP_MAKEFILES)/common.make + +TOOL_NAME = Server + +Server_OBJC_FILES = Server.m + +ADDITIONAL_TOOL_LIBS = -lStepTalk + +-include GNUmakefile.preamble +include $(GNUSTEP_MAKEFILES)/tool.make +-include Makefile.postamble diff --git a/Examples/Server/Server.m b/Examples/Server/Server.m new file mode 100644 index 0000000..4717536 --- /dev/null +++ b/Examples/Server/Server.m @@ -0,0 +1,65 @@ +/* + Server.m + + StepTalk scriptable server example + */ + +#import +#import +#import +#import + +#import + +#include + +@interface Server:NSObject +- say:(NSString *)string; +@end + +@implementation Server +- (STEnvironment *)scriptingEnvironment +{ + /* here we should add some objects or class references ... */ + + return [STEnvironment defaultScriptingEnvironment]; +} +- (NSDate *)date +{ + return [NSDate date]; +} +- say:(NSString *)string +{ + printf("%s\n",[string cString]); + + return self; +} +@end + +int main(int argc, const char **argv) +{ + NSAutoreleasePool *pool; + NSConnection *connection; + Server *server = [Server new]; + + pool = [NSAutoreleasePool new]; + + connection = [NSConnection newRegisteringAtName:@"Server" + withRootObject:server]; + + if (!connection) + { + NSLog(@"Unable to register server"); + [pool release]; + return 1; + } + + NSLog(@"Server started"); + + [[NSRunLoop currentRunLoop] run]; + + RELEASE(connection); + RELEASE(pool); + + return 0; +} diff --git a/Examples/Server/talkToServer.st b/Examples/Server/talkToServer.st new file mode 100644 index 0000000..25a4e9c --- /dev/null +++ b/Examples/Server/talkToServer.st @@ -0,0 +1,20 @@ +" talkToServer.stalk + + Server script example + + Ussage: + stalk Server talkToServer.st [message] +" +| message | + +((Args count) < 1 ) +ifTrue: + [ + message := 'Hello!'. ^0 + ] +ifFalse: + [ + message := Args objectAtIndex: 0. ^0 + ]. + +Server say:message diff --git a/Examples/Smalltalk/createFile.st b/Examples/Smalltalk/createFile.st new file mode 100644 index 0000000..a3fdfeb --- /dev/null +++ b/Examples/Smalltalk/createFile.st @@ -0,0 +1,17 @@ +| fileManager fileName data | + +fileManager := NSFileManager defaultManager. + +fileName := '/tmp/TestFile.text'. + +('This is some file' writeToFile:fileName atomically:NO) + ifTrue: + [ + Transcript showLine:'File was succesfully created.' + ] + ifFalse: + [ + Transcript showLine:'File was not created.' + ] + + diff --git a/Examples/Smalltalk/exception.st b/Examples/Smalltalk/exception.st new file mode 100644 index 0000000..1fc3def --- /dev/null +++ b/Examples/Smalltalk/exception.st @@ -0,0 +1,29 @@ +| fileName flag | + +fileName := '/tmp/TestFile.text'. + +flag := NO. + +[ + ('This is some file' writeToFile:fileName atomically:NO) + ifTrue: + [ Transcript showLine:'File was succesfully created.'] + ifFalse: + [ Transcript showLine:'File was not created.'] +] +handler: + [ :exception | + Transcript showLine:('Handled exception: ',(exception name)). + Transcript showLine:('Reason : ',(exception reason)). + flag := YES + ]. + +flag ifTrue: + [ + Transcript showLine:'Finished with exception' + ] + ifFalse: + [ + Transcript showLine:'Finished succesfully' + ] + diff --git a/Examples/Smalltalk/extern.st b/Examples/Smalltalk/extern.st new file mode 100644 index 0000000..8b94655 --- /dev/null +++ b/Examples/Smalltalk/extern.st @@ -0,0 +1,16 @@ +| foo | + + +"foo is local variable" + +foo := 'Foo'. + +Transcript showLine:( 'This is foo : ', foo ). + + +" bar is created in environment as extern variable " + +bar := 'Bar'. + +Transcript showLine:( 'And this is bar: ', bar ). + diff --git a/Examples/Smalltalk/hello.st b/Examples/Smalltalk/hello.st new file mode 100644 index 0000000..034d5c8 --- /dev/null +++ b/Examples/Smalltalk/hello.st @@ -0,0 +1,19 @@ +" hello.st + + Ussage: + stexec hello.st name +" + +((Args count) < 1 ) +ifTrue: + [ + Transcript showLine:'Hello ... who?' + ] +ifFalse: + [ + " See ..../Library/StepTalk/Environments/Foundation-operators.stenv + or Source/Environments/Foundation-operators.stenv + " + + Transcript showLine: ('Hello ', (Args @ 0), '!'). + ] diff --git a/Examples/Smalltalk/listDir.st b/Examples/Smalltalk/listDir.st new file mode 100644 index 0000000..69d7caa --- /dev/null +++ b/Examples/Smalltalk/listDir.st @@ -0,0 +1,26 @@ +| fileManager path files dict | + +fileManager := NSFileManager defaultManager. + +path := fileManager currentDirectoryPath. + +Transcript showLine:( 'Listing of directory: ', path ). + +files := fileManager directoryContentsAtPath:path. + +files do: + [ :file | + + dict := fileManager fileAttributesAtPath: (path / file) + traverseLink:NO. + Transcript showLine:file. + + Transcript showLine: (' Type: ', (dict @ NSFileType)). + Transcript showLine: (' Size: ', ((dict @ NSFileSize) stringValue)). + Transcript showLine: (' Date: ', ((dict @ NSFileModificationDate) + description)). + + Transcript showLine:'' + ] + + diff --git a/Examples/Smalltalk/math.st b/Examples/Smalltalk/math.st new file mode 100644 index 0000000..41a4767 --- /dev/null +++ b/Examples/Smalltalk/math.st @@ -0,0 +1,5 @@ +" Simple example " + +Transcript show:'1 + 1 = '. +Transcript showLine: (1 + 1) + diff --git a/Examples/Smalltalk/notification.st b/Examples/Smalltalk/notification.st new file mode 100644 index 0000000..45d0820 --- /dev/null +++ b/Examples/Smalltalk/notification.st @@ -0,0 +1,24 @@ +" Notification example " +[| + +main + | nc | + + nc := NSNotificationCenter defaultCenter. + + Transcript showLine:'Registering for notification'. + nc addObserver:self selector:#notification: name:'Notification' object:nil. + + Transcript showLine:'Posting notification'. + nc postNotificationName:'Notification' object:nil. + + ^self +! + +notification:notif + + Transcript showLine:'Notification received'. + + ^self + +] diff --git a/Examples/Smalltalk/pldes.st b/Examples/Smalltalk/pldes.st new file mode 100644 index 0000000..cab3e90 --- /dev/null +++ b/Examples/Smalltalk/pldes.st @@ -0,0 +1,58 @@ +" +pldes.st + + GNUstep plpdes tool rewriten as Smalltalk script for StepTalk + +Ussage: + stexec pldes.st file1 [file2 ...] + + +" +[| :locale + +main + locale := (NSUserDefaults standardUserDefaults) dictionaryRepresentation. + + ((Args count) < 1 ) + ifTrue: + [ + Transcript showLine:'No file names given to deserialize.' + ] + ifFalse: + [ + Args do: + [ :file | + [self deserializeFile:file] + handler: + [ :exception | + Transcript showLine:'Loading \'', file, '\' - ', (exception reason). + ] + ] + ]. + + ^self +! + +deserializeFile:file + | myData myString result out | + + myData := NSData dataWithContentsOfFile: file. + result := NSDeserializer deserializePropertyListFromData: myData + mutableContainers: NO. + + (result isNil) + ifTrue: [ + Transcript showLine:'Loading \'',file, '\' - nil property list'. + ] + ifFalse: [ + + myString := result descriptionWithLocale: locale indent: 0. + myData := myString dataUsingEncoding: NSASCIIStringEncoding. + + out := NSFileHandle fileHandleWithStandardOutput. + out writeData: myData; + synchronizeFile. + ]. + + ^self +] diff --git a/Examples/Smalltalk/plparse.st b/Examples/Smalltalk/plparse.st new file mode 100644 index 0000000..ef31702 --- /dev/null +++ b/Examples/Smalltalk/plparse.st @@ -0,0 +1,79 @@ +" +plparse.st + + GNUstep plparse tool rewriten as Smalltalk script for StepTalk + +Ussage: + stexec plparse.st file1 [file2 ...] + + +" +[| + +main + + | string result | + + ((Args count) < 1 ) + ifTrue: + [ + Transcript showLine:'No file names given to parse.' + ] + ifFalse: + [ + Args do: + [ + :file | self parseFile:file + ] + ]. + + ^self +! + +parseFile: file + + Transcript show: ('Parsing ', file, ' - '). + + [ + + string := NSString stringWithContentsOfFile:file. + result := string propertyList. + + (result isNil) + ifTrue: + [ + Transcript showLine:'nil property list' + ] + ifFalse: + [ + (result isKindOfClass: (NSDictionary class)) + + ifTrue: [ Transcript showLine:'a dictionary'] + ifFalse: + [ + (result isKindOfClass: (NSArray class)) + ifTrue: [ Transcript showLine:'an array'] + ifFalse: + [ + (result isKindOfClass: (NSData class)) + ifTrue: [ Transcript showLine:'a data'] + ifFalse: + [ + (result isKindOfClass: (NSString class)) + ifTrue: [ Transcript showLine:'a string'] + ifFalse: + [ + Transcript showLine: ('unexpected class - ', + result class description ) + ] + ] + ] + ] + ] + ] + handler: + [ + :localException | + Transcript showLine: (localException reason) + ]. +] diff --git a/Examples/Smalltalk/range.st b/Examples/Smalltalk/range.st new file mode 100644 index 0000000..17d9fbd --- /dev/null +++ b/Examples/Smalltalk/range.st @@ -0,0 +1,27 @@ +" Range example " +|str substr range| + +str := 'I like apples and plums.'. + +Transcript showLine: ('String is : \'', str, '\''). + +substr := str substringWithRange: (7 <> 5). + +Transcript showLine: ('Substring at location 7 with length 5 is \'', + substr, '\''). + +range := str rangeOfString: 'tomato'. + +((range location) = NSNotFound) +ifTrue: + [ Transcript showLine: 'Tomato not found' .]. + +range := str rangeOfString: 'plum'. + +Transcript showLine: ('Location of \'plum\' is ', ((range location) stringValue), + ' and length is ', ((range length) stringValue)). + +range := ( (range location) <> 5). + +Transcript showLine: ('Substring with modified range \'', + (str substringWithRange:range), '\''). diff --git a/Examples/Smalltalk/scope.st b/Examples/Smalltalk/scope.st new file mode 100644 index 0000000..a9604e2 --- /dev/null +++ b/Examples/Smalltalk/scope.st @@ -0,0 +1,63 @@ +" Variable scope example + + try to run: + + > stexec scope.st , scope.st + +" + +[| :global + +main + | local | + + Transcript showLine: ':: Start'. + + (extern isNil) ifTrue: + [ + Transcript showLine: 'Script was run for first time. Setting extern.'. + extern := 100. + ] + ifFalse: + [ + Transcript showLine: 'Extern: ', (extern stringValue). + ]. + + local := 10. + Transcript showLine: 'Local: ', (local stringValue). + + self setLocal:20. + Transcript showLine: 'Local after call: ', (local stringValue), + ' (has to be 10 not 20)'. + + global := 10. + Transcript showLine: 'Global: ', (global stringValue). + + self setGlobal:20. + Transcript showLine: 'Global after call 1: ', (global stringValue), + ' (has to be 20 not 10)'. + + self testGlobal. + Transcript showLine: 'Global after call 2: ', (global stringValue), + ' (has to be 20 not 0)'. + + ^nil +! + +setLocal:val + | local | + local := val. + ^self +! + +setGlobal:val + global := val. + ^self +! + +testGlobal + | global | + global := 0. + ^self + +] diff --git a/Examples/Smalltalk/selector.st b/Examples/Smalltalk/selector.st new file mode 100644 index 0000000..7347ae9 --- /dev/null +++ b/Examples/Smalltalk/selector.st @@ -0,0 +1,27 @@ +" Selector example " + +[| + +main + self performSelector:#hello. + + ^nil +! + +hello + | b | + Transcript showLine:'Hello!'. + ^self +! +hello2 + Transcript showLine:'Hello!'. + ^self + +! + +hello3 + |a| + Transcript showLine:'Hello!'. + ^self + +] diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..75a2014 --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,43 @@ +# +# 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 +# + +GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles + +include $(GNUSTEP_MAKEFILES)/common.make +include Version + +PACKAGE_NAME = StepTalk + +SUBPROJECTS = \ + Source \ + Languages \ + Modules \ + Tools + + +-include GNUMakefile.preamble +include $(GNUSTEP_MAKEFILES)/aggregate.make +include $(GNUSTEP_MAKEFILES)/Master/source-distribution.make +-include GNUMakefile.postamble + diff --git a/GNUmakefile.postamble b/GNUmakefile.postamble new file mode 100644 index 0000000..4815ba2 --- /dev/null +++ b/GNUmakefile.postamble @@ -0,0 +1,66 @@ +# +# 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:: + ln -sf Source/Headers . + +# Things to do after compiling +# after-all:: + +# Things to do before installing +# before-install:: + +# Things to do after installing +# after-install:: + +# Things to do before uninstalling +# before-uninstall:: + +# Things to do after uninstalling +# after-uninstall:: + +# 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/Languages/GNUmakefile b/Languages/GNUmakefile new file mode 100644 index 0000000..6dcc3d1 --- /dev/null +++ b/Languages/GNUmakefile @@ -0,0 +1,38 @@ +# +# 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 +# + +GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_USER_ROOT) + +GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles + +include $(GNUSTEP_MAKEFILES)/common.make + +SUBPROJECTS = \ + Smalltalk \ +# Guile + +-include GNUMakefile.preamble +include $(GNUSTEP_MAKEFILES)/aggregate.make +-include GNUMakefile.postamble + diff --git a/Languages/Guile/GNUmakefile b/Languages/Guile/GNUmakefile new file mode 100644 index 0000000..93fcc47 --- /dev/null +++ b/Languages/Guile/GNUmakefile @@ -0,0 +1,46 @@ +# +# Guile language bundle +# +# Copyright (C) 2000,2001 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., 675 Mass Ave, Cambridge, MA 02111, USA. +# + +GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles + +include $(GNUSTEP_MAKEFILES)/common.make + +BUNDLE_NAME = Guile +BUNDLE_EXTENSION := .stlanguage +BUNDLE_INSTALL_DIR:=$(GNUSTEP_INSTALLATION_DIR)/Library/StepTalk/Languages + +Guile_OBJC_FILES = \ + GuileEngine.m + +Guile_PRINCIPAL_CLASS = GuileEngine + +ADDITIONAL_INCLUDE_DIRS += -I../../Source/Headers +ADDITIONAL_LIBRARIES += -I../../Source/Headers +Guile_BUNDLE_LIBS += -lgstep_guile -lScriptKit $(GUILE_LIBS) + +-include GNUmakefile.preamble +include $(GNUSTEP_MAKEFILES)/bundle.make +-include GNUMakefile.postamble + +STGrammar.m: STGrammar.y + $(YACC) -d -pSTC -o$@ $< + diff --git a/Languages/Guile/GuileEngine.h b/Languages/Guile/GuileEngine.h new file mode 100644 index 0000000..79db108 --- /dev/null +++ b/Languages/Guile/GuileEngine.h @@ -0,0 +1,32 @@ +/** + GuileEngine + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2002 Jan 13 + + 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 + +@interface GuileEngine:STEngine +{ +} +@end diff --git a/Languages/Guile/GuileEngine.m b/Languages/Guile/GuileEngine.m new file mode 100644 index 0000000..83c6fef --- /dev/null +++ b/Languages/Guile/GuileEngine.m @@ -0,0 +1,90 @@ +/** + GuileEngine + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2002 Jan 13 + + 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 "GuileEngine.h" + +#import +#import + +#import + +@class NSEnumerator; + +int fake_guile_main(int argc, char **argv) +{ + NSString *sourceCode = (NSString *)argv[1]; + STEnvironment *env = (STEnvironment *)argv[2]; + GuileInterpreter *interp; + GuileScript *script; + GuileSCM *result; + NSEnumerator *e; + id *obj; + + gstep_init(); +// gstep_link_base(); + + [GuileInterpreter initializeInterpreter]; + + interp = AUTORELEASE([[GuileInterpreter alloc] init]); + script = AUTORELEASE([[GuileScript alloc] init]); + + e = [[[env defaultObjectPool] allKeys] objectEnumerator]; + + /* FIXME: If we do not remove these, we get an exception */ + [env removeObjectWithName:@"NSProxy"]; + [env removeObjectWithName:@"NSDistantObject"]; + [env addObject:env withName:@"Env"]; + [script setUserDictionary:[env defaultObjectPool]]; + [script setDelegate:sourceCode]; + result = [interp executeScript:script]; + + /* FIXME: ignore result */ + + return 0; +} + + +@implementation GuileEngine +- (BOOL)understandsCode:(NSString *)code +{ + NSLog(@"Do not know how to chceck if code is Guile."); + return NO; +} + +- (id) executeCode:(NSString *)sourceCode + inEnvironment:(STEnvironment *)env +{ + char *args[3]; + + args[0] = "dummy"; + args[1] = (char *)sourceCode; + args[2] = (char *)env; + + /* FIXME: ugly trick */ + gh_enter(3, args, fake_guile_main); +} +@end + diff --git a/Languages/Guile/GuileInfo.plist b/Languages/Guile/GuileInfo.plist new file mode 100644 index 0000000..a40c2b6 --- /dev/null +++ b/Languages/Guile/GuileInfo.plist @@ -0,0 +1,3 @@ +{ + STFileTypes = ( "scm" ); +} diff --git a/Languages/Guile/Tests/hello.scm b/Languages/Guile/Tests/hello.scm new file mode 100644 index 0000000..6157e3f --- /dev/null +++ b/Languages/Guile/Tests/hello.scm @@ -0,0 +1,2 @@ +([] Transcript show: ($$ "Hello ")) +([] Transcript showLine: ([] Args objectAtIndex: 0)) diff --git a/Languages/Guile/Tests/transcript.scm b/Languages/Guile/Tests/transcript.scm new file mode 100644 index 0000000..a532090 --- /dev/null +++ b/Languages/Guile/Tests/transcript.scm @@ -0,0 +1 @@ +([] Transcript showLine: ($$ "Hello from Transcript!")) diff --git a/Languages/Smalltalk/ChangeLog b/Languages/Smalltalk/ChangeLog new file mode 100644 index 0000000..ad8a72c --- /dev/null +++ b/Languages/Smalltalk/ChangeLog @@ -0,0 +1,49 @@ +2002 Mar 17 + + * STCompiler, STGrammar: changed grammar to be able to have "methods" or + "just statements" in source + +2002 Feb 14 + + * STSourceReader: Retain character sets + +2002 Feb 5 + + * STSelector+additions.[hm]: new files + * STCompiler: use STSelector class for symbol literals + +2002 Feb 3 + + * STScriptObject: handle special method 'exit' + * STBytecodeInterpreter: added code to halt the interpreter and return from + all contexts + +2002 Jan 31 + + * STBlock: small speed improvements + * STBlockContext: removed evaluateWithArguments:count:, and moved code + into STBLock + +2002 Jan 23 + + * NSNumber+additions: moved arithmetic code to the library + +2002 Jan 22 + + * STCompiler: create one more duplicate of stack top when assigning to a + variable. + +2002 Jan 9 + + * SmalltalkEngine: implemented executeScript:inEnvironment: + +2001 Dec 8 + + * Fixed temporary variable compilation + * Added special handling of nil, YES and NO constants; added corresponding + bytecodes + +2001 Dec 8 + + * CahgeLog started + diff --git a/Languages/Smalltalk/Externs.h b/Languages/Smalltalk/Externs.h new file mode 100644 index 0000000..e8e46c4 --- /dev/null +++ b/Languages/Smalltalk/Externs.h @@ -0,0 +1,15 @@ +/** + Externs + Misc. variables + + Copyright (c) 2002 Free Software Foundation + + This file is part of the StepTalk project. + + */ +#import + +extern NSString *STCompilerSyntaxException; +extern NSString *STCompilerGenericException; + +extern NSString *STInterpreterGenericException; diff --git a/Languages/Smalltalk/Externs.m b/Languages/Smalltalk/Externs.m new file mode 100644 index 0000000..9c8fc9e --- /dev/null +++ b/Languages/Smalltalk/Externs.m @@ -0,0 +1,15 @@ +/** + Externs.m + Misc. variables + + Copyright (c) 2002 Free Software Foundation + + This file is part of the StepTalk project. + + */ +#import + +NSString *STCompilerSyntaxException = @"STCompilerSyntaxException"; +NSString *STCompilerGenericException = @"STCompilerGenericException"; + +NSString *STInterpreterGenericException = @"STInterpreterGenericException"; diff --git a/Languages/Smalltalk/GNUmakefile b/Languages/Smalltalk/GNUmakefile new file mode 100644 index 0000000..3a081cf --- /dev/null +++ b/Languages/Smalltalk/GNUmakefile @@ -0,0 +1,67 @@ +# +# Smalltalk language bundle +# +# 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., 675 Mass Ave, Cambridge, MA 02111, USA. +# + +GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles + +include $(GNUSTEP_MAKEFILES)/common.make + +BUNDLE_NAME = Smalltalk +BUNDLE_EXTENSION := .stlanguage +BUNDLE_INSTALL_DIR:=$(GNUSTEP_INSTALLATION_DIR)/Library/StepTalk/Languages + +Smalltalk_OBJC_FILES = \ + SmalltalkEngine.m \ + NSArray+additions.m \ + NSNumber+additions.m \ + NSObject+additions.m \ + STBlock.m \ + STBlockContext.m \ + STBytecodeInterpreter.m \ + STBytecodes.m \ + STCompiledCode.m \ + STCompiledMethod.m \ + STCompiledScript.m \ + STCompiler.m \ + STCompilerUtils.m \ + STExecutionContext.m \ + STGrammar.m \ + STLiterals.m \ + STMessage.m \ + STMethodContext.m \ + STScriptObject.m \ + STStack.m \ + STUndefinedObject+additions.m \ + STSelector+additions.m \ + STSourceReader.m \ + Externs.m + +Smalltalk_PRINCIPAL_CLASS = SmalltalkEngine + +ADDITIONAL_INCLUDE_DIRS += -I../../Source/Headers + +-include GNUmakefile.preamble +include $(GNUSTEP_MAKEFILES)/bundle.make +-include GNUMakefile.postamble + +STGrammar.m: STGrammar.y + $(YACC) -d -pSTC -o$@ $< + diff --git a/Languages/Smalltalk/NSArray+additions.h b/Languages/Smalltalk/NSArray+additions.h new file mode 100644 index 0000000..e73b365 --- /dev/null +++ b/Languages/Smalltalk/NSArray+additions.h @@ -0,0 +1,35 @@ +/** + NSArray-additions.h + Various methods for NSArray + + 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 + +@class STBlock; + +@interface NSArray (STCollecting) +- do:(STBlock *)block; +- select:(STBlock *)block; +- reject:(STBlock *)block; +- collect:(STBlock *)block; +- detect:(STBlock *)block; +@end diff --git a/Languages/Smalltalk/NSArray+additions.m b/Languages/Smalltalk/NSArray+additions.m new file mode 100644 index 0000000..51f0e0a --- /dev/null +++ b/Languages/Smalltalk/NSArray+additions.m @@ -0,0 +1,127 @@ +/** + NSArray-additions.m + Various methods for NSArray + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + + 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 "NSArray+additions.h" +#import "NSNumber+additions.h" +#import "STBlock.h" + +#import + +@implementation NSArray (STCollecting) +- do:(STBlock *)block +{ + NSEnumerator *enumerator; + id object; + id retval = nil; + + enumerator = [self objectEnumerator]; + while( (object = [enumerator nextObject]) ) + { + retval = [block valueWith:object]; + } + return retval; +} +- select:(STBlock *)block +{ + NSMutableArray *array; + NSEnumerator *enumerator; + id object; + id value; + + array = [NSMutableArray array]; + + enumerator = [self objectEnumerator]; + while( (object = [enumerator nextObject]) ) + { + value = [block valueWith:object]; + if([(NSNumber *)value isTrue]) + { + [array addObject:object]; + } + } + + return [NSArray arrayWithArray:array]; +} + +- reject:(STBlock *)block +{ + NSMutableArray *array; + NSEnumerator *enumerator; + id object; + id value; + + array = [NSMutableArray array]; + + enumerator = [self objectEnumerator]; + while( (object = [enumerator nextObject]) ) + { + value = [block valueWith:object]; + if([(NSNumber *)value isFalse]) + { + [array addObject:object]; + } + } + + return [NSArray arrayWithArray:array]; +} + +- collect:(STBlock *)block +{ + NSMutableArray *array; + NSEnumerator *enumerator; + id object; + id value; + + array = [NSMutableArray array]; + + enumerator = [self objectEnumerator]; + while( (object = [enumerator nextObject]) ) + { + value = [block valueWith:object]; + [array addObject:value]; + } + + return [NSArray arrayWithArray:array]; + +} +- detect:(STBlock *)block +{ + NSEnumerator *enumerator; + id object; + id retval = nil; + + enumerator = [self objectEnumerator]; + while( (object = [enumerator nextObject]) ) + { + retval = [block valueWith:object]; + if([(NSNumber *)retval isTrue]) + { + return object; + } + } + return retval; +} +@end diff --git a/Languages/Smalltalk/NSNumber+additions.h b/Languages/Smalltalk/NSNumber+additions.h new file mode 100644 index 0000000..8f7efc7 --- /dev/null +++ b/Languages/Smalltalk/NSNumber+additions.h @@ -0,0 +1,40 @@ +/** + NSNumber-additions.h + Various methods for NSNumber + + 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 + +@class STBlock; + +@interface NSNumber (STSmalltalkAdditions) +- ifTrue:(STBlock *)block; +- ifFalse:(STBlock *)block; +- ifTrue:(STBlock *)trueBlock ifFalse:(STBlock *)falseBlock; +- ifFalse:(STBlock *)falseBlock ifTrue:(STBlock *)trueBlock; + +- (BOOL)isTrue; +- (BOOL)isFalse; + +- to:(int)number do:(STBlock *)block; +- to:(int)number step:(int)step do:(STBlock *)block; +@end diff --git a/Languages/Smalltalk/NSNumber+additions.m b/Languages/Smalltalk/NSNumber+additions.m new file mode 100644 index 0000000..ec88b61 --- /dev/null +++ b/Languages/Smalltalk/NSNumber+additions.m @@ -0,0 +1,83 @@ +/** + NSNumber-additions.h + Various methods for NSNumber + + Copyright (c) 2002 Free Software Foundation + + This file is part of the StepTalk project. + + */ + +#import "NSNumber+additions.h" +#import "STBlock.h" +#include + +@implementation NSNumber (STSmalltalkAdditions) +- ifTrue:(STBlock *)block +{ + if([self isTrue]) + { + return [block value]; + } + return self; +} +- ifFalse:(STBlock *)block +{ + if([self isFalse]) + { + return [block value]; + } + return self; +} +- ifTrue:(STBlock *)trueBlock ifFalse:(STBlock *)falseBlock +{ + if([self isTrue]) + { + return [trueBlock value]; + } + return [falseBlock value]; +} +- ifFalse:(STBlock *)falseBlock ifTrue:(STBlock *)trueBlock +{ + if([self isFalse]) + { + return [falseBlock value]; + } + return [trueBlock value]; +} + +- (BOOL)isTrue +{ + return ([self intValue] != 0); +} +- (BOOL)isFalse +{ + return ([self intValue] == 0); +} + +/* FIXME: make it work with floats */ + +- to:(int)number do:(STBlock *)block +{ + id retval = nil; + int i; + + for(i=[self intValue];i<=number;i++) + { + retval = [block valueWith:[NSNumber numberWithInt:i]]; + } + return retval; +} + +- to:(int)number step:(int)step do:(STBlock *)block +{ + id retval = nil; + int i; + + for(i=[self intValue];i<=number;i+=step) + { + retval = [block valueWith:[NSNumber numberWithInt:i]]; + } + return retval; +} +@end diff --git a/Languages/Smalltalk/NSObject+additions.h b/Languages/Smalltalk/NSObject+additions.h new file mode 100644 index 0000000..ef15aa0 --- /dev/null +++ b/Languages/Smalltalk/NSObject+additions.h @@ -0,0 +1,30 @@ +/** + 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)isNil; +- (BOOL)notNil; +@end diff --git a/Languages/Smalltalk/NSObject+additions.m b/Languages/Smalltalk/NSObject+additions.m new file mode 100644 index 0000000..2fced6c --- /dev/null +++ b/Languages/Smalltalk/NSObject+additions.m @@ -0,0 +1,24 @@ +/** + NSObject-additions.m + Various methods for NSObject + + Copyright (c) 2002 Free Software Foundation + + This file is part of the StepTalk project. + + */ + +#import "NSObject+additions.h" + +@implementation NSObject (STAdditions) +- (BOOL)isNil +{ + return NO; +} +- (BOOL)notNil +{ + return YES; +} + +@end + diff --git a/Languages/Smalltalk/STBlock.h b/Languages/Smalltalk/STBlock.h new file mode 100644 index 0000000..7eef5e3 --- /dev/null +++ b/Languages/Smalltalk/STBlock.h @@ -0,0 +1,61 @@ +/** + STBlock.h + Wrapper for STBlockContext to make it invisible + + 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 + +@class STBlockLiteral; +@class STBytecodeInterpreter; +@class STMethodContext; +@class STBlockContext; + +@interface STBlock:NSObject +{ + STBytecodeInterpreter *interpreter; + STMethodContext *homeContext; + + unsigned initialIP; + unsigned argCount; + unsigned stackSize; + + STBlockContext *defaultContext; + BOOL defaultContextInUse; +} +- initWithInterpreter:(STBytecodeInterpreter *)anInterpreter + homeContext:(STMethodContext *)context + initialIP:(unsigned)ptr + info:(STBlockLiteral *)info; + +- (unsigned)argumentCount; + +- value; +- valueWith:arg; +- valueWith:arg1 with:arg2; +- valueWith:arg1 with:arg2 with:arg3; +- valueWithArgs:(id *)args count:(unsigned)count; + +- whileTrue:(STBlock *)doBlock; +- whileFalse:(STBlock *)doBlock; + +- handler:(STBlock *)handlerBlock; +@end diff --git a/Languages/Smalltalk/STBlock.m b/Languages/Smalltalk/STBlock.m new file mode 100644 index 0000000..0848439 --- /dev/null +++ b/Languages/Smalltalk/STBlock.m @@ -0,0 +1,228 @@ +/** + STBlock.m + Wrapper for STBlockContext to make it invisible from the user + + 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 "STBlock.h" +#import "STLiterals.h" +#import "STBlockContext.h" +#import "STBytecodeInterpreter.h" +#import "STStack.h" + +#import + +#import +#import +#import + + + +@implementation STBlock +- initWithInterpreter:(STBytecodeInterpreter *)anInterpreter + homeContext:(STMethodContext *)context + initialIP:(unsigned)ptr + info:(STBlockLiteral *)info +{ + homeContext = context; + argCount = [info argumentCount]; + stackSize = [info stackSize]; + initialIP = ptr; + interpreter = anInterpreter; + + return [super init]; +} + +- (unsigned)argumentCount +{ + return argCount; +} + +- value +{ + if(argCount != 0) + { + [NSException raise:STScriptingException + format:@"Block needs %i arguments", argCount]; + return nil; + } + return [self valueWithArgs:(id*)0 count:0]; +} + +- valueWith:arg +{ + id args[1] = {arg}; + id retval; + + retval = [self valueWithArgs:args count:1]; + return retval; +} + +- valueWith:arg1 with:arg2 +{ + id args[2] = {arg1,arg2}; + id retval; + + retval = [self valueWithArgs:args count:2]; + return retval; +} + +- valueWith:arg1 with:arg2 with:arg3 +{ + id args[3] = {arg1,arg2,arg3}; + id retval; + + retval = [self valueWithArgs:args count:3]; + return retval; +} + +- valueWith:arg1 with:arg2 with:arg3 with:arg4 +{ + id args[4] = {arg1,arg2,arg3,arg4}; + id retval; + + retval = [self valueWithArgs:args count:4]; + return retval; +} + +- (STBlockContext *)createBlockContext +{ + STBlockContext *context; + + context = [[STBlockContext alloc] initWithInterpreter:interpreter + initialIP:initialIP + stackSize:stackSize]; + + [context setHomeContext:homeContext]; + + return context; +} +- valueWithArgs:(id *)args count:(unsigned)count; +{ + STBlockContext *context = nil; + id retval; + + if(argCount != count) + { + [NSException raise:STScriptingException + format:@"Invalid block argument count %i, " + @"wants to be %i", count, argCount]; + return nil; + } + + if(!defaultContext) + { + defaultContext = [self createBlockContext]; + + context = RETAIN(defaultContext); + } + else + { + if(!defaultContextInUse) + { + context = RETAIN(defaultContext); + defaultContextInUse = YES; + } + else + { + context = [self createBlockContext]; + } + } + + + NSDebugLLog(@"STExecutionContext", + @"new block context %@",context); + + retval = [self evaluateInContext:context arguments:args count:count]; + + if(defaultContext == context) + { + defaultContextInUse = NO; + } + + RELEASE(context); + + return retval; +} + +- evaluateInContext:(STBlockContext *)context + arguments:(id *)args + count:(unsigned)count +{ + STStack *stack; + id retval; + int i; + + stack = [context stack]; + + for(i=0;i + +#import +#import +#import + +@implementation STBlockContext +- initWithInterpreter:(STBytecodeInterpreter *)anInterpreter + initialIP:(unsigned)pointer + stackSize:(unsigned)size +{ + interpreter = RETAIN(anInterpreter); + initialIP = pointer; + + [self setInstructionPointer:initialIP]; + + return [super initWithStackSize:size]; +} +- (void)dealloc +{ + RELEASE(interpreter); + [super dealloc]; +} + +- (BOOL)isBlockContext +{ + return YES; +} +- (void)setHomeContext:(STMethodContext *)context +{ + ASSIGN(homeContext,context); +} +- (STMethodContext *)homeContext +{ + return homeContext; +} +- (void)invalidate +{ + [self setParrentContext:nil]; +} +- (BOOL)isInvalid +{ + return (!parrentContext); +} + +- (unsigned)initialIP +{ + return initialIP; +} +- (void)initializeIntstructionPointer +{ + [self setInstructionPointer:initialIP]; +} + +- temporaryAtIndex:(unsigned)index; +{ + return [homeContext temporaryAtIndex:index]; +} +- (void)setTemporary:anObject atIndex:(unsigned)index; +{ + [homeContext setTemporary:anObject atIndex:index]; +} + +- externAtIndex:(unsigned)index; +{ + return [homeContext externAtIndex:index]; +} +- (void)setExtern:anObject atIndex:(unsigned)index; +{ + [homeContext setExtern:anObject atIndex:index]; +} + +- (void) forceReturn +{ + NSDebugLLog(@"STBytecodeInterpreter", + @"!!! force return from block context"); + [interpreter forceReturnFromBlockContext]; +} +- (STBytecodes *)bytecodes +{ + return [homeContext bytecodes]; +} +- (id)literalObjectAtIndex:(unsigned)index +{ + return [homeContext literalObjectAtIndex:index]; +} +@end diff --git a/Languages/Smalltalk/STBytecodeInterpreter.h b/Languages/Smalltalk/STBytecodeInterpreter.h new file mode 100644 index 0000000..ef7ec56 --- /dev/null +++ b/Languages/Smalltalk/STBytecodeInterpreter.h @@ -0,0 +1,69 @@ +/** + STBytecodeInterpreter.h + + 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 + +@class STCompiledMethod; +@class STCompiledCode; +@class STBytecodes; +@class STExecutionContext; +@class STStack; +@class STEnvironment; + +@class NSArray; +@class NSMutableArray; +@class NSMutableDictionary; + +@interface STBytecodeInterpreter:NSObject +{ + STEnvironment *environment; /* scripting environment */ + + STExecutionContext *activeContext; /* current execution context */ + STStack *stack; /* from context */ + STBytecodes *bytecodes; /* from context */ + unsigned instructionPointer; /* IP */ + id receiver; + + int entry; + + BOOL stopRequested; +} + ++ (STBytecodeInterpreter *)sharedInterpreter; +- (void)setEnvironment:(STEnvironment *)env; + +- executeCompiledMethod:(STCompiledMethod *)aScript; +- executeCompiledMethod:(STCompiledMethod *)method + withArguments:(NSArray *)args; +- executeCompiledCode:(STCompiledCode *)code; + +- (void)setReceiver:(id)anObject; +@end + +@class STBlockContext; + +@interface STBytecodeInterpreter(STInterpreterPrivate) +- valueOfBlockContext:(STBlockContext *)block; +- (void)forceReturnFromBlockContext; +@end + diff --git a/Languages/Smalltalk/STBytecodeInterpreter.m b/Languages/Smalltalk/STBytecodeInterpreter.m new file mode 100644 index 0000000..bdb38be --- /dev/null +++ b/Languages/Smalltalk/STBytecodeInterpreter.m @@ -0,0 +1,656 @@ +/** + STBytecodeInterpreter.m + + 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 "STBytecodeInterpreter.h" + +#import "Externs.h" +#import "STBlock.h" +#import "STBlockContext.h" +#import "STLiterals.h" +#import "STBytecodes.h" +#import "STCompiledMethod.h" +#import "STExecutionContext.h" +#import "STMethodContext.h" +#import "STMessage.h" +#import "STStack.h" + +#import +#import +#import +#import +#import + +#import +#import +#import +#import +#import +#import +#import + +#import + +@interface STBytecodeInterpreter(STPrivateMethods) +- (void)fetchContextRegisters; + +- (short)fetchBytecode; +- (BOOL)dispatchBytecode:(STBytecode)bytecode; +- (void)invalidBytecode:(STBytecode)bytecode; + +- (void)setInstructionPointer:(unsigned)newIP; +- (unsigned) instructionPointer; + +- temporaryAtIndex:(unsigned)index; +- externAtIndex:(unsigned)index; +- literalAtIndex:(unsigned)index; +- (void)setTemporary:anObject atIndex:(unsigned)index; +- (void)registerObject:anObject withName:(NSString *)name; + +- (void)sendSelectorAtIndex:(unsigned)index withArgs:(unsigned)argCount; + +- (void)resolveExternReferencesFrom:(NSArray *)array; + +- (void)setArgumentsFromArray:(NSArray *)args; +- (void)prepareHomeContextWithMethod:(STCompiledMethod *)aMethod; +- (id) interpretInContext:(STExecutionContext *)context; +- (void)setNewActiveContext:(STExecutionContext *)newContext; +- (void)fetchContextRegisters; +- (void)blockCopyWithInfo:(STBlockLiteral *)info; +- (id) valueOfBlockContext:(STBlockContext *)block; +- (void)blockReturnValue:(id)value; +- (void)returnValue:(id)value; +- (void)returnToContext:(STExecutionContext *)context; +@end + +static STBytecodeInterpreter *sharedInterpreter = nil; + +static SEL sendSelectorAtIndexSel; +static IMP sendSelectorAtIndexImp; +static SEL dispatchBytecodeSel; +static IMP dispatchBytecodeImp; +static SEL pushSel; +static IMP pushImp; +static SEL popSel; +static id (*popImp)(id obj, SEL sel); + +@implementation STBytecodeInterpreter ++ (void)initialize +{ + sendSelectorAtIndexSel = @selector(sendSelectorAtIndex:withArgCount:); + pushSel = @selector(push:); + popSel = @selector(pop); + + sendSelectorAtIndexImp = [STBytecodeInterpreter instanceMethodForSelector:sendSelectorAtIndexSel]; + pushImp = [STStack instanceMethodForSelector:pushSel]; + popImp = [STStack instanceMethodForSelector:popSel]; +} + ++ (STBytecodeInterpreter *)sharedInterpreter +{ + if(!sharedInterpreter) + { + sharedInterpreter = [[self alloc] init]; + } + return sharedInterpreter; +} + +- (void)setEnvironment:(STEnvironment *)env +{ + ASSIGN(environment,env); +} + +- executeCompiledMethod:(STCompiledMethod *)aScript +{ + return [self executeCompiledMethod:aScript withArguments:nil]; +} + +- executeCompiledMethod:(STCompiledMethod *)method + withArguments:(NSArray *)args +{ + STMethodContext *newContext; + id retval; + + if(!environment) + { + [NSException raise:STInterpreterGenericException + format:@"No execution environment set"]; + return nil; + } + + NSDebugLLog(@"STBytecodeInterpreter",@"Executing method %@ with %i args", + [method selector],[args count]); + + if(!method) + { + return nil; + } + + if([args count] != [method argumentCount]) + { + [NSException raise:STInterpreterGenericException + format:@"Invalid argument count %i(%i) for method %@ ", + [args count],[method argumentCount], [method selector]]; + } + + newContext = [STMethodContext methodContextWithMethod:method + environment:environment]; + + [newContext setArgumentsFromArray:args]; + + retval = [self interpretInContext:newContext]; + + return retval; +} + +- executeCompiledCode:(STCompiledCode *)code +{ + STCompiledMethod *method; + STMethodContext *newContext; + STMessage *pattern; + id retval; + + pattern = [STMessage messageWithSelector:@"_anonymous_code" + arguments:nil]; + + method = [STCompiledMethod methodWithCode:code + messagePattern:pattern]; + + return [self executeCompiledMethod:method withArguments:nil]; +} + + +/* --------------------------------------------------------------------------- + * Interpret + * --------------------------------------------------------------------------- + */ +- (id)interpretInContext:(STExecutionContext *)newContext +{ + STBytecode bytecode; + id retval; + + entry++; + NSDebugLLog(@"STBytecodeInterpreter", @"Interpreter entry %i", entry); + + [newContext setParrentContext:activeContext]; + + [self setNewActiveContext:newContext]; + + NSDebugLLog(@"STBytecodeInterpreter", @"IP %i %x", instructionPointer, [bytecodes length]); + + if(!bytecodes) + { + [NSException raise:STInterpreterGenericException + format:@"No bytecodes"]; + return nil; + } + + stopRequested = NO; + + do + { + bytecode = [bytecodes fetchNextBytecodeAtPointer:&instructionPointer]; + + if(stopRequested) + { + break; + } + + } while( [self dispatchBytecode:bytecode] ); + + if(!stopRequested) + { + retval = [stack pop]; + } + else + { + NSDebugLLog(@"STBytecode interpreter",@"Stop requested"); + + retval = nil; + } + + NSDebugLLog(@"STBytecodeInterpreter", + @"Returning '%@' from interpreter (entry %i)",retval,entry); + + entry --; + return retval; +} + +- (void)halt +{ + NSDebugLLog(@"STBytecode interpreter",@"Halt!"); + stopRequested = YES; +} +/* --------------------------------------------------------------------------- + * Context manipulation + * --------------------------------------------------------------------------- + */ + +- (void)setNewActiveContext:(STExecutionContext *)newContext +{ + + NSDebugLLog(@"STExecutionContext", @"Switch from context %@ to context %@", + activeContext, newContext); + + [activeContext setInstructionPointer:instructionPointer]; + + if( [newContext isInvalid]) + { + [NSException raise:STInterpreterGenericException + format:@"Invalid context"]; + } + + ASSIGN(activeContext,newContext); + + if(activeContext) + { + stack = [activeContext stack]; + + if(!stack) + { + [NSException raise:STInternalInconsistencyException + format:@"No execution stack"]; + } + + instructionPointer = [activeContext instructionPointer]; + + bytecodes = [activeContext bytecodes]; + } + else + { + instructionPointer = 0; + bytecodes = nil; + } +} + +/* --------------------------------------------------------------------------- + * Return + * --------------------------------------------------------------------------- + */ + +- (void)returnValue:(id)value +{ + + NSDebugLLog(@"STExecutionContext", + @"%@ return value '%@' from method", + activeContext,value); + + [self returnToContext:[activeContext parrentContext]]; + [stack push:value]; +} + +- (void)returnToContext:(STExecutionContext *)context +{ + NSDebugLLog(@"STExecutionContext", + @"%@ return to context %@",activeContext,context); + + + [activeContext invalidate]; + + [self setNewActiveContext:context]; +} + +- (unsigned) instructionPointer +{ + return instructionPointer; +} + +/* --------------------------------------------------------------------------- + Variables manipulation + * --------------------------------------------------------------------------- + */ +- (id)temporaryAtIndex:(unsigned)index +{ + id object = [activeContext temporaryAtIndex:index]; + return object; +} + +- (id)literalAtIndex:(unsigned)index +{ + return [activeContext literalObjectAtIndex:index]; +} + +- (id)externAtIndex:(unsigned)index +{ + return [activeContext externAtIndex:index]; +} + + +- (void)setReceiver:(id)anObject +{ + NSDebugLLog(@"STBytecodeInterpreter", + @"set receiver '%@'",anObject); + ASSIGN(receiver,anObject); +} + +/* FIXME: --------------------------------------------------------------------- + * Block manipulation + * --------------------------------------------------------------------------- + */ +- (void)blockCopyWithInfo:(STBlockLiteral *)info +{ + unsigned ptr; + STBlock *block; + + ptr = instructionPointer + STLongJumpBytecodeSize; + + NSDebugLLog(@"STExecutionContext", + @"%@ create block",activeContext); + + NSDebugLLog(@"STExecutionContext", + @"%@ argc:%i stack:%i ip:0x%04x", + activeContext, + [info argumentCount], + [info stackSize], + ptr); + + + block = [STBlock alloc]; + + [block initWithInterpreter:self + homeContext:[activeContext homeContext] + initialIP:ptr + info:info]; + + [stack push:block]; +} + +- (id)valueOfBlockContext:(STBlockContext *)block +{ + id retval; + + NSDebugLLog(@"STBytecodeInterpreter",@"evaluating block context"); + + NSDebugLLog(@"STExecutionContext", + @"%@ evaluate block %@", + activeContext, block); + + [block setParrentContext:activeContext]; + [block initializeIntstructionPointer]; + + retval = [self interpretInContext:block]; + + NSDebugLLog(@"STBytecodeInterpreter", + @"Returning '%@' from block",retval); + + return retval; +} + +- (void)forceReturnFromBlockContext +{ + NSDebugLLog(@"STBytecodeInterpreter", + @"Forced return from block"); + [self blockReturnValue:[stack pop]]; +} + +- (void)blockReturnValue:(id)value +{ + NSDebugLLog(@"STExecutionContext", + @"%@ block return value '%@' to parrent", + activeContext,value); + + [self returnToContext:[activeContext parrentContext]]; + [stack push:value]; +} + + + +/* --------------------------------------------------------------------------- + send selector (see also STEnvironment class) + * --------------------------------------------------------------------------- + */ + +- (void)sendSelectorAtIndex:(unsigned)selIndex withArgCount:(unsigned)argCount +{ + NSString *selector; + NSInvocation *invocation; + id target; + int index; + id object; + + NSDebugLLog(@"STSending", + @"send selector '%@' with %i args'", + [self literalAtIndex:selIndex],argCount); + + target = [stack valueFromTop:argCount]; + + /* FIXME */ + if(!target) + { + target = STNil; + } + + selector = [self literalAtIndex:selIndex]; + + NSDebugLLog(@"STSending", + @" %s receiver:%@ (%s) selector:%@", + [receiver isProxy] ? "proxy for" : "", + target, + [target name], + selector); + + selector = [environment translateSelector:selector forReceiver:target]; + + invocation = [NSInvocation invocationWithTarget:target + selectorName:selector]; + + if(!invocation) + { + [NSException raise:STInternalInconsistencyException + format:@"Should not send selector '%@' to " + @"receiver of type %@ (could not create invocation)", + selector,[target className]]; + return; + } + + + for(index = argCount + 1; index > 1; index--) + { + + object = [stack pop]; + + if(object == STNil) + { + object = nil; + } + + NSDebugLLog(@"STSending", + @" argument %2i: '%@'",index - 2, object); + + [invocation setArgumentAsObject:object atIndex:index]; + } + + /* ---------------------------- + * invoke it! + * ---------------------------- + */ + + NSDebugLLog(@"STSending",@" invoking... (%@)",invocation); + [invocation invoke]; + + /* FIXME */ + if(!stopRequested) + { + /* pop the receiver from the stack */ + [stack pop]; + [stack push: [invocation returnValueAsObject]]; + } +} + + +/* --------------------------------------------------------------------------- + Bytecode manipulation + * --------------------------------------------------------------------------- + */ +#define STDebugBytecode(bc) \ + NSDebugLLog(@"STBytecodeInterpreter", \ + @"#%04x %@", \ + (bc).pointer, \ + STDissasembleBytecode(bc)) + +#define STDebugBytecodeWith(bc,object) \ + NSDebugLLog(@"STBytecodeInterpreter", \ + @"#%04x %@ (%@)", \ + (bc).pointer, \ + STDissasembleBytecode(bc), \ + (object)) + +#define STPush(s, v) (*pushImp)(s, pushSel, v) +// #define STPush(s, v) [s push:v] + +#define STPop(s) (*popImp)(s, popSel) +// #define STPop(s) [s pop] + +- (BOOL)dispatchBytecode:(STBytecode)bytecode +{ + id object; + + switch(bytecode.code) + { + case STLongJumpBytecode: + { + int offset = STLongJumpOffset(bytecode.arg1,bytecode.arg2) + - STLongJumpBytecodeSize; + + STDebugBytecode(bytecode); + instructionPointer+=offset; + break; + } + + case STPushReceiverBytecode: + STDebugBytecodeWith(bytecode,receiver); + STPush(stack, receiver); + break; + + case STPushNilBytecode: + STDebugBytecodeWith(bytecode,receiver); + STPush(stack,nil); + break; + + case STPushTrueBytecode: + STDebugBytecodeWith(bytecode,receiver); + STPush(stack,[NSNumber numberWithInt:YES]); + break; + + case STPushFalseBytecode: + STDebugBytecodeWith(bytecode,receiver); + STPush(stack,[NSNumber numberWithInt:NO]); + break; + + case STPushRecVarBytecode: + object = [receiver instanceVariableAtIndex:bytecode.arg1]; + STDebugBytecodeWith(bytecode,object); + STPush(stack,object); + break; + + case STPushExternBytecode: + object = [self externAtIndex:bytecode.arg1]; + STDebugBytecodeWith(bytecode,object); + STPush(stack,object); + break; + + case STPushTemporaryBytecode: + object = [self temporaryAtIndex:bytecode.arg1]; + STPush(stack,object); + STDebugBytecodeWith(bytecode,object); + break; + + case STPushLiteralBytecode: + object = [self literalAtIndex:bytecode.arg1]; + STDebugBytecodeWith(bytecode,object); + STPush(stack,object); + break; + + case STPopAndStoreRecVarBytecode: + STDebugBytecode(bytecode); + [receiver setInstanceVariable:STPop(stack) + atIndex:bytecode.arg1]; + break; + + case STPopAndStoreExternBytecode: + STDebugBytecode(bytecode); + [activeContext setExtern:STPop(stack) atIndex:bytecode.arg1]; + break; + + case STPopAndStoreTempBytecode: + STDebugBytecode(bytecode); + [activeContext setTemporary:STPop(stack) atIndex:bytecode.arg1]; + break; + + case STSendSelectorBytecode: + STDebugBytecodeWith(bytecode, + [self literalAtIndex:bytecode.arg1]); + + (*sendSelectorAtIndexImp)(self, sendSelectorAtIndexSel, + bytecode.arg1,bytecode.arg2); +/* + [self sendSelectorAtIndex:bytecode.arg1 + withArgCount:bytecode.arg2]; +*/ break; + + case STSuperSendSelectorBytecode: /* FIXME: not implemented */ + [self invalidBytecode:bytecode]; + break; + + case STDupBytecode: + STDebugBytecode(bytecode); + [stack duplicateTop]; + break; + + + case STPopStackBytecode: + STDebugBytecode(bytecode); + [stack pop]; + break; + + case STReturnBytecode: + STDebugBytecode(bytecode); + [self returnValue:[stack pop]]; + return NO; + + case STReturnBlockBytecode: + STDebugBytecode(bytecode); + [self blockReturnValue:[stack pop]]; + return NO; + + case STBlockCopyBytecode: + STDebugBytecode(bytecode); + [self blockCopyWithInfo:[stack pop]]; + break; + + default: + [self invalidBytecode:bytecode]; + break; + }; + + return YES; +} + +- (void)invalidBytecode:(STBytecode)bytecode +{ + [NSException raise:STInternalInconsistencyException + format:@"invalid bytecode (0x%02x) at 0x%06x", + bytecode.code,bytecode.pointer]; +} +@end + + diff --git a/Languages/Smalltalk/STBytecodes.h b/Languages/Smalltalk/STBytecodes.h new file mode 100644 index 0000000..eba0b71 --- /dev/null +++ b/Languages/Smalltalk/STBytecodes.h @@ -0,0 +1,91 @@ +/** + STBytecodes.h + + 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 + + +/* Bytecode table */ +/* +#define STReceiverConstant 0x00 +#define STTrueConstant 0x01 +#define STFalseConstant 0x02 +#define STNilConstant 0x03 +*/ +#define STPushReceiverBytecode 0x00 /* push self */ +#define STPushNilBytecode 0x01 +#define STPushTrueBytecode 0x02 +#define STPushFalseBytecode 0x03 +/* 0x00 - 0x07 receiver,true,false,nil, + -1,0,1,2 */ +#define STPushRecVarBytecode 0x08 /* recvar index */ +#define STPushExternBytecode 0x09 /* extern index */ +#define STPushTemporaryBytecode 0x0a /* temp index */ +#define STPushLiteralBytecode 0x0b /* lit index */ +#define STPopAndStoreRecVarBytecode 0x0c /* recvar index */ +#define STPopAndStoreExternBytecode 0x0d /* extern index */ +#define STPopAndStoreTempBytecode 0x0e /* temp index */ +/* 0x0f reserved */ +#define STSendSelectorBytecode 0x10 /* lit index, arg count */ +#define STSuperSendSelectorBytecode 0x11 /* lit index, arg count */ +#define STBlockCopyBytecode 0x12 +#define STLongJumpBytecode 0x13 /* byte 1, byte 2 */ +#define STDupBytecode 0x14 +#define STPopStackBytecode 0x15 +#define STReturnBytecode 0x16 +#define STReturnBlockBytecode 0x17 +/* 0x18-0x27 reserved single bytecodes */ +/* 0x27-0xfe reserved */ +#define STBreakpointBytecode 0xff + +#define STLongJumpOffset(arg1, arg2) \ + ( (((arg1) & 0xff) << 8) | ((arg2) & 0xff) ) +#define STLongJumpFirstByte(offset)\ + ( ((offset) >> 8) & 0xff ) +#define STLongJumpSecondByte(offset)\ + ( (offset) & 0xff ) +#define STLongJumpBytecodeSize 3 + +@class NSArray; +@class NSString; + +typedef struct +{ + unsigned short code; + unsigned short arg1; + unsigned short arg2; + unsigned pointer; +} STBytecode; + +extern NSArray *STBytecodeNames; +extern NSString *STBytecodeName(short code); +extern NSString *STDissasembleBytecode(STBytecode bytecode); + +@interface STBytecodes:NSData +{ + NSData *bytes; +} +- (STBytecode)fetchNextBytecodeAtPointer:(unsigned *)pointer; +@end + + + diff --git a/Languages/Smalltalk/STBytecodes.m b/Languages/Smalltalk/STBytecodes.m new file mode 100644 index 0000000..3a92ee3 --- /dev/null +++ b/Languages/Smalltalk/STBytecodes.m @@ -0,0 +1,270 @@ +/** + STBytecodes.m + + 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 "STBytecodes.h" + +#import + +#import "Externs.h" + +#import +#import +#import +#import + + +NSArray *STBytecodeNames; + +static void initNamesArray(void) +{ + NSString *invalid = @"invalid bytecode"; + NSMutableArray *array; + int i; + + array = [NSMutableArray arrayWithCapacity:256]; + + for(i=0;i<256;i++) + { + [array insertObject:invalid atIndex:i]; + } + + [array replaceObjectAtIndex:STPushReceiverBytecode + withObject:@"push self"]; + [array replaceObjectAtIndex:STPushNilBytecode + withObject:@"push nil"]; + [array replaceObjectAtIndex:STPushTrueBytecode + withObject:@"push true"]; + [array replaceObjectAtIndex:STPushFalseBytecode + withObject:@"push false"]; + [array replaceObjectAtIndex:STPushRecVarBytecode + withObject:@"push ivar"]; + [array replaceObjectAtIndex:STPushExternBytecode + withObject:@"push extern"]; + [array replaceObjectAtIndex:STPushTemporaryBytecode + withObject:@"push temporary"]; + [array replaceObjectAtIndex:STPushLiteralBytecode + withObject:@"push literal"]; + [array replaceObjectAtIndex:STPopAndStoreRecVarBytecode + withObject:@"pop and store ivar"]; + [array replaceObjectAtIndex:STPopAndStoreExternBytecode + withObject:@"pop and store extern"]; + [array replaceObjectAtIndex:STPopAndStoreTempBytecode + withObject:@"pop and store temp"]; + [array replaceObjectAtIndex:STSendSelectorBytecode + withObject:@"send selector"]; + [array replaceObjectAtIndex:STSuperSendSelectorBytecode + withObject:@"send super selector"]; + [array replaceObjectAtIndex:STBlockCopyBytecode + withObject:@"block copy"]; + [array replaceObjectAtIndex:STDupBytecode + withObject:@"dup"]; + [array replaceObjectAtIndex:STPopStackBytecode + withObject:@"pop"]; + [array replaceObjectAtIndex:STReturnBytecode + withObject:@"return"]; + [array replaceObjectAtIndex:STReturnBlockBytecode + withObject:@"return from block"]; + [array replaceObjectAtIndex:STBreakpointBytecode + withObject:@"breakpoint"]; + [array replaceObjectAtIndex:STLongJumpBytecode + withObject:@"long jump"]; + + STBytecodeNames = [[NSArray alloc] initWithArray:array]; +} + + +NSString *STBytecodeName(short code) +{ + static NSString *invalid = @"invalid bytecode"; + NSString *name; + + if( code < 0 || code > [STBytecodeNames count] ) + { + return invalid; + } + + name = [STBytecodeNames objectAtIndex:code]; + + if(name == nil) + { + return invalid; + } + + return name; +} + +NSString *STDissasembleBytecode(STBytecode bytecode) +{ + NSString *str; + + str = STBytecodeName(bytecode.code); + + switch(bytecode.code) + { + case STLongJumpBytecode: + { + int offset = STLongJumpOffset(bytecode.arg1,bytecode.arg2); + return [NSString stringWithFormat:@"%@ %i (0x%06x)", + str, offset, bytecode.pointer+offset]; + } + case STSendSelectorBytecode: + case STSuperSendSelectorBytecode: + return [NSString stringWithFormat:@"%@ %i with %i args", + str, bytecode.arg1, bytecode.arg2]; + case STPushRecVarBytecode: + case STPushExternBytecode: + case STPushTemporaryBytecode: + case STPushLiteralBytecode: + case STPopAndStoreRecVarBytecode: + case STPopAndStoreExternBytecode: + case STPopAndStoreTempBytecode: + return [NSString stringWithFormat:@"%@ %i", + str, bytecode.arg1]; + case STPushReceiverBytecode: + case STPushNilBytecode: + case STPushTrueBytecode: + case STPushFalseBytecode: + case STBlockCopyBytecode: + case STDupBytecode: + case STPopStackBytecode: + case STReturnBytecode: + case STReturnBlockBytecode: + case STBreakpointBytecode: + return str; + default: + return [NSString stringWithFormat:@"invalid (0x%02x)", + bytecode.code]; + + } +} + + +@implementation STBytecodes ++ (void)initialize +{ + initNamesArray(); +} +/* +- (id) initWithBytesNoCopy: (void*)someBytes + length: (unsigned)length + fromZone: (NSZone*)zone +{ + bytes = [[NSData alloc] initWithBytesNoCopy:someBytes + length:length + fromZone:zone]; + return self; +} +*/ +- (id) initWithBytes: (const void*)someBytes + length: (unsigned int)length +{ + bytes = [[NSData alloc] initWithBytes:someBytes + length:length]; + return self; +} + +- (void)dealloc +{ + RELEASE(bytes); + [super dealloc]; +} + +- (const void *)bytes +{ + return [bytes bytes]; +} +- (unsigned) length +{ + return [bytes length]; +} + +- (NSString *)description +{ + return [bytes description]; +} + +- (STBytecode)fetchNextBytecodeAtPointer:(unsigned *)pointer +{ + STBytecode bytecode; + const char *bytesPtr = (const char *)[bytes bytes]; + unsigned length = [self length]; + + if(*pointer < length) + { + bytecode.pointer = *pointer; + bytecode.code = bytesPtr[(*pointer)++]; + + switch(bytecode.code) + { + case STLongJumpBytecode: + case STSendSelectorBytecode: + case STSuperSendSelectorBytecode: + if(*pointer + 2 >= length) + { + break; + } + bytecode.arg1 = bytesPtr[(*pointer)++]; + bytecode.arg2 = bytesPtr[(*pointer)++]; + return bytecode; + case STPushRecVarBytecode: + case STPushExternBytecode: + case STPushTemporaryBytecode: + case STPushLiteralBytecode: + case STPopAndStoreRecVarBytecode: + case STPopAndStoreExternBytecode: + case STPopAndStoreTempBytecode: + if(*pointer + 1 >= length) + { + break; + } + bytecode.arg1 = bytesPtr[(*pointer)++]; + bytecode.arg2 = 0; + return bytecode; + case STPushReceiverBytecode: + case STPushNilBytecode: + case STPushTrueBytecode: + case STPushFalseBytecode: + case STBlockCopyBytecode: + case STDupBytecode: + case STPopStackBytecode: + case STReturnBytecode: + case STReturnBlockBytecode: + case STBreakpointBytecode: + bytecode.arg1 = 0; + bytecode.arg2 = 0; + return bytecode; + default: + [NSException raise:STInternalInconsistencyException + format:@"Invalid bytecode 0x%02x at 0x%06x", + bytecode.code,*pointer-1]; + + } + } + + [NSException raise:STInternalInconsistencyException + format:@"Instruction pointer 0x%06x out of bounds (0x%06x)", + *pointer,length]; + return bytecode; +} +@end + diff --git a/Languages/Smalltalk/STCompiledCode.h b/Languages/Smalltalk/STCompiledCode.h new file mode 100644 index 0000000..9295503 --- /dev/null +++ b/Languages/Smalltalk/STCompiledCode.h @@ -0,0 +1,50 @@ +/** + STCompiledCode.h + + Copyright (c) 2002 Free Software Foundation + + 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 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 NSData; +@class NSArray; +@class NSMutableArray; +@class STBytecodes; + +@interface STCompiledCode:NSObject +{ + STBytecodes *bytecodes; + NSArray *literals; + NSMutableArray *externRefs; + short tempCount; + short stackSize; +} +- initWithBytecodesData:(NSData *)data + literals:(NSArray *)anArray + temporariesCount:(unsigned)count + stackSize:(unsigned)size + externReferences:(NSMutableArray *)refs; + +- (STBytecodes *)bytecodes; +- (unsigned)temporariesCount; +- (unsigned)stackSize; +- (id)literalObjectAtIndex:(unsigned)index; +- (NSMutableArray *)externReferences; +- (NSArray *)literals; +@end diff --git a/Languages/Smalltalk/STCompiledCode.m b/Languages/Smalltalk/STCompiledCode.m new file mode 100644 index 0000000..7e1dff7 --- /dev/null +++ b/Languages/Smalltalk/STCompiledCode.m @@ -0,0 +1,83 @@ +/** + STCompiledCode.m + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + + 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 "STCompiledCode.h" +#import "STBytecodes.h" + +#import +#import +#import + +@implementation STCompiledCode +- initWithBytecodesData:(NSData *)data + literals:(NSArray *)anArray + temporariesCount:(unsigned)count + stackSize:(unsigned)size + externReferences:(NSMutableArray *)refs +{ + [super init]; + + bytecodes = [[STBytecodes alloc] initWithData:RETAIN(data)]; + literals = RETAIN(anArray); + tempCount = count; + stackSize = size; + ASSIGN(externRefs,refs); + + return self; +} +- (void)dealloc +{ + RELEASE(bytecodes); + RELEASE(literals); + RELEASE(externRefs); + [super dealloc]; +} +- (STBytecodes *)bytecodes +{ + return bytecodes; +} + +- (unsigned)temporariesCount +{ + return tempCount; +} +- (unsigned)stackSize +{ + return stackSize; +} +- (NSArray *)literals +{ + return literals; +} +- (id)literalObjectAtIndex:(unsigned)index +{ + return [literals objectAtIndex:index]; +} + +- (NSMutableArray *)externReferences +{ + return externRefs; +} +@end diff --git a/Languages/Smalltalk/STCompiledMethod.h b/Languages/Smalltalk/STCompiledMethod.h new file mode 100644 index 0000000..ef6a463 --- /dev/null +++ b/Languages/Smalltalk/STCompiledMethod.h @@ -0,0 +1,46 @@ +/** + STCompiledMethod.h + + Copyright (c) 2002 Free Software Foundation + + 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 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 "STCompiledCode.h" + +@class STMessage; + +@interface STCompiledMethod:STCompiledCode +{ + NSString *selector; + short argCount; + +// unsigned primitive; +} ++ methodWithCode:(STCompiledCode *)code messagePattern:(STMessage *)pattern; + +- initWithSelector:(NSString *)sel + argumentCount:(unsigned)aCount + bytecodesData:(NSData *)data + literals:(NSArray *)anArray + temporariesCount:(unsigned)tCount + stackSize:(unsigned)size + externReferences:(NSMutableArray *)refs; + +- (NSString *)selector; +- (unsigned)argumentCount; +@end diff --git a/Languages/Smalltalk/STCompiledMethod.m b/Languages/Smalltalk/STCompiledMethod.m new file mode 100644 index 0000000..a89320a --- /dev/null +++ b/Languages/Smalltalk/STCompiledMethod.m @@ -0,0 +1,120 @@ +/** + STCompiledMethod.m + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + + 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 "STCompiledMethod.h" + +#import "STMessage.h" +#import "STBytecodes.h" + +#import + +#import +#import +#import + +@implementation STCompiledMethod ++ methodWithCode:(STCompiledCode *)code messagePattern:(STMessage *)pattern +{ + STCompiledMethod *method; + + method = [STCompiledMethod alloc]; + + [method initWithSelector:[pattern selector] + argumentCount:[[pattern arguments] count] + bytecodesData:[code bytecodes] + literals:[code literals] + temporariesCount:[code temporariesCount] + stackSize:[code stackSize] + externReferences:[code externReferences]]; + + + return AUTORELEASE(method); +} + +- initWithSelector:(NSString *)sel + argumentCount:(unsigned)aCount + bytecodesData:(NSData *)data + literals:(NSArray *)anArray + temporariesCount:(unsigned)tCount + stackSize:(unsigned)size + externReferences:(NSMutableArray *)refs; +{ + [super initWithBytecodesData:data + literals:anArray + temporariesCount:tCount + stackSize:size + externReferences:refs]; + + selector = RETAIN(sel); + argCount = aCount; + + return self; +} +- (void)dealloc +{ + RELEASE(selector); + [super dealloc]; +} +- (NSString *)selector +{ + return selector; +} + +- (void)setSelector:(NSString *)newSelector +{ + ASSIGN(selector,newSelector); +} +- (unsigned)argumentCount +{ + return argCount; +} +- (void)setArgumentCount:(unsigned)count +{ + argCount = count; +} +- (NSString*)description +{ + NSMutableString *desc = [NSMutableString string]; + + [desc appendFormat:@"%s:\n" + @"Selector = %@\n" + @"Literals Count = %i\n" + @"Literals = %@\n" + @"External References = %@\n" + @"Temporaries Count = %i\n" + @"Stack Size = %i\n" + @"Byte Codes = %@\n", + [self clasName], + selector, + [literals count], + [literals description], + [externRefs description], + tempCount, + stackSize, + [bytecodes description]]; + + return desc; +} +@end diff --git a/Languages/Smalltalk/STCompiledScript.h b/Languages/Smalltalk/STCompiledScript.h new file mode 100644 index 0000000..e232fff --- /dev/null +++ b/Languages/Smalltalk/STCompiledScript.h @@ -0,0 +1,45 @@ +/** + STCompiledScript.h + + Copyright (c) 2002 Free Software Foundation + + 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 NSDictionary; +@class NSMutableDictionary; +@class NSString; +@class STCompiledMethod; +@class STEnvironment; + +@interface STCompiledScript:NSObject +{ + NSMutableDictionary *methodDictionary; + int variableCount; +} +- initWithVariableCount:(unsigned)count; + +- (id)executeInEnvironment:(STEnvironment *)env; + +- (STCompiledMethod *)methodWithName:(NSString *)name; +- (void)addMethod:(STCompiledMethod *)method; +- (int)variableCount; +@end + diff --git a/Languages/Smalltalk/STCompiledScript.m b/Languages/Smalltalk/STCompiledScript.m new file mode 100644 index 0000000..f2cba2e --- /dev/null +++ b/Languages/Smalltalk/STCompiledScript.m @@ -0,0 +1,153 @@ +/** + STCompiledScript.m + + Copyright (c) 2002 Free Software Foundation + + 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 "STCompiledScript.h" + +#import "STScriptObject.h" +#import "STCompiledMethod.h" + +#import +#import + +#import +#import +#import +#import +#import +#import + +@class STEnvironment; +static SEL mainSelector; +static SEL initializeSelector; +static SEL finalizeSelector; + +@implementation STCompiledScript:NSObject ++ (void)initialize +{ + mainSelector = STSelectorFromString(@"main"); + initializeSelector = STSelectorFromString(@"startUp"); + finalizeSelector = STSelectorFromString(@"finalize"); +} + +- initWithVariableCount:(unsigned)count +{ + [super init]; + + variableCount = count; + + return self; +} +- (void)addMethod:(STCompiledMethod *)method +{ + if(!methodDictionary) + { + methodDictionary = [[NSMutableDictionary alloc] init]; + } + + if( ! [method isKindOfClass:[STCompiledMethod class]] ) + { + [NSException raise:STGenericException + format:@"Invalid compiled method class '%@'", + [method class]]; + } + + [methodDictionary setObject:method forKey:[method selector]]; +} + +- (void)dealloc +{ + RELEASE(methodDictionary); + [super dealloc]; +} + +- (STCompiledMethod *)methodWithName:(NSString *)name +{ + return [methodDictionary objectForKey:name]; +} + +- (int)variableCount +{ + return variableCount; +} + +- (id)executeInEnvironment:(STEnvironment *)env +{ + STScriptObject *object; + int methodCount; + id retval = nil; + + + object = [[STScriptObject alloc] initWithEnvironment:env + compiledScript:self]; + + methodCount = [methodDictionary count]; + + if(methodCount == 0) + { + NSLog(@"Empty script executed"); + return nil; + } + else if(methodCount == 1) + { + NSString *selName = [[methodDictionary allKeys] objectAtIndex:0]; + SEL sel = STSelectorFromString(selName); + + NSDebugLog(@"Executing single-method script. (%@)", selName); + [object performSelector:sel]; + } + else if(![object respondsToSelector:mainSelector]) + { + NSLog(@"No 'main' method found"); + return nil; + } + else + { + + if( [object respondsToSelector:initializeSelector] ) + { + NSDebugLog(@"Sending 'startUp' to script object"); + [object performSelector:initializeSelector]; + } + + if( [object respondsToSelector:mainSelector] ) + { + retval = [object performSelector:mainSelector]; + } + else + { + NSLog(@"No 'main' found in script"); + } + + if( [object respondsToSelector:finalizeSelector] ) + { + NSDebugLog(@"Sending 'finalize' to script object"); + [object performSelector:finalizeSelector]; + } + } + + RELEASE(object); + + return retval; +} + +@end diff --git a/Languages/Smalltalk/STCompiler.h b/Languages/Smalltalk/STCompiler.h new file mode 100644 index 0000000..e4ac6ad --- /dev/null +++ b/Languages/Smalltalk/STCompiler.h @@ -0,0 +1,130 @@ +/** + STCompiler.h + Bytecode compiler. Generates STExecutableCode from source code. + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + + 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 + +@class STCompiledScript; +@class STCompiledCode; +@class STCompiledMethod; +@class STEnvironment; +@class STSourceReader; + +@class STCExpression; +@class STCMethod; +@class STCPrimary; +@class STCStatements; + +@class STCompiler; + +@class NSMutableData; +@class NSMutableArray; + +/*" Parser context information "*/ +typedef struct _STParserContext +{ + STCompiler *compiler; + STSourceReader *reader; +} STParserContext; + + +/*" Get compiler from parser context "*/ +#define STParserContextGetCompiler(context)\ + (((STParserContext *)context)->compiler) +/*" 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) \ + do { \ + ((STParserContext *)context)->compiler = aCompiler; \ + ((STParserContext *)context)->reader = aReader; \ + } while(0) + +@interface STCompiler:NSObject +{ + STEnvironment *environment; + + STSourceReader *reader; + STParserContext context; + + NSMutableData *byteCodes; + NSMutableArray *tempVars; + NSMutableArray *externVars; + NSMutableArray *receiverVars; + NSMutableArray *literals; + + STCompiledScript *script; + + unsigned stackSize; /* Required stack size */ + unsigned stackPos; /* Current stack pointer */ + unsigned tempsSize; /* Required temp space */ + unsigned tempsCount; /* Actual temp space */ + unsigned bcpos; /* Bytecode position */ + + Class stringLiteralClass; /* default: NSMutableString */ + Class arrayLiteralClass; /* default: NSMutableArray */ + Class characterLiteralClass; /* default: NSString */ + Class numberLiteralClass; /* default: NSNumber */ + Class symbolLiteralClass; /* default: NSString */ +} +/*" Instance creation "*/ ++ (STCompiler *)sharedCompiler; + +/*" Environment "*/ +- (void)setEnvironment:(STEnvironment *)env; +- (STSourceReader *)sourceReader; + +/*" Compilation "*/ + +- (STCompiledCode *)compileString:(NSString *)aString; +- (STCompiledScript *)compileScript:(NSString *)script; + +/* +- (NSMutableArray *)compileString:(NSString *)string; +- (NSMutableArray *)compileString:(NSString *)string range:(NSRange) range; +*/ + + +/*" Literals "*/ +- (Class)stringLiteralClass; +- (Class)arrayLiteralClass; +- (Class)numberLiteralClass; +- (Class)symbolLiteralClass; +- (void)setStringLiteralClass:(Class)aClass; +- (void)setArrayLiteralClass:(Class)aClass; +- (void)setNumberLiteralClass:(Class)aClass; +- (void)setSymbolLiteralClass:(Class)aClass; + +- (void)setReceiverVariables:(NSArray *)vars; + +- (void)addTempVariable:(NSString *)varName; +@end diff --git a/Languages/Smalltalk/STCompiler.m b/Languages/Smalltalk/STCompiler.m new file mode 100644 index 0000000..846dce4 --- /dev/null +++ b/Languages/Smalltalk/STCompiler.m @@ -0,0 +1,944 @@ +/** + STCompiler.m + Bytecode compiler. Generates STExecutableCode from source code. + + 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 "STCompiler.h" + +#import "STMessage.h" +#import "STLiterals.h" +#import "STBytecodes.h" +#import "STCompiledScript.h" +#import "STCompiledCode.h" +#import "STCompiledMethod.h" +#import "STCompilerUtils.h" +#import "STSourceReader.h" + +#import +#import +#import + +#import +#import +#import +#import +#import +#import + +#import "STGrammar.m.h" + +extern int STCparse(void *context); + +@interface STCompiler(STCompilerPrivate) +- (void)compile; +- (void)initializeContext; +- (unsigned)tempVariableIndex:(NSString *)varName; +- (unsigned)externalVariableIndex:(NSString *)varName; + +- (void) initializeCompilation; + +- (NSDictionary *)exceptionInfo; + +- (unsigned)addSelectorLiteral:(NSString*)selector; +- (unsigned)addLiteral:literal; + +- (void)compileMethod:(STCMethod *)method; +- (STCompiledCode *) compileStatements:(STCStatements *)statements; +- (void)compileStatements:(STCStatements *)statements blockFlag:(BOOL)blockFlag; +- (void)compilePrimary:(STCPrimary *)primary; +- (void)compileExpression:(STCExpression *)expr; + +- (void)emitPushReceiverVariable:(unsigned)index; +- (void)emitPushSelf; +- (void)emitPopAndStoreReceiverVariable:(unsigned)index; +- (void)emitReturn; +- (void)emitReturnFromBlock; +- (void)emitPushTemporary:(unsigned)index; +- (void)emitPushLiteral:(unsigned)index; +- (void)emitPushVariable:(unsigned)index; +- (void)emitPopAndStoreTemporary:(unsigned)index; +- (void)emitPopAndStoreVariable:(unsigned)index ; +- (void)emitPopStack; +- (void)emitSendSelector:(unsigned)index argCount:(unsigned)argCount; +- (void)emitBlockCopy; +- (void)emitDuplicateStackTop; +- (void)emitJump:(short)offset; +- (void)emitLongJump:(short)offset; +- (void)fixupLongJumpAt:(unsigned)index with:(short)offset; +- (unsigned)currentBytecode; +@end + +#define MAX(a,b) (((a)>(b))?(a):(b)) + +@implementation STCompiler +- init +{ + [super init]; + + arrayLiteralClass = [NSMutableArray class]; + stringLiteralClass = [NSMutableString class]; + /* bytesLiteralClass = [NSMutableData class]; */ + numberLiteralClass = [NSNumber class]; + symbolLiteralClass = [STSelector class]; + characterLiteralClass = [NSString class]; + + return self; +} +- (void)dealloc +{ + [super dealloc]; +} + + +/* --------------------------------------------------------------------------- + * Compilation + * --------------------------------------------------------------------------- + */ + +- (void)setEnvironment:(STEnvironment *)env +{ + if(!reader) + { + reader = [[STSourceReader alloc] init]; + } + ASSIGN(environment,env); +} + + +- (STCompiledScript *)compileString:(NSString *)aString +{ + NSString *exceptionFmt = @"Syntax error at line %i near '%@', " + @"reason: %@."; + int parsRetval = 0; + + + NSDebugLLog(@"STCompiler", @"Compile string", aString); + + if(!environment) + { + [NSException raise:STCompilerGenericException + format:@"Compilation environment is not initialized"]; + return nil; + } + + reader = [[STSourceReader alloc] initWithString:aString]; + receiverVars = [[NSMutableArray alloc] init]; + + STParserContextInit(&context,self,reader); + + NS_DURING + { + // extern int STCdebug; + // STCdebug = 1; + parsRetval = STCparse(&context); + } + NS_HANDLER + { + if ([[localException name] isEqualToString: STCompilerSyntaxException]) + { + [NSException raise:STCompilerSyntaxException + format:exceptionFmt, + [reader currentLine], + [reader tokenString], + [localException reason]]; + + } + [localException raise]; + } + NS_ENDHANDLER + + RELEASE(reader); + + return script; +} + +- (void)compileMethod:(STCMethod *)method +{ + STCompiledMethod *compiledMethod; + STCompiledCode *code; + STMessage *messagePattern; + + if(!script) + { + NSDebugLLog(@"STCompiler", + @"Creating script with %i variables",[receiverVars count]); + + script = [[STCompiledScript alloc] initWithVariableCount: + [receiverVars count]]; + } + + messagePattern = [method messagePattern]; + + if(!messagePattern) + { + messagePattern = [STMessage messageWithSelector:@"_unnamed_method" + arguments:nil]; + } + + NSDebugLLog(@"STCompiler", @"Compile method %@", [messagePattern selector]); + + tempVars = [NSMutableArray arrayWithArray:[messagePattern arguments]]; + + code = [self compileStatements:[method statements]]; + + compiledMethod = [STCompiledMethod methodWithCode:code + messagePattern:messagePattern]; + + [script addMethod:compiledMethod]; +} + +- (STCompiledCode *)compileStatements:(STCStatements *)statements +{ + STCompiledCode *compiledCode; + int count; + int i; + + [self initializeCompilationContext]; + + NSDebugLLog(@"STCompiler", @"compiling statements"); + + tempsSize = tempsCount = [tempVars count]; + + [self compileStatements:statements blockFlag:NO]; + + NSDebugLLog(@"STCompiler", @" temporaries %i stack %i", + tempsSize,stackSize); + +#ifdef DEBUG + count = [literals count]; + + NSDebugLLog(@"STCompiler", @" literals count %i", count); + + for(i=0;i 0; index--) + { + [self emitPopAndStoreTemporary:tempsSave + index - 1]; + } + } + + array = [statements expressions]; + + if(array) + { + enumerator = [array objectEnumerator]; + while((expr = [enumerator nextObject])) + { + [self compileExpression:expr]; + } + } + + expr = [statements returnExpression]; + if(expr) + { + [self compileExpression:expr]; + } + + if(blockFlag) + { + [blockInfo setStackSize:stackSize]; + AUTORELEASE(blockInfo); + + stackSize = stackSizeSave; + stackPos = stackPosSave; + + [self emitReturnFromBlock]; + } + else + { + [self emitReturn]; + } + + /* fixup jump (if block) */ + if(blockFlag) + { + [self fixupLongJumpAt:jumpIP with:[self currentBytecode] - jumpIP]; + } + + /* cleanup unneeded temp variables */ + [tempVars removeObjectsInRange:NSMakeRange(tempsSave, + [tempVars count]-tempsSave)]; + tempsCount = tempsSave; +} + +- (void)compilePrimary:(STCPrimary *)primary +{ + id object = [primary object]; + int index; + + NSDebugLLog(@"STCompiler-misc",@" compile primary"); + + switch([primary type]) + { + case STCVariablePrimaryType: + + if([object isEqualToString:@"YES"] + || [object isEqualToString:@"true"]) + { + [self emitPushTrue]; + } + else if([object isEqualToString:@"NO"] + || [object isEqualToString:@"false"]) + { + [self emitPushFalse]; + } + else if([object isEqualToString:@"nil"]) + { + [self emitPushNil]; + } + else + { + index = [self tempVariableIndex:object]; + if(index != NSNotFound) + { + [self emitPushTemporary:index]; + break; + } + else if( (index = [self receiverVariableIndex:object])!= NSNotFound) + { + [self emitPushReceiverVariable:index]; + break; + } + else if( [object isEqual:@"self"] ) + { + [self emitPushSelf]; + break; + } + + index = [self externalVariableIndex:object]; + [self emitPushVariable:index]; + } + break; + + case STCLiteralPrimaryType: + + index = [self addLiteral:object]; + [self emitPushLiteral:index]; + break; + + case STCBlockPrimaryType: + + [self compileStatements:object blockFlag:YES]; + break; + + case STCExpressionPrimaryType: + + [self compileExpression:object]; + break; + + default: + + [NSException raise:STCompilerInconsistencyException + format:@"Unknown primary type %i", + [primary type]]; + break; + } +} + +- (void)compileMessage:(STCMessage *)message +{ + NSEnumerator *enumerator; + NSArray *args; + id obj; + int index; + + args = [message arguments]; + if(args && ([args count]>0)) + { + enumerator = [args objectEnumerator]; + while((obj = [enumerator nextObject])) + { + if([obj isKindOfClass:[STCPrimary class]]) + [self compilePrimary:obj]; + else + [self compileExpression:obj]; + } + } + + index = [self addSelectorLiteral:[message selector]]; + [self emitSendSelector:index argCount:[args count]]; +} + +- (void)compileExpression:(STCExpression *)expr +{ + NSEnumerator *enumerator; + NSArray *cascade; + NSString *varName; + NSArray *array; + unsigned count; + unsigned index,i; + id obj; + + NSDebugLLog(@"STCompiler-misc",@" compile expression"); + + if([expr isPrimary]) + { + [self compilePrimary:[expr object]]; + } + else /* message expression */ + { + obj = [expr target]; + + /* target */ + if([obj isKindOfClass:[STCPrimary class]]) + [self compilePrimary:obj]; + else + [self compileExpression:obj]; + + cascade = [expr cascade]; + if(cascade) + { + count = [cascade count]; + for(i=0;i0) + { + for(i = 0; i +#import +#import +#import + +@class STCMessage; +@class STCStatements; +@class STCExpression; + +enum{ + STCVariablePrimaryType, + STCLiteralPrimaryType, + STCBlockPrimaryType, + STCExpressionPrimaryType +}; + +@interface STCompiler(Utils_private) +- (STCompiledMethod *)compileMethod:(STCMethod *)method; +- (id)createNumberLiteralFrom:(NSString *)aString; +- (id)createSymbolLiteralFrom:(NSString *)aString; +- (id)createStringLiteralFrom:(NSString *)aString; +- (id)createCharacterLiteralFrom:(NSString *)aString; +- (id)createArrayLiteralFrom:(NSArray *)anArray; +@end + +/* + * STCMethod + * --------------------------------------------------------------------------- + */ + +@interface STCMethod:NSObject +{ + STCMessage *messagePattern; + STCStatements *statements; +} ++ methodWithPattern:(STCMessage *)patt statements:(STCStatements *)stats; +- initWithPattern:(STCMessage *)patt statements:(STCStatements *)stats; +- (STCStatements *)statements; +- (STCMessage *)messagePattern; +@end + +/* + * STCStatements + * --------------------------------------------------------------------------- + */ +@interface STCStatements:NSObject +{ + NSArray *variables; + NSArray *expressions; + STCExpression *retexpr; +} ++ statements; + +- (void)setTemporaries:(NSArray *)vars; +- (NSArray *)temporaries; + +- (void)setExpressions:(NSArray *)exprs; +- (NSArray *)expressions; + +- (void)setReturnExpression:(STCExpression *)ret; +- (STCExpression *)returnExpression; +@end + + +/* + * STCMessage + * --------------------------------------------------------------------------- + */ + +@interface STCMessage:NSObject +{ + NSMutableString *selector; + NSMutableArray *args; +} ++ message; +- (void) addKeyword:(NSString *)keyword object:object; +- (NSString *)selector; +- (NSArray*)args; +@end + + +/* + * STCExpression + * --------------------------------------------------------------------------- + */ + +@interface STCExpression:NSObject +{ + NSArray *cascade; + NSArray *assignments; +} ++ (STCExpression *) primaryExpressionWithObject:(id)anObject; ++ (STCExpression *) messageExpressionWithTarget:(id)anObject + message:(STCMessage *)message; +- (void)setCascade:(NSArray *)casc; +- (void)setAssignments:(NSArray *)asgs; + +- (NSArray *)cascade; +- (NSArray *)assignments; +- (BOOL) isPrimary; + +- (id) target; +- (STCMessage *)message; +- (id) object; +@end + +@interface STCMessageExpression:STCExpression +{ + id target; + STCMessage *message; +} +- initWithTarget:(id)anObject message:(STCMessage *)message; +@end + +@interface STCPrimaryExpression:STCExpression +{ + id object; +} +- initWithObject:(id)anObject; +@end + +/* + * STCPrimary + * --------------------------------------------------------------------------- + */ +@interface STCPrimary:NSObject +{ + int type; + id object; +} ++ primaryWithVariable:(id)anObject; ++ primaryWithLiteral:(id)anObject; ++ primaryWithBlock:(id)anObject; ++ primaryWithExpression:(id)anObject; +- initWithType:(int)newType object:(id)obj; +- (int)type; +- object; +@end + + +/* + * Compiler additions for literals + * --------------------------------------------------------------------------- + */ + +@interface NSString(STCompilerAdditions) ++ (NSString *) symbolFromString:(NSString *)aString; ++ (id) characterFromString:(NSString *)aString; +@end + +@interface NSMutableString(STCompilerAdditions) ++ (id) stringFromString:(NSString *)aString; +@end + +@interface NSNumber(STCompilerAdditions) ++ (id) numberFromString:(NSString *)aString; +@end + +@interface NSMutableArray(STCompilerAdditions) ++ (id) arrayFromArray:(NSArray *)anArray; +@end diff --git a/Languages/Smalltalk/STCompilerUtils.m b/Languages/Smalltalk/STCompilerUtils.m new file mode 100644 index 0000000..faae899 --- /dev/null +++ b/Languages/Smalltalk/STCompilerUtils.m @@ -0,0 +1,366 @@ +/** + STCompilerUtils.m + Various compiler utilities. + + Copyright (c) 2002 Free Software Foundation + + This file is part of StepTalk. + + */ + +#import "STCompiler.h" + +#import "STCompilerUtils.h" +#import "STGrammar.m.h" +#import "STSourceReader.h" + +#import + +#import +#import +#import +#import +#import + +/* + * Compiler utilities + * -------------------------------------------------------------------------- + */ + +/* + * STCMethod + * --------------------------------------------------------------------------- + */ + + + +@implementation STCMethod ++ methodWithPattern:(STCMessage *)patt statements:(STCStatements *)stats +{ + STCMethod *method; + method = [[STCMethod alloc] initWithPattern:patt statements:stats]; + return AUTORELEASE(method); +} +- initWithPattern:(STCMessage *)patt statements:(STCStatements *)stats +{ + [super init]; + messagePattern = RETAIN(patt); + statements = RETAIN(stats); + return self; +} +- (void)dealloc +{ + RELEASE(messagePattern); + RELEASE(statements); + [super dealloc]; +} +- (STCStatements *)statements +{ + return statements; +} + +- (STCMessage *)messagePattern +{ + return messagePattern; +} +@end + +/* + * STCStatements + * --------------------------------------------------------------------------- + */ +@implementation STCStatements ++ statements +{ + STCStatements *statements = [[STCStatements alloc] init]; + return AUTORELEASE(statements); +} +- (void)setTemporaries:(NSArray *)vars +{ + ASSIGN(variables,vars); +} +- (void)setExpressions:(NSArray *)exprs +{ + ASSIGN(expressions,exprs); +} +- (void)setReturnExpression:(STCExpression *)ret +{ + ASSIGN(retexpr,ret); +} +- (void)dealloc +{ + RELEASE(variables); + RELEASE(expressions); + RELEASE(retexpr); + [super dealloc]; +} +- (NSArray *)temporaries +{ + return variables; +} +- (NSArray *)expressions +{ + return expressions; +} +- (STCExpression *)returnExpression +{ + return retexpr; +} +@end + +/* + * STCMessage + * --------------------------------------------------------------------------- + */ + +@implementation STCMessage ++ message +{ + STCMessage *message = [[STCMessage alloc] init]; + return AUTORELEASE(message); +} +- init +{ + [super init]; + + selector = [[NSMutableString alloc] init]; + args = [[NSMutableArray alloc] init]; + + return self; +} +- (void)dealloc +{ + RELEASE(selector); + RELEASE(args); + [super dealloc]; +} +-(void) addKeyword:(NSString *)keyword object:object +{ + [selector appendString:keyword]; + if(object!=nil) + [args addObject:object]; +} +- (NSString *)selector +{ + return selector; +} +- (NSArray *)arguments +{ + return args; +} +@end + +/* + * STCExpression + * --------------------------------------------------------------------------- + */ +@implementation STCExpression:NSObject ++ (STCExpression *) primaryExpressionWithObject:(id)anObject +{ + STCPrimaryExpression *expr; + expr = [[STCPrimaryExpression alloc] initWithObject:anObject]; + return AUTORELEASE(expr); +} + ++ (STCExpression *) messageExpressionWithTarget:(id)anObject + message:(STCMessage *)message +{ + STCMessageExpression *expr; + expr = [[STCMessageExpression alloc] initWithTarget:anObject + message:message]; + return AUTORELEASE(expr); +} + +- (void)dealloc +{ + RELEASE(cascade); + RELEASE(assignments); + [super dealloc]; +} +- (void)setCascade:(NSArray *)casc +{ + ASSIGN(cascade,casc); +} +- (void)setAssignments:(NSArray *)asgs +{ + ASSIGN(assignments,asgs); +} +- (NSArray *)cascade +{ + return cascade; +} +- (NSArray *)assignments +{ + return assignments; +} +- (BOOL)isPrimary +{ + [self subclassResponsibility]; + return NO; +} +- (id) target +{ + [self subclassResponsibility]; + return nil; +} +- (STCMessage *)message +{ + [self subclassResponsibility]; + return nil; +} +- (id) object +{ + [self subclassResponsibility]; + return nil; +} + +@end + +@implementation STCMessageExpression:STCExpression +- initWithTarget:(id)anObject message:(STCMessage *)aMessage; +{ + [super init]; + + target = RETAIN(anObject); + message = RETAIN(aMessage); + + return self; +} +- (void)dealloc +{ + RELEASE(target); + RELEASE(message); + [super dealloc]; +} +- (id) target +{ + return target; +} +- (STCMessage *)message +{ + return message; +} +- (BOOL)isPrimary +{ + return NO; +} +@end + +@implementation STCPrimaryExpression:STCExpression +{ + id object; +} +- (void)dealloc +{ + RELEASE(object); + [super dealloc]; +} +- initWithObject:(id)anObject +{ + [super init]; + object = RETAIN(anObject); + return self; +} + +- (id) object +{ + return object; +} +- (BOOL)isPrimary +{ + return YES; +} +@end + +/* + * STCPrimary + * --------------------------------------------------------------------------- + */ +@implementation STCPrimary ++ primaryWithVariable:(id) anObject +{ + STCPrimary *primary; + primary = [STCPrimary alloc]; + [primary initWithType:STCVariablePrimaryType object:anObject]; + return AUTORELEASE(primary); +} ++ primaryWithLiteral:(id) anObject +{ + STCPrimary *primary; + primary = [STCPrimary alloc]; + [primary initWithType:STCLiteralPrimaryType object:anObject]; + return AUTORELEASE(primary); +} ++ primaryWithBlock:(id) anObject +{ + STCPrimary *primary; + primary = [STCPrimary alloc]; + [primary initWithType:STCBlockPrimaryType object:anObject]; + return AUTORELEASE(primary); +} ++ primaryWithExpression:(id) anObject +{ + STCPrimary *primary; + primary = [STCPrimary alloc]; + [primary initWithType:STCExpressionPrimaryType object:anObject]; + return AUTORELEASE(primary); +} +- initWithType:(int)newType object:obj +{ + type = newType; + object = RETAIN(obj); + return [super init]; +} +- (void)dealloc +{ + RELEASE(object); + [super dealloc]; +} +- (int)type +{ + return type; +} +- object +{ + return object; +} +@end + + +/* + * Compiler additions for literals + * --------------------------------------------------------------------------- + */ + +@implementation NSString(STCompilerAdditions) ++ (NSString *) symbolFromString:(NSString *)aString +{ + return [self stringWithString:aString]; +} ++ (id) characterFromString:(NSString *)aString +{ + return [self stringWithString:aString]; +} +@end + +@implementation NSMutableString(STCompilerAdditions) ++ (id) stringFromString:(NSString *)aString +{ + return [self stringWithString:aString]; +} +@end + +@implementation NSNumber(STCompilerAdditions) ++ (id) numberFromString:(NSString *)aString +{ + /* FIXME: handle all formats */ + return [self numberWithInt:[aString intValue]]; +} +@end + +@implementation NSMutableArray(STCompilerAdditions) ++ (id) arrayFromArray:(NSArray *)anArray +{ + return [self arrayWithArray:anArray]; +} +@end diff --git a/Languages/Smalltalk/STExecutionContext.h b/Languages/Smalltalk/STExecutionContext.h new file mode 100644 index 0000000..fa37d6a --- /dev/null +++ b/Languages/Smalltalk/STExecutionContext.h @@ -0,0 +1,64 @@ +/** + STExecutionContext.h + + 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 + +@class STStack; +@class STBytecodes; +@class STMethodContext; + +@interface STExecutionContext:NSObject +{ + unsigned contextId; /* for debugging */ + + STExecutionContext *parrentContext; /* for return */ + STStack *stack; + + unsigned instructionPointer; +} +- initWithStackSize:(unsigned)stackSize; + +- (void)invalidate; +- (BOOL)isInvalid; + +- (STExecutionContext *)parrentContext; +- (void)setParrentContext:(STExecutionContext *)context; + +- (STMethodContext *)homeContext; +- (void)setHomeContext:(STMethodContext *)context; + +- (BOOL)isBlockContext; + +- (unsigned)instructionPointer; +- (void)setInstructionPointer:(unsigned)value; + +- (STBytecodes *)bytecodes; + +- (STStack *)stack; + +- (id)temporaryAtIndex:(unsigned)index; +- (void)setTemporary:anObject atIndex:(unsigned)index; +- (id)externAtIndex:(unsigned)index; +- (void)setExtern:anObject atIndex:(unsigned)index; +- (id)literalObjectAtIndex:(unsigned)index; +@end diff --git a/Languages/Smalltalk/STExecutionContext.m b/Languages/Smalltalk/STExecutionContext.m new file mode 100644 index 0000000..1db46d6 --- /dev/null +++ b/Languages/Smalltalk/STExecutionContext.m @@ -0,0 +1,124 @@ +/** + STExecutionContext.m + + Copyright (c) 2002 Free Software Foundation + + This file is part of the StepTalk project. + + */ + +#import "STExecutionContext.h" + +#import "STStack.h" + +#import +#import +#import + +static unsigned nextId = 1; + +@implementation STExecutionContext +- initWithStackSize:(unsigned)stackSize +{ + stack = [[STStack alloc] initWithSize:stackSize]; + + contextId = nextId ++; + + return [super init]; +} +- (void)dealloc +{ + RELEASE(stack); + RELEASE(parrentContext); + [super dealloc]; +} +- (unsigned)contextId +{ + return contextId; +} +- (NSString *)description +{ + NSMutableString *str; + str = [NSMutableString stringWithFormat: + @"%s[%i]{p:%i h:%i}", + [self name], + contextId, + [parrentContext contextId], + [[self homeContext] contextId]]; + return str; +} +- (void)invalidate +{ + [self subclassResponsibility]; +} + +- (BOOL)isInvalid +{ + [self subclassResponsibility]; + return YES; +} + +- (STExecutionContext *)parrentContext +{ + return parrentContext; +} +- (void)setParrentContext:(STExecutionContext *)context +{ + ASSIGN(parrentContext,context); +} +- (unsigned)instructionPointer +{ + return instructionPointer; +} +- (void)setInstructionPointer:(unsigned)value +{ + instructionPointer = value; +} +- (STMethodContext *)homeContext +{ + [self subclassResponsibility]; + return nil; +} +- (void)setHomeContext:(STMethodContext *)newContext +{ + [self subclassResponsibility]; +} + +- (STStack *)stack +{ + return stack; +} +- (BOOL)isBlockContext; +{ + [self subclassResponsibility]; + return NO; +} +- (id)temporaryAtIndex:(unsigned)index +{ + [self subclassResponsibility]; + return nil; +} +- (void)setTemporary:anObject atIndex:(unsigned)index +{ + [self subclassResponsibility]; +} +- (id)externAtIndex:(unsigned)index +{ + [self subclassResponsibility]; + return nil; +} +- (void)setExtern:anObject atIndex:(unsigned)index +{ + [self subclassResponsibility]; +} +- (STBytecodes *)bytecodes +{ + [self subclassResponsibility]; + return nil; +} +- (id)literalObjectAtIndex:(unsigned)index +{ + [self subclassResponsibility]; + return nil; +} +@end diff --git a/Languages/Smalltalk/STGrammar.m b/Languages/Smalltalk/STGrammar.m new file mode 100644 index 0000000..d1f2b9d --- /dev/null +++ b/Languages/Smalltalk/STGrammar.m @@ -0,0 +1,1437 @@ + +/* A Bison parser, made from STGrammar.y + by GNU Bison version 1.25 + */ + +#define YYBISON 1 /* Identify Bison output. */ + +#define yyparse STCparse +#define yylex STClex +#define yyerror STCerror +#define yylval STClval +#define yychar STCchar +#define yydebug STCdebug +#define yynerrs STCnerrs +#define TK_SEPARATOR 258 +#define TK_BAR 259 +#define TK_ASSIGNMENT 260 +#define TK_LPAREN 261 +#define TK_RPAREN 262 +#define TK_BLOCK_OPEN 263 +#define TK_BLOCK_CLOSE 264 +#define TK_ARRAY_OPEN 265 +#define TK_DOT 266 +#define TK_COLON 267 +#define TK_SEMICOLON 268 +#define TK_RETURN 269 +#define TK_IDENTIFIER 270 +#define TK_BINARY_SELECTOR 271 +#define TK_KEYWORD 272 +#define TK_NUMBER 273 +#define TK_SYMBOL 274 +#define TK_STRING 275 +#define TK_CHARACTER 276 + +#line 25 "STGrammar.y" + + + #define YYSTYPE id + #define YYLTYPE int + #undef YYDEBUG + + #import + #import "STCompiler.h" + #import "STCompilerUtils.h" + #import "STSourceReader.h" + + #import + + +/* extern int STCerror(const char *str); + extern int STClex (YYSTYPE *lvalp, void *context); +*/ + #define YYPARSE_PARAM context + #define YYLEX_PARAM context + #define YYERROR_VERBOSE + + #define CONTEXT ((STParserContext *)context) + #define COMPILER (CONTEXT->compiler) + #define READER (CONTEXT->reader) + #define RESULT (CONTEXT->result) + +#ifndef YYSTYPE +#define YYSTYPE int +#endif +#include + +#ifndef __cplusplus +#ifndef __STDC__ +#define const +#endif +#endif + + + +#define YYFINAL 115 +#define YYFLAG -32768 +#define YYNTBASE 22 + +#define YYTRANSLATE(x) ((unsigned)(x) <= 276 ? yytranslate[x] : 57) + +static const char yytranslate[] = { 0, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 1, 2, 3, 4, 5, + 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21 +}; + +#if YYDEBUG != 0 +static const short yyprhs[] = { 0, + 0, 1, 3, 8, 10, 13, 14, 18, 20, 22, + 26, 29, 33, 35, 38, 40, 43, 47, 51, 53, + 56, 59, 63, 69, 72, 76, 79, 81, 84, 89, + 91, 95, 97, 100, 102, 105, 107, 110, 112, 115, + 118, 121, 124, 128, 130, 133, 135, 137, 139, 141, + 144, 148, 151, 154, 158, 160, 162, 164, 166, 168, + 170, 172, 176, 178, 180, 182, 184, 186, 188, 190, + 192, 196, 198, 200, 203, 206, 208, 210 +}; + +static const short yyrhs[] = { -1, + 23, 0, 8, 4, 24, 9, 0, 34, 0, 30, + 34, 0, 0, 33, 25, 26, 0, 26, 0, 27, + 0, 26, 3, 27, 0, 28, 34, 0, 28, 30, + 34, 0, 51, 0, 52, 50, 0, 29, 0, 53, + 50, 0, 29, 53, 50, 0, 4, 31, 4, 0, + 50, 0, 31, 50, 0, 8, 9, 0, 8, 34, + 9, 0, 8, 33, 4, 34, 9, 0, 12, 50, + 0, 33, 12, 50, 0, 14, 36, 0, 35, 0, + 35, 11, 0, 35, 11, 14, 36, 0, 36, 0, + 35, 11, 36, 0, 49, 0, 37, 49, 0, 42, + 0, 37, 42, 0, 39, 0, 37, 39, 0, 38, + 0, 37, 38, 0, 50, 5, 0, 42, 40, 0, + 13, 41, 0, 40, 13, 41, 0, 51, 0, 52, + 47, 0, 46, 0, 43, 0, 44, 0, 45, 0, + 47, 51, 0, 48, 52, 47, 0, 48, 46, 0, + 53, 48, 0, 46, 53, 48, 0, 49, 0, 43, + 0, 47, 0, 44, 0, 50, 0, 54, 0, 32, + 0, 6, 36, 7, 0, 15, 0, 15, 0, 16, + 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, + 0, 10, 55, 7, 0, 54, 0, 56, 0, 55, + 54, 0, 55, 56, 0, 15, 0, 52, 0, 17, + 0 +}; + +#endif + +#if YYDEBUG != 0 +static const short yyrline[] = { 0, + 66, 71, 75, 81, 86, 94, 101, 101, 104, 108, + 114, 119, 127, 133, 138, 141, 146, 153, 157, 162, + 169, 173, 177, 183, 188, 194, 200, 206, 211, 219, + 225, 231, 236, 242, 243, 248, 249, 255, 260, 267, + 270, 276, 281, 287, 292, 297, 300, 301, 302, 304, + 313, 322, 328, 333, 339, 340, 342, 343, 345, 349, + 353, 357, 362, 364, 366, 368, 370, 372, 374, 376, + 378, 381, 383, 385, 386, 388, 390, 392 +}; +#endif + + +#if YYDEBUG != 0 || defined (YYERROR_VERBOSE) + +static const char * const yytname[] = { "$","error","$undefined.","TK_SEPARATOR", +"TK_BAR","TK_ASSIGNMENT","TK_LPAREN","TK_RPAREN","TK_BLOCK_OPEN","TK_BLOCK_CLOSE", +"TK_ARRAY_OPEN","TK_DOT","TK_COLON","TK_SEMICOLON","TK_RETURN","TK_IDENTIFIER", +"TK_BINARY_SELECTOR","TK_KEYWORD","TK_NUMBER","TK_SYMBOL","TK_STRING","TK_CHARACTER", +"source","single_method","methods","@1","method_list","method","message_pattern", +"keyword_list","temporaries","variable_list","block","block_var_list","statements", +"expressions","expression","assignments","assignment","cascade","cascade_list", +"cascade_item","message_expression","unary_expression","binary_expression","keyword_expression", +"keyword_expr_list","unary_object","binary_object","primary","variable_name", +"unary_selector","binary_selector","keyword","literal","array","symbol", NULL +}; +#endif + +static const short yyr1[] = { 0, + 22, 22, 22, 23, 23, 25, 24, 24, 26, 26, + 27, 27, 28, 28, 28, 29, 29, 30, 31, 31, + 32, 32, 32, 33, 33, 34, 34, 34, 34, 35, + 35, 36, 36, 36, 36, 36, 36, 37, 37, 38, + 39, 40, 40, 41, 41, 41, 42, 42, 42, 43, + 44, 45, 46, 46, 47, 47, 48, 48, 49, 49, + 49, 49, 50, 51, 52, 53, 54, 54, 54, 54, + 54, 55, 55, 55, 55, 56, 56, 56 +}; + +static const short yyr2[] = { 0, + 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, + 3, 1, 1, 2, 2, 1, 1, 1 +}; + +static const short yydefact[] = { 1, + 0, 0, 0, 0, 0, 63, 67, 68, 69, 70, + 2, 0, 61, 4, 27, 30, 0, 38, 36, 34, + 47, 48, 49, 57, 0, 32, 59, 60, 0, 19, + 0, 0, 0, 21, 0, 0, 0, 76, 65, 78, + 77, 72, 0, 73, 26, 5, 28, 39, 37, 35, + 33, 0, 41, 64, 50, 66, 52, 0, 0, 40, + 18, 20, 62, 0, 8, 9, 0, 15, 6, 13, + 0, 0, 24, 0, 0, 22, 71, 74, 75, 0, + 31, 42, 46, 44, 0, 0, 0, 56, 51, 55, + 59, 58, 53, 3, 0, 0, 11, 0, 0, 14, + 16, 0, 25, 29, 45, 43, 54, 10, 12, 17, + 7, 23, 0, 0, 0 +}; + +static const short yydefgoto[] = { 113, + 11, 64, 99, 65, 66, 67, 68, 12, 29, 13, + 36, 37, 15, 16, 17, 18, 19, 53, 82, 20, + 21, 22, 23, 83, 24, 25, 26, 27, 55, 58, + 59, 28, 43, 44 +}; + +static const short yypact[] = { 46, + 11, 177, 95, 3, 177,-32768,-32768,-32768,-32768,-32768, +-32768, 145,-32768,-32768, -4,-32768, 177,-32768,-32768, 4, + 109, 15,-32768, 14, 78, 141, 7,-32768, 64,-32768, + 129, 9, 194,-32768, 11, 29, 27,-32768,-32768,-32768, +-32768,-32768, 184,-32768,-32768,-32768, 161,-32768,-32768, 4, + 141, 157, 32,-32768,-32768,-32768, 36, 177, 177,-32768, +-32768,-32768,-32768, 50, 52,-32768, 113, 36, 51,-32768, + 11, 11,-32768, 145, 11,-32768,-32768,-32768,-32768, 177, +-32768,-32768, 36,-32768, 177, 157, 177,-32768, 14,-32768, +-32768,-32768, 56,-32768, 157, 145,-32768, 11, 157,-32768, +-32768, 71,-32768,-32768, 14,-32768, 56,-32768,-32768,-32768, + 52,-32768, 82, 85,-32768 +}; + +static const short yypgoto[] = {-32768, +-32768,-32768,-32768, -11, -5,-32768,-32768, 33,-32768,-32768, + 69, 2,-32768, 1,-32768, 89, 91,-32768, 25, 101, + -50, -49,-32768, 87, -43, -48, -12, -1, -8, -3, + -6, 0,-32768, 77 +}; + + +#define YYLAST 211 + + +static const short yytable[] = { 30, + 41, 14, 32, 42, 51, 45, 47, 88, 88, 92, + 93, 60, 4, 46, 89, 63, 52, 38, 39, 40, + 7, 8, 9, 10, 70, 6, 72, 62, 54, 71, + -58, -58, 74, 73, 88, 76, 88, 92, 107, 41, + 75, 105, 78, 84, 86, 90, 90, 81, 85, 1, + 87, 2, 56, 3, 95, 4, 91, 91, 94, 5, + 6, 98, 75, 7, 8, 9, 10, 61, 97, 100, + 101, 39, 90, 103, 90, 102, 87, 84, 6, 112, + 104, 114, 85, 91, 115, 91, 70, 111, 72, 108, + 70, 71, 72, 39, 56, 71, 110, 109, 33, 96, + 2, 69, 31, 34, 4, 48, 35, 49, 5, 6, + 106, 57, 7, 8, 9, 10, 1, 50, 2, 79, + 31, 0, 4, -56, -56, -56, 5, 6, 0, 0, + 7, 8, 9, 10, 2, 0, 31, 34, 4, 0, + 35, 0, 5, 6, 0, 0, 7, 8, 9, 10, + 2, 0, 31, 0, 4, -55, -55, -55, 5, 6, + 0, 0, 7, 8, 9, 10, 2, 0, 31, 0, + 4, 54, 39, 56, 80, 6, 0, 0, 7, 8, + 9, 10, 2, 0, 31, 0, 4, 0, 0, 0, + 77, 6, 0, 4, 7, 8, 9, 10, 38, 39, + 40, 7, 8, 9, 10, 35, 0, 0, 54, 39, + 56 +}; + +static const short yycheck[] = { 1, + 4, 0, 2, 4, 17, 5, 11, 58, 59, 59, + 59, 5, 10, 12, 58, 7, 13, 15, 16, 17, + 18, 19, 20, 21, 33, 15, 33, 29, 15, 33, + 16, 17, 4, 35, 85, 9, 87, 87, 87, 43, + 12, 85, 43, 52, 13, 58, 59, 47, 52, 4, + 57, 6, 17, 8, 3, 10, 58, 59, 9, 14, + 15, 68, 12, 18, 19, 20, 21, 4, 67, 71, + 72, 16, 85, 75, 87, 74, 83, 86, 15, 9, + 80, 0, 86, 85, 0, 87, 95, 99, 95, 95, + 99, 95, 99, 16, 17, 99, 98, 96, 4, 67, + 6, 33, 8, 9, 10, 17, 12, 17, 14, 15, + 86, 25, 18, 19, 20, 21, 4, 17, 6, 43, + 8, -1, 10, 15, 16, 17, 14, 15, -1, -1, + 18, 19, 20, 21, 6, -1, 8, 9, 10, -1, + 12, -1, 14, 15, -1, -1, 18, 19, 20, 21, + 6, -1, 8, -1, 10, 15, 16, 17, 14, 15, + -1, -1, 18, 19, 20, 21, 6, -1, 8, -1, + 10, 15, 16, 17, 14, 15, -1, -1, 18, 19, + 20, 21, 6, -1, 8, -1, 10, -1, -1, -1, + 7, 15, -1, 10, 18, 19, 20, 21, 15, 16, + 17, 18, 19, 20, 21, 12, -1, -1, 15, 16, + 17 +}; +#define YYPURE 1 + +/* -*-C-*- Note some compilers choke on comments on `#line' lines. */ +#line 3 "/usr/local/share/bison.simple" + +/* Skeleton output parser for bison, + Copyright (c) 2002 Free Software Foundation + + 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, 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 02139, USA. */ + +/* As a special exception, when this file is copied by Bison into a + Bison output file, you may use that output file without restriction. + This special exception was added by the Free Software Foundation + in version 1.24 of Bison. */ + +#ifndef alloca +#ifdef __GNUC__ +#define alloca __builtin_alloca +#else /* not GNU C. */ +#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) +#include +#else /* not sparc */ +#if defined (MSDOS) && !defined (__TURBOC__) +#include +#else /* not MSDOS, or __TURBOC__ */ +#if defined(_AIX) +#include + #pragma alloca +#else /* not MSDOS, __TURBOC__, or _AIX */ +#ifdef __hpux +#ifdef __cplusplus +extern "C" { +void *alloca (unsigned int); +}; +#else /* not __cplusplus */ +void *alloca (); +#endif /* not __cplusplus */ +#endif /* __hpux */ +#endif /* not _AIX */ +#endif /* not MSDOS, or __TURBOC__ */ +#endif /* not sparc. */ +#endif /* not GNU C. */ +#endif /* alloca not defined. */ + +/* This is the parser code that is written into each bison parser + when the %semantic_parser declaration is not specified in the grammar. + It was written by Richard Stallman by simplifying the hairy parser + used when %semantic_parser is specified. */ + +/* Note: there must be only one dollar sign in this file. + It is replaced by the list of actions, each action + as one case of the switch. */ + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY -2 +#define YYEOF 0 +#define YYACCEPT return(0) +#define YYABORT return(1) +#define YYERROR goto yyerrlab1 +/* Like YYERROR except do call yyerror. + This remains here temporarily to ease the + transition to the new meaning of YYERROR, for GCC. + Once GCC version 2 has supplanted version 1, this can go. */ +#define YYFAIL goto yyerrlab +#define YYRECOVERING() (!!yyerrstatus) +#define YYBACKUP() \ +do \ + if (yychar == YYEMPTY && yylen == 1) \ + { yychar = (token), yylval = (value); \ + yychar1 = YYTRANSLATE (yychar); \ + YYPOPSTACK; \ + goto yybackup; \ + } \ + else \ + { yyerror ("syntax error: cannot back up"); YYERROR; } \ +while (0) + +#define YYTERROR 1 +#define YYERRCODE 256 + +#ifndef YYPURE +#define YYLEX yylex() +#endif + +#ifdef YYPURE +#ifdef YYLSP_NEEDED +#ifdef YYLEX_PARAM +#define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM) +#else +#define YYLEX yylex(&yylval, &yylloc) +#endif +#else /* not YYLSP_NEEDED */ +#ifdef YYLEX_PARAM +#define YYLEX yylex(&yylval, YYLEX_PARAM) +#else +#define YYLEX yylex(&yylval) +#endif +#endif /* not YYLSP_NEEDED */ +#endif + +/* If nonreentrant, generate the variables here */ + +#ifndef YYPURE + +int yychar; /* the lookahead symbol */ +YYSTYPE yylval; /* the semantic value of the */ + /* lookahead symbol */ + +#ifdef YYLSP_NEEDED +YYLTYPE yylloc; /* location data for the lookahead */ + /* symbol */ +#endif + +int yynerrs; /* number of parse errors so far */ +#endif /* not YYPURE */ + +#if YYDEBUG != 0 +int yydebug; /* nonzero means print parse trace */ +/* Since this is uninitialized, it does not stop multiple parsers + from coexisting. */ +#endif + +/* YYINITDEPTH indicates the initial size of the parser's stacks */ + +#ifndef YYINITDEPTH +#define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH is the maximum size the stacks can grow to + (effective only if the built-in stack extension method is used). */ + +#if YYMAXDEPTH == 0 +#undef YYMAXDEPTH +#endif + +#ifndef YYMAXDEPTH +#define YYMAXDEPTH 10000 +#endif + +/* Prevent warning if -Wstrict-prototypes. */ +#ifdef __GNUC__ +/*int yyparse ();*/ +#endif + +#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */ +#define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT) +#else /* not GNU C or C++ */ +#ifndef __cplusplus + +/* This is the most reliable way to avoid incompatibilities + in available built-in functions on various systems. */ +static void +__yy_memcpy (to, from, count) + char *to; + char *from; + int count; +{ + register char *f = from; + register char *t = to; + register int i = count; + + while (i-- > 0) + *t++ = *f++; +} + +#else /* __cplusplus */ + +/* This is the most reliable way to avoid incompatibilities + in available built-in functions on various systems. */ +static void +__yy_memcpy (char *to, char *from, int count) +{ + register char *f = from; + register char *t = to; + register int i = count; + + while (i-- > 0) + *t++ = *f++; +} + +#endif +#endif + +#line 196 "/usr/local/share/bison.simple" + +/* The user can define YYPARSE_PARAM as the name of an argument to be passed + into yyparse. The argument should have type void *. + It should actually point to an object. + Grammar actions can access the variable by casting it + to the proper pointer type. */ + +typedef void *VOIDP; +#ifdef YYPARSE_PARAM +#ifdef __cplusplus +#define YYPARSE_PARAM_ARG void *YYPARSE_PARAM +#define YYPARSE_PARAM_DECL +#else /* not __cplusplus */ +#define YYPARSE_PARAM_ARG YYPARSE_PARAM +#define YYPARSE_PARAM_DECL VOIDP YYPARSE_PARAM; +#endif /* not __cplusplus */ +#else /* not YYPARSE_PARAM */ +#define YYPARSE_PARAM_ARG +#define YYPARSE_PARAM_DECL +#endif /* not YYPARSE_PARAM */ + +int +yyparse(YYPARSE_PARAM_ARG) + YYPARSE_PARAM_DECL +{ + register int yystate; + register int yyn; + register short *yyssp; + register YYSTYPE *yyvsp; + int yyerrstatus; /* number of tokens to shift before error messages enabled */ + int yychar1 = 0; /* lookahead token as an internal (translated) token number */ + + short yyssa[YYINITDEPTH]; /* the state stack */ + YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */ + + short *yyss = yyssa; /* refer to the stacks thru separate pointers */ + YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */ + +#ifdef YYLSP_NEEDED + YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */ + YYLTYPE *yyls = yylsa; + YYLTYPE *yylsp; + +#define YYPOPSTACK (yyvsp--, yyssp--, yylsp--) +#else +#define YYPOPSTACK (yyvsp--, yyssp--) +#endif + + int yystacksize = YYINITDEPTH; + +#ifdef YYPURE + int yychar; + YYSTYPE yylval; + int yynerrs; +#ifdef YYLSP_NEEDED + YYLTYPE yylloc; +#endif +#endif + + YYSTYPE yyval; /* the variable used to return */ + /* semantic values from the action */ + /* routines */ + + int yylen; + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Starting parse\n"); +#endif + + yystate = 0; + yyerrstatus = 0; + yynerrs = 0; + yychar = YYEMPTY; /* Cause a token to be read. */ + + /* Initialize stack pointers. + Waste one element of value and location stack + so that they stay on the same level as the state stack. + The wasted elements are never initialized. */ + + yyssp = yyss - 1; + yyvsp = yyvs; +#ifdef YYLSP_NEEDED + yylsp = yyls; +#endif + +/* Push a new state, which is found in yystate . */ +/* In all cases, when you get here, the value and location stacks + have just been pushed. so pushing a state here evens the stacks. */ +yynewstate: + + *++yyssp = yystate; + + if (yyssp >= yyss + yystacksize - 1) + { + /* Give user a chance to reallocate the stack */ + /* Use copies of these so that the &'s don't force the real ones into memory. */ + YYSTYPE *yyvs1 = yyvs; + short *yyss1 = yyss; +#ifdef YYLSP_NEEDED + YYLTYPE *yyls1 = yyls; +#endif + + /* Get the current used size of the three stacks, in elements. */ + int size = yyssp - yyss + 1; + +#ifdef yyoverflow + /* Each stack pointer address is followed by the size of + the data in use in that stack, in bytes. */ +#ifdef YYLSP_NEEDED + /* This used to be a conditional around just the two extra args, + but that might be undefined if yyoverflow is a macro. */ + yyoverflow("parser stack overflow", + &yyss1, size * sizeof (*yyssp), + &yyvs1, size * sizeof (*yyvsp), + &yyls1, size * sizeof (*yylsp), + &yystacksize); +#else + yyoverflow("parser stack overflow", + &yyss1, size * sizeof (*yyssp), + &yyvs1, size * sizeof (*yyvsp), + &yystacksize); +#endif + + yyss = yyss1; yyvs = yyvs1; +#ifdef YYLSP_NEEDED + yyls = yyls1; +#endif +#else /* no yyoverflow */ + /* Extend the stack our own way. */ + if (yystacksize >= YYMAXDEPTH) + { + yyerror("parser stack overflow"); + return 2; + } + yystacksize *= 2; + if (yystacksize > YYMAXDEPTH) + yystacksize = YYMAXDEPTH; + yyss = (short *) alloca (yystacksize * sizeof (*yyssp)); + __yy_memcpy ((char *)yyss, (char *)yyss1, size * sizeof (*yyssp)); + yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp)); + __yy_memcpy ((char *)yyvs, (char *)yyvs1, size * sizeof (*yyvsp)); +#ifdef YYLSP_NEEDED + yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp)); + __yy_memcpy ((char *)yyls, (char *)yyls1, size * sizeof (*yylsp)); +#endif +#endif /* no yyoverflow */ + + yyssp = yyss + size - 1; + yyvsp = yyvs + size - 1; +#ifdef YYLSP_NEEDED + yylsp = yyls + size - 1; +#endif + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Stack size increased to %d\n", yystacksize); +#endif + + if (yyssp >= yyss + yystacksize - 1) + YYABORT; + } + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Entering state %d\n", yystate); +#endif + + goto yybackup; + yybackup: + +/* Do appropriate processing given the current state. */ +/* Read a lookahead token if we need one and don't already have one. */ +/* yyresume: */ + + /* First try to decide what to do without reference to lookahead token. */ + + yyn = yypact[yystate]; + if (yyn == YYFLAG) + goto yydefault; + + /* Not known => get a lookahead token if don't already have one. */ + + /* yychar is either YYEMPTY or YYEOF + or a valid token in external form. */ + + if (yychar == YYEMPTY) + { +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Reading a token: "); +#endif + yychar = YYLEX; + } + + /* Convert token to internal form (in yychar1) for indexing tables with */ + + if (yychar <= 0) /* This means end of input. */ + { + yychar1 = 0; + yychar = YYEOF; /* Don't call YYLEX any more */ + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Now at end of input.\n"); +#endif + } + else + { + yychar1 = YYTRANSLATE(yychar); + +#if YYDEBUG != 0 + if (yydebug) + { + fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]); + /* Give the individual parser a way to print the precise meaning + of a token, for further debugging info. */ +#ifdef YYPRINT + YYPRINT (stderr, yychar, yylval); +#endif + fprintf (stderr, ")\n"); + } +#endif + } + + yyn += yychar1; + if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1) + goto yydefault; + + yyn = yytable[yyn]; + + /* yyn is what to do for this token type in this state. + Negative => reduce, -yyn is rule number. + Positive => shift, yyn is new state. + New state is final state => don't bother to shift, + just return success. + 0, or most negative number => error. */ + + if (yyn < 0) + { + if (yyn == YYFLAG) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + else if (yyn == 0) + goto yyerrlab; + + if (yyn == YYFINAL) + YYACCEPT; + + /* Shift the lookahead token. */ + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]); +#endif + + /* Discard the token being shifted unless it is eof. */ + if (yychar != YYEOF) + yychar = YYEMPTY; + + *++yyvsp = yylval; +#ifdef YYLSP_NEEDED + *++yylsp = yylloc; +#endif + + /* count tokens shifted since error; after three, turn off error status. */ + if (yyerrstatus) yyerrstatus--; + + yystate = yyn; + goto yynewstate; + +/* Do the default action for the current state. */ +yydefault: + + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + +/* Do a reduction. yyn is the number of a rule to reduce with. */ +yyreduce: + yylen = yyr2[yyn]; + if (yylen > 0) + yyval = yyvsp[1-yylen]; /* implement default value of the action */ + +#if YYDEBUG != 0 + if (yydebug) + { + int i; + + fprintf (stderr, "Reducing via rule %d (line %d), ", + yyn, yyrline[yyn]); + + /* Print the symbols being reduced, and their result. */ + for (i = yyprhs[yyn]; yyrhs[i] > 0; i++) + fprintf (stderr, "%s ", yytname[yyrhs[i]]); + fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]); + } +#endif + + + switch (yyn) { + +case 1: +#line 66 "STGrammar.y" +{ + [COMPILER compileMethod:nil]; + ; + break;} +case 2: +#line 71 "STGrammar.y" +{ + [COMPILER compileMethod:yyvsp[0]]; + ; + break;} +case 4: +#line 82 "STGrammar.y" +{ + yyval = [STCMethod methodWithPattern:nil + /**/ statements:yyvsp[0]]; + ; + break;} +case 5: +#line 87 "STGrammar.y" +{ + [yyvsp[0] setTemporaries:yyvsp[-1]]; + yyval = [STCMethod methodWithPattern:nil + /**/ statements:yyvsp[0]]; + ; + break;} +case 6: +#line 96 "STGrammar.y" +{ + [COMPILER setReceiverVariables:yyvsp[0]]; + ; + break;} +case 9: +#line 105 "STGrammar.y" +{ + [COMPILER compileMethod:yyvsp[0]]; + ; + break;} +case 10: +#line 109 "STGrammar.y" +{ + [COMPILER compileMethod:yyvsp[0]]; + ; + break;} +case 11: +#line 115 "STGrammar.y" +{ + yyval = [STCMethod methodWithPattern:yyvsp[-1] + /**/ statements:yyvsp[0]]; + ; + break;} +case 12: +#line 120 "STGrammar.y" +{ + [yyvsp[0] setTemporaries:yyvsp[-1]]; + yyval = [STCMethod methodWithPattern:yyvsp[-2] + /**/ statements:yyvsp[0]]; + ; + break;} +case 13: +#line 129 "STGrammar.y" +{ + yyval = [STCMessage message]; + [yyval addKeyword:yyvsp[0] object:nil]; + ; + break;} +case 14: +#line 134 "STGrammar.y" +{ + yyval = [STCMessage message]; + [yyval addKeyword:yyvsp[-1] object:yyvsp[0]]; + ; + break;} +case 16: +#line 142 "STGrammar.y" +{ + yyval = [STCMessage message]; + [yyval addKeyword:yyvsp[-1] object:yyvsp[0]]; + ; + break;} +case 17: +#line 147 "STGrammar.y" +{ + [yyvsp[-2] addKeyword:yyvsp[-1] object:yyvsp[0]]; + yyval = yyvsp[-2]; + ; + break;} +case 18: +#line 154 "STGrammar.y" +{ yyval = yyvsp[-1]; ; + break;} +case 19: +#line 158 "STGrammar.y" +{ + yyval = [NSMutableArray array]; + [yyval addObject:yyvsp[0]]; + ; + break;} +case 20: +#line 163 "STGrammar.y" +{ + yyval = yyvsp[-1]; + [yyval addObject:yyvsp[0]]; + ; + break;} +case 21: +#line 170 "STGrammar.y" +{ + yyval = [STCStatements statements]; + ; + break;} +case 22: +#line 174 "STGrammar.y" +{ + yyval = yyvsp[-1]; + ; + break;} +case 23: +#line 178 "STGrammar.y" +{ + yyval = yyvsp[-1]; + [yyval setTemporaries:yyvsp[-3]]; + ; + break;} +case 24: +#line 184 "STGrammar.y" +{ + yyval = [NSMutableArray array]; + [yyval addObject:yyvsp[0]]; + ; + break;} +case 25: +#line 189 "STGrammar.y" +{ + yyval = yyvsp[-2]; + [yyval addObject:yyvsp[0]]; + ; + break;} +case 26: +#line 196 "STGrammar.y" +{ + yyval = [STCStatements statements]; + [yyval setReturnExpression:yyvsp[0]]; + ; + break;} +case 27: +#line 201 "STGrammar.y" +{ + yyval = [STCStatements statements]; + [yyval setExpressions:yyvsp[0]]; + ; + break;} +case 28: +#line 207 "STGrammar.y" +{ + yyval = [STCStatements statements]; + [yyval setExpressions:yyvsp[-1]]; + ; + break;} +case 29: +#line 212 "STGrammar.y" +{ + yyval = [STCStatements statements]; + [yyval setReturnExpression:yyvsp[0]]; + [yyval setExpressions:yyvsp[-3]]; + ; + break;} +case 30: +#line 220 "STGrammar.y" +{ + yyval = [NSMutableArray array]; + [yyval addObject:yyvsp[0]]; + ; + break;} +case 31: +#line 226 "STGrammar.y" +{ + yyval = yyvsp[-2]; + [yyval addObject:yyvsp[0]]; + ; + break;} +case 32: +#line 232 "STGrammar.y" +{ + yyval = [STCExpression + /**/ primaryExpressionWithObject:yyvsp[0]]; + ; + break;} +case 33: +#line 237 "STGrammar.y" +{ + yyval = [STCExpression + /**/ primaryExpressionWithObject:yyvsp[0]]; + [yyval setAssignments:yyvsp[-1]]; + ; + break;} +case 35: +#line 244 "STGrammar.y" +{ + yyval = yyvsp[0]; + [yyval setAssignments:yyvsp[-1]]; + ; + break;} +case 37: +#line 250 "STGrammar.y" +{ + yyval = yyvsp[0]; + [yyval setAssignments:yyvsp[-1]]; + ; + break;} +case 38: +#line 256 "STGrammar.y" +{ + yyval = [NSMutableArray array]; + [yyval addObject:yyvsp[0]]; + ; + break;} +case 39: +#line 261 "STGrammar.y" +{ + yyval = yyvsp[-1]; + [yyval addObject:yyvsp[0]]; + ; + break;} +case 40: +#line 268 "STGrammar.y" +{ yyval = yyvsp[-1];; + break;} +case 41: +#line 271 "STGrammar.y" +{ + /* FIXME: check if this is this OK */ + [yyval setCascade:yyvsp[0]]; + ; + break;} +case 42: +#line 277 "STGrammar.y" +{ + yyval = [NSMutableArray array]; + [yyval addObject:yyvsp[0]]; + ; + break;} +case 43: +#line 282 "STGrammar.y" +{ + yyval = yyvsp[-2]; + [yyval addObject:yyvsp[0]]; + ; + break;} +case 44: +#line 288 "STGrammar.y" +{ + yyval = [STCMessage message]; + [yyval addKeyword:yyvsp[0] object:nil]; + ; + break;} +case 45: +#line 293 "STGrammar.y" +{ + yyval = [STCMessage message]; + [yyval addKeyword:yyvsp[-1] object:yyvsp[0]]; + ; + break;} +case 50: +#line 305 "STGrammar.y" +{ + STCMessage *message = [STCMessage message]; + [message addKeyword:yyvsp[0] object:nil]; + yyval = [STCExpression + /**/ messageExpressionWithTarget:yyvsp[-1] + /**/ message:message]; + ; + break;} +case 51: +#line 314 "STGrammar.y" +{ + STCMessage *message = [STCMessage message]; + [message addKeyword:yyvsp[-1] object:yyvsp[0]]; + yyval = [STCExpression + /**/ messageExpressionWithTarget:yyvsp[-2] + /**/ message:message]; + ; + break;} +case 52: +#line 323 "STGrammar.y" +{ + yyval = [STCExpression + /**/ messageExpressionWithTarget:yyvsp[-1] + /**/ message:yyvsp[0]]; + ; + break;} +case 53: +#line 329 "STGrammar.y" +{ + yyval = [STCMessage message]; + [yyval addKeyword:yyvsp[-1] object:yyvsp[0]]; + ; + break;} +case 54: +#line 334 "STGrammar.y" +{ + yyval = yyvsp[-2]; + [yyval addKeyword:yyvsp[-1] object:yyvsp[0]]; + ; + break;} +case 59: +#line 346 "STGrammar.y" +{ + yyval = [STCPrimary primaryWithVariable:yyvsp[0]]; + ; + break;} +case 60: +#line 350 "STGrammar.y" +{ + yyval = [STCPrimary primaryWithLiteral:yyvsp[0]]; + ; + break;} +case 61: +#line 354 "STGrammar.y" +{ + yyval = [STCPrimary primaryWithBlock:yyvsp[0]]; + ; + break;} +case 62: +#line 358 "STGrammar.y" +{ + yyval = [STCPrimary primaryWithExpression:yyvsp[-1]]; + ; + break;} +case 67: +#line 371 "STGrammar.y" +{ yyval = [COMPILER createNumberLiteralFrom:yyvsp[0]]; ; + break;} +case 68: +#line 373 "STGrammar.y" +{ yyval = [COMPILER createSymbolLiteralFrom:yyvsp[0]]; ; + break;} +case 69: +#line 375 "STGrammar.y" +{ yyval = [COMPILER createStringLiteralFrom:yyvsp[0]]; ; + break;} +case 70: +#line 377 "STGrammar.y" +{ yyval = [COMPILER createCharacterLiteralFrom:yyvsp[0]]; ; + break;} +case 71: +#line 379 "STGrammar.y" +{ yyval = [COMPILER createArrayLiteralFrom:yyvsp[-1]]; ; + break;} +case 72: +#line 381 "STGrammar.y" +{ yyval = [NSMutableArray array]; + [yyval addObject:yyvsp[0]]; ; + break;} +case 73: +#line 383 "STGrammar.y" +{ yyval = [NSMutableArray array]; + [yyval addObject:yyvsp[0]]; ; + break;} +case 74: +#line 385 "STGrammar.y" +{ yyval = yyvsp[-1]; [yyval addObject:yyvsp[0]]; ; + break;} +case 75: +#line 386 "STGrammar.y" +{ yyval = yyvsp[-1]; [yyval addObject:yyvsp[0]]; ; + break;} +case 76: +#line 389 "STGrammar.y" +{ yyval = [COMPILER createSymbolLiteralFrom:yyvsp[0]]; ; + break;} +case 77: +#line 391 "STGrammar.y" +{ yyval = [COMPILER createSymbolLiteralFrom:yyvsp[0]]; ; + break;} +case 78: +#line 393 "STGrammar.y" +{ yyval = [COMPILER createSymbolLiteralFrom:yyvsp[0]]; ; + break;} +} + /* the action file gets copied in in place of this dollarsign */ +#line 498 "/usr/local/share/bison.simple" + + yyvsp -= yylen; + yyssp -= yylen; +#ifdef YYLSP_NEEDED + yylsp -= yylen; +#endif + +#if YYDEBUG != 0 + if (yydebug) + { + short *ssp1 = yyss - 1; + fprintf (stderr, "state stack now"); + while (ssp1 != yyssp) + fprintf (stderr, " %d", *++ssp1); + fprintf (stderr, "\n"); + } +#endif + + *++yyvsp = yyval; + +#ifdef YYLSP_NEEDED + yylsp++; + if (yylen == 0) + { + yylsp->first_line = yylloc.first_line; + yylsp->first_column = yylloc.first_column; + yylsp->last_line = (yylsp-1)->last_line; + yylsp->last_column = (yylsp-1)->last_column; + yylsp->text = 0; + } + else + { + yylsp->last_line = (yylsp+yylen-1)->last_line; + yylsp->last_column = (yylsp+yylen-1)->last_column; + } +#endif + + /* Now "shift" the result of the reduction. + Determine what state that goes to, + based on the state we popped back to + and the rule number reduced by. */ + + yyn = yyr1[yyn]; + + yystate = yypgoto[yyn - YYNTBASE] + *yyssp; + if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp) + yystate = yytable[yystate]; + else + yystate = yydefgoto[yyn - YYNTBASE]; + + goto yynewstate; + +yyerrlab: /* here on detecting error */ + + if (! yyerrstatus) + /* If not already recovering from an error, report this error. */ + { + ++yynerrs; + +#ifdef YYERROR_VERBOSE + yyn = yypact[yystate]; + + if (yyn > YYFLAG && yyn < YYLAST) + { + int size = 0; + char *msg; + int x, count; + + count = 0; + /* Start X at -yyn if nec to avoid negative indexes in yycheck. */ + for (x = (yyn < 0 ? -yyn : 0); + x < (sizeof(yytname) / sizeof(char *)); x++) + if (yycheck[x + yyn] == x) + size += strlen(yytname[x]) + 15, count++; + msg = (char *) malloc(size + 15); + if (msg != 0) + { + strcpy(msg, "parse error"); + + if (count < 5) + { + count = 0; + for (x = (yyn < 0 ? -yyn : 0); + x < (sizeof(yytname) / sizeof(char *)); x++) + if (yycheck[x + yyn] == x) + { + strcat(msg, count == 0 ? ", expecting `" : " or `"); + strcat(msg, yytname[x]); + strcat(msg, "'"); + count++; + } + } + yyerror(msg); + free(msg); + } + else + yyerror ("parse error; also virtual memory exceeded"); + } + else +#endif /* YYERROR_VERBOSE */ + yyerror("parse error"); + } + + goto yyerrlab1; +yyerrlab1: /* here on error raised explicitly by an action */ + + if (yyerrstatus == 3) + { + /* if just tried and failed to reuse lookahead token after an error, discard it. */ + + /* return failure if at end of input */ + if (yychar == YYEOF) + YYABORT; + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]); +#endif + + yychar = YYEMPTY; + } + + /* Else will try to reuse lookahead token + after shifting the error token. */ + + yyerrstatus = 3; /* Each real token shifted decrements this */ + + goto yyerrhandle; + +yyerrdefault: /* current state does not do anything special for the error token. */ + +#if 0 + /* This is wrong; only states that explicitly want error tokens + should shift them. */ + yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/ + if (yyn) goto yydefault; +#endif + +yyerrpop: /* pop the current state because it cannot handle the error token */ + + if (yyssp == yyss) YYABORT; + yyvsp--; + yystate = *--yyssp; +#ifdef YYLSP_NEEDED + yylsp--; +#endif + +#if YYDEBUG != 0 + if (yydebug) + { + short *ssp1 = yyss - 1; + fprintf (stderr, "Error: state stack now"); + while (ssp1 != yyssp) + fprintf (stderr, " %d", *++ssp1); + fprintf (stderr, "\n"); + } +#endif + +yyerrhandle: + + yyn = yypact[yystate]; + if (yyn == YYFLAG) + goto yyerrdefault; + + yyn += YYTERROR; + if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR) + goto yyerrdefault; + + yyn = yytable[yyn]; + if (yyn < 0) + { + if (yyn == YYFLAG) + goto yyerrpop; + yyn = -yyn; + goto yyreduce; + } + else if (yyn == 0) + goto yyerrpop; + + if (yyn == YYFINAL) + YYACCEPT; + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Shifting error token, "); +#endif + + *++yyvsp = yylval; +#ifdef YYLSP_NEEDED + *++yylsp = yylloc; +#endif + + yystate = yyn; + goto yynewstate; +} +#line 395 "STGrammar.y" + + +int STCerror(const char *str) +{ + [NSException raise:STCompilerSyntaxException + format:@"Unknown parse error (%s)", str]; + return 0; +} + + + +/* + * Lexer + * -------------------------------------------------------------------------- + */ + +int STClex (YYSTYPE *lvalp, void *context) +{ + STTokenType tokenType = [READER nextToken]; + + if(tokenType == STEndTokenType) + { + return 0; + } + + *lvalp = [READER tokenString]; + + switch(tokenType) + { + case STBarTokenType: return TK_BAR; + case STReturnTokenType: return TK_RETURN; + case STColonTokenType: return TK_COLON; + case STSemicolonTokenType: return TK_SEMICOLON; + case STDotTokenType: return TK_DOT; + case STLParenTokenType: return TK_LPAREN; + case STRParenTokenType: return TK_RPAREN; + case STBlockOpenTokenType: return TK_BLOCK_OPEN; + case STBlockCloseTokenType: return TK_BLOCK_CLOSE; + case STArrayOpenTokenType: return TK_ARRAY_OPEN; + case STAssignTokenType: return TK_ASSIGNMENT; + case STIdentifierTokenType: return TK_IDENTIFIER; + case STKeywordTokenType: return TK_KEYWORD; + case STBinarySelectorTokenType: return TK_BINARY_SELECTOR; + case STSymbolTokenType: return TK_SYMBOL; + case STStringTokenType: return TK_STRING; + case STCharacterTokenType: return TK_CHARACTER; + case STNumberTokenType: return TK_NUMBER; + case STSeparatorTokenType: return TK_SEPARATOR; + + case STEndTokenType: return 0; + + case STSharpTokenType: + case STInvalidTokenType: + case STErrorTokenType: + return 1; + } + + return 1; +} diff --git a/Languages/Smalltalk/STGrammar.m.h b/Languages/Smalltalk/STGrammar.m.h new file mode 100644 index 0000000..c30b908 --- /dev/null +++ b/Languages/Smalltalk/STGrammar.m.h @@ -0,0 +1,23 @@ +#ifndef YYSTYPE +#define YYSTYPE int +#endif +#define TK_SEPARATOR 258 +#define TK_BAR 259 +#define TK_ASSIGNMENT 260 +#define TK_LPAREN 261 +#define TK_RPAREN 262 +#define TK_BLOCK_OPEN 263 +#define TK_BLOCK_CLOSE 264 +#define TK_ARRAY_OPEN 265 +#define TK_DOT 266 +#define TK_COLON 267 +#define TK_SEMICOLON 268 +#define TK_RETURN 269 +#define TK_IDENTIFIER 270 +#define TK_BINARY_SELECTOR 271 +#define TK_KEYWORD 272 +#define TK_NUMBER 273 +#define TK_SYMBOL 274 +#define TK_STRING 275 +#define TK_CHARACTER 276 + diff --git a/Languages/Smalltalk/STGrammar.y b/Languages/Smalltalk/STGrammar.y new file mode 100644 index 0000000..07f99eb --- /dev/null +++ b/Languages/Smalltalk/STGrammar.y @@ -0,0 +1,453 @@ +/** + * STGrammar.y + * StepTalk grammar + * + * Copyright (c) 2000 Stefan Urbanek + * + * 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. + * + */ + +%{ + + #define YYSTYPE id + #define YYLTYPE int + #undef YYDEBUG + + #import + #import "STCompiler.h" + #import "STCompilerUtils.h" + #import "STSourceReader.h" + + #import + + +/* extern int STCerror(const char *str); + extern int STClex (YYSTYPE *lvalp, void *context); +*/ + #define YYPARSE_PARAM context + #define YYLEX_PARAM context + #define YYERROR_VERBOSE + + #define CONTEXT ((STParserContext *)context) + #define COMPILER (CONTEXT->compiler) + #define READER (CONTEXT->reader) + #define RESULT (CONTEXT->result) + +%} + +%pure_parser + +/* BISON declarations */ + +%token TK_SEPARATOR TK_BAR TK_ASSIGNMENT +%token TK_LPAREN TK_RPAREN TK_BLOCK_OPEN TK_BLOCK_CLOSE TK_ARRAY_OPEN +%token TK_DOT TK_COLON TK_SEMICOLON TK_RETURN +%token TK_IDENTIFIER TK_BINARY_SELECTOR TK_KEYWORD +%token TK_NUMBER TK_SYMBOL TK_STRING TK_CHARACTER + +/* Grammar */ + +%% +source: /* empty string */ { + [COMPILER compileMethod:nil]; + } + + + | single_method { + [COMPILER compileMethod:$1]; + } + + | + TK_BLOCK_OPEN TK_BAR + methods + TK_BLOCK_CLOSE +; + +single_method: statements + { + $$ = [STCMethod methodWithPattern:nil + /**/ statements:$1]; + } + | temporaries statements + { + [$2 setTemporaries:$1]; + $$ = [STCMethod methodWithPattern:nil + /**/ statements:$2]; + } +; + +methods: + block_var_list + { + [COMPILER setReceiverVariables:$1]; + } + method_list + + | method_list +; + +method_list: method + { + [COMPILER compileMethod:$1]; + } + | method_list TK_SEPARATOR method + { + [COMPILER compileMethod:$3]; + } +; + +method: message_pattern statements + { + $$ = [STCMethod methodWithPattern:$1 + /**/ statements:$2]; + } + | message_pattern temporaries statements + { + [$3 setTemporaries:$2]; + $$ = [STCMethod methodWithPattern:$1 + /**/ statements:$3]; + } +; + +message_pattern: + unary_selector + { + $$ = [STCMessage message]; + [$$ addKeyword:$1 object:nil]; + } + | binary_selector variable_name + { + $$ = [STCMessage message]; + [$$ addKeyword:$1 object:$2]; + } + | keyword_list +; + +keyword_list: keyword variable_name + { + $$ = [STCMessage message]; + [$$ addKeyword:$1 object:$2]; + } + | keyword_list keyword variable_name + { + [$1 addKeyword:$2 object:$3]; + $$ = $1; + } +; + +temporaries: TK_BAR variable_list TK_BAR + { $$ = $2; } +; + +variable_list: variable_name + { + $$ = [NSMutableArray array]; + [$$ addObject:$1]; + } + | variable_list variable_name + { + $$ = $1; + [$$ addObject:$2]; + } +; + +block: TK_BLOCK_OPEN TK_BLOCK_CLOSE + { + $$ = [STCStatements statements]; + } + | TK_BLOCK_OPEN statements TK_BLOCK_CLOSE + { + $$ = $2; + } + | TK_BLOCK_OPEN block_var_list TK_BAR statements TK_BLOCK_CLOSE + { + $$ = $4; + [$$ setTemporaries:$2]; + } +; +block_var_list: TK_COLON variable_name + { + $$ = [NSMutableArray array]; + [$$ addObject:$2]; + } + | block_var_list TK_COLON variable_name + { + $$ = $1; + [$$ addObject:$3]; + } +; +statements: + TK_RETURN expression + { + $$ = [STCStatements statements]; + [$$ setReturnExpression:$2]; + } + | expressions + { + $$ = [STCStatements statements]; + [$$ setExpressions:$1]; + } + + | expressions TK_DOT + { + $$ = [STCStatements statements]; + [$$ setExpressions:$1]; + } + | expressions TK_DOT TK_RETURN expression + { + $$ = [STCStatements statements]; + [$$ setReturnExpression:$4]; + [$$ setExpressions:$1]; + } +; + +expressions: + expression { + $$ = [NSMutableArray array]; + [$$ addObject:$1]; + } + + | expressions TK_DOT expression + { + $$ = $1; + [$$ addObject:$3]; + } +; +expression: primary + { + $$ = [STCExpression + /**/ primaryExpressionWithObject:$1]; + } + | assignments primary + { + $$ = [STCExpression + /**/ primaryExpressionWithObject:$2]; + [$$ setAssignments:$1]; + } + | message_expression + | assignments message_expression + { + $$ = $2; + [$$ setAssignments:$1]; + } + | cascade + | assignments cascade + { + $$ = $2; + [$$ setAssignments:$1]; + } +; +assignments: assignment + { + $$ = [NSMutableArray array]; + [$$ addObject:$1]; + } + | assignments assignment + { + $$ = $1; + [$$ addObject:$2]; + } +; + +assignment: variable_name TK_ASSIGNMENT + { $$ = $1;} + +cascade: message_expression cascade_list + { + /* FIXME: check if this is this OK */ + [$$ setCascade:$2]; + } +; +cascade_list: TK_SEMICOLON cascade_item + { + $$ = [NSMutableArray array]; + [$$ addObject:$2]; + } + | cascade_list TK_SEMICOLON cascade_item + { + $$ = $1; + [$$ addObject:$3]; + } +; +cascade_item: unary_selector + { + $$ = [STCMessage message]; + [$$ addKeyword:$1 object:nil]; + } + | binary_selector unary_object + { + $$ = [STCMessage message]; + [$$ addKeyword:$1 object:$2]; + } + | keyword_expr_list +; + +message_expression: unary_expression + | binary_expression + | keyword_expression +; +unary_expression: unary_object unary_selector + { + STCMessage *message = [STCMessage message]; + [message addKeyword:$2 object:nil]; + $$ = [STCExpression + /**/ messageExpressionWithTarget:$1 + /**/ message:message]; + } +; +binary_expression: binary_object binary_selector unary_object + { + STCMessage *message = [STCMessage message]; + [message addKeyword:$2 object:$3]; + $$ = [STCExpression + /**/ messageExpressionWithTarget:$1 + /**/ message:message]; + } +; +keyword_expression: binary_object keyword_expr_list + { + $$ = [STCExpression + /**/ messageExpressionWithTarget:$1 + /**/ message:$2]; + } +keyword_expr_list: keyword binary_object + { + $$ = [STCMessage message]; + [$$ addKeyword:$1 object:$2]; + } + | keyword_expr_list keyword binary_object + { + $$ = $1; + [$$ addKeyword:$2 object:$3]; + } +; +unary_object: primary + | unary_expression +; +binary_object: unary_object + | binary_expression +; +primary: variable_name + { + $$ = [STCPrimary primaryWithVariable:$1]; + } + | literal + { + $$ = [STCPrimary primaryWithLiteral:$1]; + } + | block + { + $$ = [STCPrimary primaryWithBlock:$1]; + } + | TK_LPAREN expression TK_RPAREN + { + $$ = [STCPrimary primaryWithExpression:$2]; + } +; +variable_name: TK_IDENTIFIER /* STCheckVariable ... */ +; +unary_selector: TK_IDENTIFIER +; +binary_selector: TK_BINARY_SELECTOR +; +keyword: TK_KEYWORD +; +literal: TK_NUMBER + { $$ = [COMPILER createNumberLiteralFrom:$1]; } + | TK_SYMBOL + { $$ = [COMPILER createSymbolLiteralFrom:$1]; } + | TK_STRING + { $$ = [COMPILER createStringLiteralFrom:$1]; } + | TK_CHARACTER + { $$ = [COMPILER createCharacterLiteralFrom:$1]; } + | TK_ARRAY_OPEN array TK_RPAREN + { $$ = [COMPILER createArrayLiteralFrom:$2]; } +; +array: literal { $$ = [NSMutableArray array]; + [$$ addObject:$1]; } + | symbol { $$ = [NSMutableArray array]; + [$$ addObject:$1]; } + | array literal { $$ = $1; [$$ addObject:$2]; } + | array symbol { $$ = $1; [$$ addObject:$2]; } +; +symbol: TK_IDENTIFIER + { $$ = [COMPILER createSymbolLiteralFrom:$1]; } + | binary_selector + { $$ = [COMPILER createSymbolLiteralFrom:$1]; } + | TK_KEYWORD + { $$ = [COMPILER createSymbolLiteralFrom:$1]; } + +%% + +int STCerror(const char *str) +{ + [NSException raise:STCompilerSyntaxException + format:@"Unknown parse error (%s)", str]; + return 0; +} + + + +/* + * Lexer + * -------------------------------------------------------------------------- + */ + +int STClex (YYSTYPE *lvalp, void *context) +{ + STTokenType tokenType = [READER nextToken]; + + if(tokenType == STEndTokenType) + { + return 0; + } + + *lvalp = [READER tokenString]; + + switch(tokenType) + { + case STBarTokenType: return TK_BAR; + case STReturnTokenType: return TK_RETURN; + case STColonTokenType: return TK_COLON; + case STSemicolonTokenType: return TK_SEMICOLON; + case STDotTokenType: return TK_DOT; + case STLParenTokenType: return TK_LPAREN; + case STRParenTokenType: return TK_RPAREN; + case STBlockOpenTokenType: return TK_BLOCK_OPEN; + case STBlockCloseTokenType: return TK_BLOCK_CLOSE; + case STArrayOpenTokenType: return TK_ARRAY_OPEN; + case STAssignTokenType: return TK_ASSIGNMENT; + case STIdentifierTokenType: return TK_IDENTIFIER; + case STKeywordTokenType: return TK_KEYWORD; + case STBinarySelectorTokenType: return TK_BINARY_SELECTOR; + case STSymbolTokenType: return TK_SYMBOL; + case STStringTokenType: return TK_STRING; + case STCharacterTokenType: return TK_CHARACTER; + case STNumberTokenType: return TK_NUMBER; + case STSeparatorTokenType: return TK_SEPARATOR; + + case STEndTokenType: return 0; + + case STSharpTokenType: + case STInvalidTokenType: + case STErrorTokenType: + return 1; + } + + return 1; +} diff --git a/Languages/Smalltalk/STLiterals.h b/Languages/Smalltalk/STLiterals.h new file mode 100644 index 0000000..9080bca --- /dev/null +++ b/Languages/Smalltalk/STLiterals.h @@ -0,0 +1,49 @@ +/** + STLiterals.h + Literal objects + + 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 STLiteral:NSObject +@end + +@interface STObjectReferenceLiteral:STLiteral +{ + NSString *poolName; + NSString *objectName; +} +- initWithObjectName:(NSString *)anObject poolName:(NSString *)aPool; +- (NSString *)poolName; +- (NSString *)objectName; +@end + +@interface STBlockLiteral:STLiteral +{ + unsigned argCount; + unsigned stackSize; +} +- initWithArgumentCount:(unsigned)count; +- (void)setStackSize:(unsigned)size; +- (unsigned)argumentCount; +- (unsigned)stackSize; +@end diff --git a/Languages/Smalltalk/STLiterals.m b/Languages/Smalltalk/STLiterals.m new file mode 100644 index 0000000..420c0b8 --- /dev/null +++ b/Languages/Smalltalk/STLiterals.m @@ -0,0 +1,86 @@ +/** + STLiterals.h + Literal objects + + 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 "STLiterals.h" + +#import + +@implementation STLiteral +@end + +@implementation STObjectReferenceLiteral +- initWithObjectName:(NSString *)anObject poolName:(NSString *)aPool +{ + objectName = RETAIN(anObject); + poolName = RETAIN(aPool); + return [super init]; +} +- copyWithZone:(NSZone *)zone +{ + STObjectReferenceLiteral *copy = [super copyWithZone:zone]; + return copy; +} + +- (void)dealloc +{ + RELEASE(objectName); + RELEASE(poolName); + [super dealloc]; +} +- (NSString *)poolName +{ + return poolName; +} +- (NSString *)objectName +{ + return objectName; +} +- (NSString *)description +{ + return [NSMutableString stringWithFormat: + @"STObjectReferenceLiteral { object '%@', pool '%@' }", + objectName,poolName]; +} +@end + +@implementation STBlockLiteral +- initWithArgumentCount:(unsigned)count +{ + argCount = count; + return [super init]; +} +- (void)setStackSize:(unsigned)size +{ + stackSize = size; +} +- (unsigned)argumentCount +{ + return argCount; +} +- (unsigned)stackSize +{ + return stackSize; +} +@end + diff --git a/Languages/Smalltalk/STMessage.h b/Languages/Smalltalk/STMessage.h new file mode 100644 index 0000000..cdfb645 --- /dev/null +++ b/Languages/Smalltalk/STMessage.h @@ -0,0 +1,43 @@ +/** + STMessage.h + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2001 Jun 18 + + 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 NSArray; + +@interface STMessage:NSObject +{ + NSString *selector; + NSArray *args; +} ++ (STMessage *)messageWithSelector:(NSString *)selector + arguments:(NSArray *)args; +- initWithSelector:(NSString *)aString + arguments:(NSArray *)anArray; +- (NSString *)selector; +- (NSArray*)arguments; +@end diff --git a/Languages/Smalltalk/STMessage.m b/Languages/Smalltalk/STMessage.m new file mode 100644 index 0000000..c86d35d --- /dev/null +++ b/Languages/Smalltalk/STMessage.m @@ -0,0 +1,71 @@ +/** + STMessage.m + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2001 Jun 18 + + 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 "STMessage.h" + +#import +#import +#import +#import + + +@implementation STMessage ++ (STMessage *)messageWithSelector:(NSString *)aString + arguments:(NSArray *)anArray +{ + STMessage *message; + + message = [[STMessage alloc] initWithSelector:aString + arguments:anArray]; + return AUTORELEASE(message); +} +- initWithSelector:(NSString *)aString + arguments:(NSArray *)anArray +{ + [super init]; + selector = RETAIN(aString); + args = RETAIN(anArray); + + return self; +} + +- (void)dealloc +{ + RELEASE(selector); + RELEASE(args); + + [super dealloc]; +} + +- (NSString *)selector +{ + return selector; +} + +- (NSArray *)arguments +{ + return args; +} +@end diff --git a/Languages/Smalltalk/STMethodContext.h b/Languages/Smalltalk/STMethodContext.h new file mode 100644 index 0000000..0accbfc --- /dev/null +++ b/Languages/Smalltalk/STMethodContext.h @@ -0,0 +1,61 @@ +/** + STMethodContext.h + + 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 "STExecutionContext.h" + +@class STCompiledMethod; +@class STEnvironment; +@class NSMutableArray; + +@interface STMethodContext:STExecutionContext +{ + STCompiledMethod *method; + + NSMutableArray *temporaries; + NSMutableArray *externs; + + id receiver; +} + ++ methodContextWithMethod:(STCompiledMethod *)newMethod + environment:(STEnvironment *)env; + +- initWithMethod:(STCompiledMethod *)newMethod + environment:(STEnvironment *)env; + +- (STCompiledMethod*)method; + +- (void)setReceiver:anObject; +- (id)receiver; + +- (void)setArgumentsFromArray:(NSArray *)args; + +- (id)temporaryAtIndex:(unsigned)index; +- (void)setTemporary:anObject atIndex:(unsigned)index; + +- (id)externAtIndex:(unsigned)index; +- (void)setExtern:anObject atIndex:(unsigned)index; + +- (STBytecodes *)bytecodes; +- (id)literalObjectAtIndex:(unsigned)index; +@end diff --git a/Languages/Smalltalk/STMethodContext.m b/Languages/Smalltalk/STMethodContext.m new file mode 100644 index 0000000..fa43cbf --- /dev/null +++ b/Languages/Smalltalk/STMethodContext.m @@ -0,0 +1,200 @@ +/** + STMethodContext.m + + 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 "STMethodContext.h" + +#import "STBytecodes.h" +#import "STCompiledMethod.h" +#import "STLiterals.h" +#import "STStack.h" + +#import +#import +#import + +#import +#import +#import + +@interface STMethodContext(STPrivateMethods) +- (void)_resolveExternReferences:(NSArray *)array + environment:(STEnvironment *)env; +@end + +@implementation STMethodContext ++ methodContextWithMethod:(STCompiledMethod *)newMethod + environment:(STEnvironment *)env +{ + return AUTORELEASE([[self alloc] initWithMethod:newMethod environment:env]); +} + +- initWithMethod:(STCompiledMethod *)newMethod + environment:(STEnvironment *)env +{ + unsigned int tempCount; + unsigned int i; + + method = RETAIN(newMethod); + + tempCount = [method temporariesCount]; + temporaries = [[NSMutableArray alloc] initWithCapacity:tempCount]; + + for(i=0;i + +@class NSMutableArray; +@class NSMutableDictionary; +@class STBytecodeInterpreter; +@class STCompiledScript; +@class STEnvironment; + +@interface STScriptObject:NSObject +{ + NSString *name; + STBytecodeInterpreter *interpreter; + STEnvironment *environment; + STCompiledScript *script; + NSMutableArray *variables; +} +- initWithEnvironment:(STEnvironment *)env + compiledScript:(STCompiledScript *)compiledScript; + +- (void)setInstanceVariable:(id)anObject atIndex:(int)anIndex; +- (id)instanceVariableAtIndex:(int)anIndex; +@end diff --git a/Languages/Smalltalk/STScriptObject.m b/Languages/Smalltalk/STScriptObject.m new file mode 100644 index 0000000..a0194e6 --- /dev/null +++ b/Languages/Smalltalk/STScriptObject.m @@ -0,0 +1,170 @@ +/** + STScriptObject.m + Object that represents script + + Copyright (c) 2002 Free Software Foundation + + 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 "STScriptObject.h" + +#import "STBytecodeInterpreter.h" +#import "STCompiledScript.h" + +#import +#import +#import +#import + +#import +#import +#import +#import + +@implementation STScriptObject +- initWithEnvironment:(STEnvironment *)env + compiledScript:(STCompiledScript *)compiledScript +{ + int count = [compiledScript variableCount]; + int i; + + [super init]; + + NSDebugLLog(@"STEngine", + @"creating script object %p with %i ivars",compiledScript, + count); + + environment = RETAIN(env); + script = RETAIN(compiledScript); + variables = [[NSMutableArray alloc] initWithCapacity:count]; + + for(i=0;i> forwarding to self ..."); + + retval = [interpreter executeCompiledMethod:method withArguments:args]; + + NSDebugLLog(@"STSending", + @"<< returned from forwarding"); + + [invocation setReturnValue:&retval]; +} +@end diff --git a/Languages/Smalltalk/STSelector+additions.h b/Languages/Smalltalk/STSelector+additions.h new file mode 100644 index 0000000..d4e94cf --- /dev/null +++ b/Languages/Smalltalk/STSelector+additions.h @@ -0,0 +1,30 @@ +/* + STSelector additions + + Copyright (c) 2002 Free Software Foundation + 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(SmalltalkCompiler) ++ symbolFromString:(NSString *)aString; +@end + diff --git a/Languages/Smalltalk/STSelector+additions.m b/Languages/Smalltalk/STSelector+additions.m new file mode 100644 index 0000000..44f86d0 --- /dev/null +++ b/Languages/Smalltalk/STSelector+additions.m @@ -0,0 +1,34 @@ +/* + STSelector additions + + Copyright (c) 2002 Free Software Foundation + 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 "STSelector+additions.h" + +@implementation STSelector(SmalltalkCompiler) ++ symbolFromString:(NSString *)aString +{ + STSelector *aSel; + aSel = [[STSelector alloc] initWithSelector:STSelectorFromString(aString)]; + return AUTORELEASE(aSel); +} +@end diff --git a/Languages/Smalltalk/STSourceReader.h b/Languages/Smalltalk/STSourceReader.h new file mode 100644 index 0000000..1fb5da3 --- /dev/null +++ b/Languages/Smalltalk/STSourceReader.h @@ -0,0 +1,48 @@ +/** + STSourceReader.h + Source reader class. + + 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 +#import + +#include "STTokenTypes.h" + + +@class NSString; + +@interface STSourceReader:NSObject +{ + NSString *source; // Source + NSRange srcRange; // range of source in string + int srcOffset; // Scan offset + NSRange tokenRange; // Tokenn range + STTokenType tokenType; // Token type +} +- initWithString:(NSString *)aString; +- initWithString:(NSString *)aString range:(NSRange)range; +- (STTokenType)nextToken; +- (STTokenType)tokenType; +- (NSString *)tokenString; +- (NSRange)tokenRange; +- (int)currentLine; + +@end diff --git a/Languages/Smalltalk/STSourceReader.m b/Languages/Smalltalk/STSourceReader.m new file mode 100644 index 0000000..4f55451 --- /dev/null +++ b/Languages/Smalltalk/STSourceReader.m @@ -0,0 +1,488 @@ +/** + STSourceReader.m + Source reader class. + + Copyright (c) 2002 Free Software Foundation + + This file is part of the StepTalk project. + + */ + +#import "STSourceReader.h" +#import +#import +#import + +#import + +#import "Externs.h" + +static NSCharacterSet *identStartCharacterSet; +static NSCharacterSet *identCharacterSet; +static NSCharacterSet *wsCharacterSet; +static NSCharacterSet *numericCharacterSet; +static NSCharacterSet *symbolicSelectorCharacterSet; +static NSCharacterSet *validCharacterCharacterSet; + +#define AT_END (srcOffset >= NSMaxRange(srcRange)) +// #define AT_END ([self atEnd]) + +@interface NSString (LineCounting) +- (int)lineNumberForIndex:(int)index; +@end + +@implementation NSString (LineCounting) +- (int)lineNumberForIndex:(int)index +{ + int i, len; + int cr = 0; + int line = 1; + len = [self length]; + index = (index < len) ? index : len; + + for(i=0;i?@\\~"]; + + RETAIN(wsCharacterSet); + RETAIN(numericCharacterSet); + RETAIN(symbolicSelectorCharacterSet); + +/* + set = [[NSCharacterSet alphanumericCharacterSet] mutableCopy]; + [set formUnionWithCharacterSet:[NSCharacterSet punctuationCharacterSet]]; + [set formUnionWithCharacterSet:[NSCharacterSet nonBaseCharacterSet]]; +*/ + set = [[NSCharacterSet controlCharacterSet] mutableCopy]; + [set formUnionWithCharacterSet:[NSCharacterSet illegalCharacterSet]]; + [set formUnionWithCharacterSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + + validCharacterCharacterSet = RETAIN([set invertedSet]); + + RELEASE(set); +/* + characterAtIndex = (unichar (*)(NSString*, SEL, unsigned int)) + [NSString instanceMethodForSelector: @selector(characterAtIndex:)]; + characterIsMember = (unichar (*)(NSString*, SEL, unsigned int)) + [NSCharacterSet instanceMethodForSelector: @selector(characterAtIndex:)]; +*/ +} +- (void)dealloc +{ + RELEASE(source); +} + + +- initWithString:(NSString *)aString +{ + return [self initWithString:aString range:NSMakeRange(0,[aString length])]; +} + +- initWithString:(NSString *)aString range:(NSRange)range +{ + [super init]; + + ASSIGN(source,aString); + srcRange = range; + srcOffset = range.location; + tokenRange = NSMakeRange(0,0); + tokenType = STInvalidTokenType; + + return self; +} + +- (STTokenType) tokenType +{ + return tokenType; +} + +- (NSString *)tokenString +{ + + if(tokenType == STStringTokenType) + { + return _STNormalizeStringToken([source substringWithRange:tokenRange]); + } + else + { + return [source substringWithRange:tokenRange]; + } +} + +- (NSRange)tokenRange; +{ + return tokenRange; +} + +- (BOOL) atEnd +{ + return (srcOffset >= NSMaxRange(srcRange)); +} + +- (int) currentLine +{ + return [source lineNumberForIndex:srcOffset]; +} + +- (BOOL) eatWhiteSpace +{ + unichar uc; + + for(;;) + { + if(AT_END) + { + return 0; + } + + uc = PEEK_CHAR; + + /* treat comments as whitespace */ + if(uc == '"') + { + unsigned int start = srcOffset; + do + { + srcOffset++; + if(AT_END) + { + tokenRange = NSMakeRange(start, 1); + + [NSException raise:STCompilerSyntaxException + format:@"Unterminated comment"]; + return 1; + } + } while(PEEK_CHAR != '"'); + } + else if([wsCharacterSet characterIsMember:uc] == NO) + { + return 0; + } + srcOffset++; + } +} + +- (STTokenType)readNextToken +{ + unichar c; + int start; + + if([self eatWhiteSpace]) + { + return STErrorTokenType; + } + + if(AT_END) + { + return STEndTokenType; + } + + c = PEEK_CHAR; + + if([identStartCharacterSet characterIsMember:c]) + { + start=srcOffset++; + while([identCharacterSet characterIsMember:c]) + { + c = GET_CHAR; + if(AT_END) + { + break; + } + } + srcOffset--; + if(!AT_END) + { + c = PEEK_CHAR; + if(c == ':') + { + c = GET_CHAR; + if(c=='=') + { + srcOffset--; /* we got := */ + } + else + { + tokenRange = NSMakeRange(start,srcOffset - start); + return STKeywordTokenType; + } + } + } + tokenRange = NSMakeRange(start,srcOffset - start); + return STIdentifierTokenType; + } + else if ( c == '-' || [numericCharacterSet characterIsMember:c]) + { + start=srcOffset; + + c = GET_CHAR; + + while([numericCharacterSet characterIsMember:c]) + { + c = GET_CHAR; + if(AT_END) + break; + } + + srcOffset--; + tokenRange = NSMakeRange(start,srcOffset - start); + + c = PEEK_CHAR; + if([identCharacterSet characterIsMember:c]) + { + tokenRange = NSMakeRange(start,srcOffset - start + 1); + [NSException raise:STCompilerSyntaxException + format:@"Letters in number"]; + return STErrorTokenType; + } + return STNumberTokenType; + + } + else if ([symbolicSelectorCharacterSet characterIsMember:c]) + { + start = srcOffset++; + c = PEEK_CHAR; + if ([symbolicSelectorCharacterSet characterIsMember:c]) + { + srcOffset++; + tokenRange = NSMakeRange(start,2); + } + else + tokenRange = NSMakeRange(start,1); + return STBinarySelectorTokenType; + } + else + { + switch(c) + { + case '$': + srcOffset++; + c = GET_CHAR; + if(AT_END) + { + tokenRange = NSMakeRange(srcOffset-2, 1); + [NSException raise:STCompilerSyntaxException + format:@"Character expected"]; + return STErrorTokenType; + }; + + if([validCharacterCharacterSet characterIsMember:c]) + { + c = PEEK_CHAR; + if([identCharacterSet characterIsMember:c]) + { + tokenRange = NSMakeRange(srcOffset-2, 3); + [NSException raise:STCompilerSyntaxException + format:@"Too many characters"]; + return STErrorTokenType; + } + + tokenRange = NSMakeRange(srcOffset++,1);\ + return STCharacterTokenType; + } + + tokenRange = NSMakeRange(srcOffset-2,2);\ + [NSException raise:STCompilerSyntaxException + format:@"Invalid character literal"]; + return STErrorTokenType; + + case '#': + start=srcOffset++; + c = PEEK_CHAR; + if(c=='(') + { + srcOffset++; + tokenRange = NSMakeRange(start,2); + return STArrayOpenTokenType; + } + + if([identStartCharacterSet characterIsMember:c]) + { + start=srcOffset++; + while([identCharacterSet characterIsMember:c] || c == ':') + { + c = GET_CHAR; + if(AT_END) + break; + } + srcOffset--; + tokenRange = NSMakeRange(start,srcOffset - start); + return STSymbolTokenType; + } + tokenRange = NSMakeRange(start,srcOffset - start); + return STSharpTokenType; + case ':': + start=srcOffset++; + c = PEEK_CHAR; + if(c == '=') + { + srcOffset++; + tokenRange = NSMakeRange(start,srcOffset - start); + return STAssignTokenType; + } + tokenRange = NSMakeRange(start,srcOffset - start); + return STColonTokenType; + +#define SIMPLE_TOKEN_RETURN(type) \ + tokenRange = NSMakeRange(srcOffset++,1);\ + return type + + case '(':SIMPLE_TOKEN_RETURN(STLParenTokenType); + case ')':SIMPLE_TOKEN_RETURN(STRParenTokenType); + case '|':SIMPLE_TOKEN_RETURN(STBarTokenType); + case ';':SIMPLE_TOKEN_RETURN(STSemicolonTokenType); + case '[':SIMPLE_TOKEN_RETURN(STBlockOpenTokenType); + case ']':SIMPLE_TOKEN_RETURN(STBlockCloseTokenType); + case '^':SIMPLE_TOKEN_RETURN(STReturnTokenType); + case '!':SIMPLE_TOKEN_RETURN(STSeparatorTokenType); + case '.':SIMPLE_TOKEN_RETURN(STDotTokenType); + case '\'': + start= 1 + srcOffset++; + for(;;) + { + + if(AT_END) + { + tokenRange = NSMakeRange(start-1,1);\ + + [NSException raise:STCompilerSyntaxException + format:@"Unterminated string"]; + return STErrorTokenType; + }; + + c = GET_CHAR; + if( c=='\\') + { + if(AT_END) + { + [NSException raise:STCompilerSyntaxException + format:@"\\ at end"]; + return STErrorTokenType; + } + + GET_CHAR; + } + else if( c=='\'' ) + { + if(AT_END) + { + return STStringTokenType; + } + + c = GET_CHAR; + if(c != '\'') + { + srcOffset--; + tokenRange = NSMakeRange(start, + srcOffset - start - 1); + return STStringTokenType; + } + + } + } + default: return STErrorTokenType; + } + } +} + +- (STTokenType)nextToken +{ + tokenType = [self readNextToken]; + return tokenType; +} + +- (void)unreadLastToken +{ + srcOffset = tokenRange.location; +} +@end diff --git a/Languages/Smalltalk/STStack.h b/Languages/Smalltalk/STStack.h new file mode 100644 index 0000000..5885c39 --- /dev/null +++ b/Languages/Smalltalk/STStack.h @@ -0,0 +1,45 @@ +/** + STStack.h + Stack object + + 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 STStack:NSObject +{ + unsigned size; + unsigned pointer; + id *stack; +} ++ stackWithSize:(unsigned)newSize; +- initWithSize:(unsigned)newSize; + +- (void)push:anObject; +- (id) pop; +- (void)popCount:(unsigned)count; +- (id) valueAtTop; +- (id) valueFromTop:(unsigned)offset; + +- (void)duplicateTop; + +- (void)empty; +@end diff --git a/Languages/Smalltalk/STStack.m b/Languages/Smalltalk/STStack.m new file mode 100644 index 0000000..231b6fe --- /dev/null +++ b/Languages/Smalltalk/STStack.m @@ -0,0 +1,128 @@ +/** + STStack.m + Temporaries and stack storage. + + Copyright (c) 2002 Free Software Foundation + + This file is part of the StepTalk project. + + */ + +#import "STStack.h" + +#import + +#import +#import + +@implementation STStack ++ stackWithSize:(unsigned)newSize +{ + return AUTORELEASE([[self alloc] initWithSize:newSize]); +} + +- initWithSize:(unsigned)newSize +{ + size = newSize; + pointer = 0; + stack = NSZoneMalloc( NSDefaultMallocZone(), size * sizeof(id) ); + + return [super init]; +} + +- (void)invalidPointer:(unsigned)ptr +{ + [NSException raise:STInternalInconsistencyException + format:@"%s (%p): invalid pointer %i (sp=%i size=%i)", + [self name],self, + ptr, + pointer, + size]; +} +- (void)dealloc +{ + NSZoneFree(NSDefaultMallocZone(),stack); + [super dealloc]; +} + +#define INDEX_IS_VALID(index) \ + ((index >= 0) && (index < size)) + +#define CHECK_POINTER(value) \ + do {\ + if(!INDEX_IS_VALID(value)) \ + {\ + [self invalidPointer:value];\ + } \ + }\ + while(0) +/* +- (void)setPointer:(unsigned)newPointer +{ + CHECK_POINTER(newPointer); + pointer=newPointer; +} +*/ + +- (int)pointer +{ + return pointer; +} + +- (void)push:(id)value +{ + CHECK_POINTER(pointer); + + NSDebugLLog(@"STStack",@"stack:%p %02i push '%@'",self,pointer,value); + + stack[pointer++] = value; +} + +- (void)duplicateTop +{ + [self push:[self valueAtTop]]; +} +#define CONVERT_NIL(obj) ((obj == STNil) ? nil : (obj)) +- (id)valueAtTop +{ + CHECK_POINTER(pointer-1); + + return CONVERT_NIL(stack[pointer-1]); +} +- (id)valueFromTop:(unsigned)index +{ + id value; + + CHECK_POINTER(pointer-index-1); + + value = stack[pointer - index - 1]; + NSDebugLLog(@"STStack",@"stack:%p %02i from top %i '%@'", + self,pointer,index,value); + + return CONVERT_NIL(value); +} + +- (id)pop +{ + CHECK_POINTER(pointer-1); + + NSDebugLLog(@"STStack",@"stack:%p %02i pop '%@'",self,pointer,stack[pointer-1]); + + pointer --; + return CONVERT_NIL(stack[pointer]); +} + +- (void)popCount:(unsigned)count +{ + CHECK_POINTER(pointer-count); + + NSDebugLLog(@"STStack",@"stack:%p %02i pop count %i (%i)",self, + pointer,count,pointer-count); + pointer -= count; +} +- (void)empty +{ + pointer = 0; +} + +@end diff --git a/Languages/Smalltalk/STTokenTypes.h b/Languages/Smalltalk/STTokenTypes.h new file mode 100644 index 0000000..24daf1e --- /dev/null +++ b/Languages/Smalltalk/STTokenTypes.h @@ -0,0 +1,56 @@ +/* + STTokenTypes.h + STSourceReader token types + + Copyright (c) 2002 Free Software Foundation + + This file is part of the StpTalk 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 +*/ + +typedef enum +{ + STInvalidTokenType, + STSeparatorTokenType, // ! + STBarTokenType, // | + STReturnTokenType, // ^ + STColonTokenType, // : + STSemicolonTokenType, // ; + STDotTokenType, // . + STLParenTokenType, // ( + STRParenTokenType, // ) + STBlockOpenTokenType, // [ + STBlockCloseTokenType, // ] + STArrayOpenTokenType, // #( + STSharpTokenType, // # + STAssignTokenType, // := + + STErrorTokenType, + STIdentifierTokenType, // thisIsIdentifier + STKeywordTokenType, // thisIsKeyword: + + STBinarySelectorTokenType, // +,-,*,/ + STSymbolTokenType, // #thisIsSymbol + STStringTokenType, // 'This is string' + + STCharacterTokenType, // $a (any single alphanum character) + STNumberTokenType, // -?[0-9]+ + + STMethodTokenType, // method token (for chunk reader) + + STEndTokenType + +} STTokenType; diff --git a/Languages/Smalltalk/STUndefinedObject+additions.h b/Languages/Smalltalk/STUndefinedObject+additions.h new file mode 100644 index 0000000..7d8ed76 --- /dev/null +++ b/Languages/Smalltalk/STUndefinedObject+additions.h @@ -0,0 +1,36 @@ +/** + STUndefinedObject.h + Wrapper for nil object + + 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 + +@class STBlock; + +@interface STUndefinedObject(SmalltalkAdditions) +- ifFalse:(STBlock *)block ifTrue:(STBlock *)anotherBlock; +- ifTrue:(STBlock *)block ifFalse:(STBlock *)anotherBlock; +- ifTrue:(STBlock *)block; +- ifFalse:(STBlock *)block; +- ifNil:(STBlock *)block; +- notNil:(STBlock *)block; +- (BOOL)isNil; +@end diff --git a/Languages/Smalltalk/STUndefinedObject+additions.m b/Languages/Smalltalk/STUndefinedObject+additions.m new file mode 100644 index 0000000..5288e21 --- /dev/null +++ b/Languages/Smalltalk/STUndefinedObject+additions.m @@ -0,0 +1,54 @@ +/** + STUndefinedObject.m + Wrapper for nil object + + Copyright (c) 2002 Free Software Foundation + + This file is part of the StepTalk project. + + */ +#import "STUndefinedObject+additions.h" + +#import "STBlock.h" +#import + +#import +#import + +@implementation STUndefinedObject(SmalltalkAdditions) +- (BOOL)isNil +{ + return YES; +} + +- ifNil:(STBlock *)block +{ + return [block value]; +} + +- notNil:(STBlock *)block +{ + return nil; +} + +- ifFalse:(STBlock *)block +{ + return [block value]; +} + +- ifTrue:(STBlock *)block +{ + return nil; +} + +- ifFalse:(STBlock *)block ifTrue:(STBlock *)anotherBlock +{ + return [block value]; +} + +- ifTrue:(STBlock *)block ifFalse:(STBlock *)anotherBlock +{ + return [anotherBlock value]; +} +@end + diff --git a/Languages/Smalltalk/SmalltalkEngine.h b/Languages/Smalltalk/SmalltalkEngine.h new file mode 100644 index 0000000..456a3aa --- /dev/null +++ b/Languages/Smalltalk/SmalltalkEngine.h @@ -0,0 +1,32 @@ +/** + SmalltalkEngine + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2001 Oct 24 + + 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 + +@interface SmalltalkEngine:STEngine +{ +} +@end diff --git a/Languages/Smalltalk/SmalltalkEngine.m b/Languages/Smalltalk/SmalltalkEngine.m new file mode 100644 index 0000000..6784f36 --- /dev/null +++ b/Languages/Smalltalk/SmalltalkEngine.m @@ -0,0 +1,80 @@ +/** + SmalltalkEngine + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2001 Oct 24 + + 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 "SmalltalkEngine.h" + +#import "STBytecodeInterpreter.h" +#import "STCompiler.h" +#import "STCompiledCode.h" + +#import +#import +#import + +@implementation SmalltalkEngine +- (BOOL)canExecuteCode:(NSString *)sourceCode +{ + STCompiler *compiler; + STCompiledCode *code = nil; + BOOL retval = NO; + + compiler = [[STCompiler alloc] init]; + + NS_DURING + code = [compiler compileString:sourceCode]; + NS_HANDLER + NSLog(@"Smalltalk: Ignoring: %@", [localException reason]); + NS_ENDHANDLER + + if(code) + { + retval = YES; + } + + RELEASE(compiler); + + return retval; +} + +- (id) executeCode:(NSString *)sourceCode + inEnvironment:(STEnvironment *)env +{ + STCompiler *compiler; + STCompiledScript *script; + id retval = nil; + + compiler = [[STCompiler alloc] init]; + + [compiler setEnvironment:env]; + + script = [compiler compileString:sourceCode]; + retval = [script executeInEnvironment:env]; + + RELEASE(compiler); + + return retval; +} +@end diff --git a/Languages/Smalltalk/SmalltalkInfo.plist b/Languages/Smalltalk/SmalltalkInfo.plist new file mode 100644 index 0000000..26ed217 --- /dev/null +++ b/Languages/Smalltalk/SmalltalkInfo.plist @@ -0,0 +1,3 @@ +{ + STFileTypes = ( "st", "stalk" ); +} diff --git a/Modules/AppKit/AppKitConstants.list b/Modules/AppKit/AppKitConstants.list new file mode 100644 index 0000000..e464a2d --- /dev/null +++ b/Modules/AppKit/AppKitConstants.list @@ -0,0 +1,460 @@ +# AppKit Constants +# + +# id NSApp + +id NSModalPanelRunLoopMode +id NSEventTrackingRunLoopMode + +id NSFontAttributeName +id NSParagraphStyleAttributeName +id NSForegroundColorAttributeName +id NSUnderlineStyleAttributeName +id NSSuperscriptAttributeName +id NSBackgroundColorAttributeName +id NSAttachmentAttributeName +id NSLigatureAttributeName +id NSBaselineOffsetAttributeName +id NSKernAttributeName +id NSLinkAttributeName + +id NSDataLinkFileNameExtension + +id NSAFMAscender +id NSAFMCapHeight +id NSAFMCharacterSet +id NSAFMDescender +id NSAFMEncodingScheme +id NSAFMFamilyName +id NSAFMFontName +id NSAFMFormatVersion +id NSAFMFullName +id NSAFMItalicAngle +id NSAFMMappingScheme +id NSAFMNotice +id NSAFMUnderlinePosition +id NSAFMUnderlineThickness +id NSAFMVersion +id NSAFMWeight +id NSAFMXHeight + +id NSCalibratedWhiteColorSpace +id NSCalibratedBlackColorSpace +id NSCalibratedRGBColorSpace +id NSDeviceWhiteColorSpace +id NSDeviceBlackColorSpace +id NSDeviceRGBColorSpace +id NSDeviceCMYKColorSpace +id NSNamedColorSpace +id NSCustomColorSpace + +int NSDefaultDepth +int NSTwoBitGrayDepth +int NSEightBitGrayDepth +int NSEightBitRGBDepth +int NSTwelveBitRGBDepth +int GSSixteenBitRGBDepth +int NSTwentyFourBitRGBDepth + +float NSBlack +float NSDarkGray +float NSWhite +float NSLightGray +float NSGray + +id NSDeviceResolution +id NSDeviceColorSpaceName +id NSDeviceBitsPerSample +id NSDeviceIsScreen +id NSDeviceIsPrinter +id NSDeviceSize +id NSInterfaceStyleDefault + +id NSColorPboardType +id NSFileContentsPboardType +id NSFilenamesPboardType +id NSFontPboardType +id NSRulerPboardType +id NSPostScriptPboardType +id NSTabularTextPboardType +id NSRTFPboardType +id NSRTFDPboardType +id NSTIFFPboardType +id NSDataLinkPboardType +id NSGeneralPboardType +id NSDragPboard +id NSFindPboard +id NSFontPboard +id NSGeneralPboard +id NSRulerPboard + +id NSPrintAllPages +id NSPrintBottomMargin +id NSPrintCopies +id NSPrintFaxCoverSheetName +id NSPrintFaxHighResolution +id NSPrintFaxModem +id NSPrintFaxReceiverNames +id NSPrintFaxReceiverNumbers +id NSPrintFaxReturnReceipt +id NSPrintFaxSendTime +id NSPrintFaxTrimPageEnds +id NSPrintFaxUseCoverSheet +id NSPrintFirstPage +id NSPrintHorizontalPagination +id NSPrintHorizontallyCentered +id NSPrintJobDisposition +id NSPrintJobFeatures +id NSPrintLastPage +id NSPrintLeftMargin +id NSPrintManualFeed +id NSPrintOrientation +id NSPrintPagesPerSheet +id NSPrintPaperFeed +id NSPrintPaperName +id NSPrintPaperSize +id NSPrintPrinter +id NSPrintReversePageOrder +id NSPrintRightMargin +id NSPrintSavePath +id NSPrintScalingFactor +id NSPrintTopMargin +id NSPrintVerticalPagination +id NSPrintVerticallyCentered +id NSPrintCancelJob +id NSPrintFaxJob +id NSPrintPreviewJob +id NSPrintSaveJob +id NSPrintSpoolJob +id NSOldSelectedCharacterRange + +# FIXME: + +# NSSize NSIconSize +# NSSize NSTokenSize + +id NSPlainFileType +id NSDirectoryFileType +id NSApplicationFileType +id NSFilesystemFileType +id NSShellCommandFileType +id NSWorkspaceCompressOperation +id NSWorkspaceCopyOperation +id NSWorkspaceDecompressOperation +id NSWorkspaceDecryptOperation +id NSWorkspaceDestroyOperation +id NSWorkspaceDuplicateOperation +id NSWorkspaceEncryptOperation +id NSWorkspaceLinkOperation +id NSWorkspaceMoveOperation +id NSWorkspaceRecycleOperation + +int NSRunStoppedResponse +int NSRunAbortedResponse +int NSRunContinuesResponse + +int GSNoUnderlineStyle +int NSSingleUnderlineStyle + +int NSButtLineCapStyle +int NSRoundLineCapStyle +int NSSquareLineCapStyle + +int NSMiterLineJoinStyle +int NSRoundLineJoinStyle +int NSBevelLineJoinStyle + +int NSNonZeroWindingRule +int NSEvenOddWindingRule +int NSMoveToBezierPathElement +int NSLineToBezierPathElement +int NSCurveToBezierPathElement +int NSClosePathBezierPathElement + +int NSNoTitle +int NSAboveTop +int NSAtTop +int NSBelowTop +int NSAboveBottom +int NSAtBottom +int NSBelowBottom + +int NSTIFFCompressionNone +int NSTIFFCompressionCCITTFAX3 +int NSTIFFCompressionCCITTFAX4 +int NSTIFFCompressionLZW +int NSTIFFCompressionJPEG +int NSTIFFCompressionNEXT +int NSTIFFCompressionPackBits +int NSTIFFCompressionOldJPEG + +int NSTIFFFileType +int NSBMPFileType +int NSGIFFileType +int NSJPEGFileType +int NSPNGFileType + +int NSMomentaryPushButton +int NSPushOnPushOffButton +int NSToggleButton +int NSSwitchButton +int NSRadioButton +int NSMomentaryChangeButton +int NSOnOffButton +int NSMomentaryLight + +int NSRoundedBezelStyle +int NSRegularSquareBezelStyle +int NSThickSquareBezelStyle +int NSThickerSquareBezelStyle +int NSNeXTBezelStyle +int NSPushButtonBezelStyle +int NSSmallIconButtonBezelStyle +int NSMediumIconButtonBezelStyle +int NSLargeIconButtonBezelStyle + +int NSGradientNone +int NSGradientConcaveWeak +int NSGradientConcaveStrong +int NSGradientConvexWeak +int NSGradientConvexStrong + +# int NSLeftAlignedParagraph +# int NSRightAlignedParagraph +# int NSCenterAlignedParagraph +# int NSJustificationAlignedParagraph +# int NSFirstIndentParagraph +# int NSIndentParagraph +# int NSAddTabParagraph +# int NSRemoveTabParagraph +# int NSLeftMarginParagraph +# int NSRightMarginParagraph + +# int NSTextBlockSize + +int NSNullCellType +int NSTextCellType +int NSImageCellType + +int NSAnyType +int NSIntType +int NSPositiveIntType +int NSFloatType +int NSPositiveFloatType +int NSDateType +int NSDoubleType +int NSPositiveDoubleType + +int NSNoImage +int NSImageOnly +int NSImageLeft +int NSImageRight +int NSImageBelow +int NSImageAbove +int NSImageOverlaps + +int NSCellDisabled +int NSCellState +int NSPushInCell +int NSCellEditable +int NSChangeGrayCell +int NSCellHighlighted +int NSCellLightsByContents +int NSCellLightsByGray +int NSChangeBackgroundCell +int NSCellLightsByBackground +int NSCellIsBordered +int NSCellHasOverlappingImage +int NSCellHasImageHorizontal +int NSCellHasImageOnLeftOrBottom +int NSCellChangesContents +int NSCellIsInsetButton +int NSCellAllowsMixedState + +int NSNoCellMask +int NSContentsCellMask +int NSPushInCellMask +int NSChangeGrayCellMask +int NSChangeBackgroundCellMask +int NSOffState +int NSOnState +int NSMixedState + +int NSDefaultControlTint +int NSClearControlTint + +int NSGrayModeColorPanel +int NSRGBModeColorPanel +int NSCMYKModeColorPanel +int NSHSBModeColorPanel +int NSCustomPaletteModeColorPanel +int NSColorListModeColorPanel +int NSWheelModeColorPanel + +int NSColorPanelGrayModeMask +int NSColorPanelRGBModeMask +int NSColorPanelCMYKModeMask +int NSColorPanelHSBModeMask +int NSColorPanelCustomPaletteModeMask +int NSColorPanelColorListModeMask +int NSColorPanelWheelModeMask +int NSColorPanelAllModesMask + +# GSCursorTypes +int GSArrowCursor +int GSIBeamCursor + +# NSDataLinkDisposition +int NSLinkInDestination +int NSLinkInSource +int NSLinkBroken + +# NSDataLinkUpdateMode +int NSUpdateContinuously +int NSUpdateWhenSourceSaved +int NSUpdateManually +int NSUpdateNever + +int NSChangeDone +int NSChangeUndone +int NSChangeCleared + +int NSSaveOperation +int NSSaveAsOperation +int NSSaveToOperation + +int NSDragOperationNone +int NSDragOperationCopy +int NSDragOperationLink +int NSDragOperationGeneric +int NSDragOperationPrivate +int NSDragOperationAll + +# GSFileWrapperType + +int GSFileWrapperDirectoryType +int GSFileWrapperRegularFileType +int GSFileWrapperSymbolicLinkType + +int NSControlGlyph +int NSNullGlyph + +# NSGlyphRelation + +int NSGlyphBelow +int NSGlyphAbove + +# NSMultibyteGlyphPacking +int NSOneByteGlyphPacking +int NSJapaneseEUCGlyphPacking +int NSAsciiWithDoubleByteEUCGlyphPacking +int NSTwoByteGlyphPacking +int NSFourByteGlyphPacking + +int NSItalicFontMask +int NSUnitalicFontMask +int NSBoldFontMask +int NSUnboldFontMask +int NSNarrowFontMask +int NSExpandedFontMask +int NSCondensedFontMask +int NSSmallCapsFontMask +int NSPosterFontMask +int NSCompressedFontMask +int NSNonStandardCharacterSetFontMask +int NSFixedPitchFontMask + +# NSFontTag + +int NSNoFontChangeAction +int NSViaPanelFontAction +int NSAddTraitFontAction +int NSRemoveTraitFontAction +int NSSizeUpFontAction +int NSSizeDownFontAction +int NSHeavierFontAction +int NSLighterFontAction + +int NSFPPreviewButton +int NSFPRevertButton +int NSFPSetButton +int NSFPPreviewField +int NSFPSizeField +int NSFPSizeTitle +int NSFPCurrentField + +int NSFPFamilyBrowser +int NSFPFaceBrowser +int NSFPSizeBrowser + +# NSBackingStoreType + +int NSBackingStoreRetained +int NSBackingStoreNonretained +int NSBackingStoreBuffered + + +# NSCompositingOperation + +int NSCompositeClear +int NSCompositeCopy +int NSCompositeSourceOver +int NSCompositeSourceIn +int NSCompositeSourceOut +int NSCompositeSourceAtop +int NSCompositeDestinationOver +int NSCompositeDestinationIn +int NSCompositeDestinationOut +int NSCompositeDestinationAtop +int NSCompositeXOR +int NSCompositePlusDarker +int NSCompositeHighlight +int NSCompositePlusLighter + +# NSWindowOrderingMode + +int NSWindowAbove +int NSWindowBelow +int NSWindowOut + +# GSWindowInputState +int GSTitleBarKey +int GSTitleBarNormal +int GSTitleBarMain + +# NSImageScaling +int NSScaleProportionally +int NSScaleToFit +int NSScaleNone + +# NSImageAlignment +int NSImageAlignCenter +int NSImageAlignTop +int NSImageAlignTopLeft +int NSImageAlignTopRight +int NSImageAlignLeft +int NSImageAlignBottom +int NSImageAlignBottomLeft +int NSImageAlignBottomRight +int NSImageAlignRight + +# NSImageFrameStyle + +int NSImageFrameNone +int NSImageFramePhoto +int NSImageFrameGrayBezel +int NSImageFrameGroove +int NSImageFrameButton + +# NSPanel + +int NSUtilityWindowMask +int NSDocModalWindowMask +int NSOKButton +int NSCancelButton + +int NSAlertDefaultReturn +int NSAlertAlternateReturn +int NSAlertOtherReturn +int NSAlertErrorReturn + diff --git a/Modules/AppKit/AppKitConstants.m b/Modules/AppKit/AppKitConstants.m new file mode 100644 index 0000000..16f42eb --- /dev/null +++ b/Modules/AppKit/AppKitConstants.m @@ -0,0 +1,430 @@ +/** + AppKitConstants.m + + NOTE: Do not edit this file, it is automaticaly generated. + + 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 +#import +#import + +#import +#import + +#import +#import + + +NSDictionary *STGetAppKitConstants(void) +{ + NSMutableDictionary *dict = [NSMutableDictionary dictionary]; + Class numberClass = [NSNumber class]; + IMP numberWithInt; + IMP numberWithFloat; + IMP setObject_forKey; + + SEL numberWithInt_sel = @selector(numberWithInt:); + SEL numberWithFloat_sel = @selector(numberWithFloat:); + SEL setObject_forKey_sel = @selector(setObject:forKey:); + + numberWithInt = [NSNumber methodForSelector:numberWithInt_sel]; + numberWithFloat = [NSNumber methodForSelector:numberWithFloat_sel]; + setObject_forKey = [dict methodForSelector:setObject_forKey_sel]; + +#define ADD_id_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, obj, name) + +#define ADD_int_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, \ + numberWithInt(numberClass, numberWithInt_sel, obj), \ + name) + +#define ADD_float_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, \ + numberWithFloat(numberClass, numberWithInt_sel, obj), \ + name) + + ADD_id_OBJECT(NSModalPanelRunLoopMode,@"NSModalPanelRunLoopMode"); + ADD_id_OBJECT(NSEventTrackingRunLoopMode,@"NSEventTrackingRunLoopMode"); + ADD_id_OBJECT(NSFontAttributeName,@"NSFontAttributeName"); + ADD_id_OBJECT(NSParagraphStyleAttributeName,@"NSParagraphStyleAttributeName"); + ADD_id_OBJECT(NSForegroundColorAttributeName,@"NSForegroundColorAttributeName"); + ADD_id_OBJECT(NSUnderlineStyleAttributeName,@"NSUnderlineStyleAttributeName"); + ADD_id_OBJECT(NSSuperscriptAttributeName,@"NSSuperscriptAttributeName"); + ADD_id_OBJECT(NSBackgroundColorAttributeName,@"NSBackgroundColorAttributeName"); + ADD_id_OBJECT(NSAttachmentAttributeName,@"NSAttachmentAttributeName"); + ADD_id_OBJECT(NSLigatureAttributeName,@"NSLigatureAttributeName"); + ADD_id_OBJECT(NSBaselineOffsetAttributeName,@"NSBaselineOffsetAttributeName"); + ADD_id_OBJECT(NSKernAttributeName,@"NSKernAttributeName"); + ADD_id_OBJECT(NSLinkAttributeName,@"NSLinkAttributeName"); + ADD_id_OBJECT(NSDataLinkFileNameExtension,@"NSDataLinkFileNameExtension"); + ADD_id_OBJECT(NSAFMAscender,@"NSAFMAscender"); + ADD_id_OBJECT(NSAFMCapHeight,@"NSAFMCapHeight"); + ADD_id_OBJECT(NSAFMCharacterSet,@"NSAFMCharacterSet"); + ADD_id_OBJECT(NSAFMDescender,@"NSAFMDescender"); + ADD_id_OBJECT(NSAFMEncodingScheme,@"NSAFMEncodingScheme"); + ADD_id_OBJECT(NSAFMFamilyName,@"NSAFMFamilyName"); + ADD_id_OBJECT(NSAFMFontName,@"NSAFMFontName"); + ADD_id_OBJECT(NSAFMFormatVersion,@"NSAFMFormatVersion"); + ADD_id_OBJECT(NSAFMFullName,@"NSAFMFullName"); + ADD_id_OBJECT(NSAFMItalicAngle,@"NSAFMItalicAngle"); + ADD_id_OBJECT(NSAFMMappingScheme,@"NSAFMMappingScheme"); + ADD_id_OBJECT(NSAFMNotice,@"NSAFMNotice"); + ADD_id_OBJECT(NSAFMUnderlinePosition,@"NSAFMUnderlinePosition"); + ADD_id_OBJECT(NSAFMUnderlineThickness,@"NSAFMUnderlineThickness"); + ADD_id_OBJECT(NSAFMVersion,@"NSAFMVersion"); + ADD_id_OBJECT(NSAFMWeight,@"NSAFMWeight"); + ADD_id_OBJECT(NSAFMXHeight,@"NSAFMXHeight"); + ADD_id_OBJECT(NSCalibratedWhiteColorSpace,@"NSCalibratedWhiteColorSpace"); + ADD_id_OBJECT(NSCalibratedBlackColorSpace,@"NSCalibratedBlackColorSpace"); + ADD_id_OBJECT(NSCalibratedRGBColorSpace,@"NSCalibratedRGBColorSpace"); + ADD_id_OBJECT(NSDeviceWhiteColorSpace,@"NSDeviceWhiteColorSpace"); + ADD_id_OBJECT(NSDeviceBlackColorSpace,@"NSDeviceBlackColorSpace"); + ADD_id_OBJECT(NSDeviceRGBColorSpace,@"NSDeviceRGBColorSpace"); + ADD_id_OBJECT(NSDeviceCMYKColorSpace,@"NSDeviceCMYKColorSpace"); + ADD_id_OBJECT(NSNamedColorSpace,@"NSNamedColorSpace"); + ADD_id_OBJECT(NSCustomColorSpace,@"NSCustomColorSpace"); + ADD_int_OBJECT(NSDefaultDepth,@"NSDefaultDepth"); + ADD_int_OBJECT(NSTwoBitGrayDepth,@"NSTwoBitGrayDepth"); + ADD_int_OBJECT(NSEightBitGrayDepth,@"NSEightBitGrayDepth"); + ADD_int_OBJECT(NSEightBitRGBDepth,@"NSEightBitRGBDepth"); + ADD_int_OBJECT(NSTwelveBitRGBDepth,@"NSTwelveBitRGBDepth"); + ADD_int_OBJECT(GSSixteenBitRGBDepth,@"GSSixteenBitRGBDepth"); + ADD_int_OBJECT(NSTwentyFourBitRGBDepth,@"NSTwentyFourBitRGBDepth"); + ADD_float_OBJECT(NSBlack,@"NSBlack"); + ADD_float_OBJECT(NSDarkGray,@"NSDarkGray"); + ADD_float_OBJECT(NSWhite,@"NSWhite"); + ADD_float_OBJECT(NSLightGray,@"NSLightGray"); + ADD_float_OBJECT(NSGray,@"NSGray"); + ADD_id_OBJECT(NSDeviceResolution,@"NSDeviceResolution"); + ADD_id_OBJECT(NSDeviceColorSpaceName,@"NSDeviceColorSpaceName"); + ADD_id_OBJECT(NSDeviceBitsPerSample,@"NSDeviceBitsPerSample"); + ADD_id_OBJECT(NSDeviceIsScreen,@"NSDeviceIsScreen"); + ADD_id_OBJECT(NSDeviceIsPrinter,@"NSDeviceIsPrinter"); + ADD_id_OBJECT(NSDeviceSize,@"NSDeviceSize"); + ADD_id_OBJECT(NSInterfaceStyleDefault,@"NSInterfaceStyleDefault"); + ADD_id_OBJECT(NSColorPboardType,@"NSColorPboardType"); + ADD_id_OBJECT(NSFileContentsPboardType,@"NSFileContentsPboardType"); + ADD_id_OBJECT(NSFilenamesPboardType,@"NSFilenamesPboardType"); + ADD_id_OBJECT(NSFontPboardType,@"NSFontPboardType"); + ADD_id_OBJECT(NSRulerPboardType,@"NSRulerPboardType"); + ADD_id_OBJECT(NSPostScriptPboardType,@"NSPostScriptPboardType"); + ADD_id_OBJECT(NSTabularTextPboardType,@"NSTabularTextPboardType"); + ADD_id_OBJECT(NSRTFPboardType,@"NSRTFPboardType"); + ADD_id_OBJECT(NSRTFDPboardType,@"NSRTFDPboardType"); + ADD_id_OBJECT(NSTIFFPboardType,@"NSTIFFPboardType"); + ADD_id_OBJECT(NSDataLinkPboardType,@"NSDataLinkPboardType"); + ADD_id_OBJECT(NSGeneralPboardType,@"NSGeneralPboardType"); + ADD_id_OBJECT(NSDragPboard,@"NSDragPboard"); + ADD_id_OBJECT(NSFindPboard,@"NSFindPboard"); + ADD_id_OBJECT(NSFontPboard,@"NSFontPboard"); + ADD_id_OBJECT(NSGeneralPboard,@"NSGeneralPboard"); + ADD_id_OBJECT(NSRulerPboard,@"NSRulerPboard"); + ADD_id_OBJECT(NSPrintAllPages,@"NSPrintAllPages"); + ADD_id_OBJECT(NSPrintBottomMargin,@"NSPrintBottomMargin"); + ADD_id_OBJECT(NSPrintCopies,@"NSPrintCopies"); + ADD_id_OBJECT(NSPrintFaxCoverSheetName,@"NSPrintFaxCoverSheetName"); + ADD_id_OBJECT(NSPrintFaxHighResolution,@"NSPrintFaxHighResolution"); + ADD_id_OBJECT(NSPrintFaxModem,@"NSPrintFaxModem"); + ADD_id_OBJECT(NSPrintFaxReceiverNames,@"NSPrintFaxReceiverNames"); + ADD_id_OBJECT(NSPrintFaxReceiverNumbers,@"NSPrintFaxReceiverNumbers"); + ADD_id_OBJECT(NSPrintFaxReturnReceipt,@"NSPrintFaxReturnReceipt"); + ADD_id_OBJECT(NSPrintFaxSendTime,@"NSPrintFaxSendTime"); + ADD_id_OBJECT(NSPrintFaxTrimPageEnds,@"NSPrintFaxTrimPageEnds"); + ADD_id_OBJECT(NSPrintFaxUseCoverSheet,@"NSPrintFaxUseCoverSheet"); + ADD_id_OBJECT(NSPrintFirstPage,@"NSPrintFirstPage"); + ADD_id_OBJECT(NSPrintHorizontalPagination,@"NSPrintHorizontalPagination"); + ADD_id_OBJECT(NSPrintHorizontallyCentered,@"NSPrintHorizontallyCentered"); + ADD_id_OBJECT(NSPrintJobDisposition,@"NSPrintJobDisposition"); + ADD_id_OBJECT(NSPrintJobFeatures,@"NSPrintJobFeatures"); + ADD_id_OBJECT(NSPrintLastPage,@"NSPrintLastPage"); + ADD_id_OBJECT(NSPrintLeftMargin,@"NSPrintLeftMargin"); + ADD_id_OBJECT(NSPrintManualFeed,@"NSPrintManualFeed"); + ADD_id_OBJECT(NSPrintOrientation,@"NSPrintOrientation"); + ADD_id_OBJECT(NSPrintPagesPerSheet,@"NSPrintPagesPerSheet"); + ADD_id_OBJECT(NSPrintPaperFeed,@"NSPrintPaperFeed"); + ADD_id_OBJECT(NSPrintPaperName,@"NSPrintPaperName"); + ADD_id_OBJECT(NSPrintPaperSize,@"NSPrintPaperSize"); + ADD_id_OBJECT(NSPrintPrinter,@"NSPrintPrinter"); + ADD_id_OBJECT(NSPrintReversePageOrder,@"NSPrintReversePageOrder"); + ADD_id_OBJECT(NSPrintRightMargin,@"NSPrintRightMargin"); + ADD_id_OBJECT(NSPrintSavePath,@"NSPrintSavePath"); + ADD_id_OBJECT(NSPrintScalingFactor,@"NSPrintScalingFactor"); + ADD_id_OBJECT(NSPrintTopMargin,@"NSPrintTopMargin"); + ADD_id_OBJECT(NSPrintVerticalPagination,@"NSPrintVerticalPagination"); + ADD_id_OBJECT(NSPrintVerticallyCentered,@"NSPrintVerticallyCentered"); + ADD_id_OBJECT(NSPrintCancelJob,@"NSPrintCancelJob"); + ADD_id_OBJECT(NSPrintFaxJob,@"NSPrintFaxJob"); + ADD_id_OBJECT(NSPrintPreviewJob,@"NSPrintPreviewJob"); + ADD_id_OBJECT(NSPrintSaveJob,@"NSPrintSaveJob"); + ADD_id_OBJECT(NSPrintSpoolJob,@"NSPrintSpoolJob"); + ADD_id_OBJECT(NSOldSelectedCharacterRange,@"NSOldSelectedCharacterRange"); + ADD_id_OBJECT(NSPlainFileType,@"NSPlainFileType"); + ADD_id_OBJECT(NSDirectoryFileType,@"NSDirectoryFileType"); + ADD_id_OBJECT(NSApplicationFileType,@"NSApplicationFileType"); + ADD_id_OBJECT(NSFilesystemFileType,@"NSFilesystemFileType"); + ADD_id_OBJECT(NSShellCommandFileType,@"NSShellCommandFileType"); + ADD_id_OBJECT(NSWorkspaceCompressOperation,@"NSWorkspaceCompressOperation"); + ADD_id_OBJECT(NSWorkspaceCopyOperation,@"NSWorkspaceCopyOperation"); + ADD_id_OBJECT(NSWorkspaceDecompressOperation,@"NSWorkspaceDecompressOperation"); + ADD_id_OBJECT(NSWorkspaceDecryptOperation,@"NSWorkspaceDecryptOperation"); + ADD_id_OBJECT(NSWorkspaceDestroyOperation,@"NSWorkspaceDestroyOperation"); + ADD_id_OBJECT(NSWorkspaceDuplicateOperation,@"NSWorkspaceDuplicateOperation"); + ADD_id_OBJECT(NSWorkspaceEncryptOperation,@"NSWorkspaceEncryptOperation"); + ADD_id_OBJECT(NSWorkspaceLinkOperation,@"NSWorkspaceLinkOperation"); + ADD_id_OBJECT(NSWorkspaceMoveOperation,@"NSWorkspaceMoveOperation"); + ADD_id_OBJECT(NSWorkspaceRecycleOperation,@"NSWorkspaceRecycleOperation"); + ADD_int_OBJECT(NSRunStoppedResponse,@"NSRunStoppedResponse"); + ADD_int_OBJECT(NSRunAbortedResponse,@"NSRunAbortedResponse"); + ADD_int_OBJECT(NSRunContinuesResponse,@"NSRunContinuesResponse"); + ADD_int_OBJECT(GSNoUnderlineStyle,@"GSNoUnderlineStyle"); + ADD_int_OBJECT(NSSingleUnderlineStyle,@"NSSingleUnderlineStyle"); + ADD_int_OBJECT(NSButtLineCapStyle,@"NSButtLineCapStyle"); + ADD_int_OBJECT(NSRoundLineCapStyle,@"NSRoundLineCapStyle"); + ADD_int_OBJECT(NSSquareLineCapStyle,@"NSSquareLineCapStyle"); + ADD_int_OBJECT(NSMiterLineJoinStyle,@"NSMiterLineJoinStyle"); + ADD_int_OBJECT(NSRoundLineJoinStyle,@"NSRoundLineJoinStyle"); + ADD_int_OBJECT(NSBevelLineJoinStyle,@"NSBevelLineJoinStyle"); + ADD_int_OBJECT(NSNonZeroWindingRule,@"NSNonZeroWindingRule"); + ADD_int_OBJECT(NSEvenOddWindingRule,@"NSEvenOddWindingRule"); + ADD_int_OBJECT(NSMoveToBezierPathElement,@"NSMoveToBezierPathElement"); + ADD_int_OBJECT(NSLineToBezierPathElement,@"NSLineToBezierPathElement"); + ADD_int_OBJECT(NSCurveToBezierPathElement,@"NSCurveToBezierPathElement"); + ADD_int_OBJECT(NSClosePathBezierPathElement,@"NSClosePathBezierPathElement"); + ADD_int_OBJECT(NSNoTitle,@"NSNoTitle"); + ADD_int_OBJECT(NSAboveTop,@"NSAboveTop"); + ADD_int_OBJECT(NSAtTop,@"NSAtTop"); + ADD_int_OBJECT(NSBelowTop,@"NSBelowTop"); + ADD_int_OBJECT(NSAboveBottom,@"NSAboveBottom"); + ADD_int_OBJECT(NSAtBottom,@"NSAtBottom"); + ADD_int_OBJECT(NSBelowBottom,@"NSBelowBottom"); + ADD_int_OBJECT(NSTIFFCompressionNone,@"NSTIFFCompressionNone"); + ADD_int_OBJECT(NSTIFFCompressionCCITTFAX3,@"NSTIFFCompressionCCITTFAX3"); + ADD_int_OBJECT(NSTIFFCompressionCCITTFAX4,@"NSTIFFCompressionCCITTFAX4"); + ADD_int_OBJECT(NSTIFFCompressionLZW,@"NSTIFFCompressionLZW"); + ADD_int_OBJECT(NSTIFFCompressionJPEG,@"NSTIFFCompressionJPEG"); + ADD_int_OBJECT(NSTIFFCompressionNEXT,@"NSTIFFCompressionNEXT"); + ADD_int_OBJECT(NSTIFFCompressionPackBits,@"NSTIFFCompressionPackBits"); + ADD_int_OBJECT(NSTIFFCompressionOldJPEG,@"NSTIFFCompressionOldJPEG"); + ADD_int_OBJECT(NSTIFFFileType,@"NSTIFFFileType"); + ADD_int_OBJECT(NSBMPFileType,@"NSBMPFileType"); + ADD_int_OBJECT(NSGIFFileType,@"NSGIFFileType"); + ADD_int_OBJECT(NSJPEGFileType,@"NSJPEGFileType"); + ADD_int_OBJECT(NSPNGFileType,@"NSPNGFileType"); + ADD_int_OBJECT(NSMomentaryPushButton,@"NSMomentaryPushButton"); + ADD_int_OBJECT(NSPushOnPushOffButton,@"NSPushOnPushOffButton"); + ADD_int_OBJECT(NSToggleButton,@"NSToggleButton"); + ADD_int_OBJECT(NSSwitchButton,@"NSSwitchButton"); + ADD_int_OBJECT(NSRadioButton,@"NSRadioButton"); + ADD_int_OBJECT(NSMomentaryChangeButton,@"NSMomentaryChangeButton"); + ADD_int_OBJECT(NSOnOffButton,@"NSOnOffButton"); + ADD_int_OBJECT(NSMomentaryLight,@"NSMomentaryLight"); + ADD_int_OBJECT(NSRoundedBezelStyle,@"NSRoundedBezelStyle"); + ADD_int_OBJECT(NSRegularSquareBezelStyle,@"NSRegularSquareBezelStyle"); + ADD_int_OBJECT(NSThickSquareBezelStyle,@"NSThickSquareBezelStyle"); + ADD_int_OBJECT(NSThickerSquareBezelStyle,@"NSThickerSquareBezelStyle"); + ADD_int_OBJECT(NSNeXTBezelStyle,@"NSNeXTBezelStyle"); + ADD_int_OBJECT(NSPushButtonBezelStyle,@"NSPushButtonBezelStyle"); + ADD_int_OBJECT(NSSmallIconButtonBezelStyle,@"NSSmallIconButtonBezelStyle"); + ADD_int_OBJECT(NSMediumIconButtonBezelStyle,@"NSMediumIconButtonBezelStyle"); + ADD_int_OBJECT(NSLargeIconButtonBezelStyle,@"NSLargeIconButtonBezelStyle"); + ADD_int_OBJECT(NSGradientNone,@"NSGradientNone"); + ADD_int_OBJECT(NSGradientConcaveWeak,@"NSGradientConcaveWeak"); + ADD_int_OBJECT(NSGradientConcaveStrong,@"NSGradientConcaveStrong"); + ADD_int_OBJECT(NSGradientConvexWeak,@"NSGradientConvexWeak"); + ADD_int_OBJECT(NSGradientConvexStrong,@"NSGradientConvexStrong"); + ADD_int_OBJECT(NSNullCellType,@"NSNullCellType"); + ADD_int_OBJECT(NSTextCellType,@"NSTextCellType"); + ADD_int_OBJECT(NSImageCellType,@"NSImageCellType"); + ADD_int_OBJECT(NSAnyType,@"NSAnyType"); + ADD_int_OBJECT(NSIntType,@"NSIntType"); + ADD_int_OBJECT(NSPositiveIntType,@"NSPositiveIntType"); + ADD_int_OBJECT(NSFloatType,@"NSFloatType"); + ADD_int_OBJECT(NSPositiveFloatType,@"NSPositiveFloatType"); + ADD_int_OBJECT(NSDateType,@"NSDateType"); + ADD_int_OBJECT(NSDoubleType,@"NSDoubleType"); + ADD_int_OBJECT(NSPositiveDoubleType,@"NSPositiveDoubleType"); + ADD_int_OBJECT(NSNoImage,@"NSNoImage"); + ADD_int_OBJECT(NSImageOnly,@"NSImageOnly"); + ADD_int_OBJECT(NSImageLeft,@"NSImageLeft"); + ADD_int_OBJECT(NSImageRight,@"NSImageRight"); + ADD_int_OBJECT(NSImageBelow,@"NSImageBelow"); + ADD_int_OBJECT(NSImageAbove,@"NSImageAbove"); + ADD_int_OBJECT(NSImageOverlaps,@"NSImageOverlaps"); + ADD_int_OBJECT(NSCellDisabled,@"NSCellDisabled"); + ADD_int_OBJECT(NSCellState,@"NSCellState"); + ADD_int_OBJECT(NSPushInCell,@"NSPushInCell"); + ADD_int_OBJECT(NSCellEditable,@"NSCellEditable"); + ADD_int_OBJECT(NSChangeGrayCell,@"NSChangeGrayCell"); + ADD_int_OBJECT(NSCellHighlighted,@"NSCellHighlighted"); + ADD_int_OBJECT(NSCellLightsByContents,@"NSCellLightsByContents"); + ADD_int_OBJECT(NSCellLightsByGray,@"NSCellLightsByGray"); + ADD_int_OBJECT(NSChangeBackgroundCell,@"NSChangeBackgroundCell"); + ADD_int_OBJECT(NSCellLightsByBackground,@"NSCellLightsByBackground"); + ADD_int_OBJECT(NSCellIsBordered,@"NSCellIsBordered"); + ADD_int_OBJECT(NSCellHasOverlappingImage,@"NSCellHasOverlappingImage"); + ADD_int_OBJECT(NSCellHasImageHorizontal,@"NSCellHasImageHorizontal"); + ADD_int_OBJECT(NSCellHasImageOnLeftOrBottom,@"NSCellHasImageOnLeftOrBottom"); + ADD_int_OBJECT(NSCellChangesContents,@"NSCellChangesContents"); + ADD_int_OBJECT(NSCellIsInsetButton,@"NSCellIsInsetButton"); + ADD_int_OBJECT(NSCellAllowsMixedState,@"NSCellAllowsMixedState"); + ADD_int_OBJECT(NSNoCellMask,@"NSNoCellMask"); + ADD_int_OBJECT(NSContentsCellMask,@"NSContentsCellMask"); + ADD_int_OBJECT(NSPushInCellMask,@"NSPushInCellMask"); + ADD_int_OBJECT(NSChangeGrayCellMask,@"NSChangeGrayCellMask"); + ADD_int_OBJECT(NSChangeBackgroundCellMask,@"NSChangeBackgroundCellMask"); + ADD_int_OBJECT(NSOffState,@"NSOffState"); + ADD_int_OBJECT(NSOnState,@"NSOnState"); + ADD_int_OBJECT(NSMixedState,@"NSMixedState"); + ADD_int_OBJECT(NSDefaultControlTint,@"NSDefaultControlTint"); + ADD_int_OBJECT(NSClearControlTint,@"NSClearControlTint"); + ADD_int_OBJECT(NSGrayModeColorPanel,@"NSGrayModeColorPanel"); + ADD_int_OBJECT(NSRGBModeColorPanel,@"NSRGBModeColorPanel"); + ADD_int_OBJECT(NSCMYKModeColorPanel,@"NSCMYKModeColorPanel"); + ADD_int_OBJECT(NSHSBModeColorPanel,@"NSHSBModeColorPanel"); + ADD_int_OBJECT(NSCustomPaletteModeColorPanel,@"NSCustomPaletteModeColorPanel"); + ADD_int_OBJECT(NSColorListModeColorPanel,@"NSColorListModeColorPanel"); + ADD_int_OBJECT(NSWheelModeColorPanel,@"NSWheelModeColorPanel"); + ADD_int_OBJECT(NSColorPanelGrayModeMask,@"NSColorPanelGrayModeMask"); + ADD_int_OBJECT(NSColorPanelRGBModeMask,@"NSColorPanelRGBModeMask"); + ADD_int_OBJECT(NSColorPanelCMYKModeMask,@"NSColorPanelCMYKModeMask"); + ADD_int_OBJECT(NSColorPanelHSBModeMask,@"NSColorPanelHSBModeMask"); + ADD_int_OBJECT(NSColorPanelCustomPaletteModeMask,@"NSColorPanelCustomPaletteModeMask"); + ADD_int_OBJECT(NSColorPanelColorListModeMask,@"NSColorPanelColorListModeMask"); + ADD_int_OBJECT(NSColorPanelWheelModeMask,@"NSColorPanelWheelModeMask"); + ADD_int_OBJECT(NSColorPanelAllModesMask,@"NSColorPanelAllModesMask"); + ADD_int_OBJECT(GSArrowCursor,@"GSArrowCursor"); + ADD_int_OBJECT(GSIBeamCursor,@"GSIBeamCursor"); + ADD_int_OBJECT(NSLinkInDestination,@"NSLinkInDestination"); + ADD_int_OBJECT(NSLinkInSource,@"NSLinkInSource"); + ADD_int_OBJECT(NSLinkBroken,@"NSLinkBroken"); + ADD_int_OBJECT(NSUpdateContinuously,@"NSUpdateContinuously"); + ADD_int_OBJECT(NSUpdateWhenSourceSaved,@"NSUpdateWhenSourceSaved"); + ADD_int_OBJECT(NSUpdateManually,@"NSUpdateManually"); + ADD_int_OBJECT(NSUpdateNever,@"NSUpdateNever"); + ADD_int_OBJECT(NSChangeDone,@"NSChangeDone"); + ADD_int_OBJECT(NSChangeUndone,@"NSChangeUndone"); + ADD_int_OBJECT(NSChangeCleared,@"NSChangeCleared"); + ADD_int_OBJECT(NSSaveOperation,@"NSSaveOperation"); + ADD_int_OBJECT(NSSaveAsOperation,@"NSSaveAsOperation"); + ADD_int_OBJECT(NSSaveToOperation,@"NSSaveToOperation"); + ADD_int_OBJECT(NSDragOperationNone,@"NSDragOperationNone"); + ADD_int_OBJECT(NSDragOperationCopy,@"NSDragOperationCopy"); + ADD_int_OBJECT(NSDragOperationLink,@"NSDragOperationLink"); + ADD_int_OBJECT(NSDragOperationGeneric,@"NSDragOperationGeneric"); + ADD_int_OBJECT(NSDragOperationPrivate,@"NSDragOperationPrivate"); + ADD_int_OBJECT(NSDragOperationAll,@"NSDragOperationAll"); + ADD_int_OBJECT(GSFileWrapperDirectoryType,@"GSFileWrapperDirectoryType"); + ADD_int_OBJECT(GSFileWrapperRegularFileType,@"GSFileWrapperRegularFileType"); + ADD_int_OBJECT(GSFileWrapperSymbolicLinkType,@"GSFileWrapperSymbolicLinkType"); + ADD_int_OBJECT(NSControlGlyph,@"NSControlGlyph"); + ADD_int_OBJECT(NSNullGlyph,@"NSNullGlyph"); + ADD_int_OBJECT(NSGlyphBelow,@"NSGlyphBelow"); + ADD_int_OBJECT(NSGlyphAbove,@"NSGlyphAbove"); + ADD_int_OBJECT(NSOneByteGlyphPacking,@"NSOneByteGlyphPacking"); + ADD_int_OBJECT(NSJapaneseEUCGlyphPacking,@"NSJapaneseEUCGlyphPacking"); + ADD_int_OBJECT(NSAsciiWithDoubleByteEUCGlyphPacking,@"NSAsciiWithDoubleByteEUCGlyphPacking"); + ADD_int_OBJECT(NSTwoByteGlyphPacking,@"NSTwoByteGlyphPacking"); + ADD_int_OBJECT(NSFourByteGlyphPacking,@"NSFourByteGlyphPacking"); + ADD_int_OBJECT(NSItalicFontMask,@"NSItalicFontMask"); + ADD_int_OBJECT(NSUnitalicFontMask,@"NSUnitalicFontMask"); + ADD_int_OBJECT(NSBoldFontMask,@"NSBoldFontMask"); + ADD_int_OBJECT(NSUnboldFontMask,@"NSUnboldFontMask"); + ADD_int_OBJECT(NSNarrowFontMask,@"NSNarrowFontMask"); + ADD_int_OBJECT(NSExpandedFontMask,@"NSExpandedFontMask"); + ADD_int_OBJECT(NSCondensedFontMask,@"NSCondensedFontMask"); + ADD_int_OBJECT(NSSmallCapsFontMask,@"NSSmallCapsFontMask"); + ADD_int_OBJECT(NSPosterFontMask,@"NSPosterFontMask"); + ADD_int_OBJECT(NSCompressedFontMask,@"NSCompressedFontMask"); + ADD_int_OBJECT(NSNonStandardCharacterSetFontMask,@"NSNonStandardCharacterSetFontMask"); + ADD_int_OBJECT(NSFixedPitchFontMask,@"NSFixedPitchFontMask"); + ADD_int_OBJECT(NSNoFontChangeAction,@"NSNoFontChangeAction"); + ADD_int_OBJECT(NSViaPanelFontAction,@"NSViaPanelFontAction"); + ADD_int_OBJECT(NSAddTraitFontAction,@"NSAddTraitFontAction"); + ADD_int_OBJECT(NSRemoveTraitFontAction,@"NSRemoveTraitFontAction"); + ADD_int_OBJECT(NSSizeUpFontAction,@"NSSizeUpFontAction"); + ADD_int_OBJECT(NSSizeDownFontAction,@"NSSizeDownFontAction"); + ADD_int_OBJECT(NSHeavierFontAction,@"NSHeavierFontAction"); + ADD_int_OBJECT(NSLighterFontAction,@"NSLighterFontAction"); + ADD_int_OBJECT(NSFPPreviewButton,@"NSFPPreviewButton"); + ADD_int_OBJECT(NSFPRevertButton,@"NSFPRevertButton"); + ADD_int_OBJECT(NSFPSetButton,@"NSFPSetButton"); + ADD_int_OBJECT(NSFPPreviewField,@"NSFPPreviewField"); + ADD_int_OBJECT(NSFPSizeField,@"NSFPSizeField"); + ADD_int_OBJECT(NSFPSizeTitle,@"NSFPSizeTitle"); + ADD_int_OBJECT(NSFPCurrentField,@"NSFPCurrentField"); + ADD_int_OBJECT(NSFPFamilyBrowser,@"NSFPFamilyBrowser"); + ADD_int_OBJECT(NSFPFaceBrowser,@"NSFPFaceBrowser"); + ADD_int_OBJECT(NSFPSizeBrowser,@"NSFPSizeBrowser"); + ADD_int_OBJECT(NSBackingStoreRetained,@"NSBackingStoreRetained"); + ADD_int_OBJECT(NSBackingStoreNonretained,@"NSBackingStoreNonretained"); + ADD_int_OBJECT(NSBackingStoreBuffered,@"NSBackingStoreBuffered"); + ADD_int_OBJECT(NSCompositeClear,@"NSCompositeClear"); + ADD_int_OBJECT(NSCompositeCopy,@"NSCompositeCopy"); + ADD_int_OBJECT(NSCompositeSourceOver,@"NSCompositeSourceOver"); + ADD_int_OBJECT(NSCompositeSourceIn,@"NSCompositeSourceIn"); + ADD_int_OBJECT(NSCompositeSourceOut,@"NSCompositeSourceOut"); + ADD_int_OBJECT(NSCompositeSourceAtop,@"NSCompositeSourceAtop"); + ADD_int_OBJECT(NSCompositeDestinationOver,@"NSCompositeDestinationOver"); + ADD_int_OBJECT(NSCompositeDestinationIn,@"NSCompositeDestinationIn"); + ADD_int_OBJECT(NSCompositeDestinationOut,@"NSCompositeDestinationOut"); + ADD_int_OBJECT(NSCompositeDestinationAtop,@"NSCompositeDestinationAtop"); + ADD_int_OBJECT(NSCompositeXOR,@"NSCompositeXOR"); + ADD_int_OBJECT(NSCompositePlusDarker,@"NSCompositePlusDarker"); + ADD_int_OBJECT(NSCompositeHighlight,@"NSCompositeHighlight"); + ADD_int_OBJECT(NSCompositePlusLighter,@"NSCompositePlusLighter"); + ADD_int_OBJECT(NSWindowAbove,@"NSWindowAbove"); + ADD_int_OBJECT(NSWindowBelow,@"NSWindowBelow"); + ADD_int_OBJECT(NSWindowOut,@"NSWindowOut"); + ADD_int_OBJECT(GSTitleBarKey,@"GSTitleBarKey"); + ADD_int_OBJECT(GSTitleBarNormal,@"GSTitleBarNormal"); + ADD_int_OBJECT(GSTitleBarMain,@"GSTitleBarMain"); + ADD_int_OBJECT(NSScaleProportionally,@"NSScaleProportionally"); + ADD_int_OBJECT(NSScaleToFit,@"NSScaleToFit"); + ADD_int_OBJECT(NSScaleNone,@"NSScaleNone"); + ADD_int_OBJECT(NSImageAlignCenter,@"NSImageAlignCenter"); + ADD_int_OBJECT(NSImageAlignTop,@"NSImageAlignTop"); + ADD_int_OBJECT(NSImageAlignTopLeft,@"NSImageAlignTopLeft"); + ADD_int_OBJECT(NSImageAlignTopRight,@"NSImageAlignTopRight"); + ADD_int_OBJECT(NSImageAlignLeft,@"NSImageAlignLeft"); + ADD_int_OBJECT(NSImageAlignBottom,@"NSImageAlignBottom"); + ADD_int_OBJECT(NSImageAlignBottomLeft,@"NSImageAlignBottomLeft"); + ADD_int_OBJECT(NSImageAlignBottomRight,@"NSImageAlignBottomRight"); + ADD_int_OBJECT(NSImageAlignRight,@"NSImageAlignRight"); + ADD_int_OBJECT(NSImageFrameNone,@"NSImageFrameNone"); + ADD_int_OBJECT(NSImageFramePhoto,@"NSImageFramePhoto"); + ADD_int_OBJECT(NSImageFrameGrayBezel,@"NSImageFrameGrayBezel"); + ADD_int_OBJECT(NSImageFrameGroove,@"NSImageFrameGroove"); + ADD_int_OBJECT(NSImageFrameButton,@"NSImageFrameButton"); + ADD_int_OBJECT(NSUtilityWindowMask,@"NSUtilityWindowMask"); + ADD_int_OBJECT(NSDocModalWindowMask,@"NSDocModalWindowMask"); + ADD_int_OBJECT(NSOKButton,@"NSOKButton"); + ADD_int_OBJECT(NSCancelButton,@"NSCancelButton"); + ADD_int_OBJECT(NSAlertDefaultReturn,@"NSAlertDefaultReturn"); + ADD_int_OBJECT(NSAlertAlternateReturn,@"NSAlertAlternateReturn"); + ADD_int_OBJECT(NSAlertOtherReturn,@"NSAlertOtherReturn"); + ADD_int_OBJECT(NSAlertErrorReturn,@"NSAlertErrorReturn"); + + return dict; +} + +/* -- End of file -- */ diff --git a/Modules/AppKit/AppKitEvents.list b/Modules/AppKit/AppKitEvents.list new file mode 100644 index 0000000..655fc90 --- /dev/null +++ b/Modules/AppKit/AppKitEvents.list @@ -0,0 +1,135 @@ +# AppKit Events and Keys +# + +int NSLeftMouseDown +int NSLeftMouseUp +int NSOtherMouseDown +int NSOtherMouseUp +int NSRightMouseDown +int NSRightMouseUp +int NSMouseMoved +int NSLeftMouseDragged +int NSOtherMouseDragged +int NSRightMouseDragged +int NSMouseEntered +int NSMouseExited +int NSKeyDown +int NSKeyUp +int NSFlagsChanged +int NSAppKitDefined +int NSSystemDefined +int NSApplicationDefined +int NSPeriodic +int NSCursorUpdate +int NSScrollWheel + + +int NSBackspaceKey +int NSCarriageReturnKey +int NSDeleteKey +int NSBacktabKey + +int NSUpArrowFunctionKey +int NSDownArrowFunctionKey +int NSLeftArrowFunctionKey +int NSRightArrowFunctionKey +int NSF1FunctionKey +int NSF2FunctionKey +int NSF3FunctionKey +int NSF4FunctionKey +int NSF5FunctionKey +int NSF6FunctionKey +int NSF7FunctionKey +int NSF8FunctionKey +int NSF9FunctionKey +int NSF10FunctionKey +int NSF11FunctionKey +int NSF12FunctionKey +int NSF13FunctionKey +int NSF14FunctionKey +int NSF15FunctionKey +int NSF16FunctionKey +int NSF17FunctionKey +int NSF18FunctionKey +int NSF19FunctionKey +int NSF20FunctionKey +int NSF21FunctionKey +int NSF22FunctionKey +int NSF23FunctionKey +int NSF24FunctionKey +int NSF25FunctionKey +int NSF26FunctionKey +int NSF27FunctionKey +int NSF28FunctionKey +int NSF29FunctionKey +int NSF30FunctionKey +int NSF31FunctionKey +int NSF32FunctionKey +int NSF33FunctionKey +int NSF34FunctionKey +int NSF35FunctionKey +int NSInsertFunctionKey +int NSDeleteFunctionKey +int NSHomeFunctionKey +int NSBeginFunctionKey +int NSEndFunctionKey +int NSPageUpFunctionKey +int NSPageDownFunctionKey +int NSPrintScreenFunctionKey +int NSScrollLockFunctionKey +int NSPauseFunctionKey +int NSSysReqFunctionKey +int NSBreakFunctionKey +int NSResetFunctionKey +int NSStopFunctionKey +int NSMenuFunctionKey +int NSUserFunctionKey +int NSSystemFunctionKey +int NSPrintFunctionKey +int NSClearLineFunctionKey +int NSClearDisplayFunctionKey +int NSInsertLineFunctionKey +int NSDeleteLineFunctionKey +int NSInsertCharFunctionKey +int NSDeleteCharFunctionKey +int NSPrevFunctionKey +int NSNextFunctionKey +int NSSelectFunctionKey +int NSExecuteFunctionKey +int NSUndoFunctionKey +int NSRedoFunctionKey +int NSFindFunctionKey +int NSHelpFunctionKey +int NSModeSwitchFunctionKey + +int NSLeftMouseDownMask +int NSLeftMouseUpMask +int NSOtherMouseDownMask +int NSOtherMouseUpMask +int NSRightMouseDownMask +int NSRightMouseUpMask +int NSMouseMovedMask +int NSLeftMouseDraggedMask +int NSOtherMouseDraggedMask +int NSRightMouseDraggedMask +int NSMouseEnteredMask +int NSMouseExitedMask +int NSFlagsChangedMask +int NSAppKitDefinedMask +int NSSystemDefinedMask +int NSApplicationDefinedMask +int NSPeriodicMask +int NSCursorUpdateMask +int NSScrollWheelMask +int NSAnyEventMask + +int NSAlphaShiftKeyMask +int NSAlternateKeyMask +int NSCommandKeyMask +int NSControlKeyMask +int NSFunctionKeyMask +int NSHelpKeyMask +int NSKeyDownMask +int NSKeyUpMask +int NSNumericPadKeyMask +int NSShiftKeyMask diff --git a/Modules/AppKit/AppKitEvents.m b/Modules/AppKit/AppKitEvents.m new file mode 100644 index 0000000..a21aa22 --- /dev/null +++ b/Modules/AppKit/AppKitEvents.m @@ -0,0 +1,197 @@ +/** + AppKitEvents.m + + NOTE: Do not edit this file, it is automaticaly generated. + + 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 +#import +#import + +#import +#import + +#import +#import + + +NSDictionary *STGetAppKitEvents(void) +{ + NSMutableDictionary *dict = [NSMutableDictionary dictionary]; + Class numberClass = [NSNumber class]; + IMP numberWithInt; + IMP numberWithFloat; + IMP setObject_forKey; + + SEL numberWithInt_sel = @selector(numberWithInt:); + SEL numberWithFloat_sel = @selector(numberWithFloat:); + SEL setObject_forKey_sel = @selector(setObject:forKey:); + + numberWithInt = [NSNumber methodForSelector:numberWithInt_sel]; + numberWithFloat = [NSNumber methodForSelector:numberWithFloat_sel]; + setObject_forKey = [dict methodForSelector:setObject_forKey_sel]; + +#define ADD_id_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, obj, name) + +#define ADD_int_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, \ + numberWithInt(numberClass, numberWithInt_sel, obj), \ + name) + +#define ADD_float_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, \ + numberWithFloat(numberClass, numberWithInt_sel, obj), \ + name) + + ADD_int_OBJECT(NSLeftMouseDown,@"NSLeftMouseDown"); + ADD_int_OBJECT(NSLeftMouseUp,@"NSLeftMouseUp"); + ADD_int_OBJECT(NSOtherMouseDown,@"NSOtherMouseDown"); + ADD_int_OBJECT(NSOtherMouseUp,@"NSOtherMouseUp"); + ADD_int_OBJECT(NSRightMouseDown,@"NSRightMouseDown"); + ADD_int_OBJECT(NSRightMouseUp,@"NSRightMouseUp"); + ADD_int_OBJECT(NSMouseMoved,@"NSMouseMoved"); + ADD_int_OBJECT(NSLeftMouseDragged,@"NSLeftMouseDragged"); + ADD_int_OBJECT(NSOtherMouseDragged,@"NSOtherMouseDragged"); + ADD_int_OBJECT(NSRightMouseDragged,@"NSRightMouseDragged"); + ADD_int_OBJECT(NSMouseEntered,@"NSMouseEntered"); + ADD_int_OBJECT(NSMouseExited,@"NSMouseExited"); + ADD_int_OBJECT(NSKeyDown,@"NSKeyDown"); + ADD_int_OBJECT(NSKeyUp,@"NSKeyUp"); + ADD_int_OBJECT(NSFlagsChanged,@"NSFlagsChanged"); + ADD_int_OBJECT(NSAppKitDefined,@"NSAppKitDefined"); + ADD_int_OBJECT(NSSystemDefined,@"NSSystemDefined"); + ADD_int_OBJECT(NSApplicationDefined,@"NSApplicationDefined"); + ADD_int_OBJECT(NSPeriodic,@"NSPeriodic"); + ADD_int_OBJECT(NSCursorUpdate,@"NSCursorUpdate"); + ADD_int_OBJECT(NSScrollWheel,@"NSScrollWheel"); + ADD_int_OBJECT(NSBackspaceKey,@"NSBackspaceKey"); + ADD_int_OBJECT(NSCarriageReturnKey,@"NSCarriageReturnKey"); + ADD_int_OBJECT(NSDeleteKey,@"NSDeleteKey"); + ADD_int_OBJECT(NSBacktabKey,@"NSBacktabKey"); + ADD_int_OBJECT(NSUpArrowFunctionKey,@"NSUpArrowFunctionKey"); + ADD_int_OBJECT(NSDownArrowFunctionKey,@"NSDownArrowFunctionKey"); + ADD_int_OBJECT(NSLeftArrowFunctionKey,@"NSLeftArrowFunctionKey"); + ADD_int_OBJECT(NSRightArrowFunctionKey,@"NSRightArrowFunctionKey"); + ADD_int_OBJECT(NSF1FunctionKey,@"NSF1FunctionKey"); + ADD_int_OBJECT(NSF2FunctionKey,@"NSF2FunctionKey"); + ADD_int_OBJECT(NSF3FunctionKey,@"NSF3FunctionKey"); + ADD_int_OBJECT(NSF4FunctionKey,@"NSF4FunctionKey"); + ADD_int_OBJECT(NSF5FunctionKey,@"NSF5FunctionKey"); + ADD_int_OBJECT(NSF6FunctionKey,@"NSF6FunctionKey"); + ADD_int_OBJECT(NSF7FunctionKey,@"NSF7FunctionKey"); + ADD_int_OBJECT(NSF8FunctionKey,@"NSF8FunctionKey"); + ADD_int_OBJECT(NSF9FunctionKey,@"NSF9FunctionKey"); + ADD_int_OBJECT(NSF10FunctionKey,@"NSF10FunctionKey"); + ADD_int_OBJECT(NSF11FunctionKey,@"NSF11FunctionKey"); + ADD_int_OBJECT(NSF12FunctionKey,@"NSF12FunctionKey"); + ADD_int_OBJECT(NSF13FunctionKey,@"NSF13FunctionKey"); + ADD_int_OBJECT(NSF14FunctionKey,@"NSF14FunctionKey"); + ADD_int_OBJECT(NSF15FunctionKey,@"NSF15FunctionKey"); + ADD_int_OBJECT(NSF16FunctionKey,@"NSF16FunctionKey"); + ADD_int_OBJECT(NSF17FunctionKey,@"NSF17FunctionKey"); + ADD_int_OBJECT(NSF18FunctionKey,@"NSF18FunctionKey"); + ADD_int_OBJECT(NSF19FunctionKey,@"NSF19FunctionKey"); + ADD_int_OBJECT(NSF20FunctionKey,@"NSF20FunctionKey"); + ADD_int_OBJECT(NSF21FunctionKey,@"NSF21FunctionKey"); + ADD_int_OBJECT(NSF22FunctionKey,@"NSF22FunctionKey"); + ADD_int_OBJECT(NSF23FunctionKey,@"NSF23FunctionKey"); + ADD_int_OBJECT(NSF24FunctionKey,@"NSF24FunctionKey"); + ADD_int_OBJECT(NSF25FunctionKey,@"NSF25FunctionKey"); + ADD_int_OBJECT(NSF26FunctionKey,@"NSF26FunctionKey"); + ADD_int_OBJECT(NSF27FunctionKey,@"NSF27FunctionKey"); + ADD_int_OBJECT(NSF28FunctionKey,@"NSF28FunctionKey"); + ADD_int_OBJECT(NSF29FunctionKey,@"NSF29FunctionKey"); + ADD_int_OBJECT(NSF30FunctionKey,@"NSF30FunctionKey"); + ADD_int_OBJECT(NSF31FunctionKey,@"NSF31FunctionKey"); + ADD_int_OBJECT(NSF32FunctionKey,@"NSF32FunctionKey"); + ADD_int_OBJECT(NSF33FunctionKey,@"NSF33FunctionKey"); + ADD_int_OBJECT(NSF34FunctionKey,@"NSF34FunctionKey"); + ADD_int_OBJECT(NSF35FunctionKey,@"NSF35FunctionKey"); + ADD_int_OBJECT(NSInsertFunctionKey,@"NSInsertFunctionKey"); + ADD_int_OBJECT(NSDeleteFunctionKey,@"NSDeleteFunctionKey"); + ADD_int_OBJECT(NSHomeFunctionKey,@"NSHomeFunctionKey"); + ADD_int_OBJECT(NSBeginFunctionKey,@"NSBeginFunctionKey"); + ADD_int_OBJECT(NSEndFunctionKey,@"NSEndFunctionKey"); + ADD_int_OBJECT(NSPageUpFunctionKey,@"NSPageUpFunctionKey"); + ADD_int_OBJECT(NSPageDownFunctionKey,@"NSPageDownFunctionKey"); + ADD_int_OBJECT(NSPrintScreenFunctionKey,@"NSPrintScreenFunctionKey"); + ADD_int_OBJECT(NSScrollLockFunctionKey,@"NSScrollLockFunctionKey"); + ADD_int_OBJECT(NSPauseFunctionKey,@"NSPauseFunctionKey"); + ADD_int_OBJECT(NSSysReqFunctionKey,@"NSSysReqFunctionKey"); + ADD_int_OBJECT(NSBreakFunctionKey,@"NSBreakFunctionKey"); + ADD_int_OBJECT(NSResetFunctionKey,@"NSResetFunctionKey"); + ADD_int_OBJECT(NSStopFunctionKey,@"NSStopFunctionKey"); + ADD_int_OBJECT(NSMenuFunctionKey,@"NSMenuFunctionKey"); + ADD_int_OBJECT(NSUserFunctionKey,@"NSUserFunctionKey"); + ADD_int_OBJECT(NSSystemFunctionKey,@"NSSystemFunctionKey"); + ADD_int_OBJECT(NSPrintFunctionKey,@"NSPrintFunctionKey"); + ADD_int_OBJECT(NSClearLineFunctionKey,@"NSClearLineFunctionKey"); + ADD_int_OBJECT(NSClearDisplayFunctionKey,@"NSClearDisplayFunctionKey"); + ADD_int_OBJECT(NSInsertLineFunctionKey,@"NSInsertLineFunctionKey"); + ADD_int_OBJECT(NSDeleteLineFunctionKey,@"NSDeleteLineFunctionKey"); + ADD_int_OBJECT(NSInsertCharFunctionKey,@"NSInsertCharFunctionKey"); + ADD_int_OBJECT(NSDeleteCharFunctionKey,@"NSDeleteCharFunctionKey"); + ADD_int_OBJECT(NSPrevFunctionKey,@"NSPrevFunctionKey"); + ADD_int_OBJECT(NSNextFunctionKey,@"NSNextFunctionKey"); + ADD_int_OBJECT(NSSelectFunctionKey,@"NSSelectFunctionKey"); + ADD_int_OBJECT(NSExecuteFunctionKey,@"NSExecuteFunctionKey"); + ADD_int_OBJECT(NSUndoFunctionKey,@"NSUndoFunctionKey"); + ADD_int_OBJECT(NSRedoFunctionKey,@"NSRedoFunctionKey"); + ADD_int_OBJECT(NSFindFunctionKey,@"NSFindFunctionKey"); + ADD_int_OBJECT(NSHelpFunctionKey,@"NSHelpFunctionKey"); + ADD_int_OBJECT(NSModeSwitchFunctionKey,@"NSModeSwitchFunctionKey"); + ADD_int_OBJECT(NSLeftMouseDownMask,@"NSLeftMouseDownMask"); + ADD_int_OBJECT(NSLeftMouseUpMask,@"NSLeftMouseUpMask"); + ADD_int_OBJECT(NSOtherMouseDownMask,@"NSOtherMouseDownMask"); + ADD_int_OBJECT(NSOtherMouseUpMask,@"NSOtherMouseUpMask"); + ADD_int_OBJECT(NSRightMouseDownMask,@"NSRightMouseDownMask"); + ADD_int_OBJECT(NSRightMouseUpMask,@"NSRightMouseUpMask"); + ADD_int_OBJECT(NSMouseMovedMask,@"NSMouseMovedMask"); + ADD_int_OBJECT(NSLeftMouseDraggedMask,@"NSLeftMouseDraggedMask"); + ADD_int_OBJECT(NSOtherMouseDraggedMask,@"NSOtherMouseDraggedMask"); + ADD_int_OBJECT(NSRightMouseDraggedMask,@"NSRightMouseDraggedMask"); + ADD_int_OBJECT(NSMouseEnteredMask,@"NSMouseEnteredMask"); + ADD_int_OBJECT(NSMouseExitedMask,@"NSMouseExitedMask"); + ADD_int_OBJECT(NSFlagsChangedMask,@"NSFlagsChangedMask"); + ADD_int_OBJECT(NSAppKitDefinedMask,@"NSAppKitDefinedMask"); + ADD_int_OBJECT(NSSystemDefinedMask,@"NSSystemDefinedMask"); + ADD_int_OBJECT(NSApplicationDefinedMask,@"NSApplicationDefinedMask"); + ADD_int_OBJECT(NSPeriodicMask,@"NSPeriodicMask"); + ADD_int_OBJECT(NSCursorUpdateMask,@"NSCursorUpdateMask"); + ADD_int_OBJECT(NSScrollWheelMask,@"NSScrollWheelMask"); + ADD_int_OBJECT(NSAnyEventMask,@"NSAnyEventMask"); + ADD_int_OBJECT(NSAlphaShiftKeyMask,@"NSAlphaShiftKeyMask"); + ADD_int_OBJECT(NSAlternateKeyMask,@"NSAlternateKeyMask"); + ADD_int_OBJECT(NSCommandKeyMask,@"NSCommandKeyMask"); + ADD_int_OBJECT(NSControlKeyMask,@"NSControlKeyMask"); + ADD_int_OBJECT(NSFunctionKeyMask,@"NSFunctionKeyMask"); + ADD_int_OBJECT(NSHelpKeyMask,@"NSHelpKeyMask"); + ADD_int_OBJECT(NSKeyDownMask,@"NSKeyDownMask"); + ADD_int_OBJECT(NSKeyUpMask,@"NSKeyUpMask"); + ADD_int_OBJECT(NSNumericPadKeyMask,@"NSNumericPadKeyMask"); + ADD_int_OBJECT(NSShiftKeyMask,@"NSShiftKeyMask"); + + return dict; +} + +/* -- End of file -- */ diff --git a/Modules/AppKit/AppKitExceptions.list b/Modules/AppKit/AppKitExceptions.list new file mode 100644 index 0000000..7dd61d9 --- /dev/null +++ b/Modules/AppKit/AppKitExceptions.list @@ -0,0 +1,38 @@ +# AppKit Exceptions + +id NSAbortModalException +id NSAbortPrintingException +id NSAppKitIgnoredException +id NSAppKitVirtualMemoryException +id NSBadBitmapParametersException +id NSBadComparisonException +id NSBadRTFColorTableException +id NSBadRTFDirectiveException +id NSBadRTFFontTableException +id NSBadRTFStyleSheetException +id NSBrowserIllegalDelegateException +id NSColorListIOException +id NSColorListNotEditableException +id NSDraggingException +id NSFontUnavailableException +id NSIllegalSelectorException +id NSImageCacheException +id NSNibLoadingException +id NSPPDIncludeNotFoundException +id NSPPDIncludeStackOverflowException +id NSPPDIncludeStackUnderflowException +id NSPPDParseException +id NSPasteboardCommunicationException +id NSPrintOperationExistsException +id NSPrintPackageException +id NSPrintingCommunicationException +id NSRTFPropertyStackOverflowException +id NSTIFFException +id NSTextLineTooLongException +id NSTextNoSelectionException +id NSTextReadException +id NSTextWriteException +id NSTypedStreamVersionException +id NSWindowServerCommunicationException +id NSWordTablesReadException +id NSWordTablesWriteException diff --git a/Modules/AppKit/AppKitExceptions.m b/Modules/AppKit/AppKitExceptions.m new file mode 100644 index 0000000..4a3f85e --- /dev/null +++ b/Modules/AppKit/AppKitExceptions.m @@ -0,0 +1,106 @@ +/** + AppKitExceptions.m + + NOTE: Do not edit this file, it is automaticaly generated. + + 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 +#import +#import + +#import +#import + +#import +#import + + +NSDictionary *STGetAppKitExceptions(void) +{ + NSMutableDictionary *dict = [NSMutableDictionary dictionary]; + Class numberClass = [NSNumber class]; + IMP numberWithInt; + IMP numberWithFloat; + IMP setObject_forKey; + + SEL numberWithInt_sel = @selector(numberWithInt:); + SEL numberWithFloat_sel = @selector(numberWithFloat:); + SEL setObject_forKey_sel = @selector(setObject:forKey:); + + numberWithInt = [NSNumber methodForSelector:numberWithInt_sel]; + numberWithFloat = [NSNumber methodForSelector:numberWithFloat_sel]; + setObject_forKey = [dict methodForSelector:setObject_forKey_sel]; + +#define ADD_id_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, obj, name) + +#define ADD_int_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, \ + numberWithInt(numberClass, numberWithInt_sel, obj), \ + name) + +#define ADD_float_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, \ + numberWithFloat(numberClass, numberWithInt_sel, obj), \ + name) + + ADD_id_OBJECT(NSAbortModalException,@"NSAbortModalException"); + ADD_id_OBJECT(NSAbortPrintingException,@"NSAbortPrintingException"); + ADD_id_OBJECT(NSAppKitIgnoredException,@"NSAppKitIgnoredException"); + ADD_id_OBJECT(NSAppKitVirtualMemoryException,@"NSAppKitVirtualMemoryException"); + ADD_id_OBJECT(NSBadBitmapParametersException,@"NSBadBitmapParametersException"); + ADD_id_OBJECT(NSBadComparisonException,@"NSBadComparisonException"); + ADD_id_OBJECT(NSBadRTFColorTableException,@"NSBadRTFColorTableException"); + ADD_id_OBJECT(NSBadRTFDirectiveException,@"NSBadRTFDirectiveException"); + ADD_id_OBJECT(NSBadRTFFontTableException,@"NSBadRTFFontTableException"); + ADD_id_OBJECT(NSBadRTFStyleSheetException,@"NSBadRTFStyleSheetException"); + ADD_id_OBJECT(NSBrowserIllegalDelegateException,@"NSBrowserIllegalDelegateException"); + ADD_id_OBJECT(NSColorListIOException,@"NSColorListIOException"); + ADD_id_OBJECT(NSColorListNotEditableException,@"NSColorListNotEditableException"); + ADD_id_OBJECT(NSDraggingException,@"NSDraggingException"); + ADD_id_OBJECT(NSFontUnavailableException,@"NSFontUnavailableException"); + ADD_id_OBJECT(NSIllegalSelectorException,@"NSIllegalSelectorException"); + ADD_id_OBJECT(NSImageCacheException,@"NSImageCacheException"); + ADD_id_OBJECT(NSNibLoadingException,@"NSNibLoadingException"); + ADD_id_OBJECT(NSPPDIncludeNotFoundException,@"NSPPDIncludeNotFoundException"); + ADD_id_OBJECT(NSPPDIncludeStackOverflowException,@"NSPPDIncludeStackOverflowException"); + ADD_id_OBJECT(NSPPDIncludeStackUnderflowException,@"NSPPDIncludeStackUnderflowException"); + ADD_id_OBJECT(NSPPDParseException,@"NSPPDParseException"); + ADD_id_OBJECT(NSPasteboardCommunicationException,@"NSPasteboardCommunicationException"); + ADD_id_OBJECT(NSPrintOperationExistsException,@"NSPrintOperationExistsException"); + ADD_id_OBJECT(NSPrintPackageException,@"NSPrintPackageException"); + ADD_id_OBJECT(NSPrintingCommunicationException,@"NSPrintingCommunicationException"); + ADD_id_OBJECT(NSRTFPropertyStackOverflowException,@"NSRTFPropertyStackOverflowException"); + ADD_id_OBJECT(NSTIFFException,@"NSTIFFException"); + ADD_id_OBJECT(NSTextLineTooLongException,@"NSTextLineTooLongException"); + ADD_id_OBJECT(NSTextNoSelectionException,@"NSTextNoSelectionException"); + ADD_id_OBJECT(NSTextReadException,@"NSTextReadException"); + ADD_id_OBJECT(NSTextWriteException,@"NSTextWriteException"); + ADD_id_OBJECT(NSTypedStreamVersionException,@"NSTypedStreamVersionException"); + ADD_id_OBJECT(NSWindowServerCommunicationException,@"NSWindowServerCommunicationException"); + ADD_id_OBJECT(NSWordTablesReadException,@"NSWordTablesReadException"); + ADD_id_OBJECT(NSWordTablesWriteException,@"NSWordTablesWriteException"); + + return dict; +} + +/* -- End of file -- */ diff --git a/Modules/AppKit/AppKitInfo.plist b/Modules/AppKit/AppKitInfo.plist new file mode 100644 index 0000000..dce58d5 --- /dev/null +++ b/Modules/AppKit/AppKitInfo.plist @@ -0,0 +1,143 @@ +{ + STClasses = + ( + NSActionCell, + NSAffineTransform, + NSApplication, + NSAttributedString, + NSBezierPath, + NSBitmapImageRep, + NSBox, + NSBrowser, + NSBrowserCell, + NSBundle, + NSButton, + NSButtonCell, + NSCachedImageRep, + NSCell, + NSClipView, + NSCoder, + NSColor, + NSColorList, + NSColorPanel, + NSColorPicker, + NSColorWell, + NSComboBox, + NSComboBoxCell, + NSControl, + NSCursor, + NSCustomImageRep, + NSDataLink, + NSDataLinkManager, + NSDataLinkPanel, + NSDocument, + NSDocumentController, + NSDrawer, + NSEPSImageRep, + NSEvent, + NSFileWrapper, + NSFont, + NSFontManager, + NSFontPanel, + NSForm, + NSFormCell, + NSGraphicsContext, + NSHelpManager, + NSHelpPanel, + NSImage, + NSImageCell, + NSImageRep, + NSImageView, + NSInputManager, + NSInputServer, + NSLayoutManager, + NSMatrix, + NSMenu, + NSMenuItem, + NSMenuItemCell, + NSMenuView, + NSMutableAttributedString, + NSMutableParagraphStyle, + NSNibConnector, + NSNibControlConnector, + NSNibOutletConnector, + NSOpenPanel, + NSOutlineView, + NSPageLayout, + NSPanel, + NSParagraphStyle, + NSPasteboard, + NSPopUpButton, + NSPopUpButtonCell, + NSPrintInfo, + NSPrintOperation, + NSPrintPanel, + NSPrinter, + NSProgressIndicator, + NSResponder, + NSRulerMarker, + NSRulerView, + NSSavePanel, + NSScreen, + NSScrollView, + NSScroller, + NSSecureTextField, + NSSecureTextFieldCell, + NSSelection, +/* NSSimpleHorizontalTypesetter,*/ + NSSlider, + NSSliderCell, + NSSpellChecker, + NSSpellServer, + NSSplitView, + NSStepper, + NSStepperCell, + NSString, + NSTabView, + NSTabViewItem, + NSTableColumn, + NSTableHeaderCell, + NSTableHeaderView, + NSTableView, + NSText, + NSTextAttachment, + NSTextAttachmentCell, + NSTextContainer, + NSTextField, + NSTextFieldCell, + NSTextStorage, + NSTextTab, + NSTextView, +/* NSTypesetter,*/ + NSView, + NSWindow, + NSWindowController, + NSWorkspace + + /* + + GMArchiver, + GMModel, + GMUnarchiver, + + GSCustomView, + GSFontEnumerator, + GSFontInfo, + GSHbox, + GSHelpManagerPanel, + GSInfoPanel, + GSNibContainer, + GSNibItem, + GSServicesManager, + GSTable, + GSTrackingRect, + GSVbox, + + IMConnector, + IMControlConnector, + IMCustomObject, + IMCustomView, + IMOutletConnector, + */ + ); +} diff --git a/Modules/AppKit/AppKitNotifications.list b/Modules/AppKit/AppKitNotifications.list new file mode 100644 index 0000000..f1b1722 --- /dev/null +++ b/Modules/AppKit/AppKitNotifications.list @@ -0,0 +1,82 @@ +# AppKit Notifications + +id NSColorListChangedNotification +id NSColorPanelColorChangedNotification + +# id NSComboBoxWillPopUpNotification +# id NSComboBoxWillDismissNotification +# id NSComboBoxSelectionDidChangeNotification +# id NSComboBoxSelectionIsChangingNotification + +id NSControlTextDidBeginEditingNotification +id NSControlTextDidEndEditingNotification +id NSControlTextDidChangeNotification + +id NSDrawerDidCloseNotification +id NSDrawerDidOpenNotification +id NSDrawerWillCloseNotification +id NSDrawerWillOpenNotification + +id NSImageRepRegistryChangedNotification + + +################################################## +# FIXME: Undefined symbols +# +# id NSOutlineViewColumnDidMoveNotification +# id NSOutlineViewColumnDidResizeNotification +# id NSOutlineViewSelectionDidChangeNotification +# id NSOutlineViewSelectionIsChangingNotification +# id NSOutlineViewItemDidExpandNotification +# id NSOutlineViewItemDidCollapseNotification +# +################################################## + + +id NSPopUpButtonWillPopUpNotification + +id NSSplitViewDidResizeSubviewsNotification +id NSSplitViewWillResizeSubviewsNotification + +id NSTableViewColumnDidMoveNotification +id NSTableViewColumnDidResizeNotification +id NSTableViewSelectionDidChangeNotification +id NSTableViewSelectionIsChangingNotification + +id NSTextDidBeginEditingNotification +id NSTextDidEndEditingNotification +id NSTextDidChangeNotification + +id NSTextStorageWillProcessEditingNotification +id NSTextStorageDidProcessEditingNotification + +id NSTextViewWillChangeNotifyingTextViewNotification +id NSTextViewDidChangeSelectionNotification + +id NSViewFrameDidChangeNotification +id NSViewBoundsDidChangeNotification +id NSViewFocusDidChangeNotification + +id NSWindowDidBecomeKeyNotification +id NSWindowDidBecomeMainNotification +id NSWindowDidChangeScreenNotification +id NSWindowDidDeminiaturizeNotification +id NSWindowDidExposeNotification +id NSWindowDidMiniaturizeNotification +id NSWindowDidMoveNotification +id NSWindowDidResignKeyNotification +id NSWindowDidResignMainNotification +id NSWindowDidResizeNotification +id NSWindowDidUpdateNotification +id NSWindowWillCloseNotification +id NSWindowWillMiniaturizeNotification +id NSWindowWillMoveNotification + +id NSWorkspaceDidLaunchApplicationNotification +id NSWorkspaceDidMountNotification +id NSWorkspaceDidPerformFileOperationNotification +id NSWorkspaceDidTerminateApplicationNotification +id NSWorkspaceDidUnmountNotification +id NSWorkspaceWillLaunchApplicationNotification +id NSWorkspaceWillPowerOffNotification +id NSWorkspaceWillUnmountNotification diff --git a/Modules/AppKit/AppKitNotifications.m b/Modules/AppKit/AppKitNotifications.m new file mode 100644 index 0000000..7cab7d5 --- /dev/null +++ b/Modules/AppKit/AppKitNotifications.m @@ -0,0 +1,119 @@ +/** + AppKitNotifications.m + + NOTE: Do not edit this file, it is automaticaly generated. + + 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 +#import +#import + +#import +#import + +#import +#import + + +NSDictionary *STGetAppKitNotifications(void) +{ + NSMutableDictionary *dict = [NSMutableDictionary dictionary]; + Class numberClass = [NSNumber class]; + IMP numberWithInt; + IMP numberWithFloat; + IMP setObject_forKey; + + SEL numberWithInt_sel = @selector(numberWithInt:); + SEL numberWithFloat_sel = @selector(numberWithFloat:); + SEL setObject_forKey_sel = @selector(setObject:forKey:); + + numberWithInt = [NSNumber methodForSelector:numberWithInt_sel]; + numberWithFloat = [NSNumber methodForSelector:numberWithFloat_sel]; + setObject_forKey = [dict methodForSelector:setObject_forKey_sel]; + +#define ADD_id_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, obj, name) + +#define ADD_int_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, \ + numberWithInt(numberClass, numberWithInt_sel, obj), \ + name) + +#define ADD_float_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, \ + numberWithFloat(numberClass, numberWithInt_sel, obj), \ + name) + + ADD_id_OBJECT(NSColorListChangedNotification,@"NSColorListChangedNotification"); + ADD_id_OBJECT(NSColorPanelColorChangedNotification,@"NSColorPanelColorChangedNotification"); + ADD_id_OBJECT(NSControlTextDidBeginEditingNotification,@"NSControlTextDidBeginEditingNotification"); + ADD_id_OBJECT(NSControlTextDidEndEditingNotification,@"NSControlTextDidEndEditingNotification"); + ADD_id_OBJECT(NSControlTextDidChangeNotification,@"NSControlTextDidChangeNotification"); + ADD_id_OBJECT(NSDrawerDidCloseNotification,@"NSDrawerDidCloseNotification"); + ADD_id_OBJECT(NSDrawerDidOpenNotification,@"NSDrawerDidOpenNotification"); + ADD_id_OBJECT(NSDrawerWillCloseNotification,@"NSDrawerWillCloseNotification"); + ADD_id_OBJECT(NSDrawerWillOpenNotification,@"NSDrawerWillOpenNotification"); + ADD_id_OBJECT(NSImageRepRegistryChangedNotification,@"NSImageRepRegistryChangedNotification"); + ADD_id_OBJECT(NSPopUpButtonWillPopUpNotification,@"NSPopUpButtonWillPopUpNotification"); + ADD_id_OBJECT(NSSplitViewDidResizeSubviewsNotification,@"NSSplitViewDidResizeSubviewsNotification"); + ADD_id_OBJECT(NSSplitViewWillResizeSubviewsNotification,@"NSSplitViewWillResizeSubviewsNotification"); + ADD_id_OBJECT(NSTableViewColumnDidMoveNotification,@"NSTableViewColumnDidMoveNotification"); + ADD_id_OBJECT(NSTableViewColumnDidResizeNotification,@"NSTableViewColumnDidResizeNotification"); + ADD_id_OBJECT(NSTableViewSelectionDidChangeNotification,@"NSTableViewSelectionDidChangeNotification"); + ADD_id_OBJECT(NSTableViewSelectionIsChangingNotification,@"NSTableViewSelectionIsChangingNotification"); + ADD_id_OBJECT(NSTextDidBeginEditingNotification,@"NSTextDidBeginEditingNotification"); + ADD_id_OBJECT(NSTextDidEndEditingNotification,@"NSTextDidEndEditingNotification"); + ADD_id_OBJECT(NSTextDidChangeNotification,@"NSTextDidChangeNotification"); + ADD_id_OBJECT(NSTextStorageWillProcessEditingNotification,@"NSTextStorageWillProcessEditingNotification"); + ADD_id_OBJECT(NSTextStorageDidProcessEditingNotification,@"NSTextStorageDidProcessEditingNotification"); + ADD_id_OBJECT(NSTextViewWillChangeNotifyingTextViewNotification,@"NSTextViewWillChangeNotifyingTextViewNotification"); + ADD_id_OBJECT(NSTextViewDidChangeSelectionNotification,@"NSTextViewDidChangeSelectionNotification"); + ADD_id_OBJECT(NSViewFrameDidChangeNotification,@"NSViewFrameDidChangeNotification"); + ADD_id_OBJECT(NSViewBoundsDidChangeNotification,@"NSViewBoundsDidChangeNotification"); + ADD_id_OBJECT(NSViewFocusDidChangeNotification,@"NSViewFocusDidChangeNotification"); + ADD_id_OBJECT(NSWindowDidBecomeKeyNotification,@"NSWindowDidBecomeKeyNotification"); + ADD_id_OBJECT(NSWindowDidBecomeMainNotification,@"NSWindowDidBecomeMainNotification"); + ADD_id_OBJECT(NSWindowDidChangeScreenNotification,@"NSWindowDidChangeScreenNotification"); + ADD_id_OBJECT(NSWindowDidDeminiaturizeNotification,@"NSWindowDidDeminiaturizeNotification"); + ADD_id_OBJECT(NSWindowDidExposeNotification,@"NSWindowDidExposeNotification"); + ADD_id_OBJECT(NSWindowDidMiniaturizeNotification,@"NSWindowDidMiniaturizeNotification"); + ADD_id_OBJECT(NSWindowDidMoveNotification,@"NSWindowDidMoveNotification"); + ADD_id_OBJECT(NSWindowDidResignKeyNotification,@"NSWindowDidResignKeyNotification"); + ADD_id_OBJECT(NSWindowDidResignMainNotification,@"NSWindowDidResignMainNotification"); + ADD_id_OBJECT(NSWindowDidResizeNotification,@"NSWindowDidResizeNotification"); + ADD_id_OBJECT(NSWindowDidUpdateNotification,@"NSWindowDidUpdateNotification"); + ADD_id_OBJECT(NSWindowWillCloseNotification,@"NSWindowWillCloseNotification"); + ADD_id_OBJECT(NSWindowWillMiniaturizeNotification,@"NSWindowWillMiniaturizeNotification"); + ADD_id_OBJECT(NSWindowWillMoveNotification,@"NSWindowWillMoveNotification"); + ADD_id_OBJECT(NSWorkspaceDidLaunchApplicationNotification,@"NSWorkspaceDidLaunchApplicationNotification"); + ADD_id_OBJECT(NSWorkspaceDidMountNotification,@"NSWorkspaceDidMountNotification"); + ADD_id_OBJECT(NSWorkspaceDidPerformFileOperationNotification,@"NSWorkspaceDidPerformFileOperationNotification"); + ADD_id_OBJECT(NSWorkspaceDidTerminateApplicationNotification,@"NSWorkspaceDidTerminateApplicationNotification"); + ADD_id_OBJECT(NSWorkspaceDidUnmountNotification,@"NSWorkspaceDidUnmountNotification"); + ADD_id_OBJECT(NSWorkspaceWillLaunchApplicationNotification,@"NSWorkspaceWillLaunchApplicationNotification"); + ADD_id_OBJECT(NSWorkspaceWillPowerOffNotification,@"NSWorkspaceWillPowerOffNotification"); + ADD_id_OBJECT(NSWorkspaceWillUnmountNotification,@"NSWorkspaceWillUnmountNotification"); + + return dict; +} + +/* -- End of file -- */ diff --git a/Modules/AppKit/Functions.h b/Modules/AppKit/Functions.h new file mode 100644 index 0000000..272edda --- /dev/null +++ b/Modules/AppKit/Functions.h @@ -0,0 +1,41 @@ +/** + Functions.m + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2001 Nov 14 + + 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 NSDictionary; +@class NSString; + +#define _STCreateConstantsDictionaryForType(t, v, n, c) \ + _ST_##t##_namesDictionary(v, n, c); + +#define function_header(type) \ + NSDictionary *_ST_##type##_namesDictionary(type *vals, \ + NSString **names, \ + int count) + +function_header(int); +function_header(float); +function_header(id); + diff --git a/Modules/AppKit/Functions.m b/Modules/AppKit/Functions.m new file mode 100644 index 0000000..8ab2e15 --- /dev/null +++ b/Modules/AppKit/Functions.m @@ -0,0 +1,56 @@ +/** + Functions.m + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2001 Nov 14 + + 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 + +#define function_template(type, class, selector) \ + NSDictionary *_ST_##type##_namesDictionary(type *vals, \ + NSString **names, \ + int count) \ + { \ + NSMutableDictionary *dict = [NSMutableDictionary dictionary]; \ + \ + for(i = 0; i $@; \ + cat $< | awk -f create_constants.awk >> $@;\ + cat footer.m >> $@; ) + diff --git a/Modules/AppKit/NSApplication+additions.h b/Modules/AppKit/NSApplication+additions.h new file mode 100644 index 0000000..59dd6d7 --- /dev/null +++ b/Modules/AppKit/NSApplication+additions.h @@ -0,0 +1,46 @@ +/** + NSApplication additions + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2001 Nov 15 + + 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 NSApplication(STAdditions) +- (int)runAlertPanelWithTitle:(NSString *)title + message:(NSString *)message + defaultButton:(NSString *)defaultButton + alternateButton:(NSString *)alternateButton + otherButton:(NSString *)otherButton; +- (int)runCriticalAlertPanelWithTitle:(NSString *)title + message:(NSString *)message + defaultButton:(NSString *)defaultButton + alternateButton:(NSString *)alternateButton + otherButton:(NSString *)otherButton; +- (int)runInformationalAlertPanelWithTitle:(NSString *)title + message:(NSString *)message + defaultButton:(NSString *)defaultButton + alternateButton:(NSString *)alternateButton + otherButton:(NSString *)otherButton; +@end diff --git a/Modules/AppKit/NSApplication+additions.m b/Modules/AppKit/NSApplication+additions.m new file mode 100644 index 0000000..3155adb --- /dev/null +++ b/Modules/AppKit/NSApplication+additions.m @@ -0,0 +1,62 @@ +/** + NSApplication additions + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2001 Nov 15 + + 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 "NSApplication+additions.h" + +#import + +@implementation NSApplication(STAdditions) +- (int)runAlertPanelWithTitle:(NSString *)title + message:(NSString *)message + defaultButton:(NSString *)defaultButton + alternateButton:(NSString *)alternateButton + otherButton:(NSString *)otherButton +{ + return NSRunAlertPanel(title, message, defaultButton, + alternateButton, otherButton); +} + +- (int)runCriticalAlertPanelWithTitle:(NSString *)title + message:(NSString *)message + defaultButton:(NSString *)defaultButton + alternateButton:(NSString *)alternateButton + otherButton:(NSString *)otherButton +{ + return NSRunCriticalAlertPanel(title, message, defaultButton, + alternateButton, otherButton); +} + +- (int)runInformationalAlertPanelWithTitle:(NSString *)title + message:(NSString *)message + defaultButton:(NSString *)defaultButton + alternateButton:(NSString *)alternateButton + otherButton:(NSString *)otherButton +{ + return NSRunInformationalAlertPanel(title, message, defaultButton, + alternateButton, otherButton); + +} +@end diff --git a/Modules/AppKit/STAppKitModule.h b/Modules/AppKit/STAppKitModule.h new file mode 100644 index 0000000..00f29ea --- /dev/null +++ b/Modules/AppKit/STAppKitModule.h @@ -0,0 +1,34 @@ +/** + STAppKitModule.h + AppKit bindings + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2001 May 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 + +@interface STAppKitModule:STModule +{ +} +@end + diff --git a/Modules/AppKit/STAppKitModule.m b/Modules/AppKit/STAppKitModule.m new file mode 100644 index 0000000..b12d617 --- /dev/null +++ b/Modules/AppKit/STAppKitModule.m @@ -0,0 +1,57 @@ +/** + STAppKitModule.m + AppKit bindings + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2001 May 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 "STAppKitModule.h" + +#import +#import + +@class NSApplication; +extern NSDictionary *STGetAppKitConstants(); +extern NSDictionary *STGetAppKitNotifications(); +extern NSDictionary *STGetAppKitExceptions(); +extern NSDictionary *STGetAppKitEvents(); + +@implementation STAppKitModule ++ (void)initialize +{ + [NSApplication sharedApplication]; +} + +- (NSDictionary *)namedObjects +{ + NSMutableDictionary *dict = [NSMutableDictionary dictionary]; + + [dict addEntriesFromDictionary:STGetAppKitConstants()]; + [dict addEntriesFromDictionary:STGetAppKitNotifications()]; + [dict addEntriesFromDictionary:STGetAppKitExceptions()]; + [dict addEntriesFromDictionary:STGetAppKitEvents()]; + + return [dict copy]; /* get immutable copy */ +} +@end + diff --git a/Modules/AppKit/create_constants.awk b/Modules/AppKit/create_constants.awk new file mode 100644 index 0000000..93fe336 --- /dev/null +++ b/Modules/AppKit/create_constants.awk @@ -0,0 +1,5 @@ +($0 !~ /^[\t ]*#.*$/) && ($0 !~ /^[\t ]*$/) && (NF == 2) { + + printf " ADD_%s_OBJECT(%s,@\"%s\");\n", $1, $2, $2 + +} diff --git a/Modules/AppKit/footer.m b/Modules/AppKit/footer.m new file mode 100644 index 0000000..22c60af --- /dev/null +++ b/Modules/AppKit/footer.m @@ -0,0 +1,5 @@ + + return dict; +} + +/* -- End of file -- */ diff --git a/Modules/AppKit/header.m b/Modules/AppKit/header.m new file mode 100644 index 0000000..eb1f38b --- /dev/null +++ b/Modules/AppKit/header.m @@ -0,0 +1,65 @@ +/** + @@NAME@@.m + + NOTE: Do not edit this file, it is automaticaly generated. + + 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 +#import +#import + +#import +#import + +#import +#import + + +NSDictionary *STGet@@NAME@@(void) +{ + NSMutableDictionary *dict = [NSMutableDictionary dictionary]; + Class numberClass = [NSNumber class]; + IMP numberWithInt; + IMP numberWithFloat; + IMP setObject_forKey; + + SEL numberWithInt_sel = @selector(numberWithInt:); + SEL numberWithFloat_sel = @selector(numberWithFloat:); + SEL setObject_forKey_sel = @selector(setObject:forKey:); + + numberWithInt = [NSNumber methodForSelector:numberWithInt_sel]; + numberWithFloat = [NSNumber methodForSelector:numberWithFloat_sel]; + setObject_forKey = [dict methodForSelector:setObject_forKey_sel]; + +#define ADD_id_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, obj, name) + +#define ADD_int_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, \ + numberWithInt(numberClass, numberWithInt_sel, obj), \ + name) + +#define ADD_float_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, \ + numberWithFloat(numberClass, numberWithInt_sel, obj), \ + name) + diff --git a/Modules/Foundation/FoundationConstants.list b/Modules/Foundation/FoundationConstants.list new file mode 100644 index 0000000..1ab2e8b --- /dev/null +++ b/Modules/Foundation/FoundationConstants.list @@ -0,0 +1,170 @@ +# Objective-C constants +int NO +int YES + +# Foundation constants + +NSPoint NSZeroPoint +NSSize NSZeroSize +NSRect NSZeroRect + +int NSOrderedAscending +int NSOrderedSame +int NSOrderedDescending +int NSNotFound + +int NSMinXEdge +int NSMinYEdge +int NSMaxXEdge +int NSMaxYEdge + +int NS_UnknownByteOrder +int NS_LittleEndian +int NS_BigEndian + +int NSOpenStepUnicodeReservedBase + +int NSCaseInsensitiveSearch +int NSLiteralSearch +int NSBackwardsSearch +int NSAnchoredSearch + +# Language defs keys + +id NSAMPMDesignation +id NSCurrencyString +id NSCurrencySymbol +id NSDateFormatString +id NSDateTimeOrdering +id NSDecimalDigits +id NSDecimalSeparator +id NSEarlierTimeDesignations +id NSHourNameDesignations +id NSInternationalCurrencyString +id NSLaterTimeDesignations +id NSMonthNameArray +id NSNextDayDesignations +id NSNextNextDayDesignations +id NSPriorDayDesignations +id NSShortMonthNameArray +id NSShortTimeDateFormatString +id NSShortWeekDayNameArray +id NSThisDayDesignations +id NSThousandsSeparator +id NSTimeDateFormatString +id NSTimeFormatString +id NSWeekDayNameArray +id NSYearMonthWeekDesignations + + +# File / File System attributes + +id NSFileDeviceIdentifier +id NSFileGroupOwnerAccountNumber +id NSFileModificationDate +id NSFileOwnerAccountNumber +id NSFilePosixPermissions +id NSFileReferenceCount +id NSFileSize +id NSFileSystemFileNumber +id NSFileSystemNumber +id NSFileType +id NSFileTypeBlockSpecial +id NSFileTypeCharacterSpecial +id NSFileTypeDirectory +id NSFileTypeRegular +id NSFileTypeSocket +id NSFileTypeSymbolicLink +id NSFileTypeUnknown + +id NSFileSystemSize +id NSFileSystemFreeSize +id NSFileSystemNodes +id NSFileSystemFreeNodes + + +# ObjC types + +# FIXME: It seeems, that they are not defined anywhere + +# int NSObjCNoType +# int NSObjCVoidType +# int NSObjCCharType +# int NSObjCShortType +# int NSObjCLongType +# int NSObjCLonglongType +# int NSObjCFloatType +# int NSObjCDoubleType +# int NSObjCSelectorType +# int NSObjCObjectType +# int NSObjCStructType +# int NSObjCPointerType +# int NSObjCStringType +# int NSObjCArrayType +# int NSObjCUnionType +# int NSObjCBitfield + + +# String encodings + +int NSASCIIStringEncoding +int NSISO2022JPStringEncoding +int NSISOLatin1StringEncoding +int NSISOLatin2StringEncoding +int NSJapaneseEUCStringEncoding +int NSNEXTSTEPStringEncoding +int NSNonLossyASCIIStringEncoding +int NSShiftJISStringEncoding +int NSSymbolStringEncoding +int NSUTF8StringEncoding +int NSUnicodeStringEncoding +int NSWindowsCP1250StringEncoding +int NSWindowsCP1251StringEncoding +int NSWindowsCP1252StringEncoding +int NSWindowsCP1253StringEncoding +int NSWindowsCP1254StringEncoding + + +# Exception names + +id NSInconsistentArchiveException +# id NSByteStoreLockedException +# id NSByteStoreVersionException +# id NSBTreeStoreKeyTooLargeException +# id NSByteStoreDamagedException +# id NSPosixFileOperationException +id NSCharacterConversionException +# id NSDestinationInvalidException +id NSGenericException +id NSInternalInconsistencyException +id NSInvalidArgumentException +# id NSInvalidReceivePort +# id NSInvalidReceivePortException +# id NSInvalidSendPort +# id NSInvalidSendPortException +id NSMallocException +# id NSObjectInaccessibleException +# id NSObjectNotAvailableException +# id NSOldStyleException +# id NSPortReceiveError +# id NSPortReceiveException +# id NSPortSendError +# id NSPortSendException +id NSPortTimeoutException +id NSRangeException +id NSFailedAuthenticationException + + +# Notification names + +# id NSBundleLoaded +id NSConnectionDidDieNotification +id NSPortDidBecomeInvalidNotification +# id NSPPLDidBecomeDirtyNotification +# id NSPPLDidSaveNotification +id NSBecomingMultiThreaded +id NSThreadExiting +id NSGlobalDomain +id NSArgumentDomain +id NSRegistrationDomain + diff --git a/Modules/Foundation/FoundationConstants.m b/Modules/Foundation/FoundationConstants.m new file mode 100644 index 0000000..23d609c --- /dev/null +++ b/Modules/Foundation/FoundationConstants.m @@ -0,0 +1,178 @@ +/** + FoundationConstants.m + + NOTE: Do not edit this file, it is automaticaly generated. + + 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 + +NSDictionary *STGetFoundationConstants(void) +{ + NSMutableDictionary *dict = [NSMutableDictionary dictionary]; + Class numberClass = [NSNumber class]; + IMP numberWithInt; + IMP numberWithFloat; + IMP setObject_forKey; + + SEL numberWithInt_sel = @selector(numberWithInt:); + SEL numberWithFloat_sel = @selector(numberWithFloat:); + SEL setObject_forKey_sel = @selector(setObject:forKey:); + + numberWithInt = [NSNumber methodForSelector:numberWithInt_sel]; + numberWithFloat = [NSNumber methodForSelector:numberWithFloat_sel]; + setObject_forKey = [dict methodForSelector:setObject_forKey_sel]; + +#define ADD_id_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, obj, name) + +#define ADD_int_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, \ + numberWithInt(numberClass, numberWithInt_sel, obj), \ + name) + +#define ADD_float_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, \ + numberWithFloat(numberClass, numberWithInt_sel, obj), \ + name) + +#define ADD_NSPoint_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, \ + [NSValue valueWithPoint:obj], \ + name) + +#define ADD_NSRange_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, \ + [NSValue valueWithRange:obj], \ + name) + +#define ADD_NSSize_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, \ + [NSValue valueWithSize:obj], \ + name) + +#define ADD_NSRect_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, \ + [NSValue valueWithRect:obj], \ + name) + ADD_int_OBJECT(NO,@"NO"); + ADD_int_OBJECT(YES,@"YES"); + ADD_NSPoint_OBJECT(NSZeroPoint,@"NSZeroPoint"); + ADD_NSSize_OBJECT(NSZeroSize,@"NSZeroSize"); + ADD_NSRect_OBJECT(NSZeroRect,@"NSZeroRect"); + ADD_int_OBJECT(NSOrderedAscending,@"NSOrderedAscending"); + ADD_int_OBJECT(NSOrderedSame,@"NSOrderedSame"); + ADD_int_OBJECT(NSOrderedDescending,@"NSOrderedDescending"); + ADD_int_OBJECT(NSNotFound,@"NSNotFound"); + ADD_int_OBJECT(NSMinXEdge,@"NSMinXEdge"); + ADD_int_OBJECT(NSMinYEdge,@"NSMinYEdge"); + ADD_int_OBJECT(NSMaxXEdge,@"NSMaxXEdge"); + ADD_int_OBJECT(NSMaxYEdge,@"NSMaxYEdge"); + ADD_int_OBJECT(NS_UnknownByteOrder,@"NS_UnknownByteOrder"); + ADD_int_OBJECT(NS_LittleEndian,@"NS_LittleEndian"); + ADD_int_OBJECT(NS_BigEndian,@"NS_BigEndian"); + ADD_int_OBJECT(NSOpenStepUnicodeReservedBase,@"NSOpenStepUnicodeReservedBase"); + ADD_int_OBJECT(NSCaseInsensitiveSearch,@"NSCaseInsensitiveSearch"); + ADD_int_OBJECT(NSLiteralSearch,@"NSLiteralSearch"); + ADD_int_OBJECT(NSBackwardsSearch,@"NSBackwardsSearch"); + ADD_int_OBJECT(NSAnchoredSearch,@"NSAnchoredSearch"); + ADD_id_OBJECT(NSAMPMDesignation,@"NSAMPMDesignation"); + ADD_id_OBJECT(NSCurrencyString,@"NSCurrencyString"); + ADD_id_OBJECT(NSCurrencySymbol,@"NSCurrencySymbol"); + ADD_id_OBJECT(NSDateFormatString,@"NSDateFormatString"); + ADD_id_OBJECT(NSDateTimeOrdering,@"NSDateTimeOrdering"); + ADD_id_OBJECT(NSDecimalDigits,@"NSDecimalDigits"); + ADD_id_OBJECT(NSDecimalSeparator,@"NSDecimalSeparator"); + ADD_id_OBJECT(NSEarlierTimeDesignations,@"NSEarlierTimeDesignations"); + ADD_id_OBJECT(NSHourNameDesignations,@"NSHourNameDesignations"); + ADD_id_OBJECT(NSInternationalCurrencyString,@"NSInternationalCurrencyString"); + ADD_id_OBJECT(NSLaterTimeDesignations,@"NSLaterTimeDesignations"); + ADD_id_OBJECT(NSMonthNameArray,@"NSMonthNameArray"); + ADD_id_OBJECT(NSNextDayDesignations,@"NSNextDayDesignations"); + ADD_id_OBJECT(NSNextNextDayDesignations,@"NSNextNextDayDesignations"); + ADD_id_OBJECT(NSPriorDayDesignations,@"NSPriorDayDesignations"); + ADD_id_OBJECT(NSShortMonthNameArray,@"NSShortMonthNameArray"); + ADD_id_OBJECT(NSShortTimeDateFormatString,@"NSShortTimeDateFormatString"); + ADD_id_OBJECT(NSShortWeekDayNameArray,@"NSShortWeekDayNameArray"); + ADD_id_OBJECT(NSThisDayDesignations,@"NSThisDayDesignations"); + ADD_id_OBJECT(NSThousandsSeparator,@"NSThousandsSeparator"); + ADD_id_OBJECT(NSTimeDateFormatString,@"NSTimeDateFormatString"); + ADD_id_OBJECT(NSTimeFormatString,@"NSTimeFormatString"); + ADD_id_OBJECT(NSWeekDayNameArray,@"NSWeekDayNameArray"); + ADD_id_OBJECT(NSYearMonthWeekDesignations,@"NSYearMonthWeekDesignations"); + ADD_id_OBJECT(NSFileDeviceIdentifier,@"NSFileDeviceIdentifier"); + ADD_id_OBJECT(NSFileGroupOwnerAccountNumber,@"NSFileGroupOwnerAccountNumber"); + ADD_id_OBJECT(NSFileModificationDate,@"NSFileModificationDate"); + ADD_id_OBJECT(NSFileOwnerAccountNumber,@"NSFileOwnerAccountNumber"); + ADD_id_OBJECT(NSFilePosixPermissions,@"NSFilePosixPermissions"); + ADD_id_OBJECT(NSFileReferenceCount,@"NSFileReferenceCount"); + ADD_id_OBJECT(NSFileSize,@"NSFileSize"); + ADD_id_OBJECT(NSFileSystemFileNumber,@"NSFileSystemFileNumber"); + ADD_id_OBJECT(NSFileSystemNumber,@"NSFileSystemNumber"); + ADD_id_OBJECT(NSFileType,@"NSFileType"); + ADD_id_OBJECT(NSFileTypeBlockSpecial,@"NSFileTypeBlockSpecial"); + ADD_id_OBJECT(NSFileTypeCharacterSpecial,@"NSFileTypeCharacterSpecial"); + ADD_id_OBJECT(NSFileTypeDirectory,@"NSFileTypeDirectory"); + ADD_id_OBJECT(NSFileTypeRegular,@"NSFileTypeRegular"); + ADD_id_OBJECT(NSFileTypeSocket,@"NSFileTypeSocket"); + ADD_id_OBJECT(NSFileTypeSymbolicLink,@"NSFileTypeSymbolicLink"); + ADD_id_OBJECT(NSFileTypeUnknown,@"NSFileTypeUnknown"); + ADD_id_OBJECT(NSFileSystemSize,@"NSFileSystemSize"); + ADD_id_OBJECT(NSFileSystemFreeSize,@"NSFileSystemFreeSize"); + ADD_id_OBJECT(NSFileSystemNodes,@"NSFileSystemNodes"); + ADD_id_OBJECT(NSFileSystemFreeNodes,@"NSFileSystemFreeNodes"); + ADD_int_OBJECT(NSASCIIStringEncoding,@"NSASCIIStringEncoding"); + ADD_int_OBJECT(NSISO2022JPStringEncoding,@"NSISO2022JPStringEncoding"); + ADD_int_OBJECT(NSISOLatin1StringEncoding,@"NSISOLatin1StringEncoding"); + ADD_int_OBJECT(NSISOLatin2StringEncoding,@"NSISOLatin2StringEncoding"); + ADD_int_OBJECT(NSJapaneseEUCStringEncoding,@"NSJapaneseEUCStringEncoding"); + ADD_int_OBJECT(NSNEXTSTEPStringEncoding,@"NSNEXTSTEPStringEncoding"); + ADD_int_OBJECT(NSNonLossyASCIIStringEncoding,@"NSNonLossyASCIIStringEncoding"); + ADD_int_OBJECT(NSShiftJISStringEncoding,@"NSShiftJISStringEncoding"); + ADD_int_OBJECT(NSSymbolStringEncoding,@"NSSymbolStringEncoding"); + ADD_int_OBJECT(NSUTF8StringEncoding,@"NSUTF8StringEncoding"); + ADD_int_OBJECT(NSUnicodeStringEncoding,@"NSUnicodeStringEncoding"); + ADD_int_OBJECT(NSWindowsCP1250StringEncoding,@"NSWindowsCP1250StringEncoding"); + ADD_int_OBJECT(NSWindowsCP1251StringEncoding,@"NSWindowsCP1251StringEncoding"); + ADD_int_OBJECT(NSWindowsCP1252StringEncoding,@"NSWindowsCP1252StringEncoding"); + ADD_int_OBJECT(NSWindowsCP1253StringEncoding,@"NSWindowsCP1253StringEncoding"); + ADD_int_OBJECT(NSWindowsCP1254StringEncoding,@"NSWindowsCP1254StringEncoding"); + ADD_id_OBJECT(NSInconsistentArchiveException,@"NSInconsistentArchiveException"); + ADD_id_OBJECT(NSCharacterConversionException,@"NSCharacterConversionException"); + ADD_id_OBJECT(NSGenericException,@"NSGenericException"); + ADD_id_OBJECT(NSInternalInconsistencyException,@"NSInternalInconsistencyException"); + ADD_id_OBJECT(NSInvalidArgumentException,@"NSInvalidArgumentException"); + ADD_id_OBJECT(NSMallocException,@"NSMallocException"); + ADD_id_OBJECT(NSPortTimeoutException,@"NSPortTimeoutException"); + ADD_id_OBJECT(NSRangeException,@"NSRangeException"); + ADD_id_OBJECT(NSFailedAuthenticationException,@"NSFailedAuthenticationException"); + ADD_id_OBJECT(NSConnectionDidDieNotification,@"NSConnectionDidDieNotification"); + ADD_id_OBJECT(NSPortDidBecomeInvalidNotification,@"NSPortDidBecomeInvalidNotification"); + ADD_id_OBJECT(NSBecomingMultiThreaded,@"NSBecomingMultiThreaded"); + ADD_id_OBJECT(NSThreadExiting,@"NSThreadExiting"); + ADD_id_OBJECT(NSGlobalDomain,@"NSGlobalDomain"); + ADD_id_OBJECT(NSArgumentDomain,@"NSArgumentDomain"); + ADD_id_OBJECT(NSRegistrationDomain,@"NSRegistrationDomain"); + + return dict; +} + +/* -- End of file -- */ diff --git a/Modules/Foundation/FoundationInfo.plist b/Modules/Foundation/FoundationInfo.plist new file mode 100644 index 0000000..bb1ca1b --- /dev/null +++ b/Modules/Foundation/FoundationInfo.plist @@ -0,0 +1,93 @@ +{ + STClasses = ( + + GSHTMLParser, + GSHTMLSAXHandler, + GSMimeCodingContext, + GSMimeDocument, + GSMimeParser, + GSSAXHandler, + + GSXMLAttribute, + GSXMLDocument, + GSXMLNamespace, + GSXMLNode, + GSXMLParser, + + NSArchiver, + NSArray, + NSAssertionHandler, + NSAttributedString, + NSAutoreleasePool, + NSBitmapCharSet, + NSBundle, + NSCalendarDate, + NSCharacterSet, + NSClassDescription, + NSCoder, + NSConditionLock, + NSConnection, + NSCountedSet, + NSData, + NSDate, + NSDateFormatter, + NSDecimalNumber, + NSDecimalNumberHandler, + NSDeserializer, + NSDictionary, + NSDirectoryEnumerator, + NSDistantObject, + NSDistributedLock, + NSDistributedNotificationCenter, + NSEnumerator, + NSException, + NSFileHandle, + NSFileManager, + NSFormatter, + NSGDate, + NSHost, + NSInvocation, + NSLock, + NSMethodSignature, + NSMutableArray, + NSMutableAttributedString, + NSMutableBitmapCharSet, + NSMutableCharacterSet, + NSMutableData, + NSMutableDictionary, + NSMutableSet, + NSMutableString, + NSNotification, + NSNotificationCenter, + NSNotificationQueue, + NSNull, + NSNumber, + NSNumberFormatter, + NSObject, + NSPipe, + NSPort, + NSPortCoder, + NSPortMessage, + NSPortNameServer, + NSProcessInfo, + NSProtocolChecker, + NSProxy, + NSRecursiveLock, + NSRunLoop, + NSScanner, + NSSerializer, + NSSet, + NSString, + NSTask, + NSThread, + NSTimeZone, + NSTimeZoneDetail, + NSTimer, + NSURL, + NSURLHandle, + NSUnarchiver, + NSUndoManager, + NSUserDefaults, + NSValue + ); +} diff --git a/Modules/Foundation/Functions.h b/Modules/Foundation/Functions.h new file mode 100644 index 0000000..272edda --- /dev/null +++ b/Modules/Foundation/Functions.h @@ -0,0 +1,41 @@ +/** + Functions.m + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2001 Nov 14 + + 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 NSDictionary; +@class NSString; + +#define _STCreateConstantsDictionaryForType(t, v, n, c) \ + _ST_##t##_namesDictionary(v, n, c); + +#define function_header(type) \ + NSDictionary *_ST_##type##_namesDictionary(type *vals, \ + NSString **names, \ + int count) + +function_header(int); +function_header(float); +function_header(id); + diff --git a/Modules/Foundation/Functions.m b/Modules/Foundation/Functions.m new file mode 100644 index 0000000..8ab2e15 --- /dev/null +++ b/Modules/Foundation/Functions.m @@ -0,0 +1,56 @@ +/** + Functions.m + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2001 Nov 14 + + 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 + +#define function_template(type, class, selector) \ + NSDictionary *_ST_##type##_namesDictionary(type *vals, \ + NSString **names, \ + int count) \ + { \ + NSMutableDictionary *dict = [NSMutableDictionary dictionary]; \ + \ + for(i = 0; i $@; \ + cat $< | awk -f create_constants.awk >> $@;\ + cat footer.m >> $@; ) + diff --git a/Modules/Foundation/STFoundationModule.h b/Modules/Foundation/STFoundationModule.h new file mode 100644 index 0000000..642d8cd --- /dev/null +++ b/Modules/Foundation/STFoundationModule.h @@ -0,0 +1,34 @@ +/** + STFoundationModule.h + Foundation bindings + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2001 May 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 + +@interface STFoundationModule:STModule +{ +} +@end + diff --git a/Modules/Foundation/STFoundationModule.m b/Modules/Foundation/STFoundationModule.m new file mode 100644 index 0000000..33b34b1 --- /dev/null +++ b/Modules/Foundation/STFoundationModule.m @@ -0,0 +1,45 @@ +/** + STFoundationModule.m + Foundation bindings + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2002 Jan 21 + + 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 "STFoundationModule.h" + +#import +#import + +extern NSDictionary *STGetFoundationConstants(); + +@implementation STFoundationModule +- (NSDictionary *)namedObjects +{ + NSMutableDictionary *dict = [NSMutableDictionary dictionary]; + + [dict addEntriesFromDictionary:STGetFoundationConstants()]; + + return [dict copy]; /* get immutable copy */ +} +@end + diff --git a/Modules/Foundation/create_constants.awk b/Modules/Foundation/create_constants.awk new file mode 100644 index 0000000..93fe336 --- /dev/null +++ b/Modules/Foundation/create_constants.awk @@ -0,0 +1,5 @@ +($0 !~ /^[\t ]*#.*$/) && ($0 !~ /^[\t ]*$/) && (NF == 2) { + + printf " ADD_%s_OBJECT(%s,@\"%s\");\n", $1, $2, $2 + +} diff --git a/Modules/Foundation/footer.m b/Modules/Foundation/footer.m new file mode 100644 index 0000000..22c60af --- /dev/null +++ b/Modules/Foundation/footer.m @@ -0,0 +1,5 @@ + + return dict; +} + +/* -- End of file -- */ diff --git a/Modules/Foundation/header.m b/Modules/Foundation/header.m new file mode 100644 index 0000000..fdd64e7 --- /dev/null +++ b/Modules/Foundation/header.m @@ -0,0 +1,75 @@ +/** + @@NAME@@.m + + NOTE: Do not edit this file, it is automaticaly generated. + + 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 + +NSDictionary *STGet@@NAME@@(void) +{ + NSMutableDictionary *dict = [NSMutableDictionary dictionary]; + Class numberClass = [NSNumber class]; + IMP numberWithInt; + IMP numberWithFloat; + IMP setObject_forKey; + + SEL numberWithInt_sel = @selector(numberWithInt:); + SEL numberWithFloat_sel = @selector(numberWithFloat:); + SEL setObject_forKey_sel = @selector(setObject:forKey:); + + numberWithInt = [NSNumber methodForSelector:numberWithInt_sel]; + numberWithFloat = [NSNumber methodForSelector:numberWithFloat_sel]; + setObject_forKey = [dict methodForSelector:setObject_forKey_sel]; + +#define ADD_id_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, obj, name) + +#define ADD_int_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, \ + numberWithInt(numberClass, numberWithInt_sel, obj), \ + name) + +#define ADD_float_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, \ + numberWithFloat(numberClass, numberWithInt_sel, obj), \ + name) + +#define ADD_NSPoint_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, \ + [NSValue valueWithPoint:obj], \ + name) + +#define ADD_NSRange_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, \ + [NSValue valueWithRange:obj], \ + name) + +#define ADD_NSSize_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, \ + [NSValue valueWithSize:obj], \ + name) + +#define ADD_NSRect_OBJECT(obj, name) \ + setObject_forKey(dict, setObject_forKey_sel, \ + [NSValue valueWithRect:obj], \ + name) diff --git a/Modules/GNUmakefile b/Modules/GNUmakefile new file mode 100644 index 0000000..f4421e7 --- /dev/null +++ b/Modules/GNUmakefile @@ -0,0 +1,45 @@ +# +# 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 +# + +GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_USER_ROOT) + +GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles + +include $(GNUSTEP_MAKEFILES)/common.make + +APPKIT=AppKit + +ifeq ($(appkit),no) + APPKIT= +endif + +SUBPROJECTS = \ + SimpleTranscript \ + Foundation \ + $(APPKIT) + +-include GNUMakefile.preamble +include $(GNUSTEP_MAKEFILES)/aggregate.make +-include GNUMakefile.postamble + diff --git a/Modules/SimpleTranscript/GNUmakefile b/Modules/SimpleTranscript/GNUmakefile new file mode 100644 index 0000000..382bbf6 --- /dev/null +++ b/Modules/SimpleTranscript/GNUmakefile @@ -0,0 +1,46 @@ +# +# SimpleTranscript module +# +# Copyright (C)2001 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., 675 Mass Ave, Cambridge, MA 02111, USA. +# + +GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles + +include $(GNUSTEP_MAKEFILES)/common.make + +BUNDLE_NAME = SimpleTranscript + +SimpleTranscript_OBJC_FILES = \ + SimpleTranscriptModule.m \ + SimpleTranscript.m \ + +SimpleTranscript_PRINCIPAL_CLASS = SimpleTranscriptModule + + +SimpleTranscript_BUNDLE_LIBS += -lStepTalk +ADDITIONAL_INCLUDE_DIRS += -I../../Source/Headers +ADDITIONAL_LIB_DIRS += -L../../Source/$(GNUSTEP_OBJ_DIR) + + +BUNDLE_EXTENSION := .stmodule +BUNDLE_INSTALL_DIR:=$(GNUSTEP_INSTALLATION_DIR)/Library/StepTalk/Modules + +-include GNUmakefile.preamble +include $(GNUSTEP_MAKEFILES)/bundle.make +-include GNUMakefile.postamble diff --git a/Modules/SimpleTranscript/SimpleTranscript.h b/Modules/SimpleTranscript/SimpleTranscript.h new file mode 100644 index 0000000..cc915c4 --- /dev/null +++ b/Modules/SimpleTranscript/SimpleTranscript.h @@ -0,0 +1,34 @@ +/** + SimpleTranscript.h + StepTalk simple transcript + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2001 Apr 13 + + 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 SimpleTranscript:NSObject ++ sharedTranscript; +- show:(id)anObject; +- showLine:(id)anObject; +@end diff --git a/Modules/SimpleTranscript/SimpleTranscript.m b/Modules/SimpleTranscript/SimpleTranscript.m new file mode 100644 index 0000000..67fed89 --- /dev/null +++ b/Modules/SimpleTranscript/SimpleTranscript.m @@ -0,0 +1,84 @@ +/** + SimpleTranscript.m + StepTalk simple transcript + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2001 Apr 13 + + 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 "SimpleTranscript.h" + +#import +#import + +#include + +static Class NSString_class; +static Class NSNumber_class; + +static SimpleTranscript *sharedTranscript; + +@implementation SimpleTranscript:NSObject ++ (void)initialize +{ + NSString_class = [NSString class]; + NSNumber_class = [NSNumber class]; +} ++ sharedTranscript +{ + if(!sharedTranscript) + { + sharedTranscript = [[SimpleTranscript alloc] init]; + } + + return sharedTranscript; +} +- show:(id)anObject +{ + NSString *string; + + if( [anObject isKindOfClass:NSString_class] ) + { + string = anObject; + } + else if ( [anObject isKindOfClass:NSNumber_class] ) + { + string = [anObject stringValue]; + } + else + { + string = [anObject description]; + } + + printf("%s", [string cString]); + + return self; +} + +- showLine:(id)anObject +{ + [self show:anObject]; + putchar('\n'); + + return self; +} +@end diff --git a/Modules/SimpleTranscript/SimpleTranscriptInfo.plist b/Modules/SimpleTranscript/SimpleTranscriptInfo.plist new file mode 100644 index 0000000..7b13f14 --- /dev/null +++ b/Modules/SimpleTranscript/SimpleTranscriptInfo.plist @@ -0,0 +1,4 @@ +{ + STClasses = ( + ); +} diff --git a/Modules/SimpleTranscript/SimpleTranscriptModule.h b/Modules/SimpleTranscript/SimpleTranscriptModule.h new file mode 100644 index 0000000..7d8e78f --- /dev/null +++ b/Modules/SimpleTranscript/SimpleTranscriptModule.h @@ -0,0 +1,32 @@ +/** + SimpleTranscriptModule.h + Transcript module + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2001 May 18 + + 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 SimpleTranscriptModule:STModule +@end + diff --git a/Modules/SimpleTranscript/SimpleTranscriptModule.m b/Modules/SimpleTranscript/SimpleTranscriptModule.m new file mode 100644 index 0000000..803f414 --- /dev/null +++ b/Modules/SimpleTranscript/SimpleTranscriptModule.m @@ -0,0 +1,41 @@ +/** + SimpleTranscriptModule.m + Transcript module + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2001 May 18 + + 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 "SimpleTranscriptModule.h" +#import "SimpleTranscript.h" + +#import +@class NSDictionary; + +@implementation SimpleTranscriptModule +- (NSDictionary *)namedObjects +{ + return [NSDictionary dictionaryWithObject:[SimpleTranscript sharedTranscript] + forKey:@"Transcript"]; +} +@end + diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..df08d85 --- /dev/null +++ b/NEWS @@ -0,0 +1,61 @@ +0.5.2 + + * Separated AppTalk + * Added option to make "appkit=no" to disable making of AppKit stuff. + +0.5.1 + + * Added AppTalk application scripting library + * Smalltalk syntax changed. See Documentation/Smalltalk section Source. + * Fixed AppKit constants + * Make it build with latest GNUstep release + * Various bugfixes + +0.5.0 + + * support for NSRange, NSPoint and NSSize (see example range.st) + * Implemented SEL type handling (see examples selector.st and + notification.st) + * New example pldes.st - pldes tool written in smalltalk + + Smalltalk: + * Small (10-15%)speed improvements of block evaluation + * Handle 'exit' method in script object. 'self exit' will terminate script + execution. + * Documentation describing smalltalk features (exception handling, + symbolic selector and iterators) + +0.4.1 + + * Guile - new language bundle. gstep-guile library is needed. + + Guile bundle is not build by default. You have to make it in + Languages/Guile directory (make; make install). You may try to execute + very simple piece of code in Languages/Guile/Tests using stexec. + + NOTE: do not forget to run 'stupdate_languages' after installing any new + language bundle. To find out if languages were updated, try + 'stexec -list-languages' + + * Separated Foundation binding stuff to Foundation module + +0.4.0 + + * AppKit - new module + * AppKit examples + openPanel - shows NSOpenPanel + rtf2text - converts RTF document to plain text + * Added execution of script with more methods + * Tools will now try to get language type from file extension + * Added new tool stupdate_languages to create file extensions dictionary + +0.3.0 +for more details see ChangeLog file + + * Added few examples to show how scripting works. See Examples directory + in source package. + * Added tool 'stalk' to talk to named servers. + * Added new tool options. + * Some known bugs were fixed. + * Little bit of documentation added (see Documentation directory) + * STEnvironment interface changed diff --git a/README b/README new file mode 100644 index 0000000..edcbaee --- /dev/null +++ b/README @@ -0,0 +1,90 @@ +StepTalk +-------- + +Ahthor: Stefan Urbanek + + +What is StepTalk ? +------------------ + +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. It is written using +GNUstep. + + +Where to get it? +---------------- + +You can download StepTalk from + + http://steptalk.host.sk + + +Installation +------------ +To install StepTalk type: + > make + > make install + + +Tools +----- + stexec - execute a StepTalk script in the GNUstep Foundation environment + stalk - talk to named server + stupdate_languages - update the available languages info + + Predefined objects for executing scripts by 'stexec' + + Args - command line arguments + Engine - scripting engine + Environment - scripting environment + + Transcript - simple transcript + + +Sripting environment description +------------------------------------------- + +Scripting environment description is used to translate the method names and/or +allow or deny the methods for concrete classes. Denying methods can be used to +create safe scripting environment as prevention against script viruses. + +It contains: + - list of methods, that are available for scripting for particular class + - symbolic selector (operator) to selector mapping + + +Standard vs. full scripting +--------------------------- +Before each message send, selector is translated using scipting description. +When standard scripting is used and there is no such selector avilable for +scripting for target object, then an exception is raised. With full scripting, +any message should be sent to any target object. + +Files +----- + StepTalk is looking for its files in GNUSTEP_*_ROOT/Library/StepTalk + + There should be these directories: + + Environments + - directory containig environment descriptions + Languages + - StepTalk language bundles + Modules + - StepTalk modules + + Scripts + - directory containig StepTalk scripts + + +Defaults +-------- +See Documentation/Defaults.txt + + +Feedback +-------- +Any bug reports and comments are welcome at + diff --git a/Source/Environments/Foundation-operators.stenv b/Source/Environments/Foundation-operators.stenv new file mode 100644 index 0000000..063ee4f --- /dev/null +++ b/Source/Environments/Foundation-operators.stenv @@ -0,0 +1,123 @@ +/** Foundation-operators.stenv + */ + +{ + Name = "Foundation-operators"; + Use = (SymbolicSelectors); + + DefaultRestriction = AllowAll; + + Behaviours = + { + "NSObject-operators" = { + Use = (Comparison); + } + }; + + Classes = + { + NSObject = { + Use = ("NSObject-operators"); + }; + + NSArray = { + Super = "NSObject"; + SymbolicSelectors = { + "@" = "objectAtIndex:"; + "," = "arrayByAddingObject:"; + "+" = "arrayByAddingObject:"; + }; + }; + + NSMutableArray = { + Super = "NSArray"; + SymbolicSelectors = + { + "+=" = "addObject:"; + "-=" = "removeObject:"; + } + }; + + NSDictionary = + { + Super = NSObject; + SymbolicSelectors = { + "@" = "objectForKey:"; + } + }; + + NSUserDefaults = + { + Super = NSObject; + SymbolicSelectors = { + "@" = "objectForKey:"; + } + }; + + NSString = + { + Super = NSObject; + SymbolicSelectors = + { + "," = "stringByAppendingString:"; + "/" = "stringByAppendingPathComponent:"; + "@" = "characterAtIndex:"; + }; + Aliases = + { + size = length; + }; + }; + + NSMutableString = + { + Super = NSString; + SymbolicSelectors = + { + "+=" = "appendString:"; + } + }; + + NSSet = + { + Super = NSObject; + SymbolicSelectors = + { + "<" = "isSubsetOfSet:"; + } + + }; + NSMutableSet = + { + Super = NSSet; + SymbolicSelectors = + { + "+=" = "addObject:"; + "-=" = "removeObject:"; + } + }; + + NSDate = + { + Super = NSObject; + SymbolicSelectors = + { + "-" = "timeIntervalSinceDate:"; + } + + }; + + NSNumber = + { + Super = NSValue; + Use = (NumberArithmetic); + + SymbolicSelectors = + { + "<>" = "rangeWith:"; + "@" = "pointWith:"; + "@@" = "sizeWith:"; + } + }; + }; /* Classes */ +} diff --git a/Source/Environments/Foundation.stenv b/Source/Environments/Foundation.stenv new file mode 100644 index 0000000..c3437fd --- /dev/null +++ b/Source/Environments/Foundation.stenv @@ -0,0 +1,44 @@ +/** Foundation.stenv + */ + +{ + Name = "Foundation"; + + Use = ("Foundation-operators"); + + DefaultRestriction = AllowAll; + + Classes = + { + NSObject = { + Super = nil; + }; + + "NSObject class" = { + Super = nil; + }; + + NSString = + { + Super = "NSObject"; + }; + + NSArray = + { + Super = "NSObject"; + }; + NSDate = + { Super = "NSObject"; + }; + + NSValue = + { + Super = "NSObject"; + }; + + NSNumber = + { + Super = "NSValue"; + }; + }; /* Classes */ +} diff --git a/Source/Environments/Safe.stenv b/Source/Environments/Safe.stenv new file mode 100644 index 0000000..f639b52 --- /dev/null +++ b/Source/Environments/Safe.stenv @@ -0,0 +1,67 @@ +/** Foundation-safe.stenv + */ + +{ + Name = "Foundation-safe"; + + Use = ("Standard"); + + Behaviours = + { + "DenyWriteToFile" = { + DenyMethods = ( + "writeToFile:atomically:", + "writeToURL:atomically:" + ) + } + }; + + Classes = + { + NSString = + { + Use = (DenyWriteToFile); + }; + NSArray = + { + Use = (DenyWriteToFile); + }; + NSDictionary = + { + Use = (DenyWriteToFile); + }; + NSData = + { + Use = (DenyWriteToFile); + }; + + NSFileManager = + { + DenyMethods = ( + "copyPath:toPath:handler:", + "createFileAtPath:contents:attributes:", + "movePath:toPath:handler:", + "linkPath:toPath:handler:", + "removeFileAtPath:handler:", + "changeFileAttributes:atPath:", + "createSymbolicLinkAtPath:pathContent:" + ); + }; + + NSUserDefaults = + { + DenyMethods = ( + "removeObjectForKey:", + "setBool:forKey:", + "setFloat:forKey:", + "setInteger:forKey:", + "setObject:forKey:", + "removePersistentDomainForName:", + "setPersistentDomain:forName:", + "removeVolatileDomainForName:", + "setVolatileDomain:forName:", + "registerDefaults:" + ); + }; + }; /* Classes */ +} diff --git a/Source/Environments/Standard.stenv b/Source/Environments/Standard.stenv new file mode 100644 index 0000000..7f48326 --- /dev/null +++ b/Source/Environments/Standard.stenv @@ -0,0 +1,11 @@ +/** Standard.stenv + * Standard cripting description + */ + +{ + Name = "Standard"; + Use = ( "SymbolicSelectors", + "Foundation", + "StepTalk" + ); +} diff --git a/Source/Environments/StepTalk.stenv b/Source/Environments/StepTalk.stenv new file mode 100644 index 0000000..4d80acf --- /dev/null +++ b/Source/Environments/StepTalk.stenv @@ -0,0 +1,41 @@ +/** StepTalk.stenv + * StepTalk scripting description + * + * Copyright (c) 2000 Stefan Urbanek + * + * This file is part of the StepTalk project. + * + * + */ + +{ + Name = "StepTalk"; + + Classes = + { + STBlock = + { + Super = NSObject; + AllowMethods = + ( + "value", + "valueWith:", + "valueWith:with:", + "valueWith:with:with:", + "valueWith:with:with:with:", + "argumentCount", + "handler:" + ); + }; + STScriptObject = + { + Super = NSObject; + Restriction = AllowAll; + }; + STUndefinedObject = + { + Super = nil; + Restriction = AllowAll; + }; + } +} diff --git a/Source/Environments/SymbolicSelectors.stenv b/Source/Environments/SymbolicSelectors.stenv new file mode 100644 index 0000000..408d5ae --- /dev/null +++ b/Source/Environments/SymbolicSelectors.stenv @@ -0,0 +1,42 @@ +/** SymbolicSelectors.stenv + * Mappings for some symbolic selectors + * + * Copyright (c) 2000 Stefan Urbanek + * + * This file is part of the StepTalk project. + * + */ + +{ + Name = "SymbolicSelectors"; + + Behaviours = + { + Comparison = { + SymbolicSelectors = + { + "=" = "isEqual:"; + "==" = "isSame:"; + "~=" = "notEqual:"; + "~~" = "notSame:"; + + "<" = "isLessThan:"; + ">" = "isGreatherThan:"; + "<=" = "isLessOrEqualThan:"; + ">=" = "isGreatherOrEqualThan:"; + + } + }; + + NumberArithmetic = + { + SymbolicSelectors = + { + "+" = "add:"; + "-" = "subtract:"; + "*" = "multiply:"; + "/" = "divide:"; + }; + }; + }; +} diff --git a/Source/GNUmakefile b/Source/GNUmakefile new file mode 100644 index 0000000..3110f20 --- /dev/null +++ b/Source/GNUmakefile @@ -0,0 +1,96 @@ +# +# 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. + +GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles + +include $(GNUSTEP_MAKEFILES)/common.make + +include ../Version + +LIBRARY_NAME = libStepTalk + +libStepTalk_OBJC_FILES = \ + STBehaviourInfo.m \ + STClassInfo.m \ + STEnvironment.m \ + STExterns.m \ + STFunctions.m \ + STLanguage.m \ + STObjectReference.m \ + STUndefinedObject.m \ + NSInvocation+additions.m \ + STEnvironmentDescription.m \ + STObjCRuntime.m \ + STStructure.m \ + STEngine.m \ + STModule.m \ + STScripting.m \ + STSelector.m \ + NSNumber+additions.m + +STEPTALK_HEADER_FILES = \ + STEnvironment.h \ + STExterns.h \ + STFunctions.h \ + STLanguage.h \ + STObjectReference.h \ + STUndefinedObject.h \ + NSInvocation+additions.h \ + STObjCRuntime.h \ + STEngine.h \ + STModule.h \ + STScripting.h \ + STSelector.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 + +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 + + +-include GNUmakefile.preamble + +include $(GNUSTEP_MAKEFILES)/library.make + +ifeq ($(doc),yes) +include $(GNUSTEP_MAKEFILES)/documentation.make +endif + +-include GNUmakefile.postamble diff --git a/Source/GNUmakefile.postamble b/Source/GNUmakefile.postamble new file mode 100644 index 0000000..da1df2d --- /dev/null +++ b/Source/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 *; 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/Source/Headers/StepTalk/NSInvocation+additions.h b/Source/Headers/StepTalk/NSInvocation+additions.h new file mode 100644 index 0000000..a1e2d30 --- /dev/null +++ b/Source/Headers/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/Source/Headers/StepTalk/NSNumber+additions.h b/Source/Headers/StepTalk/NSNumber+additions.h new file mode 100644 index 0000000..6d474c4 --- /dev/null +++ b/Source/Headers/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/Source/Headers/StepTalk/STBehaviourInfo.h b/Source/Headers/StepTalk/STBehaviourInfo.h new file mode 100644 index 0000000..af3a834 --- /dev/null +++ b/Source/Headers/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/Source/Headers/StepTalk/STClassInfo.h b/Source/Headers/StepTalk/STClassInfo.h new file mode 100644 index 0000000..9500294 --- /dev/null +++ b/Source/Headers/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/Source/Headers/StepTalk/STEngine.h b/Source/Headers/StepTalk/STEngine.h new file mode 100644 index 0000000..ccbe137 --- /dev/null +++ b/Source/Headers/StepTalk/STEngine.h @@ -0,0 +1,59 @@ +/** + 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 + +@class STEnvironment; +@class STLanguageEngine; + +@interface STEngine:NSObject +{ + STEnvironment *defaultEnvironment; +} + +/*" Instance creation "*/ ++ (STEngine *) engineForLanguageWithName:(NSString *)language; + +/*" Environment "*/ +- (STEnvironment *)defaultEnvironment; +- (void) setDefaultEnvironment:(STEnvironment *)anEnvironment; + +- (id) executeCode:(NSString *)code; + +- (id) executeCode:(NSString *)code + inEnvironment:(STEnvironment *)env; + +- (BOOL)understandsCode:(NSString *)code; + +/*" Script execution "*/ +/* +- (id) executeScript:(NSString *)script; +- (id) executeScript:(NSString *)script withArguments:(NSArray *)args; +- (id) executeScriptFromFile:(NSString *)fileName withArguments:(NSArray *)args; +- (id) executeScriptSource:(NSString *)source withArguments:(NSArray *)args; +*/ +@end diff --git a/Source/Headers/StepTalk/STEnvironment.h b/Source/Headers/StepTalk/STEnvironment.h new file mode 100644 index 0000000..8540c6b --- /dev/null +++ b/Source/Headers/StepTalk/STEnvironment.h @@ -0,0 +1,105 @@ +/** + 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 NSDictionary; +@class NSMutableDictionary; +@class NSMutableSet; + +@class STObjectReference; +@class STEnvironmentDescription; + +@interface STEnvironment:NSObject +{ + NSMutableDictionary *pools; + NSMutableDictionary *defaultPool; + + STEnvironmentDescription *description; + NSMutableDictionary *classes; /* from description */ + +// NSMutableSet *modules; + + BOOL fullScripting; + BOOL createsUnknownObjects; + + NSMutableDictionary *infoCache; +} +/** Creating environment */ ++ (STEnvironment *)defaultScriptingEnvironment; + ++ environmentWithDescriptionName:(NSString *)descName; ++ environmentWithDescriptionFromDictionary:(NSDictionary *)dict; ++ environmentWithDescriptionFromFile:(NSString *)path; + +- initWithDescriptionName:(NSString *)descName; +- initWithDescriptionFromDictionary:(NSDictionary *)dict; +- initWithDescriptionFromFile:(NSString *)path; + +/** Full scripting */ + +- (void)setFullScriptingEnabled:(BOOL)flag; +- (BOOL)fullScriptingEnabled; + +-(void)setCreatesUnknownObjects:(BOOL)flag; +-(BOOL)createsUnknownObjects; + +/** Modules */ + +- (void) loadModule:(NSString *)moduleName; + +- (void)addClassesWithNames:(NSArray *)names; + +/** Named objects and object references */ + +- (void)setObject:(id)anObject + forName:(NSString *)objName; + +- (void)removeObjectWithName:(NSString *)objName; +- (void)removeObjectWithName:(NSString *)objName + pool:(NSString *)poolName; + +- (void)addNamedObjectsFromDictionary:(NSDictionary *)dict; +- (void)addNamedObjectsFromDictionary:(NSDictionary *)dict + pool:(NSString *)poolName; + +- (id)objectWithName:(NSString *)objName; +- (id)objectWithName:(NSString *)objName + pool:(NSString *)poolName; + +- (STObjectReference *)objectReferenceForObjectWithName:(NSString *)name; +- (STObjectReference *)objectReferenceForObjectWithName:(NSString *)name + pool:(NSString *)poolName; + +- (void)removePool:(NSString *)poolName; + +/** Selector translation */ + +- (NSString *)translateSelector:(NSString *)aString forReceiver:(id)anObject; +@end diff --git a/Source/Headers/StepTalk/STEnvironmentDescription.h b/Source/Headers/StepTalk/STEnvironmentDescription.h new file mode 100644 index 0000000..52fe1f0 --- /dev/null +++ b/Source/Headers/StepTalk/STEnvironmentDescription.h @@ -0,0 +1,65 @@ +/** + STEnvironmentDescription.m + Script executor + + 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; + + int restriction; +} ++ (NSString *)defaultEnvironmentDescriptionName; + ++ descriptionWithName:(NSString *)descriptionName; ++ descriptionFromFile:(NSString *)fileName; ++ descriptionFromDictionary:(NSDictionary *)dictionary; + +- initFromFile:(NSString *)fileName; +- initWithName:(NSString *)defName; +- initFromDictionary:(NSDictionary *)def; + +- (void)updateFromDictionary:(NSDictionary *)def; +- (void)updateClassWithName:(NSString *)className description:(NSDictionary *)def; + +- (NSMutableDictionary *)classes; +@end + diff --git a/Source/Headers/StepTalk/STExterns.h b/Source/Headers/StepTalk/STExterns.h new file mode 100644 index 0000000..3a5f376 --- /dev/null +++ b/Source/Headers/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/Source/Headers/StepTalk/STFunctions.h b/Source/Headers/StepTalk/STFunctions.h new file mode 100644 index 0000000..08b8746 --- /dev/null +++ b/Source/Headers/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/Source/Headers/StepTalk/STLanguage.h b/Source/Headers/StepTalk/STLanguage.h new file mode 100644 index 0000000..90f17c3 --- /dev/null +++ b/Source/Headers/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 *)allLanguageNames; + ++ languageWithName:(NSString *)languageName; ++ languageWithBundle:(NSString *)path; + ++ (NSString *)languageNameForFileType:(NSString *)fileType; ++ (STLanguage *)languageForFileType:(NSString *)fileType; + +- (NSString *)languageName; + +- (STEngine *)engine; +@end diff --git a/Source/Headers/StepTalk/STModule.h b/Source/Headers/StepTalk/STModule.h new file mode 100644 index 0000000..fa69c0e --- /dev/null +++ b/Source/Headers/StepTalk/STModule.h @@ -0,0 +1,45 @@ +/** + STModule.h + StepTalk module + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2001 May 7 + + 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 NSString; +@class NSBundle; + +@interface STModule:NSObject +{ +} + ++ (NSArray *)allModuleNames; + ++ moduleWithName:(NSString *)moduleName; ++ moduleWithPath:(NSString *)modulePath; + +- (NSDictionary *)namedObjects; +- (NSBundle *)bundle; +@end diff --git a/Source/Headers/StepTalk/STObjCRuntime.h b/Source/Headers/StepTalk/STObjCRuntime.h new file mode 100644 index 0000000..02ba95a --- /dev/null +++ b/Source/Headers/StepTalk/STObjCRuntime.h @@ -0,0 +1,42 @@ +/** + 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 NSMutableDictionary *STClassDictionaryFromNames(NSArray *classNames); + +extern NSValue *STValueFromSelector(SEL sel); +extern SEL STSelectorFromValue(NSValue *val); +extern SEL STSelectorFromString(NSString *aString); +NSMethodSignature *STMethodSignatureForSelector(SEL sel); diff --git a/Source/Headers/StepTalk/STObjectReference.h b/Source/Headers/StepTalk/STObjectReference.h new file mode 100644 index 0000000..60fb00e --- /dev/null +++ b/Source/Headers/StepTalk/STObjectReference.h @@ -0,0 +1,54 @@ +/** + 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; + +- initWithObjectName:(NSString *)name + pool:(NSMutableDictionary *)aPool + create:(BOOL)createFlag; + +- (void)setObject:anObject; +- object; + +- (NSString *)objectName; +- (void)setObjectName:(NSString *)newName; + +- (NSMutableDictionary *) pool; +- (void)setPool:(NSMutableDictionary *) aDict; +@end + diff --git a/Source/Headers/StepTalk/STScripting.h b/Source/Headers/StepTalk/STScripting.h new file mode 100644 index 0000000..1f16b46 --- /dev/null +++ b/Source/Headers/StepTalk/STScripting.h @@ -0,0 +1,45 @@ +/** + 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; + +- (STEnvironment *)scriptingEnvironment; +@end + + +@interface NSObject (STScripting) +@end diff --git a/Source/Headers/StepTalk/STSelector.h b/Source/Headers/StepTalk/STSelector.h new file mode 100644 index 0000000..3b769a1 --- /dev/null +++ b/Source/Headers/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/Source/Headers/StepTalk/STStructure.h b/Source/Headers/StepTalk/STStructure.h new file mode 100644 index 0000000..b1f40bb --- /dev/null +++ b/Source/Headers/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/Source/Headers/StepTalk/STUndefinedObject.h b/Source/Headers/StepTalk/STUndefinedObject.h new file mode 100644 index 0000000..c6735b1 --- /dev/null +++ b/Source/Headers/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/Source/Headers/StepTalk/StepTalk.h b/Source/Headers/StepTalk/StepTalk.h new file mode 100644 index 0000000..4d2bead --- /dev/null +++ b/Source/Headers/StepTalk/StepTalk.h @@ -0,0 +1,38 @@ +/** + 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 diff --git a/Source/NSInvocation+additions.m b/Source/NSInvocation+additions.m new file mode 100644 index 0000000..159e4c8 --- /dev/null +++ b/Source/NSInvocation+additions.m @@ -0,0 +1,279 @@ +/** + 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 + +#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) ++ invocationWithTarget:(id)target selectorName:(NSString *)selectorName +{ + NSMethodSignature *signature; + NSInvocation *invocation; + SEL sel; + + sel = STSelectorFromString(selectorName); + + signature = [target methodSignatureForSelector: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/Source/NSNumber+additions.m b/Source/NSNumber+additions.m new file mode 100644 index 0000000..b431576 --- /dev/null +++ b/Source/NSNumber+additions.m @@ -0,0 +1,120 @@ +/** + 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])]; +} + +- (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/Source/STBehaviourInfo.m b/Source/STBehaviourInfo.m new file mode 100644 index 0000000..6d5233f --- /dev/null +++ b/Source/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/Source/STClassInfo.m b/Source/STClassInfo.m new file mode 100644 index 0000000..00ba1f2 --- /dev/null +++ b/Source/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/Source/STEngine.m b/Source/STEngine.m new file mode 100644 index 0000000..e606d63 --- /dev/null +++ b/Source/STEngine.m @@ -0,0 +1,116 @@ +/** + 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); + } +} + ++ (STEngine *) engineForFileType:(NSString *)fileType +{ + STLanguage *language = [STLanguage languageForFileType:fileType]; + + return [language engine]; +} + ++ (STEngine *) engineForLanguage:(NSString *)name +{ + if(!name) + { + NSLog(@"No language name given"); + return NULL; + } + + return [[STLanguage languageWithName:name] engine]; +} + +- (void)dealloc +{ + RELEASE(defaultEnvironment); + + [super dealloc]; +} + +- (STEnvironment *)defaultEnvironment +{ + return defaultEnvironment; +} + +- (void) setDefaultEnvironment:(STEnvironment *)anEnvironment +{ + ASSIGN(defaultEnvironment,anEnvironment); +} + +- (id) executeCode:(NSString *)code +{ + return [self executeCode:code + inEnvironment:defaultEnvironment]; +} +- (id) executeCode:(NSString *)code + inEnvironment:(STEnvironment *)env +{ + [self subclassResponsibility:_cmd]; + + return nil; +} + +- (BOOL)understandsCode:(NSString *)code +{ + [self subclassResponsibility:_cmd]; + + return NO; +} +@end diff --git a/Source/STEnvironment.m b/Source/STEnvironment.m new file mode 100644 index 0000000..8b2b07a --- /dev/null +++ b/Source/STEnvironment.m @@ -0,0 +1,535 @@ +/** + 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 + +@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 description + from dictionary dict. + */ ++ environmentWithDescriptionFromDictionary:(NSDictionary *)dict +{ + return AUTORELEASE([[self alloc] initWithDescriptionFromDictionary:dict]); + +} + +/** + Creates and initialises scripting environment using description + from file at path. + */ ++ environmentWithDescriptionFromFile:(NSString *)path +{ + return AUTORELEASE([[self alloc] initWithDescriptionFromFile:path]); + +} + +- init +{ + defaultPool = [[NSMutableDictionary alloc] init]; +/* FIXME: */ +// [defaultPool setObject:STNil forKey:@"nil"]; + infoCache = [[NSMutableDictionary alloc] init]; + + return [super init]; +} + +/** + Initialises scripting environment using description with name + descName. + */ +- initWithDescriptionName:(NSString *)descName +{ + [self init]; + + description = [STEnvironmentDescription descriptionWithName:descName]; + classes = [description classes]; + + RETAIN(description); + + return self; +} + +/** + Initialises scripting environment using description from dictionary + dict. + */ +- initWithDescriptionFromDictionary:(NSDictionary *)dict +{ + [self init]; + + description = [STEnvironmentDescription descriptionFromDictionary:dict]; + classes = [description classes]; + + RETAIN(description); + + return self; +} + +/** + Initialises scripting environment using description + from file at path + */ +- initWithDescriptionFromFile:(NSString *)path +{ + [self init]; + + description = [STEnvironmentDescription descriptionFromFile:path]; + classes = [description classes]; + + RETAIN(description); + + return self; +} + +- (void)dealloc +{ + RELEASE(defaultPool); + RELEASE(pools); + RELEASE(description); + + RELEASE(infoCache); + + [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. + */ +-(void)setCreatesUnknownObjects:(BOOL)flag +{ + createsUnknownObjects = flag; +} + +/** + Returns YES if unknown objects are being created. + */ +-(BOOL)createsUnknownObjects +{ + return createsUnknownObjects; +} + +- (void)addAllClasses +{ + [self addNamedObjectsFromDictionary:STAllObjectiveCClasses()]; +} +/** + Add classes specified by name in names array. +*/ +- (void)addClassesWithNames:(NSArray *)names +{ + [self addNamedObjectsFromDictionary:STClassDictionaryFromNames(names)]; +} + +/** + Load StepTalk module with name moduleName. You do not have to + add module extension .stmodule to moduleName. Modules are stored + in Library/StepTalk/Modules + */ +- (void) loadModule:(NSString *)moduleName +{ + STModule *module = [STModule moduleWithName:moduleName]; + + [self addNamedObjectsFromDictionary:[module namedObjects]]; + [self addClassesWithNames:[module providedClasses]]; +} + +/** + Description forthcomming. + */ +- (NSMutableDictionary *)defaultObjectPool +{ + return defaultPool; +} + +/* ----------------------------------------------------------------------- + Object pools + ----------------------------------------------------------------------- */ + +/** + Register object anObject with name objName. + */ +- (void)addObject:(id)anObject + withName:(NSString *)objName +{ + NSLog(@"In STEnvironment: addObject:withName: used. Use setObject:forName:"); + [defaultPool setObject:anObject forKey:objName]; +} + +/** + 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]; + } +} + +/** + Description forthcomming. + */ + +- (NSMutableDictionary *) poolWithName:(NSString *)poolName +{ + NSMutableDictionary *pool = [pools objectForKey:poolName]; + + if(!defaultPool) + { + defaultPool = [[NSMutableDictionary alloc] init]; + } + + if(!pool) + { + [NSException raise:STGenericException + format:@"Undefined pool with name '%@'", poolName]; + + + pool = defaultPool; + } + + return pool; +} + + +/** + Register object anObject with name objName in pool + poolName. + */ +- (void)addObject:(id)anObject + withName:(NSString *)objName + pool:(NSString *)poolName +{ + + [[self poolWithName:poolName] setObject:anObject forKey:objName]; +} + +/** + Remove object named objName. + */ +- (void)removeObjectWithName:(NSString *)objName +{ + [defaultPool removeObjectForKey:objName]; +} + +/** + Remove object named objName form pool poolName + */ +- (void)removeObjectWithName:(NSString *)objName + pool:(NSString *)poolName +{ + [[self poolWithName:poolName] removeObjectForKey:objName]; +} + +/** + + */ +- (void)addNamedObjectsFromDictionary:(NSDictionary *)dict +{ + [defaultPool addEntriesFromDictionary:dict]; +} + + +- (void)addNamedObjectsFromDictionary:(NSDictionary *)dict + pool:(NSString *)poolName +{ + [[self poolWithName:poolName] addEntriesFromDictionary:dict]; + +} + +- (id)objectWithName:(NSString *)objName +{ + id object; + + object = [defaultPool objectForKey:objName]; + + return object; +} + +- (id)objectWithName:(NSString *)objName + pool:(NSString *)poolName + +{ + id object; + + object = [[self poolWithName:poolName] objectForKey:objName]; + + return object; +} + +- (STObjectReference *)objectReferenceForObjectWithName:(NSString *)name +{ + STObjectReference *ref; + + ref = [STObjectReference alloc]; + [ref initWithObjectName:name + pool:defaultPool + create:createsUnknownObjects]; + + return AUTORELEASE(ref); +} + +- (STObjectReference *)objectReferenceForObjectWithName:(NSString *)name + pool:(NSString *)poolName +{ + STObjectReference *ref; + + ref = [STObjectReference alloc]; + [ref initWithObjectName:name + pool:[self poolWithName:poolName] + create:createsUnknownObjects]; + + return AUTORELEASE(ref); + +} + +- (void)removePool:(NSString *)poolName +{ + [pools removeObjectForKey:poolName]; +} + + +/* FIXME: rewrite */ +- (STClassInfo *)findClassInfoForObject:(id)anObject +{ + NSString *origName; + NSString *name; + STClassInfo *info = nil; + Class class; + + if(!anObject) + { + anObject = STNil; + } + + if( [anObject isProxy] ) + { + NSDebugLog(@"FIXME: receiver is a distant object"); + return nil; + } + + class = [anObject classForScripting]; + + if([anObject isClass]) + { + origName = name = [[class className] + stringByAppendingString:@" class"]; + + NSDebugLLog(@"STSending", + @"Looking for class info '%@'...", + name); + + info = [infoCache objectForKey:name]; + + if(info) + { + return info; + } + + while( !(info = [classes objectForKey:name]) ) + { + class = [[class superclass] classForScripting]; + if(!class) + { + break; + } + + name = [[class className] + stringByAppendingString:@" class"]; + NSDebugLLog(@"STSending", + @" ... %@?",name); + } + } + else + { + origName = name = [class className]; + + NSDebugLLog(@"STSending", + @"Looking for class info '%@' (instance)...", + name); + + info = [infoCache objectForKey:name]; + if(info) + { + return info; + } + + while( !(info = [classes objectForKey:name]) ) + { + class = [[class superclass] classForScripting]; + if(!class) + { + break; + } + + name = [class className]; + NSDebugLLog(@"STSending", + @" ... %@?",name); + } + } + + if(!info) + { + NSDebugLLog(@"STSending", + @"No class info '%@'", + name); + return nil; + } + + NSDebugLLog(@"STSending", + @"Found class info '%@'", + name); + + [infoCache setObject:info forKey:origName]; + return info; +} + +- (NSString *)translateSelector:(NSString *)aString forReceiver:(id)anObject +{ + STClassInfo *class; + NSString *selector; + + if( [anObject isProxy] ) + { + NSDebugLog(@"Warning: receiver is a distant object (FIXME)"); + + return aString; + } + + 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; +} +@end diff --git a/Source/STEnvironmentDescription.m b/Source/STEnvironmentDescription.m new file mode 100644 index 0000000..c319d13 --- /dev/null +++ b/Source/STEnvironmentDescription.m @@ -0,0 +1,454 @@ +/** + 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; +@end + +@implementation STEnvironmentDescription ++ (NSString *)defaultEnvironmentDescriptionName +{ + NSUserDefaults *defs; + NSDictionary *dict; + NSString *name; + + defs = [NSUserDefaults standardUserDefaults]; + dict = [defs persistentDomainForName:@"StepTalk"]; + name = [dict objectForKey:@"DefaultEnvironmentDescriptionName"]; + + if(!name || [name isEqualToString:@""]) + { + name = [NSString stringWithString:@"Standard"]; + } + + return name; +} + ++ descriptionWithName:(NSString *)descriptionName +{ + return AUTORELEASE([[self alloc] initWithName:descriptionName]); +} ++ descriptionFromFile:(NSString *)fileName +{ + return AUTORELEASE([[self alloc] initFromFile:fileName]); +} ++ descriptionFromDictionary:(NSDictionary *)dictionary +{ + return AUTORELEASE([[self alloc] initFromDictionary:dictionary]); +} +- (void)dealloc +{ + RELEASE(behaviours); + RELEASE(classes); + [super dealloc]; +} + +- initFromFile:(NSString *)fileName +{ + NSDictionary *dict; + + dict = [NSDictionary dictionaryWithContentsOfFile:fileName]; + return [self initFromDictionary:dict]; +} + +- 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 updateUseListFromDictionary:def]; + [self updateBehavioursFromDictionary:def]; + [self updateClassesFromDictionary:def]; + [self updateAliasesFromDictionary:def]; + + restriction = saveFlag; +} + +- (void)updateUseListFromDictionary:(NSDictionary *)def +{ + NSEnumerator *enumerator; + NSString *str; + + if(!def) + { + return; + } + + enumerator = [[def objectForKey:@"Use"] objectEnumerator]; + + while( (str = [enumerator nextObject]) ) + { + if(!usedDefs) + { + usedDefs = [[NSMutableArray alloc] init]; + } + if( [usedDefs containsObject:str] ) + { + continue; + } + else + { + [usedDefs addObject:str]; + } + + [self updateFromDictionary:dictForDescriptionWithName(str)]; + } + +} + +- (void)updateBehavioursFromDictionary:(NSDictionary *)aDict +{ + NSEnumerator *enumerator; + NSDictionary *dict; + NSString *name; + + STBehaviourInfo *behInfo; + + dict = [aDict objectForKey:@"Behaviours"]; + 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]; +// NSDebugLog(@"Create behaviour %@", name); + + [self updateBehaviour:behInfo description:[dict objectForKey:name]]; + } + +} + +- (void)updateBehaviour:(STBehaviourInfo *)behInfo + description:(NSDictionary *)def +{ + NSString *str; + NSEnumerator *enumerator; + STBehaviourInfo *useInfo; + + +// NSDebugLog(@"Update behaviour '%@'", [behInfo behaviourName]); + + 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"]]]; + + /* FIXME: should be special */ + [behInfo addTranslationsFromDictionary:[def objectForKey:@"SymbolicSelectors"]]; + + [behInfo addTranslationsFromDictionary:[def objectForKey:@"Aliases"]]; +} + +- (void)updateClassesFromDictionary:(NSDictionary *)def +{ + NSEnumerator *enumerator; + NSDictionary *dict; + NSString *str; + + dict = [def objectForKey:@"Classes"]; + 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 *)def +{ + NSEnumerator *enumerator; + NSDictionary *dict; + NSString *str; + + dict = [def objectForKey:@"Aliases"]; + enumerator = [dict keyEnumerator]; + + while( (str = [enumerator nextObject]) ) + { + [aliases setObject:str forKey:[dict objectForKey:str]]; + } +} + +- (NSMutableDictionary *)classes +{ + return classes; +} + +- (void)fixupScriptingDescription +{ + [self resolveSuperclasses]; +} + +- (void)resolveSuperclasses +{ + STClassInfo *class; + STClassInfo *superclass; + NSString *className; + NSEnumerator *enumerator; + + enumerator = [classes objectEnumerator]; + + while( (class = [enumerator nextObject]) ) + { + className = [class superclassName]; + + if( (className == nil) || [className isEqualToString:@"nil"] ) + { + continue; + } + + 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/Source/STExterns.m b/Source/STExterns.m new file mode 100644 index 0000000..df5cd26 --- /dev/null +++ b/Source/STExterns.m @@ -0,0 +1,56 @@ +/** + 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 *STScriptExtension = @"stalk"; + +NSString *STModulesDirectory = @"Modules"; +NSString *STModuleExtension = @"stmodule"; + +NSString *STScriptingEnvironmentsDirectory = @"Environments"; +NSString *STScriptingEnvironmentExtension = @"stenv"; + +NSString *STLanguageBundlesDirectory = @"Languages"; +NSString *STLanguageBundleExtension = @"stlanguage"; + +NSString *STLanguagesConfigFile = @"Languages.plist"; diff --git a/Source/STFunctions.m b/Source/STFunctions.m new file mode 100644 index 0000000..48fccf7 --- /dev/null +++ b/Source/STFunctions.m @@ -0,0 +1,128 @@ +/** + 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 + + +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]; + + 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 AUTORELEASE([resources copy]); +} + +NSString *STUserConfigPath(void) +{ + NSString *path = nil; + NSArray *paths; + + paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, + NSUserDomainMask, YES); + path = [paths objectAtIndex: 0]; + + path = [path stringByAppendingPathComponent:STLibraryDirectory]; + path = [path stringByAppendingPathComponent:@"Config"]; + + return path; +} diff --git a/Source/STLanguage.m b/Source/STLanguage.m new file mode 100644 index 0000000..f47d545 --- /dev/null +++ b/Source/STLanguage.m @@ -0,0 +1,197 @@ +/** + 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 + +static NSDictionary *fileTypeDictionary = nil; + +@implementation STLanguage ++ (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 languageWithBundle:path]; + + [languages addObject:[lang languageName]]; + } + + return AUTORELEASE([languages copy]); +} ++ (NSString *)defaultLanguageName +{ + NSUserDefaults *defs = [NSUserDefaults standardUserDefaults]; + NSDictionary *dict = [defs persistentDomainForName:@"StepTalk"]; + NSString *name; + name = [dict objectForKey:@"DefaultLanguageName"]; + + if(!name) + { + return @"Smalltalk"; + } + else + { + return name; + } +} + ++ languageWithName:(NSString *)languageName +{ + NSString *file = STFindResource(languageName, STLanguageBundlesDirectory, + STLanguageBundleExtension); + if(!file) + { + NSLog(@"Could not find language with name '%@'", languageName); + return nil; + } + + return [self languageWithBundle:file]; + +} + ++ languageWithBundle:(NSString *)path +{ + if(!path) + { + return nil; + } + + return AUTORELEASE([[STLanguage alloc] initWithPath:path]); +} + ++ (NSString *)languageNameForFileType:(NSString *)fileType +{ + if(!fileTypeDictionary) + { + NSString *path = STUserConfigPath(); + NSFileManager *fm = [NSFileManager defaultManager]; + NSTask *task; + NSDictionary *dict; + + 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); + } + + return [fileTypeDictionary objectForKey: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; +} + +- (NSString *)languageName +{ + NSString *name; + + name = [[self infoDictionary] objectForKey:@"STLanguageName"]; + + if(!name) + { + + name = [[self bundlePath] lastPathComponent]; + name = [name stringByDeletingPathExtension]; + } + + return name; +} + +/** + Returns default language engine. +*/ +- (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/Source/STModule.m b/Source/STModule.m new file mode 100644 index 0000000..18ef1e5 --- /dev/null +++ b/Source/STModule.m @@ -0,0 +1,101 @@ +/** + STMoudle.m + StepTalk module + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2001 May 7 + + 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 STModule ++ (NSArray *)allModuleNames +{ + NSLog(@"+[STModule allModuleNames] not implemented yet"); + + return nil; +} + ++ moduleWithName:(NSString *)moduleName +{ + NSString *file = STFindResource(moduleName, STModulesDirectory, + STModuleExtension); + if(!file) + { + NSLog(@"Could not find module with name '%@'", moduleName); + return nil; + } + + return [self moduleWithPath:file]; +} + ++ moduleWithPath:(NSString *)modulePath +{ + NSBundle *bundle; + STModule *module; + + bundle = [NSBundle bundleWithPath:modulePath]; + + if(!bundle) + { + NSLog(@"Could not load module '%@'", modulePath); + return nil; + } + + + NSDebugLog(@"Instantiating module '%@'", modulePath); + module = [[[bundle principalClass] alloc] init]; + + if(!module) + { + NSLog(@"Could not instantiate module '%@'", modulePath); + return nil; + } + + NSDebugLog(@"Module '%@' loaded", modulePath); + return AUTORELEASE(module); +} + +- (NSArray *)providedClasses +{ + return [[[self bundle] infoDictionary] objectForKey:@"STClasses"]; +} + +/* Subclass responsibility */ +- (NSDictionary *)namedObjects +{ + return nil; +} + +- (NSBundle *)bundle +{ + return [NSBundle bundleForClass:[self class]]; +} +@end diff --git a/Source/STObjCRuntime.m b/Source/STObjCRuntime.m new file mode 100644 index 0000000..d1672f8 --- /dev/null +++ b/Source/STObjCRuntime.m @@ -0,0 +1,159 @@ +/** + 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 + +@class NSProcessInfo ; +/* FIXME: this is just for testing */ +#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; +} + +NSMutableDictionary *STClassDictionaryFromNames(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 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; +} + +NSMethodSignature *STMethodSignatureForSelector(SEL sel) +{ + return [NSMethodSignature signatureWithObjCTypes:sel_get_type(sel)]; +} diff --git a/Source/STObjectReference.m b/Source/STObjectReference.m new file mode 100644 index 0000000..d098300 --- /dev/null +++ b/Source/STObjectReference.m @@ -0,0 +1,106 @@ +/** + 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 +{ + return [self initWithObjectName:name + pool:pool + create:NO]; +} + +- initWithObjectName:(NSString *)name + pool:(NSMutableDictionary *)aPool + create:(BOOL)createFlag +{ + + [super init]; + + key = RETAIN(name); + pool = RETAIN(aPool); + + if(![self object] && createFlag) + { + NSDebugLog(@"Creating object name '%@'", name); + [pool setObject:STNil forKey:name]; + } + + + 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/Source/STScripting.m b/Source/STScripting.m new file mode 100644 index 0000000..abaf52f --- /dev/null +++ b/Source/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/Source/STSelector.m b/Source/STSelector.m new file mode 100644 index 0000000..6563a8e --- /dev/null +++ b/Source/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 [self description]; +} +@end diff --git a/Source/STStructure.m b/Source/STStructure.m new file mode 100644 index 0000000..4952751 --- /dev/null +++ b/Source/STStructure.m @@ -0,0 +1,307 @@ +/** + 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; + + + 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 [super init]; +} +- (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 +{ + return [fields objectAtIndex:0]; +} + +- (id)size +{ + return [fields objectAtIndex:1] ; +} + +@end diff --git a/Source/STUndefinedObject.m b/Source/STUndefinedObject.m new file mode 100644 index 0000000..5793e03 --- /dev/null +++ b/Source/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/Testing/Smalltalk/block_test.st b/Testing/Smalltalk/block_test.st new file mode 100644 index 0000000..bd756d6 --- /dev/null +++ b/Testing/Smalltalk/block_test.st @@ -0,0 +1,7 @@ +| array | + +array := NSMutableArray array. + +1 to: 10000 do: [ :i | array addObject: i]. + +Transcript showLine:array count. diff --git a/Testing/Smalltalk/extern.st b/Testing/Smalltalk/extern.st new file mode 100644 index 0000000..e7b07e3 --- /dev/null +++ b/Testing/Smalltalk/extern.st @@ -0,0 +1,8 @@ +1 to: 100000 do: +[ :i | + extern := nil. + extern := nil. + extern := nil. + extern := nil. + extern := nil. +] diff --git a/Testing/Smalltalk/local.st b/Testing/Smalltalk/local.st new file mode 100644 index 0000000..790f008 --- /dev/null +++ b/Testing/Smalltalk/local.st @@ -0,0 +1,10 @@ +| local | + +1 to: 100000 do: +[ :i | + local := nil. + local := nil. + local := nil. + local := nil. + local := nil. +] diff --git a/Testing/Smalltalk/nil.st b/Testing/Smalltalk/nil.st new file mode 100644 index 0000000..8a1cc59 --- /dev/null +++ b/Testing/Smalltalk/nil.st @@ -0,0 +1 @@ +nil objectAtIndex:1. diff --git a/Testing/Smalltalk/test.st b/Testing/Smalltalk/test.st new file mode 100644 index 0000000..4017a7e --- /dev/null +++ b/Testing/Smalltalk/test.st @@ -0,0 +1,38 @@ +[| :array + +main + + array := #(A B C D E F G H). + + self testBlock. + self testExceptions. + ^self + +! + +testBlock + | count | + + Transcript showLine:'> Block test'. + + count := 0. + array do: [ :element | count := count + 1. ]. + + Transcript showLine:' Count ', (count stringValue). + ^self + + +! + +testExceptions + + Transcript showLine:'> Exception handler test'. + + [ NSException raise:'Some exception' format:' '. ] + handler: + [ :localException | + Transcript showLine:(' Exception: ', localException name). + ]. + + ^self +] diff --git a/Tools/GNUmakefile b/Tools/GNUmakefile new file mode 100644 index 0000000..dcbc91c --- /dev/null +++ b/Tools/GNUmakefile @@ -0,0 +1,53 @@ +# +# StepTalk tools +# +# Copyright (C) 2000,2001 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., 675 Mass Ave, Cambridge, MA 02111, USA. +# + +GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles + +include $(GNUSTEP_MAKEFILES)/common.make + +TOOL_NAME = \ + stexec \ + stalk \ + stupdate_languages + +COMMON_OBJC_FILES = \ + STExecutor.m + +stexec_OBJC_FILES = \ + $(COMMON_OBJC_FILES) \ + $(DEBUG_FILES) \ + stexec.m + +stalk_OBJC_FILES = \ + $(COMMON_OBJC_FILES) \ + stalk.m + +stupdate_languages_OBJC_FILES = \ + stupdate_languages.m + +ADDITIONAL_INCLUDE_DIRS += -I../Source/Headers +ADDITIONAL_TOOL_LIBS += -lStepTalk +ADDITIONAL_LIB_DIRS += -L../Source/$(GNUSTEP_OBJ_DIR) + +-include GNUmakefile.preamble +include $(GNUSTEP_MAKEFILES)/tool.make +-include GNUMakefile.postamble diff --git a/Tools/GNUmakefile.preamble b/Tools/GNUmakefile.preamble new file mode 100644 index 0000000..acb4593 --- /dev/null +++ b/Tools/GNUmakefile.preamble @@ -0,0 +1,63 @@ +# +# GNUmakefile.preamble +# +# 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 variables, and additional +# +# Do not put any Makefile rules in this file, instead they should +# be put into Makefile.postamble. +# + +# +# Flags dealing with compiling and linking +# + +# Additional flags to pass to the preprocessor +ADDITIONAL_CPPFLAGS += + +# Additional flags to pass to the Objective-C compiler +ADDITIONAL_OBJCFLAGS += + +# Additional flags to pass to the C compiler +ADDITIONAL_CFLAGS += +#ADDITIONAL_CFLAGS += + +# Additional include directories the compiler should search +ADDITIONAL_INCLUDE_DIRS += + +# Additional LDFLAGS to pass to the linker +ADDITIONAL_LDFLAGS += + +# Additional library directories the linker should search +ADDITIONAL_LIB_DIRS += + +ADDITIONAL_TOOL_LIBS += + +# +# Flags dealing with installing and uninstalling +# + +# Additional directories to be created during installation +ADDITIONAL_INSTALL_DIRS += + +# +# Local configuration +# diff --git a/Tools/STExecutor.h b/Tools/STExecutor.h new file mode 100644 index 0000000..bfe8d29 --- /dev/null +++ b/Tools/STExecutor.h @@ -0,0 +1,68 @@ +/** + STExecutor.h + Common class for stalk and stexec tools + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2001 + + 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 + +extern NSString *STExecutorException; +extern const char *STExecutorCommonOptions; + +extern void STPrintCassStats(void); + +enum +{ + STListNone, + STListObjects, + STListClasses, + STListAll +}; + + +@class STEnvironment; +@class NSString; +@class NSArray; + +@interface STExecutor:NSObject +{ + STEnvironment *env; + + NSString *langName; + + NSArray *arguments; + unsigned int currentArg; + + BOOL contFlag; + int listObjects; +} +- (void)printHelp; +- (int)processOption:(NSString *)option; +- (void)executeScript:(NSString *)fileName withArguments:(NSArray *)args; +- (int)parseOptions; +- (void)executeScripts; +- (NSString *)nextArgument; +- (void)reuseArgument; +- (void)runWithArguments:(NSArray *)argsArray; +@end diff --git a/Tools/STExecutor.m b/Tools/STExecutor.m new file mode 100644 index 0000000..1f68ee4 --- /dev/null +++ b/Tools/STExecutor.m @@ -0,0 +1,375 @@ +/** + STExecutor.m + Common class for stalk and stexec tools + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2001 + + 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 "STExecutor.h" + +#import + +#import +#import +#import +#import +#import + + +NSString *STExecutorException = @"STExecutorException"; + +const char *STExecutorCommonOptions = +" -help print this message\n" +" -list-all-objects list all available objects\n" +" -list-classes list available classes\n" +" -list-objects list named instances\n\n" +" -language lang force use of language lang\n" +" -list-languages list available languages\n" +" -continue do not stop when one of scripts failed to execute\n\n"; +//" -set obj=value define named object 'obj' with string value 'value'\n" + +@implementation STExecutor +- (void)createEnvironment +{ + [self subclassResponsibility:_cmd]; +} + +- (void) dealloc +{ + RELEASE(env); + [super dealloc]; +} + +- (void)executeScripts +{ + NSString *logFmt = @"'%@': execution failed, reason: %@"; + NSMutableArray *scriptArgs; + NSString *script; + NSString *arg; + + script = [self nextArgument]; + + if(!script) + { + NSLog(@"No script name specified"); + return; + } + + scriptArgs = [NSMutableArray array]; + + do + { + [scriptArgs removeAllObjects]; + arg = [self nextArgument]; + while(![arg isEqualToString:@","] && arg != nil) + { + [scriptArgs addObject:arg]; + arg = [self nextArgument]; + } + +#ifndef DEBUG + NS_DURING +#endif + + [self executeScript:script withArguments:scriptArgs]; + +#ifndef DEBUG + NS_HANDLER + if(contFlag) + { + NSLog(logFmt,script,[localException reason]); + } + else + { + [localException raise]; + } + NS_ENDHANDLER +#endif + + } while( (script = [self nextArgument]) ); +} + +- (void)executeScript:(NSString *)file withArguments:(NSArray *)args; +{ + NSFileManager *manager = [NSFileManager defaultManager]; + STEngine *engine; + + if( [manager fileExistsAtPath:file isDirectory:NO] ) + { + NSString *source = [NSString stringWithContentsOfFile:file]; + + if(langName) + { + NSDebugLog(@"Using language %@", langName); + + engine = [STEngine engineForLanguage:langName]; + } + else + { + NSDebugLog(@"Using language fo file extension %@", + [file pathExtension]); + + engine = [STEngine engineForFileType:[file pathExtension]]; + } + + if(!engine) + { + NSDebugLog(@"Using default language %@", + [STLanguage defaultLanguageName]); + + engine = [STEngine engineForLanguage:[STLanguage defaultLanguageName]]; + } + + if(engine) + { + NSDebugLog(@"Executing file '%@'",file); + + [engine setDefaultEnvironment:env]; + + [env setObject:args forName:@"Args"]; + [env setObject:env forName:@"Environment"]; + + [engine executeCode:source]; + } + else + { + [NSException raise:STExecutorException + format:@"Unable to create engine"]; + + } + } + else + { + [NSException raise:STExecutorException + format:@"Could not find script '%@'", file]; + } +} + +- (void)listLanguages +{ + NSArray *languages; + NSEnumerator *enumerator; + NSString *name; + + languages = [STLanguage allLanguageNames]; + + enumerator = [languages objectEnumerator]; + + while( (name = [enumerator nextObject]) ) + { + printf("%s\n", [name cString]); + } +} + +- (NSString *)nextArgument +{ + if(currentArg < [arguments count]) + { + return [arguments objectAtIndex:currentArg++]; + } + + return nil; +} + +- (void)reuseArgument +{ + currentArg--; +} + +- (void)listObjects +{ + NSArray *objects; + NSEnumerator *enumerator; + NSString *name; + NSDictionary *pool; + + pool = [env defaultObjectPool]; + + objects = [pool allKeys]; + objects = [objects sortedArrayUsingSelector:@selector(compare:)]; + + enumerator = [objects objectEnumerator]; + + if(listObjects == STListAll) + { + while( (name = [enumerator nextObject]) ) + { + printf("%s\n", [name cString]); + } + } + else if (listObjects == STListClasses) + { + while( (name = [enumerator nextObject]) ) + { + if([[pool objectForKey:name] isClass]) + { + printf("%s\n", [name cString]); + } + } + } + else /* (listObjects == STListInstances) */ + { + while( (name = [enumerator nextObject]) ) + { + if(! [[pool objectForKey:name] isClass]) + { + printf("%s\n", [name cString]); + } + } + } + +} + +- (int)parseOptions +{ + BOOL isOption = NO; + NSString *arg; + + listObjects = STListNone; + + while( (arg = [self nextArgument]) ) + { + isOption = NO; + if( [arg hasPrefix:@"--"] ) + { + arg = [arg substringFromIndex:2]; + isOption = YES; + } + else if( [arg hasPrefix:@"-"] ) + { + arg = [arg substringFromIndex:1]; + isOption = YES; + } + + if ([@"help" hasPrefix:arg]) + { + [self printHelp]; + return 1; + } + else if ([@"list-languages" hasPrefix:arg]) + { + [self listLanguages]; + return 1; + } +/* + else if ([@"list-engines" hasPrefix:arg]) + { + [self listEngines]; + return 1; + } + */ + + else if ([@"list-objects" hasPrefix:arg]) + { + listObjects = STListObjects; + } + else if ([@"list-classes" hasPrefix:arg]) + { + listObjects = STListClasses; + } + else if ([@"list-all-objects" hasPrefix:arg]) + { + listObjects = STListAll; + } + else if ([@"continue" hasPrefix:arg]) + { + contFlag = YES; + } + else if ([@"language" hasPrefix:arg]) + { + RELEASE(langName); + + langName = [self nextArgument]; + if(!langName) + { + [NSException raise:STExecutorException + format:@"Language name expected"]; + } + } + else + { + if(!isOption) + { + break; + } + else + { + if( [self processOption:arg] ) + { + return 1; + } + } + } + } + + if(arg) + { + [self reuseArgument]; + } + + return 0; +} + +- (void)beforeExecuting +{ +} + +- (void)afterExecuting +{ +} + +- (void)runWithArguments:(NSArray *)args +{ + arguments = RETAIN(args); + currentArg = 1; + + if([self parseOptions]) + { + return; + } + + [self beforeExecuting]; + + [self createEnvironment]; + [self executeScripts]; + + [self afterExecuting]; + + if(listObjects != STListNone) + { + [self listObjects]; + } +} + +- (void)printHelp +{ + [self subclassResponsibility:_cmd]; +} + +- (int)processOption:(NSString *)option +{ + [self subclassResponsibility:_cmd]; + + return 0; +} +@end diff --git a/Tools/stalk.m b/Tools/stalk.m new file mode 100644 index 0000000..8249150 --- /dev/null +++ b/Tools/stalk.m @@ -0,0 +1,175 @@ +/** + stalk.m + Program for 'talking' to scriptable objects + + 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 "STExecutor.h" + +#import + +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import + +@interface Executor:STExecutor +{ + NSString *hostName; + NSString *objectName; + + id target; +} +- (void)setTargetWithName:(NSString *)name; +@end + +@implementation Executor +- (void)dealloc +{ + RELEASE(objectName); + RELEASE(hostName); + [super dealloc]; +} +- (void)setTargetWithName:(NSString *)targetName +{ + NSDebugLog(@"connecting object '%@' on host '%@'",targetName,hostName); + + if(!targetName) + { + [NSException raise:STExecutorException + format:@"No target specified"]; + } + + target = [NSConnection rootProxyForConnectionWithRegisteredName:targetName + host:hostName]; +/* + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector(connectionDidDie:) + name:NSConnectionDidDieNotification + object:object]; +*/ + + if(!target) + { + [NSException raise:STExecutorException + format:@"Unable to connect to target named '%@' " + @"on host '%@'", + targetName, hostName]; + return; + } + + ASSIGN(objectName,targetName); +} + +- (void)createEnvironment +{ + if([target respondsToSelector:@selector(scriptingEnvironment)]) + { + env = [target scriptingEnvironment]; + } + else + { + [NSException raise:STExecutorException + format:@"Target '%@' on host '%@' " + @"does not provide scripting environment.", + objectName, hostName]; + } + + RETAIN(env); + + [env setObject:target forName:objectName]; +} + +- (int)processOption:(NSString *)option +{ + if ([@"host" hasPrefix:option]) + { + ASSIGN(hostName,[self nextArgument]); + + if(!hostName) + { + [NSException raise:STExecutorException + format:@"Hostname expected"]; + } + } + else + { + [NSException raise:STExecutorException + format:@"Unknown option -%@", option]; + } + + return NO; +} + +-(void) beforeExecuting +{ + [self setTargetWithName:[self nextArgument]]; +} + +- (void)printHelp +{ + printf( +"stalk - 'talk' to objects with StepTalk script\n" +"Usage: stalk [options] target script [args ...] [ , script ...]\n" +" Options:\n" +"%s" +" -host hostName look for target on specified host\n", +STExecutorCommonOptions + ); +} +@end + +int main(int argc, const char **argv) +{ + Executor *executor; + NSArray *args; + NSAutoreleasePool *pool; + NSProcessInfo *procInfo; + + pool = [NSAutoreleasePool new]; + + procInfo = [NSProcessInfo processInfo]; + if (procInfo == nil) + { + NSLog(@"Unable to get process information"); + [pool release]; + exit(1); + } + + executor = [[Executor alloc] init]; + + args = [procInfo arguments]; + [executor runWithArguments:args]; + + [pool release]; + + return 0; +} diff --git a/Tools/stexec.m b/Tools/stexec.m new file mode 100644 index 0000000..3b86462 --- /dev/null +++ b/Tools/stexec.m @@ -0,0 +1,141 @@ +/** + stexec.m + Script executor + + 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 "STExecutor.h" + +#import + +#import +#import +#import +#import +#import +#import +#import + +#include + +@interface Executor:STExecutor +{ + NSString *envName; + BOOL enableFull; +} +@end + +@implementation Executor +- (void)createEnvironment +{ + if(!envName || [envName isEqualToString:@""]) + { + env = [STEnvironment defaultScriptingEnvironment]; + } + else + { + env = [STEnvironment environmentWithDescriptionName:envName]; + } + + [env loadModule:@"Foundation"]; + [env loadModule:@"SimpleTranscript"]; + + [env setCreatesUnknownObjects:YES]; + + RETAIN(env); +} + +- (int)processOption:(NSString *)option +{ + if ([@"environment" hasPrefix:option]) + { + RELEASE(envName); + + envName = [self nextArgument]; + if(!envName) + { + [NSException raise:STExecutorException + format:@"Environment name expected"]; + } + } + else if ([@"full" hasPrefix:option]) + { + enableFull = YES; + } + else + { + [NSException raise:STExecutorException + format:@"Unknown option -%@", option]; + } + return 0; +} + +- (void)beforeExecuting +{ + [env setFullScriptingEnabled:enableFull]; +} + +- (void) printHelp +{ + printf( +"stexec - execute StepTalk script (in GNUstep-base environment)\n" +"Usage: stexec [options] script [args ...] [ , script ...]\n" +" Options:\n" +"%s" +" -full enable full scripting\n" +" -environment env use scripting environment with name env\n", +STExecutorCommonOptions + ); +} +@end + +int main(int argc, const char **argv) +{ + Executor *executor; + NSArray *args; + NSAutoreleasePool *pool; + NSProcessInfo *procInfo; + + pool = [NSAutoreleasePool new]; + +// [NSAutoreleasePool enableDoubleReleaseCheck:YES]; + + procInfo = [NSProcessInfo processInfo]; + + if (procInfo == nil) + { + NSLog(@"Unable to get process information"); + RELEASE(pool); + exit(1); + } + + executor = [[Executor alloc] init]; + + args = [procInfo arguments]; + [executor runWithArguments:args]; + + RELEASE(executor); + RELEASE(pool); + + return 0; +} diff --git a/Tools/stupdate_languages.m b/Tools/stupdate_languages.m new file mode 100644 index 0000000..3ca5e75 --- /dev/null +++ b/Tools/stupdate_languages.m @@ -0,0 +1,119 @@ +/** + stupdate_languages.m + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + Date: 2002 + + 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 "STExecutor.h" + +#import + +#import +#import +#import +#import +#import +#import +#import +#import +#import + +#include + +NSFileManager *fm; + +BOOL create_directory(NSString *path) +{ + NSString *par = [path stringByDeletingLastPathComponent]; + + if( [fm fileExistsAtPath:path] ) + { + return YES; + } + else if( ![fm fileExistsAtPath:par] ) + { + if(!create_directory(par)) + { + return NO; + } + } + + return [fm createDirectoryAtPath:path attributes:nil]; +} + +void update_languages(void) +{ + NSArray *langNames = [STLanguage allLanguageNames]; + NSString *path = STUserConfigPath(); + STLanguage *lang; + NSString *langName; + NSEnumerator *enumerator; + NSArray *types; + NSEnumerator *typeenum; + NSString *type; + NSDictionary *typeDict = [NSMutableDictionary dictionary]; + NSDictionary *dict; + enumerator = [langNames objectEnumerator]; + + NSLog(@"Updating languages..."); + + while( (langName = [enumerator nextObject]) ) + { + lang = [STLanguage languageWithName:langName]; + types = [[lang infoDictionary] objectForKey:@"STFileTypes"]; + + typeenum = [types objectEnumerator]; + while( (type = [typeenum nextObject]) ) + { + [typeDict setObject:langName forKey:type]; + } + } + + dict = [NSDictionary dictionaryWithObject:typeDict + forKey:@"STFileTypes"]; + + if(!create_directory(path)) + { + NSLog(@"Unable to create directory '%@'", path); + return; + } + + path = [path stringByAppendingPathComponent:STLanguagesConfigFile]; + + [dict writeToFile:path atomically:YES]; +} + + +int main(int argc, const char **argv) +{ + NSAutoreleasePool *pool; + + pool = [NSAutoreleasePool new]; + + fm = [NSFileManager defaultManager]; + + update_languages(); + + RELEASE(pool); + + return 0; +} diff --git a/Version b/Version new file mode 100644 index 0000000..8538457 --- /dev/null +++ b/Version @@ -0,0 +1,11 @@ +# This file is included in various Makefile's to get version information. +# Compatible with Bourne shell syntax, so it can included there too. + +# The version number of this release. +MAJOR_VERSION=0 +MINOR_VERSION=5 +SUBMINOR_VERSION=3 + +STEPTALK_VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${SUBMINOR_VERSION} + +VERSION=${STEPTALK_VERSION}