├── LICENSE.GPL2 ├── LICENSE.GPL3 ├── LjSOM.cpp ├── LjSOM.h ├── LjSOM.pro ├── LjTraceDump.lua ├── Readme.md ├── Results ├── Are-we-fast-yet_Results.ods ├── Benchmarks_All_CSOM.txt ├── Benchmarks_All_Results.ods ├── Benchmarks_All_SOM++.txt ├── Benchmarks_All_SOMpp.txt ├── Benchmarks_All_SomLjVirtualMachine_0.2_lua.txt ├── Benchmarks_All_SomLjVirtualMachine_0.2_pcall_every_method.txt ├── Benchmarks_All_SomLjVirtualMachine_0.5_bc.txt ├── Benchmarks_All_SomLjVirtualMachine_0.7.1_bc.txt ├── Benchmarks_All_SomLjVirtualMachine_0.7_bc.txt ├── Benchmarks_All_SomLjVirtualMachine_0.8.0_bc.txt ├── Benchmarks_All_SomLjVirtualMachine_generated_Lua │ ├── All.lua │ ├── Array.lua │ ├── Ball.lua │ ├── Benchmark.lua │ ├── BenchmarkHarness.lua │ ├── Block.lua │ ├── Boolean.lua │ ├── Bounce.lua │ ├── BubbleSort.lua │ ├── Class.lua │ ├── Dispatch.lua │ ├── Double.lua │ ├── False.lua │ ├── Fibonacci.lua │ ├── FieldLoop.lua │ ├── Integer.lua │ ├── IntegerLoop.lua │ ├── List.lua │ ├── ListElement.lua │ ├── Loop.lua │ ├── Metaclass.lua │ ├── Nil.lua │ ├── Object.lua │ ├── Permute.lua │ ├── Queens.lua │ ├── QuickSort.lua │ ├── Random.lua │ ├── Recurse.lua │ ├── Set.lua │ ├── Sieve.lua │ ├── Sort.lua │ ├── Storage.lua │ ├── String.lua │ ├── Sum.lua │ ├── Symbol.lua │ ├── System.lua │ ├── Towers.lua │ ├── TowersDisk.lua │ ├── TreeNode.lua │ ├── TreeSort.lua │ ├── True.lua │ └── Vector.lua ├── SOMpp.pro ├── are-we-fast-yet_crystal_lua_node_som_pharo_i386_results_2020-12-29.pdf └── run_are-we-fast-yet.sh ├── Smalltalk ├── Array.som ├── Block.som ├── Block1.som ├── Block2.som ├── Block3.som ├── Boolean.som ├── Class.som ├── Dictionary.som ├── Double.som ├── False.som ├── HashEntry.som ├── Hashtable.som ├── Integer.som ├── Metaclass.som ├── Method.som ├── Nil.som ├── Object.som ├── Pair.som ├── Primitive.som ├── Set.som ├── Source.txt ├── String.som ├── Symbol.som ├── System.som ├── True.som └── Vector.som ├── SomAst.cpp ├── SomAst.h ├── SomAstModel.cpp ├── SomAstModel.h ├── SomClassBrowser.cpp ├── SomClassBrowser.h ├── SomClassBrowser.pro ├── SomClassBrowser.qrc ├── SomHighlighter.cpp ├── SomHighlighter.h ├── SomLexer.cpp ├── SomLexer.h ├── SomLjLibFfi.cpp ├── SomLjObjectManager.cpp ├── SomLjObjectManager.h ├── SomLjVirtualMachine.cpp ├── SomLjVirtualMachine.h ├── SomLjVirtualMachine.pro ├── SomLjVirtualMachine.qrc ├── SomLjbcCompiler.cpp ├── SomLjbcCompiler.h ├── SomLjbcCompiler2.cpp ├── SomLjbcCompiler2.h ├── SomLuaTranspiler.cpp ├── SomLuaTranspiler.h ├── SomParser.cpp ├── SomParser.h ├── SomPrimitives.lua └── images ├── break-marker.png ├── breakpoint.png ├── close.png ├── exclamation-circle.png ├── exclamation-red.png └── marker.png /LjSOM.h: -------------------------------------------------------------------------------- 1 | #ifndef SOMLjSOM_H 2 | #define SOMLjSOM_H 3 | 4 | /* 5 | * Copyright 2020 Rochus Keller 6 | * 7 | * This file is part of the SOM Smalltalk parser/compiler library. 8 | * 9 | * The following is the license that applies to this copy of the 10 | * library. For a license to use the library under conditions 11 | * other than those described here, please email to me@rochus-keller.ch. 12 | * 13 | * GNU General Public License Usage 14 | * This file may be used under the terms of the GNU General Public 15 | * License (GPL) versions 2.0 or 3.0 as published by the Free Software 16 | * Foundation and appearing in the file LICENSE.GPL included in 17 | * the packaging of this file. Please review the following information 18 | * to ensure GNU General Public Licensing requirements will be met: 19 | * http://www.fsf.org/licensing/licenses/info/GPLv2.html and 20 | * http://www.gnu.org/copyleft/gpl.html. 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | namespace Lua 27 | { 28 | class Engine2; 29 | } 30 | 31 | namespace Som 32 | { 33 | class LjObjectManager; 34 | 35 | class LjSOM : public QObject 36 | { 37 | Q_OBJECT 38 | public: 39 | explicit LjSOM(QObject *parent = 0); 40 | bool load(const QString& file, const QString& paths = QString() ); 41 | bool run(bool useJit = true, bool trace = false, const QStringList& extraArgs = QStringList()); 42 | Lua::Engine2* getLua() const { return d_lua; } 43 | QStringList getLuaFiles() const; 44 | QByteArrayList getClassNames() const; 45 | void setGenLua( bool ); 46 | void setGenClosures( bool ); 47 | LjObjectManager* getOm() const { return d_om;} 48 | protected slots: 49 | void onNotify( int messageType, QByteArray val1, int val2 ); 50 | private: 51 | Lua::Engine2* d_lua; 52 | LjObjectManager* d_om; 53 | }; 54 | } 55 | 56 | #endif // SOMLjSOM_H 57 | -------------------------------------------------------------------------------- /LjSOM.pro: -------------------------------------------------------------------------------- 1 | #/* 2 | #* Copyright 2020 Rochus Keller 3 | #* 4 | #* This file is part of the SOM Smalltalk VM application. 5 | #* 6 | #* The following is the license that applies to this copy of the 7 | #* application. For a license to use the application under conditions 8 | #* other than those described here, please email to me@rochus-keller.ch. 9 | #* 10 | #* GNU General Public License Usage 11 | #* This file may be used under the terms of the GNU General Public 12 | #* License (GPL) versions 2.0 or 3.0 as published by the Free Software 13 | #* Foundation and appearing in the file LICENSE.GPL included in 14 | #* the packaging of this file. Please review the following information 15 | #* to ensure GNU General Public Licensing requirements will be met: 16 | #* http://www.fsf.org/licensing/licenses/info/GPLv2.html and 17 | #* http://www.gnu.org/copyleft/gpl.html. 18 | #*/ 19 | 20 | QT += core 21 | QT -= gui 22 | 23 | TARGET = LjSOM 24 | CONFIG += console 25 | CONFIG -= app_bundle 26 | TEMPLATE = app 27 | 28 | INCLUDEPATH += .. ../LuaJIT/src 29 | 30 | SOURCES += \ 31 | SomLjObjectManager.cpp \ 32 | SomAst.cpp \ 33 | SomLexer.cpp \ 34 | SomParser.cpp \ 35 | SomLuaTranspiler.cpp \ 36 | SomLjLibFfi.cpp \ 37 | SomLjbcCompiler.cpp \ 38 | ../LjTools/LuaJitBytecode.cpp \ 39 | ../LjTools/Engine2.cpp \ 40 | ../LjTools/LuaJitComposer.cpp \ 41 | LjSOM.cpp \ 42 | SomLjbcCompiler2.cpp 43 | 44 | 45 | HEADERS += \ 46 | SomLjObjectManager.h \ 47 | SomAst.h \ 48 | SomLexer.h \ 49 | SomParser.h \ 50 | SomLuaTranspiler.h \ 51 | SomLjbcCompiler.h \ 52 | ../LjTools/LuaJitBytecode.h \ 53 | ../LjTools/Engine2.h \ 54 | ../LjTools/LuaJitComposer.h \ 55 | LjSOM.h \ 56 | SomLjbcCompiler2.h 57 | 58 | 59 | win32 { 60 | LIBS += -L../LuaJIT/src -llua51 61 | } 62 | linux { 63 | include( ../LuaJIT/src/LuaJit.pri ){ 64 | LIBS += -ldl 65 | } else { 66 | LIBS += -lluajit 67 | } 68 | QMAKE_LFLAGS += -rdynamic -ldl 69 | #rdynamic is required so that the LjLibFfi functions are visible to LuaJIT FFI 70 | } 71 | macx { 72 | include( ../LuaJIT/src/LuaJit.pri ) 73 | QMAKE_LFLAGS += -rdynamic -ldl -pagezero_size 10000 -image_base 100000000 74 | } 75 | 76 | CONFIG(debug, debug|release) { 77 | DEFINES += _DEBUG 78 | } 79 | 80 | !win32 { 81 | QMAKE_CXXFLAGS += -Wno-reorder -Wno-unused-parameter -Wno-unused-function -Wno-unused-variable 82 | QMAKE_CXXFLAGS += -fno-stack-protector # see https://stackoverflow.com/questions/1345670/stack-smashing-detected 83 | } 84 | 85 | RESOURCES += \ 86 | SomLjVirtualMachine.qrc 87 | -------------------------------------------------------------------------------- /LjTraceDump.lua: -------------------------------------------------------------------------------- 1 | ../LjTools/LjTraceDump.lua -------------------------------------------------------------------------------- /Results/Are-we-fast-yet_Results.ods: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rochus-keller/Som/b7e8f8ccb89bce8daf61a18ea420976c9bfe92c0/Results/Are-we-fast-yet_Results.ods -------------------------------------------------------------------------------- /Results/Benchmarks_All_CSOM.txt: -------------------------------------------------------------------------------- 1 | git clone https://github.com/SOM-st/CSOM.git 2 | CSOM commit d7ce9e9 June 28 from https://github.com/SOM-st/CSOM 3 | unmodified build with default options 4 | 5 | ./CSOM -cp Smalltalk:Examples/Benchmarks/LanguageFeatures Examples/Benchmarks/All.som 6 | This is CSOM. 7 | Start execution of all benchmarks. Iterations: 100 8 | Starting Fibonacci benchmark ... warmup ... completed. 9 | 10 | Benchmark: Fibonacci 11 | Iterations: 9 (elapsed time 3272 ms) 12 | AVERAGE: 364 ms 13 | 14 | Starting Dispatch benchmark ... warmup ... completed. 15 | 16 | Benchmark: Dispatch 17 | Iterations: 12 (elapsed time 3193 ms) 18 | AVERAGE: 266 ms 19 | 20 | Starting Bounce benchmark ... warmup ... completed. 21 | 22 | Benchmark: Bounce 23 | Iterations: 8 (elapsed time 3251 ms) 24 | AVERAGE: 406 ms 25 | 26 | Starting Loop benchmark ... warmup ... completed. 27 | 28 | Benchmark: Loop 29 | Iterations: 12 (elapsed time 3186 ms) 30 | AVERAGE: 266 ms 31 | 32 | Starting Permute benchmark ... warmup ... completed. 33 | 34 | Benchmark: Permute 35 | Iterations: 11 (elapsed time 3033 ms) 36 | AVERAGE: 276 ms 37 | 38 | Starting Queens benchmark ... warmup ... completed. 39 | 40 | Benchmark: Queens 41 | Iterations: 11 (elapsed time 3149 ms) 42 | AVERAGE: 286 ms 43 | 44 | Starting List benchmark ... warmup ... completed. 45 | 46 | Benchmark: List 47 | Iterations: 8 (elapsed time 3078 ms) 48 | AVERAGE: 385 ms 49 | 50 | Starting Recurse benchmark ... warmup ... completed. 51 | 52 | Benchmark: Recurse 53 | Iterations: 11 (elapsed time 3022 ms) 54 | AVERAGE: 275 ms 55 | 56 | Starting Storage benchmark ... warmup ... completed. 57 | 58 | Benchmark: Storage 59 | Iterations: 3 (elapsed time 4546 ms) 60 | AVERAGE: 1515 ms 61 | 62 | Starting Sieve benchmark ... warmup ... completed. 63 | 64 | Benchmark: Sieve 65 | Iterations: 11 (elapsed time 3298 ms) 66 | AVERAGE: 300 ms 67 | 68 | Starting BubbleSort benchmark ... warmup ... completed. 69 | 70 | Benchmark: BubbleSort 71 | Iterations: 10 (elapsed time 3019 ms) 72 | AVERAGE: 302 ms 73 | 74 | Starting QuickSort benchmark ... warmup ... completed. 75 | 76 | Benchmark: QuickSort 77 | Iterations: 6 (elapsed time 3565 ms) 78 | AVERAGE: 594 ms 79 | 80 | Starting Sum benchmark ... warmup ... completed. 81 | 82 | Benchmark: Sum 83 | Iterations: 12 (elapsed time 3019 ms) 84 | AVERAGE: 252 ms 85 | 86 | Starting Towers benchmark ... warmup ... completed. 87 | 88 | Benchmark: Towers 89 | Iterations: 8 (elapsed time 3149 ms) 90 | AVERAGE: 394 ms 91 | 92 | Starting TreeSort benchmark ... warmup ... completed. 93 | 94 | Benchmark: TreeSort 95 | Iterations: 3 (elapsed time 3408 ms) 96 | AVERAGE: 1136 ms 97 | 98 | Starting IntegerLoop benchmark ... warmup ... completed. 99 | 100 | Benchmark: IntegerLoop 101 | Iterations: 6 (elapsed time 3079 ms) 102 | AVERAGE: 513 ms 103 | 104 | Starting FieldLoop benchmark ... warmup ... completed. 105 | 106 | Benchmark: FieldLoop 107 | Iterations: 3 (elapsed time 3223 ms) 108 | AVERAGE: 1074 ms 109 | 110 | Summed Average Runtime: 1074 ms 111 | Total average: 506 112 | Total geomean: 423 113 | Total median: 364 114 | Total sum: 8604 115 | 116 | 117 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_Results.ods: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rochus-keller/Som/b7e8f8ccb89bce8daf61a18ea420976c9bfe92c0/Results/Benchmarks_All_Results.ods -------------------------------------------------------------------------------- /Results/Benchmarks_All_SOM++.txt: -------------------------------------------------------------------------------- 1 | git clone https://github.com/SOM-st/SOMpp.git 2 | CMakeList.txt and flags.make modified (unittest und LIB_CPPUNIT removed, 3 | -m64 replaced -m32 and -std=gnu++1y by -std=gnu++11) 4 | Default options otherwise 5 | 6 | ./SOM++ -cp Smalltalk:Examples/Benchmarks/LanguageFeatures Examples/Benchmarks/All.som 7 | This is SOM++ 8 | garbage collector: copying 9 | not tagging integers 10 | not caching integers 11 | -------------------------------------- 12 | Start execution of all benchmarks. Iterations: 100 13 | Starting Fibonacci benchmark ... warmup ... completed. 14 | 15 | Benchmark: Fibonacci 16 | Iterations: 20 (elapsed time 3078 ms) 17 | AVERAGE: 154 ms 18 | 19 | Starting Dispatch benchmark ... warmup ... completed. 20 | 21 | Benchmark: Dispatch 22 | Iterations: 16 (elapsed time 3021 ms) 23 | AVERAGE: 189 ms 24 | 25 | Starting Bounce benchmark ... warmup ... completed. 26 | 27 | Benchmark: Bounce 28 | Iterations: 22 (elapsed time 3142 ms) 29 | AVERAGE: 143 ms 30 | 31 | Starting Loop benchmark ... warmup ... completed. 32 | 33 | Benchmark: Loop 34 | Iterations: 20 (elapsed time 3096 ms) 35 | AVERAGE: 155 ms 36 | 37 | Starting Permute benchmark ... warmup ... completed. 38 | 39 | Benchmark: Permute 40 | Iterations: 19 (elapsed time 3172 ms) 41 | AVERAGE: 167 ms 42 | 43 | Starting Queens benchmark ... warmup ... completed. 44 | 45 | Benchmark: Queens 46 | Iterations: 17 (elapsed time 3175 ms) 47 | AVERAGE: 187 ms 48 | 49 | Starting List benchmark ... warmup ... completed. 50 | 51 | Benchmark: List 52 | Iterations: 15 (elapsed time 3201 ms) 53 | AVERAGE: 213 ms 54 | 55 | Starting Recurse benchmark ... warmup ... completed. 56 | 57 | Benchmark: Recurse 58 | Iterations: 15 (elapsed time 3033 ms) 59 | AVERAGE: 202 ms 60 | 61 | Starting Storage benchmark ... warmup ... completed. 62 | 63 | Benchmark: Storage 64 | Iterations: 24 (elapsed time 3096 ms) 65 | AVERAGE: 129 ms 66 | 67 | Starting Sieve benchmark ... warmup ... completed. 68 | 69 | Benchmark: Sieve 70 | Iterations: 16 (elapsed time 3041 ms) 71 | AVERAGE: 190 ms 72 | 73 | Starting BubbleSort benchmark ... warmup ... completed. 74 | 75 | Benchmark: BubbleSort 76 | Iterations: 20 (elapsed time 3122 ms) 77 | AVERAGE: 156 ms 78 | 79 | Starting QuickSort benchmark ... warmup ... completed. 80 | 81 | Benchmark: QuickSort 82 | Iterations: 27 (elapsed time 3096 ms) 83 | AVERAGE: 115 ms 84 | 85 | Starting Sum benchmark ... warmup ... completed. 86 | 87 | Benchmark: Sum 88 | Iterations: 20 (elapsed time 3033 ms) 89 | AVERAGE: 152 ms 90 | 91 | Starting Towers benchmark ... warmup ... completed. 92 | 93 | Benchmark: Towers 94 | Iterations: 15 (elapsed time 3167 ms) 95 | AVERAGE: 211 ms 96 | 97 | Starting TreeSort benchmark ... warmup ... completed. 98 | 99 | Benchmark: TreeSort 100 | Iterations: 30 (elapsed time 3045 ms) 101 | AVERAGE: 101 ms 102 | 103 | Starting IntegerLoop benchmark ... warmup ... completed. 104 | 105 | Benchmark: IntegerLoop 106 | Iterations: 10 (elapsed time 3033 ms) 107 | AVERAGE: 303 ms 108 | 109 | Starting FieldLoop benchmark ... warmup ... completed. 110 | 111 | Benchmark: FieldLoop 112 | Iterations: 5 (elapsed time 3292 ms) 113 | AVERAGE: 658 ms 114 | 115 | Summed Average Runtime: 658 ms 116 | Time spent in GC: [0.932000] msec 117 | 118 | Total average: 201 119 | Total geomean: 181 120 | Total median: 167 121 | Total sum: 3425 122 | 123 | 124 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SOMpp.txt: -------------------------------------------------------------------------------- 1 | SOM++ commit c46c3bf June 28 from https://github.com/SOM-st/SOMpp 2 | Downloaded as zip and unpacked 3 | Compiled using my own qmake SOMpp.pro file and M&S GC 4 | 5 | ./SOMpp -cp Smalltalk:Examples/Benchmarks/LanguageFeatures Examples/Benchmarks/All.som 6 | This is SOM++ 7 | garbage collector: mark-sweep 8 | not tagging integers 9 | not caching integers 10 | -------------------------------------- 11 | Start execution of all benchmarks. Iterations: 100 12 | Starting Fibonacci benchmark ... warmup ... completed. 13 | 14 | Benchmark: Fibonacci 15 | Iterations: 34 (elapsed time 3050 ms) 16 | AVERAGE: 90 ms 17 | 18 | Starting Dispatch benchmark ... warmup ... completed. 19 | 20 | Benchmark: Dispatch 21 | Iterations: 32 (elapsed time 3036 ms) 22 | AVERAGE: 95 ms 23 | 24 | Starting Bounce benchmark ... warmup ... completed. 25 | 26 | Benchmark: Bounce 27 | Iterations: 39 (elapsed time 3051 ms) 28 | AVERAGE: 78 ms 29 | 30 | Starting Loop benchmark ... warmup ... completed. 31 | 32 | Benchmark: Loop 33 | Iterations: 35 (elapsed time 3019 ms) 34 | AVERAGE: 86 ms 35 | 36 | Starting Permute benchmark ... warmup ... completed. 37 | 38 | Benchmark: Permute 39 | Iterations: 33 (elapsed time 3004 ms) 40 | AVERAGE: 91 ms 41 | 42 | Starting Queens benchmark ... warmup ... completed. 43 | 44 | Benchmark: Queens 45 | Iterations: 29 (elapsed time 3051 ms) 46 | AVERAGE: 105 ms 47 | 48 | Starting List benchmark ... warmup ... completed. 49 | 50 | Benchmark: List 51 | Iterations: 27 (elapsed time 3045 ms) 52 | AVERAGE: 113 ms 53 | 54 | Starting Recurse benchmark ... warmup ... completed. 55 | 56 | Benchmark: Recurse 57 | Iterations: 29 (elapsed time 3105 ms) 58 | AVERAGE: 107 ms 59 | 60 | Starting Storage benchmark ... warmup ... completed. 61 | 62 | Benchmark: Storage 63 | Iterations: 43 (elapsed time 3021 ms) 64 | AVERAGE: 70 ms 65 | 66 | Starting Sieve benchmark ... warmup ... completed. 67 | 68 | Benchmark: Sieve 69 | Iterations: 31 (elapsed time 3017 ms) 70 | AVERAGE: 97 ms 71 | 72 | Starting BubbleSort benchmark ... warmup ... completed. 73 | 74 | Benchmark: BubbleSort 75 | Iterations: 35 (elapsed time 3024 ms) 76 | AVERAGE: 86 ms 77 | 78 | Starting QuickSort benchmark ... warmup ... completed. 79 | 80 | Benchmark: QuickSort 81 | Iterations: 49 (elapsed time 3021 ms) 82 | AVERAGE: 62 ms 83 | 84 | Starting Sum benchmark ... warmup ... completed. 85 | 86 | Benchmark: Sum 87 | Iterations: 37 (elapsed time 3072 ms) 88 | AVERAGE: 83 ms 89 | 90 | Starting Towers benchmark ... warmup ... completed. 91 | 92 | Benchmark: Towers 93 | Iterations: 26 (elapsed time 3029 ms) 94 | AVERAGE: 117 ms 95 | 96 | Starting TreeSort benchmark ... warmup ... completed. 97 | 98 | Benchmark: TreeSort 99 | Iterations: 57 (elapsed time 3001 ms) 100 | AVERAGE: 53 ms 101 | 102 | Starting IntegerLoop benchmark ... warmup ... completed. 103 | 104 | Benchmark: IntegerLoop 105 | Iterations: 18 (elapsed time 3026 ms) 106 | AVERAGE: 168 ms 107 | 108 | Starting FieldLoop benchmark ... warmup ... completed. 109 | 110 | Benchmark: FieldLoop 111 | Iterations: 9 (elapsed time 3357 ms) 112 | AVERAGE: 373 ms 113 | 114 | Summed Average Runtime: 373 ms 115 | Time spent in GC: [0.352000] msec 116 | 117 | Total runtime by stop watch 74 secs 118 | Total average: 110 119 | Total geomean: 99 120 | Total median: 91 121 | Total sum: 1874 122 | 123 | 124 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_0.2_lua.txt: -------------------------------------------------------------------------------- 1 | SomLjVirtualMachine Lua source code version 2 | 3 | Start execution of all benchmarks. Iterations: 100 4 | Starting Fibonacci benchmark ... warmup ... completed. 5 | 6 | Benchmark: Fibonacci 7 | Iterations: 26 (elapsed time 3099 ms) 8 | AVERAGE: 119 ms 9 | 10 | Starting Dispatch benchmark ... warmup ... completed. 11 | 12 | Benchmark: Dispatch 13 | Iterations: 100 (elapsed time 2442 ms) 14 | AVERAGE: 24 ms 15 | 16 | Starting Bounce benchmark ... warmup ... completed. 17 | 18 | Benchmark: Bounce 19 | Iterations: 63 (elapsed time 3014 ms) 20 | AVERAGE: 48 ms 21 | 22 | Starting Loop benchmark ... warmup ... completed. 23 | 24 | Benchmark: Loop 25 | Iterations: 100 (elapsed time 2591 ms) 26 | AVERAGE: 26 ms 27 | 28 | Starting Permute benchmark ... warmup ... completed. 29 | 30 | Benchmark: Permute 31 | Iterations: 100 (elapsed time 2905 ms) 32 | AVERAGE: 29 ms 33 | 34 | Starting Queens benchmark ... warmup ... completed. 35 | 36 | Benchmark: Queens 37 | Iterations: 78 (elapsed time 3028 ms) 38 | AVERAGE: 39 ms 39 | 40 | Starting List benchmark ... warmup ... completed. 41 | 42 | Benchmark: List 43 | Iterations: 67 (elapsed time 3039 ms) 44 | AVERAGE: 45 ms 45 | 46 | Starting Recurse benchmark ... warmup ... completed. 47 | 48 | Benchmark: Recurse 49 | Iterations: 88 (elapsed time 3034 ms) 50 | AVERAGE: 34 ms 51 | 52 | Starting Storage benchmark ... warmup ... completed. 53 | 54 | Benchmark: Storage 55 | Iterations: 74 (elapsed time 3001 ms) 56 | AVERAGE: 41 ms 57 | 58 | Starting Sieve benchmark ... warmup ... completed. 59 | 60 | Benchmark: Sieve 61 | Iterations: 90 (elapsed time 3013 ms) 62 | AVERAGE: 33 ms 63 | 64 | Starting BubbleSort benchmark ... warmup ... completed. 65 | 66 | Benchmark: BubbleSort 67 | Iterations: 91 (elapsed time 3028 ms) 68 | AVERAGE: 33 ms 69 | 70 | Starting QuickSort benchmark ... warmup ... completed. 71 | 72 | Benchmark: QuickSort 73 | Iterations: 100 (elapsed time 2303 ms) 74 | AVERAGE: 23 ms 75 | 76 | Starting Sum benchmark ... warmup ... completed. 77 | 78 | Benchmark: Sum 79 | Iterations: 100 (elapsed time 2402 ms) 80 | AVERAGE: 24 ms 81 | 82 | Starting Towers benchmark ... warmup ... completed. 83 | 84 | Benchmark: Towers 85 | Iterations: 45 (elapsed time 3027 ms) 86 | AVERAGE: 67 ms 87 | 88 | Starting TreeSort benchmark ... warmup ... completed. 89 | 90 | Benchmark: TreeSort 91 | Iterations: 35 (elapsed time 3073 ms) 92 | AVERAGE: 88 ms 93 | 94 | Starting IntegerLoop benchmark ... warmup ... completed. 95 | 96 | Benchmark: IntegerLoop 97 | Iterations: 62 (elapsed time 3006 ms) 98 | AVERAGE: 48 ms 99 | 100 | Starting FieldLoop benchmark ... warmup ... completed. 101 | 102 | Benchmark: FieldLoop 103 | Iterations: 100 (elapsed time 2521 ms) 104 | AVERAGE: 25 ms 105 | 106 | Summed Average Runtime: 25 ms 107 | 108 | Total runtime by stop watch 62 secs 109 | Total average: 44 110 | Total geomean: 39 111 | Total median: 34 112 | Total sum: 746 113 | 114 | 115 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_0.2_pcall_every_method.txt: -------------------------------------------------------------------------------- 1 | Start execution of all benchmarks. Iterations: 100 2 | Starting Fibonacci benchmark ... warmup ... completed. 3 | 4 | Benchmark: Fibonacci 5 | Iterations: 22 (elapsed time 3013 ms) 6 | AVERAGE: 137 ms 7 | 8 | Starting Dispatch benchmark ... warmup ... completed. 9 | 10 | Benchmark: Dispatch 11 | Iterations: 79 (elapsed time 3014 ms) 12 | AVERAGE: 38 ms 13 | 14 | Starting Bounce benchmark ... warmup ... completed. 15 | 16 | Benchmark: Bounce 17 | Iterations: 50 (elapsed time 3003 ms) 18 | AVERAGE: 60 ms 19 | 20 | Starting Loop benchmark ... warmup ... completed. 21 | 22 | Benchmark: Loop 23 | Iterations: 100 (elapsed time 2949 ms) 24 | AVERAGE: 29 ms 25 | 26 | Starting Permute benchmark ... warmup ... completed. 27 | 28 | Benchmark: Permute 29 | Iterations: 55 (elapsed time 3039 ms) 30 | AVERAGE: 55 ms 31 | 32 | Starting Queens benchmark ... warmup ... completed. 33 | 34 | Benchmark: Queens 35 | Iterations: 50 (elapsed time 3032 ms) 36 | AVERAGE: 61 ms 37 | 38 | Starting List benchmark ... warmup ... completed. 39 | 40 | Benchmark: List 41 | Iterations: 46 (elapsed time 3034 ms) 42 | AVERAGE: 66 ms 43 | 44 | Starting Recurse benchmark ... warmup ... completed. 45 | 46 | Benchmark: Recurse 47 | Iterations: 50 (elapsed time 3011 ms) 48 | AVERAGE: 60 ms 49 | 50 | Starting Storage benchmark ... warmup ... completed. 51 | 52 | Benchmark: Storage 53 | Iterations: 56 (elapsed time 3048 ms) 54 | AVERAGE: 54 ms 55 | 56 | Starting Sieve benchmark ... warmup ... completed. 57 | 58 | Benchmark: Sieve 59 | Iterations: 77 (elapsed time 3037 ms) 60 | AVERAGE: 39 ms 61 | 62 | Starting BubbleSort benchmark ... warmup ... completed. 63 | 64 | Benchmark: BubbleSort 65 | Iterations: 70 (elapsed time 3026 ms) 66 | AVERAGE: 43 ms 67 | 68 | Starting QuickSort benchmark ... warmup ... completed. 69 | 70 | Benchmark: QuickSort 71 | Iterations: 100 (elapsed time 2679 ms) 72 | AVERAGE: 27 ms 73 | 74 | Starting Sum benchmark ... warmup ... completed. 75 | 76 | Benchmark: Sum 77 | Iterations: 100 (elapsed time 2658 ms) 78 | AVERAGE: 27 ms 79 | 80 | Starting Towers benchmark ... warmup ... completed. 81 | 82 | Benchmark: Towers 83 | Iterations: 28 (elapsed time 3077 ms) 84 | AVERAGE: 110 ms 85 | 86 | Starting TreeSort benchmark ... warmup ... completed. 87 | 88 | Benchmark: TreeSort 89 | Iterations: 31 (elapsed time 3043 ms) 90 | AVERAGE: 98 ms 91 | 92 | Starting IntegerLoop benchmark ... warmup ... completed. 93 | 94 | Benchmark: IntegerLoop 95 | Iterations: 56 (elapsed time 3023 ms) 96 | AVERAGE: 54 ms 97 | 98 | Starting FieldLoop benchmark ... warmup ... completed. 99 | 100 | Benchmark: FieldLoop 101 | Iterations: 61 (elapsed time 3045 ms) 102 | AVERAGE: 50 ms 103 | 104 | Summed Average Runtime: 50 ms 105 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_0.5_bc.txt: -------------------------------------------------------------------------------- 1 | SomLjVirtualMachine LuaJIT Bytecode version 2 | 3 | Start execution of all benchmarks. Iterations: 100 4 | Starting Fibonacci benchmark ... warmup ... completed. 5 | 6 | Benchmark: Fibonacci 7 | Iterations: 41 (elapsed time 3042 ms) 8 | AVERAGE: 74 ms 9 | 10 | Starting Dispatch benchmark ... warmup ... completed. 11 | 12 | Benchmark: Dispatch 13 | Iterations: 100 (elapsed time 2871 ms) 14 | AVERAGE: 29 ms 15 | 16 | Starting Bounce benchmark ... warmup ... completed. 17 | 18 | Benchmark: Bounce 19 | Iterations: 65 (elapsed time 3039 ms) 20 | AVERAGE: 47 ms 21 | 22 | Starting Loop benchmark ... warmup ... completed. 23 | 24 | Benchmark: Loop 25 | Iterations: 97 (elapsed time 3011 ms) 26 | AVERAGE: 31 ms 27 | 28 | Starting Permute benchmark ... warmup ... completed. 29 | 30 | Benchmark: Permute 31 | Iterations: 93 (elapsed time 3029 ms) 32 | AVERAGE: 33 ms 33 | 34 | Starting Queens benchmark ... warmup ... completed. 35 | 36 | Benchmark: Queens 37 | Iterations: 75 (elapsed time 3039 ms) 38 | AVERAGE: 41 ms 39 | 40 | Starting List benchmark ... warmup ... completed. 41 | 42 | Benchmark: List 43 | Iterations: 76 (elapsed time 3009 ms) 44 | AVERAGE: 40 ms 45 | 46 | Starting Recurse benchmark ... warmup ... completed. 47 | 48 | Benchmark: Recurse 49 | Iterations: 80 (elapsed time 3015 ms) 50 | AVERAGE: 38 ms 51 | 52 | Starting Storage benchmark ... warmup ... completed. 53 | 54 | Benchmark: Storage 55 | Iterations: 78 (elapsed time 3034 ms) 56 | AVERAGE: 39 ms 57 | 58 | Starting Sieve benchmark ... warmup ... completed. 59 | 60 | Benchmark: Sieve 61 | Iterations: 77 (elapsed time 3009 ms) 62 | AVERAGE: 39 ms 63 | 64 | Starting BubbleSort benchmark ... warmup ... completed. 65 | 66 | Benchmark: BubbleSort 67 | Iterations: 84 (elapsed time 3018 ms) 68 | AVERAGE: 36 ms 69 | 70 | Starting QuickSort benchmark ... warmup ... completed. 71 | 72 | Benchmark: QuickSort 73 | Iterations: 100 (elapsed time 2622 ms) 74 | AVERAGE: 26 ms 75 | 76 | Starting Sum benchmark ... warmup ... completed. 77 | 78 | Benchmark: Sum 79 | Iterations: 100 (elapsed time 2901 ms) 80 | AVERAGE: 29 ms 81 | 82 | Starting Towers benchmark ... warmup ... completed. 83 | 84 | Benchmark: Towers 85 | Iterations: 46 (elapsed time 3034 ms) 86 | AVERAGE: 66 ms 87 | 88 | Starting TreeSort benchmark ... warmup ... completed. 89 | 90 | Benchmark: TreeSort 91 | Iterations: 39 (elapsed time 3071 ms) 92 | AVERAGE: 79 ms 93 | 94 | Starting IntegerLoop benchmark ... warmup ... completed. 95 | 96 | Benchmark: IntegerLoop 97 | Iterations: 52 (elapsed time 3036 ms) 98 | AVERAGE: 58 ms 99 | 100 | Starting FieldLoop benchmark ... warmup ... completed. 101 | 102 | Benchmark: FieldLoop 103 | Iterations: 100 (elapsed time 2758 ms) 104 | AVERAGE: 28 ms 105 | 106 | Summed Average Runtime: 28 ms 107 | 108 | average 43 109 | geomean 41 110 | median 39 111 | sum 733 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_0.7.1_bc.txt: -------------------------------------------------------------------------------- 1 | SomLjVirtualMachine LuaJIT Bytecode version with ifTrue/ifFalse and whileTrue/whileFalse inlined 2 | 3 | Start execution of all benchmarks. Iterations: 100 4 | Starting Fibonacci benchmark ... warmup ... completed. 5 | 6 | Benchmark: Fibonacci 7 | Iterations: 65 (elapsed time 3045 ms) 8 | AVERAGE: 47 ms 9 | 10 | Starting Dispatch benchmark ... warmup ... completed. 11 | 12 | Benchmark: Dispatch 13 | Iterations: 100 (elapsed time 2239 ms) 14 | AVERAGE: 22 ms 15 | 16 | Starting Bounce benchmark ... warmup ... completed. 17 | 18 | Benchmark: Bounce 19 | Iterations: 100 (elapsed time 2288 ms) 20 | AVERAGE: 23 ms 21 | 22 | Starting Loop benchmark ... warmup ... completed. 23 | 24 | Benchmark: Loop 25 | Iterations: 100 (elapsed time 2334 ms) 26 | AVERAGE: 23 ms 27 | 28 | Starting Permute benchmark ... warmup ... completed. 29 | 30 | Benchmark: Permute 31 | Iterations: 100 (elapsed time 1819 ms) 32 | AVERAGE: 18 ms 33 | 34 | Starting Queens benchmark ... warmup ... completed. 35 | 36 | Benchmark: Queens 37 | Iterations: 96 (elapsed time 3030 ms) 38 | AVERAGE: 32 ms 39 | 40 | Starting List benchmark ... warmup ... 41 | completed. 42 | 43 | Benchmark: List 44 | Iterations: 100 (elapsed time 221 ms) 45 | AVERAGE: 2 ms 46 | 47 | Starting Recurse benchmark ... warmup ... 48 | completed. 49 | 50 | Benchmark: Recurse 51 | Iterations: 100 (elapsed time 2535 ms) 52 | AVERAGE: 25 ms 53 | 54 | Starting Storage benchmark ... warmup ... 55 | completed. 56 | 57 | Benchmark: Storage 58 | Iterations: 100 (elapsed time 2201 ms) 59 | AVERAGE: 22 ms 60 | 61 | Starting Sieve benchmark ... warmup ... completed. 62 | 63 | Benchmark: Sieve 64 | Iterations: 100 (elapsed time 2945 ms) 65 | AVERAGE: 29 ms 66 | 67 | Starting BubbleSort benchmark ... warmup ... completed. 68 | 69 | Benchmark: BubbleSort 70 | Iterations: 100 (elapsed time 2633 ms) 71 | AVERAGE: 26 ms 72 | 73 | Starting QuickSort benchmark ... warmup ... completed. 74 | 75 | Benchmark: QuickSort 76 | Iterations: 100 (elapsed time 1274 ms) 77 | AVERAGE: 13 ms 78 | 79 | Starting Sum benchmark ... warmup ... completed. 80 | 81 | Benchmark: Sum 82 | Iterations: 100 (elapsed time 2263 ms) 83 | AVERAGE: 23 ms 84 | 85 | Starting Towers benchmark ... warmup ... completed. 86 | 87 | Benchmark: Towers 88 | Iterations: 100 (elapsed time 2564 ms) 89 | AVERAGE: 26 ms 90 | 91 | Starting TreeSort benchmark ... warmup ... completed. 92 | 93 | Benchmark: TreeSort 94 | Iterations: 100 (elapsed time 1029 ms) 95 | AVERAGE: 10 ms 96 | 97 | Starting IntegerLoop benchmark ... warmup ... completed. 98 | 99 | Benchmark: IntegerLoop 100 | Iterations: 68 (elapsed time 3032 ms) 101 | AVERAGE: 45 ms 102 | 103 | Starting FieldLoop benchmark ... warmup ... completed. 104 | 105 | Benchmark: FieldLoop 106 | Iterations: 37 (elapsed time 3051 ms) 107 | AVERAGE: 82 ms 108 | 109 | Summed Average Runtime: 82 ms 110 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_0.7_bc.txt: -------------------------------------------------------------------------------- 1 | SomLjVirtualMachine LuaJIT Bytecode version with ifTrue/ifFalse inlined 2 | 3 | Start execution of all benchmarks. Iterations: 100 4 | Starting Fibonacci benchmark ... warmup ... completed. 5 | 6 | Benchmark: Fibonacci 7 | Iterations: 64 (elapsed time 3014 ms) 8 | AVERAGE: 47 ms 9 | 10 | Starting Dispatch benchmark ... warmup ... completed. 11 | 12 | Benchmark: Dispatch 13 | Iterations: 100 (elapsed time 2827 ms) 14 | AVERAGE: 28 ms 15 | 16 | Starting Bounce benchmark ... warmup ... completed. 17 | 18 | Benchmark: Bounce 19 | Iterations: 100 (elapsed time 2619 ms) 20 | AVERAGE: 26 ms 21 | 22 | Starting Loop benchmark ... warmup ... completed. 23 | 24 | Benchmark: Loop 25 | Iterations: 98 (elapsed time 3005 ms) 26 | AVERAGE: 31 ms 27 | 28 | Starting Permute benchmark ... warmup ... completed. 29 | 30 | Benchmark: Permute 31 | Iterations: 100 (elapsed time 1718 ms) 32 | AVERAGE: 17 ms 33 | 34 | Starting Queens benchmark ... warmup ... completed. 35 | 36 | Benchmark: Queens 37 | Iterations: 93 (elapsed time 3001 ms) 38 | AVERAGE: 32 ms 39 | 40 | Starting List benchmark ... warmup ... completed. 41 | 42 | Benchmark: List 43 | Iterations: 100 (elapsed time 1436 ms) 44 | AVERAGE: 14 ms 45 | 46 | Starting Recurse benchmark ... warmup ... completed. 47 | 48 | Benchmark: Recurse 49 | Iterations: 100 (elapsed time 2235 ms) 50 | AVERAGE: 22 ms 51 | 52 | Starting Storage benchmark ... warmup ... completed. 53 | 54 | Benchmark: Storage 55 | Iterations: 100 (elapsed time 2630 ms) 56 | AVERAGE: 26 ms 57 | 58 | Starting Sieve benchmark ... warmup ... completed. 59 | 60 | Benchmark: Sieve 61 | Iterations: 85 (elapsed time 3031 ms) 62 | AVERAGE: 36 ms 63 | 64 | Starting BubbleSort benchmark ... warmup ... completed. 65 | 66 | Benchmark: BubbleSort 67 | Iterations: 100 (elapsed time 3021 ms) 68 | AVERAGE: 30 ms 69 | 70 | Starting QuickSort benchmark ... warmup ... completed. 71 | 72 | Benchmark: QuickSort 73 | Iterations: 100 (elapsed time 2353 ms) 74 | AVERAGE: 24 ms 75 | 76 | Starting Sum benchmark ... warmup ... completed. 77 | 78 | Benchmark: Sum 79 | Iterations: 100 (elapsed time 2828 ms) 80 | AVERAGE: 28 ms 81 | 82 | Starting Towers benchmark ... warmup ... completed. 83 | 84 | Benchmark: Towers 85 | Iterations: 100 (elapsed time 2585 ms) 86 | AVERAGE: 26 ms 87 | 88 | Starting TreeSort benchmark ... warmup ... completed. 89 | 90 | Benchmark: TreeSort 91 | Iterations: 100 (elapsed time 1153 ms) 92 | AVERAGE: 12 ms 93 | 94 | Starting IntegerLoop benchmark ... warmup ... completed. 95 | 96 | Benchmark: IntegerLoop 97 | Iterations: 53 (elapsed time 3041 ms) 98 | AVERAGE: 57 ms 99 | 100 | Starting FieldLoop benchmark ... warmup ... completed. 101 | 102 | Benchmark: FieldLoop 103 | Iterations: 100 (elapsed time 2918 ms) 104 | AVERAGE: 29 ms 105 | 106 | Summed Average Runtime: 29 ms 107 | 108 | average 29 109 | geomean 27 110 | median 28 111 | sum 485 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_0.8.0_bc.txt: -------------------------------------------------------------------------------- 1 | LjSOM version: 0.8.0 license: GPL; see http://github.com/rochus-keller/Som 2 | based on LuaJIT 2.0.5 Copyright (C) 2005-2020 Mike Pall http://luajit.org/ 3 | JIT: ON CMOV SSE2 SSE3 SSE4.1 fold cse dce fwd dse narrow loop abc sink fuse 4 | 5 | Start execution of all benchmarks. Iterations: 100 6 | Starting Fibonacci benchmark ... warmup ... completed. 7 | 8 | Benchmark: Fibonacci 9 | Iterations: 100 (elapsed time 1163 ms) 10 | AVERAGE: 12 ms 11 | 12 | Starting Dispatch benchmark ... warmup ... completed. 13 | 14 | Benchmark: Dispatch 15 | Iterations: 100 (elapsed time 726 ms) 16 | AVERAGE: 7 ms 17 | 18 | Starting Bounce benchmark ... warmup ... completed. 19 | 20 | Benchmark: Bounce 21 | Iterations: 100 (elapsed time 656 ms) 22 | AVERAGE: 7 ms 23 | 24 | Starting Loop benchmark ... warmup ... completed. 25 | 26 | Benchmark: Loop 27 | Iterations: 100 (elapsed time 730 ms) 28 | AVERAGE: 7 ms 29 | 30 | Starting Permute benchmark ... warmup ... completed. 31 | 32 | Benchmark: Permute 33 | Iterations: 100 (elapsed time 616 ms) 34 | AVERAGE: 6 ms 35 | 36 | Starting Queens benchmark ... warmup ... completed. 37 | 38 | Benchmark: Queens 39 | Iterations: 100 (elapsed time 889 ms) 40 | AVERAGE: 9 ms 41 | 42 | Starting List benchmark ... warmup ... completed. 43 | 44 | Benchmark: List 45 | Iterations: 100 (elapsed time 212 ms) 46 | AVERAGE: 2 ms 47 | 48 | Starting Recurse benchmark ... warmup ... completed. 49 | 50 | Benchmark: Recurse 51 | Iterations: 100 (elapsed time 817 ms) 52 | AVERAGE: 8 ms 53 | 54 | Starting Storage benchmark ... warmup ... completed. 55 | 56 | Benchmark: Storage 57 | Iterations: 100 (elapsed time 787 ms) 58 | AVERAGE: 8 ms 59 | 60 | Starting Sieve benchmark ... warmup ... completed. 61 | 62 | Benchmark: Sieve 63 | Iterations: 100 (elapsed time 1104 ms) 64 | AVERAGE: 11 ms 65 | 66 | Starting BubbleSort benchmark ... warmup ... completed. 67 | 68 | Benchmark: BubbleSort 69 | Iterations: 100 (elapsed time 874 ms) 70 | AVERAGE: 9 ms 71 | 72 | Starting QuickSort benchmark ... warmup ... completed. 73 | 74 | Benchmark: QuickSort 75 | Iterations: 100 (elapsed time 354 ms) 76 | AVERAGE: 4 ms 77 | 78 | Starting Sum benchmark ... warmup ... completed. 79 | 80 | Benchmark: Sum 81 | Iterations: 100 (elapsed time 1298 ms) 82 | AVERAGE: 13 ms 83 | 84 | Starting Towers benchmark ... warmup ... completed. 85 | 86 | Benchmark: Towers 87 | Iterations: 100 (elapsed time 722 ms) 88 | AVERAGE: 7 ms 89 | 90 | Starting TreeSort benchmark ... warmup ... completed. 91 | 92 | Benchmark: TreeSort 93 | Iterations: 100 (elapsed time 437 ms) 94 | AVERAGE: 4 ms 95 | 96 | Starting IntegerLoop benchmark ... warmup ... completed. 97 | 98 | Benchmark: IntegerLoop 99 | Iterations: 100 (elapsed time 2476 ms) 100 | AVERAGE: 25 ms 101 | 102 | Starting FieldLoop benchmark ... warmup ... completed. 103 | 104 | Benchmark: FieldLoop 105 | Iterations: 100 (elapsed time 682 ms) 106 | AVERAGE: 7 ms 107 | 108 | Summed Average Runtime: 145 ms 109 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/All.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = All 4 | local class = All._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.all(self) 12 | return ((((((((((((((((Fibonacci):_0c(Dispatch)):_0c(Bounce)):_0c(Loop)):_0c(Permute)):_0c(Queens)):_0c(List)):_0c(Recurse)):_0c(Storage)):_0c(Sieve)):_0c(BubbleSort)):_0c(QuickSort)):_0c(Sum)):_0c(Towers)):_0c(TreeSort)):_0c(IntegerLoop)):_0c(FieldLoop); 13 | end 14 | 15 | function class.run_(self,params) 16 | (((params):length()):_0l((2))):ifTrue_ifFalse_(_block( function() 17 | return (self):exec_((100)) 18 | end ),_block( function() 19 | return (self):exec_(((params):at_((2))):asInteger()) 20 | end )); 21 | return self 22 | end 23 | 24 | function class.printUsage(self) 25 | (_str("./som.sh -cp Smalltalk Examples/Benchmarks/All.som [number-of-iterations]")):println(); 26 | (_str("")):println(); 27 | (_str(" number-of-iterations - the number of time each benchmark is executed, default: 1")):println(); 28 | return self 29 | end 30 | 31 | function class.initialize(self) 32 | self._super.initialize(self); 33 | self[8] = (0); 34 | return self 35 | end 36 | 37 | function class.exec_(self,iterations) 38 | (_str("Start execution of all benchmarks. Iterations: ")):print(); 39 | (iterations):println(); 40 | ((self):all()):do_(_block( function(cls) 41 | (self):initialize(); 42 | (self):benchmarkClass_(cls); 43 | (self):printAll_(false); 44 | (self):maxRuntime_((3)); 45 | (self):numIterations_(iterations); 46 | (self):warmUp_((10)); 47 | return (self):runBenchmark() 48 | end )); 49 | (self):printTotal(); 50 | return self 51 | end 52 | 53 | function class.reportBenchmark_result_(self,bench,total) 54 | (_str("")):println(); 55 | (_str("Benchmark: ")):print(); 56 | ((bench):name()):println(); 57 | (((((_str(" Iterations: ")):_0p(self[3])):_0p(_str(" (elapsed time "))):_0p(((total):_0hh((1000))):round())):_0p(_str(" ms)"))):println(); 58 | (((_str(" AVERAGE: ")):_0p((((total):_0hh(self[3])):_0hh((1000))):round())):_0p(_str(" ms"))):println(); 59 | self[8] = (self[8]):_0p((total):_0hh(self[3])); 60 | return self 61 | end 62 | 63 | function class.printTotal(self) 64 | (((_str("Summed Average Runtime: ")):_0p((((self[8]):_0hh((1000))):round()):asString())):_0p(_str(" ms"))):println(); 65 | return self 66 | end 67 | 68 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Array.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Array 4 | local class = Array._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.putAll_(self,block) 12 | (self):doIndexes_(_block( function(i) 13 | return (self):at_put_(i,(block):value()) 14 | end )); 15 | return self 16 | end 17 | 18 | function class.first(self) 19 | return (self):at_((1)); 20 | end 21 | 22 | function class.last(self) 23 | return (self):at_((self):length()); 24 | end 25 | 26 | function class.do_(self,block) 27 | (self):doIndexes_(_block( function(i) 28 | return (block):value_((self):at_(i)) 29 | end )); 30 | return self 31 | end 32 | 33 | function class.doIndexes_(self,block) 34 | ((1)):to_do_((self):length(),_block( function(i) 35 | return (block):value_(i) 36 | end )); 37 | return self 38 | end 39 | 40 | function class.from_to_do_(self,start,_end,block) 41 | (start):to_do_(_end,_block( function(i) 42 | return (block):value_((self):at_(i)) 43 | end )); 44 | return self 45 | end 46 | 47 | function class.copyFrom_to_(self,start,_end) 48 | local result 49 | local i 50 | result = (Array):new_(((_end):_0m(start)):_0p((1))); 51 | i = (1); 52 | (self):from_to_do_(start,_end,_block( function(e) 53 | (result):at_put_(i,e); 54 | i = (i):_0p((1)) 55 | return i 56 | end )); 57 | return result; 58 | end 59 | 60 | function class.copyFrom_(self,start) 61 | return (self):copyFrom_to_(start,(self):length()); 62 | end 63 | 64 | function class.replaceFrom_to_with_startingAt_(self,start,stop,replacement,repStart) 65 | local index 66 | local repOff 67 | repOff = (repStart):_0m(start); 68 | index = (start):_0m((1)); 69 | (_block( function() 70 | return (( function()index = (index):_0p((1)); return index end )()):_0lq(stop) 71 | end )):whileTrue_(_block( function() 72 | return (self):at_put_(index,(replacement):at_((repOff):_0p(index))) 73 | end )); 74 | return self 75 | end 76 | 77 | function class.copy(self) 78 | return (self):copyFrom_((1)); 79 | end 80 | 81 | function class.sum(self) 82 | return (self):inject_into_((0),_block( function(sub,elem) 83 | return (sub):_0p(elem) 84 | end )); 85 | end 86 | 87 | function class.average(self) 88 | return ((self):sum()):_0h((self):length()); 89 | end 90 | 91 | function class.contains_(self,element) 92 | local _nonLocal, _nlRes 93 | local _status, _pcallRes = pcall( function() 94 | (self):do_(_block( function(e) 95 | return ((e):_0q(element)):ifTrue_(_block( function() 96 | _nlRes = true; _nonLocal = true; error(_nlRes) 97 | end )) 98 | end )); 99 | return false; 100 | end ) 101 | if _status then return _pcallRes elseif _nonLocal then return _nlRes else error(_pcallRes) end 102 | end 103 | 104 | function class.indexOf_(self,element) 105 | local _nonLocal, _nlRes 106 | local _status, _pcallRes = pcall( function() 107 | (self):doIndexes_(_block( function(i) 108 | return (((self):at_(i)):_0q(element)):ifTrue_(_block( function() 109 | _nlRes = i; _nonLocal = true; error(_nlRes) 110 | end )) 111 | end )); 112 | return nil; 113 | end ) 114 | if _status then return _pcallRes elseif _nonLocal then return _nlRes else error(_pcallRes) end 115 | end 116 | 117 | function class.lastIndexOf_(self,element) 118 | local _nonLocal, _nlRes 119 | local _status, _pcallRes = pcall( function() 120 | ((self):length()):downTo_do_((1),_block( function(i) 121 | return (((self):at_(i)):_0q(element)):ifTrue_(_block( function() 122 | _nlRes = i; _nonLocal = true; error(_nlRes) 123 | end )) 124 | end )); 125 | return nil; 126 | end ) 127 | if _status then return _pcallRes elseif _nonLocal then return _nlRes else error(_pcallRes) end 128 | end 129 | 130 | function class.collect_(self,aBlock) 131 | local result 132 | result = (Array):new_((self):length()); 133 | (self):doIndexes_(_block( function(i) 134 | return (result):at_put_(i,(aBlock):value_((self):at_(i))) 135 | end )); 136 | return result; 137 | end 138 | 139 | function class.inject_into_(self,sub,aBlock) 140 | local next 141 | next = sub; 142 | (self):do_(_block( function(e) 143 | next = (aBlock):value_with_(next,e) 144 | return next 145 | end )); 146 | return next; 147 | end 148 | 149 | function class.reject_(self,aBlock) 150 | return (self):select_(_block( function(element) 151 | return ((aBlock):value_(element)):_0qq(false) 152 | end )); 153 | end 154 | 155 | function class.select_(self,aBlock) 156 | local newCollection 157 | newCollection = (Vector):new_((self):length()); 158 | (self):do_(_block( function(each) 159 | return ((aBlock):value_(each)):ifTrue_(_block( function() 160 | return (newCollection):append_(each) 161 | end )) 162 | end )); 163 | return newCollection; 164 | end 165 | 166 | function class.union_(self,aCollection) 167 | local new 168 | new = (Set):new(); 169 | (new):addAll_(self); 170 | (new):addAll_(aCollection); 171 | return new; 172 | end 173 | 174 | function metaclass.new(self) 175 | return (self):new_((0)); 176 | end 177 | 178 | function metaclass.new_withAll_(self,length,block) 179 | return ((self):new_(length)):putAll_(block); 180 | end 181 | 182 | function metaclass.with_(self,a) 183 | local arr 184 | arr = (self):new_((1)); 185 | (arr):at_put_((1),a); 186 | return arr; 187 | end 188 | 189 | function metaclass.with_with_(self,a,b) 190 | local arr 191 | arr = (self):new_((2)); 192 | (arr):at_put_((1),a); 193 | (arr):at_put_((2),b); 194 | return arr; 195 | end 196 | 197 | function metaclass.with_with_with_(self,a,b,c) 198 | local arr 199 | arr = (self):new_((3)); 200 | (arr):at_put_((1),a); 201 | (arr):at_put_((2),b); 202 | (arr):at_put_((3),c); 203 | return arr; 204 | end 205 | 206 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Ball.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Ball 4 | local class = Ball._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.bounce(self) 12 | local xLimit 13 | local yLimit 14 | local bounced 15 | xLimit = ( function()yLimit = (500); return yLimit end )(); 16 | bounced = false; 17 | self[1] = (self[1]):_0p(self[3]); 18 | self[2] = (self[2]):_0p(self[4]); 19 | ((self[1]):_0g(xLimit)):ifTrue_(_block( function() 20 | self[1] = xLimit; 21 | self[3] = ((0)):_0m((self[3]):abs()); 22 | bounced = true 23 | return bounced 24 | end )); 25 | ((self[1]):_0l((0))):ifTrue_(_block( function() 26 | self[1] = (0); 27 | self[3] = (self[3]):abs(); 28 | bounced = true 29 | return bounced 30 | end )); 31 | ((self[2]):_0g(yLimit)):ifTrue_(_block( function() 32 | self[2] = yLimit; 33 | self[4] = ((0)):_0m((self[4]):abs()); 34 | bounced = true 35 | return bounced 36 | end )); 37 | ((self[2]):_0l((0))):ifTrue_(_block( function() 38 | self[2] = (0); 39 | self[4] = (self[4]):abs(); 40 | bounced = true 41 | return bounced 42 | end )); 43 | return bounced; 44 | end 45 | 46 | function class.initialize(self) 47 | self[1] = ((Random):next()):_0r((500)); 48 | self[2] = ((Random):next()):_0r((500)); 49 | self[3] = (((Random):next()):_0r((300))):_0m((150)); 50 | self[4] = (((Random):next()):_0r((300))):_0m((150)); 51 | return self 52 | end 53 | 54 | function metaclass.new(self) 55 | return (self._super.new(self)):initialize(); 56 | end 57 | 58 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Benchmark.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Benchmark 4 | local class = Benchmark._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.run(self) 12 | local harness 13 | harness = (All):new(); 14 | (harness):initialize(); 15 | (harness):benchmarkClass_((self):class()); 16 | (harness):printAll_(false); 17 | (harness):maxRuntime_((3)); 18 | (harness):numIterations_((100)); 19 | (harness):warmUp_((10)); 20 | (harness):runBenchmark(); 21 | (harness):printTotal(); 22 | return self 23 | end 24 | 25 | function class.oneTimeSetup(self) 26 | end 27 | 28 | function class.innerBenchmarkLoop_(self,innerIterations) 29 | local _nonLocal, _nlRes 30 | local _status, _pcallRes = pcall( function() 31 | local i 32 | i = (0); 33 | (_block( function() 34 | return (i):_0l(innerIterations) 35 | end )):whileTrue_(_block( function() 36 | ((self):verifyResult_((self):benchmark())):ifFalse_(_block( function() 37 | _nlRes = false; _nonLocal = true; error(_nlRes) 38 | end )); 39 | i = (i):_0p((1)) 40 | return i 41 | end )); 42 | return true; 43 | end ) 44 | if _status then return _pcallRes elseif _nonLocal then return _nlRes else error(_pcallRes) end 45 | end 46 | 47 | function class.benchmark(self) 48 | (self):subclassResponsibility(); 49 | return self 50 | end 51 | 52 | function class.verifyResult_(self,result) 53 | (self):subclassResponsibility(); 54 | return self 55 | end 56 | 57 | function class.name(self) 58 | return (((self):class()):name()):asString(); 59 | end 60 | 61 | function class.assert_equals_(self,expected,value) 62 | ((expected):_0q(value)):ifFalse_(_block( function() 63 | return (self):error_(((((_str("Expected value (")):_0p((expected):asString())):_0p(_str(") differs from actual ("))):_0p((value):asString())):_0p(_str(") benchmark result."))) 64 | end )); 65 | return true; 66 | end 67 | 68 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Block.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Block 4 | local class = Block._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.whileFalse_(self,block) 12 | (_block( function() 13 | return ((self):value()):_not() 14 | end )):whileTrue_(block); 15 | return self 16 | end 17 | 18 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Boolean.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Boolean 4 | local class = Boolean._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.ifTrue_ifFalse_(self,trueBlock,falseBlock) 12 | local _nonLocal, _nlRes 13 | local _status, _pcallRes = pcall( function() 14 | (self):ifTrue_(_block( function() 15 | _nlRes = (trueBlock):value(); _nonLocal = true; error(_nlRes) 16 | end )); 17 | (self):ifFalse_(_block( function() 18 | _nlRes = (falseBlock):value(); _nonLocal = true; error(_nlRes) 19 | end )); 20 | return self 21 | end ) 22 | if _status then return _pcallRes elseif _nonLocal then return _nlRes else error(_pcallRes) end 23 | end 24 | 25 | function class._0bb(self,boolean) 26 | return (self):or_(boolean); 27 | end 28 | 29 | function class._0aa(self,boolean) 30 | return (self):and_(boolean); 31 | end 32 | 33 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Bounce.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Bounce 4 | local class = Bounce._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.benchmark(self) 12 | local ballCount 13 | local balls 14 | local bounces 15 | (Random):initialize(); 16 | ballCount = (100); 17 | bounces = (0); 18 | balls = (Array):new_withAll_(ballCount,_block( function() 19 | return (Ball):new() 20 | end )); 21 | ((1)):to_do_((50),_block( function(i) 22 | return (balls):do_(_block( function(ball) 23 | return ((ball):bounce()):ifTrue_(_block( function() 24 | bounces = (bounces):_0p((1)) 25 | return bounces 26 | end )) 27 | end )) 28 | end )); 29 | return bounces; 30 | end 31 | 32 | function class.verifyResult_(self,result) 33 | return (self):assert_equals_((1331),result); 34 | end 35 | 36 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/BubbleSort.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = BubbleSort 4 | local class = BubbleSort._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.sort_(self,array) 12 | ((array):length()):downTo_do_((1),_block( function(i) 13 | return ((1)):to_do_((i):_0m((1)),_block( function(j) 14 | local current 15 | local next 16 | current = (array):at_(j); 17 | next = (array):at_((j):_0p((1))); 18 | return ((current):_0g(next)):ifTrue_(_block( function() 19 | (array):at_put_(j,next); 20 | return (array):at_put_((j):_0p((1)),current) 21 | end )) 22 | end )) 23 | end )); 24 | return array; 25 | end 26 | 27 | function class.dataSize(self) 28 | return (130); 29 | end 30 | 31 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Class.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Class 4 | local class = Class._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.asString(self) 12 | return ((self):name()):asString(); 13 | end 14 | 15 | function class.selectors(self) 16 | return ((self):methods()):collect_(_block( function(inv) 17 | return (inv):signature() 18 | end )); 19 | end 20 | 21 | function class.hasMethod_(self,aSymbol) 22 | local _nonLocal, _nlRes 23 | local _status, _pcallRes = pcall( function() 24 | ((self):methods()):do_(_block( function(m) 25 | return (((m):signature()):_0q(aSymbol)):ifTrue_(_block( function() 26 | _nlRes = true; _nonLocal = true; error(_nlRes) 27 | end )) 28 | end )); 29 | return false; 30 | end ) 31 | if _status then return _pcallRes elseif _nonLocal then return _nlRes else error(_pcallRes) end 32 | end 33 | 34 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Dispatch.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Dispatch 4 | local class = Dispatch._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.benchmark(self) 12 | local cnt 13 | cnt = (0); 14 | ((1)):to_do_((20000),_block( function(i) 15 | cnt = (cnt):_0p((self):method_(i)) 16 | return cnt 17 | end )); 18 | return cnt; 19 | end 20 | 21 | function class.method_(self,argument) 22 | return argument; 23 | end 24 | 25 | function class.verifyResult_(self,result) 26 | return ((200010000)):_0q(result); 27 | end 28 | 29 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Double.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Double 4 | local class = Double._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.abs(self) 12 | return ((self):_0l(_dbl(0.0))):ifTrue_ifFalse_((_dbl(0.0)):_0m(self),self); 13 | end 14 | 15 | function class.negated(self) 16 | return (_dbl(0.0)):_0m(self); 17 | end 18 | 19 | function class._0g(self,argument) 20 | return ((self):_0gq(argument)):and_(_block( function() 21 | return (self):_0lg(argument) 22 | end )); 23 | end 24 | 25 | function class._0gq(self,argument) 26 | return ((self):_0l(argument)):_not(); 27 | end 28 | 29 | function class._0lq(self,argument) 30 | return ((self):_0l(argument)):or_(_block( function() 31 | return (self):_0q(argument) 32 | end )); 33 | end 34 | 35 | function class.negative(self) 36 | return (self):_0l(_dbl(0.0)); 37 | end 38 | 39 | function class.between_and_(self,a,b) 40 | return ((self):_0g(a)):and_(_block( function() 41 | return (self):_0l(b) 42 | end )); 43 | end 44 | 45 | function class.to_do_(self,limit,block) 46 | local i 47 | i = self; 48 | (_block( function() 49 | return (i):_0lq(limit) 50 | end )):whileTrue_(_block( function() 51 | (block):value_(i); 52 | i = (i):_0p(_dbl(1.0)) 53 | return i 54 | end )); 55 | return self 56 | end 57 | 58 | function class.downTo_do_(self,limit,block) 59 | local i 60 | i = self; 61 | (_block( function() 62 | return (i):_0gq(limit) 63 | end )):whileTrue_(_block( function() 64 | (block):value_(i); 65 | i = (i):_0m(_dbl(1.0)) 66 | return i 67 | end )); 68 | return self 69 | end 70 | 71 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/False.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = False 4 | local class = False._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.asString(self) 12 | return _str("false"); 13 | end 14 | 15 | function class.ifTrue_(self,block) 16 | return nil; 17 | end 18 | 19 | function class.ifFalse_(self,block) 20 | return (block):value(); 21 | end 22 | 23 | function class._not(self) 24 | return true; 25 | end 26 | 27 | function class.or_(self,block) 28 | return (block):value(); 29 | end 30 | 31 | function class.and_(self,block) 32 | return false; 33 | end 34 | 35 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Fibonacci.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Fibonacci 4 | local class = Fibonacci._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.benchmark(self) 12 | local result 13 | result = (self):fibonacci_((20)); 14 | return result; 15 | end 16 | 17 | function class.fibonacci_(self,n) 18 | return ((n):_0lq((1))):ifTrue_ifFalse_((1),_block( function() 19 | return ((self):fibonacci_((n):_0m((1)))):_0p((self):fibonacci_((n):_0m((2)))) 20 | end )); 21 | end 22 | 23 | function class.verifyResult_(self,result) 24 | return ((10946)):_0q(result); 25 | end 26 | 27 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/FieldLoop.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = FieldLoop 4 | local class = FieldLoop._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.benchmark(self) 12 | local iter 13 | self[1] = (0); 14 | iter = (20000); 15 | (_block( function() 16 | return (iter):_0g((0)) 17 | end )):whileTrue_(_block( function() 18 | iter = (iter):_0m((1)); 19 | self[1] = (self[1]):_0p((1)); 20 | self[1] = (self[1]):_0p((1)); 21 | self[1] = (self[1]):_0p((1)); 22 | self[1] = (self[1]):_0p((1)); 23 | self[1] = (self[1]):_0p((1)); 24 | self[1] = (self[1]):_0p((1)); 25 | self[1] = (self[1]):_0p((1)); 26 | self[1] = (self[1]):_0p((1)); 27 | self[1] = (self[1]):_0p((1)); 28 | self[1] = (self[1]):_0p((1)); 29 | self[1] = (self[1]):_0p((1)); 30 | self[1] = (self[1]):_0p((1)); 31 | self[1] = (self[1]):_0p((1)); 32 | self[1] = (self[1]):_0p((1)); 33 | self[1] = (self[1]):_0p((1)); 34 | self[1] = (self[1]):_0p((1)); 35 | self[1] = (self[1]):_0p((1)); 36 | self[1] = (self[1]):_0p((1)); 37 | self[1] = (self[1]):_0p((1)); 38 | self[1] = (self[1]):_0p((1)); 39 | self[1] = (self[1]):_0p((1)); 40 | self[1] = (self[1]):_0p((1)); 41 | self[1] = (self[1]):_0p((1)); 42 | self[1] = (self[1]):_0p((1)); 43 | self[1] = (self[1]):_0p((1)); 44 | self[1] = (self[1]):_0p((1)); 45 | self[1] = (self[1]):_0p((1)); 46 | self[1] = (self[1]):_0p((1)); 47 | self[1] = (self[1]):_0p((1)); 48 | self[1] = (self[1]):_0p((1)) 49 | return self[1] 50 | end )); 51 | return self[1]; 52 | end 53 | 54 | function class.verifyResult_(self,result) 55 | return ((600000)):_0q(result); 56 | end 57 | 58 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Integer.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Integer 4 | local class = Integer._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.abs(self) 12 | return ((self):_0l((0))):ifTrue_ifFalse_(((0)):_0m(self),self); 13 | end 14 | 15 | function class.negated(self) 16 | return ((0)):_0m(self); 17 | end 18 | 19 | function class._0tq(self,argument) 20 | return ((self):_0q(argument)):_not(); 21 | end 22 | 23 | function class._0g(self,argument) 24 | return ((self):_0gq(argument)):and_(_block( function() 25 | return (self):_0lg(argument) 26 | end )); 27 | end 28 | 29 | function class._0gq(self,argument) 30 | return ((self):_0l(argument)):_not(); 31 | end 32 | 33 | function class._0lq(self,argument) 34 | return ((self):_0l(argument)):or_(_block( function() 35 | return (self):_0q(argument) 36 | end )); 37 | end 38 | 39 | function class.negative(self) 40 | return (self):_0l((0)); 41 | end 42 | 43 | function class.between_and_(self,a,b) 44 | return ((self):_0g(a)):and_(_block( function() 45 | return (self):_0l(b) 46 | end )); 47 | end 48 | 49 | function class.hashcode(self) 50 | return self; 51 | end 52 | 53 | function class.to_do_(self,limit,block) 54 | (self):to_by_do_(limit,(1),block); 55 | return self 56 | end 57 | 58 | function class.to_by_do_(self,limit,step,block) 59 | local i 60 | i = self; 61 | (_block( function() 62 | return (i):_0lq(limit) 63 | end )):whileTrue_(_block( function() 64 | (block):value_(i); 65 | i = (i):_0p(step) 66 | return i 67 | end )); 68 | return self 69 | end 70 | 71 | function class.downTo_do_(self,limit,block) 72 | (self):downTo_by_do_(limit,(1),block); 73 | return self 74 | end 75 | 76 | function class.downTo_by_do_(self,limit,step,block) 77 | local i 78 | i = self; 79 | (_block( function() 80 | return (i):_0gq(limit) 81 | end )):whileTrue_(_block( function() 82 | (block):value_(i); 83 | i = (i):_0m(step) 84 | return i 85 | end )); 86 | return self 87 | end 88 | 89 | function class.timesRepeat_(self,block) 90 | ((1)):to_do_(self,_block( function(i) 91 | return (block):value() 92 | end )); 93 | return self 94 | end 95 | 96 | function class.to_(self,upper) 97 | local range 98 | range = (Array):new_(((upper):_0m(self)):_0p((1))); 99 | (self):to_do_(upper,_block( function(i) 100 | return (range):at_put_(i,i) 101 | end )); 102 | return range; 103 | end 104 | 105 | function class.max_(self,otherInt) 106 | local _nonLocal, _nlRes 107 | local _status, _pcallRes = pcall( function() 108 | ((self):_0l(otherInt)):ifTrue_ifFalse_(_block( function() 109 | _nlRes = otherInt; _nonLocal = true; error(_nlRes) 110 | end ),_block( function() 111 | _nlRes = self; _nonLocal = true; error(_nlRes) 112 | end )); 113 | return self 114 | end ) 115 | if _status then return _pcallRes elseif _nonLocal then return _nlRes else error(_pcallRes) end 116 | end 117 | 118 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/IntegerLoop.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = IntegerLoop 4 | local class = IntegerLoop._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.benchmark(self) 12 | local bounds 13 | local a 14 | bounds = (20000); 15 | ((bounds):negated()):to_by_do_(bounds,(1),_block( function(value) 16 | a = (value):_0m(value) 17 | return a 18 | end )); 19 | return a; 20 | end 21 | 22 | function class.verifyResult_(self,result) 23 | return ((0)):_0q(result); 24 | end 25 | 26 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/List.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = List 4 | local class = List._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.benchmark(self) 12 | local result 13 | result = (self):taklWithX_withY_withZ_((self):makeList_((15)),(self):makeList_((10)),(self):makeList_((6))); 14 | return (result):length(); 15 | end 16 | 17 | function class.verifyResult_(self,result) 18 | return (self):assert_equals_((10),result); 19 | end 20 | 21 | function class.makeList_(self,length) 22 | local _nonLocal, _nlRes 23 | local _status, _pcallRes = pcall( function() 24 | ((length):_0q((0))):ifTrue_ifFalse_(_block( function() 25 | _nlRes = nil; _nonLocal = true; error(_nlRes) 26 | end ),_block( function() 27 | _nlRes = ((ListElement):new_(length)):next_((self):makeList_((length):_0m((1)))); _nonLocal = true; error(_nlRes) 28 | end )); 29 | return self 30 | end ) 31 | if _status then return _pcallRes elseif _nonLocal then return _nlRes else error(_pcallRes) end 32 | end 33 | 34 | function class.isShorter_than_(self,x,y) 35 | local _nonLocal, _nlRes 36 | local _status, _pcallRes = pcall( function() 37 | local xTail 38 | local yTail 39 | xTail = x; 40 | yTail = y; 41 | (_block( function() 42 | return (yTail):isNil() 43 | end )):whileFalse_(_block( function() 44 | ((xTail):isNil()):ifTrue_(_block( function() 45 | _nlRes = true; _nonLocal = true; error(_nlRes) 46 | end )); 47 | xTail = (xTail):next(); 48 | yTail = (yTail):next() 49 | return yTail 50 | end )); 51 | return false; 52 | end ) 53 | if _status then return _pcallRes elseif _nonLocal then return _nlRes else error(_pcallRes) end 54 | end 55 | 56 | function class.taklWithX_withY_withZ_(self,x,y,z) 57 | local _nonLocal, _nlRes 58 | local _status, _pcallRes = pcall( function() 59 | ((self):isShorter_than_(y,x)):ifTrue_ifFalse_(_block( function() 60 | _nlRes = (self):taklWithX_withY_withZ_((self):taklWithX_withY_withZ_((x):next(),y,z),(self):taklWithX_withY_withZ_((y):next(),z,x),(self):taklWithX_withY_withZ_((z):next(),x,y)); _nonLocal = true; error(_nlRes) 61 | end ),_block( function() 62 | _nlRes = z; _nonLocal = true; error(_nlRes) 63 | end )); 64 | return self 65 | end ) 66 | if _status then return _pcallRes elseif _nonLocal then return _nlRes else error(_pcallRes) end 67 | end 68 | 69 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/ListElement.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = ListElement 4 | local class = ListElement._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.length(self) 12 | local _nonLocal, _nlRes 13 | local _status, _pcallRes = pcall( function() 14 | ((self[2]):isNil()):ifTrue_ifFalse_(_block( function() 15 | _nlRes = (1); _nonLocal = true; error(_nlRes) 16 | end ),_block( function() 17 | _nlRes = ((1)):_0p((self[2]):length()); _nonLocal = true; error(_nlRes) 18 | end )); 19 | return self 20 | end ) 21 | if _status then return _pcallRes elseif _nonLocal then return _nlRes else error(_pcallRes) end 22 | end 23 | 24 | function class.val(self) 25 | return self[1]; 26 | end 27 | 28 | function class.val_(self,n) 29 | self[1] = n; 30 | return self 31 | end 32 | 33 | function class.next(self) 34 | return self[2]; 35 | end 36 | 37 | function class.next_(self,element) 38 | self[2] = element; 39 | return self 40 | end 41 | 42 | function metaclass.new_(self,n) 43 | return (self._super.new(self)):val_(n); 44 | end 45 | 46 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Loop.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Loop 4 | local class = Loop._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.singleRun(self) 12 | local sum 13 | sum = (0); 14 | ((1)):to_do_((100),_block( function(j) 15 | sum = (sum):_0p((1)) 16 | return sum 17 | end )); 18 | ((sum):_0q((100))):ifFalse_(_block( function() 19 | return (self):error_(((_str("Wrong result: ")):_0p(sum)):_0p(_str(" should be: 100"))) 20 | end )); 21 | return sum; 22 | end 23 | 24 | function class.benchmark(self) 25 | local sum 26 | sum = (0); 27 | ((1)):to_do_((200),_block( function(i) 28 | sum = (sum):_0p((self):singleRun()) 29 | return sum 30 | end )); 31 | return sum; 32 | end 33 | 34 | function class.verifyResult_(self,result) 35 | return ((20000)):_0q(result); 36 | end 37 | 38 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Metaclass.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Metaclass 4 | local class = Metaclass._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Nil.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Nil 4 | local class = Nil._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.asString(self) 12 | return _str("nil"); 13 | end 14 | 15 | function class.isNil(self) 16 | return true; 17 | end 18 | 19 | function class.notNil(self) 20 | return false; 21 | end 22 | 23 | function class.ifNil_(self,aBlock) 24 | return (aBlock):value(); 25 | end 26 | 27 | function class.ifNotNil_(self,aBlock) 28 | return self; 29 | end 30 | 31 | function class.ifNil_ifNotNil_(self,goBlock,noGoBlock) 32 | return (goBlock):value(); 33 | end 34 | 35 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Object.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Object 4 | local class = Object._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class._0q(self,other) 12 | return (self):_0qq(other); 13 | end 14 | 15 | function class._0lg(self,argument) 16 | return ((self):_0q(argument)):_not(); 17 | end 18 | 19 | function class._0tq(self,other) 20 | return ((self):_0qq(other)):_not(); 21 | end 22 | 23 | function class.isNil(self) 24 | return false; 25 | end 26 | 27 | function class.notNil(self) 28 | return true; 29 | end 30 | 31 | function class.asString(self) 32 | return (_str("instance of ")):_0p((self):class()); 33 | end 34 | 35 | function class._0c(self,element) 36 | return (((Vector):new()):append_(self)):append_(element); 37 | end 38 | 39 | function class.value(self) 40 | return self; 41 | end 42 | 43 | function class.ifNil_(self,aBlock) 44 | return self; 45 | end 46 | 47 | function class.ifNotNil_(self,aBlock) 48 | return (aBlock):value(); 49 | end 50 | 51 | function class.ifNil_ifNotNil_(self,noGoBlock,goBlock) 52 | return (goBlock):value(); 53 | end 54 | 55 | function class.print(self) 56 | ((self):asString()):print(); 57 | return self 58 | end 59 | 60 | function class.println(self) 61 | (self):print(); 62 | (_cl("system")):printNewline(); 63 | return self 64 | end 65 | 66 | function class.error_(self,string) 67 | (_str("")):println(); 68 | ((_str("ERROR: ")):_0p(string)):println(); 69 | (_cl("system")):exit_((1)); 70 | return self 71 | end 72 | 73 | function class.subclassResponsibility(self) 74 | (self):error_(_str("This method is abstract and should be overridden")); 75 | return self 76 | end 77 | 78 | function class.doesNotUnderstand_arguments_(self,selector,arguments) 79 | (self):error_((((_str("Method ")):_0p(selector)):_0p(_str(" not found in class "))):_0p(((self):class()):name())); 80 | return self 81 | end 82 | 83 | function class.escapedBlock_(self,block) 84 | (self):error_(_str("Block has escaped and cannot be executed")); 85 | return self 86 | end 87 | 88 | function class.unknownGlobal_(self,name) 89 | return (_cl("system")):resolve_(name); 90 | end 91 | 92 | function class.respondsTo_(self,aSymbol) 93 | local _nonLocal, _nlRes 94 | local _status, _pcallRes = pcall( function() 95 | (((self):class()):hasMethod_(aSymbol)):ifTrue_ifFalse_(_block( function() 96 | _nlRes = true; _nonLocal = true; error(_nlRes) 97 | end ),_block( function() 98 | local cls 99 | cls = ((self):class()):superclass(); 100 | (_block( function() 101 | return (cls):isNil() 102 | end )):whileFalse_(_block( function() 103 | return ((cls):hasMethod_(aSymbol)):ifTrue_ifFalse_(_block( function() 104 | _nlRes = true; _nonLocal = true; error(_nlRes) 105 | end ),_block( function() 106 | cls = (cls):superclass() 107 | return cls 108 | end )) 109 | end )); 110 | _nlRes = false; _nonLocal = true; error(_nlRes) 111 | end )); 112 | return self 113 | end ) 114 | if _status then return _pcallRes elseif _nonLocal then return _nlRes else error(_pcallRes) end 115 | end 116 | 117 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Permute.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Permute 4 | local class = Permute._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.benchmark(self) 12 | self[1] = (0); 13 | self[2] = (Array):new_((7)); 14 | (self):permute_((6)); 15 | return self[1]; 16 | end 17 | 18 | function class.verifyResult_(self,result) 19 | return (self):assert_equals_((8660),result); 20 | end 21 | 22 | function class.permute_(self,n) 23 | self[1] = (self[1]):_0p((1)); 24 | ((n):_0lg((0))):ifTrue_(_block( function() 25 | (self):permute_((n):_0m((1))); 26 | return (n):downTo_do_((1),_block( function(i) 27 | (self):swap_with_(n,i); 28 | (self):permute_((n):_0m((1))); 29 | return (self):swap_with_(n,i) 30 | end )) 31 | end )); 32 | return self 33 | end 34 | 35 | function class.swap_with_(self,i,j) 36 | local tmp 37 | tmp = (self[2]):at_(i); 38 | (self[2]):at_put_(i,(self[2]):at_(j)); 39 | (self[2]):at_put_(j,tmp); 40 | return self 41 | end 42 | 43 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Queens.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Queens 4 | local class = Queens._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.benchmark(self) 12 | local result 13 | result = true; 14 | ((1)):to_do_((10),_block( function(i) 15 | result = (result):and_((self):queens()) 16 | return result 17 | end )); 18 | return result; 19 | end 20 | 21 | function class.verifyResult_(self,result) 22 | return result; 23 | end 24 | 25 | function class.queens(self) 26 | self[2] = (Array):new_withAll_((8),true); 27 | self[1] = (Array):new_withAll_((16),true); 28 | self[3] = (Array):new_withAll_((16),true); 29 | self[4] = (Array):new_withAll_((8),(-1)); 30 | return (self):placeQueen_((1)); 31 | end 32 | 33 | function class.placeQueen_(self,c) 34 | local _nonLocal, _nlRes 35 | local _status, _pcallRes = pcall( function() 36 | ((1)):to_do_((8),_block( function(r) 37 | return ((self):row_column_(r,c)):ifTrue_(_block( function() 38 | (self[4]):at_put_(r,c); 39 | (self):row_column_put_(r,c,false); 40 | ((c):_0q((8))):ifTrue_(_block( function() 41 | _nlRes = true; _nonLocal = true; error(_nlRes) 42 | end )); 43 | ((self):placeQueen_((c):_0p((1)))):ifTrue_(_block( function() 44 | _nlRes = true; _nonLocal = true; error(_nlRes) 45 | end )); 46 | return (self):row_column_put_(r,c,true) 47 | end )) 48 | end )); 49 | return false; 50 | end ) 51 | if _status then return _pcallRes elseif _nonLocal then return _nlRes else error(_pcallRes) end 52 | end 53 | 54 | function class.row_column_(self,r,c) 55 | return (((self[2]):at_(r)):_0aa((self[1]):at_((c):_0p(r)))):_0aa((self[3]):at_(((c):_0m(r)):_0p((8)))); 56 | end 57 | 58 | function class.row_column_put_(self,r,c,v) 59 | (self[2]):at_put_(r,v); 60 | (self[1]):at_put_((c):_0p(r),v); 61 | (self[3]):at_put_(((c):_0m(r)):_0p((8)),v); 62 | return self 63 | end 64 | 65 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/QuickSort.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = QuickSort 4 | local class = QuickSort._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.sort_(self,array) 12 | (self):sort_low_high_(array,(1),(self):dataSize()); 13 | return array; 14 | end 15 | 16 | function class.sort_low_high_(self,array,low,high) 17 | local pivot 18 | local i 19 | local j 20 | pivot = (array):at_(((low):_0p(high)):_0h((2))); 21 | i = low; 22 | j = high; 23 | (_block( function() 24 | return (i):_0lq(j) 25 | end )):whileTrue_(_block( function() 26 | (_block( function() 27 | return ((array):at_(i)):_0l(pivot) 28 | end )):whileTrue_(_block( function() 29 | i = (i):_0p((1)) 30 | return i 31 | end )); 32 | (_block( function() 33 | return (pivot):_0l((array):at_(j)) 34 | end )):whileTrue_(_block( function() 35 | j = (j):_0m((1)) 36 | return j 37 | end )); 38 | return ((i):_0lq(j)):ifTrue_(_block( function() 39 | local tmp 40 | tmp = (array):at_(i); 41 | (array):at_put_(i,(array):at_(j)); 42 | (array):at_put_(j,tmp); 43 | i = (i):_0p((1)); 44 | j = (j):_0m((1)) 45 | return j 46 | end )) 47 | end )); 48 | ((low):_0l(j)):ifTrue_(_block( function() 49 | return (self):sort_low_high_(array,low,j) 50 | end )); 51 | ((i):_0l(high)):ifTrue_(_block( function() 52 | return (self):sort_low_high_(array,i,high) 53 | end )); 54 | return self 55 | end 56 | 57 | function class.dataSize(self) 58 | return (800); 59 | end 60 | 61 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Random.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Random 4 | local class = Random._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.initialize(self) 12 | self[1] = (74755); 13 | return self 14 | end 15 | 16 | function class.next(self) 17 | self[1] = (((self[1]):_0s((1309))):_0p((13849))):_0a((65535)); 18 | return self[1]; 19 | end 20 | 21 | function class.run(self) 22 | local _nonLocal, _nlRes 23 | local _status, _pcallRes = pcall( function() 24 | local fail 25 | (_str("Testing random number generator ... ")):print(); 26 | fail = _block( function() 27 | (_str("FAILED:")):println(); 28 | _nlRes = nil; _nonLocal = true; error(_nlRes) 29 | end ); 30 | (((self):next()):_0lg((22896))):ifTrue_(fail); 31 | (((self):next()):_0lg((34761))):ifTrue_(fail); 32 | (((self):next()):_0lg((34014))):ifTrue_(fail); 33 | (((self):next()):_0lg((39231))):ifTrue_(fail); 34 | (((self):next()):_0lg((52540))):ifTrue_(fail); 35 | (((self):next()):_0lg((41445))):ifTrue_(fail); 36 | (((self):next()):_0lg((1546))):ifTrue_(fail); 37 | (((self):next()):_0lg((5947))):ifTrue_(fail); 38 | (((self):next()):_0lg((65224))):ifTrue_(fail); 39 | (_str("PASSED")):println(); 40 | return self 41 | end ) 42 | if _status then return _pcallRes elseif _nonLocal then return _nlRes else error(_pcallRes) end 43 | end 44 | 45 | function metaclass.new(self) 46 | return (self._super.new(self)):initialize(); 47 | end 48 | 49 | function metaclass.next(self) 50 | return ((self):random()):next(); 51 | end 52 | 53 | function metaclass.initialize(self) 54 | return ( function()self[1] = (Random):new(); return self[1] end )(); 55 | end 56 | 57 | function metaclass.random(self) 58 | return self[1]; 59 | end 60 | 61 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Recurse.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Recurse 4 | local class = Recurse._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.benchmark(self) 12 | return (self):recurse_((13)); 13 | end 14 | 15 | function class.recurse_(self,n) 16 | ((n):_0g((0))):ifTrue_(_block( function() 17 | (self):recurse_((n):_0m((1))); 18 | return (self):recurse_((n):_0m((1))) 19 | end )); 20 | return n; 21 | end 22 | 23 | function class.verifyResult_(self,result) 24 | return ((13)):_0q(result); 25 | end 26 | 27 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Set.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Set 4 | local class = Set._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class._0q(self,otherSet) 12 | local _nonLocal, _nlRes 13 | local _status, _pcallRes = pcall( function() 14 | (((self):size()):_0q((otherSet):size())):ifFalse_(_block( function() 15 | _nlRes = false; _nonLocal = true; error(_nlRes) 16 | end )); 17 | (self):do_(_block( function(item) 18 | return ((otherSet):contains_(item)):ifFalse_(_block( function() 19 | _nlRes = false; _nonLocal = true; error(_nlRes) 20 | end )) 21 | end )); 22 | return true; 23 | end ) 24 | if _status then return _pcallRes elseif _nonLocal then return _nlRes else error(_pcallRes) end 25 | end 26 | 27 | function class.add_(self,anObject) 28 | ((self):contains_(anObject)):ifFalse_(_block( function() 29 | return (self[1]):append_(anObject) 30 | end )); 31 | return self 32 | end 33 | 34 | function class.addAll_(self,aCollection) 35 | (aCollection):do_(_block( function(each) 36 | return (self):add_(each) 37 | end )); 38 | return self 39 | end 40 | 41 | function class.union_(self,aCollection) 42 | local new 43 | new = (Set):new(); 44 | (new):addAll_(self); 45 | (new):addAll_(aCollection); 46 | return new; 47 | end 48 | 49 | function class.intersection_(self,aCollection) 50 | local new 51 | new = (Set):new(); 52 | (self):do_(_block( function(it) 53 | return ((aCollection):contains_(it)):ifTrue_(_block( function() 54 | return (new):add_(it) 55 | end )) 56 | end )); 57 | return new; 58 | end 59 | 60 | function class._0m(self,aCollection) 61 | local new 62 | new = (Set):new(); 63 | (self):do_(_block( function(it) 64 | return ((aCollection):contains_(it)):ifFalse_(_block( function() 65 | return (new):add_(it) 66 | end )) 67 | end )); 68 | return new; 69 | end 70 | 71 | function class.contains_(self,anObject) 72 | local _nonLocal, _nlRes 73 | local _status, _pcallRes = pcall( function() 74 | (self[1]):do_(_block( function(it) 75 | return ((it):_0qq(anObject)):ifTrue_(_block( function() 76 | _nlRes = true; _nonLocal = true; error(_nlRes) 77 | end )) 78 | end )); 79 | return false; 80 | end ) 81 | if _status then return _pcallRes elseif _nonLocal then return _nlRes else error(_pcallRes) end 82 | end 83 | 84 | function class.remove_(self,anObject) 85 | local newItems 86 | newItems = (Vector):new(); 87 | (_block( function() 88 | return (self[1]):isEmpty() 89 | end )):whileFalse_(_block( function() 90 | local it 91 | it = (self[1]):remove(); 92 | return ((it):_0q(anObject)):ifFalse_(_block( function() 93 | return (newItems):append_(it) 94 | end )) 95 | end )); 96 | self[1] = newItems; 97 | return self 98 | end 99 | 100 | function class.first(self) 101 | return (self[1]):at_((1)); 102 | end 103 | 104 | function class.isEmpty(self) 105 | return (self[1]):isEmpty(); 106 | end 107 | 108 | function class.do_(self,block) 109 | (self[1]):do_(block); 110 | return self 111 | end 112 | 113 | function class.collect_(self,block) 114 | local coll 115 | coll = (Vector):new(); 116 | (self):do_(_block( function(e) 117 | return (coll):append_((block):value_(e)) 118 | end )); 119 | return coll; 120 | end 121 | 122 | function class.println(self) 123 | (_str("(")):print(); 124 | (self):do_(_block( function(it) 125 | (_str("(")):print(); 126 | (it):print(); 127 | return (_str(")")):print() 128 | end )); 129 | (_str(")")):println(); 130 | return self 131 | end 132 | 133 | function class.asString(self) 134 | local result 135 | result = _str("a Set("); 136 | (self[1]):do_(_block( function(e) 137 | result = ((result):_0p((e):asString())):_0p(_str(", ")) 138 | return result 139 | end )); 140 | result = (result):_0p(_str(")")); 141 | return result; 142 | end 143 | 144 | function class.size(self) 145 | return (self[1]):size(); 146 | end 147 | 148 | function class.items_(self,it) 149 | self[1] = it; 150 | return self 151 | end 152 | 153 | function metaclass.new(self) 154 | local newSet 155 | newSet = self._super.new(self); 156 | (newSet):items_((Vector):new()); 157 | return newSet; 158 | end 159 | 160 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Sieve.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Sieve 4 | local class = Sieve._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.benchmark(self) 12 | local flags 13 | flags = (Array):new_((5000)); 14 | return (self):sieve_size_(flags,(5000)); 15 | end 16 | 17 | function class.verifyResult_(self,result) 18 | return (self):assert_equals_((669),result); 19 | end 20 | 21 | function class.sieve_size_(self,flags,size) 22 | local primeCount 23 | primeCount = (0); 24 | (flags):putAll_(true); 25 | ((2)):to_do_(size,_block( function(i) 26 | return ((flags):at_((i):_0m((1)))):ifTrue_(_block( function() 27 | local k 28 | primeCount = (primeCount):_0p((1)); 29 | k = (i):_0p(i); 30 | return (_block( function() 31 | return (k):_0lq(size) 32 | end )):whileTrue_(_block( function() 33 | (flags):at_put_((k):_0m((1)),false); 34 | k = (k):_0p(i) 35 | return k 36 | end )) 37 | end )) 38 | end )); 39 | return primeCount; 40 | end 41 | 42 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Sort.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Sort 4 | local class = Sort._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.benchmark(self) 12 | local array 13 | array = (self):randomArray_((self):dataSize()); 14 | return (self):sort_(array); 15 | end 16 | 17 | function class.dataSize(self) 18 | (self):subclassResponsibility(); 19 | return self 20 | end 21 | 22 | function class.sort_(self,array) 23 | (self):subclassResponsibility(); 24 | return self 25 | end 26 | 27 | function class.verifyResult_(self,array) 28 | ((((array):at_((1))):_0lg(self[1])):_0bb(((array):at_((array):length())):_0lg(self[2]))):ifTrue_(_block( function() 29 | return (self):error_((((((((_str("Array is not sorted. smallest: ")):_0p((self[1]):asString())):_0p(_str(" largest: "))):_0p((self[2]):asString())):_0p(_str(" [1]: "))):_0p(((array):at_((1))):asString())):_0p(_str(" [l]: "))):_0p(((array):at_((array):length())):asString())) 30 | end )); 31 | ((3)):to_do_((array):length(),_block( function(i) 32 | return (((array):at_((i):_0m((1)))):_0g((array):at_(i))):ifTrue_(_block( function() 33 | return (self):error_((((((((_str("Array is not sorted. [")):_0p((i):asString())):_0p(_str(" - 1]: "))):_0p(((array):at_((i):_0m((1)))):asString())):_0p(_str(" ["))):_0p((i):asString())):_0p(_str("]: "))):_0p(((array):at_(i)):asString())) 34 | end )) 35 | end )); 36 | return true; 37 | end 38 | 39 | function class.randomArray_(self,size) 40 | local array 41 | (Random):initialize(); 42 | array = (Array):new_withAll_(size,_block( function() 43 | return (Random):next() 44 | end )); 45 | self[1] = ( function()self[2] = (array):at_((1)); return self[2] end )(); 46 | (array):do_(_block( function(elm) 47 | ((elm):_0g(self[2])):ifTrue_(_block( function() 48 | self[2] = elm 49 | return self[2] 50 | end )); 51 | return ((elm):_0l(self[1])):ifTrue_(_block( function() 52 | self[1] = elm 53 | return self[1] 54 | end )) 55 | end )); 56 | return array; 57 | end 58 | 59 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Storage.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Storage 4 | local class = Storage._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.benchmark(self) 12 | (Random):initialize(); 13 | self[1] = (0); 14 | (self):buildTreeDepth_((7)); 15 | return self[1]; 16 | end 17 | 18 | function class.verifyResult_(self,result) 19 | return (self):assert_equals_((5461),result); 20 | end 21 | 22 | function class.buildTreeDepth_(self,depth) 23 | self[1] = (self[1]):_0p((1)); 24 | return ((depth):_0q((1))):ifTrue_ifFalse_(_block( function() 25 | return (Array):new_((((Random):next()):_0r((10))):_0p((1))) 26 | end ),_block( function() 27 | return (Array):new_withAll_((4),_block( function() 28 | return (self):buildTreeDepth_((depth):_0m((1))) 29 | end )) 30 | end )); 31 | end 32 | 33 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/String.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = String 4 | local class = String._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class._0p(self,argument) 12 | return (self):concatenate_((argument):asString()); 13 | end 14 | 15 | function class.asString(self) 16 | return self; 17 | end 18 | 19 | function class.substringFrom_to_(self,start,_end) 20 | local _nonLocal, _nlRes 21 | local _status, _pcallRes = pcall( function() 22 | ((((_end):_0lq((self):length())):_0aa((start):_0g((0)))):_0aa((start):_0lq(_end))):ifTrue_ifFalse_(_block( function() 23 | _nlRes = (self):primSubstringFrom_to_(start,_end); _nonLocal = true; error(_nlRes) 24 | end ),_block( function() 25 | return (self):error_(((((((_str("Attempting to index string out of its bounds (start: ")):_0p((start):asString())):_0p(_str(" end: "))):_0p((_end):asString())):_0p(_str(" length: "))):_0p(((self):length()):asString())):_0p(_str(")"))) 26 | end )); 27 | return self 28 | end ) 29 | if _status then return _pcallRes elseif _nonLocal then return _nlRes else error(_pcallRes) end 30 | end 31 | 32 | function class.beginsWith_(self,prefix) 33 | local _nonLocal, _nlRes 34 | local _status, _pcallRes = pcall( function() 35 | (((self):length()):_0l((prefix):length())):ifTrue_(_block( function() 36 | _nlRes = false; _nonLocal = true; error(_nlRes) 37 | end )); 38 | ((1)):to_do_((prefix):length(),_block( function(i) 39 | return (((self):charAt_(i)):_0q((prefix):charAt_(i))):ifFalse_(_block( function() 40 | _nlRes = false; _nonLocal = true; error(_nlRes) 41 | end )) 42 | end )); 43 | return true; 44 | end ) 45 | if _status then return _pcallRes elseif _nonLocal then return _nlRes else error(_pcallRes) end 46 | end 47 | 48 | function class.endsWith_(self,suffix) 49 | local _nonLocal, _nlRes 50 | local _status, _pcallRes = pcall( function() 51 | local l 52 | local sufL 53 | l = (self):length(); 54 | sufL = (suffix):length(); 55 | ((l):_0l(sufL)):ifTrue_(_block( function() 56 | _nlRes = false; _nonLocal = true; error(_nlRes) 57 | end )); 58 | ((1)):to_do_(sufL,_block( function(i) 59 | return (((self):charAt_(((l):_0m(sufL)):_0p(i))):_0q((suffix):charAt_(i))):ifFalse_(_block( function() 60 | _nlRes = false; _nonLocal = true; error(_nlRes) 61 | end )) 62 | end )); 63 | return true; 64 | end ) 65 | if _status then return _pcallRes elseif _nonLocal then return _nlRes else error(_pcallRes) end 66 | end 67 | 68 | function class.asInteger(self) 69 | return (Integer):fromString_(self); 70 | end 71 | 72 | function class.charAt_(self,argument) 73 | return (self):substringFrom_to_(argument,argument); 74 | end 75 | 76 | function class.print(self) 77 | (_cl("system")):printString_(self); 78 | return self 79 | end 80 | 81 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Sum.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Sum 4 | local class = Sum._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.benchmark(self) 12 | local result 13 | ((1)):to_do_((2),_block( function(i) 14 | result = (self):sumFrom_to_((1),(10000)) 15 | return result 16 | end )); 17 | return result; 18 | end 19 | 20 | function class.sumFrom_to_(self,start,_end) 21 | local sum 22 | sum = (0); 23 | (start):to_do_(_end,_block( function(i) 24 | sum = (sum):_0p(i) 25 | return sum 26 | end )); 27 | return sum; 28 | end 29 | 30 | function class.verifyResult_(self,result) 31 | return ((50005000)):_0q(result); 32 | end 33 | 34 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Symbol.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Symbol 4 | local class = Symbol._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.asSymbol(self) 12 | return self; 13 | end 14 | 15 | function class.print(self) 16 | (_str("#")):print(); 17 | self._super.print(self); 18 | return self 19 | end 20 | 21 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/System.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = System 4 | local class = System._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.initialize_(self,arguments) 12 | local _nonLocal, _nlRes 13 | local _status, _pcallRes = pcall( function() 14 | local application 15 | (((arguments):length()):_0l((1))):ifTrue_(_block( function() 16 | (_str("No class specified")):println(); 17 | _nlRes = nil; _nonLocal = true; error(_nlRes) 18 | end )); 19 | application = ((self):resolve_(((arguments):at_((1))):asSymbol())):new(); 20 | ((application):respondsTo_(_sym("run_"))):ifTrue_ifFalse_(_block( function() 21 | return (application):run_(arguments) 22 | end ),_block( function() 23 | return (application):run() 24 | end )); 25 | return self 26 | end ) 27 | if _status then return _pcallRes elseif _nonLocal then return _nlRes else error(_pcallRes) end 28 | end 29 | 30 | function class.resolve_(self,symbol) 31 | local _nonLocal, _nlRes 32 | local _status, _pcallRes = pcall( function() 33 | local class 34 | local current_class 35 | (((self):global_(symbol)):_0qq(nil)):ifFalse_(_block( function() 36 | _nlRes = (self):global_(symbol); _nonLocal = true; error(_nlRes) 37 | end )); 38 | class = (self):load_(symbol); 39 | ((class):_0qq(nil)):ifFalse_(_block( function() 40 | current_class = class; 41 | (_block( function() 42 | return ((self):global_((current_class):name())):_0qq(nil) 43 | end )):whileTrue_(_block( function() 44 | (self):global_put_((current_class):name(),current_class); 45 | current_class = (current_class):superclass() 46 | return current_class 47 | end )); 48 | _nlRes = class; _nonLocal = true; error(_nlRes) 49 | end )); 50 | (self):error_((_str("Unable to resolve ")):_0p(symbol)); 51 | return self 52 | end ) 53 | if _status then return _pcallRes elseif _nonLocal then return _nlRes else error(_pcallRes) end 54 | end 55 | 56 | function class.exit(self) 57 | (self):exit_((0)); 58 | return self 59 | end 60 | 61 | function metaclass.new(self) 62 | (self):error_(_str("The system object is singular")); 63 | return self 64 | end 65 | 66 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Towers.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Towers 4 | local class = Towers._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.pushDisk_onPile_(self,disk,pile) 12 | local top 13 | top = (self[1]):at_(pile); 14 | ((((top):isNil()):_not()):_0aa(_block( function() 15 | return ((disk):size()):_0gq((top):size()) 16 | end ))):ifTrue_(_block( function() 17 | return (self):error_(_str("Cannot put a big disk on a smaller one")) 18 | end )); 19 | (disk):next_(top); 20 | (self[1]):at_put_(pile,disk); 21 | return self 22 | end 23 | 24 | function class.popDiskFrom_(self,pile) 25 | local top 26 | top = (self[1]):at_(pile); 27 | ((top):isNil()):ifTrue_(_block( function() 28 | return (self):error_(_str("Attempting to remove a disk from an empty pile")) 29 | end )); 30 | (self[1]):at_put_(pile,(top):next()); 31 | (top):next_(nil); 32 | return top; 33 | end 34 | 35 | function class.moveTopDiskFrom_to_(self,fromPile,toPile) 36 | (self):pushDisk_onPile_((self):popDiskFrom_(fromPile),toPile); 37 | self[2] = (self[2]):_0p((1)); 38 | return self 39 | end 40 | 41 | function class.buildTowerAt_disks_(self,pile,disks) 42 | (disks):downTo_do_((0),_block( function(i) 43 | return (self):pushDisk_onPile_((TowersDisk):new_(i),pile) 44 | end )); 45 | return self 46 | end 47 | 48 | function class.move_disksFrom_to_(self,disks,fromPile,toPile) 49 | ((disks):_0q((1))):ifTrue_ifFalse_(_block( function() 50 | return (self):moveTopDiskFrom_to_(fromPile,toPile) 51 | end ),_block( function() 52 | local otherPile 53 | otherPile = (((6)):_0m(fromPile)):_0m(toPile); 54 | (self):move_disksFrom_to_((disks):_0m((1)),fromPile,otherPile); 55 | (self):moveTopDiskFrom_to_(fromPile,toPile); 56 | return (self):move_disksFrom_to_((disks):_0m((1)),otherPile,toPile) 57 | end )); 58 | return self 59 | end 60 | 61 | function class.benchmark(self) 62 | self[1] = (Array):new_((4)); 63 | (self):buildTowerAt_disks_((1),(13)); 64 | self[2] = (0); 65 | (self):move_disksFrom_to_((13),(1),(2)); 66 | return self[2]; 67 | end 68 | 69 | function class.verifyResult_(self,result) 70 | return (self):assert_equals_((8191),result); 71 | end 72 | 73 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/TowersDisk.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = TowersDisk 4 | local class = TowersDisk._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.size(self) 12 | return self[1]; 13 | end 14 | 15 | function class.size_(self,value) 16 | self[1] = value; 17 | return self 18 | end 19 | 20 | function class.next(self) 21 | return self[2]; 22 | end 23 | 24 | function class.next_(self,value) 25 | self[2] = value; 26 | return self 27 | end 28 | 29 | function metaclass.new_(self,value) 30 | return (self._super.new(self)):size_(value); 31 | end 32 | 33 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/TreeNode.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = TreeNode 4 | local class = TreeNode._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.value(self) 12 | return self[3]; 13 | end 14 | 15 | function class.value_(self,v) 16 | self[3] = v; 17 | return self 18 | end 19 | 20 | function class.check(self) 21 | return (((self[1]):isNil()):_0bb(_block( function() 22 | return (((self[1]):value()):_0l(self[3])):_0aa((self[1]):check()) 23 | end ))):_0aa(((self[2]):isNil()):_0bb(_block( function() 24 | return (((self[2]):value()):_0gq(self[3])):_0aa((self[2]):check()) 25 | end ))); 26 | end 27 | 28 | function class.insert_(self,n) 29 | ((n):_0l(self[3])):ifTrue_ifFalse_(_block( function() 30 | return ((self[1]):isNil()):ifTrue_ifFalse_(_block( function() 31 | self[1] = (TreeNode):new_(n) 32 | return self[1] 33 | end ),_block( function() 34 | return (self[1]):insert_(n) 35 | end )) 36 | end ),_block( function() 37 | return ((self[2]):isNil()):ifTrue_ifFalse_(_block( function() 38 | self[2] = (TreeNode):new_(n) 39 | return self[2] 40 | end ),_block( function() 41 | return (self[2]):insert_(n) 42 | end )) 43 | end )); 44 | return self 45 | end 46 | 47 | function metaclass.new_(self,value) 48 | return (self._super.new(self)):value_(value); 49 | end 50 | 51 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/TreeSort.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = TreeSort 4 | local class = TreeSort._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.sort_(self,array) 12 | local tree 13 | (array):doIndexes_(_block( function(i) 14 | return ((i):_0q((1))):ifTrue_ifFalse_(_block( function() 15 | tree = (TreeNode):new_((array):at_(i)) 16 | return tree 17 | end ),_block( function() 18 | return (tree):insert_((array):at_(i)) 19 | end )) 20 | end )); 21 | return tree; 22 | end 23 | 24 | function class.verifyResult_(self,tree) 25 | ((tree):check()):ifFalse_(_block( function() 26 | return (self):error_(_str("Invalid result, tree not sorted")) 27 | end )); 28 | return true; 29 | end 30 | 31 | function class.dataSize(self) 32 | return (1000); 33 | end 34 | 35 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/True.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = True 4 | local class = True._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.asString(self) 12 | return _str("true"); 13 | end 14 | 15 | function class.ifTrue_(self,block) 16 | return (block):value(); 17 | end 18 | 19 | function class.ifFalse_(self,block) 20 | return nil; 21 | end 22 | 23 | function class._not(self) 24 | return false; 25 | end 26 | 27 | function class.or_(self,block) 28 | return true; 29 | end 30 | 31 | function class.and_(self,block) 32 | return (block):value(); 33 | end 34 | 35 | -------------------------------------------------------------------------------- /Results/Benchmarks_All_SomLjVirtualMachine_generated_Lua/Vector.lua: -------------------------------------------------------------------------------- 1 | -- generated by SomLjVirtualMachine on Sa. Aug. 29 23:05:07 2020 2 | 3 | local metaclass = Vector 4 | local class = Vector._class 5 | local function _block(f) local t = { _f = f }; setmetatable(t,Block._class); return t end 6 | local _str = _primitives._newString 7 | local _sym = _primitives._newSymbol 8 | local _dbl = _primitives._newDouble 9 | local _cl = _primitives._checkLoad 10 | 11 | function class.at_(self,index) 12 | return (self):checkIndex_ifValid_(index,_block( function() 13 | return (self[3]):at_(index) 14 | end )); 15 | end 16 | 17 | function class.at_put_(self,index,value) 18 | return (self):checkIndex_ifValid_(index,_block( function() 19 | return (self[3]):at_put_(index,value) 20 | end )); 21 | end 22 | 23 | function class.first(self) 24 | return (((self):size()):_0g((0))):ifTrue_ifFalse_(_block( function() 25 | return (self[3]):at_((1)) 26 | end ),_block( function() 27 | return nil 28 | end )); 29 | end 30 | 31 | function class.do_(self,block) 32 | (self[1]):to_do_((self[2]):_0m((1)),_block( function(i) 33 | return (block):value_((self[3]):at_(i)) 34 | end )); 35 | return self 36 | end 37 | 38 | function class.doIndexes_(self,block) 39 | (self[1]):to_do_((self[2]):_0m((1)),block); 40 | return self 41 | end 42 | 43 | function class._0c(self,element) 44 | return (self):append_(element); 45 | end 46 | 47 | function class.append_(self,element) 48 | ((self[2]):_0gq((self[3]):length())):ifTrue_(_block( function() 49 | local newStorage 50 | newStorage = (Array):new_(((2)):_0s((self[3]):length())); 51 | (self[3]):doIndexes_(_block( function(i) 52 | return (newStorage):at_put_(i,(self[3]):at_(i)) 53 | end )); 54 | self[3] = newStorage 55 | return self[3] 56 | end )); 57 | (self[3]):at_put_(self[2],element); 58 | self[2] = (self[2]):_0p((1)); 59 | return self; 60 | end 61 | 62 | function class.remove(self) 63 | local _nonLocal, _nlRes 64 | local _status, _pcallRes = pcall( function() 65 | ((self[2]):_0g(self[1])):ifTrue_ifFalse_(_block( function() 66 | self[2] = (self[2]):_0m((1)); 67 | _nlRes = (self[3]):at_(self[2]); _nonLocal = true; error(_nlRes) 68 | end ),_block( function() 69 | return (self):error_(_str("Vector: Attempting to pop element from empty Vector")) 70 | end )); 71 | return self 72 | end ) 73 | if _status then return _pcallRes elseif _nonLocal then return _nlRes else error(_pcallRes) end 74 | end 75 | 76 | function class.remove_(self,object) 77 | local newArray 78 | local newLast 79 | local found 80 | newArray = (Array):new_((self):capacity()); 81 | newLast = (1); 82 | found = false; 83 | (self):do_(_block( function(it) 84 | return ((it):_0qq(object)):ifTrue_ifFalse_(_block( function() 85 | found = true 86 | return found 87 | end ),_block( function() 88 | (newArray):at_put_(newLast,it); 89 | newLast = (newLast):_0p((1)) 90 | return newLast 91 | end )) 92 | end )); 93 | self[3] = newArray; 94 | self[2] = newLast; 95 | self[1] = (1); 96 | return found; 97 | end 98 | 99 | function class.contains_(self,anObject) 100 | return (self[3]):contains_(anObject); 101 | end 102 | 103 | function class.println(self) 104 | (_str("(")):print(); 105 | (self):do_(_block( function(it) 106 | (_str("(")):print(); 107 | (it):print(); 108 | return (_str(")")):print() 109 | end )); 110 | (_str(")")):println(); 111 | return self 112 | end 113 | 114 | function class.isEmpty(self) 115 | return (self[2]):_0q(self[1]); 116 | end 117 | 118 | function class.size(self) 119 | return (self[2]):_0m(self[1]); 120 | end 121 | 122 | function class.capacity(self) 123 | return (self[3]):length(); 124 | end 125 | 126 | function class.asArray(self) 127 | local arr 128 | arr = (Array):new_((self):size()); 129 | (self):doIndexes_(_block( function(i) 130 | return (arr):at_put_(i,(self):at_(i)) 131 | end )); 132 | return arr; 133 | end 134 | 135 | function class.initialize_(self,size) 136 | self[3] = (Array):new_(size); 137 | self[1] = (1); 138 | self[2] = (1); 139 | return self 140 | end 141 | 142 | function class.checkIndex_ifValid_(self,index,block) 143 | return (((self[1]):_0lq(index)):_0aa((index):_0lq(self[2]))):ifTrue_ifFalse_(_block( function() 144 | return (block):value() 145 | end ),_block( function() 146 | return (self):error_(((((((_str("Vector[")):_0p((self[1]):asString())):_0p(_str(".."))):_0p((self[2]):asString())):_0p(_str("]: Index "))):_0p((index):asString())):_0p(_str(" out of bounds"))) 147 | end )); 148 | end 149 | 150 | function class.removeFirst(self) 151 | ((self):isEmpty()):ifTrue_(_block( function() 152 | return (self):error_(_str("OrderedCollection is empty")) 153 | end )); 154 | self[1] = (self[1]):_0p((1)); 155 | return (self[3]):at_((self[1]):_0m((1))); 156 | end 157 | 158 | function class.asSet(self) 159 | return ((Set):new()):addAll_(self); 160 | end 161 | 162 | function metaclass.new(self) 163 | return (self):new_((50)); 164 | end 165 | 166 | function metaclass.new_(self,initialSize) 167 | return (self._super.new(self)):initialize_(initialSize); 168 | end 169 | 170 | function metaclass.with_(self,elem) 171 | local newVector 172 | newVector = (self):new_((1)); 173 | (newVector):append_(elem); 174 | return newVector; 175 | end 176 | 177 | -------------------------------------------------------------------------------- /Results/SOMpp.pro: -------------------------------------------------------------------------------- 1 | 2 | QT -= core 3 | QT -= gui 4 | 5 | TARGET = SOM 6 | TEMPLATE = app 7 | 8 | CONFIG += c++11 9 | 10 | DEFINES += GC_TYPE=MARK_SWEEP 11 | 12 | INCLUDEPATH += src 13 | 14 | HEADERS += \ 15 | src/compiler/BytecodeGenerator.h \ 16 | src/compiler/ClassGenerationContext.h \ 17 | src/compiler/Disassembler.h \ 18 | src/compiler/Lexer.h \ 19 | src/compiler/MethodGenerationContext.h \ 20 | src/compiler/Parser.h \ 21 | src/compiler/SourcecodeCompiler.h \ 22 | src/interpreter/bytecodes.h \ 23 | src/interpreter/Interpreter.h \ 24 | src/memory/CopyingCollector.h \ 25 | src/memory/CopyingHeap.h \ 26 | src/memory/GarbageCollector.h \ 27 | src/memory/GenerationalCollector.h \ 28 | src/memory/GenerationalHeap.h \ 29 | src/memory/Heap.h \ 30 | src/memory/MarkSweepCollector.h \ 31 | src/memory/MarkSweepHeap.h \ 32 | src/misc/debug.h \ 33 | src/misc/defs.h \ 34 | src/misc/ExtendedList.h \ 35 | src/misc/gettimeofday.h \ 36 | src/misc/Timer.h \ 37 | src/primitives/Array.h \ 38 | src/primitives/Block.h \ 39 | src/primitives/Class.h \ 40 | src/primitives/Double.h \ 41 | src/primitives/Integer.h \ 42 | src/primitives/Method.h \ 43 | src/primitives/Object.h \ 44 | src/primitives/Primitive.h \ 45 | src/primitives/String.h \ 46 | src/primitives/Symbol.h \ 47 | src/primitives/System.h \ 48 | src/primitivesCore/PrimitiveContainer.h \ 49 | src/primitivesCore/PrimitiveLoader.h \ 50 | src/primitivesCore/Routine.h \ 51 | src/vm/Shell.h \ 52 | src/vm/Universe.h \ 53 | src/vmobjects/AbstractObject.h \ 54 | src/vmobjects/IntegerBox.h \ 55 | src/vmobjects/ObjectFormats.h \ 56 | src/vmobjects/PrimitiveRoutine.h \ 57 | src/vmobjects/Signature.h \ 58 | src/vmobjects/VMArray.h \ 59 | src/vmobjects/VMBlock.h \ 60 | src/vmobjects/VMClass.h \ 61 | src/vmobjects/VMDouble.h \ 62 | src/vmobjects/VMEvaluationPrimitive.h \ 63 | src/vmobjects/VMFrame.h \ 64 | src/vmobjects/VMInteger.h \ 65 | src/vmobjects/VMInvokable.h \ 66 | src/vmobjects/VMMethod.h \ 67 | src/vmobjects/VMObject.h \ 68 | src/vmobjects/VMObjectBase.h \ 69 | src/vmobjects/VMPrimitive.h \ 70 | src/vmobjects/VMString.h \ 71 | src/vmobjects/VMSymbol.h 72 | 73 | SOURCES += \ 74 | src/compiler/BytecodeGenerator.cpp \ 75 | src/compiler/ClassGenerationContext.cpp \ 76 | src/compiler/Disassembler.cpp \ 77 | src/compiler/Lexer.cpp \ 78 | src/compiler/MethodGenerationContext.cpp \ 79 | src/compiler/Parser.cpp \ 80 | src/compiler/SourcecodeCompiler.cpp \ 81 | src/interpreter/bytecodes.cpp \ 82 | src/interpreter/Interpreter.cpp \ 83 | src/memory/CopyingCollector.cpp \ 84 | src/memory/CopyingHeap.cpp \ 85 | src/memory/GenerationalCollector.cpp \ 86 | src/memory/GenerationalHeap.cpp \ 87 | src/memory/Heap.cpp \ 88 | src/memory/MarkSweepCollector.cpp \ 89 | src/memory/MarkSweepHeap.cpp \ 90 | src/misc/Timer.cpp \ 91 | src/primitives/Array.cpp \ 92 | src/primitives/Block.cpp \ 93 | src/primitives/Class.cpp \ 94 | src/primitives/Double.cpp \ 95 | src/primitives/Integer.cpp \ 96 | src/primitives/Method.cpp \ 97 | src/primitives/Object.cpp \ 98 | src/primitives/Primitive.cpp \ 99 | src/primitives/String.cpp \ 100 | src/primitives/Symbol.cpp \ 101 | src/primitives/System.cpp \ 102 | src/primitivesCore/PrimitiveContainer.cpp \ 103 | src/primitivesCore/PrimitiveLoader.cpp \ 104 | src/vm/Shell.cpp \ 105 | src/vm/Universe.cpp \ 106 | src/vmobjects/AbstractObject.cpp \ 107 | src/vmobjects/IntegerBox.cpp \ 108 | src/vmobjects/Signature.cpp \ 109 | src/vmobjects/VMArray.cpp \ 110 | src/vmobjects/VMBlock.cpp \ 111 | src/vmobjects/VMClass.cpp \ 112 | src/vmobjects/VMDouble.cpp \ 113 | src/vmobjects/VMEvaluationPrimitive.cpp \ 114 | src/vmobjects/VMFrame.cpp \ 115 | src/vmobjects/VMInteger.cpp \ 116 | src/vmobjects/VMInvokable.cpp \ 117 | src/vmobjects/VMMethod.cpp \ 118 | src/vmobjects/VMObject.cpp \ 119 | src/vmobjects/VMPrimitive.cpp \ 120 | src/vmobjects/VMString.cpp \ 121 | src/vmobjects/VMSymbol.cpp \ 122 | src/Main.cpp 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /Results/are-we-fast-yet_crystal_lua_node_som_pharo_i386_results_2020-12-29.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rochus-keller/Som/b7e8f8ccb89bce8daf61a18ea420976c9bfe92c0/Results/are-we-fast-yet_crystal_lua_node_som_pharo_i386_results_2020-12-29.pdf -------------------------------------------------------------------------------- /Results/run_are-we-fast-yet.sh: -------------------------------------------------------------------------------- 1 | SOM=../SOM++ 2 | 3 | Benchmarks=( Richards Json Havlak Bounce List Mandelbrot NBody Permute Queens Sieve Storage Towers ) 4 | Iterations=( 20 20 20 150 150 50 1000 100 100 300 100 100 ) 5 | 6 | for i in "${!Benchmarks[@]}" 7 | do 8 | echo "running" ${Benchmarks[i]} "with" ${Iterations[i]} "iterations" 9 | $SOM -cp .:Core:CD:DeltaBlue:Havlak:Json:NBody:Richards:Smalltalk Harness.som ${Benchmarks[i]} ${Iterations[i]} >> run.log 10 | done 11 | 12 | 13 | -------------------------------------------------------------------------------- /Smalltalk/Array.som: -------------------------------------------------------------------------------- 1 | " 2 | 3 | $Id: Array.som 29 2009-07-31 11:28:44Z michael.haupt $ 4 | 5 | Copyright (c) 2001-2013 see AUTHORS file 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the 'Software'), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | " 25 | 26 | Array = ( 27 | 28 | "Accessing" 29 | at: index = primitive 30 | at: index put: value = primitive 31 | length = primitive 32 | putAll: block = ( self doIndexes: [ :i | 33 | self at: i put: block value ] ) 34 | first = ( ^ self at: 1 ) 35 | last = ( ^ self at: self length ) 36 | 37 | 38 | "Iterating" 39 | do: block = ( self doIndexes: [ :i | 40 | block value: (self at: i) ] ) 41 | doIndexes: block = ( 1 to: self length do: [:i | 42 | block value: i. ] ) 43 | 44 | from: start to: end do: block = ( 45 | start to: end do: [:i | block value: (self at: i) ] ) 46 | 47 | "Copying (inclusively)" 48 | copyFrom: start to: end = ( 49 | | result i | 50 | 51 | result := Array new: end - start + 1. 52 | i := 1. 53 | self from: start to: end do: [ :e | 54 | result at: i put: e. 55 | i := i + 1 ]. 56 | 57 | ^result 58 | ) 59 | 60 | copyFrom: start = ( ^self copyFrom: start to: self length ) 61 | 62 | replaceFrom: start to: stop with: replacement startingAt: repStart = ( 63 | "This destructively replaces elements from start to stop in the 64 | receiver starting at index, repStart, in the sequenceable collection, 65 | replacementCollection. Answer the receiver. No range checks are 66 | performed." 67 | | index repOff | 68 | repOff := repStart - start. 69 | index := start - 1. 70 | [(index := index + 1) <= stop] 71 | whileTrue: [self at: index put: (replacement at: repOff + index)] 72 | ) 73 | 74 | copy = (^self copyFrom: 1) 75 | 76 | "Numerical" 77 | sum = ( ^self inject: 0 into: [ :sub :elem | sub + elem ] ) 78 | average = ( ^self sum / self length ) 79 | 80 | "Containment check" 81 | contains: element = ( self do: [ :e | e = element ifTrue: [ ^true ] ]. 82 | ^false ) 83 | indexOf: element = ( 84 | self doIndexes: [ :i | (self at: i) = element ifTrue: [ ^ i ]]. 85 | ^ nil 86 | ) 87 | 88 | lastIndexOf: element = ( 89 | self length downTo: 1 do: [: i | (self at: i) = element ifTrue: [ ^ i ]]. 90 | ^ nil 91 | ) 92 | 93 | "Collection" 94 | collect: aBlock = ( 95 | | result | 96 | result := Array new: self length. 97 | self doIndexes: [ :i | result at: i put: (aBlock value: (self at: i)) ]. 98 | ^result 99 | ) 100 | 101 | inject: sub into: aBlock = ( | next | 102 | next := sub. 103 | self do: [ :e | next := aBlock value: next with: e ]. 104 | ^next 105 | ) 106 | 107 | reject: aBlock = ( 108 | ^ self select: [:element | (aBlock value: element) == false ] 109 | ) 110 | 111 | select: aBlock = ( 112 | "TODO: fix the hard reference to Vector..." 113 | | newCollection | 114 | newCollection := Vector new: self length. 115 | self do: [:each | (aBlock value: each) 116 | ifTrue: [newCollection append: each]]. 117 | ^ newCollection 118 | ) 119 | 120 | union: aCollection = ( 121 | | new | 122 | new := Set new. 123 | new addAll: self. 124 | new addAll: aCollection. 125 | ^ new 126 | ) 127 | 128 | ---------------------------- 129 | 130 | "Allocation" 131 | new = ( ^self new: 0 ) 132 | new: length = primitive 133 | new: length withAll: block = ( ^((self new: length) putAll: block) ) 134 | 135 | "Convenience" 136 | with: a = ( 137 | | arr | 138 | arr := self new: 1. 139 | arr at: 1 put: a. 140 | ^ arr 141 | ) 142 | 143 | with: a with: b = ( 144 | | arr | 145 | arr := self new: 2. 146 | arr at: 1 put: a. 147 | arr at: 2 put: b. 148 | ^ arr 149 | ) 150 | 151 | with: a with: b with: c = ( 152 | | arr | 153 | arr := self new: 3. 154 | arr at: 1 put: a. 155 | arr at: 2 put: b. 156 | arr at: 3 put: c. 157 | ^ arr 158 | ) 159 | ) 160 | -------------------------------------------------------------------------------- /Smalltalk/Block.som: -------------------------------------------------------------------------------- 1 | " 2 | 3 | $Id: Block.som 27 2009-07-31 11:17:53Z michael.haupt $ 4 | 5 | Copyright (c) 2001-2013 see AUTHORS file 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the 'Software'), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | " 25 | 26 | Block = ( 27 | 28 | "For the creation of Block instances, see Universe_new_block()." 29 | 30 | "Evaluation" 31 | value = primitive 32 | 33 | "Looping" 34 | whileFalse: block = ( 35 | [ self value not ] whileTrue: block 36 | ) 37 | 38 | whileTrue: block = primitive "RK as primitive 39 | ( 40 | self value ifFalse: [ ^nil ]. 41 | block value. 42 | self restart 43 | )" 44 | 45 | "Restarting" 46 | "RK not used: restart = primitive" 47 | 48 | "RK moved here from Block2 and Block3" 49 | value: argument = primitive 50 | value: arg1 with: arg2 = primitive 51 | 52 | ) 53 | -------------------------------------------------------------------------------- /Smalltalk/Block1.som: -------------------------------------------------------------------------------- 1 | " 2 | 3 | $Id: Block1.som 27 2009-07-31 11:17:53Z michael.haupt $ 4 | 5 | Copyright (c) 2001-2013 see AUTHORS file 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the 'Software'), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | " 25 | 26 | Block1 = Block ( 27 | 28 | "For the creation of Block instances, see Universe_new_block()." 29 | 30 | "Evaluating" 31 | value = primitive 32 | 33 | ) 34 | -------------------------------------------------------------------------------- /Smalltalk/Block2.som: -------------------------------------------------------------------------------- 1 | " 2 | 3 | $Id: Block2.som 27 2009-07-31 11:17:53Z michael.haupt $ 4 | 5 | Copyright (c) 2001-2013 see AUTHORS file 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the 'Software'), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | " 25 | 26 | Block2 = Block ( 27 | 28 | "For the creation of Block instances, see Universe_new_block()." 29 | 30 | "Evaluating" 31 | value = ( self value: nil ) 32 | value: argument = primitive 33 | 34 | ) 35 | -------------------------------------------------------------------------------- /Smalltalk/Block3.som: -------------------------------------------------------------------------------- 1 | " 2 | 3 | $Id: Block3.som 27 2009-07-31 11:17:53Z michael.haupt $ 4 | 5 | Copyright (c) 2001-2013 see AUTHORS file 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the 'Software'), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | " 25 | 26 | Block3 = Block ( 27 | 28 | "For the creation of Block instances, see Universe_new_block()." 29 | 30 | "Evaluating" 31 | value = ( self value: nil with: nil ) 32 | value: arg = ( self value: arg with: nil ) 33 | value: arg1 with: arg2 = primitive 34 | 35 | ) 36 | -------------------------------------------------------------------------------- /Smalltalk/Boolean.som: -------------------------------------------------------------------------------- 1 | " 2 | 3 | $Id: Boolean.som 27 2009-07-31 11:17:53Z michael.haupt $ 4 | 5 | Copyright (c) 2001-2013 see AUTHORS file 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the 'Software'), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | " 25 | 26 | Boolean = ( 27 | 28 | "Conditional evaluation" 29 | ifTrue: trueBlock ifFalse: falseBlock = ( 30 | self ifTrue: [ ^trueBlock value ]. 31 | self ifFalse: [ ^falseBlock value ]. 32 | ) 33 | 34 | "Logical operations" 35 | || boolean = ( ^self or: boolean ) 36 | && boolean = ( ^self and: boolean ) 37 | 38 | "RK: implement True and False here because in Lua there is only one class (Boolean) for true/false" 39 | asString = primitive 40 | ifTrue: block = primitive 41 | ifFalse: block = primitive 42 | not = primitive 43 | or: block = primitive 44 | and: block = primitive 45 | ) 46 | 47 | -------------------------------------------------------------------------------- /Smalltalk/Class.som: -------------------------------------------------------------------------------- 1 | " 2 | 3 | $Id: Class.som 27 2009-07-31 11:17:53Z michael.haupt $ 4 | 5 | Copyright (c) 2001-2013 see AUTHORS file 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the 'Software'), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | " 25 | 26 | Class = ( 27 | 28 | "Accessing" 29 | name = primitive 30 | 31 | "Converting" 32 | asString = ( ^self name asString ) 33 | 34 | "Allocation" 35 | new = primitive 36 | 37 | "Meta Information" 38 | superclass = primitive 39 | fields = primitive 40 | methods = primitive 41 | selectors = ( ^self methods collect: [:inv | inv signature ] ) 42 | 43 | hasMethod: aSymbol = ( 44 | self methods do: [ :m | 45 | m signature = aSymbol ifTrue: [ ^true ] ]. 46 | ^false 47 | ) 48 | 49 | ) 50 | -------------------------------------------------------------------------------- /Smalltalk/Dictionary.som: -------------------------------------------------------------------------------- 1 | " 2 | 3 | $Id: Dictionary.som 29 2009-07-31 11:28:44Z michael.haupt $ 4 | 5 | Copyright (c) 2001-2013 see AUTHORS file 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the 'Software'), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | " 25 | 26 | Dictionary = ( 27 | 28 | | pairs | 29 | 30 | at: aKey put: aValue = ( 31 | (self containsKey: aKey) 32 | ifTrue: [ (self pairAt: aKey) value: aValue ] 33 | ifFalse: [ pairs add: (Pair withKey: aKey andValue: aValue) ] 34 | ) 35 | 36 | at: aKey = ( 37 | pairs do: [ :p | p key = aKey ifTrue: [ ^p value ] ]. 38 | ^nil 39 | ) 40 | 41 | containsKey: aKey = ( 42 | pairs do: [ :p | p key = aKey ifTrue: [ ^true ] ]. 43 | ^false 44 | ) 45 | 46 | keys = ( ^pairs collect: [ :p | p key ] ) 47 | values = ( ^pairs collect: [ :p | p value ] ) 48 | 49 | "Iteration" 50 | do: block = ( pairs do: block ) 51 | 52 | "Private" 53 | pairs: aSet = ( pairs := aSet ) 54 | pairAt: aKey = ( 55 | pairs do: [ :p | p key = aKey ifTrue: [ ^p ] ]. 56 | ^nil 57 | ) 58 | 59 | "Printing" 60 | print = ( '{' print. pairs do: [ :p | p print ]. '}' print ) 61 | println = ( self print. '' println ) 62 | 63 | ---- 64 | 65 | new = ( 66 | | newDictionary | 67 | newDictionary := super new. 68 | newDictionary pairs: Set new. 69 | ^newDictionary 70 | ) 71 | 72 | ) 73 | -------------------------------------------------------------------------------- /Smalltalk/Double.som: -------------------------------------------------------------------------------- 1 | " 2 | 3 | $Id: Double.som 27 2009-07-31 11:17:53Z michael.haupt $ 4 | 5 | Copyright (c) 2001-2013 see AUTHORS file 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the 'Software'), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | " 25 | 26 | Double = ( 27 | 28 | "Arithmetic" 29 | + argument = primitive 30 | - argument = primitive 31 | * argument = primitive 32 | // argument = primitive 33 | % argument = primitive 34 | abs = ( ^(self < 0.0) ifTrue: (0.0 - self) ifFalse: self ) 35 | sqrt = primitive 36 | negated = ( ^0.0 - self ) 37 | round = primitive 38 | asInteger = primitive 39 | cos = primitive 40 | sin = primitive 41 | 42 | "Comparing" 43 | = argument = primitive 44 | < argument = primitive 45 | > argument = ( ^(self >= argument) and: [ self <> argument ] ) 46 | >= argument = ( ^(self < argument) not ) 47 | <= argument = ( ^(self < argument) or: [ self = argument ] ) 48 | negative = ( ^self < 0.0 ) 49 | between: a and: b = ( ^(self > a) and: [ self < b ] ) 50 | 51 | "Converting" 52 | asString = primitive 53 | 54 | "Iterating" 55 | to: limit do: block = ( 56 | | i | 57 | i := self. 58 | [ i <= limit ] whileTrue: [ block value: i. i := i + 1.0 ] 59 | ) 60 | 61 | downTo: limit do: block = ( 62 | | i | 63 | i := self. 64 | [ i >= limit ] whileTrue: [ block value: i. i := i - 1.0 ] 65 | ) 66 | 67 | ---- 68 | 69 | PositiveInfinity = primitive 70 | ) 71 | -------------------------------------------------------------------------------- /Smalltalk/False.som: -------------------------------------------------------------------------------- 1 | " 2 | 3 | $Id: False.som 27 2009-07-31 11:17:53Z michael.haupt $ 4 | 5 | Copyright (c) 2001-2013 see AUTHORS file 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the 'Software'), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | " 25 | 26 | False = Boolean ( 27 | 28 | "Converting" 29 | asString = ( ^'false' ) 30 | 31 | "Conditional evaluation" 32 | ifTrue: block = ( ^nil ) 33 | ifFalse: block = ( ^block value ) 34 | 35 | "Logical operations" 36 | not = ( ^true ) 37 | or: block = ( ^block value ) 38 | and: block = ( ^false ) 39 | 40 | ) 41 | -------------------------------------------------------------------------------- /Smalltalk/HashEntry.som: -------------------------------------------------------------------------------- 1 | " 2 | 3 | $Id: HashEntry.som 27 2009-07-31 11:17:53Z michael.haupt $ 4 | 5 | Copyright (c) 2001-2013 see AUTHORS file 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the 'Software'), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | " 25 | 26 | " 27 | This class is not meant for direct use - it's an internal datastructure 28 | for Hashtable 29 | " 30 | 31 | HashEntry = ( 32 | 33 | | key value next hash | 34 | 35 | key = ( ^key ) 36 | value = ( ^value ) 37 | next = ( ^next ) 38 | hash = ( ^hash ) 39 | 40 | key: k = ( key := k ) 41 | value: v = ( value := v ) 42 | next: n = ( next := n ) 43 | hash: h = ( hash := h ) 44 | 45 | setKey: key value: value = ( 46 | key = self key 47 | ifTrue: [ self value: value. ^false. ] 48 | ifFalse: [ 49 | next isNil 50 | ifTrue: [ 51 | self next: (HashEntry newKey: key value: value next: nil). 52 | ^true. ] 53 | ifFalse: [ 54 | ^(self next setKey: key value: value) ] ]. 55 | ) 56 | 57 | getValue: key = ( 58 | key = self key ifTrue: [ ^value ]. 59 | next isNil ifTrue: [ ^nil ]. 60 | ^next getValue: key. 61 | ) 62 | 63 | containsKey: key = ( 64 | key = self key ifTrue: [ ^true ]. 65 | next isNil ifTrue: [ ^false ]. 66 | ^next containsKey: key. 67 | ) 68 | 69 | containsValue: value = ( 70 | value = self value ifTrue: [ ^true ]. 71 | next isNil ifTrue: [ ^false ]. 72 | ^next containsValue: value. 73 | ) 74 | 75 | keys = ( 76 | next isNil 77 | ifTrue: [ ^Vector new append: key ] 78 | ifFalse: [ ^(next keys), key ] 79 | ) 80 | 81 | values = ( 82 | next isNil 83 | ifTrue: [ ^Vector new append: value ] 84 | ifFalse: [ ^(next values), value ] 85 | ) 86 | 87 | ---- 88 | 89 | newKey: k value: v next: n = ( 90 | | newEntry | 91 | newEntry := super new. 92 | newEntry key: k. 93 | newEntry value: v. 94 | newEntry next: n. 95 | newEntry hash: (k hashcode). 96 | ^newEntry 97 | ) 98 | 99 | ) 100 | -------------------------------------------------------------------------------- /Smalltalk/Hashtable.som: -------------------------------------------------------------------------------- 1 | " 2 | 3 | $Id: Hashtable.som 29 2009-07-31 11:28:44Z michael.haupt $ 4 | 5 | Copyright (c) 2001-2013 see AUTHORS file 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the 'Software'), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | " 25 | 26 | Hashtable = ( 27 | 28 | | table count | 29 | 30 | "Testing" 31 | containsKey: key = ( | idx e | 32 | idx := self indexForKey: key. 33 | e := table at: idx. 34 | e isNil ifFalse: [ e keys do: [ :k | k = key ifTrue: [ ^true ] ] ]. 35 | ^false. 36 | ) 37 | 38 | containsValue: val = ( 39 | table do: [ :ent | 40 | ent isNil ifFalse: [ 41 | ent values do: [ :v | v = val ifTrue: [ ^true ] ] ] ]. 42 | ^false. 43 | ) 44 | 45 | isEmpty = ( ^count = 0 ) 46 | size = ( ^count ) 47 | 48 | "Accessing" 49 | get: key = ( | idx e | 50 | idx := self indexForKey: key. 51 | e := table at: idx. 52 | e isNil ifTrue: [ ^nil ]. 53 | ^e getValue: key. 54 | ) 55 | 56 | at: key put: value = ( | idx | 57 | idx := self indexForKey: key. 58 | (table at: idx) isNil 59 | ifTrue: [ 60 | table at: idx put: 61 | (HashEntry newKey: key value: value next: nil). 62 | count := count + 1 ] 63 | ifFalse: [ 64 | ((table at: idx) setKey: key value: value) 65 | ifTrue: [ count := count + 1 ] ]. 66 | "TODO: enlarge table, rehash if too large" 67 | ) 68 | 69 | "TODO: some way to delete keys'd be nice..." 70 | 71 | "Enumerate" 72 | keys = ( | vec | 73 | vec := Vector new. 74 | table do: [ :ent | 75 | ent isNil ifFalse: [ ent keys do: [ :k | vec append: k ] ] ]. 76 | ^vec. 77 | ) 78 | 79 | values = ( | vec | 80 | vec := Vector new. 81 | table do: [ :ent | 82 | ent isNil ifFalse: [ ent values do: [ :v | vec append: v ] ] ]. 83 | ^vec. 84 | ) 85 | 86 | "Clearing" 87 | clear = ( table := Array new: 11. 88 | count := 0 ) 89 | 90 | "Private" 91 | indexForKey: aKey = ( ^(aKey hashcode % table length) abs + 1 ) 92 | 93 | ---------------- 94 | 95 | "Allocation" 96 | new = ( | ht | 97 | ht := super new. 98 | ht clear. 99 | ^ht. 100 | ) 101 | 102 | ) 103 | -------------------------------------------------------------------------------- /Smalltalk/Integer.som: -------------------------------------------------------------------------------- 1 | " 2 | 3 | $Id: Integer.som 29 2009-07-31 11:28:44Z michael.haupt $ 4 | 5 | Copyright (c) 2001-2013 see AUTHORS file 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the 'Software'), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | " 25 | 26 | Integer = ( 27 | 28 | "Arithmetic" 29 | + argument = primitive 30 | - argument = primitive 31 | * argument = primitive 32 | / argument = primitive 33 | // argument = primitive 34 | % argument = primitive "modulo with sign of divisor" 35 | rem: argument=primitive "modulo with sign of dividend" 36 | & argument = primitive 37 | << argument = primitive 38 | >>> argument= primitive 39 | bitXor: argument = primitive 40 | abs = ( ^(self < 0) ifTrue: (0 - self) ifFalse: self ) 41 | sqrt = primitive 42 | negated = ( ^0 - self ) 43 | 44 | "Random numbers" 45 | atRandom = primitive 46 | 47 | "Comparing" 48 | = argument = primitive 49 | ~= argument = (^ (self = argument) not ) 50 | < argument = primitive 51 | > argument = ( ^(self >= argument) and: [ self <> argument ] ) 52 | >= argument = ( ^(self < argument) not ) 53 | <= argument = ( ^(self < argument) or: [ self = argument ] ) 54 | negative = ( ^self < 0 ) 55 | between: a and: b = ( ^(self > a) and: [ self < b ] ) 56 | 57 | "Converting" 58 | asString = primitive 59 | as32BitSignedValue = primitive " returns an int, with the value that a signed 32-bit integer would have" 60 | as32BitUnsignedValue = primitive " returns an int, with the value that a unsigned 32-bit integer would have" 61 | hashcode = ( ^self ) 62 | 63 | "Iterating" 64 | to: limit do: block = ( 65 | self to: limit by: 1 do: block 66 | ) 67 | 68 | to: limit by: step do: block = ( 69 | | i | 70 | i := self. 71 | [ i <= limit ] whileTrue: [ block value: i. i := i + step ] 72 | ) 73 | 74 | downTo: limit do: block = ( 75 | self downTo: limit by: 1 do: block 76 | ) 77 | 78 | downTo: limit by: step do: block = ( 79 | | i | 80 | i := self. 81 | [ i >= limit ] whileTrue: [ block value: i. i := i - step ] 82 | ) 83 | 84 | "More Iterations" 85 | timesRepeat: block = ( 86 | 1 to: self do: [ :i | block value ] 87 | ) 88 | 89 | "Range Creation" 90 | to: upper = ( 91 | | range | 92 | range := Array new: upper - self + 1. 93 | self to: upper do: [ :i | range at: i put: i ]. 94 | ^range 95 | ) 96 | 97 | max: otherInt = ( 98 | (self < otherInt) ifTrue: [^otherInt] ifFalse: [^self]. 99 | ) 100 | 101 | ---- 102 | 103 | fromString: aString = primitive 104 | 105 | ) 106 | -------------------------------------------------------------------------------- /Smalltalk/Metaclass.som: -------------------------------------------------------------------------------- 1 | " 2 | 3 | $Id: Metaclass.som 27 2009-07-31 11:17:53Z michael.haupt $ 4 | 5 | Copyright (c) 2001-2013 see AUTHORS file 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the 'Software'), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | " 25 | 26 | Metaclass = Class ( ) 27 | -------------------------------------------------------------------------------- /Smalltalk/Method.som: -------------------------------------------------------------------------------- 1 | " 2 | 3 | $Id: Method.som 30 2009-07-31 12:20:25Z michael.haupt $ 4 | 5 | Copyright (c) 2001-2013 see AUTHORS file 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the 'Software'), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | " 25 | 26 | Method = ( 27 | 28 | "Meta Information" 29 | signature = primitive 30 | holder = primitive 31 | 32 | "Printing" 33 | asString = ( ^self holder asString + '>>' + self signature asString ) 34 | 35 | invokeOn: obj with: args = primitive 36 | 37 | ) 38 | -------------------------------------------------------------------------------- /Smalltalk/Nil.som: -------------------------------------------------------------------------------- 1 | " 2 | 3 | $Id: Nil.som 27 2009-07-31 11:17:53Z michael.haupt $ 4 | 5 | Copyright (c) 2001-2013 see AUTHORS file 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the 'Software'), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | " 25 | 26 | Nil = ( 27 | 28 | "Converting" 29 | asString = ( ^'nil' ) 30 | 31 | "Comparing" 32 | isNil = ( ^true ) 33 | notNil = ( ^false ) 34 | 35 | "Convenience" 36 | ifNil: aBlock = (^aBlock value) 37 | ifNotNil: aBlock = (^self) 38 | ifNil: goBlock ifNotNil: noGoBlock = (^goBlock value) 39 | 40 | ) 41 | -------------------------------------------------------------------------------- /Smalltalk/Object.som: -------------------------------------------------------------------------------- 1 | " 2 | 3 | $Id: Object.som 27 2009-07-31 11:17:53Z michael.haupt $ 4 | 5 | Copyright (c) 2001-2013 see AUTHORS file 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the 'Software'), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | " 25 | 26 | Object = nil ( 27 | class = primitive 28 | objectSize = primitive "size in bytes" 29 | 30 | "Comparing" 31 | 32 | " If you override =, you MUST override hashcode as well. The rule 33 | obj1 = obj2 => obj1 hashcode = obj2 hashcode 34 | must be valid for all objects, or Hashtable will not work" 35 | = other = ( ^self == other ) 36 | <> argument = ( ^(self = argument) not ) 37 | == other = primitive 38 | ~= other = (^ (self == other) not ) 39 | isNil = ( ^false ) 40 | notNil = ( ^true ) 41 | 42 | "Converting" 43 | asString = ( ^'instance of ' + (self class) ) 44 | , element = ( ^(Vector new append: self) append: element ) 45 | hashcode = primitive 46 | 47 | "Evaluating" 48 | value = ( ^self ) 49 | 50 | "Convenience" 51 | ifNil: aBlock = (^self) 52 | ifNotNil: aBlock = (^aBlock value) 53 | ifNil: noGoBlock ifNotNil: goBlock = (^goBlock value) 54 | 55 | "Printing" 56 | print = ( self asString print ) 57 | println = ( self print. system printNewline ) 58 | 59 | "Debugging" 60 | inspect = primitive 61 | halt = primitive 62 | 63 | "Error handling" 64 | error: string = ( '' println. ('ERROR: ' + string) println. system exit: 1 ) 65 | 66 | "Abstract method support" 67 | subclassResponsibility = ( 68 | self error: 'This method is abstract and should be overridden' 69 | ) 70 | 71 | "Error recovering" 72 | doesNotUnderstand: selector arguments: arguments = ( 73 | self error: 74 | ('Method ' + selector + ' not found in class ' + self class name) 75 | ) 76 | 77 | escapedBlock: block = ( 78 | self error: 'Block has escaped and cannot be executed' 79 | ) 80 | 81 | unknownGlobal: name = ( ^system resolve: name ) 82 | 83 | "Reflection" 84 | respondsTo: aSymbol = ( 85 | (self class hasMethod: aSymbol) 86 | ifTrue: [ ^true ] 87 | ifFalse: [ | cls | 88 | cls := self class superclass. 89 | [ cls isNil ] whileFalse: [ 90 | (cls hasMethod: aSymbol) 91 | ifTrue: [ ^true ] 92 | ifFalse: [ cls := cls superclass ] ]. 93 | ^ false ] 94 | ) 95 | 96 | perform: aSymbol = primitive 97 | perform: aSymbol withArguments: args = primitive 98 | 99 | perform: aSymbol inSuperclass: cls = primitive 100 | perform: aSymbol withArguments: args inSuperclass: cls = primitive 101 | 102 | instVarAt: idx = primitive 103 | instVarAt: idx put: obj = primitive 104 | instVarNamed: sym = primitive 105 | 106 | ) 107 | -------------------------------------------------------------------------------- /Smalltalk/Pair.som: -------------------------------------------------------------------------------- 1 | " 2 | 3 | $Id: Pair.som 27 2009-07-31 11:17:53Z michael.haupt $ 4 | 5 | Copyright (c) 2001-2013 see AUTHORS file 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the 'Software'), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | " 25 | 26 | Pair = ( 27 | 28 | | key value | 29 | 30 | key = ( ^key ) 31 | value = ( ^value ) 32 | 33 | "Private" 34 | key: aKey = ( key := aKey ) 35 | value: aValue = ( value := aValue ) 36 | 37 | "Printing" 38 | print = ( '[' print. key print. '=>' print. value print. ']' print ) 39 | println = ( self print. '' println ) 40 | 41 | ---- 42 | 43 | withKey: aKey andValue: aValue = ( 44 | | newPair | 45 | newPair := super new. 46 | newPair key: aKey. 47 | newPair value: aValue. 48 | ^newPair 49 | ) 50 | 51 | ) 52 | -------------------------------------------------------------------------------- /Smalltalk/Primitive.som: -------------------------------------------------------------------------------- 1 | " 2 | 3 | $Id: Primitive.som 27 2009-07-31 11:17:53Z michael.haupt $ 4 | 5 | Copyright (c) 2001-2013 see AUTHORS file 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the 'Software'), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | " 25 | 26 | Primitive = ( 27 | 28 | signature = primitive 29 | holder = primitive 30 | 31 | invokeOn: obj with: args = primitive 32 | 33 | ) 34 | -------------------------------------------------------------------------------- /Smalltalk/Set.som: -------------------------------------------------------------------------------- 1 | " 2 | 3 | $Id: Set.som 29 2009-07-31 11:28:44Z michael.haupt $ 4 | 5 | Copyright (c) 2001-2013 see AUTHORS file 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the 'Software'), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | " 25 | 26 | Set = ( 27 | 28 | | items | 29 | 30 | = otherSet = ( 31 | self size = otherSet size ifFalse: [^ false ]. 32 | 33 | self do: [:item | (otherSet contains: item) ifFalse: [^ false]. ]. 34 | 35 | ^ true. 36 | ) 37 | 38 | add: anObject = ( 39 | (self contains: anObject) 40 | ifFalse: [ items append: anObject ] 41 | ) 42 | 43 | addAll: aCollection = ( 44 | aCollection do: [:each | 45 | self add: each] 46 | ) 47 | 48 | union: aCollection = ( 49 | | new | 50 | new := Set new. 51 | new addAll: self. 52 | new addAll: aCollection. 53 | ^ new 54 | ) 55 | 56 | intersection: aCollection = ( 57 | | new | 58 | new := Set new. 59 | self do: [:it | 60 | (aCollection contains: it) ifTrue: [ new add: it ]]. 61 | ^ new 62 | ) 63 | 64 | - aCollection = ( "set difference" 65 | | new | 66 | new := Set new. 67 | self do: [:it | 68 | (aCollection contains: it) ifFalse: [ new add: it ]]. 69 | ^ new 70 | ) 71 | 72 | contains: anObject = ( 73 | items do: [ :it | it == anObject ifTrue: [ ^true ] ]. 74 | ^false 75 | ) 76 | 77 | remove: anObject = ( 78 | | newItems | 79 | newItems := Vector new. 80 | [ items isEmpty ] 81 | whileFalse: [ | it | 82 | it := items remove. 83 | it = anObject ifFalse: [ newItems append: it ] ]. 84 | items := newItems 85 | ) 86 | 87 | "Sets do not have the notion of ordering, but 88 | for convenience we provide those accessors" 89 | first = ( 90 | ^items at: 1 91 | ) 92 | 93 | isEmpty = ( 94 | ^items isEmpty 95 | ) 96 | 97 | "Iteration" 98 | do: block = ( items do: block ) 99 | 100 | "Collection" 101 | collect: block = ( | coll | 102 | coll := Vector new. 103 | self do: [ :e | coll append: (block value: e) ]. 104 | ^coll 105 | ) 106 | 107 | "Printing" 108 | println = ( 109 | '(' print. 110 | self do: [ :it | '(' print. it print. ')' print ]. 111 | ')' println 112 | ) 113 | 114 | asString = ( 115 | | result | 116 | result := 'a Set('. 117 | items do: [:e | result := result + e asString + ', ']. 118 | result := result + ')'. 119 | ^ result 120 | ) 121 | 122 | size = ( 123 | ^ items size 124 | ) 125 | 126 | "Private" 127 | items: it = ( items := it ) 128 | 129 | ---- 130 | 131 | new = ( 132 | | newSet | 133 | newSet := super new. 134 | newSet items: Vector new. 135 | ^newSet 136 | ) 137 | 138 | ) 139 | -------------------------------------------------------------------------------- /Smalltalk/Source.txt: -------------------------------------------------------------------------------- 1 | Downloaded from https://github.com/SOM-st/SOM on 2020-08-08. 2 | Commit 47805b6 3 | -------------------------------------------------------------------------------- /Smalltalk/String.som: -------------------------------------------------------------------------------- 1 | " 2 | 3 | $Id: String.som 29 2009-07-31 11:28:44Z michael.haupt $ 4 | 5 | Copyright (c) 2001-2013 see AUTHORS file 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the 'Software'), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | " 25 | 26 | String = ( 27 | "Strings are immutable" 28 | 29 | "Concatenate: returns a new string object" 30 | concatenate: argument = primitive 31 | + argument = ( ^self concatenate: argument asString ) 32 | 33 | "Converting" 34 | asString = ( ^self ) 35 | asSymbol = primitive 36 | hashcode = primitive 37 | 38 | "Info" 39 | length = primitive 40 | 41 | "Returns true if all characters in the string are whitespace. 42 | False otherwise, including for the empty string." 43 | isWhiteSpace = primitive 44 | 45 | "Returns true if all characters in the string are letters. 46 | False otherwise, including for the empty string." 47 | isLetters = primitive 48 | 49 | "Returns true if all characters in the string are digits. 50 | False otherwise, including for the empty string." 51 | isDigits = primitive 52 | 53 | "Comparing" 54 | = argument = primitive 55 | 56 | "substring: from 'start' to (and including) 'end'." 57 | primSubstringFrom: start to: end = primitive 58 | 59 | substringFrom: start to: end = ( 60 | ((end <= self length) && (start > 0) && (start <= end)) 61 | ifTrue: [^self primSubstringFrom: start to: end] 62 | ifFalse: [ 63 | self error: 'Attempting to index string out of its bounds (start: ' + start asString + ' end: ' + end asString + ' length: ' + self length asString + ')' ] 64 | ) 65 | 66 | beginsWith: prefix = ( 67 | self length < prefix length ifTrue: [ ^ false ]. 68 | 69 | 1 to: prefix length do: [:i | 70 | ((self charAt: i) = (prefix charAt: i)) ifFalse: [ ^ false ]. 71 | ]. 72 | 73 | ^ true 74 | ) 75 | 76 | endsWith: suffix = ( 77 | | l sufL | 78 | l := self length. 79 | sufL := suffix length. 80 | l < sufL ifTrue: [ ^ false ]. 81 | 82 | 1 to: sufL do: [:i | 83 | (self charAt: l - sufL + i) = (suffix charAt: i) ifFalse: [ ^ false ] 84 | ]. 85 | ^ true 86 | ) 87 | 88 | asInteger = ( 89 | ^ Integer fromString: self 90 | ) 91 | 92 | charAt: argument = ( 93 | ^self substringFrom: argument to: argument 94 | ) 95 | 96 | "Printing" 97 | print = ( system printString: self ) 98 | 99 | ) 100 | -------------------------------------------------------------------------------- /Smalltalk/Symbol.som: -------------------------------------------------------------------------------- 1 | " 2 | 3 | $Id: Symbol.som 27 2009-07-31 11:17:53Z michael.haupt $ 4 | 5 | Copyright (c) 2001-2013 see AUTHORS file 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the 'Software'), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | " 25 | 26 | Symbol = String ( 27 | 28 | "Converting" 29 | asString = primitive 30 | asSymbol = ( ^self ) 31 | 32 | "Printing" 33 | print = ( '#' print. super print ) 34 | 35 | ) 36 | -------------------------------------------------------------------------------- /Smalltalk/System.som: -------------------------------------------------------------------------------- 1 | " 2 | 3 | $Id: System.som 29 2009-07-31 11:28:44Z michael.haupt $ 4 | 5 | Copyright (c) 2001-2013 see AUTHORS file 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the 'Software'), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | " 25 | 26 | System = ( 27 | 28 | "Accessing" 29 | global: name = primitive 30 | global: name put: value = primitive 31 | hasGlobal: name = primitive 32 | 33 | "Initializing" 34 | initialize: arguments = ( 35 | | application | 36 | 37 | "Make sure we have got at least one argument" 38 | (arguments length < 1) ifTrue: [ 'No class specified' println. ^nil ]. 39 | 40 | "Load the class with the specified name, create an instance of it, and 41 | run it. If there is more than only the class given on the command line, 42 | and the class has a method #run:, the arguments array is passed to it, 43 | otherwise, #run is sent." 44 | application := (self resolve: (arguments at: 1) asSymbol) new. 45 | 46 | (application respondsTo: #run:) 47 | ifTrue: [ application run: arguments ] 48 | ifFalse: [ application run ] 49 | ) 50 | 51 | "Loading and resolving" 52 | load: symbol = primitive 53 | resolve: symbol = ( 54 | | class current_class | 55 | 56 | "Check if we've already got the global" 57 | (self global: symbol) == nil ifFalse: [ ^self global: symbol ]. 58 | 59 | "Try loading the class" 60 | class := self load: symbol. 61 | (class == nil) ifFalse: [ 62 | "Put class and its super-classes into global dictionary. We can stop 63 | as soon as we find a super-class in the globals dictionary because 64 | in this case, all its super-classes must have been added to the 65 | dictionary earlier" 66 | current_class := class. 67 | [ (self global: (current_class name)) == nil ] whileTrue: [ 68 | self global: (current_class name) put: current_class. 69 | current_class := current_class superclass. ]. 70 | ^class ]. 71 | self error: 'Unable to resolve ' + symbol 72 | ) 73 | 74 | "Exiting" 75 | exit: error = primitive 76 | exit = ( self exit: 0 ) 77 | 78 | "Printing" 79 | printString: string = primitive 80 | printNewline = primitive 81 | 82 | "Time" 83 | time = primitive 84 | ticks = primitive "returns the microseconds since start" 85 | 86 | "Force Garbage Collection" 87 | fullGC = primitive 88 | 89 | TRAP = primitive "RK addition" 90 | 91 | ---------------------------------- 92 | 93 | "Allocation" 94 | new = ( self error: 'The system object is singular' ) 95 | 96 | ) 97 | -------------------------------------------------------------------------------- /Smalltalk/True.som: -------------------------------------------------------------------------------- 1 | " 2 | 3 | $Id: True.som 27 2009-07-31 11:17:53Z michael.haupt $ 4 | 5 | Copyright (c) 2001-2013 see AUTHORS file 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the 'Software'), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | " 25 | 26 | True = Boolean ( 27 | 28 | "Converting" 29 | asString = ( ^'true' ) 30 | 31 | "Conditional evaluation" 32 | ifTrue: block = ( ^block value ) 33 | ifFalse: block = ( ^nil ) 34 | 35 | "Logical operations" 36 | not = ( ^false ) 37 | or: block = ( ^true ) 38 | and: block = ( ^block value ) 39 | 40 | ) 41 | -------------------------------------------------------------------------------- /Smalltalk/Vector.som: -------------------------------------------------------------------------------- 1 | " 2 | 3 | $Id: Vector.som 29 2009-07-31 11:28:44Z michael.haupt $ 4 | 5 | Copyright (c) 2001-2013 see AUTHORS file 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the 'Software'), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | " 25 | 26 | "FIXME: Implement pushFront and popFront..." 27 | 28 | Vector = ( 29 | 30 | | first last storage | 31 | 32 | "Accessing" 33 | at: index = ( ^ self checkIndex: index ifValid: [ storage at: index ] ) 34 | 35 | at: index put: value = ( 36 | ^ self checkIndex: index ifValid: [ storage at: index put: value ] 37 | ) 38 | 39 | first = ( ^ (self size > 0) ifTrue: [storage at: 1] ifFalse: [nil] ) 40 | 41 | "Iterating" 42 | do: block = ( 43 | first to: last - 1 do: [ :i | block value: (storage at: i) ] 44 | ) 45 | 46 | doIndexes: block = ( 47 | first to: last - 1 do: block 48 | ) 49 | 50 | "Adding" 51 | , element = ( ^self append: element ) 52 | 53 | append: element = ( 54 | (last >= storage length) ifTrue: [ 55 | "Need to expand capacity first" 56 | | newStorage | 57 | newStorage := Array new: (2 * storage length). 58 | storage doIndexes: [ :i | newStorage at: i put: (storage at: i) ]. 59 | storage := newStorage. ]. 60 | 61 | storage at: last put: element. 62 | last := last + 1. 63 | ^self 64 | ) 65 | 66 | "Removing" 67 | remove = ( 68 | (last > first) 69 | ifTrue: [ last := last - 1. ^storage at: last ] 70 | ifFalse: [ 71 | self error: 72 | 'Vector: Attempting to pop element from empty Vector' ] 73 | ) 74 | 75 | remove: object = ( 76 | | newArray newLast found | 77 | newArray := Array new: self capacity. 78 | newLast := 1. 79 | found := false. 80 | 81 | self do: [ :it | 82 | (it == object) 83 | ifTrue: [ found := true ] 84 | ifFalse: [ 85 | newArray at: newLast put: it. 86 | newLast := newLast + 1. 87 | ] 88 | ]. 89 | 90 | storage := newArray. 91 | last := newLast. 92 | first := 1. 93 | ^found 94 | ) 95 | 96 | contains: anObject = ( 97 | ^ storage contains: anObject 98 | ) 99 | 100 | "Printing" 101 | println = ( 102 | '(' print. 103 | self do: [ :it | '(' print. it print. ')' print ]. 104 | ')' println 105 | ) 106 | 107 | "Sizing" 108 | isEmpty = ( ^last = first ) 109 | size = ( ^last - first ) 110 | capacity = ( ^storage length ) 111 | 112 | "Conversion" 113 | asArray = ( | arr | 114 | arr := Array new: self size. 115 | self doIndexes: [ :i | arr at: i put: (self at: i) ]. 116 | ^arr 117 | ) 118 | 119 | "Private" 120 | initialize: size = ( 121 | storage := Array new: size. 122 | first := 1. 123 | last := 1. 124 | ) 125 | 126 | checkIndex: index ifValid: block = ( 127 | ^ ((first <= index) && (index <= last) 128 | ifTrue: [ block value ] 129 | ifFalse: [ 130 | self error: 131 | 'Vector[' + first asString + '..' + last asString + 132 | ']: Index ' + index asString + ' out of bounds' ]) 133 | ) 134 | 135 | "DeltaBlue" 136 | removeFirst = ( 137 | self isEmpty ifTrue: [ self error: 'OrderedCollection is empty' ]. 138 | first := first + 1. 139 | ^ storage at: first - 1 140 | ) 141 | 142 | "Conversion" 143 | asSet = ( 144 | ^ Set new addAll: self 145 | ) 146 | 147 | ---------------------------- 148 | 149 | "Allocation" 150 | new = ( ^ self new: 50 ) 151 | new: initialSize = ( ^ super new initialize: initialSize ) 152 | 153 | with: elem = ( 154 | | newVector | 155 | newVector := self new: 1. 156 | newVector append: elem. 157 | ^ newVector 158 | ) 159 | 160 | ) 161 | -------------------------------------------------------------------------------- /SomAstModel.h: -------------------------------------------------------------------------------- 1 | #ifndef SOM_AST_MODEL_H 2 | #define SOM_AST_MODEL_H 3 | 4 | /* 5 | * Copyright 2020 Rochus Keller 6 | * 7 | * This file is part of the SOM Smalltalk parser/compiler library. 8 | * 9 | * The following is the license that applies to this copy of the 10 | * library. For a license to use the library under conditions 11 | * other than those described here, please email to me@rochus-keller.ch. 12 | * 13 | * GNU General Public License Usage 14 | * This file may be used under the terms of the GNU General Public 15 | * License (GPL) versions 2.0 or 3.0 as published by the Free Software 16 | * Foundation and appearing in the file LICENSE.GPL included in 17 | * the packaging of this file. Please review the following information 18 | * to ensure GNU General Public Licensing requirements will be met: 19 | * http://www.fsf.org/licensing/licenses/info/GPLv2.html and 20 | * http://www.gnu.org/copyleft/gpl.html. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | class QIODevice; 28 | 29 | namespace Som 30 | { 31 | class Model : public QObject 32 | { 33 | Q_OBJECT 34 | public: 35 | typedef QMap > Classes; 36 | typedef QHash< const char*, Ast::Ref > Classes2; 37 | typedef QMap > ClassCats; 38 | typedef QHash > MethodXref; 39 | typedef QHash > VariableXref; 40 | typedef QHash > PrimitiveXref; 41 | typedef QHash > IdentXref; 42 | typedef QHash > PatternXref; 43 | 44 | struct File 45 | { 46 | QIODevice* d_dev; 47 | QString d_path; 48 | File( QIODevice* d = 0, const QString& n = QString() ):d_dev(d),d_path(n){} 49 | }; 50 | 51 | explicit Model(QObject *parent = 0); 52 | 53 | typedef QList Files; 54 | bool parse( const Files& ); 55 | void clear(); 56 | 57 | const Classes& getClasses() const { return d_classes; } 58 | const ClassCats& getCats() const { return d_cats; } 59 | const MethodXref& getMxref() const { return d_mx; } 60 | const PrimitiveXref& getPxref() const { return d_px; } 61 | const IdentXref& getIxref() const { return d_ix; } 62 | const VariableXref& getVxref() const { return d_vx; } 63 | const PatternXref& getTxref() const { return d_tx; } 64 | const QStringList& getErrs() const { return d_errs; } 65 | protected: 66 | void error(const QString& msg, const Ast::Loc& loc ); 67 | private: 68 | class ResolveIdents; 69 | QStringList d_errs; 70 | Classes d_classes; 71 | Classes2 d_classes2; 72 | ClassCats d_cats; 73 | MethodXref d_mx; 74 | VariableXref d_vx; // only global, instance and class vars 75 | PrimitiveXref d_px; 76 | IdentXref d_ix; 77 | PatternXref d_tx; 78 | QByteArray nil; 79 | Ast::GlobalScope d_globals; 80 | QSet d_keywords; 81 | }; 82 | } 83 | 84 | #endif // SOM_AST_MODEL_H 85 | -------------------------------------------------------------------------------- /SomClassBrowser.h: -------------------------------------------------------------------------------- 1 | #ifndef SOM_CLASSBROWSER_H 2 | #define SOM_CLASSBROWSER_H 3 | 4 | /* 5 | * Copyright 2020 Rochus Keller 6 | * 7 | * This file is part of the SOM Smalltalk ClassBrowser application. 8 | * 9 | * The following is the license that applies to this copy of the 10 | * application. For a license to use the application under conditions 11 | * other than those described here, please email to me@rochus-keller.ch. 12 | * 13 | * GNU General Public License Usage 14 | * This file may be used under the terms of the GNU General Public 15 | * License (GPL) versions 2.0 or 3.0 as published by the Free Software 16 | * Foundation and appearing in the file LICENSE.GPL included in 17 | * the packaging of this file. Please review the following information 18 | * to ensure GNU General Public Licensing requirements will be met: 19 | * http://www.fsf.org/licensing/licenses/info/GPLv2.html and 20 | * http://www.gnu.org/copyleft/gpl.html. 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | class QTreeWidget; 27 | class QTreeWidgetItem; 28 | class QLabel; 29 | class QPlainTextEdit; 30 | class QTextBrowser; 31 | 32 | namespace Som 33 | { 34 | class ClassBrowser : public QMainWindow 35 | { 36 | Q_OBJECT 37 | 38 | public: 39 | ClassBrowser(QWidget *parent = 0); 40 | ~ClassBrowser(); 41 | 42 | bool parse(const QString& path , bool recursive); 43 | 44 | protected: 45 | void closeEvent(QCloseEvent* event); 46 | void createClassList(); 47 | void fillClassList(); 48 | static void fillClassItem( QTreeWidgetItem* item, Ast::Class* ); 49 | void createClassInfo(); 50 | void createMembers(); 51 | void fillMembers(); 52 | void setCurClass(Ast::Class*); 53 | void setCurMethod(Ast::Method*); 54 | void setCurVar(Ast::Variable*); 55 | static QString getClassSummary(Ast::Class*, bool elided = true); 56 | void createMethod(); 57 | void fillMethod(); 58 | void createHierarchy(); 59 | void fillHierarchy(); 60 | void fillHierarchy(QTreeWidgetItem* p, Ast::Class* ); 61 | void createMessages(); 62 | void fillMessages(); 63 | void createPrimitives(); 64 | void fillPrimitives(); 65 | void createUse(); 66 | void fillNamedUse(Ast::Named*); 67 | void fillPatternUse(const QByteArray&); 68 | void pushLocation(); 69 | void syncLists(QWidget* besides = 0); 70 | void createVars(); 71 | void fillVars(); 72 | 73 | protected slots: 74 | void onClassesClicked(); 75 | void onMembersClicked(); 76 | void onHierarchyClicked(); 77 | void onMessagesClicked(); 78 | void onPrimitiveClicked(); 79 | void onVarsClicked(); 80 | void onUseClicked(); 81 | void onGoBack(); 82 | void onGoForward(); 83 | void onLink( const QString& link ); 84 | 85 | 86 | private: 87 | class CodeViewer; 88 | Model* d_mdl; 89 | QTreeWidget* d_classes; 90 | QLabel* d_class; 91 | QTreeWidget* d_members; 92 | QTreeWidget* d_hierarchy; 93 | QTreeWidget* d_messages; 94 | QTreeWidget* d_primitives; 95 | QTreeWidget* d_vars; 96 | QTreeWidget* d_use; 97 | QLabel* d_useTitle; 98 | CodeViewer* d_code; 99 | QTextBrowser* d_classInfo; 100 | QLabel* d_method; 101 | Ast::ClassRef d_curClass; 102 | Ast::MethodRef d_curMethod; 103 | Ast::VarRef d_curVar; 104 | typedef QPair Location; 105 | QList d_backHisto; // d_backHisto.last() is the current location 106 | QList d_forwardHisto; 107 | bool d_pushBackLock; 108 | }; 109 | } 110 | 111 | #endif // SOM_CLASSBROWSER_H 112 | -------------------------------------------------------------------------------- /SomClassBrowser.pro: -------------------------------------------------------------------------------- 1 | #/* 2 | #* Copyright 2020 Rochus Keller 3 | #* 4 | #* This file is part of the SOM Smalltalk ClassBrowser application. 5 | #* 6 | #* The following is the license that applies to this copy of the 7 | #* application. For a license to use the application under conditions 8 | #* other than those described here, please email to me@rochus-keller.ch. 9 | #* 10 | #* GNU General Public License Usage 11 | #* This file may be used under the terms of the GNU General Public 12 | #* License (GPL) versions 2.0 or 3.0 as published by the Free Software 13 | #* Foundation and appearing in the file LICENSE.GPL included in 14 | #* the packaging of this file. Please review the following information 15 | #* to ensure GNU General Public Licensing requirements will be met: 16 | #* http://www.fsf.org/licensing/licenses/info/GPLv2.html and 17 | #* http://www.gnu.org/copyleft/gpl.html. 18 | #*/ 19 | 20 | QT += core gui 21 | 22 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 23 | 24 | TARGET = SomClassBrowser 25 | TEMPLATE = app 26 | 27 | INCLUDEPATH += .. 28 | 29 | SOURCES +=\ 30 | SomParser.cpp \ 31 | SomAstModel.cpp \ 32 | SomLexer.cpp \ 33 | SomClassBrowser.cpp \ 34 | SomHighlighter.cpp \ 35 | SomAst.cpp 36 | 37 | HEADERS += \ 38 | SomParser.h \ 39 | SomAstModel.h \ 40 | SomLexer.h \ 41 | SomClassBrowser.h \ 42 | SomHighlighter.h \ 43 | SomAst.h 44 | 45 | 46 | CONFIG(debug, debug|release) { 47 | DEFINES += _DEBUG 48 | } 49 | 50 | !win32 { 51 | QMAKE_CXXFLAGS += -Wno-reorder -Wno-unused-parameter -Wno-unused-function -Wno-unused-variable 52 | } 53 | 54 | RESOURCES += \ 55 | SomClassBrowser.qrc 56 | -------------------------------------------------------------------------------- /SomClassBrowser.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | Smalltalk/Array.som 4 | Smalltalk/Block.som 5 | Smalltalk/Block1.som 6 | Smalltalk/Block2.som 7 | Smalltalk/Block3.som 8 | Smalltalk/Boolean.som 9 | Smalltalk/Class.som 10 | Smalltalk/Dictionary.som 11 | Smalltalk/Double.som 12 | Smalltalk/False.som 13 | Smalltalk/HashEntry.som 14 | Smalltalk/Hashtable.som 15 | Smalltalk/Integer.som 16 | Smalltalk/Metaclass.som 17 | Smalltalk/Method.som 18 | Smalltalk/Nil.som 19 | Smalltalk/Object.som 20 | Smalltalk/Pair.som 21 | Smalltalk/Primitive.som 22 | Smalltalk/Set.som 23 | Smalltalk/Source.txt 24 | Smalltalk/String.som 25 | Smalltalk/Symbol.som 26 | Smalltalk/System.som 27 | Smalltalk/True.som 28 | Smalltalk/Vector.som 29 | 30 | 31 | -------------------------------------------------------------------------------- /SomHighlighter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Rochus Keller 3 | * 4 | * This file is part of the SOM Smalltalk parser/compiler library. 5 | * 6 | * The following is the license that applies to this copy of the 7 | * library. For a license to use the library under conditions 8 | * other than those described here, please email to me@rochus-keller.ch. 9 | * 10 | * GNU General Public License Usage 11 | * This file may be used under the terms of the GNU General Public 12 | * License (GPL) versions 2.0 or 3.0 as published by the Free Software 13 | * Foundation and appearing in the file LICENSE.GPL included in 14 | * the packaging of this file. Please review the following information 15 | * to ensure GNU General Public Licensing requirements will be met: 16 | * http://www.fsf.org/licensing/licenses/info/GPLv2.html and 17 | * http://www.gnu.org/copyleft/gpl.html. 18 | */ 19 | 20 | #include "SomHighlighter.h" 21 | #include "SomLexer.h" 22 | using namespace Som; 23 | 24 | Highlighter::Highlighter(QTextDocument* parent) : QSyntaxHighlighter(parent) 25 | { 26 | for( int i = 0; i < C_Max; i++ ) 27 | { 28 | d_format[i].setFontWeight(QFont::Normal); 29 | d_format[i].setForeground(Qt::black); 30 | d_format[i].setBackground(Qt::transparent); 31 | } 32 | // see https://www.rapidtables.com/web/color/brown-color.html 33 | static const QColor darkGreen(7, 131, 7); 34 | static const QColor brown(165,42,42); 35 | static const QColor darkOrange(255,140,0); 36 | static const QColor darkRed(153, 0, 0); 37 | static const QColor chocolate(210,105,30); 38 | 39 | d_format[C_Num].setForeground(QColor(0, 153, 153)); 40 | d_format[C_Str].setForeground(QColor(208, 16, 64)); 41 | d_format[C_Cmt].setForeground(darkGreen); // QColor(51, 153, 51)); // QColor(153, 153, 136)); 42 | d_format[C_Kw].setForeground(QColor(68, 85, 136)); 43 | d_format[C_Kw].setFontWeight(QFont::Bold); 44 | d_format[C_Op].setForeground(darkRed); 45 | d_format[C_Op].setFontWeight(QFont::Bold); 46 | d_format[C_Type].setForeground(QColor(153, 0, 115)); 47 | // d_format[C_Type].setFontWeight(QFont::Bold); 48 | d_format[C_Sym].setForeground(chocolate); 49 | 50 | d_keywords << "self" << "super" << "true" << "false" << "nil" << "primitive"; 51 | } 52 | 53 | void Highlighter::highlightBlock(const QString& text) 54 | { 55 | const int previousBlockState_ = previousBlockState(); 56 | int lexerState = 0, initialBraceDepth = 0; 57 | if (previousBlockState_ != -1) { 58 | lexerState = previousBlockState_ & 0xff; 59 | initialBraceDepth = previousBlockState_ >> 8; 60 | } 61 | 62 | int braceDepth = initialBraceDepth; 63 | 64 | 65 | int start = 0; 66 | if( lexerState == 1 ) 67 | { 68 | // wir sind in einem Multi Line Comment 69 | // suche das Ende 70 | QTextCharFormat f = d_format[C_Cmt]; 71 | int pos = text.indexOf("\""); 72 | if( pos == -1 ) // comments don't have embedded ""! 73 | { 74 | // the whole block ist part of the comment 75 | setFormat( start, text.size(), f ); 76 | setCurrentBlockState( (braceDepth << 8) | lexerState); 77 | return; 78 | }else 79 | { 80 | // End of Comment found 81 | pos += 1; 82 | setFormat( start, pos , f ); 83 | lexerState = 0; 84 | braceDepth--; 85 | start = pos; 86 | } 87 | }else if( lexerState == 2 ) 88 | { 89 | // wir sind in einem Multi Line String 90 | // suche das Ende 91 | QTextCharFormat f = d_format[C_Str]; 92 | int pos = text.indexOf("'"); 93 | if( pos == -1 || ( ( pos + 1 ) < text.size() && text[pos+1] == '\'' ) ) 94 | { 95 | // the whole block ist part of the string 96 | setFormat( start, text.size(), f ); 97 | setCurrentBlockState( (braceDepth << 8) | lexerState); 98 | return; 99 | }else 100 | { 101 | // End of string found 102 | pos += 1; 103 | setFormat( start, pos , f ); 104 | lexerState = 0; 105 | braceDepth--; 106 | start = pos; 107 | } 108 | } 109 | 110 | 111 | Lexer lex; 112 | lex.setFragMode(true); 113 | lex.setEatComments(false); 114 | 115 | QString text2 = text; 116 | text2.replace("←", "_" ); 117 | text2.replace("↑", "^" ); 118 | QList tokens = lex.tokens(text2.mid(start).toUtf8()); 119 | for( int i = 0; i < tokens.size(); ++i ) 120 | { 121 | Lexer::Token &t = tokens[i]; 122 | t.d_loc.d_pos += start; 123 | 124 | QTextCharFormat f; 125 | if( t.d_type == Lexer::LCmt ) 126 | { 127 | braceDepth++; 128 | f = d_format[C_Cmt]; 129 | lexerState = 1; 130 | }else if( t.d_type == Lexer::Comment ) 131 | f = d_format[C_Cmt]; 132 | else if( t.d_type == Lexer::LStr ) 133 | { 134 | braceDepth++; 135 | f = d_format[C_Str]; 136 | lexerState = 2; 137 | }else if( t.d_type == Lexer::String || t.d_type == Lexer::Char ) 138 | f = d_format[C_Str]; 139 | else if( t.d_type == Lexer::Real || t.d_type == Lexer::Integer ) 140 | f = d_format[C_Num]; 141 | else if( t.d_type == Lexer::Symbol ) 142 | { 143 | QTextCharFormat fb = d_format[C_Sym]; 144 | fb.setFontWeight(QFont::Bold); 145 | setFormat( t.d_loc.d_pos, 1, fb ); 146 | t.d_loc.d_pos++; t.d_loc.d_len--; 147 | f = d_format[C_Sym]; 148 | }else if( t.d_type >= Lexer::Colon && t.d_type <= Lexer::Rbrack ) 149 | f = d_format[C_Op]; 150 | else if( t.d_type == Lexer::Ident ) 151 | { 152 | //f = d_format[C_Type]; 153 | if( i + 1 < tokens.size() && tokens[i+1].d_type == Lexer::Colon ) 154 | f = d_format[C_Type]; 155 | else if( d_keywords.contains(t.d_val) ) 156 | f = d_format[C_Kw]; 157 | else 158 | f = d_format[C_Ident]; 159 | } 160 | 161 | if( f.isValid() ) 162 | { 163 | setFormat( t.d_loc.d_pos, t.d_loc.d_len, f ); 164 | } 165 | } 166 | 167 | setCurrentBlockState((braceDepth << 8) | lexerState ); 168 | } 169 | 170 | -------------------------------------------------------------------------------- /SomHighlighter.h: -------------------------------------------------------------------------------- 1 | #ifndef SOMHIGHLIGHTER_H 2 | #define SOMHIGHLIGHTER_H 3 | 4 | /* 5 | * Copyright 2020 Rochus Keller 6 | * 7 | * This file is part of the SOM Smalltalk parser/compiler library. 8 | * 9 | * The following is the license that applies to this copy of the 10 | * library. For a license to use the library under conditions 11 | * other than those described here, please email to me@rochus-keller.ch. 12 | * 13 | * GNU General Public License Usage 14 | * This file may be used under the terms of the GNU General Public 15 | * License (GPL) versions 2.0 or 3.0 as published by the Free Software 16 | * Foundation and appearing in the file LICENSE.GPL included in 17 | * the packaging of this file. Please review the following information 18 | * to ensure GNU General Public Licensing requirements will be met: 19 | * http://www.fsf.org/licensing/licenses/info/GPLv2.html and 20 | * http://www.gnu.org/copyleft/gpl.html. 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | namespace Som 27 | { 28 | class Highlighter : public QSyntaxHighlighter 29 | { 30 | public: 31 | explicit Highlighter(QTextDocument *parent = 0); 32 | 33 | protected: 34 | // overrides 35 | void highlightBlock(const QString &text); 36 | private: 37 | enum Category { C_Num, C_Str, C_Kw, C_Type, C_Ident, C_Op, C_Cmt, C_Sym, C_Max }; 38 | QTextCharFormat d_format[C_Max]; 39 | QSet d_keywords; 40 | }; 41 | } 42 | 43 | #endif // SOMHIGHLIGHTER_H 44 | -------------------------------------------------------------------------------- /SomLexer.h: -------------------------------------------------------------------------------- 1 | #ifndef SOM_LEXER_H 2 | #define SOM_LEXER_H 3 | 4 | /* 5 | * Copyright 2020 Rochus Keller 6 | * 7 | * This file is part of the SOM Smalltalk parser/compiler library. 8 | * 9 | * The following is the license that applies to this copy of the 10 | * library. For a license to use the library under conditions 11 | * other than those described here, please email to me@rochus-keller.ch. 12 | * 13 | * GNU General Public License Usage 14 | * This file may be used under the terms of the GNU General Public 15 | * License (GPL) versions 2.0 or 3.0 as published by the Free Software 16 | * Foundation and appearing in the file LICENSE.GPL included in 17 | * the packaging of this file. Please review the following information 18 | * to ensure GNU General Public Licensing requirements will be met: 19 | * http://www.fsf.org/licensing/licenses/info/GPLv2.html and 20 | * http://www.gnu.org/copyleft/gpl.html. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | class QIODevice; 28 | 29 | namespace Som 30 | { 31 | class Lexer 32 | { 33 | public: 34 | enum TokenType { Invalid, Error, EoF, 35 | Colon, Hat, Hash, Assig, Tilde, At, Percent, Ampers, Star, Minus, Plus, 36 | Eq, Bar, Bslash, Lt, Gt, Comma, Qmark, Slash, Dot, Semi, 37 | Lpar, Rpar, Lbrack, Rbrack, 38 | String, Char, Ident, Integer, Real, Comment, LCmt, LStr, Symbol, BinSelector, Separator, Keyword }; 39 | 40 | static const char* s_typeName[]; 41 | 42 | struct Token 43 | { 44 | QByteArray d_val; 45 | #ifdef _DEBUG 46 | TokenType d_type; 47 | #else 48 | quint8 d_type; 49 | #endif 50 | Ast::Loc d_loc; 51 | 52 | Token():d_type(Invalid){} 53 | bool isValid() const { return d_type != Invalid && d_type != EoF && d_type != Error; } 54 | const char* typeName() const { return s_typeName[d_type]; } 55 | }; 56 | 57 | explicit Lexer(); 58 | void setDevice( QIODevice*, const QString& path = QString() ); 59 | void setFragMode(bool on) { d_fragMode = on; } 60 | void setEatComments(bool on) { d_eatComments = on; } 61 | quint32 getLine() const { return d_line; } 62 | Token next(); 63 | Token peek(quint8 lookAhead = 1); 64 | QList tokens( const QByteArray& code ); 65 | static QByteArray getSymbol(const QByteArray& str); 66 | static bool isBinaryTokType( quint8 ); 67 | static bool isBinaryChar( char ); 68 | protected: 69 | char get(); 70 | char peekChar(int n = 1); 71 | Token string(); 72 | Token comment(); 73 | Token symbol(); 74 | Token ident(char); 75 | Token selector(char); 76 | Token number(char); 77 | Token token(TokenType type, char ); 78 | Token token(TokenType type, const QByteArray& val = QByteArray() ); 79 | Token nextImp(); 80 | void begin(); 81 | Token commit(TokenType type, const QByteArray& val = QByteArray() ); 82 | void skipWhite(); 83 | QPair readString(); 84 | private: 85 | QIODevice* d_in; 86 | QString d_path; 87 | quint32 d_pos; 88 | quint32 d_startPos; 89 | quint32 d_startLine; 90 | quint32 d_line; 91 | quint16 d_col; 92 | quint16 d_startCol; 93 | QList d_buffer; 94 | bool d_fragMode; 95 | bool d_eatComments; 96 | static QHash d_symbols; 97 | }; 98 | } 99 | 100 | #endif // SOM_LEXER_H 101 | -------------------------------------------------------------------------------- /SomLjLibFfi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Rochus Keller 3 | * 4 | * This file is part of the SOM Smalltalk parser/compiler library. 5 | * 6 | * The following is the license that applies to this copy of the 7 | * library. For a license to use the library under conditions 8 | * other than those described here, please email to me@rochus-keller.ch. 9 | * 10 | * GNU General Public License Usage 11 | * This file may be used under the terms of the GNU General Public 12 | * License (GPL) versions 2.0 or 3.0 as published by the Free Software 13 | * Foundation and appearing in the file LICENSE.GPL included in 14 | * the packaging of this file. Please review the following information 15 | * to ensure GNU General Public Licensing requirements will be met: 16 | * http://www.fsf.org/licensing/licenses/info/GPLv2.html and 17 | * http://www.gnu.org/copyleft/gpl.html. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #ifdef _WIN32 28 | #define DllExport __declspec(dllexport) 29 | #else 30 | #define DllExport 31 | #endif 32 | 33 | 34 | extern "C" 35 | { 36 | 37 | DllExport int Som_isWhiteSpace( const char* str ) 38 | { 39 | const int len = ::strlen(str); 40 | if( len == 0 ) 41 | return 0; 42 | for( int i = 0; i < len; i++ ) 43 | { 44 | if( !::isspace(str[i]) ) 45 | return 0; 46 | } 47 | return 1; 48 | } 49 | 50 | DllExport int Som_isLetters( const char* str ) 51 | { 52 | const int len = ::strlen(str); 53 | if( len == 0 ) 54 | return 0; 55 | for( int i = 0; i < len; i++ ) 56 | { 57 | if( !::isalpha(str[i]) ) 58 | return 0; 59 | } 60 | return 1; 61 | } 62 | 63 | DllExport int Som_isDigits( const char* str ) 64 | { 65 | const int len = ::strlen(str); 66 | if( len == 0 ) 67 | return 0; 68 | for( int i = 0; i < len; i++ ) 69 | { 70 | if( !::isdigit(str[i]) ) 71 | return 0; 72 | } 73 | return 1; 74 | } 75 | 76 | DllExport int Som_usecs() 77 | { 78 | static QElapsedTimer t; 79 | if( !t.isValid() ) 80 | t.start(); 81 | return t.nsecsElapsed() / 1000; 82 | } 83 | 84 | DllExport int Som_toInt32(double d) 85 | { 86 | return d; 87 | } 88 | 89 | DllExport unsigned int Som_toUInt32(double d) 90 | { 91 | const int tmp = d; 92 | return tmp; 93 | } 94 | 95 | DllExport int Som_rem(int l, int r) 96 | { 97 | return l % r; 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /SomLjObjectManager.h: -------------------------------------------------------------------------------- 1 | #ifndef SOMLJOBJECTMANAGER_H 2 | #define SOMLJOBJECTMANAGER_H 3 | 4 | /* 5 | * Copyright 2020 Rochus Keller 6 | * 7 | * This file is part of the SOM Smalltalk parser/compiler library. 8 | * 9 | * The following is the license that applies to this copy of the 10 | * library. For a license to use the library under conditions 11 | * other than those described here, please email to me@rochus-keller.ch. 12 | * 13 | * GNU General Public License Usage 14 | * This file may be used under the terms of the GNU General Public 15 | * License (GPL) versions 2.0 or 3.0 as published by the Free Software 16 | * Foundation and appearing in the file LICENSE.GPL included in 17 | * the packaging of this file. Please review the following information 18 | * to ensure GNU General Public Licensing requirements will be met: 19 | * http://www.fsf.org/licensing/licenses/info/GPLv2.html and 20 | * http://www.gnu.org/copyleft/gpl.html. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | class QIODevice; 28 | 29 | namespace Lua 30 | { 31 | class Engine2; 32 | } 33 | 34 | namespace Som 35 | { 36 | class LjObjectManager : public QObject 37 | { 38 | public: 39 | typedef QList > GeneratedFiles; // source path -> generated path 40 | explicit LjObjectManager(Lua::Engine2*, QObject *parent = 0); 41 | bool load( const QString& mainSomFile, const QStringList& paths = QStringList() ); 42 | bool loadAtRuntime( const QByteArray& className ); 43 | bool setArgs( const QStringList& ); 44 | bool run(); 45 | const QStringList& getErrors() const { return d_errors; } 46 | const GeneratedFiles& getGenerated() const { return d_generated; } 47 | void generateSomPrimitives(); 48 | QByteArrayList getClassNames() const; 49 | void setGenLua( bool on ) { d_genLua = on; } 50 | void setGenClosures( bool on ) { d_genClosures = on; } 51 | QString pathInDir( const QString& dir, const QString& name ); 52 | protected: 53 | bool parseMain(const QString& mainFile); 54 | Ast::Ref parseFile( const QString& file ); 55 | bool error( const Ast::Loc&, const QString& msg ); 56 | bool error( const QString& msg ); 57 | QString findClassFile(const char* className); 58 | bool loadAndSetSuper( Ast::Class* ); 59 | bool resolveIdents( Ast::Class* ); 60 | Ast::Ref getOrLoadClass( const QByteArray& ); 61 | Ast::Ref getOrLoadClassImp( const char* className, bool* loaded = 0 ); 62 | bool handleUnresolved(); 63 | bool instantiateClasses(); 64 | bool instantiateClass( Ast::Class* ); 65 | bool compileMethods( Ast::Class* ); 66 | void writeLua( QIODevice* out, Ast::Class* cls); 67 | void writeBc( QIODevice* out, Ast::Class* cls); 68 | private: 69 | class ResolveIdents; 70 | Lua::Engine2* d_lua; 71 | QStringList d_classPaths; 72 | QStringList d_errors; 73 | QString d_mainPath; 74 | Ast::Ref d_mainClass; 75 | typedef QHash > Classes; 76 | Classes d_classes; 77 | QList d_loadingOrder; 78 | quint32 d_instantiated; 79 | QByteArray _nil, _Class, _Object; 80 | QHash d_keywords; 81 | Ast::Ref d_system; 82 | QList d_unresolved; 83 | GeneratedFiles d_generated; 84 | bool d_genLua, d_genClosures; 85 | }; 86 | } 87 | 88 | #endif // SOMLJOBJECTMANAGER_H 89 | -------------------------------------------------------------------------------- /SomLjVirtualMachine.h: -------------------------------------------------------------------------------- 1 | #ifndef SOMLJVIRTUALMACHINE_H 2 | #define SOMLJVIRTUALMACHINE_H 3 | 4 | /* 5 | * Copyright 2020 Rochus Keller 6 | * 7 | * This file is part of the SOM Smalltalk parser/compiler library. 8 | * 9 | * The following is the license that applies to this copy of the 10 | * library. For a license to use the library under conditions 11 | * other than those described here, please email to me@rochus-keller.ch. 12 | * 13 | * GNU General Public License Usage 14 | * This file may be used under the terms of the GNU General Public 15 | * License (GPL) versions 2.0 or 3.0 as published by the Free Software 16 | * Foundation and appearing in the file LICENSE.GPL included in 17 | * the packaging of this file. Please review the following information 18 | * to ensure GNU General Public Licensing requirements will be met: 19 | * http://www.fsf.org/licensing/licenses/info/GPLv2.html and 20 | * http://www.gnu.org/copyleft/gpl.html. 21 | */ 22 | 23 | #include 24 | 25 | namespace Lua 26 | { 27 | class Engine2; 28 | } 29 | 30 | namespace Som 31 | { 32 | class LjObjectManager; 33 | 34 | class LjVirtualMachine : public QObject 35 | { 36 | Q_OBJECT 37 | public: 38 | explicit LjVirtualMachine(QObject *parent = 0); 39 | bool load(const QString& file, const QString& paths = QString() ); 40 | void run(bool useJit = true, bool useProfiler = false); 41 | Lua::Engine2* getLua() const { return d_lua; } 42 | QStringList getLuaFiles() const; 43 | QByteArrayList getClassNames() const; 44 | void setGenLua( bool ); 45 | void setGenClosures( bool ); 46 | LjObjectManager* getOm() const { return d_om;} 47 | protected slots: 48 | void onNotify( int messageType, QByteArray val1, int val2 ); 49 | private: 50 | Lua::Engine2* d_lua; 51 | LjObjectManager* d_om; 52 | }; 53 | } 54 | 55 | #endif // SOMLJVIRTUALMACHINE_H 56 | -------------------------------------------------------------------------------- /SomLjVirtualMachine.pro: -------------------------------------------------------------------------------- 1 | #/* 2 | #* Copyright 2020 Rochus Keller 3 | #* 4 | #* This file is part of the SOM Smalltalk VM application. 5 | #* 6 | #* The following is the license that applies to this copy of the 7 | #* application. For a license to use the application under conditions 8 | #* other than those described here, please email to me@rochus-keller.ch. 9 | #* 10 | #* GNU General Public License Usage 11 | #* This file may be used under the terms of the GNU General Public 12 | #* License (GPL) versions 2.0 or 3.0 as published by the Free Software 13 | #* Foundation and appearing in the file LICENSE.GPL included in 14 | #* the packaging of this file. Please review the following information 15 | #* to ensure GNU General Public Licensing requirements will be met: 16 | #* http://www.fsf.org/licensing/licenses/info/GPLv2.html and 17 | #* http://www.gnu.org/copyleft/gpl.html. 18 | #*/ 19 | 20 | QT += core gui 21 | 22 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 23 | QT += printsupport 24 | 25 | TARGET = SomLjVirtualMachine 26 | TEMPLATE = app 27 | 28 | INCLUDEPATH += .. ../LuaJIT/src 29 | 30 | SOURCES += \ 31 | SomLjVirtualMachine.cpp \ 32 | SomLjObjectManager.cpp \ 33 | SomAst.cpp \ 34 | SomLexer.cpp \ 35 | SomParser.cpp \ 36 | SomLuaTranspiler.cpp \ 37 | SomLjLibFfi.cpp \ 38 | SomLjbcCompiler.cpp \ 39 | ../LjTools/LjBcDebugger.cpp \ 40 | SomLjbcCompiler2.cpp 41 | 42 | HEADERS += \ 43 | SomLjVirtualMachine.h \ 44 | SomLjObjectManager.h \ 45 | SomAst.h \ 46 | SomLexer.h \ 47 | SomParser.h \ 48 | SomLuaTranspiler.h \ 49 | SomLjbcCompiler.h \ 50 | ../LjTools/LjBcDebugger.h \ 51 | SomLjbcCompiler2.h 52 | 53 | DEFINES += LUAIDE_EMBEDDED 54 | include( ../LjTools/LuaIde.pri ) 55 | include( ../LjTools/Lua.pri ) 56 | include( ../GuiTools/Menu.pri ) 57 | 58 | win32 { 59 | LIBS += -L../LuaJIT/src -llua51 60 | } 61 | linux { 62 | include( ../LuaJIT/src/LuaJit.pri ){ 63 | LIBS += -ldl 64 | } else { 65 | LIBS += -lluajit 66 | } 67 | QMAKE_LFLAGS += -rdynamic -ldl 68 | #rdynamic is required so that the LjLibFfi functions are visible to LuaJIT FFI 69 | } 70 | macx { 71 | include( ../LuaJIT/src/LuaJit.pri ) 72 | QMAKE_LFLAGS += -rdynamic -ldl -pagezero_size 10000 -image_base 100000000 73 | } 74 | 75 | CONFIG(debug, debug|release) { 76 | DEFINES += _DEBUG 77 | } 78 | 79 | !win32 { 80 | QMAKE_CXXFLAGS += -Wno-reorder -Wno-unused-parameter -Wno-unused-function -Wno-unused-variable 81 | QMAKE_CXXFLAGS += -fno-stack-protector # see https://stackoverflow.com/questions/1345670/stack-smashing-detected 82 | } 83 | 84 | RESOURCES += \ 85 | SomLjVirtualMachine.qrc 86 | -------------------------------------------------------------------------------- /SomLjVirtualMachine.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/close.png 4 | images/exclamation-circle.png 5 | images/exclamation-red.png 6 | Smalltalk/Array.som 7 | Smalltalk/Block.som 8 | Smalltalk/Block1.som 9 | Smalltalk/Block2.som 10 | Smalltalk/Block3.som 11 | Smalltalk/Boolean.som 12 | Smalltalk/Class.som 13 | Smalltalk/Dictionary.som 14 | Smalltalk/Double.som 15 | Smalltalk/False.som 16 | Smalltalk/HashEntry.som 17 | Smalltalk/Hashtable.som 18 | Smalltalk/Integer.som 19 | Smalltalk/Metaclass.som 20 | Smalltalk/Method.som 21 | Smalltalk/Nil.som 22 | Smalltalk/Object.som 23 | Smalltalk/Pair.som 24 | Smalltalk/Primitive.som 25 | Smalltalk/Set.som 26 | Smalltalk/String.som 27 | Smalltalk/Symbol.som 28 | Smalltalk/System.som 29 | Smalltalk/True.som 30 | Smalltalk/Vector.som 31 | SomPrimitives.lua 32 | images/breakpoint.png 33 | images/marker.png 34 | images/break-marker.png 35 | LjTraceDump.lua 36 | 37 | 38 | -------------------------------------------------------------------------------- /SomLjbcCompiler.h: -------------------------------------------------------------------------------- 1 | #ifndef SOMLJBCCOMPILER_H 2 | #define SOMLJBCCOMPILER_H 3 | 4 | /* 5 | * Copyright 2020 Rochus Keller 6 | * 7 | * This file is part of the SOM Smalltalk parser/compiler library. 8 | * 9 | * The following is the license that applies to this copy of the 10 | * library. For a license to use the library under conditions 11 | * other than those described here, please email to me@rochus-keller.ch. 12 | * 13 | * GNU General Public License Usage 14 | * This file may be used under the terms of the GNU General Public 15 | * License (GPL) versions 2.0 or 3.0 as published by the Free Software 16 | * Foundation and appearing in the file LICENSE.GPL included in 17 | * the packaging of this file. Please review the following information 18 | * to ensure GNU General Public Licensing requirements will be met: 19 | * http://www.fsf.org/licensing/licenses/info/GPLv2.html and 20 | * http://www.gnu.org/copyleft/gpl.html. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | namespace Som 28 | { 29 | class NoMoreFreeSlots : public std::exception 30 | { 31 | public: 32 | NoMoreFreeSlots( const Ast::Loc& ); 33 | ~NoMoreFreeSlots() throw() {} 34 | const char* what() const throw() { return d_what.constData(); } 35 | private: 36 | QByteArray d_what; 37 | }; 38 | 39 | class LjbcCompiler 40 | { 41 | public: 42 | static bool translate( Lua::JitComposer&, Ast::Method* ); 43 | 44 | private: 45 | LjbcCompiler(); 46 | }; 47 | } 48 | 49 | #endif // SOMLJBCCOMPILER_H 50 | -------------------------------------------------------------------------------- /SomLjbcCompiler2.h: -------------------------------------------------------------------------------- 1 | #ifndef SOMLJBCCOMPILER2_H 2 | #define SOMLJBCCOMPILER2_H 3 | 4 | /* 5 | * Copyright 2020 Rochus Keller 6 | * 7 | * This file is part of the SOM Smalltalk parser/compiler library. 8 | * 9 | * The following is the license that applies to this copy of the 10 | * library. For a license to use the library under conditions 11 | * other than those described here, please email to me@rochus-keller.ch. 12 | * 13 | * GNU General Public License Usage 14 | * This file may be used under the terms of the GNU General Public 15 | * License (GPL) versions 2.0 or 3.0 as published by the Free Software 16 | * Foundation and appearing in the file LICENSE.GPL included in 17 | * the packaging of this file. Please review the following information 18 | * to ensure GNU General Public Licensing requirements will be met: 19 | * http://www.fsf.org/licensing/licenses/info/GPLv2.html and 20 | * http://www.gnu.org/copyleft/gpl.html. 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | namespace Som 27 | { 28 | 29 | class LjbcCompiler2 30 | { 31 | public: 32 | static bool translate( Lua::JitComposer&, Ast::Method* ); 33 | static bool translate( Lua::JitComposer&, Ast::Method*, Ast::Block* ); 34 | 35 | private: 36 | LjbcCompiler2(); 37 | }; 38 | } 39 | 40 | #endif // SOMLJBCCOMPILER2_H 41 | -------------------------------------------------------------------------------- /SomLuaTranspiler.h: -------------------------------------------------------------------------------- 1 | #ifndef SOMLUATRANSPILER_H 2 | #define SOMLUATRANSPILER_H 3 | 4 | /* 5 | * Copyright 2020 Rochus Keller 6 | * 7 | * This file is part of the SOM Smalltalk parser/compiler library. 8 | * 9 | * The following is the license that applies to this copy of the 10 | * library. For a license to use the library under conditions 11 | * other than those described here, please email to me@rochus-keller.ch. 12 | * 13 | * GNU General Public License Usage 14 | * This file may be used under the terms of the GNU General Public 15 | * License (GPL) versions 2.0 or 3.0 as published by the Free Software 16 | * Foundation and appearing in the file LICENSE.GPL included in 17 | * the packaging of this file. Please review the following information 18 | * to ensure GNU General Public Licensing requirements will be met: 19 | * http://www.fsf.org/licensing/licenses/info/GPLv2.html and 20 | * http://www.gnu.org/copyleft/gpl.html. 21 | */ 22 | 23 | #include 24 | 25 | class QTextStream; 26 | 27 | namespace Som 28 | { 29 | class LuaTranspiler 30 | { 31 | public: 32 | static bool transpile( QTextStream&, Ast::Method* ); 33 | static QByteArray map(QByteArray name ); 34 | static QByteArray map(const QByteArray& name, quint8 patternType ); 35 | static QByteArray escape( const QByteArray& string ); 36 | private: 37 | LuaTranspiler(); 38 | }; 39 | } 40 | 41 | #endif // SOMLUATRANSPILER_H 42 | -------------------------------------------------------------------------------- /SomParser.h: -------------------------------------------------------------------------------- 1 | #ifndef SOM_PARSER_H 2 | #define SOM_PARSER_H 3 | 4 | /* 5 | * Copyright 2020 Rochus Keller 6 | * 7 | * This file is part of the SOM Smalltalk parser/compiler library. 8 | * 9 | * The following is the license that applies to this copy of the 10 | * library. For a license to use the library under conditions 11 | * other than those described here, please email to me@rochus-keller.ch. 12 | * 13 | * GNU General Public License Usage 14 | * This file may be used under the terms of the GNU General Public 15 | * License (GPL) versions 2.0 or 3.0 as published by the Free Software 16 | * Foundation and appearing in the file LICENSE.GPL included in 17 | * the packaging of this file. Please review the following information 18 | * to ensure GNU General Public Licensing requirements will be met: 19 | * http://www.fsf.org/licensing/licenses/info/GPLv2.html and 20 | * http://www.gnu.org/copyleft/gpl.html. 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | class QIODevice; 27 | 28 | namespace Som 29 | { 30 | class Parser 31 | { 32 | public: 33 | struct Error 34 | { 35 | QByteArray d_msg; 36 | Ast::Loc d_loc; 37 | Error( const QByteArray& msg, const Ast::Loc& loc ):d_msg(msg),d_loc(loc){} 38 | }; 39 | 40 | explicit Parser(Lexer*); 41 | 42 | bool readFile(); 43 | bool readClass(); 44 | // bool readExpression(); 45 | 46 | Ast::Class* getClass() const { return d_curClass.data(); } 47 | const QList& getErrs() const { return d_errs; } 48 | 49 | static void convertFile( QIODevice*, const QString& to ); 50 | 51 | protected: 52 | bool error( const QByteArray& msg, const Lexer::Token& pos ); 53 | bool readClassExpr(); 54 | Ast::Ref readMethod(Ast::Class* c, bool classLevel); 55 | 56 | struct TokStream 57 | { 58 | typedef QList Toks; 59 | Toks d_toks; 60 | quint32 d_pos; 61 | TokStream(const Toks& t = Toks(), quint32 pos = 0 ):d_toks(t),d_pos(pos){} 62 | Lexer::Token next(); 63 | Lexer::Token peek(int la = 1) const; 64 | bool atEnd() const { return d_pos >= d_toks.size(); } 65 | }; 66 | 67 | bool parseMethodBody(TokStream& ); 68 | bool parseLocals(Ast::Function*, TokStream& ); 69 | Ast::Ref parseExpression(Ast::Function*, TokStream&, quint8 inPattern = 0); 70 | Ast::Ref simpleExpression(Ast::Function*, TokStream&); 71 | Ast::Ref parseBlock(Ast::Function*, TokStream&); 72 | Ast::Ref parseArray(Ast::Function*, TokStream&); 73 | Ast::Ref parseAssig(Ast::Function*, TokStream&); 74 | Ast::Ref parseReturn(Ast::Function*, TokStream&); 75 | bool parseBlockBody(Ast::Function* block, TokStream& ); 76 | bool parseFields( bool classLevel ); 77 | private: 78 | Lexer* d_lex; 79 | QByteArray primitive, Object; 80 | QList d_errs; 81 | Ast::Ref d_curClass; 82 | Ast::Ref d_curMeth; 83 | int d_blockLevel; 84 | }; 85 | } 86 | 87 | #endif // SOM_PARSER_H 88 | -------------------------------------------------------------------------------- /images/break-marker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rochus-keller/Som/b7e8f8ccb89bce8daf61a18ea420976c9bfe92c0/images/break-marker.png -------------------------------------------------------------------------------- /images/breakpoint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rochus-keller/Som/b7e8f8ccb89bce8daf61a18ea420976c9bfe92c0/images/breakpoint.png -------------------------------------------------------------------------------- /images/close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rochus-keller/Som/b7e8f8ccb89bce8daf61a18ea420976c9bfe92c0/images/close.png -------------------------------------------------------------------------------- /images/exclamation-circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rochus-keller/Som/b7e8f8ccb89bce8daf61a18ea420976c9bfe92c0/images/exclamation-circle.png -------------------------------------------------------------------------------- /images/exclamation-red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rochus-keller/Som/b7e8f8ccb89bce8daf61a18ea420976c9bfe92c0/images/exclamation-red.png -------------------------------------------------------------------------------- /images/marker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rochus-keller/Som/b7e8f8ccb89bce8daf61a18ea420976c9bfe92c0/images/marker.png --------------------------------------------------------------------------------