├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .gitlab-ci.yml ├── .gitmodules ├── AUTHORS ├── CSOM.xcodeproj └── project.pbxproj ├── Examples ├── INSTALL ├── LICENSE ├── Makefile ├── README.md ├── Smalltalk ├── TestSuite ├── awfy-test.conf ├── build ├── Darwin.make ├── Linux.make ├── SunOS.make ├── ostool.c ├── unix.make └── windows.make ├── doc ├── CSOM.1 ├── ObjectModel.graffle ├── ObjectModel.pdf ├── Primitives │ ├── Hello.som │ ├── HelloDefine.h │ ├── Makefile │ ├── README.de │ └── README.en ├── common.tex ├── glossary.tex ├── styleguide.tex └── tab.c ├── rebench.conf ├── som-em.sh ├── som.sh ├── src ├── compiler │ ├── BytecodeGeneration.c │ ├── BytecodeGeneration.h │ ├── Disassembler.c │ ├── Disassembler.h │ ├── GenerationContexts.c │ ├── GenerationContexts.h │ ├── Lexer.c │ ├── Lexer.h │ ├── Parser.c │ ├── Parser.h │ ├── SourcecodeCompiler.c │ └── SourcecodeCompiler.h ├── interpreter │ ├── Interpreter.c │ ├── Interpreter.h │ └── bytecodes.h ├── main.c ├── memory │ ├── gc.c │ └── gc.h ├── misc │ ├── Hashmap.c │ ├── Hashmap.h │ ├── List.c │ ├── List.h │ ├── String.c │ ├── String.h │ ├── StringHashmap.c │ ├── StringHashmap.h │ ├── debug.h │ └── defs.h ├── primitives │ ├── %Primitive.c% │ ├── Array.c │ ├── Array.h │ ├── Block.c │ ├── Block.h │ ├── Class.c │ ├── Class.h │ ├── Core.c │ ├── Double.c │ ├── Double.h │ ├── Integer.c │ ├── Integer.h │ ├── Method.c │ ├── Method.h │ ├── Object.c │ ├── Object.h │ ├── Primitive.c │ ├── Primitive.h │ ├── String.c │ ├── String.h │ ├── Symbol.c │ ├── Symbol.h │ ├── System.c │ ├── System.h │ ├── som2lib.rb │ └── som2strlist.sh ├── vm │ ├── Shell.c │ ├── Shell.h │ ├── Universe.c │ └── Universe.h └── vmobjects │ ├── OOObject.c │ ├── OOObject.h │ ├── Signature.c │ ├── Signature.h │ ├── Symboltable.c │ ├── Symboltable.h │ ├── VMArray.c │ ├── VMArray.h │ ├── VMBlock.c │ ├── VMBlock.h │ ├── VMClass.c │ ├── VMClass.h │ ├── VMDouble.c │ ├── VMDouble.h │ ├── VMEvaluationPrimitive.c │ ├── VMEvaluationPrimitive.h │ ├── VMFrame.c │ ├── VMFrame.h │ ├── VMInteger.c │ ├── VMInteger.h │ ├── VMInvokable.c │ ├── VMInvokable.h │ ├── VMMethod.c │ ├── VMMethod.h │ ├── VMObject.c │ ├── VMObject.h │ ├── VMPrimitive.c │ ├── VMPrimitive.h │ ├── VMString.c │ ├── VMString.h │ ├── VMSymbol.c │ ├── VMSymbol.h │ └── objectformats.h └── tests ├── BasicInterpreterTests.c └── main.c /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | test_som: 7 | runs-on: ubuntu-latest 8 | strategy: 9 | fail-fast: false 10 | matrix: 11 | include: 12 | - name: GCC 32bit 13 | bit: 32 14 | compiler: gcc 15 | - name: GCC 64bit 16 | bit: 64 17 | compiler: gcc 18 | - name: Clang 32bit 19 | bit: 32 20 | compiler: Clang 21 | - name: Clang 64bit 22 | bit: 64 23 | compiler: clang 24 | - name: Emscripten 25 | compiler: emcc 26 | 27 | steps: 28 | - name: Checkout 29 | uses: actions/checkout@v2 30 | with: 31 | submodules: true 32 | 33 | - name: Install Multilib 34 | if: matrix.bit == 32 35 | run: | 36 | sudo apt-get install libc6-dev-i386 gcc-multilib 37 | 38 | - name: Tests 39 | run: | 40 | export COMPILER=${{ matrix.compiler }} 41 | export ARCH=${{ matrix.bit }}bit 42 | make test 43 | if: matrix.compiler != 'emcc' 44 | 45 | - name: Load Emscripten 46 | uses: mymindstorm/setup-emsdk@v10 47 | with: 48 | version: 1.38.40 49 | if: matrix.compiler == 'emcc' 50 | 51 | - name: Tests Emscripten 52 | run: | 53 | make emscripten 54 | ./som-em.sh -cp Smalltalk TestSuite/TestHarness.som 55 | if: matrix.compiler == 'emcc' 56 | 57 | # - name: SomSom Tests 58 | # run: | 59 | # ./CSOM -cp core-lib/Smalltalk:core-lib/TestSuite:core-lib/SomSom/src/compiler:core-lib/SomSom/src/vm:core-lib/SomSom/src/vmobjects:core-lib/SomSom/src/interpreter:core-lib/SomSom/src/primitives \ 60 | # core-lib/SomSom/tests/SomSomTests.som 61 | 62 | # - name: Checkout AWFY 63 | # uses: actions/checkout@v2 64 | # with: 65 | # repository: smarr/are-we-fast-yet 66 | # path: are-we-fast-yet 67 | 68 | # - name: AWFY Test Run 69 | # run: | 70 | # pwd 71 | # export COMPILER=${{ matrix.compiler }} 72 | # export ARCH=${{ matrix.bit }}bit 73 | # make 74 | # pip install ReBench 75 | # rebench awfy-test.conf 76 | # if: matrix.compiler != 'emcc' 77 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | build/ostool.exe* 3 | CORE 4 | CSOM 5 | Smalltalk/SOMCore.csp 6 | src/platform.h 7 | CSOM.xcodeproj/project.xcworkspace 8 | CSOM.xcodeproj/xcuserdata 9 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | stages: 2 | - build-test-benchmark 3 | 4 | variables: 5 | PYTHONUNBUFFERED: "true" 6 | 7 | before_script: 8 | - git submodule update --init 9 | 10 | build_test_benchmark_job: 11 | stage: build-test-benchmark 12 | tags: [benchmarks, infinity] 13 | script: 14 | - ARCH=64bit make 15 | - ARCH=64bit make test 16 | - rebench --experiment="CI ID $CI_PIPELINE_ID" --branch="$CI_COMMIT_REF_NAME" -c rebench.conf CSOM 17 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "core-lib"] 2 | path = core-lib 3 | url = https://github.com/SOM-st/SOM.git 4 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | This file lists all people who have contributed to the CSOM VM. 2 | 3 | The precursor of CSOM was SOM, which was originally implemented in Java at the 4 | University of Aarhus (Denmark) in 2001/2002. The implementation of SOM was done 5 | by Jakob Roland Andersen, Kasper Verdich Lund, Lars Bak, Mads Torgersen, and 6 | Ulrik Pagh Schultz. They also wrote the original versions of the SOM Smalltalk 7 | libraries, test suites, and benchmarks, that are (in extended versions) bundled 8 | with CSOM. 9 | 10 | SOM was used by Michael Haupt in courses on virtual machines at Lancaster 11 | University and Technische Universitaet Darmstadt (Germany) in VM courses in 12 | 2006. During that time, some changes were applied to SOM by Michael Haupt and 13 | Sebastian Kanthak. 14 | 15 | CSOM, the C port of SOM, was realised at the Hasso Plattner Institute (Potsdam, 16 | Germany) in 2006/7 by Michael Haupt and Tobias Pape. Stefan Marr and Jan-Arne 17 | Sobania have contributed a performance patch. Stefan Marr also contributed the Snake game. 18 | 19 | This file was last modified on: 20 | $LastChangedDate: 2008-04-10 20:15:47 +0200 (Do, 10 Apr 2008) $. 21 | -------------------------------------------------------------------------------- /Examples: -------------------------------------------------------------------------------- 1 | core-lib/Examples -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | see README 2 | siehe README 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007 Michael Haupt, Tobias Pape 2 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 3 | http://www.hpi.uni-potsdam.de/swa/ 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env make -f 2 | 3 | # 4 | # Makefile by Tobias Pape 5 | # $Id: Makefile 206 2008-04-14 12:22:39Z michael.haupt $ 6 | # 7 | # Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | # Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | # http://www.hpi.uni-potsdam.de/swa/ 10 | # 11 | # Permission is hereby granted, free of charge, to any person obtaining a copy 12 | # of this software and associated documentation files (the "Software"), to deal 13 | # in the Software without restriction, including without limitation the rights 14 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | # copies of the Software, and to permit persons to whom the Software is 16 | # furnished to do so, subject to the following conditions: 17 | # 18 | # The above copyright notice and this permission notice shall be included in 19 | # all copies or substantial portions of the Software. 20 | # 21 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | # THE SOFTWARE. 28 | # 29 | 30 | 31 | export ROOT_DIR :=$(PWD) 32 | export BUILD_DIR:=$(ROOT_DIR)/build 33 | 34 | export ARCH?=64bit 35 | 36 | ifeq ($(ARCH),32bit) 37 | COMPILER_ARCH=-m32 38 | endif 39 | ifeq ($(ARCH),64bit) 40 | COMPILER_ARCH=-m64 41 | endif 42 | 43 | 44 | ifeq ($(OS),) 45 | # only Windows has OS predefined. 46 | UNAME := $(shell uname -s) 47 | else 48 | UNAME :=windows 49 | endif 50 | 51 | ############# 52 | include $(BUILD_DIR)/$(UNAME).make 53 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | CSOM - The Simple Object Machine implemented in C 2 | ================================================= 3 | 4 | Introduction 5 | ------------ 6 | 7 | SOM is a minimal Smalltalk dialect used to teach VM construction at the [Hasso 8 | Plattner Institute][SOM]. It was originally built at the University of Århus 9 | (Denmark) where it was also used for teaching. 10 | 11 | Currently, implementations exist for Java (SOM), C (CSOM), C++ (SOM++), and 12 | Squeak/Pharo Smalltalk (AweSOM). 13 | 14 | A simple SOM Hello World looks like: 15 | 16 | ```Smalltalk 17 | Hello = ( 18 | run = ( 19 | 'Hello World!' println. 20 | ) 21 | ) 22 | ``` 23 | 24 | This repository contains a plain C implementation of SOM, including an 25 | implementation of the SOM standard library and a number of examples. Please see 26 | the [main project page][SOMst] for links to the VM implementations. 27 | 28 | 29 | CSOM can be built with Make: 30 | 31 | $ make 32 | 33 | Afterwards, the tests can be executed with: 34 | 35 | ./som.sh -cp Smalltalk TestSuite/TestHarness.som 36 | 37 | A simple Hello World program is executed with: 38 | 39 | ./som.sh -cp Smalltalk Examples/Hello.som 40 | 41 | The debug version of CSOM can be built using the `debug` target: 42 | 43 | $ make debug 44 | 45 | Information on previous authors are included in the AUTHORS file. This code is 46 | distributed under the MIT License. Please see the LICENSE file for details. 47 | Additional documentation, detailing for instance the object model and how to 48 | implement primitives, is available in the `doc` folder. 49 | 50 | WebAssembly CSOM 51 | ---------------- 52 | 53 | CSOM can be compiled using GCC, Clang, but also emscripten. 54 | With emscripten, it can run on Node.js as follows: 55 | 56 | - install [emscripten](http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html) and set it up for compilation. 57 | One easy way is using Docker, as in the .travis.yml. Another is with [emsdk](https://github.com/juj/emsdk/) 58 | - build with: `make emscripten` 59 | - run with: `node CSOM.js -cp Smalltalk Examples/Hello.som` 60 | 61 | Build Status 62 | ------------ 63 | 64 | Thanks to Travis CI, all commits of this repository are tested. 65 | The current build status is: [![Build Status](https://travis-ci.org/SOM-st/CSOM.png?branch=master)](https://travis-ci.org/SOM-st/CSOM/) 66 | 67 | [SOM]: http://www.hpi.uni-potsdam.de/hirschfeld/projects/som/ 68 | [SOMst]: https://travis-ci.org/SOM-st/ 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /Smalltalk: -------------------------------------------------------------------------------- 1 | core-lib/Smalltalk -------------------------------------------------------------------------------- /TestSuite: -------------------------------------------------------------------------------- 1 | core-lib/TestSuite -------------------------------------------------------------------------------- /awfy-test.conf: -------------------------------------------------------------------------------- 1 | # -*- mode: yaml -*- 2 | # Config file for ReBench 3 | default_experiment: all 4 | default_data_file: 'benchmark.data' 5 | 6 | runs: 7 | iterations: 1 8 | invocations: 1 9 | 10 | # definition of benchmark suites 11 | benchmark_suites: 12 | test-som: 13 | gauge_adapter: RebenchLog 14 | command: " -cp ../../../core-lib/Smalltalk:.:Core:CD:DeltaBlue:Havlak:Json:NBody:Richards ./Harness.som %(benchmark)s 1 " 15 | location: are-we-fast-yet/benchmarks/SOM 16 | max_invocation_time: 240 17 | benchmarks: &BENCHMARKS 18 | - DeltaBlue: 19 | extra_args: 1 20 | - Richards: 21 | extra_args: 1 22 | - Json: 23 | extra_args: 1 24 | - CD: 25 | extra_args: 10 26 | - Havlak: 27 | extra_args: 1 28 | 29 | - Bounce: 30 | extra_args: 1 31 | - List: 32 | extra_args: 1 33 | - Mandelbrot: 34 | extra_args: 1 35 | - NBody: 36 | extra_args: 1 37 | - Permute: 38 | extra_args: 1 39 | - Queens: 40 | extra_args: 1 41 | - Sieve: 42 | extra_args: 1 43 | - Storage: 44 | extra_args: 1 45 | - Towers: 46 | extra_args: 1 47 | 48 | executors: 49 | CSOM: 50 | path: . 51 | executable: CSOM 52 | args: " -H10 " 53 | 54 | experiments: 55 | test-awfy: 56 | description: | 57 | This is a test run of the Are We Fast Yet benchmarks. 58 | It's expected that the repository is located in the are-we-fast-yet folder. 59 | suites: 60 | - test-som 61 | executions: 62 | - CSOM 63 | -------------------------------------------------------------------------------- /build/Darwin.make: -------------------------------------------------------------------------------- 1 | unix.make -------------------------------------------------------------------------------- /build/Linux.make: -------------------------------------------------------------------------------- 1 | unix.make -------------------------------------------------------------------------------- /build/SunOS.make: -------------------------------------------------------------------------------- 1 | unix.make -------------------------------------------------------------------------------- /doc/CSOM.1: -------------------------------------------------------------------------------- 1 | .\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples. 2 | .\"See Also: 3 | .\"man mdoc.samples for a complete listing of options 4 | .\"man mdoc for the short list of editing options 5 | .\"/usr/share/misc/mdoc.template 6 | .\" $Id: CSOM.1 124 2007-10-09 19:54:03Z tobias.pape $ 7 | .Dd 11.07.2007 \" DATE 8 | .Dt CSOM 1 \" Program name and manual section number 9 | .Os Darwin 10 | .Sh NAME \" Section Header - required - don't modify 11 | .Nm CSOM 12 | .\" The following lines are read in generating the apropos(man -k) database. Use only key 13 | .\" words here as the database is built based on the words here and in the .ND line. 14 | .\".Nm Other_name_for_same_program(), 15 | .\".Nm Yet another name for the same program. 16 | .\" Use .Nm macro to designate other names for the documented program. 17 | .Nd a virtual machine for 18 | .Ar Simple Object Machine 19 | written in C 20 | .Sh SYNOPSIS \" Section Header - required - don't modify 21 | .Nm 22 | .\".Op Fl abcd \" [-abcd] 23 | .Fl cp Ar path 24 | .Op Fl d 25 | .Op Fl h 26 | .Oo 27 | .Op Ar path 28 | .Ar class ... 29 | .Oc 30 | .Sh DESCRIPTION \" Section Header - required - don't modify 31 | .Nm 32 | is a minimal Virtual Machine for the 33 | .Ar Simple Object Machine 34 | , a Smalltalk inspired programming language. It is written in 35 | .Ar C 36 | .Pp \" Inserts a space 37 | A list of items with descriptions: 38 | .Bl -tag -width -indent \" Begins a tagged list 39 | .It item a \" Each item preceded by .It macro 40 | Description of item a 41 | .It item b 42 | Description of item b 43 | .El \" Ends the list 44 | .Pp 45 | A list of flags and their descriptions: 46 | .Bl -tag -width -indent \" Differs from above in tag removed 47 | .It Fl a \"-a flag as a list item 48 | Description of -a flag 49 | .It Fl b 50 | Description of -b flag 51 | .El \" Ends the list 52 | .Pp 53 | .\" .Sh ENVIRONMENT \" May not be needed 54 | .\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1 55 | .\" .It Ev ENV_VAR_1 56 | .\" Description of ENV_VAR_1 57 | .\" .It Ev ENV_VAR_2 58 | .\" Description of ENV_VAR_2 59 | .\" .El 60 | .Sh FILES \" File used or created by the topic of the man page 61 | .Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact 62 | .It Pa /usr/share/file_name 63 | FILE_1 description 64 | .It Pa /Users/joeuser/Library/really_long_file_name 65 | FILE_2 description 66 | .El \" Ends the list 67 | .\" .Sh DIAGNOSTICS \" May not be needed 68 | .\" .Bl -diag 69 | .\" .It Diagnostic Tag 70 | .\" Diagnostic informtion here. 71 | .\" .It Diagnostic Tag 72 | .\" Diagnostic informtion here. 73 | .\" .El 74 | .Sh SEE ALSO 75 | .\" List links in ascending order by section, alphabetically within a section. 76 | .\" Please do not reference files that do not exist without filing a bug report 77 | .Xr a 1 , 78 | .Xr b 1 , 79 | .Xr c 1 , 80 | .Xr a 2 , 81 | .Xr b 2 , 82 | .Xr a 3 , 83 | .Xr b 3 84 | .\" .Sh BUGS \" Document known, unremedied bugs 85 | .\" .Sh HISTORY \" Document history if command behaves in a unique manner 86 | -------------------------------------------------------------------------------- /doc/ObjectModel.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SOM-st/CSOM/24c6956bc5c94bd39e571297243aa9da00426ddd/doc/ObjectModel.pdf -------------------------------------------------------------------------------- /doc/Primitives/Hello.som: -------------------------------------------------------------------------------- 1 | " Simple Object Machine 2 | $Id: Hello.som 792 2009-04-06 08:07:33Z michael.haupt $ 3 | 4 | Copyright (c) 2007 Michael Haupt, Tobias Pape 5 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 6 | http://www.hpi.uni-potsdam.de/swa/ 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the 'Software'), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | 26 | Primitives Test 27 | 28 | 29 | @include \'HelloDefine.h\' 30 | @include 31 | @include 32 | 33 | @init{ 34 | //init here 35 | }@ 36 | @fini{ 37 | // fini here 38 | }@ 39 | " 40 | 41 | Hello = ( 42 | "The 'run' method is called when initializing the system" 43 | run = ( 44 | 45 | 'Test no argument message' println. 46 | self helloWorld. 47 | 'Test one argument message' println. 48 | self makeNoise: 'Hello, world'. 49 | 'Test two argument message' println. 50 | self fastPrint: 'hello,' for: 5. 51 | 52 | 'Test return value and class method' println. 53 | Hello getSomeNumber println. 54 | Hello getSomeNumber println. 55 | Hello getSomeNumber println. 56 | 57 | 'Finished.' println. 58 | 59 | ) 60 | 61 | helloWorld = primitive "@ 62 | pVMObject self = (pVMObject)SEND(frame, pop); 63 | // test Define.. 64 | printf(\'Hello, World: %s\n\', A_STRING); 65 | SEND(frame, push, self); 66 | @" 67 | 68 | makeNoise: string = primitive "@ 69 | pVMString string = (pVMString)SEND(frame, pop); 70 | pVMObject self = (pVMObject)SEND(frame, pop); 71 | 72 | const char* s= SEND(string, get_chars); 73 | printf(\'Line noise following:\t\'); 74 | int len=strlen(s); 75 | int i, j; 76 | for(i=10;i<=50;i+=10) { 77 | for(j=0;j 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | 35 | #define A_STRING "muhhhhhhh" 36 | 37 | #endif // HELLODEFINE_H_ 38 | -------------------------------------------------------------------------------- /doc/Primitives/Makefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env make 2 | 3 | # 4 | # $Id: Makefile 95 2007-09-10 09:48:20Z tobias.pape $ 5 | # 6 | # Copyright (c) 2007 Michael Haupt, Tobias Pape 7 | # Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 8 | # http://www.hpi.uni-potsdam.de/swa/ 9 | # 10 | # Permission is hereby granted, free of charge, to any person obtaining a copy 11 | # of this software and associated documentation files (the "Software"), to deal 12 | # in the Software without restriction, including without limitation the rights 13 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | # copies of the Software, and to permit persons to whom the Software is 15 | # furnished to do so, subject to the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be included in 18 | # all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 26 | # THE SOFTWARE. 27 | 28 | 29 | #configure here. 30 | 31 | CLASSNAME :=Hello 32 | 33 | SRC_DIR =../../src 34 | INCLUDES =-I$(SRC_DIR) 35 | LIBS = 36 | OSTOOL_NAME:=ostool.exe 37 | SOM2LIB =$(SRC_DIR)/primitives/som2lib.rb 38 | 39 | 40 | # do not change anything beneath this line 41 | #============================================================================== 42 | 43 | ## we need c99! 44 | CC =gcc 45 | CFLAGS =-Wno-endif-labels -std=gnu99 $(DBG_FLAGS) $(OFLAGS) $(INCLUDES) 46 | LDFLAGS = 47 | 48 | INSTALL =install 49 | OSTOOL :=$(SRC_DIR)/$(OSTOOL_NAME) 50 | 51 | .SUFFIXES: .som .pic.o 52 | 53 | .som.c: 54 | $(SOM2LIB) $*.som 55 | 56 | .c.pic.o: 57 | $(CC) $(CFLAGS) -fPIC -g -c $< -o $*.pic.o 58 | 59 | all: PRIMITIVE 60 | 61 | PRIMITIVE: $(CLASSNAME).pic.o 62 | @echo Linking $(CLASSNAME) 63 | $(CC) $(LDFLAGS) `$(OSTOOL) l "$(CLASSNAME)"` \ 64 | -o `$(OSTOOL) s "$(CLASSNAME).som"` $(CLASSNAME).pic.o $(LIBS) 65 | @touch PRIMITIVE 66 | @echo Done. 67 | 68 | $(OSTOOL): 69 | $(MAKE) -C $(INCLUDES) $(OSTOOL_NAME) -------------------------------------------------------------------------------- /doc/common.tex: -------------------------------------------------------------------------------- 1 | % 2 | % common defintions for CSOM documentation LaTeX files. 3 | % 4 | % $Id: common.tex 170 2008-01-03 15:27:10Z tobias.pape $ 5 | % 6 | 7 | 8 | \usepackage[english]{babel} 9 | \usepackage[utf8x]{inputenc} 10 | \usepackage[T1]{fontenc} 11 | \usepackage{xspace} 12 | \usepackage{listings} 13 | \usepackage{color} 14 | \definecolor{darkblue}{rgb}{0,0,0.4} 15 | \definecolor{darkgreen}{rgb}{0,0.5,0.5} 16 | \definecolor{middlegray}{rgb}{0.5,0.5,0.5} 17 | \definecolor{lightgray}{rgb}{0.8,0.8,0.8} 18 | \definecolor{orange}{rgb}{0.8,0.3,0.3} 19 | \definecolor{yac}{rgb}{0.6,0.6,0.1} 20 | 21 | 22 | \lstdefinelanguage{SOM}{ 23 | morekeywords={true,false,self,super,nil}, 24 | morekeywords=[2]{primitive}, 25 | otherkeywords={^,.}, 26 | sensitive=true, 27 | morecomment=[s]{"}{"}, 28 | morestring=[d]', 29 | } 30 | 31 | \lstloadlanguages{C,[gnu]make}% 32 | \lstset{language=C,% 33 | basicstyle=\ttfamily\scriptsize\color{darkblue}, 34 | keywordstyle=\ttfamily\scriptsize\bfseries\color{yac}, 35 | keywordstyle=[2]\ttfamily\scriptsize\bfseries\color{orange}, 36 | stringstyle=\sffamily\scriptsize\color{darkgreen}, 37 | commentstyle=\rmfamily\scriptsize\color{middlegray}, 38 | % mathescape, 39 | % emph={square}, 40 | % emphstyle=\ttfamily, 41 | % emph={[2]root,base}, 42 | % emphstyle={[2]\ttfamily}, 43 | % showstringspaces=false, 44 | % flexiblecolumns=false, 45 | % tabsize=4, 46 | % numbers=left, 47 | % numberstyle=\tiny, 48 | % % numberblanklines=false, 49 | % stepnumber=1, 50 | % numbersep=5pt 51 | } 52 | 53 | \newcommand{\ignore}[1]{} 54 | 55 | % Logo Font 56 | %\font\logo=logo10 57 | 58 | \newcommand{\CSOM}{{\scshape CSOM}\xspace} 59 | \newcommand{\SOM}{{\scshape SOM}\xspace} 60 | \newcommand{\C}{{\bfseries\ttfamily C}\xspace} 61 | \newcommand{\class}[2]{{\texttt{{#1}::}\textbf{{#2}}}} 62 | \newcommand{\file}[1]{\texttt{{#1}}} 63 | \newcommand{\dir}[1]{\texttt{{#1}/}} 64 | 65 | %%% Local Variables: 66 | %%% mode: latex 67 | %%% End: 68 | -------------------------------------------------------------------------------- /doc/glossary.tex: -------------------------------------------------------------------------------- 1 | \section{Glossary} 2 | \label{sec:glossary} 3 | 4 | 5 | \begin{description} 6 | \item[bytecode] A bytecode 7 | \item[bytecode index] short: bc\_idx 8 | \item[class] The word ``class'' can refer to two distinct 9 | interpretations: 10 | \begin{enumerate} 11 | \item OO class \emph{or \C class} 12 | \item \SOM class 13 | \end{enumerate} 14 | \item[\C class] The combination of a \C \lstinline|struct| defining 15 | data fields, a VTABLE defintion, prototypes of ``class methods'' and the corresponding 16 | implementations. 17 | 18 | A class shall be refered to by its component name and its class name; 19 | thus \class{vmobjects}{VMObject} would refer to the files 20 | \file{src/vmobjects/VMObject.h} (containing the \lstinline|struct| 21 | defintions and class method prototypes) and 22 | \file{src/vmobject/VMObject.c} (containing the methods' implentations 23 | and the VTABLE). 24 | \item[\CSOM] This can refer 25 | \begin{enumerate} 26 | \item to the entire project ``\CSOM'', 27 | \item to the project's entire code base, 28 | \item or to the compiled VM binary file ``\CSOM'', which can be 29 | located either in the \dir{src} or the \dir{build} directory. 30 | \end{enumerate} 31 | \item[frame]~ 32 | \item[object]~ 33 | \item[OO]~ 34 | \item[Object Model]~ 35 | \item[OO Object] These terms refer to the ``Object Model'' used 36 | throughout \CSOM. 37 | \item[Primitive] A ``primitive'' may refer to different meanings: 38 | \begin{enumerate} 39 | \item The \lstinline[language=SOM]|primitive|-Keyword of the \SOM language 40 | \item A \SOM method, which is solely defined though the keyword mentioned 41 | \item A single \C function located in an external binary file which is linked 42 | to a \SOM method on or after compiling. 43 | \item A colletion of such \C funtions in a binary dynamically loadable library. 44 | \end{enumerate} 45 | \item[\SOM class] A ``\SOM class'' is a class defined in the \SOM language, 46 | written to a file. When loaded, it is represented by an instance of 47 | \class{vmobjects}{VMClass}. 48 | \item[string]~ 49 | \item[String] An instance of \class{misc}{String}. This is an OO-capable 50 | wrapper around C-strings. They shall be used in favor of C-strings. 51 | \item[C-string] a `$\backslash 0$'-terminated sequence of bytes. Don't 52 | rely on signedness of them. Their direct use is discouraged. Use 53 | (OO-)Strings instead. 54 | \item[Trait] 55 | A trait consits of a VTABLE and an empty (except the VTABLE 56 | pointer) Object definition with corresponding method implementations. 57 | 58 | To assign a trait to classes, use\\ 59 | \lstinline|ASSIGN_TRAIT(aTrait, aClass)| \\ 60 | in their VTABLE-functions. 61 | 62 | 63 | Use \lstinline|TSEND(aTrait, anObject, aMessage, ...)| to send an 64 | trait-message to an object. \\ 65 | Do not use \lstinline|SEND|. 66 | 67 | Use \lstinline|SUPPORTS(anObject, aTrait)| to check, whether an object 68 | supports an specific interfaces. 69 | 70 | Currenty, a class can only support one trait at a time. But each 71 | trait would be able to support another trait via the same mechanism of 72 | \lstinline|ASSIGN_TRAIT|. 73 | 74 | See \class{vmobjects}{VMInvokable} for a trait implementation example and 75 | \class{vmobjects}{VMPrimitive} and \class{vmobjects}{VMMethod} for examples of 76 | trait usage. \\ 77 | The macros mentioned are defined in \file{src/vmobjects/OOObject.h}. 78 | 79 | This whole concept may change in the future. 80 | \item[vtable] see virtual method table 81 | \item[VTABLE] see virtual method table 82 | \item[virtual method table] A structure unique to each individual 83 | class containing \C function pointers. 84 | \end{description} 85 | -------------------------------------------------------------------------------- /doc/tab.c: -------------------------------------------------------------------------------- 1 | // not this 2 | void foo(void) { 3 | int i; 4 | if(a==...) { 5 | while(true) { 6 | ... 7 | } 8 | ... 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /rebench.conf: -------------------------------------------------------------------------------- 1 | # -*- mode: yaml -*- 2 | # Config file for ReBench 3 | default_experiment: all 4 | default_data_file: 'rebench.data' 5 | 6 | reporting: 7 | # Benchmark results will be reported to ReBenchDB 8 | rebenchdb: 9 | # this url needs to point to the API endpoint 10 | db_url: https://rebench.stefan-marr.de/rebenchdb 11 | repo_url: https://github.com/smarr/CSOM 12 | record_all: true # make sure everything is recorded 13 | project_name: CSOM 14 | 15 | runs: 16 | max_invocation_time: 60 17 | 18 | benchmark_suites: 19 | macro: 20 | gauge_adapter: RebenchLog 21 | command: &MACRO_CMD "-cp Smalltalk:Examples/Benchmarks/Richards:Examples/Benchmarks/DeltaBlue:Examples/Benchmarks/NBody:Examples/Benchmarks/Json:Examples/Benchmarks/GraphSearch Examples/Benchmarks/BenchmarkHarness.som %(benchmark)s %(iterations)s 0 " 22 | iterations: 10 23 | benchmarks: 24 | - Richards: {extra_args: 1} 25 | - DeltaBlue: {extra_args: 50} 26 | - NBody: {extra_args: 500} 27 | - JsonSmall: {extra_args: 1} 28 | - GraphSearch: {extra_args: 4} 29 | - PageRank: {extra_args: 40} 30 | 31 | micro: 32 | gauge_adapter: RebenchLog 33 | command: "-cp Smalltalk:Examples/Benchmarks/LanguageFeatures Examples/Benchmarks/BenchmarkHarness.som %(benchmark)s %(iterations)s 0 " 34 | iterations: 10 35 | benchmarks: 36 | - Fannkuch: {extra_args: 6} 37 | - Fibonacci: {extra_args: 3} 38 | - Dispatch: {extra_args: 2} 39 | - Bounce: {extra_args: 2} 40 | - Loop: {extra_args: 5} 41 | - Permute: {extra_args: 3} 42 | - Queens: {extra_args: 2} 43 | - List: {extra_args: 2} 44 | - Recurse: {extra_args: 3} 45 | - Storage: {extra_args: 1} 46 | - Sieve: {extra_args: 4} 47 | - BubbleSort: {extra_args: 3} 48 | - QuickSort: {extra_args: 1} 49 | - Sum: {extra_args: 2} 50 | - Towers: {extra_args: 2} 51 | - TreeSort: {extra_args: 1} 52 | - IntegerLoop: {extra_args: 2} 53 | - FieldLoop: {extra_args: 1} 54 | - WhileLoop: {extra_args: 10} 55 | - Mandelbrot: {extra_args: 30} 56 | 57 | executors: 58 | CSOM: 59 | path: . 60 | executable: CSOM 61 | 62 | # define the benchmarks to be executed for a re-executable benchmark run 63 | experiments: 64 | CSOM: 65 | description: All benchmarks on CSOM 66 | suites: 67 | - micro 68 | - macro 69 | executions: 70 | - CSOM 71 | -------------------------------------------------------------------------------- /som-em.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | SCRIPT_PATH=`dirname $0` 3 | exec node ${SCRIPT_PATH}/CSOM.js "$@" 4 | -------------------------------------------------------------------------------- /som.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | SCRIPT_PATH=`dirname $0` 3 | exec ${SCRIPT_PATH}/CSOM "$@" 4 | -------------------------------------------------------------------------------- /src/compiler/BytecodeGeneration.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: BytecodeGeneration.c 792 2009-04-06 08:07:33Z michael.haupt $ 3 | * 4 | Copyright (c) 2007 Michael Haupt, Tobias Pape 5 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 6 | http://www.hpi.uni-potsdam.de/swa/ 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | #include "BytecodeGeneration.h" 28 | #include "GenerationContexts.h" 29 | 30 | #include 31 | 32 | #include 33 | 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #define CHECK_BC_SIZE(N) \ 41 | if((N) > GEN_BC_SIZE) { \ 42 | char* s = (char*)internal_allocate(1024); \ 43 | sprintf(s, "Method %s>>%s is too long.", \ 44 | mgenc->holder_genc->name->chars, \ 45 | mgenc->signature->chars); \ 46 | Universe_error_exit(s); \ 47 | } 48 | 49 | #define EMIT1(BC) \ 50 | CHECK_BC_SIZE(mgenc->bp+1); \ 51 | mgenc->bytecode[mgenc->bp++] = (BC) 52 | 53 | #define EMIT2(BC, IDX) \ 54 | CHECK_BC_SIZE(mgenc->bp+2); \ 55 | mgenc->bytecode[mgenc->bp++] = (BC); \ 56 | mgenc->bytecode[mgenc->bp++] = (IDX) 57 | 58 | #define EMIT3(BC, IDX, CTX) \ 59 | CHECK_BC_SIZE(mgenc->bp+3); \ 60 | mgenc->bytecode[mgenc->bp++] = (BC); \ 61 | mgenc->bytecode[mgenc->bp++] = (IDX); \ 62 | mgenc->bytecode[mgenc->bp++] = (CTX) 63 | 64 | 65 | void emit_HALT(method_generation_context* mgenc) { 66 | EMIT1(BC_HALT); 67 | } 68 | 69 | 70 | void emit_DUP(method_generation_context* mgenc) { 71 | EMIT1(BC_DUP); 72 | } 73 | 74 | 75 | void emit_PUSH_LOCAL(method_generation_context* mgenc, size_t idx, size_t ctx) { 76 | EMIT3(BC_PUSH_LOCAL, idx, ctx); 77 | } 78 | 79 | 80 | void emit_PUSH_ARGUMENT(method_generation_context* mgenc, size_t idx, size_t ctx) { 81 | EMIT3(BC_PUSH_ARGUMENT, idx, ctx); 82 | } 83 | 84 | 85 | void emit_PUSH_FIELD(method_generation_context* mgenc, pVMSymbol field) { 86 | EMIT2(BC_PUSH_FIELD, SEND(mgenc->literals, indexOf, field)); 87 | } 88 | 89 | 90 | void emit_PUSH_BLOCK(method_generation_context* mgenc, pVMMethod block) { 91 | EMIT2(BC_PUSH_BLOCK, SEND(mgenc->literals, indexOf, block)); 92 | } 93 | 94 | 95 | void emit_PUSH_CONSTANT(method_generation_context* mgenc, pVMObject cst) { 96 | EMIT2(BC_PUSH_CONSTANT, SEND(mgenc->literals, indexOf, cst)); 97 | } 98 | 99 | 100 | void emit_PUSH_CONSTANT_String( 101 | method_generation_context* mgenc, 102 | pVMString str 103 | ) { 104 | const char* string = SEND(str, get_rawChars); 105 | size_t length = SEND(str, get_length); 106 | EMIT2(BC_PUSH_CONSTANT, SEND(mgenc->literals, indexOfStringLen, string, length)); 107 | } 108 | 109 | 110 | void emit_PUSH_GLOBAL(method_generation_context* mgenc, pVMSymbol global) { 111 | EMIT2(BC_PUSH_GLOBAL, SEND(mgenc->literals, indexOf, global)); 112 | } 113 | 114 | 115 | void emit_POP(method_generation_context* mgenc) { 116 | EMIT1(BC_POP); 117 | } 118 | 119 | 120 | void emit_POP_LOCAL(method_generation_context* mgenc, size_t idx, size_t ctx) { 121 | EMIT3(BC_POP_LOCAL, idx, ctx); 122 | } 123 | 124 | 125 | void emit_POP_ARGUMENT(method_generation_context* mgenc, size_t idx, size_t ctx) { 126 | EMIT3(BC_POP_ARGUMENT, idx, ctx); 127 | } 128 | 129 | 130 | void emit_POP_FIELD(method_generation_context* mgenc, pVMSymbol field) { 131 | EMIT2(BC_POP_FIELD, SEND(mgenc->literals, indexOf, field)); 132 | } 133 | 134 | 135 | void emit_SEND(method_generation_context* mgenc, pVMSymbol msg) { 136 | EMIT2(BC_SEND, method_genc_find_literal_index(mgenc, (pVMObject)msg)); 137 | } 138 | 139 | 140 | void emit_SUPER_SEND(method_generation_context* mgenc, pVMSymbol msg) { 141 | EMIT2(BC_SUPER_SEND, method_genc_find_literal_index(mgenc, (pVMObject)msg)); 142 | } 143 | 144 | 145 | void emit_RETURN_LOCAL(method_generation_context* mgenc) { 146 | EMIT1(BC_RETURN_LOCAL); 147 | } 148 | 149 | 150 | void emit_RETURN_NON_LOCAL(method_generation_context* mgenc) { 151 | EMIT1(BC_RETURN_NON_LOCAL); 152 | } 153 | -------------------------------------------------------------------------------- /src/compiler/BytecodeGeneration.h: -------------------------------------------------------------------------------- 1 | #ifndef BYTECODEGENERATION_H_ 2 | #define BYTECODEGENERATION_H_ 3 | 4 | /* 5 | * $Id: BytecodeGeneration.h 792 2009-04-06 08:07:33Z michael.haupt $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "GenerationContexts.h" 38 | 39 | 40 | void emit_HALT(method_generation_context* mgenc); 41 | void emit_DUP(method_generation_context* mgenc); 42 | void emit_PUSH_LOCAL(method_generation_context* mgenc, size_t idx, size_t ctx); 43 | void emit_PUSH_ARGUMENT(method_generation_context* mgenc, size_t idx, size_t ctx); 44 | void emit_PUSH_FIELD(method_generation_context* mgenc, pVMSymbol field); 45 | void emit_PUSH_BLOCK(method_generation_context* mgenc, pVMMethod block); 46 | void emit_PUSH_CONSTANT(method_generation_context* mgenc, pVMObject cst); 47 | void emit_PUSH_CONSTANT_String(method_generation_context* mgenc, pVMString str); 48 | void emit_PUSH_GLOBAL(method_generation_context* mgenc, pVMSymbol global); 49 | void emit_POP(method_generation_context* mgenc); 50 | void emit_POP_LOCAL(method_generation_context* mgenc, size_t idx, size_t ctx); 51 | void emit_POP_ARGUMENT(method_generation_context* mgenc, size_t idx, size_t ctx); 52 | void emit_POP_FIELD(method_generation_context* mgenc, pVMSymbol field); 53 | void emit_SEND(method_generation_context* mgenc, pVMSymbol msg); 54 | void emit_SUPER_SEND(method_generation_context* mgenc, pVMSymbol msg); 55 | void emit_RETURN_LOCAL(method_generation_context* mgenc); 56 | void emit_RETURN_NON_LOCAL(method_generation_context* mgenc); 57 | 58 | 59 | #endif // BYTECODEGENERATION_H_ 60 | -------------------------------------------------------------------------------- /src/compiler/Disassembler.h: -------------------------------------------------------------------------------- 1 | #ifndef DISASSEMBELR_H_ 2 | #define DISASSEMBELR_H_ 3 | 4 | /* 5 | * $Id: Disassembler.h 114 2007-09-19 09:45:37Z tobias.pape $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | void Disassembler_dump(pVMClass class); 35 | void Disassembler_dump_method(pVMMethod method, const char* indent); 36 | void Disassembler_dump_bytecode(pVMFrame frame, pVMMethod method, size_t bc_idx); 37 | 38 | #endif // DISASSEMBELR_H_ 39 | 40 | -------------------------------------------------------------------------------- /src/compiler/GenerationContexts.h: -------------------------------------------------------------------------------- 1 | #ifndef GENERATIONCONTEXTS_H_ 2 | #define GENERATIONCONTEXTS_H_ 3 | 4 | /* 5 | * $Id: GenerationContexts.h 792 2009-04-06 08:07:33Z michael.haupt $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | 35 | #include 36 | 37 | 38 | typedef struct _class_generation_context { 39 | pVMSymbol name; 40 | pVMSymbol super_name; 41 | bool class_side; 42 | pList instance_fields; 43 | pList instance_methods; 44 | pList class_fields; 45 | pList class_methods; 46 | } class_generation_context; 47 | 48 | 49 | #define GEN_BC_SIZE 1024 50 | 51 | // declare forward 52 | struct _method_generation_context; 53 | typedef struct _method_generation_context method_generation_context; 54 | 55 | struct _method_generation_context { 56 | class_generation_context* holder_genc; 57 | method_generation_context* outer_genc; 58 | bool block_method; 59 | pVMSymbol signature; 60 | pList arguments; 61 | bool primitive; 62 | pList locals; 63 | pList literals; 64 | bool finished; 65 | uint32_t bp; 66 | uint8_t bytecode[GEN_BC_SIZE]; 67 | }; 68 | 69 | 70 | void class_genc_init(class_generation_context* cgenc); 71 | void class_genc_release(class_generation_context* cgenc); 72 | void class_genc_set_instance_fields_of_super(class_generation_context* cgenc, pVMArray fields); 73 | void class_genc_set_class_fields_of_super(class_generation_context* cgenc, pVMArray fields); 74 | 75 | void method_genc_init(method_generation_context* mgenc); 76 | void method_genc_release(method_generation_context* mgenc); 77 | int8_t method_genc_find_literal_index( 78 | method_generation_context* mgenc, 79 | pVMObject literal 80 | ); 81 | bool method_genc_find_var( 82 | method_generation_context* mgenc, 83 | pString var, 84 | size_t* index, 85 | size_t* context, 86 | bool* is_argument 87 | ); 88 | bool method_genc_find_field(method_generation_context* mgenc, pString field); 89 | uint8_t method_genc_compute_stack_depth(method_generation_context* mgenc); 90 | 91 | bool method_genc_has_bytecodes(method_generation_context* mgenc); 92 | 93 | #endif // GENERATIONCONTEXTS_H_ 94 | -------------------------------------------------------------------------------- /src/compiler/Lexer.h: -------------------------------------------------------------------------------- 1 | #ifndef LEXER_H_ 2 | #define LEXER_H_ 3 | 4 | /* 5 | Copyright (c) 2019 Stefan Marr 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 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | 33 | typedef enum { 34 | NONE, Integer, Double, Not, And, Or, Star, Div, Mod, Plus, 35 | Minus, Equal, More, Less, Comma, At, Per, NewBlock, 36 | EndBlock, Colon, Period, Exit, Assign, NewTerm, EndTerm, Pound, 37 | Primitive, Separator, STString, Identifier, Keyword, KeywordSequence, 38 | OperatorSequence 39 | } Symbol; 40 | 41 | 42 | extern const char* const symnames[]; 43 | 44 | typedef struct { 45 | FILE* infile; 46 | const char* file_name; 47 | 48 | int line_num; 49 | Symbol sym; 50 | char symc; 51 | char _text[BUFSIZ]; 52 | size_t _textLength; 53 | 54 | bool peekDone; 55 | Symbol nextSym; 56 | char nextSymc; 57 | char _nextText[BUFSIZ]; 58 | size_t _nextTextLength; 59 | 60 | char buf[BUFSIZ]; 61 | int bufp; 62 | } Lexer; 63 | 64 | Lexer* Lexer_create(const FILE* fp, const char* fname); 65 | Lexer* Lexer_from_string(const char* stream); 66 | 67 | Symbol Lexer_get_sym(Lexer* l); 68 | pString Lexer_get_text(Lexer* l); 69 | void Lexer_consumed_text(Lexer* l); 70 | 71 | void Lexer_peek(Lexer* l); 72 | void Lexer_peek_if_necessary(Lexer* l); 73 | 74 | #define _ISOP(C) \ 75 | ((C) == '~' || (C) == '&' || (C) == '|' || (C) == '*' || (C) == '/' || \ 76 | (C) == '\\' || (C) == '+' || (C) == '=' || (C) == '>' || (C) == '<' || \ 77 | (C) == ',' || (C) == '@' || (C) == '%' || (C) == '-') 78 | 79 | 80 | #endif // LEXER_H_ 81 | -------------------------------------------------------------------------------- /src/compiler/Parser.h: -------------------------------------------------------------------------------- 1 | #ifndef PARSER_H_ 2 | #define PARSER_H_ 3 | 4 | /* 5 | * $Id: Parser.h 792 2009-04-06 08:07:33Z michael.haupt $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | 38 | #include "GenerationContexts.h" 39 | #include "Lexer.h" 40 | 41 | 42 | Lexer* Parser_init(const FILE* fp, const char* fname); 43 | Lexer* Parser_init_string(const char* stream); 44 | void Parser_classdef(Lexer* l, class_generation_context* cgenc); 45 | 46 | void Parser_init_constants(void); 47 | 48 | #endif // PARSER_H_ 49 | -------------------------------------------------------------------------------- /src/compiler/SourcecodeCompiler.h: -------------------------------------------------------------------------------- 1 | #ifndef SOURCECODECOMPILER_H_ 2 | #define SOURCECODECOMPILER_H_ 3 | 4 | /* 5 | * $Id: SourcecodeCompiler.h 792 2009-04-06 08:07:33Z michael.haupt $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | 33 | pVMClass SourcecodeCompiler_compile_class(const char* path, 34 | size_t pathLength, 35 | const char* filename, 36 | size_t filenameLength, 37 | pVMClass system_class); 38 | pVMClass SourcecodeCompiler_compile_class_string(const char* stream, 39 | pVMClass system_class); 40 | 41 | 42 | #endif // SOURCECODECOMPILER_H_ 43 | -------------------------------------------------------------------------------- /src/interpreter/Interpreter.h: -------------------------------------------------------------------------------- 1 | #ifndef INTERPRETER_H_ 2 | #define INTERPRETER_H_ 3 | 4 | /* 5 | * $Id: Interpreter.h 116 2007-09-20 13:29:40Z tobias.pape $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | void Interpreter_initialize(pVMObject nilObject); 35 | void Interpreter_start(void); 36 | pVMFrame Interpreter_push_new_frame(pVMMethod method, pVMFrame context); 37 | void Interpreter_set_frame(pVMFrame frame); 38 | pVMFrame Interpreter_get_frame(void); 39 | pVMMethod Interpreter_get_method(void); 40 | pVMObject Interpreter_get_self(void); 41 | 42 | #endif // INTERPRETER_H_ 43 | -------------------------------------------------------------------------------- /src/interpreter/bytecodes.h: -------------------------------------------------------------------------------- 1 | #ifndef BYTECODES_H_ 2 | #define BYTECODES_H_ 3 | 4 | /* 5 | * $Id: bytecodes.h 134 2007-11-16 23:27:17Z tobias.pape $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | // bytecode constants used by CSOM 33 | 34 | #define BC_HALT 0 35 | #define BC_DUP 1 36 | #define BC_PUSH_LOCAL 2 37 | #define BC_PUSH_ARGUMENT 3 38 | #define BC_PUSH_FIELD 4 39 | #define BC_PUSH_BLOCK 5 40 | #define BC_PUSH_CONSTANT 6 41 | #define BC_PUSH_GLOBAL 7 42 | #define BC_POP 8 43 | #define BC_POP_LOCAL 9 44 | #define BC_POP_ARGUMENT 10 45 | #define BC_POP_FIELD 11 46 | #define BC_SEND 12 47 | #define BC_SUPER_SEND 13 48 | #define BC_RETURN_LOCAL 14 49 | #define BC_RETURN_NON_LOCAL 15 50 | 51 | // bytecode lengths 52 | 53 | //TODO: put into own module. 54 | 55 | static const uint8_t bytecode_lengths[] = { 56 | 1, // BC_HALT 57 | 1, // BC_DUP 58 | 3, // BC_PUSH_LOCAL 59 | 3, // BC_PUSH_ARGUMENT 60 | 2, // BC_PUSH_FIELD 61 | 2, // BC_PUSH_BLOCK 62 | 2, // BC_PUSH_CONSTANT 63 | 2, // BC_PUSH_GLOBAL 64 | 1, // BC_POP 65 | 3, // BC_POP_LOCAL 66 | 3, // BC_POP_ARGUMENT 67 | 2, // BC_POP_FIELD 68 | 2, // BC_SEND 69 | 2, // BC_SUPER_SEND 70 | 1, // BC_RETURN_LOCAL 71 | 1 // BC_RETURN_NON_LOCAL 72 | }; 73 | 74 | static const char* bytecode_names[] = { 75 | "HALT ", 76 | "DUP ", 77 | "PUSH_LOCAL ", 78 | "PUSH_ARGUMENT ", 79 | "PUSH_FIELD ", 80 | "PUSH_BLOCK ", 81 | "PUSH_CONSTANT ", 82 | "PUSH_GLOBAL ", 83 | "POP ", 84 | "POP_LOCAL ", 85 | "POP_ARGUMENT ", 86 | "POP_FIELD ", 87 | "SEND ", 88 | "SUPER_SEND ", 89 | "RETURN_LOCAL ", 90 | "RETURN_NON_LOCAL" 91 | }; 92 | 93 | static inline char* bytecodes_get_bytecode_name(uint8_t bc) { 94 | return (char*)bytecode_names[bc]; 95 | } 96 | 97 | static inline uint8_t bytecodes_get_bytecode_length(uint8_t bc) { 98 | return bytecode_lengths[bc];// Return the length of the given bytecode 99 | } 100 | 101 | #endif // BYTECODES_H_ 102 | 103 | 104 | -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: main.c 792 2009-04-06 08:07:33Z michael.haupt $ 3 | * 4 | Copyright (c) 2007 Michael Haupt, Tobias Pape 5 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 6 | http://www.hpi.uni-potsdam.de/swa/ 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | 33 | int main(int argc, char** argv) { 34 | printf("This is CSOM.\n"); 35 | Parser_init_constants(); 36 | 37 | int vm_argc = 0; 38 | const char** vm_argv = 39 | Universe_handle_arguments(&vm_argc, argc, (const char**)argv); 40 | Universe_start(vm_argc, (const char**)vm_argv); 41 | 42 | FREE_ARRAY_ELEMENTS((char**)vm_argv, vm_argc); // the array itself is still part of argv, i.e., on the c-stack 43 | 44 | Universe_exit(ERR_SUCCESS); 45 | } 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/memory/gc.h: -------------------------------------------------------------------------------- 1 | #ifndef GC_H_ 2 | #define GC_H_ 3 | 4 | /* 5 | * $Id: gc.h 792 2009-04-06 08:07:33Z michael.haupt $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | 35 | 36 | /* 37 | * macro for padding - only word-aligned memory must be allocated 38 | */ 39 | #define PAD_BYTES(N) ((sizeof(void*) - ((N) % sizeof(void*))) % sizeof(void*)) 40 | 41 | 42 | /* 43 | * The heap size can be set on VM startup. The argument passed to this function 44 | * represents the dedicated heap size in MB. 45 | */ 46 | void gc_set_heap_size(uint32_t heap_size); 47 | 48 | 49 | void gc_mark_object(void* _self); 50 | 51 | 52 | void gc_collect(void); 53 | void gc_start_uninterruptable_allocation(void); 54 | void gc_end_uninterruptable_allocation(void); 55 | 56 | 57 | void* gc_allocate(size_t size); 58 | void* gc_allocate_object(size_t size); 59 | char* gc_allocate_string(const char* restrict str); 60 | void gc_free(void* ptr); 61 | 62 | 63 | void gc_stat(void); 64 | 65 | void gc_initialize(void); 66 | void gc_finalize(void); 67 | 68 | 69 | void* internal_allocate(size_t size); 70 | void internal_free(void* ptr); 71 | 72 | 73 | #endif // GC_H_ 74 | 75 | 76 | -------------------------------------------------------------------------------- /src/misc/Hashmap.h: -------------------------------------------------------------------------------- 1 | #ifndef HASHMAP_H_ 2 | #define HASHMAP_H_ 3 | 4 | /* 5 | * $Id: Hashmap.h 168 2008-01-03 14:05:26Z tobias.pape $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | 35 | 36 | #pragma mark ** Hashmap Element 37 | 38 | 39 | #pragma mark VTable definition 40 | 41 | 42 | VTABLE(HashmapElem) { 43 | #define HASHMAPELEM_VTABLE_FORMAT \ 44 | OOOBJECT_VTABLE_FORMAT; \ 45 | int64_t (*key_hash)(void*); \ 46 | bool (*key_equal_to)(void*,void*) 47 | 48 | HASHMAPELEM_VTABLE_FORMAT; 49 | }; 50 | 51 | 52 | #pragma mark class definition 53 | 54 | 55 | struct _HashmapElem { 56 | VTABLE(HashmapElem)* _vtable; 57 | #define HASHMAPELEM_FORMAT \ 58 | OOOBJECT_FORMAT; \ 59 | void* key; \ 60 | void* value 61 | 62 | HASHMAPELEM_FORMAT; 63 | }; 64 | 65 | 66 | #pragma mark class methods 67 | 68 | 69 | pHashmapElem HashmapElem_new(void* key, void* value); 70 | 71 | 72 | #pragma mark vtable initialization 73 | 74 | 75 | VTABLE(HashmapElem)* HashmapElem_vtable(void); 76 | 77 | 78 | #pragma mark ** Hashmap 79 | 80 | 81 | #pragma mark VTable definition 82 | 83 | 84 | // 85 | // The hash map implemented here for VM-internal purposes provides two different 86 | // ways for putting and getting elements. Keys are "ordinary" VM objects 87 | // (i.e., instances of heirs of OOObject). 88 | // 89 | 90 | 91 | VTABLE(Hashmap) { 92 | #define HASHMAP_VTABLE_FORMAT \ 93 | OOOBJECT_VTABLE_FORMAT; \ 94 | void (*put)(void*, void* key, void* value); \ 95 | void* (*get)(void*, void* key); \ 96 | bool (*contains_key)(void*, void* key); \ 97 | void (*clear)(void*); \ 98 | void (*rehash)(void*, size_t newSize) 99 | 100 | HASHMAP_VTABLE_FORMAT; 101 | }; 102 | 103 | 104 | #pragma mark class definition 105 | 106 | 107 | #define HASHMAP_DEFAULT_SIZE 101 108 | 109 | 110 | struct _Hashmap { 111 | VTABLE(Hashmap)* _vtable; 112 | #define HASHMAP_FORMAT \ 113 | OOOBJECT_FORMAT; \ 114 | size_t size; \ 115 | pHashmapElem* elems 116 | 117 | HASHMAP_FORMAT; 118 | }; 119 | 120 | 121 | // 122 | // forward declaration of Hashmap Class Methods goes here 123 | // 124 | 125 | 126 | #pragma mark class methods 127 | 128 | 129 | pHashmap Hashmap_new(void); 130 | 131 | 132 | #pragma mark vtable initialization 133 | 134 | 135 | VTABLE(Hashmap)* Hashmap_vtable(void); 136 | 137 | 138 | #endif // HASHMAP_H_ 139 | -------------------------------------------------------------------------------- /src/misc/List.h: -------------------------------------------------------------------------------- 1 | #ifndef LIST_H_ 2 | #define LIST_H_ 3 | 4 | /* 5 | * $Id: List.h 792 2009-04-06 08:07:33Z michael.haupt $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | #include 33 | 34 | 35 | #pragma mark VTable definition 36 | 37 | 38 | VTABLE(List) { 39 | #define LIST_VTABLE_FORMAT \ 40 | OOOBJECT_VTABLE_FORMAT; \ 41 | void (*add)(void*, void* ptr); \ 42 | void (*addString)(void*, pString str); \ 43 | void (*addIfAbsent)(void*, void* ptr); \ 44 | void (*addStringIfAbsent)(void*, pString str); \ 45 | void (*addAll)(void*, pList list); \ 46 | void (*clear)(void*); \ 47 | void (*deep_free)(void*); \ 48 | size_t (*indexOf)(void*, void* ptr); \ 49 | size_t (*indexOfString)(void*, pString str); \ 50 | size_t (*indexOfStringLen)(void*, const char* restrict str, size_t length); \ 51 | size_t (*size)(void*); \ 52 | void* (*get)(void*, size_t index) 53 | 54 | LIST_VTABLE_FORMAT; 55 | }; 56 | 57 | 58 | #pragma mark class definition 59 | 60 | 61 | typedef struct _ListElem ListElem, *pListElem; 62 | 63 | 64 | struct _List { 65 | VTABLE(List)* _vtable; 66 | #define LIST_FORMAT \ 67 | OOOBJECT_FORMAT; \ 68 | size_t size; \ 69 | pListElem head; \ 70 | pListElem last 71 | 72 | LIST_FORMAT; 73 | }; 74 | 75 | 76 | // 77 | // forward declaration of List Class Methods goes here 78 | // 79 | 80 | 81 | #pragma mark class methods 82 | 83 | 84 | pList List_new(void); 85 | 86 | 87 | #pragma mark vtable initialization 88 | 89 | 90 | VTABLE(List)* List_vtable(void); 91 | 92 | 93 | #endif // LIST_H_ 94 | -------------------------------------------------------------------------------- /src/misc/String.h: -------------------------------------------------------------------------------- 1 | #ifndef STRING_H_ 2 | #define STRING_H_ 3 | 4 | /* 5 | * $Id: String.h 168 2008-01-03 14:05:26Z tobias.pape $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | #include 33 | 34 | #include 35 | 36 | 37 | #pragma mark VTable definition 38 | 39 | 40 | VTABLE(String) { 41 | #define STRING_VTABLE_FORMAT \ 42 | OOOBJECT_VTABLE_FORMAT; \ 43 | size_t (*length)(void*); \ 44 | const char* (*rawChars)(void*); \ 45 | int (*compareTo)(void*, pString other); \ 46 | pString (*concat)(void*, pString other); \ 47 | pString (*concatChars)(void*, const char* restrict other, size_t length); \ 48 | intptr_t (*indexOf)(void*, pString pattern); \ 49 | intptr_t (*indexOfChar)(void*, char pattern); \ 50 | intptr_t (*lastIndexOfChar)(void*, char pattern); \ 51 | int (*charAt)(void*, size_t position); \ 52 | pString (*substring)(void*, size_t start, size_t end); \ 53 | pVMInteger (*toInteger)(void*); \ 54 | pVMDouble (*toDouble)(void*); \ 55 | pString* (*tokenize)(void*, size_t* length_of_result, \ 56 | const char* restrict delimiters); 57 | 58 | STRING_VTABLE_FORMAT; 59 | }; 60 | 61 | 62 | #pragma mark class definition 63 | 64 | 65 | struct _String { 66 | VTABLE(String)* _vtable; 67 | #define STRING_FORMAT \ 68 | OOOBJECT_FORMAT; \ 69 | size_t length; \ 70 | char chars[0] 71 | 72 | STRING_FORMAT; 73 | }; 74 | 75 | 76 | // 77 | // forward declaration of String Class Methods goes here 78 | // 79 | 80 | 81 | #pragma mark class methods 82 | 83 | 84 | pString String_new(const char* restrict cstring, const size_t length); 85 | pString String_new_from(pString restrict string); 86 | pString String_new_concat(pString, pString); 87 | pString String_new_concat_str(pString restrict, const char* restrict, size_t); 88 | 89 | int CString_compare(const char* restrict a, size_t lenA, const char* restrict b, size_t lenB); 90 | 91 | #pragma mark vtable initialization 92 | 93 | 94 | VTABLE(String)* String_vtable(void); 95 | 96 | 97 | #endif // STRING_H_ 98 | -------------------------------------------------------------------------------- /src/misc/StringHashmap.h: -------------------------------------------------------------------------------- 1 | #ifndef STRINGHASHMAP_H_ 2 | #define STRINGHASHMAP_H_ 3 | 4 | /* 5 | * $Id: StringHashmap.h 114 2007-09-19 09:45:37Z tobias.pape $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | 35 | 36 | #pragma mark ** StringHashmap Element 37 | 38 | 39 | #pragma mark VTable definition 40 | 41 | 42 | VTABLE(StringHashmapElem) { 43 | #define STRINGHASHMAPELEM_VTABLE_FORMAT \ 44 | OOOBJECT_VTABLE_FORMAT; \ 45 | int64_t (*key_hash)(void*); \ 46 | bool (*key_equal_to)(void*,pString) 47 | 48 | 49 | STRINGHASHMAPELEM_VTABLE_FORMAT; 50 | }; 51 | 52 | 53 | #pragma mark class definition 54 | 55 | 56 | struct _StringHashmapElem { 57 | VTABLE(StringHashmapElem)* _vtable; 58 | #define STRINGHASHMAPELEM_FORMAT \ 59 | OOOBJECT_FORMAT; \ 60 | pString key; \ 61 | void* value 62 | 63 | STRINGHASHMAPELEM_FORMAT; 64 | }; 65 | 66 | 67 | #pragma mark class methods 68 | 69 | 70 | pHashmapElem StringHashmapElem_new(pString key, void *value); 71 | 72 | 73 | #pragma mark vtable initialization 74 | 75 | 76 | VTABLE(StringHashmapElem)* StringHashmapElem_vtable(void); 77 | 78 | 79 | #pragma mark VTable definition 80 | 81 | 82 | // 83 | // The hash map implemented here for VM-internal purposes uses keys 84 | // of time pString and values of arbitary type. 85 | // 86 | 87 | 88 | VTABLE(StringHashmap) { 89 | #define STRINGHASHMAP_VTABLE_FORMAT \ 90 | OOOBJECT_VTABLE_FORMAT; \ 91 | void (*put)(void*, pString key, void* value); \ 92 | void* (*get)(void*, pString key); \ 93 | bool (*contains_key)(void*, pString key); \ 94 | void (*clear)(void*); \ 95 | void (*rehash)(void*, size_t newSize) 96 | 97 | STRINGHASHMAP_VTABLE_FORMAT; 98 | }; 99 | 100 | 101 | #pragma mark class definition 102 | 103 | 104 | struct _StringHashmap { 105 | VTABLE(StringHashmap)* _vtable; 106 | #define STRINGHASHMAP_FORMAT \ 107 | HASHMAP_FORMAT 108 | 109 | STRINGHASHMAP_FORMAT; 110 | }; 111 | 112 | 113 | // 114 | // forward declaration of Hashmap Class Methods goes here 115 | // 116 | 117 | 118 | #pragma mark class methods 119 | 120 | 121 | pStringHashmap StringHashmap_new(void); 122 | 123 | 124 | #pragma mark vtable initialization 125 | 126 | VTABLE(StringHashmap)* StringHashmap_vtable(void); 127 | 128 | 129 | #endif // STRINGHASHMAP_H_ 130 | -------------------------------------------------------------------------------- /src/misc/debug.h: -------------------------------------------------------------------------------- 1 | #ifndef DEBUG_H_ 2 | #define DEBUG_H_ 3 | 4 | /* 5 | * $Id: debug.h 111 2007-09-18 09:21:40Z tobias.pape $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | 35 | #define fprintf_pass(f,x) \ 36 | va_list ap; \ 37 | va_start(ap, (x)); \ 38 | (void)vfprintf((f), (x), ap); \ 39 | va_end(ap); \ 40 | fflush(f) 41 | 42 | 43 | static inline void debug_print(const char* fmt, ...) { 44 | fprintf_pass(stderr, fmt); 45 | } 46 | 47 | 48 | static inline void debug_prefix(const char* prefix) { 49 | debug_print("%-6s ", prefix); 50 | } 51 | 52 | 53 | #define debug_pass(x) \ 54 | va_list ap; \ 55 | va_start(ap, (x)); \ 56 | (void)vfprintf(stderr, (x), ap); \ 57 | va_end(ap); \ 58 | fflush(stderr) 59 | 60 | 61 | static inline void debug_info(const char* fmt, ...) { 62 | #ifdef DEBUG 63 | debug_prefix("INFO:"); 64 | debug_pass(fmt); 65 | #endif // DEBUG 66 | } 67 | 68 | 69 | static inline void debug_log(const char* fmt, ...) { 70 | #ifdef DEBUG 71 | debug_prefix("LOG:"); 72 | debug_pass(fmt); 73 | #endif // DEBUG 74 | } 75 | 76 | 77 | static inline void debug_warn(const char* fmt, ...) { 78 | debug_prefix("WARN:"); 79 | debug_pass(fmt); 80 | } 81 | 82 | 83 | static inline void debug_error(const char* fmt, ...) { 84 | debug_prefix("ERROR:"); 85 | debug_pass(fmt); 86 | } 87 | 88 | 89 | static inline void debug_dump(const char* fmt, ...) { 90 | debug_prefix("DUMP:"); 91 | debug_pass(fmt); 92 | } 93 | 94 | 95 | static inline void debug_trace(const char* fmt, ...) { 96 | debug_prefix("TRACE:"); 97 | debug_pass(fmt); 98 | } 99 | 100 | 101 | #undef fprintf_pass 102 | #undef debug_pass 103 | 104 | 105 | #endif // DEBUG_H_ 106 | -------------------------------------------------------------------------------- /src/misc/defs.h: -------------------------------------------------------------------------------- 1 | #ifndef DEFS_H_ 2 | #define DEFS_H_ 3 | 4 | /* 5 | * $Id: defs.h 792 2009-04-06 08:07:33Z michael.haupt $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | 34 | // 35 | // error codes 36 | // 37 | 38 | 39 | #define ERR_SUCCESS 0x0 40 | #define ERR_FAIL 0x1 41 | #define ERR_NOMEM 0x2 42 | #define ERR_PANIC 0xFFFF 43 | 44 | 45 | // 46 | // macro for freeing an array 47 | // 48 | 49 | #define FREE_ARRAY_ELEMENTS(arr,count) \ 50 | for(int i = (count)-1; i >= 0; i--) \ 51 | gc_free((arr)[i]) 52 | 53 | #define FREE_ARRAY(arr,count) \ 54 | FREE_ARRAY_ELEMENTS(arr,count); \ 55 | gc_free((arr)) 56 | 57 | 58 | /** 59 | * A String hashing inline function 60 | * Java-like; see http://mindprod.com/jgloss/hashcode.html 61 | */ 62 | static inline int64_t string_hash(const char* restrict string, size_t length) { 63 | uint64_t result = 0; 64 | 65 | for (size_t i = 0; i < length; i++) { 66 | result = 31 * result + string[i]; 67 | } 68 | return result; 69 | } 70 | 71 | 72 | // 73 | // platform-dependent includes 74 | // 75 | 76 | 77 | #include 78 | 79 | 80 | #endif // DEFS_H_ 81 | -------------------------------------------------------------------------------- /src/primitives/%Primitive.c%: -------------------------------------------------------------------------------- 1 | /* 2 | * ____CLASS_NAME____.c 3 | * CSOM 4 | * 5 | * 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | /*************************************************/ 14 | #pragma mark * Included Headers * 15 | /*************************************************/ 16 | 17 | ____SOM_INCLUDES____ 18 | 19 | /*************************************************/ 20 | #pragma mark * Primitive Foreward Declaration * 21 | /*************************************************/ 22 | 23 | ____SOM_DECLS____ 24 | 25 | /*************************************************/ 26 | #pragma mark * Internal functions and init. * 27 | /*************************************************/ 28 | 29 | /*** Lib initialization **/ 30 | #ifdef __GNUC__ 31 | void init(void) __attribute__((constructor)); 32 | void fini(void) __attribute__((destructor)); 33 | #elif 34 | void _init(void); 35 | void _fini(void); 36 | #pragma init _init 37 | #pragma fini _fini 38 | #endif 39 | 40 | 41 | #ifdef __GNUC__ 42 | void init(void) 43 | #elif 44 | void _init(void) 45 | #endif 46 | { 47 | 48 | // Call init funcions. 49 | 50 | ____SOM_FUNCTION_INIT____ 51 | 52 | } 53 | 54 | #ifdef __GNUC__ 55 | void fini(void) 56 | #elif 57 | void _fini(void) 58 | #endif 59 | { 60 | // Call fini functions 61 | ____SOM_FUNCTION_FINI____ 62 | } 63 | 64 | // Classes supported by this lib. 65 | static char *supported_classes[] = { 66 | ____SOM_CLASS_NAMES____ 67 | NULL 68 | }; 69 | 70 | 71 | /*************************************************/ 72 | #pragma mark * Exported functions starting here * 73 | /*************************************************/ 74 | 75 | // returns, whether this lib is responsible for a specific class 76 | bool supports_class(const char* name) { 77 | 78 | char **iter=supported_classes; 79 | while(*iter) 80 | if (strcmp(name,*iter++)==0) 81 | return true; 82 | return false; 83 | 84 | } 85 | 86 | /*************************************************/ 87 | /*************************************************/ 88 | /*************************************************/ 89 | #pragma mark * Primitive Implementatition here * 90 | /*************************************************/ 91 | /*************************************************/ 92 | /*************************************************/ 93 | 94 | 95 | ____PRIMITIVES____ 96 | 97 | 98 | -------------------------------------------------------------------------------- /src/primitives/Array.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: Array.c 223 2008-04-21 11:48:41Z michael.haupt $ 3 | * 4 | Copyright (c) 2007 Michael Haupt, Tobias Pape 5 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 6 | http://www.hpi.uni-potsdam.de/swa/ 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | 34 | #include "Array.h" 35 | 36 | 37 | void _Array_at_(pVMObject object, pVMFrame frame) { 38 | pVMInteger index = (pVMInteger)SEND(frame, pop); 39 | pVMArray self = (pVMArray)SEND(frame, pop); 40 | int64_t i = SEND(index, get_embedded_integer); 41 | pVMObject elem = SEND((pVMArray)self, get_indexable_field, i - 1); 42 | SEND(frame, push, elem); 43 | } 44 | 45 | 46 | void _Array_at_put_(pVMObject object, pVMFrame frame) { 47 | pVMObject value = SEND(frame, pop); 48 | pVMInteger index = (pVMInteger)SEND(frame, pop); 49 | pVMArray self = (pVMArray)SEND(frame, get_stack_element, 0); 50 | int64_t i = SEND(index, get_embedded_integer); 51 | SEND(self, set_indexable_field, i - 1, value); 52 | } 53 | 54 | 55 | void _Array_length(pVMObject object, pVMFrame frame) { 56 | pVMArray self = (pVMArray)SEND(frame, pop); 57 | pVMInteger new_int= 58 | Universe_new_integer(SEND(self, get_number_of_indexable_fields)); 59 | SEND(frame, push, (pVMObject)new_int); 60 | } 61 | 62 | 63 | void Array_new_(pVMObject object, pVMFrame frame) { 64 | pVMInteger length = (pVMInteger)SEND(frame, pop); 65 | pVMClass self __attribute__((unused)) = (pVMClass)SEND(frame, pop); 66 | int64_t size = SEND(length, get_embedded_integer); 67 | SEND(frame, push, (pVMObject) Universe_new_array(size)); 68 | } 69 | -------------------------------------------------------------------------------- /src/primitives/Array.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_ARRAY_H_ 2 | #define CORE_ARRAY_H_ 3 | 4 | /* 5 | * $Id: Array.h 144 2007-11-19 23:32:02Z michael.haupt $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | 33 | void _Array_at_(pVMObject object, pVMFrame frame); 34 | void _Array_at_put_(pVMObject object, pVMFrame frame); 35 | void _Array_length(pVMObject object, pVMFrame frame); 36 | 37 | void Array_new_(pVMObject object, pVMFrame frame); 38 | 39 | 40 | #endif // CORE_ARRAY_H_ 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/primitives/Block.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: Block.c 145 2007-11-19 23:50:24Z michael.haupt $ 3 | * 4 | Copyright (c) 2007 Michael Haupt, Tobias Pape 5 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 6 | http://www.hpi.uni-potsdam.de/swa/ 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | #include "Block.h" 28 | 29 | #include 30 | #include 31 | 32 | #include 33 | 34 | 35 | void _Block_value(pVMObject object, pVMFrame frame) { 36 | // intentionally left blank 37 | } 38 | 39 | 40 | void _Block_value_(pVMObject object, pVMFrame frame) { 41 | // intentionally left blank 42 | } 43 | 44 | 45 | void _Block_value_with_(pVMObject object, pVMFrame frame) { 46 | // intentionally left blank 47 | } 48 | 49 | 50 | void _Block_restart(pVMObject object, pVMFrame frame) { 51 | SEND(frame, set_bytecode_index, 0); 52 | SEND(frame, reset_stack_pointer); 53 | } 54 | -------------------------------------------------------------------------------- /src/primitives/Block.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_BLOCK_H_ 2 | #define CORE_BLOCK_H_ 3 | 4 | /* 5 | * $Id: Block.h 144 2007-11-19 23:32:02Z michael.haupt $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | 33 | void _Block_value(pVMObject object, pVMFrame frame); 34 | void _Block_restart(pVMObject object, pVMFrame frame); 35 | void _Block_value_(pVMObject object, pVMFrame frame); 36 | void _Block_value_with_(pVMObject object, pVMFrame frame); 37 | 38 | 39 | #endif // CORE_BLOCK_H_ 40 | -------------------------------------------------------------------------------- /src/primitives/Class.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: Class.c 116 2007-09-20 13:29:40Z tobias.pape $ 3 | * 4 | Copyright (c) 2007 Michael Haupt, Tobias Pape 5 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 6 | http://www.hpi.uni-potsdam.de/swa/ 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | 34 | #include "Class.h" 35 | 36 | 37 | void _Class_new(pVMObject object, pVMFrame frame) { 38 | pVMClass self = (pVMClass)SEND(frame, pop); 39 | SEND(frame, push, Universe_new_instance(self)); 40 | } 41 | 42 | void _Class_name(pVMObject object, pVMFrame frame) { 43 | pVMClass self = (pVMClass)SEND(frame, pop); 44 | pVMSymbol name = (pVMSymbol)SEND(self, get_name); 45 | SEND(frame, push, (pVMObject)name); 46 | } 47 | 48 | void _Class_superclass(pVMObject object, pVMFrame frame) { 49 | pVMClass self = (pVMClass)SEND(frame, pop); 50 | pVMClass super_class = (pVMClass)SEND(self, get_super_class); 51 | SEND(frame, push, (pVMObject)super_class); 52 | } 53 | 54 | void _Class_fields(pVMObject object, pVMFrame frame) { 55 | pVMClass self = (pVMClass)SEND(frame, pop); 56 | pVMArray fields = (pVMArray)SEND(self, get_instance_fields); 57 | SEND(frame, push, (pVMObject)fields); 58 | } 59 | 60 | void _Class_methods(pVMObject object, pVMFrame frame) { 61 | pVMClass self = (pVMClass)SEND(frame, pop); 62 | pVMArray methods = (pVMArray)SEND(self, get_instance_invokables); 63 | SEND(frame, push, (pVMObject)methods); 64 | } 65 | -------------------------------------------------------------------------------- /src/primitives/Class.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_CLASS_H_ 2 | #define CORE_CLASS_H_ 3 | 4 | /* 5 | * $Id: Class.h 109 2007-09-17 20:39:52Z tobias.pape $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | void _Class_new(pVMObject object, pVMFrame frame); 33 | void _Class_name(pVMObject object, pVMFrame frame); 34 | void _Class_superclass(pVMObject object, pVMFrame frame); 35 | void _Class_fields(pVMObject object, pVMFrame frame); 36 | void _Class_methods(pVMObject object, pVMFrame frame); 37 | 38 | 39 | #endif // CORE_CLASS_H_ 40 | -------------------------------------------------------------------------------- /src/primitives/Core.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: Core.c 229 2008-04-22 14:10:50Z tobias.pape $ 3 | * 4 | Copyright (c) 2007 Michael Haupt, Tobias Pape 5 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 6 | http://www.hpi.uni-potsdam.de/swa/ 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "Array.h" 33 | #include "Block.h" 34 | #include "Class.h" 35 | #include "Double.h" 36 | #include "Integer.h" 37 | #include "Method.h" 38 | #include "Object.h" 39 | #include "Primitive.h" 40 | #include "String.h" 41 | #include "Symbol.h" 42 | #include "System.h" 43 | 44 | /* Lib initialization */ 45 | #pragma mark * Load-time execution * 46 | /** 47 | * Both the following functions have to do with load/unload-time execution. 48 | * That is, anything in init/_init is being executed upon every loading of the 49 | * library, even if this very library is _not_ responsible for the class in 50 | * question. 51 | * 52 | * Use with care. 53 | */ 54 | 55 | // Library load initializer function declaration. 56 | // This is compiler/os-specific 57 | #ifdef __GNUC__ 58 | void init(void) __attribute__((constructor)); 59 | void fini(void) __attribute__((destructor)); 60 | #else 61 | void _init(void); 62 | void _fini(void); 63 | #pragma init _init 64 | #pragma fini _fini 65 | #endif // __GNUC__ 66 | 67 | // Library load initializer 68 | #ifdef __GNUC__ 69 | void init(void) { ; /* noop */} 70 | #else 71 | void _init(void) { ; /* noop */ } 72 | #endif // __GNUC__ 73 | 74 | // Library unload function 75 | #ifdef __GNUC__ 76 | void fini(void) { ; /* noop */ } 77 | #else 78 | void _fini(void) { ; /* noop */ } 79 | #endif // __GNUC__ 80 | 81 | 82 | // Classes supported by this lib. 83 | static char* supported_classes[] = { 84 | "Array", 85 | "BigInteger", 86 | "Block", //this is Block1..3 87 | "Class", 88 | "Double", 89 | "Frame", 90 | "Integer", 91 | "Method", 92 | "Object", 93 | "Primitive", 94 | "String", 95 | "Symbol", 96 | "System", 97 | NULL 98 | }; 99 | 100 | 101 | /*************************************************/ 102 | #pragma mark * Exported functions starting here * 103 | /*************************************************/ 104 | 105 | // returns, whether this lib is responsible for a specific class 106 | bool supports_class(const char* name) { 107 | char **iter=supported_classes; 108 | while(*iter) 109 | if(strcmp(name, *iter++)==0) 110 | return true; 111 | return false; 112 | } 113 | 114 | 115 | /** 116 | * init_csp() 117 | * 118 | * the library initializer. It is not equal to the init/fini-pair, as for them, 119 | * the init is executed upon every loading of the shared library. 120 | * 121 | * All work that needs to be done before the actual primitives are assigned 122 | * should be called from this function. 123 | */ 124 | static bool initialized = false; 125 | 126 | void init_csp(void) { 127 | // Call init funcions. 128 | if (!initialized) { 129 | __System_init(); 130 | __Integer_init(); 131 | initialized = true; 132 | } 133 | } 134 | 135 | -------------------------------------------------------------------------------- /src/primitives/Double.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_DOUBLE_H_ 2 | #define CORE_DOUBLE_H_ 3 | 4 | /* 5 | * $Id: Double.h 792 2009-04-06 08:07:33Z michael.haupt $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | void _Double_plus(pVMObject object, pVMFrame frame); 33 | void _Double_minus(pVMObject object, pVMFrame frame); 34 | void _Double_star(pVMObject object, pVMFrame frame); 35 | void _Double_slashslash(pVMObject object, pVMFrame frame); 36 | void _Double_percent(pVMObject object, pVMFrame frame); 37 | void _Double_and(pVMObject object, pVMFrame frame); 38 | void _Double_bitXor_(pVMObject object, pVMFrame frame); 39 | void _Double_equal(pVMObject object, pVMFrame frame); 40 | void _Double_lessthan(pVMObject object, pVMFrame frame); 41 | void _Double_asString(pVMObject object, pVMFrame frame); 42 | void _Double_sqrt(pVMObject object, pVMFrame frame); 43 | void _Double_rount(pVMObject object, pVMFrame frame); 44 | void _Double_asInteger(pVMObject object, pVMFrame frame); 45 | void _Double_cos(pVMObject object, pVMFrame frame); 46 | void _Double_sin(pVMObject object, pVMFrame frame); 47 | 48 | void Double_PositiveInfinity(pVMObject object, pVMFrame frame); 49 | 50 | #endif // CORE_DOUBLE_H_ 51 | -------------------------------------------------------------------------------- /src/primitives/Integer.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_INTEGER_H_ 2 | #define CORE_INTEGER_H_ 3 | 4 | /* 5 | * $Id: Integer.h 792 2009-04-06 08:07:33Z michael.haupt $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | void _Integer_plus(pVMObject object, pVMFrame frame); 33 | void _Integer_minus(pVMObject object, pVMFrame frame); 34 | void _Integer_star(pVMObject object, pVMFrame frame); 35 | void _Integer_slash(pVMObject object, pVMFrame frame); 36 | void _Integer_slashslash(pVMObject object, pVMFrame frame); 37 | void _Integer_percent(pVMObject object, pVMFrame frame); 38 | void _Integer_and(pVMObject object, pVMFrame frame); 39 | void _Integer_equal(pVMObject object, pVMFrame frame); 40 | void _Integer_lessthan(pVMObject object, pVMFrame frame); 41 | void _Integer_asString(pVMObject object, pVMFrame frame); 42 | void _Integer_sqrt(pVMObject object, pVMFrame frame); 43 | void _Integer_atRandom(pVMObject object, pVMFrame frame); 44 | void _Integer_rem_(pVMObject object, pVMFrame frame); 45 | void _Integer_lessthanlessthan(pVMObject object, pVMFrame frame); 46 | void _Integer_greaterthangreaterthangreaterthan(pVMObject object, pVMFrame frame); 47 | void _Integer_bitXor_(pVMObject object, pVMFrame frame); 48 | void _Integer_as32BitSignedValue(pVMObject object, pVMFrame frame); 49 | void _Integer_as32BitUnsignedValue(pVMObject object, pVMFrame frame); 50 | void _Integer_equalequal(pVMObject object, pVMFrame frame); 51 | 52 | void Integer_fromString_(pVMObject object, pVMFrame frame); 53 | 54 | void __Integer_init(void); 55 | 56 | #endif // CORE_INTEGER_H_ 57 | -------------------------------------------------------------------------------- /src/primitives/Method.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019 Stefan Marr 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #include "Method.h" 31 | 32 | 33 | void _Method_holder(pVMObject object, pVMFrame frame) { 34 | pVMMethod self = (pVMMethod)SEND(frame, pop); 35 | SEND(frame, push, (pVMObject)self->holder); 36 | } 37 | 38 | void _Method_signature(pVMObject object, pVMFrame frame) { 39 | pVMMethod self = (pVMMethod)SEND(frame, pop); 40 | SEND(frame, push, (pVMObject)self->signature); 41 | } 42 | 43 | void _Method_invokeOn_with_(pVMObject object, pVMFrame frame) { 44 | printf("NOT YET IMPLEMENTED _Method_invokeOn_with_ "); 45 | Universe_exit(1); 46 | 47 | // // REM: this is a clone with _Primitive::InvokeOn_With_ 48 | // VMArray* args = static_cast(frame->Pop()); 49 | // vm_oop_t rcvr = static_cast(frame->Pop()); 50 | // VMMethod* mthd = static_cast(frame->Pop()); 51 | // 52 | // 53 | // frame->Push(rcvr); 54 | // 55 | // size_t num_args = args->GetNumberOfIndexableFields(); 56 | // for (size_t i = 0; i < num_args; i++) { 57 | // vm_oop_t arg = args->GetIndexableField(i); 58 | // frame->Push(arg); 59 | // } 60 | // mthd->Invoke(interp, frame); 61 | } 62 | -------------------------------------------------------------------------------- /src/primitives/Method.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_METHOD_H_ 2 | #define CORE_METHOD_H_ 3 | 4 | /* 5 | Copyright (c) 2019 Stefan Marr 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 | #include 27 | 28 | void _Method_holder(pVMObject object, pVMFrame frame); 29 | void _Method_signature(pVMObject object, pVMFrame frame); 30 | void _Method_invokeOn_with_(pVMObject object, pVMFrame frame); 31 | 32 | 33 | #endif // CORE_METHOD_H_ 34 | -------------------------------------------------------------------------------- /src/primitives/Object.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_OBJECT_H_ 2 | #define CORE_OBJECT_H_ 3 | 4 | /* 5 | * $Id: Object.h 176 2008-03-19 10:21:59Z michael.haupt $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | void _Object_equalequal(pVMObject object, pVMFrame frame); 33 | void _Object_objectSize(pVMObject object, pVMFrame frame); 34 | void _Object_hashcode(pVMObject object, pVMFrame frame); 35 | void _Object_inspect(pVMObject object, pVMFrame frame); 36 | void _Object_halt(pVMObject object, pVMFrame frame); 37 | 38 | void _Object_perform_(pVMObject object, pVMFrame frame); 39 | void _Object_perform_withArguments_(pVMObject object, pVMFrame frame); 40 | void _Object_perform_inSuperclass_(pVMObject object, pVMFrame frame); 41 | void _Object_perform_withArguments_inSuperclass_(pVMObject object, pVMFrame frame); 42 | void _Object_instVarAt_(pVMObject object, pVMFrame frame); 43 | void _Object_instVarAt_put_(pVMObject object, pVMFrame frame); 44 | void _Object_instVarNamed_(pVMObject object, pVMFrame frame); 45 | 46 | void _Object_class(pVMObject object, pVMFrame frame); 47 | 48 | #endif // CORE_OBJECT_H_ 49 | -------------------------------------------------------------------------------- /src/primitives/Primitive.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019 Stefan Marr 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #include "Primitive.h" 31 | 32 | 33 | void _Primitive_holder(pVMObject object, pVMFrame frame) { 34 | pVMMethod self = (pVMMethod)SEND(frame, pop); 35 | SEND(frame, push, (pVMObject)self->holder); 36 | } 37 | 38 | void _Primitive_signature(pVMObject object, pVMFrame frame) { 39 | pVMMethod self = (pVMMethod)SEND(frame, pop); 40 | SEND(frame, push, (pVMObject)self->signature); 41 | } 42 | 43 | void _Primitive_invokeOn_with_(pVMObject object, pVMFrame frame) { 44 | printf("NOT YET IMPLEMENTED _Method_invokeOn_with_ "); 45 | Universe_exit(1); 46 | 47 | // // REM: this is a clone with _Primitive::InvokeOn_With_ 48 | // VMArray* args = static_cast(frame->Pop()); 49 | // vm_oop_t rcvr = static_cast(frame->Pop()); 50 | // VMMethod* mthd = static_cast(frame->Pop()); 51 | // 52 | // 53 | // frame->Push(rcvr); 54 | // 55 | // size_t num_args = args->GetNumberOfIndexableFields(); 56 | // for (size_t i = 0; i < num_args; i++) { 57 | // vm_oop_t arg = args->GetIndexableField(i); 58 | // frame->Push(arg); 59 | // } 60 | // mthd->Invoke(interp, frame); 61 | } 62 | -------------------------------------------------------------------------------- /src/primitives/Primitive.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_PRIMITIVE_H_ 2 | #define CORE_PRIMITIVE_H_ 3 | 4 | /* 5 | Copyright (c) 2019 Stefan Marr 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 | #include 27 | 28 | void _Primitive_holder(pVMObject object, pVMFrame frame); 29 | void _Primitive_signature(pVMObject object, pVMFrame frame); 30 | void _Primitive_invokeOn_with_(pVMObject object, pVMFrame frame); 31 | 32 | 33 | #endif // CORE_PRIMITIVE_H_ 34 | -------------------------------------------------------------------------------- /src/primitives/String.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_STRING_H_ 2 | #define CORE_STRING_H_ 3 | 4 | /* 5 | * $Id: String.h 109 2007-09-17 20:39:52Z tobias.pape $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | void _String_concatenate_(pVMObject object, pVMFrame frame); 33 | void _String_asSymbol(pVMObject object, pVMFrame frame); 34 | void _String_hashcode(pVMObject object, pVMFrame frame); 35 | void _String_length(pVMObject object, pVMFrame frame); 36 | void _String_equal(pVMObject object, pVMFrame frame); 37 | void _String_primSubstringFrom_to_(pVMObject object, pVMFrame frame); 38 | 39 | void _String_isWhiteSpace(pVMObject object, pVMFrame frame); 40 | void _String_isLetters(pVMObject object, pVMFrame frame); 41 | void _String_isDigits(pVMObject object, pVMFrame frame); 42 | 43 | #endif // CORE_STRING_H_ 44 | -------------------------------------------------------------------------------- /src/primitives/Symbol.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: Symbol.c 792 2009-04-06 08:07:33Z michael.haupt $ 3 | * 4 | Copyright (c) 2007 Michael Haupt, Tobias Pape 5 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 6 | http://www.hpi.uni-potsdam.de/swa/ 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #include 34 | 35 | #include "Symbol.h" 36 | 37 | 38 | void _Symbol_asString(pVMObject object, pVMFrame frame) { 39 | pVMSymbol sym = (pVMSymbol)SEND(frame, pop); 40 | const char* chars = SEND(sym, get_rawChars); 41 | const size_t length = SEND(sym, get_length); 42 | 43 | SEND(frame, push, (pVMObject) Universe_new_string_string(chars, length)); 44 | } 45 | 46 | 47 | void _Symbol_equal(pVMObject object, pVMFrame frame) { 48 | pVMObject op1 = SEND(frame, pop); 49 | pVMSymbol op2 = (pVMSymbol)SEND(frame, pop); 50 | 51 | pVMClass op1_class = SEND(op1, get_class); 52 | 53 | if (op1_class == symbol_class) { 54 | if ((pVMSymbol) op1 == op2) { 55 | SEND(frame, push, true_object); 56 | return; 57 | } 58 | } 59 | 60 | SEND(frame, push, false_object); 61 | } 62 | -------------------------------------------------------------------------------- /src/primitives/Symbol.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_SYMBOL_H_ 2 | #define CORE_SYMBOL_H_ 3 | 4 | /* 5 | * $Id: Symbol.h 109 2007-09-17 20:39:52Z tobias.pape $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | void _Symbol_asString(pVMObject object, pVMFrame frame); 33 | void _Symbol_equal(pVMObject object, pVMFrame frame); 34 | 35 | #endif // CORE_SYMBOL_H_ 36 | -------------------------------------------------------------------------------- /src/primitives/System.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: System.c 792 2009-04-06 08:07:33Z michael.haupt $ 3 | * 4 | Copyright (c) 2007 Michael Haupt, Tobias Pape 5 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 6 | http://www.hpi.uni-potsdam.de/swa/ 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | #include 28 | 29 | #include 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | 38 | #include 39 | 40 | #include "System.h" 41 | 42 | //file variable 43 | struct timeval _System_start_time = { 0, 0 }; 44 | 45 | void _System_global_(pVMObject object, pVMFrame frame) { 46 | pVMSymbol arg = (pVMSymbol)SEND(frame, pop); 47 | pVMObject self __attribute__((unused))= SEND(frame, pop); 48 | pVMObject result = Universe_get_global(arg); 49 | 50 | SEND(frame, push, result? 51 | result:nil_object); 52 | } 53 | 54 | 55 | void _System_global_put_(pVMObject object, pVMFrame frame) { 56 | pVMObject value = SEND(frame, pop); 57 | pVMSymbol arg = (pVMSymbol)SEND(frame, pop); 58 | Universe_set_global(arg, value); 59 | } 60 | 61 | 62 | void _System_hasGlobal_(pVMObject object, pVMFrame frame) { 63 | pVMSymbol arg = (pVMSymbol)SEND(frame, pop); 64 | SEND(frame, pop); 65 | 66 | if (Universe_has_global(arg)) { 67 | SEND(frame, push, true_object); 68 | } else { 69 | SEND(frame, push, false_object); 70 | } 71 | } 72 | 73 | 74 | void _System_load_(pVMObject object, pVMFrame frame) { 75 | pVMSymbol arg = (pVMSymbol)SEND(frame, pop); 76 | pVMObject self __attribute__((unused)) = SEND(frame, pop); 77 | pVMClass result = Universe_load_class(arg); 78 | SEND(frame, push, result? (pVMObject)result: 79 | nil_object); 80 | 81 | } 82 | 83 | 84 | void _System_exit_(pVMObject object, pVMFrame frame) { 85 | pVMInteger err = (pVMInteger)SEND(frame, pop); 86 | int64_t err_no = SEND(err, get_embedded_integer); 87 | 88 | if (err_no != ERR_SUCCESS) 89 | SEND(frame, print_stack_trace); 90 | Universe_exit((int32_t)err_no); 91 | } 92 | 93 | 94 | void _System_printString_(pVMObject object, pVMFrame frame) { 95 | pVMString arg = (pVMString)SEND(frame, pop); 96 | printf("%s", SEND(arg, get_rawChars)); 97 | fflush(stdout); 98 | } 99 | 100 | 101 | void _System_printNewline(pVMObject object, pVMFrame frame) { 102 | printf("\n"); 103 | fflush(stdout); 104 | } 105 | 106 | 107 | void _System_time(pVMObject object, pVMFrame frame) { 108 | pVMObject self __attribute__((unused)) = SEND(frame, pop); 109 | struct timeval now; 110 | gettimeofday(&now, NULL); 111 | long long diff = 112 | ((now.tv_sec - _System_start_time.tv_sec) * 1000) + //seconds 113 | ((now.tv_usec - _System_start_time.tv_usec) / 1000); // µseconds 114 | SEND(frame, push, (pVMObject)Universe_new_integer((int32_t)diff)); 115 | } 116 | 117 | void _System_ticks(pVMObject object, pVMFrame frame) { 118 | SEND(frame, pop); 119 | struct timeval now; 120 | gettimeofday(&now, NULL); 121 | 122 | int64_t ticks = ((now.tv_sec - _System_start_time.tv_sec) * 1000 * 1000) + //seconds 123 | ((now.tv_usec - _System_start_time.tv_usec)); //µseconds 124 | SEND(frame, push, (pVMObject)Universe_new_integer(ticks)); 125 | } 126 | 127 | 128 | void _System_fullGC(pVMObject object, pVMFrame frame) { 129 | SEND(frame, pop); 130 | gc_collect(); 131 | SEND(frame, push, true_object); 132 | } 133 | 134 | void __System_init(void) { 135 | gettimeofday(&_System_start_time , NULL); 136 | } 137 | -------------------------------------------------------------------------------- /src/primitives/System.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_SYSTEM_H_ 2 | #define CORE_SYSTEM_H_ 3 | 4 | /* 5 | * $Id: System.h 109 2007-09-17 20:39:52Z tobias.pape $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | void _System_global_(pVMObject object, pVMFrame frame); 34 | void _System_global_put_(pVMObject object, pVMFrame frame); 35 | void _System_hasGlobal_(pVMObject object, pVMFrame frame); 36 | void _System_load_(pVMObject object, pVMFrame frame); 37 | void _System_exit_(pVMObject object, pVMFrame frame); 38 | void _System_printString_(pVMObject object, pVMFrame frame); 39 | void _System_printNewline(pVMObject object, pVMFrame frame); 40 | void _System_time(pVMObject object, pVMFrame frame); 41 | void _System_ticks(pVMObject object, pVMFrame frame); 42 | void _System_fullGC(pVMObject object, pVMFrame frame); 43 | 44 | void __System_init(void); 45 | extern struct timeval _System_start_time; 46 | 47 | #endif // CORE_SYSTEM_H_ 48 | -------------------------------------------------------------------------------- /src/primitives/som2strlist.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for i in *.som; do 4 | if (grep primitive $i >/dev/null); then 5 | echo -n ' "'; 6 | echo $i |sed -e 's/.som/",/'; 7 | fi; 8 | done 9 | -------------------------------------------------------------------------------- /src/vm/Shell.h: -------------------------------------------------------------------------------- 1 | #ifndef SHELL_H_ 2 | #define SHELL_H_ 3 | 4 | /* 5 | * $Id: Shell.h 116 2007-09-20 13:29:40Z tobias.pape $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | void Shell_set_bootstrap_method(pVMMethod); 33 | pVMMethod Shell_get_bootstrap_method(void); 34 | void Shell_start(void); 35 | 36 | #endif // SHELL_H_ 37 | -------------------------------------------------------------------------------- /src/vm/Universe.h: -------------------------------------------------------------------------------- 1 | #ifndef UNIVERSE_H_ 2 | #define UNIVERSE_H_ 3 | 4 | /* 5 | * $Id: Universe.h 792 2009-04-06 08:07:33Z michael.haupt $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | /* Global objects */ 44 | extern pVMObject nil_object; 45 | extern pVMObject true_object; 46 | extern pVMObject false_object; 47 | 48 | extern pVMClass object_class; 49 | extern pVMClass class_class; 50 | extern pVMClass metaclass_class; 51 | 52 | extern pVMClass nil_class; 53 | extern pVMClass integer_class; 54 | extern pVMClass array_class; 55 | extern pVMClass method_class; 56 | extern pVMClass symbol_class; 57 | extern pVMClass primitive_class; 58 | extern pVMClass string_class; 59 | extern pVMClass system_class; 60 | extern pVMClass block_class; 61 | extern pVMClass double_class; 62 | 63 | extern pVMClass true_class; 64 | extern pVMClass false_class; 65 | 66 | extern pVMSymbol doesNotUnderstand_sym; 67 | extern pVMSymbol unknownGlobal_sym; 68 | extern pVMSymbol escapedBlock_sym; 69 | extern pVMSymbol run_sym; 70 | 71 | 72 | // for runtime debug 73 | extern short dump_bytecodes; 74 | extern short gc_verbosity; 75 | 76 | 77 | void Universe_exit(int) __attribute__((noreturn)); 78 | void Universe_error_exit(const char* restrict) __attribute__((noreturn)); 79 | 80 | void Universe_assert(bool); 81 | 82 | pVMSymbol Universe_symbol_for_str(pString restrict); 83 | pVMSymbol Universe_symbol_for_chars(const char* restrict, size_t); 84 | pVMSymbol Universe_symbol_for_cstr(const char* restrict); 85 | 86 | pVMArray Universe_new_array(int64_t); 87 | pVMArray Universe_new_array_list(pList list); 88 | pVMArray Universe_new_array_from_argv(int, const char**); 89 | pVMBlock Universe_new_block(pVMMethod, pVMFrame, int64_t); 90 | pVMClass Universe_new_class(pVMClass); 91 | pVMFrame Universe_new_frame(pVMFrame, pVMMethod, pVMFrame); 92 | pVMMethod Universe_new_method(pVMSymbol, size_t, size_t, size_t, size_t); 93 | pVMObject Universe_new_instance(pVMClass); 94 | pVMInteger Universe_new_integer(int64_t); 95 | pVMDouble Universe_new_double(double); 96 | pVMClass Universe_new_metaclass_class(void); 97 | 98 | pVMString Universe_new_string_cstr(const char*); 99 | pVMString Universe_new_string_str(pString); 100 | pVMString Universe_new_string_string(const char* restrict, size_t); 101 | pVMString Universe_new_string_concat(pVMString, pVMString); 102 | 103 | pVMSymbol Universe_new_symbol(pString); 104 | pVMClass Universe_new_system_class(void); 105 | 106 | void Universe_initialize_system_class(pVMClass, pVMClass, const char*); 107 | 108 | pHashmap Universe_get_globals_dictionary(void); 109 | pVMObject Universe_get_global(pVMSymbol); 110 | void Universe_set_global(pVMSymbol, pVMObject); 111 | bool Universe_has_global(pVMSymbol); 112 | 113 | pVMClass Universe_get_block_class(void); 114 | pVMClass Universe_get_block_class_with_args(int64_t); 115 | 116 | pVMClass Universe_load_class(pVMSymbol); 117 | void Universe_load_system_class(pVMClass); 118 | pVMClass Universe_load_class_basic(pVMSymbol, pVMClass); 119 | pVMClass Universe_load_shell_class(const char*); 120 | 121 | const char** Universe_handle_arguments(int* vm_argc, int argc, 122 | const char** argv); 123 | 124 | void Universe_set_classpath(const char* classpath); 125 | void Universe_start(int argc, const char** argv); 126 | pVMObject Universe_interpret(const char* class_name, const char* method_name); 127 | void Universe_destruct(void); 128 | 129 | #endif // UNIVERSE_H_ 130 | -------------------------------------------------------------------------------- /src/vmobjects/OOObject.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: OOObject.c 176 2008-03-19 10:21:59Z michael.haupt $ 3 | * 4 | Copyright (c) 2007 Michael Haupt, Tobias Pape 5 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 6 | http://www.hpi.uni-potsdam.de/swa/ 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | #include "OOObject.h" 33 | 34 | 35 | /* 36 | * Initialize an Object 37 | */ 38 | void _OOObject_init(void* _self, ...) { 39 | pOOObject self = (pOOObject)_self; 40 | // top level Object. 41 | // set the hashcode 42 | self->hash = (intptr_t)self; 43 | } 44 | 45 | 46 | // 47 | // Instance Methods (Starting with _OOObject_) 48 | // 49 | 50 | 51 | void _OOObject_free(void* _self) { 52 | internal_free(_self); 53 | } 54 | 55 | 56 | intptr_t _OOObject_object_size(void* _self) { 57 | return ((pOOObject)_self)->object_size; 58 | } 59 | 60 | 61 | // the VTable 62 | static VTABLE(OOObject) _OOObject_vtable; 63 | bool OOObject_vtable_inited = false; 64 | 65 | 66 | VTABLE(OOObject)* OOObject_vtable(void) { 67 | if(! OOObject_vtable_inited) { 68 | _OOObject_vtable._ttable = NULL; /* no traits present */ 69 | _OOObject_vtable.free = METHOD(OOObject, free); 70 | _OOObject_vtable.init = METHOD(OOObject, init); 71 | _OOObject_vtable.object_size = METHOD(OOObject, object_size); 72 | OOObject_vtable_inited = true; 73 | } 74 | return &_OOObject_vtable; 75 | } 76 | 77 | -------------------------------------------------------------------------------- /src/vmobjects/OOObject.h: -------------------------------------------------------------------------------- 1 | #ifndef OOOBJECT_H_ 2 | #define OOOBJECT_H_ 3 | 4 | /* 5 | * $Id: OOObject.h 227 2008-04-21 15:21:14Z michael.haupt $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | 36 | #pragma mark **** Object Macros. ****** 37 | 38 | 39 | /** 40 | * The SEND macro. 41 | * It is used for general sending of messages to objects. 42 | */ 43 | #define SEND(O,M,...) \ 44 | ({ typeof(O) _O = (O); \ 45 | (_O->_vtable->M(_O , ##__VA_ARGS__)); \ 46 | }) 47 | 48 | 49 | /** 50 | * The TSEND macro. 51 | * It is used for sending messages to an object's trait 52 | */ 53 | #ifdef EXPERIMENTAL 54 | #define TSEND(TRAIT,O,M,...) \ 55 | ({ typeof(O) _O = (O); \ 56 | (((VTABLE(TRAIT)*)(_O->_vtable))->M((TRAIT *)_O , ##__VA_ARGS__)); \ 57 | }) 58 | #else 59 | #define TSEND(TRAIT,O,M,...) \ 60 | ({ typeof(O) _O = (O); \ 61 | (((VTABLE(TRAIT)*)(_O->_vtable->_ttable))->M((TRAIT*)_O , ##__VA_ARGS__)); \ 62 | }) 63 | #endif // EXPERIMENTAL 64 | 65 | 66 | /** 67 | * The ASSIGN_TRAIT helper macro. 68 | * It is used for assigning a trait t to a VTable C 69 | */ 70 | // using GNU ({ ... }) extension. 71 | #ifdef EXPERIMENTAL 72 | #define ASSIGN_TRAIT(T,C) ({ \ 73 | VTABLE(OOObject)* _vt = (VTABLE(OOObject)*)&_##C##_vtable; \ 74 | while(_vt->_ttable) { \ 75 | _vt=((VTABLE(OOObject)*)_vt)->_ttable; \ 76 | } \ 77 | _vt->_ttable=T##_vtable(); \ 78 | }) 79 | #else 80 | #define ASSIGN_TRAIT(T,C) \ 81 | ((_##C##_vtable._ttable)=T##_vtable()) 82 | #endif // EXPERIMENTAL 83 | 84 | 85 | /** 86 | * The VTable Helper Macros 87 | * Useful for simpler VTable Defintition 88 | */ 89 | #define VTABLE(CLASS) \ 90 | struct _##CLASS##_vtable_layout 91 | 92 | 93 | /** 94 | * The Method Helper. 95 | * used to define instance-methods in VTables 96 | */ 97 | #define METHOD(C,M) _##C##_##M 98 | 99 | 100 | #pragma mark typing 101 | 102 | 103 | /** 104 | * Every _init shall call it's SuperConstructor, 105 | * p.e. SUPER(ASTNode, self, init); 106 | */ 107 | #define SUPER(class,object,msg, ...) \ 108 | ((class##_vtable())->msg((object) , ##__VA_ARGS__)) 109 | 110 | 111 | #define IS_A(object,class) \ 112 | (((class *)object)->_vtable == class##_vtable()) 113 | 114 | 115 | #ifdef EXPERIMENTAL 116 | #define SUPPORTS(O,TRAIT) ({ \ 117 | VTABLE(OOObject)* _vt = (VTABLE(OOObject)*)((O)->_vtable); \ 118 | bool found = false; \ 119 | while(_vt->_ttable) { \ 120 | if(_vt->_ttable == TRAIT##_vtable()) \ 121 | found = true; \ 122 | _vt=((VTABLE(OOObject)*)_vt)->_ttable; \ 123 | } \ 124 | found; \ 125 | }) 126 | #else 127 | #define SUPPORTS(O,TRAIT) \ 128 | ((VTABLE(TRAIT)*)((VTABLE(OOObject)*)((O)->_vtable)->_ttable) == \ 129 | TRAIT##_vtable()) 130 | #endif // EXPERIMENTAL 131 | 132 | 133 | #define INIT(O, ...) \ 134 | SEND((pOOObject)(O),init , ##__VA_ARGS__) 135 | 136 | 137 | #pragma mark Class type accessing 138 | 139 | 140 | #include 141 | 142 | 143 | #pragma mark Object Defintitions 144 | 145 | 146 | VTABLE(OOObject) { 147 | #define OOOBJECT_VTABLE_FORMAT \ 148 | void* _ttable; \ 149 | void (*init)(void* _self, ...); \ 150 | void (*free)(void* _self); \ 151 | intptr_t (*object_size)(void* _self) 152 | 153 | OOOBJECT_VTABLE_FORMAT; 154 | }; 155 | 156 | 157 | struct _OOObject { 158 | VTABLE(OOObject)* _vtable; 159 | 160 | #define OOOBJECT_FORMAT \ 161 | intptr_t object_size; \ 162 | intptr_t gc_field; \ 163 | intptr_t hash 164 | 165 | OOOBJECT_FORMAT; 166 | }; 167 | 168 | 169 | VTABLE(OOObject)* OOObject_vtable(void); 170 | 171 | 172 | // 173 | // macros for object size computations 174 | // 175 | 176 | 177 | #define OBJECT_SIZE_DIFF(SUB, SUPER) \ 178 | (sizeof(SUB)/sizeof(void*)-sizeof(SUPER)/sizeof(void*)) 179 | 180 | 181 | #define SIZE_DIFF_VMOBJECT(SUB) ((size_t)(OBJECT_SIZE_DIFF(SUB,VMObject))) 182 | 183 | 184 | #endif // OOOBJECT_H_ 185 | -------------------------------------------------------------------------------- /src/vmobjects/Signature.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: Signature.c 792 2009-04-06 08:07:33Z michael.haupt $ 3 | * 4 | Copyright (c) 2007 Michael Haupt, Tobias Pape 5 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 6 | http://www.hpi.uni-potsdam.de/swa/ 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | #include "Signature.h" 28 | 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | 35 | int Signature_get_number_of_arguments(pVMSymbol sig) { 36 | // check default binaries 37 | if (Signature_is_binary(sig)) { 38 | return 2; 39 | } else { 40 | const char* str = SEND(sig, get_rawChars); 41 | size_t length = SEND(sig, get_length); 42 | 43 | // colons in str 44 | int num_colons = 0; 45 | 46 | // search the str 47 | for (int i = 0 ; i < length; i++) { 48 | if (str[i] == ':') { 49 | // additional colon found 50 | num_colons++; 51 | } 52 | } 53 | 54 | // The number of arguments is equal to the number of colons plus one 55 | // (->> SELF) 56 | return num_colons + 1; 57 | } 58 | } 59 | 60 | 61 | bool Signature_is_binary(pVMSymbol sig) { 62 | const char* sigstr = SEND(sig, get_rawChars); 63 | size_t length = SEND(sig, get_length); 64 | 65 | if (length < 1) { 66 | return false; 67 | } 68 | 69 | switch (sigstr[0]) { 70 | case '~' : 71 | case '&' : 72 | case '|' : 73 | case '*' : 74 | case '/' : 75 | case '@' : 76 | case '+' : 77 | case '-' : 78 | case '=' : 79 | case '>' : 80 | case '<' : 81 | case ',' : 82 | case '%' : 83 | case '\\': 84 | return true; 85 | default: break; 86 | } 87 | return false; 88 | } 89 | 90 | 91 | -------------------------------------------------------------------------------- /src/vmobjects/Signature.h: -------------------------------------------------------------------------------- 1 | #ifndef SIGNATURE_H_ 2 | #define SIGNATURE_H_ 3 | 4 | /* 5 | * $Id: Signature.h 109 2007-09-17 20:39:52Z tobias.pape $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | #include 33 | 34 | int Signature_get_number_of_arguments(pVMSymbol); 35 | bool Signature_is_binary(pVMSymbol); 36 | 37 | #endif // SIGNATURE_H_ 38 | -------------------------------------------------------------------------------- /src/vmobjects/Symboltable.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: Symboltable.c 792 2009-04-06 08:07:33Z michael.haupt $ 3 | * 4 | Copyright (c) 2007 Michael Haupt, Tobias Pape 5 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 6 | http://www.hpi.uni-potsdam.de/swa/ 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | #include "Symboltable.h" 28 | 29 | #include "VMSymbol.h" 30 | #include "VMString.h" 31 | 32 | #include 33 | 34 | // class variable 35 | static pStringHashmap symtab; 36 | 37 | pVMSymbol Symbol_table_lookup(pString restrict string) { 38 | return (pVMSymbol)SEND(symtab, get, string); 39 | } 40 | 41 | 42 | void Symbol_table_insert(pVMSymbol symbol) { 43 | pString key = String_new(SEND(symbol, get_rawChars), SEND(symbol, get_length)); 44 | SEND(symtab, put, key, symbol); 45 | } 46 | 47 | 48 | void Symbol_table_init(void) { 49 | symtab = StringHashmap_new(); 50 | } 51 | 52 | 53 | void Symbol_table_destruct(void) { 54 | if (symtab) { 55 | SEND(symtab, free); 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /src/vmobjects/Symboltable.h: -------------------------------------------------------------------------------- 1 | #ifndef SYMBOLTABLE_H_ 2 | #define SYMBOLTABLE_H_ 3 | 4 | /* 5 | * $Id: Symboltable.h 114 2007-09-19 09:45:37Z tobias.pape $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | pVMSymbol Symbol_table_lookup(pString restrict); 33 | void Symbol_table_insert(pVMSymbol); 34 | 35 | void Symbol_table_init(void); 36 | void Symbol_table_destruct(void); 37 | 38 | #endif // SYMBOLTABLE_H_ 39 | -------------------------------------------------------------------------------- /src/vmobjects/VMArray.h: -------------------------------------------------------------------------------- 1 | #ifndef VMARRAY_H_ 2 | #define VMARRAY_H_ 3 | 4 | /* 5 | * $Id: VMArray.h 125 2007-11-08 21:40:09Z tobias.pape $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | #pragma mark VTable definition 33 | 34 | VTABLE(VMArray) { 35 | #define VMARRAY_VTABLE_FORMAT \ 36 | VMOBJECT_VTABLE_FORMAT; \ 37 | size_t (*_get_offset)(void*); \ 38 | pVMObject (*get_indexable_field)(void*, int64_t); \ 39 | void (*set_indexable_field)(void*, int64_t, pVMObject); \ 40 | int64_t (*get_number_of_indexable_fields)(void*); \ 41 | pVMArray (*copy_and_extend_with)(void*, pVMObject); \ 42 | void (*copy_indexable_fields_to)(void*, pVMArray) 43 | 44 | VMARRAY_VTABLE_FORMAT; 45 | }; 46 | 47 | #pragma mark class definition 48 | 49 | #define ARRAY_FORMAT \ 50 | VMOBJECT_FORMAT 51 | 52 | struct _VMArray { 53 | VTABLE(VMArray)* _vtable; 54 | ARRAY_FORMAT; 55 | }; 56 | 57 | #pragma mark class methods 58 | 59 | pVMArray VMArray_new(size_t size); 60 | 61 | 62 | #pragma mark vtable initialization 63 | 64 | VTABLE(VMArray)* VMArray_vtable(void); 65 | 66 | 67 | #endif // ARRAY_H_ 68 | -------------------------------------------------------------------------------- /src/vmobjects/VMBlock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: VMBlock.c 227 2008-04-21 15:21:14Z michael.haupt $ 3 | * 4 | Copyright (c) 2007 Michael Haupt, Tobias Pape 5 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 6 | http://www.hpi.uni-potsdam.de/swa/ 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | #include "VMBlock.h" 28 | #include "VMEvaluationPrimitive.h" 29 | 30 | #include 31 | 32 | #include 33 | 34 | 35 | // 36 | // Class Methods (Starting with VMBlock_) 37 | // 38 | 39 | 40 | /** 41 | * Create a new VMBlock 42 | */ 43 | pVMBlock VMBlock_new(pVMMethod method, pVMFrame context) { 44 | pVMBlock result = (pVMBlock)gc_allocate_object(sizeof(VMBlock)); 45 | if(result) { 46 | result->_vtable = VMBlock_vtable(); 47 | gc_start_uninterruptable_allocation(); 48 | INIT(result, method, context); 49 | gc_end_uninterruptable_allocation(); 50 | } 51 | return result; 52 | } 53 | 54 | 55 | pVMPrimitive VMBlock_get_evaluation_primitive(int64_t number_of_arguments) { 56 | return (pVMPrimitive)VMEvaluationPrimitive_new(number_of_arguments); 57 | } 58 | 59 | 60 | /** 61 | * Initialize a VMBlock 62 | */ 63 | void _VMBlock_init(void* _self, ...) { 64 | pVMBlock self = (pVMBlock)_self; 65 | SUPER(VMObject, self, init, SIZE_DIFF_VMOBJECT(VMBlock)); 66 | 67 | va_list args; 68 | va_start(args, _self); 69 | self->method = va_arg(args,pVMMethod); 70 | self->context = va_arg(args,pVMFrame); 71 | 72 | va_end(args); 73 | } 74 | 75 | 76 | // 77 | // Instance Methods (Starting with _VMArray_) 78 | // 79 | 80 | 81 | pVMMethod _VMBlock_get_method(void* _self) { 82 | pVMBlock self = (pVMBlock)_self; 83 | return self->method; 84 | } 85 | 86 | 87 | pVMFrame _VMBlock_get_context(void* _self) { 88 | pVMBlock self = (pVMBlock)_self; 89 | // Get the context of this block 90 | return self->context; 91 | } 92 | 93 | 94 | void _VMBlock_mark_references(void* _self) { 95 | pVMBlock self = (pVMBlock) _self; 96 | gc_mark_object(self->method); 97 | gc_mark_object(self->context); 98 | SUPER(VMObject, self, mark_references); 99 | } 100 | 101 | 102 | // 103 | // The VTABLE-function 104 | // 105 | 106 | 107 | static VTABLE(VMBlock) _VMBlock_vtable; 108 | bool VMBlock_vtable_inited = false; 109 | 110 | 111 | VTABLE(VMBlock)* VMBlock_vtable(void) { 112 | if(! VMBlock_vtable_inited) { 113 | *((VTABLE(VMObject)*)&_VMBlock_vtable) = *VMObject_vtable(); 114 | _VMBlock_vtable.init = METHOD(VMBlock, init); 115 | 116 | _VMBlock_vtable.get_method = METHOD(VMBlock, get_method); 117 | _VMBlock_vtable.get_context = METHOD(VMBlock, get_context); 118 | 119 | _VMBlock_vtable.mark_references = 120 | METHOD(VMBlock, mark_references); 121 | 122 | 123 | VMBlock_vtable_inited = true; 124 | } 125 | return &_VMBlock_vtable; 126 | } 127 | -------------------------------------------------------------------------------- /src/vmobjects/VMBlock.h: -------------------------------------------------------------------------------- 1 | #ifndef VMBLOCK_H_ 2 | #define VMBLOCK_H_ 3 | 4 | /* 5 | * $Id: VMBlock.h 227 2008-04-21 15:21:14Z michael.haupt $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | 35 | #pragma mark VTable definition 36 | 37 | 38 | VTABLE(VMBlock) { 39 | #define VMBLOCK_VTABLE_FORMAT \ 40 | VMOBJECT_VTABLE_FORMAT; \ 41 | pVMMethod (*get_method)(void*); \ 42 | pVMFrame (*get_context)(void*) 43 | 44 | VMBLOCK_VTABLE_FORMAT; 45 | }; 46 | 47 | 48 | #pragma mark class definition 49 | 50 | 51 | #define VMBLOCK_FORMAT \ 52 | VMOBJECT_FORMAT; \ 53 | pVMMethod method; \ 54 | pVMFrame context 55 | 56 | 57 | struct _VMBlock { 58 | VTABLE(VMBlock)* _vtable; 59 | VMBLOCK_FORMAT; 60 | }; 61 | 62 | 63 | #pragma mark class methods 64 | 65 | 66 | pVMBlock VMBlock_new(pVMMethod method, pVMFrame context); 67 | pVMPrimitive VMBlock_get_evaluation_primitive(int64_t number_of_arguments); 68 | 69 | 70 | #pragma mark vtable initialization 71 | 72 | 73 | VTABLE(VMBlock)* VMBlock_vtable(void); 74 | 75 | 76 | #endif // VMBLOCK_H_ 77 | -------------------------------------------------------------------------------- /src/vmobjects/VMClass.h: -------------------------------------------------------------------------------- 1 | #ifndef VMCLASS_H_ 2 | #define VMCLASS_H_ 3 | 4 | /* 5 | * $Id: VMClass.h 227 2008-04-21 15:21:14Z michael.haupt $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | #include 33 | 34 | #include 35 | 36 | #include 37 | 38 | 39 | #pragma mark VTable definition 40 | 41 | 42 | VTABLE(VMClass) { 43 | #define VMCLASS_VTABLE_FORMAT \ 44 | VMOBJECT_VTABLE_FORMAT; \ 45 | pVMClass (*get_super_class)(void*); \ 46 | void (*set_super_class)(void*, pVMClass); \ 47 | bool (*has_super_class)(void*); \ 48 | pVMSymbol (*get_name)(void*); \ 49 | void (*set_name)(void*, pVMSymbol); \ 50 | pVMArray (*get_instance_fields)(void*); \ 51 | void (*set_instance_fields)(void*, pVMArray); \ 52 | pVMArray (*get_instance_invokables)(void*); \ 53 | void (*set_instance_invokables)(void*, pVMArray); \ 54 | int64_t (*get_number_of_instance_invokables)(void*); \ 55 | pVMObject (*get_instance_invokable)(void*, int64_t); \ 56 | void (*set_instance_invokable)(void*, int64_t, pVMObject); \ 57 | pVMObject (*lookup_invokable)(void*, pVMSymbol); \ 58 | int64_t (*lookup_field_index)(void*, pVMSymbol); \ 59 | bool (*add_instance_invokable)(void*, pVMObject); \ 60 | void (*add_instance_primitive)(void*, pVMPrimitive, bool); \ 61 | pVMSymbol (*get_instance_field_name)(void*, int64_t); \ 62 | int64_t (*get_number_of_instance_fields)(void*); \ 63 | bool (*has_primitives)(void*); \ 64 | void (*load_primitives)(void*,const pString*, size_t) 65 | 66 | VMCLASS_VTABLE_FORMAT; 67 | }; 68 | 69 | 70 | #pragma mark class definition 71 | 72 | 73 | #define CLASS_FORMAT \ 74 | VMOBJECT_FORMAT; \ 75 | pVMClass super_class; \ 76 | pVMSymbol name; \ 77 | pVMArray instance_fields; \ 78 | pVMArray instance_invokables 79 | 80 | 81 | struct _VMClass { 82 | VTABLE(VMClass)* _vtable; 83 | CLASS_FORMAT; 84 | }; 85 | 86 | 87 | #pragma mark class methods 88 | 89 | 90 | pVMClass VMClass_new(void); 91 | pVMClass VMClass_new_num_fields(intptr_t); 92 | 93 | pVMClass VMClass_assemble(class_generation_context*); 94 | void VMClass_assemble_system_class(class_generation_context*, pVMClass); 95 | 96 | void VMClass_init_primitive_map(void); 97 | 98 | #pragma mark vtable initialization 99 | 100 | 101 | VTABLE(VMClass)* VMClass_vtable(void); 102 | 103 | 104 | #endif // VMCLASS_H_ 105 | -------------------------------------------------------------------------------- /src/vmobjects/VMDouble.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: VMDouble.c 210 2008-04-16 12:54:12Z michael.haupt $ 3 | * 4 | Copyright (c) 2007 Michael Haupt, Tobias Pape 5 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 6 | http://www.hpi.uni-potsdam.de/swa/ 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | #include "VMDouble.h" 28 | 29 | #include 30 | 31 | // 32 | // Class Methods (Starting with VMDouble_) 33 | // 34 | // 35 | 36 | /** 37 | * Create a new VMDouble 38 | */ 39 | pVMDouble VMDouble_new(void) { 40 | pVMDouble result = (pVMDouble)gc_allocate_object(sizeof(VMDouble)); 41 | if(result) { 42 | result->_vtable = VMDouble_vtable(); 43 | gc_start_uninterruptable_allocation(); 44 | INIT(result, (double) 0); 45 | gc_end_uninterruptable_allocation(); 46 | } 47 | return result; 48 | } 49 | 50 | /** 51 | * Create a new VMDouble with an initial value 52 | */ 53 | pVMDouble VMDouble_new_with(const double dble) { 54 | pVMDouble result = (pVMDouble)gc_allocate_object(sizeof(VMDouble)); 55 | if(result) { 56 | result->_vtable = VMDouble_vtable(); 57 | gc_start_uninterruptable_allocation(); 58 | INIT(result, dble); 59 | gc_end_uninterruptable_allocation(); 60 | } 61 | return result; 62 | } 63 | 64 | 65 | /** 66 | * Initialize a VMDouble 67 | */ 68 | void _VMDouble_init(void* _self, ...) { 69 | pVMDouble self = (pVMDouble)_self; 70 | 71 | SUPER(VMObject, self, init, (intptr_t) 0); 72 | 73 | va_list args; va_start(args, _self); 74 | self->embedded_double = va_arg(args, double); 75 | va_end(args); 76 | } 77 | 78 | // 79 | // Instance Methods (Starting with _VMDouble_) 80 | // 81 | // 82 | double _VMDouble_get_embedded_double(void* _self) { 83 | pVMDouble self = (pVMDouble)_self; 84 | return self->embedded_double; 85 | } 86 | 87 | void _VMDouble_mark_references(void* _self) { 88 | pVMDouble self = (pVMDouble) _self; 89 | SUPER(VMObject, self, mark_references); 90 | } 91 | 92 | 93 | // 94 | // The VTABLE-function 95 | // 96 | // 97 | static VTABLE(VMDouble) _VMDouble_vtable; 98 | bool VMDouble_vtable_inited = false; 99 | 100 | VTABLE(VMDouble)* VMDouble_vtable(void) { 101 | if(! VMDouble_vtable_inited) { 102 | *((VTABLE(VMObject)*)&_VMDouble_vtable) = *VMObject_vtable(); 103 | _VMDouble_vtable.init = METHOD(VMDouble, init); 104 | _VMDouble_vtable.get_embedded_double = 105 | METHOD(VMDouble, get_embedded_double); 106 | 107 | _VMDouble_vtable.mark_references = 108 | METHOD(VMDouble, mark_references); 109 | 110 | VMDouble_vtable_inited = true; 111 | } 112 | return &_VMDouble_vtable; 113 | } 114 | -------------------------------------------------------------------------------- /src/vmobjects/VMDouble.h: -------------------------------------------------------------------------------- 1 | #ifndef VMDOUBLE_H_ 2 | #define VMDOUBLE_H_ 3 | 4 | /* 5 | * $Id: VMDouble.h 168 2008-01-03 14:05:26Z tobias.pape $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | #pragma mark VTable definition 33 | 34 | VTABLE(VMDouble) { 35 | #define VMDOUBLE_VTABLE_FORMAT \ 36 | VMOBJECT_VTABLE_FORMAT; \ 37 | double (*get_embedded_double)(void*) 38 | 39 | VMDOUBLE_VTABLE_FORMAT; 40 | }; 41 | 42 | #pragma mark class definition 43 | 44 | struct _VMDouble { 45 | VTABLE(VMDouble)* _vtable; 46 | 47 | #define DOUBLE_FORMAT \ 48 | VMOBJECT_FORMAT; \ 49 | double embedded_double 50 | 51 | DOUBLE_FORMAT; 52 | }; 53 | 54 | #pragma mark class methods 55 | 56 | pVMDouble VMDouble_new(void); 57 | pVMDouble VMDouble_new_with(const double); 58 | 59 | #pragma mark vtable initialization 60 | 61 | VTABLE(VMDouble)* VMDouble_vtable(void); 62 | 63 | #endif // VMDOUBLE_H_ 64 | -------------------------------------------------------------------------------- /src/vmobjects/VMEvaluationPrimitive.h: -------------------------------------------------------------------------------- 1 | #ifndef VMEVALUATIONPRIMITIVE_H_ 2 | #define VMEVALUATIONPRIMITIVE_H_ 3 | 4 | /* 5 | * $Id: VMEvaluationPrimitive.h 227 2008-04-21 15:21:14Z michael.haupt $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | #pragma mark VTable definition 33 | 34 | VTABLE(VMEvaluationPrimitive) { 35 | 36 | #define VMEVALUATIONPRIMITIVE_VTABLE_FORMAT \ 37 | VMPRIMITIVE_VTABLE_FORMAT 38 | 39 | VMEVALUATIONPRIMITIVE_VTABLE_FORMAT; 40 | }; 41 | 42 | #pragma mark class definition 43 | 44 | #define EVALUATION_PRIMITIVE_FORMAT \ 45 | PRIMITIVE_FORMAT; \ 46 | pVMInteger number_of_arguments 47 | 48 | 49 | struct _VMEvaluationPrimitive { 50 | VTABLE(VMEvaluationPrimitive)* _vtable; 51 | EVALUATION_PRIMITIVE_FORMAT; 52 | }; 53 | 54 | #pragma mark class methods 55 | 56 | pVMEvaluationPrimitive VMEvaluationPrimitive_new(int64_t argc); 57 | 58 | #pragma mark vtable initialization 59 | 60 | VTABLE(VMEvaluationPrimitive)* VMEvaluationPrimitive_vtable(void); 61 | 62 | 63 | #endif // VMEVALUATIONPRIMITIVE_H_ 64 | -------------------------------------------------------------------------------- /src/vmobjects/VMFrame.h: -------------------------------------------------------------------------------- 1 | #ifndef VMFRAME_H_ 2 | #define VMFRAME_H_ 3 | 4 | /* 5 | * $Id: VMFrame.h 227 2008-04-21 15:21:14Z michael.haupt $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | /** 34 | * Frame layout: 35 | * 36 | * +-----------------+ 37 | * | Arguments | 0 38 | * +-----------------+ 39 | * | Local Variables | <-- local_offset 40 | * +-----------------+ 41 | * | Stack | <-- stack_pointer 42 | * | ... | 43 | * +-----------------+ 44 | */ 45 | 46 | #pragma mark VTable definition 47 | 48 | VTABLE(VMFrame) { 49 | 50 | #define VMFRAME_VTABLE_FORMAT \ 51 | VMARRAY_VTABLE_FORMAT; \ 52 | pVMFrame (*get_previous_frame)(void*); \ 53 | void (*clear_previous_frame)(void*); \ 54 | bool (*has_previous_frame)(void*); \ 55 | bool (*is_bootstrap_frame)(void*); \ 56 | pVMFrame (*get_context)(void*); \ 57 | bool (*has_context)(void*); \ 58 | pVMFrame (*get_context_level)(void*, int64_t); \ 59 | pVMFrame (*get_outer_context)(void*); \ 60 | pVMMethod (*get_method)(void*); \ 61 | pVMObject (*pop)(void*); \ 62 | void (*push)(void*, pVMObject); \ 63 | void (*reset_stack_pointer)(void*); \ 64 | size_t (*get_bytecode_index)(void*); \ 65 | void (*set_bytecode_index)(void*, size_t); \ 66 | pVMObject (*get_stack_element)(void*, size_t); \ 67 | void (*set_stack_element)(void*, size_t, pVMObject); \ 68 | pVMObject (*get_local)(void*, size_t, size_t); \ 69 | void (*set_local)(void*, size_t, size_t, pVMObject); \ 70 | pVMObject (*get_argument)(void*, size_t, size_t); \ 71 | void (*set_argument)(void*, size_t, size_t, pVMObject); \ 72 | void (*print_stack_trace)(void*); \ 73 | size_t (*argument_stack_index)(void* frame, size_t index); \ 74 | void (*copy_arguments_from)(void* self, pVMFrame frame) 75 | 76 | VMFRAME_VTABLE_FORMAT; 77 | }; 78 | 79 | #pragma mark class definition 80 | 81 | #define FRAME_FORMAT \ 82 | ARRAY_FORMAT; \ 83 | pVMFrame previous_frame; \ 84 | pVMFrame context; \ 85 | pVMMethod method; \ 86 | size_t stack_pointer; \ 87 | size_t bytecode_index; \ 88 | size_t local_offset 89 | 90 | struct _VMFrame { 91 | VTABLE(VMFrame)* _vtable; 92 | FRAME_FORMAT; 93 | }; 94 | 95 | #pragma mark class methods 96 | 97 | pVMFrame VMFrame_new(size_t length, pVMMethod method, pVMFrame context, pVMFrame previous_frame); 98 | 99 | #pragma mark vtable initialization 100 | 101 | VTABLE(VMFrame)* VMFrame_vtable(void); 102 | 103 | #endif // VMFRAME_H_ 104 | -------------------------------------------------------------------------------- /src/vmobjects/VMInteger.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: VMInteger.c 249 2008-04-28 08:17:23Z michael.haupt $ 3 | * 4 | Copyright (c) 2007 Michael Haupt, Tobias Pape 5 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 6 | http://www.hpi.uni-potsdam.de/swa/ 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | #include "VMInteger.h" 28 | 29 | #include 30 | 31 | 32 | // 33 | // Class Methods (Starting with VMInteger_) 34 | // 35 | 36 | 37 | /** 38 | * Create a new VMInteger 39 | */ 40 | pVMInteger VMInteger_new(void) { 41 | pVMInteger result = (pVMInteger)gc_allocate_object(sizeof(VMInteger)); 42 | if(result) { 43 | result->_vtable = VMInteger_vtable(); 44 | gc_start_uninterruptable_allocation(); 45 | INIT(result, (int64_t) 0); 46 | gc_end_uninterruptable_allocation(); 47 | } 48 | return result; 49 | } 50 | 51 | /** 52 | * Create a new VMInteger with initial value 53 | */ 54 | pVMInteger VMInteger_new_with(const int64_t integer) { 55 | pVMInteger result = (pVMInteger)gc_allocate_object(sizeof(VMInteger)); 56 | if(result) { 57 | result->_vtable = VMInteger_vtable(); 58 | gc_start_uninterruptable_allocation(); 59 | INIT(result, integer); 60 | gc_end_uninterruptable_allocation(); 61 | } 62 | return result; 63 | } 64 | 65 | 66 | /** 67 | * Initialize a VMInteger 68 | */ 69 | void _VMInteger_init(void* _self, ...) { 70 | pVMInteger self = (pVMInteger)_self; 71 | SUPER(VMObject, self, init, (intptr_t) 0); 72 | 73 | va_list args; va_start(args, _self); 74 | self->embedded_integer = va_arg(args, int64_t); 75 | self->hash = self->embedded_integer; 76 | va_end(args); 77 | } 78 | 79 | // 80 | // Instance Methods (Starting with _VMInteger_) 81 | // 82 | // 83 | int64_t _VMInteger_get_embedded_integer(void* _self) { 84 | pVMInteger self = (pVMInteger)_self; 85 | return self->embedded_integer; 86 | } 87 | 88 | 89 | void _VMInteger_set_embedded_integer(void* _self, const int64_t embedded) { 90 | pVMInteger self = (pVMInteger)_self; 91 | self->embedded_integer = embedded; 92 | self->hash = self->embedded_integer; 93 | } 94 | 95 | 96 | void _VMInteger_mark_references(void* _self) { 97 | pVMInteger self = (pVMInteger) _self; 98 | SUPER(VMObject, self, mark_references); 99 | } 100 | 101 | 102 | // 103 | // The VTABLE-function 104 | // 105 | // 106 | static VTABLE(VMInteger) _VMInteger_vtable; 107 | bool VMInteger_vtable_inited = false; 108 | 109 | VTABLE(VMInteger)* VMInteger_vtable(void) { 110 | if(! VMInteger_vtable_inited) { 111 | *((VTABLE(VMObject)*)&_VMInteger_vtable) = *VMObject_vtable(); 112 | _VMInteger_vtable.init = METHOD(VMInteger, init); 113 | _VMInteger_vtable.get_embedded_integer = 114 | METHOD(VMInteger, get_embedded_integer); 115 | 116 | _VMInteger_vtable.mark_references = 117 | METHOD(VMInteger, mark_references); 118 | 119 | VMInteger_vtable_inited = true; 120 | } 121 | return &_VMInteger_vtable; 122 | } 123 | -------------------------------------------------------------------------------- /src/vmobjects/VMInteger.h: -------------------------------------------------------------------------------- 1 | #ifndef VMINTEGER_H_ 2 | #define VMINTEGER_H_ 3 | 4 | /* 5 | * $Id: VMInteger.h 168 2008-01-03 14:05:26Z tobias.pape $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | #pragma mark VTable definition 33 | 34 | VTABLE(VMInteger) { 35 | #define VMINTEGER_VTABLE_FORMAT \ 36 | VMOBJECT_VTABLE_FORMAT; \ 37 | int64_t (*get_embedded_integer)(void*) 38 | 39 | VMINTEGER_VTABLE_FORMAT; 40 | }; 41 | 42 | #pragma mark class definition 43 | 44 | struct _VMInteger { 45 | VTABLE(VMInteger)* _vtable; 46 | 47 | #define INTEGER_FORMAT \ 48 | VMOBJECT_FORMAT; \ 49 | int64_t embedded_integer 50 | 51 | INTEGER_FORMAT; 52 | }; 53 | 54 | #pragma mark class methods 55 | 56 | pVMInteger VMInteger_new(void); 57 | pVMInteger VMInteger_new_with(const int64_t); 58 | 59 | #pragma mark vtable initialization 60 | 61 | VTABLE(VMInteger)* VMInteger_vtable(void); 62 | 63 | #endif // VMINTEGER_H_ 64 | -------------------------------------------------------------------------------- /src/vmobjects/VMInvokable.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: VMInvokable.c 792 2009-04-06 08:07:33Z michael.haupt $ 3 | * 4 | Copyright (c) 2007 Michael Haupt, Tobias Pape 5 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 6 | http://www.hpi.uni-potsdam.de/swa/ 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | #include "VMInvokable.h" 28 | #include "VMMethod.h" 29 | #include "VMPrimitive.h" 30 | #include "VMEvaluationPrimitive.h" 31 | 32 | #include "Signature.h" 33 | 34 | #include 35 | 36 | 37 | void _VMInvokable_invoke(void* _self, pVMFrame fra) { 38 | pVMInvokable self = (pVMInvokable)_self; 39 | // dispatch after actual type (primitive or method) 40 | if(TSEND(VMInvokable, self, is_primitive)) 41 | // no SEND, due to routine is actually data. 42 | ((pVMPrimitive)self)->routine((pVMObject)self, fra); 43 | else 44 | SEND((pVMMethod)self, invoke_method, fra); 45 | } 46 | 47 | 48 | bool _VMInvokable_is_primitive(void* _self) { 49 | pVMInvokable self = (pVMInvokable)_self; 50 | return 51 | (IS_A(self, VMPrimitive) || IS_A(self, VMEvaluationPrimitive)); 52 | } 53 | 54 | 55 | pVMSymbol _VMInvokable_get_signature(void* _self) { 56 | return ((pVMInvokable)_self)->signature; 57 | } 58 | 59 | 60 | pVMClass _VMInvokable_get_holder(void* _self) { 61 | return ((pVMInvokable)_self)->holder; 62 | } 63 | 64 | 65 | void _VMInvokable_set_holder(void* _self, pVMClass cls) { 66 | ((pVMInvokable)_self)->holder = cls; 67 | if(!TSEND(VMInvokable, (pVMInvokable)_self, is_primitive)) 68 | // if method, change holder subsequently 69 | SEND((pVMMethod)_self, set_holder_all, cls); 70 | } 71 | 72 | 73 | void _VMInvokable_mark_references(void* _self) { 74 | pVMInvokable self = (pVMInvokable) _self; 75 | SUPER(VMObject, self, mark_references); 76 | } 77 | 78 | // 79 | // The VTABLE-function 80 | // 81 | // 82 | static VTABLE(VMInvokable) _VMInvokable_vtable; 83 | bool VMInvokable_vtable_inited = false; 84 | 85 | VTABLE(VMInvokable)* VMInvokable_vtable(void) { 86 | if(!VMInvokable_vtable_inited) { 87 | /* per default, a trait does not have any trait */ 88 | _VMInvokable_vtable._ttable = NULL; 89 | _VMInvokable_vtable.invoke = METHOD(VMInvokable, invoke); 90 | _VMInvokable_vtable.is_primitive = METHOD(VMInvokable, is_primitive); 91 | _VMInvokable_vtable.get_signature = METHOD(VMInvokable, get_signature); 92 | _VMInvokable_vtable.get_holder = METHOD(VMInvokable, get_holder); 93 | _VMInvokable_vtable.set_holder = METHOD(VMInvokable, set_holder); 94 | 95 | _VMInvokable_vtable.mark_references = 96 | METHOD(VMInvokable, mark_references); 97 | 98 | VMInvokable_vtable_inited = true; 99 | } 100 | return &_VMInvokable_vtable; 101 | } 102 | -------------------------------------------------------------------------------- /src/vmobjects/VMInvokable.h: -------------------------------------------------------------------------------- 1 | #ifndef VMINVOKABLE_H_ 2 | #define VMINVOKABLE_H_ 3 | 4 | /* 5 | * $Id: VMInvokable.h 227 2008-04-21 15:21:14Z michael.haupt $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | // the following are invokables: 31 | // * method 32 | // * primitive 33 | 34 | #include 35 | #include 36 | 37 | #include 38 | 39 | VTABLE(VMInvokable) { 40 | void* _ttable; // for OOObject compatibility 41 | void (*invoke)(void*, pVMFrame); 42 | bool (*is_primitive)(void*); 43 | pVMSymbol (*get_signature)(void*); 44 | pVMClass (*get_holder)(void*); 45 | void (*set_holder)(void*, pVMClass); 46 | int (*get_size_of_object)(void*); 47 | void (*mark_references)(void*); 48 | }; 49 | 50 | struct _VMInvokable { 51 | VTABLE(VMInvokable)* _vtable; 52 | VMOBJECT_FORMAT; 53 | pVMSymbol signature; 54 | pVMClass holder; 55 | }; 56 | 57 | #pragma mark vtable initialization 58 | 59 | VTABLE(VMInvokable)* VMInvokable_vtable(void); 60 | 61 | 62 | #endif // VMINVOKABLE_H_ 63 | -------------------------------------------------------------------------------- /src/vmobjects/VMMethod.h: -------------------------------------------------------------------------------- 1 | #ifndef VMMETHOD_H_ 2 | #define VMMETHOD_H_ 3 | 4 | /* 5 | * $Id: VMMethod.h 227 2008-04-21 15:21:14Z michael.haupt $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | 35 | #include 36 | 37 | 38 | #pragma mark VTable definition 39 | 40 | 41 | VTABLE(VMMethod) { 42 | #define VMMETHOD_VTABLE_FORMAT \ 43 | VMARRAY_VTABLE_FORMAT; \ 44 | int64_t (*get_number_of_locals)(void*); \ 45 | int64_t (*get_maximum_number_of_stack_elements)(void*); \ 46 | void (*set_holder_all)(void*, pVMClass); \ 47 | pVMObject (*get_constant)(void*, size_t); \ 48 | int64_t (*get_number_of_arguments)(void*); \ 49 | int64_t (*get_number_of_bytecodes)(void*); \ 50 | uint8_t (*get_bytecode)(void*, size_t); \ 51 | void (*set_bytecode)(void*, size_t, uint8_t); \ 52 | void (*invoke_method)(void*, pVMFrame) 53 | 54 | VMMETHOD_VTABLE_FORMAT; 55 | }; 56 | 57 | 58 | #pragma mark class definition 59 | 60 | 61 | #define METHOD_FORMAT \ 62 | ARRAY_FORMAT; \ 63 | pVMSymbol signature; \ 64 | pVMClass holder; \ 65 | size_t number_of_locals; \ 66 | size_t maximum_number_of_stack_elements; \ 67 | size_t bytecodes_length; \ 68 | size_t number_of_arguments 69 | 70 | struct _VMMethod { 71 | VTABLE(VMMethod)* _vtable; 72 | METHOD_FORMAT; 73 | }; 74 | 75 | 76 | #pragma mark class methods 77 | 78 | 79 | pVMMethod VMMethod_new(size_t number_of_constants, size_t number_of_bytecodes, 80 | size_t number_of_locals, 81 | size_t max_number_of_stack_elements, 82 | pVMSymbol signature); 83 | pVMMethod VMMethod_assemble(method_generation_context* mgenc); 84 | 85 | 86 | #pragma mark vtable initialization 87 | 88 | 89 | VTABLE(VMMethod)* VMMethod_vtable(void); 90 | 91 | 92 | #endif // VMMETHOD_H_ 93 | -------------------------------------------------------------------------------- /src/vmobjects/VMObject.h: -------------------------------------------------------------------------------- 1 | #ifndef VMOBJECT_H_ 2 | #define VMOBJECT_H_ 3 | 4 | /* 5 | * $Id: VMObject.h 792 2009-04-06 08:07:33Z michael.haupt $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | #include 33 | 34 | #include 35 | 36 | #pragma mark VM Allocation Helper 37 | 38 | 39 | #pragma mark VTable definition 40 | 41 | VTABLE(VMObject) { 42 | #define VMOBJECT_VTABLE_FORMAT \ 43 | OOOBJECT_VTABLE_FORMAT; \ 44 | pVMClass (*get_class)(void*); \ 45 | void (*set_class)(void*, pVMClass); \ 46 | pVMSymbol (*get_field_name)(void*, int64_t); \ 47 | int64_t (*get_field_index)(void*, pVMSymbol); \ 48 | intptr_t (*get_number_of_fields)(void*); \ 49 | int64_t (*get_default_number_of_fields)(void*); \ 50 | void (*send)(void*, pVMSymbol, pVMObject*, size_t); \ 51 | pVMObject (*get_field)(void*, int64_t); \ 52 | void (*set_field)(void*, int64_t, pVMObject); \ 53 | void (*mark_references)(void*) 54 | 55 | VMOBJECT_VTABLE_FORMAT; 56 | }; 57 | 58 | #pragma mark class definition 59 | 60 | #define VMOBJECT_FORMAT \ 61 | OOOBJECT_FORMAT; \ 62 | intptr_t num_of_fields;\ 63 | pVMClass class; \ 64 | pVMObject fields[0] 65 | 66 | 67 | /* 68 | * This is the number of fields visible to Smalltalk objects from the Smalltalk 69 | * side of the world. The sizes of the VMObject and OOObject structs are 70 | * subtracted. Moreover, 2 is subtracted to reflect the presence of the 71 | * "num_of_fields" field, and the class field which are not visible. 72 | */ 73 | #define NUMBER_OF_OBJECT_FIELDS (OBJECT_SIZE_DIFF(VMObject,OOObject)-2) 74 | 75 | 76 | struct _VMObject { 77 | VTABLE(VMObject)* _vtable; 78 | VMOBJECT_FORMAT; 79 | }; 80 | 81 | #pragma mark class methods 82 | 83 | pVMObject VMObject_new(void); 84 | pVMObject VMObject_new_num_fields(intptr_t); 85 | void VMObject_assert(bool); 86 | 87 | #pragma mark vtable initialization 88 | 89 | VTABLE(VMObject)* VMObject_vtable(void); 90 | 91 | #endif // VMOBJECT_H_ 92 | -------------------------------------------------------------------------------- /src/vmobjects/VMPrimitive.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: VMPrimitive.c 792 2009-04-06 08:07:33Z michael.haupt $ 3 | * 4 | Copyright (c) 2007 Michael Haupt, Tobias Pape 5 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 6 | http://www.hpi.uni-potsdam.de/swa/ 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | #include "VMPrimitive.h" 28 | #include "VMInvokable.h" 29 | #include "VMSymbol.h" 30 | 31 | #include 32 | 33 | #include 34 | 35 | #include 36 | 37 | #include 38 | 39 | 40 | void empty_routine(pVMObject prim, pVMFrame); 41 | 42 | 43 | // 44 | // Class Methods (Starting with VMPrimitive_) 45 | // 46 | 47 | 48 | /** 49 | * Create a new VMPrimitive 50 | */ 51 | pVMPrimitive VMPrimitive_new(pVMSymbol signature) { 52 | pVMPrimitive result = (pVMPrimitive)gc_allocate_object(sizeof(VMPrimitive)); 53 | if(result) { 54 | result->_vtable = VMPrimitive_vtable(); 55 | gc_start_uninterruptable_allocation(); 56 | INIT(result, SIZE_DIFF_VMOBJECT(VMPrimitive), signature); 57 | gc_end_uninterruptable_allocation(); 58 | } 59 | 60 | return result; 61 | } 62 | 63 | 64 | /** 65 | * Create a new VMPrimitive with an explicit empty-routine 66 | */ 67 | pVMPrimitive VMPrimitive_get_empty_primitive(pVMSymbol signature) { 68 | debug_info("\t\t'%s'*\n", signature->chars); 69 | pVMPrimitive prim = VMPrimitive_new(signature); 70 | prim->empty = true; 71 | prim->routine = empty_routine; 72 | 73 | // Return an empty primitive with the given signature 74 | return prim; 75 | } 76 | 77 | 78 | pVMPrimitive VMPrimitive_assemble(method_generation_context* mgenc) { 79 | return VMPrimitive_get_empty_primitive(mgenc->signature); 80 | } 81 | 82 | 83 | /** 84 | * Initialize a VMPrimitive 85 | */ 86 | void _VMPrimitive_init(void* _self, ...) { 87 | pVMPrimitive self = (pVMPrimitive)_self; 88 | va_list args; va_start(args, _self); 89 | 90 | // call "super" constructor 91 | SUPER(VMObject, self, init, va_arg(args, size_t)); 92 | 93 | // 94 | // Set the class of this primitive to be the universal primitive class 95 | // NOTE: this is the only branch of the object hierachy, which 96 | // does this in the init method! 97 | // 98 | SEND(self, set_class, primitive_class); 99 | 100 | // Set the signature of this primitive 101 | self->signature = va_arg(args, pVMSymbol); 102 | va_end(args); 103 | 104 | // set routine to NULL 105 | self->routine = NULL; 106 | self->empty = false; 107 | } 108 | 109 | 110 | void _VMPrimitive_free(void* _self) { 111 | pVMPrimitive self = (pVMPrimitive)_self; 112 | SUPER(VMObject, self, free); 113 | } 114 | 115 | 116 | // 117 | // Instance Primitive (Starting with _VMPrimitive_) 118 | // 119 | 120 | 121 | bool _VMPrimitive_is_empty(void* _self) { 122 | pVMPrimitive self = (pVMPrimitive)_self; 123 | return self->empty; 124 | } 125 | 126 | 127 | void _VMPrimitive_set_routine(void* _self, routine_fn routine) { 128 | pVMPrimitive self = (pVMPrimitive)_self; 129 | self->routine = routine; 130 | } 131 | 132 | 133 | void empty_routine(pVMObject self, pVMFrame frame) { 134 | pVMSymbol sig = TSEND(VMInvokable, self, get_signature); 135 | debug_warn("undefined primitive %s called", SEND(sig, get_rawChars)); 136 | } 137 | 138 | 139 | void _VMPrimitive_mark_references(void* _self) { 140 | pVMPrimitive self = (pVMPrimitive) _self; 141 | gc_mark_object(self->signature); 142 | gc_mark_object(self->holder); 143 | SUPER(VMObject, self, mark_references); 144 | } 145 | 146 | 147 | // 148 | // The VTABLE-function 149 | // 150 | 151 | 152 | static VTABLE(VMPrimitive) _VMPrimitive_vtable; 153 | bool VMPrimitive_vtable_inited = false; 154 | 155 | 156 | VTABLE(VMPrimitive)* VMPrimitive_vtable(void) { 157 | if(! VMPrimitive_vtable_inited) { 158 | *((VTABLE(VMObject)*)&_VMPrimitive_vtable) = *VMObject_vtable(); 159 | 160 | ASSIGN_TRAIT(VMInvokable, VMPrimitive); 161 | 162 | _VMPrimitive_vtable.init = METHOD(VMPrimitive, init); 163 | _VMPrimitive_vtable.is_empty = METHOD(VMPrimitive, is_empty); 164 | _VMPrimitive_vtable.set_routine = METHOD(VMPrimitive, set_routine); 165 | _VMPrimitive_vtable.free = METHOD(VMPrimitive, free); 166 | 167 | _VMPrimitive_vtable.mark_references = 168 | METHOD(VMPrimitive, mark_references); 169 | 170 | VMPrimitive_vtable_inited = true; 171 | } 172 | return &_VMPrimitive_vtable; 173 | } 174 | -------------------------------------------------------------------------------- /src/vmobjects/VMPrimitive.h: -------------------------------------------------------------------------------- 1 | #ifndef VMPRIMITIVE_H_ 2 | #define VMPRIMITIVE_H_ 3 | 4 | /* 5 | * $Id: VMPrimitive.h 792 2009-04-06 08:07:33Z michael.haupt $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | #include 33 | 34 | #include 35 | 36 | 37 | #pragma mark VTable definition 38 | 39 | 40 | VTABLE(VMPrimitive) { 41 | #define VMPRIMITIVE_VTABLE_FORMAT \ 42 | VMOBJECT_VTABLE_FORMAT; \ 43 | bool (*is_empty)(void*); \ 44 | void (*set_routine)(void*, routine_fn) 45 | 46 | VMPRIMITIVE_VTABLE_FORMAT; 47 | }; 48 | 49 | 50 | #pragma mark class definition 51 | 52 | 53 | #define PRIMITIVE_FORMAT \ 54 | VMOBJECT_FORMAT; \ 55 | pVMSymbol signature; \ 56 | pVMClass holder; \ 57 | routine_fn routine; \ 58 | bool empty 59 | 60 | 61 | struct _VMPrimitive { 62 | VTABLE(VMPrimitive)* _vtable; 63 | PRIMITIVE_FORMAT; 64 | }; 65 | 66 | 67 | #pragma mark class methods 68 | 69 | 70 | pVMPrimitive VMPrimitive_new(pVMSymbol signature); 71 | pVMPrimitive VMPrimitive_get_empty_primitive(pVMSymbol signature); 72 | pVMPrimitive VMPrimitive_assemble(method_generation_context* mgenc); 73 | 74 | 75 | #pragma mark vtable initialization 76 | 77 | 78 | VTABLE(VMPrimitive)* VMPrimitive_vtable(void); 79 | 80 | 81 | #endif // VMPRIMITIVE_H_ 82 | -------------------------------------------------------------------------------- /src/vmobjects/VMString.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: VMString.c 792 2009-04-06 08:07:33Z michael.haupt $ 3 | * 4 | Copyright (c) 2007 Michael Haupt, Tobias Pape 5 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 6 | http://www.hpi.uni-potsdam.de/swa/ 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | #include "VMString.h" 28 | 29 | #include 30 | 31 | #include 32 | 33 | 34 | // 35 | // Class Methods (Starting with VMString_) 36 | // 37 | 38 | 39 | pVMString VMString_new(const char* restrict chars, size_t length) { 40 | pVMString result = (pVMString)gc_allocate_object( 41 | sizeof(VMString) + sizeof(char) * (length + 1)); 42 | if (result) { 43 | result->_vtable = VMString_vtable(); 44 | gc_start_uninterruptable_allocation(); 45 | INIT(result, chars, length); 46 | gc_end_uninterruptable_allocation(); 47 | } 48 | return result; 49 | } 50 | 51 | pVMString VMString_new_concat(pVMString a, pVMString b) { 52 | size_t aLen = SEND(a, get_length); 53 | size_t bLen = SEND(b, get_length); 54 | 55 | pVMString result = (pVMString)gc_allocate_object( 56 | sizeof(VMString) + sizeof(char) * (aLen + bLen + 1)); 57 | 58 | if (result) { 59 | result->_vtable = VMString_vtable(); 60 | gc_start_uninterruptable_allocation(); 61 | INIT(result, "", 0); 62 | gc_end_uninterruptable_allocation(); 63 | 64 | // now, do the actual concatination work 65 | size_t i = 0; 66 | for (; i < aLen; i++) { 67 | result->chars[i] = a->chars[i]; 68 | } 69 | 70 | size_t j = 0; 71 | for (; j < bLen; i++, j++) { 72 | result->chars[i] = b->chars[j]; 73 | } 74 | 75 | result->length = aLen + bLen; 76 | result->chars[result->length] = '\0'; 77 | } 78 | return result; 79 | } 80 | 81 | /** 82 | * Initialize a VMString 83 | */ 84 | void _VMString_init(void* _self, ...) { 85 | pVMString self = (pVMString)_self; 86 | SUPER(VMObject, self, init, (intptr_t) 0); 87 | 88 | va_list args; 89 | va_start(args, _self); 90 | const char* embed = va_arg(args, char*); 91 | size_t length = va_arg(args, size_t); 92 | va_end(args); 93 | 94 | memcpy(self->chars, embed, length); 95 | self->chars[length] = '\0'; 96 | self->length = length; 97 | self->hash = 0; 98 | } 99 | 100 | 101 | // 102 | // Instance Methods (Starting with _VMString_) 103 | // 104 | 105 | 106 | const char* _VMString_get_rawChars(void* _self) { 107 | return (const char*)(((pVMString)_self)->chars); 108 | } 109 | 110 | 111 | const size_t _VMString_get_length(void* _self) { 112 | return (const size_t)(((pVMString)_self)->length); 113 | } 114 | 115 | 116 | // 117 | // The VTABLE-function 118 | // 119 | 120 | 121 | static VTABLE(VMString) _VMString_vtable; 122 | bool VMString_vtable_inited = false; 123 | 124 | 125 | VTABLE(VMString)* VMString_vtable(void) { 126 | if(! VMString_vtable_inited) { 127 | *((VTABLE(VMObject)*)&_VMString_vtable) = *VMObject_vtable(); 128 | _VMString_vtable.init = METHOD(VMString, init); 129 | 130 | _VMString_vtable.get_length = METHOD(VMString, get_length); 131 | _VMString_vtable.get_rawChars = METHOD(VMString, get_rawChars); 132 | 133 | VMString_vtable_inited = true; 134 | } 135 | return &_VMString_vtable; 136 | } 137 | -------------------------------------------------------------------------------- /src/vmobjects/VMString.h: -------------------------------------------------------------------------------- 1 | #ifndef VMSTRING_H_ 2 | #define VMSTRING_H_ 3 | 4 | /* 5 | * $Id: VMString.h 792 2009-04-06 08:07:33Z michael.haupt $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | #pragma mark VTable definition 33 | 34 | VTABLE(VMString) { 35 | #define VMSTRING_VTABLE_FORMAT \ 36 | VMOBJECT_VTABLE_FORMAT; \ 37 | const size_t (*get_length)(void*); \ 38 | const char* (*get_rawChars)(void*) 39 | 40 | VMSTRING_VTABLE_FORMAT; 41 | }; 42 | 43 | #pragma mark class definition 44 | 45 | #define VMSTRING_FORMAT \ 46 | VMOBJECT_FORMAT; \ 47 | size_t length; \ 48 | char chars[0] 49 | 50 | 51 | struct _VMString { 52 | VTABLE(VMString)* _vtable; 53 | 54 | VMSTRING_FORMAT; 55 | }; 56 | 57 | #pragma mark class methods 58 | 59 | pVMString VMString_new(const char* restrict chars, size_t length); 60 | pVMString VMString_new_concat(pVMString a, pVMString b); 61 | 62 | #pragma mark vtable initialization 63 | 64 | VTABLE(VMString)* VMString_vtable(void); 65 | 66 | #endif // VMSTRING_H_ 67 | -------------------------------------------------------------------------------- /src/vmobjects/VMSymbol.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: VMSymbol.c 792 2009-04-06 08:07:33Z michael.haupt $ 3 | * 4 | Copyright (c) 2007 Michael Haupt, Tobias Pape 5 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 6 | http://www.hpi.uni-potsdam.de/swa/ 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | #include "VMSymbol.h" 28 | 29 | #include 30 | 31 | #include 32 | 33 | // 34 | // Class Methods (Starting with VMSymbol_) 35 | // 36 | 37 | 38 | /** 39 | * Create a new VMSymbol with an initial C-string 40 | */ 41 | pVMSymbol VMSymbol_new(pString restrict string) { 42 | pVMSymbol result = (pVMSymbol)gc_allocate_object( 43 | sizeof(VMSymbol) + sizeof(char) * (string->length + 1)); 44 | if (result) { 45 | result->_vtable = VMSymbol_vtable(); 46 | gc_start_uninterruptable_allocation(); 47 | INIT(result, (char*) string->chars, string->length); 48 | gc_end_uninterruptable_allocation(); 49 | } 50 | return result; 51 | } 52 | 53 | 54 | /** 55 | * Initialize a VMSymbol 56 | */ 57 | void _VMSymbol_init(void* _self, ...) { 58 | va_list args; 59 | va_start(args, _self); 60 | char* chars = va_arg(args, char*); 61 | size_t len = va_arg(args, size_t); 62 | 63 | SUPER(VMString, _self, init, chars, len); 64 | 65 | va_end(args); 66 | } 67 | 68 | 69 | // 70 | // Instance Methods (Starting with _VMSymbol_) 71 | // 72 | 73 | 74 | const char* _VMSymbol_get_plain_string(void* _self) { 75 | pVMSymbol self = (pVMSymbol)_self; 76 | char plain_string[1024]; 77 | plain_string[0] = '\0'; 78 | 79 | size_t l = self->length; 80 | for (size_t i = 0; i <= l; i++) { 81 | switch(self->chars[i]) { 82 | case '~': 83 | strcat(plain_string, "tilde"); 84 | break; 85 | case '&': 86 | strcat(plain_string, "and"); 87 | break; 88 | case '|': 89 | strcat(plain_string, "bar"); 90 | break; 91 | case '*': 92 | strcat(plain_string, "star"); 93 | break; 94 | case '/': 95 | strcat(plain_string, "slash"); 96 | break; 97 | case '@': 98 | strcat(plain_string, "at"); 99 | break; 100 | case '+': 101 | strcat(plain_string, "plus"); 102 | break; 103 | case '-': 104 | strcat(plain_string, "minus"); 105 | break; 106 | case '=': 107 | strcat(plain_string, "equal"); 108 | break; 109 | case '>': 110 | strcat(plain_string, "greaterthan"); 111 | break; 112 | case '<': 113 | strcat(plain_string, "lessthan"); 114 | break; 115 | case ',': 116 | strcat(plain_string, "comma"); 117 | break; 118 | case '%': 119 | strcat(plain_string, "percent"); 120 | break; 121 | case '\\': 122 | strcat(plain_string, "backslash"); 123 | break; 124 | case ':': 125 | #ifdef EXPERIMENTAL 126 | case ' ': 127 | #endif 128 | strcat(plain_string, "_"); 129 | break; 130 | default: { 131 | int64_t l = strlen(plain_string); 132 | plain_string[l] = self->chars[i]; 133 | plain_string[l + 1] = '\0'; 134 | break; 135 | } 136 | } 137 | } 138 | char* result = (char*)internal_allocate(strlen(plain_string) + 1); 139 | strcpy(result, plain_string); 140 | return (const char*)result; 141 | } 142 | 143 | 144 | // 145 | // The VTABLE-function 146 | // 147 | 148 | 149 | static VTABLE(VMSymbol) _VMSymbol_vtable; 150 | bool VMSymbol_vtable_inited = false; 151 | 152 | 153 | VTABLE(VMSymbol)* VMSymbol_vtable(void) { 154 | if(! VMSymbol_vtable_inited) { 155 | *((VTABLE(VMString)*)&_VMSymbol_vtable) = *VMString_vtable(); 156 | _VMSymbol_vtable.init = METHOD(VMSymbol, init); 157 | _VMSymbol_vtable.get_plain_string = METHOD(VMSymbol, get_plain_string); 158 | 159 | VMSymbol_vtable_inited = true; 160 | } 161 | return &_VMSymbol_vtable; 162 | } 163 | 164 | -------------------------------------------------------------------------------- /src/vmobjects/VMSymbol.h: -------------------------------------------------------------------------------- 1 | #ifndef VMSYMBOL_H_ 2 | #define VMSYMBOL_H_ 3 | 4 | /* 5 | * $Id: VMSymbol.h 792 2009-04-06 08:07:33Z michael.haupt $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | #include 33 | 34 | #pragma mark VTable definition 35 | 36 | VTABLE(VMSymbol) { 37 | #define VMSYMBOL_VTABLE_FORMAT \ 38 | VMSTRING_VTABLE_FORMAT; \ 39 | const char* (*get_plain_string)(void*) 40 | 41 | VMSYMBOL_VTABLE_FORMAT; 42 | }; 43 | 44 | #pragma mark class definition 45 | 46 | #define VMSYMBOL_FORMAT \ 47 | VMSTRING_FORMAT 48 | 49 | 50 | struct _VMSymbol { 51 | VTABLE(VMSymbol)* _vtable; 52 | VMSYMBOL_FORMAT; 53 | }; 54 | 55 | #pragma mark class methods 56 | 57 | pVMSymbol VMSymbol_new(pString restrict); 58 | 59 | #pragma mark vtable initialization 60 | 61 | VTABLE(VMSymbol)* VMSymbol_vtable(void); 62 | 63 | #endif // VMSYMBOL_H_ 64 | -------------------------------------------------------------------------------- /src/vmobjects/objectformats.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECTFORMATS_H_ 2 | #define OBJECTFORMATS_H_ 3 | 4 | /* 5 | * $Id: objectformats.h 229 2008-04-22 14:10:50Z tobias.pape $ 6 | * 7 | Copyright (c) 2007 Michael Haupt, Tobias Pape 8 | Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany 9 | http://www.hpi.uni-potsdam.de/swa/ 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | */ 29 | 30 | typedef struct _OOObject OOObject, *pOOObject; 31 | typedef struct _String String, *pString; 32 | typedef struct _List List, *pList; 33 | typedef struct _HashmapElem HashmapElem, *pHashmapElem; 34 | typedef struct _StringHashmapElem StringHashmapElem, 35 | *pStringHashmapElem; 36 | typedef struct _Hashmap Hashmap, *pHashmap; 37 | typedef struct _StringHashmap StringHashmap, *pStringHashmap; 38 | typedef struct _VMObject VMObject, *pVMObject; 39 | typedef struct _VMArray VMArray, *pVMArray; 40 | typedef struct _VMMethod VMMethod, *pVMMethod; 41 | typedef struct _VMFrame VMFrame, *pVMFrame; 42 | typedef struct _VMBlock VMBlock, *pVMBlock; 43 | typedef struct _VMClass VMClass, *pVMClass; 44 | typedef struct _VMDouble VMDouble, *pVMDouble; 45 | typedef struct _VMInteger VMInteger, *pVMInteger; 46 | typedef struct _VMPrimitive VMPrimitive, *pVMPrimitive; 47 | typedef struct _VMEvaluationPrimitive VMEvaluationPrimitive, 48 | *pVMEvaluationPrimitive; 49 | typedef struct _VMString VMString, *pVMString; 50 | typedef struct _VMSymbol VMSymbol, *pVMSymbol; 51 | 52 | typedef struct _VMInvokable VMInvokable, *pVMInvokable; 53 | 54 | typedef struct _free_list_entry free_list_entry, *pFree_list_entry; 55 | 56 | 57 | /** 58 | * typedef for Loaded primitives... 59 | */ 60 | #include 61 | typedef void (*routine_fn)(pVMObject, pVMFrame); 62 | typedef bool (*supports_class_fn)(const char*); 63 | typedef void (*init_csp_fn)(void); 64 | 65 | #endif // OBJECTFORMATS_H_ 66 | 67 | 68 | -------------------------------------------------------------------------------- /tests/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | bool run_all_tests(void); 5 | 6 | int main(int argc, const char * argv[]) { 7 | printf("Run Basic Interpreter Tests\n"); 8 | 9 | bool has_failures = run_all_tests(); 10 | 11 | return has_failures ? 1 : 0; 12 | } 13 | --------------------------------------------------------------------------------