├── .gitignore ├── .vscode ├── c_cpp_properties.json ├── launch.json ├── settings.json └── tasks.json ├── AST.md ├── LICENSE ├── OTHER.md ├── README.md ├── RI.md ├── VM.md ├── bin ├── bit.dll ├── lfs.dll ├── lua.exe ├── lua │ ├── inspect.lua │ ├── json.lua │ ├── template.lua │ └── util.lua ├── lua51.dll └── sokol-shdc.exe ├── build.bat ├── build.lua └── src ├── TODO.md ├── build └── build-app.lua ├── id ├── id-command.h ├── id-component.h ├── id-error.h └── id-event.h ├── lib ├── co-lib.c ├── co-lib.h ├── co-math.h ├── stb_printf.h └── win32 │ └── msvcrt │ ├── README.md │ ├── chkstk64.obj │ ├── msvcrt.def │ ├── msvcrt.dll │ ├── msvcrt.exp │ └── msvcrt.lib ├── main.c ├── ri-print.c ├── ri.c ├── ri.h ├── rivm-compiler.c ├── rivm-compiler.h ├── rivm-dump.c ├── rivm-dump.h ├── rivm-interpreter.c ├── rivm-interpreter.h ├── rivm-op.h ├── rivm.c ├── rivm.h ├── test-ri.c ├── test-rivm-compiler.c ├── test-rivm-interpreter.c └── test ├── ast ├── parse │ ├── const-real.recent.lisp │ ├── const-real.ri │ ├── for.ri │ ├── func-no-input-arguments.expected.lisp │ ├── func-no-input-arguments.recent.lisp │ ├── func-no-input-arguments.ri │ ├── switch.recent.lisp │ └── switch.ri └── resolve │ ├── assignment-infer-error.excpected.lisp │ ├── assignment-infer-error.recent.lisp │ ├── assignment-infer-error.ri │ ├── assignment.recent.lisp │ ├── assignment.ri │ ├── cast-arguments-count-error.expected.lisp │ ├── cast-arguments-count-error.recent.lisp │ ├── cast-arguments-count-error.ri │ ├── cast-bool.recent.lisp │ ├── cast-bool.ri │ ├── cast-float-to-bool-error.recent.lisp │ ├── cast-float-to-bool-error.ri │ ├── cast-int-to-bool-error.expected.lisp │ ├── cast-int-to-bool-error.recent.lisp │ ├── cast-int-to-bool-error.ri │ ├── decl.recent.lisp │ ├── decl.ri │ ├── for-condition-error-is-st.recent.lisp │ ├── for-condition-error-is-st.ri │ ├── for.recent.lisp │ ├── for.ri │ ├── if-condition-error-bool.expected.lisp │ ├── if-condition-error-bool.recent.lisp │ ├── if-condition-error-bool.ri │ ├── if-condition-error-is-st.ri │ ├── if.recent.lisp │ ├── if.ri │ ├── op-arithmetic-type-mismatch-error.recent.lisp │ ├── op-arithmetic-type-mismatch-error.ri │ ├── op-arithmetic.expected.lisp │ ├── op-arithmetic.recent.lisp │ ├── op-arithmetic.ri │ ├── op-binary.expected.lisp │ ├── op-binary.recent.lisp │ ├── op-bitwise.recent.lisp │ ├── op-bitwise.ri │ ├── op-boolean.recent.lisp │ ├── op-boolean.ri │ ├── op-comparison.recent.lisp │ ├── op-comparison.ri │ ├── test1.recent.lisp │ ├── test1.ri │ ├── type-inference-const-binary-left-error.expected.lisp │ ├── type-inference-const-binary-left-error.recent.lisp │ ├── type-inference-const-binary-left-error.ri │ ├── type-inference-const-binary-right-error.expected.lisp │ ├── type-inference-const-binary-right-error.recent.lisp │ ├── type-inference-const-binary-right-error.ri │ ├── type-inference-const.recent.lisp │ ├── type-inference-const.ri │ ├── type-inference.recent.lisp │ ├── type-spec.recent.lisp │ └── type-spec.ri ├── vmc ├── func.recent.lisp ├── func.ri ├── if-else.recent.lisp ├── if-else.ri ├── if.recent.lisp ├── if.ri ├── op-binary.recent.lisp └── op-binary.ri └── vmi ├── fib34.ri └── test1.ri /.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | __pycache__ 3 | *.log 4 | .vscode/ipch 5 | .vs 6 | -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Win32", 5 | "includePath": [ 6 | "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include/*", 7 | "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/um/*", 8 | "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/ucrt/*", 9 | "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/shared/*", 10 | "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/winrt/*", 11 | "${workspaceRoot}/**", 12 | "${workspaceRoot}/lib/*", 13 | "${workspaceRoot}/lib/ray/include/**" 14 | ], 15 | "defines": [ 16 | "_DEBUG", 17 | "UNICODE" 18 | ], 19 | "intelliSenseMode": "msvc-x64", 20 | "browse": { 21 | "path": [ 22 | "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include/*", 23 | "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/um/*", 24 | "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/ucrt/*", 25 | "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/shared/*", 26 | "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/winrt/*", 27 | "${workspaceRoot}" 28 | ], 29 | "limitSymbolsToIncludedHeaders": true, 30 | "databaseFilename": "" 31 | }, 32 | "cStandard": "c11", 33 | "cppStandard": "c++17" 34 | } 35 | ], 36 | "version": 4 37 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "(Windows) Launch", 6 | "type": "cppvsdbg", 7 | "request": "launch", 8 | "program": "${workspaceRoot}/build/main.exe", 9 | "cwd": "${workspaceRoot}/", 10 | "stopAtEntry": false, 11 | "environment": [], 12 | "externalConsole": true, 13 | 14 | "preLaunchTask": "build", 15 | "internalConsoleOptions": "openOnSessionStart", 16 | "logging": { 17 | "moduleLoad": false 18 | } 19 | }, 20 | { 21 | "name": "C++ Attach (Windows)", 22 | "type": "cppvsdbg", 23 | "request": "attach", 24 | "processId": "${command.pickProcess}" 25 | } 26 | ] 27 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "*.odin": "odin", 4 | "*.ri": "go", 5 | "*.h": "c", 6 | "*.rlex": "lua", 7 | "initializer_list": "cpp", 8 | "type_traits": "cpp", 9 | "xutility": "cpp", 10 | "xmemory0": "cpp", 11 | "iosfwd": "cpp", 12 | "xmemory": "cpp", 13 | "utility": "cpp", 14 | "xstddef": "cpp", 15 | "xtr1common": "cpp", 16 | "*.rh": "c", 17 | "ctype.h": "c", 18 | "xstring": "c", 19 | "xlocale": "c", 20 | "xlocnum": "c", 21 | "system_error": "c", 22 | "list": "c", 23 | "vector": "c", 24 | "xhash": "c" 25 | }, 26 | "search.exclude": { 27 | "**/.env": true, 28 | "**/.env-laptop": true, 29 | "**/__pycache__": true, 30 | "**/.git": true 31 | }, 32 | "window.title": "RI - ${activeEditorShort}", 33 | "[go]": { 34 | "editor.formatOnSave": false 35 | } 36 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "build", 8 | "type": "process", 9 | "command" : "${workspaceRoot}\\build.bat", 10 | "problemMatcher": [ "$msCompile" ], 11 | "group": { 12 | "kind": "build", 13 | "isDefault": true 14 | } 15 | }, 16 | { 17 | "label": "build-clang", 18 | "type": "process", 19 | "command" : "${workspaceRoot}\\build-clang.bat", 20 | "problemMatcher": [ "$msCompile" ], 21 | } 22 | ] 23 | } -------------------------------------------------------------------------------- /AST.md: -------------------------------------------------------------------------------- 1 | # AST 2 | 3 | ## `Spec` nodes 4 | Actual definition of one of language's entities: 5 | 6 | - Types 7 | - Numeric 8 | - Boolean 9 | - Signed integer 10 | - Unsigned integer 11 | - Floating point 12 | - Function 13 | - Pointer 14 | - Compound 15 | - Struct 16 | - Union 17 | - Functions 18 | - Variables 19 | 20 | ## `Decl` nodes 21 | Instances of spec declaration (assigning a symbol name to language entity spec). 22 | 23 | ## `Value` nodes 24 | Symbols resolve to values. 25 | 26 | - Specs resolved from symbols through declarations. 27 | - Specs defined in place. 28 | - Constants 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Martin Cohen 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 all 13 | 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 THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /OTHER.md: -------------------------------------------------------------------------------- 1 | # Misc 2 | 3 | https://github.com/tj/luna 4 | 5 | # Go 6 | 7 | https://go101.org/article/101.html 8 | https://golang.org/doc/asm -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ri 2 | 3 | Tiny statically-typed (embeddable) language. 4 | 5 | # Motivation 6 | 7 | - Language to replace Lua where more stable performance and control is needed. 8 | - Language to replace C with language of similar control, but better possibility of code organization (packages or namespaces). 9 | - Language that maps APIs and paradigms to the script with zero friction. 10 | 11 | ## Runt 12 | 13 | Project is not being made in isolation, it is made as a direct requirement of [Runt](https://github.com/martincohen/Runt) project. _Runt_ needs this for it's configuration, command customization and extensions. 14 | 15 | # Inspiration 16 | 17 | - [Go](https://golang.org/ref/spec) -- Love syntax and a feature set of Go (minus garbage collection) 18 | - [WebAssembly](https://webassembly.github.io/spec/core/index.html) -- Love most of the design, VM takes big chunk of notes from this. 19 | - [Quake3 VM](https://www.icculus.org/~phaethon/q3mc/q3vm_specs.html) -- Love idea of compiling VM to x64 at runtime, VM/x64 takes notes from this. 20 | - [Bitwise's Ion](https://github.com/pervognsen/bitwise/tree/master/ion) -- Ideas and knowledge stolen with love. 21 | 22 | # Features 23 | 24 | Implementation: 25 | 26 | - Embeddable. 27 | - STB-style libaries. 28 | - Minimal binary size. 29 | - No cstdlib dependency. 30 | - No LLVM dependency. 31 | 32 | Language: 33 | 34 | - Simple Go-inspired syntax. 35 | - Type inference. 36 | - No built-in memory management. 37 | - Packages. 38 | - Most of what C does. 39 | - Bring your own library code. 40 | - Compile time execution. 41 | 42 | # Organization 43 | 44 | Project is planned to be split to STB-style modules: 45 | 46 | - `ri.h` 47 | - Library 48 | - Lexing, Parsing, Resolution, Validation. 49 | - Take string, output AST or error. 50 | - `ri-to-vm.h` 51 | - Library 52 | - Take _RiAST_, output _RiVM_ module blob. 53 | - `ri-vm.h` 54 | - Library 55 | - Take _RiVM_ blob, run it. 56 | 57 | Standalone programs: 58 | 59 | - `ri-to-c.c` 60 | - Program 61 | - Take _RiAST_, output C file(s). 62 | - Run compiler. 63 | - Run executable. 64 | 65 | # To do 66 | 67 | The work is split to phases: 68 | 69 | - **Phase 1** AST: Basics (current) 70 | - Lexer, parser and resolver basics 71 | - All statements 72 | - Simple scalar types 73 | - Draft VM compilation 74 | - **Phase 2** AST: Compound types 75 | - Enum 76 | - Pointer 77 | - Struct 78 | - Union 79 | - Initializers 80 | - **Phase 3** AST: Slices 81 | - C arrays with count 82 | - Packages 83 | - **Phase 4** VM: Compilation and Execution 84 | - Compiling to VM 85 | - Integration with _Runt_ using simple AST interpreter for initializers. 86 | - **Later**: 87 | - Compiling VM to x64 88 | - Compiling to C 89 | 90 | The list will grow as I go. 91 | 92 | - [x] Built-in types 93 | - [x] `int8` 94 | - [x] `uint8` 95 | - [x] `int16` 96 | - [x] `uint16` 97 | - [x] `int32` 98 | - [x] `uint32` 99 | - [x] `int64` 100 | - [x] `uint64` 101 | - [x] `float32` 102 | - [x] `float64` 103 | - [x] `bool` 104 | - [ ] Complex type(s) 105 | - `complex64` 106 | - `complex128` 107 | - [ ] SSE type(s) 108 | - [ ] Pointers 109 | - [ ] Function pointers 110 | - [ ] Struct 111 | - [ ] Union 112 | - [ ] Enum 113 | - [ ] Slices 114 | - `[]type` 115 | - [ ] Constants 116 | - [ ] Untyped constant literal 117 | - [x] Integer 118 | - [x] Real 119 | - [x] Boolean 120 | - [ ] String 121 | - [ ] Initializers 122 | - [ ] Nil 123 | - [ ] Typed named constants 124 | - [ ] Untyped named constants 125 | - [ ] Comments 126 | - [x] Line comments 127 | - [ ] Block comments 128 | - [x] Function declaration 129 | - [x] `function () () { ... }` 130 | - [ ] `function () ` 131 | - [ ] `function ()` 132 | - [ ] Convenience syntax for function arguments of same type (`a, b int32`) 133 | - [ ] Function prototype declaration 134 | - [x] `function () ()` 135 | - [ ] Function type 136 | - [ ] `function () ()` 137 | - [ ] `function () ` 138 | - [ ] `function ()` 139 | - [x] Call 140 | - [x] `()` 141 | - [ ] Type checking. 142 | - [x] If statement 143 | - [x] `if ; { ... }` 144 | - [x] `if { ... }` 145 | - [x] `if ... { ... } else { ... }` 146 | - [x] `if ... { ... } else if ...` 147 | - [x] Type checking. 148 | - [x] For statement 149 | - [x] `for ; ; { ... }` 150 | - [x] `for ; ; { ... }` 151 | - [x] `for ; ; { ... }` 152 | - [x] `for ; ; { ... }` 153 | - [x] `for ; ; { ... }` 154 | - [x] `for { ... }` 155 | - [ ] `{ break }` 156 | - [ ] `{ continue }` 157 | - [x] Type checking. 158 | - [ ] Switch statement 159 | - [ ] `switch ; { ... }` 160 | - [ ] `case :` 161 | - [ ] `default` 162 | - [ ] `break` or `fallthrough`? 163 | - [ ] Goto statement 164 | - [ ] `goto