├── .github ├── CODEOWNERS ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ ├── publish.yml │ └── test.yml ├── .gitignore ├── .gitmodules ├── 8bit.sln.DotSettings ├── LICENSE ├── README.md ├── README.new.md ├── VirtualMachine.sln ├── VirtualMachine.sln.DotSettings ├── acc ├── Host.cs ├── Properties │ └── tag.cs ├── _term.cs ├── acc.csproj └── exceptions │ ├── AncientCompileException.cs │ └── AncientEvolveException.cs ├── build.ps1 ├── cheatsheet.md ├── chocolatey └── ancient-vm │ ├── ReadMe.md │ ├── _TODO.txt │ ├── ancient-vm.nuspec │ └── tools │ ├── LICENSE.txt │ ├── VERIFICATION.txt │ ├── chocolateybeforemodify.ps1 │ ├── chocolateyinstall.ps1 │ └── chocolateyuninstall.ps1 ├── etc ├── aip │ └── ancient-sdk.aip └── visual-code │ └── AncientAssembly │ ├── .vsixmanifest │ ├── LICENSE │ ├── README.md │ ├── ancient.configuration.json │ ├── extension.js │ ├── images │ ├── badges │ │ ├── ages-18.png │ │ ├── ages-18.svg │ │ ├── designed-in-ms-paint.png │ │ ├── designed-in-ms-paint.svg │ │ ├── gluten-free.png │ │ ├── gluten-free.svg │ │ ├── made-with-c-sharp.png │ │ ├── made-with-c-sharp.svg │ │ ├── winter-is-coming.png │ │ └── winter-is-coming.svg │ └── icon.png │ ├── package.json │ └── syntaxes │ ├── _.csx │ ├── asm.tmLanguage │ ├── neeed.js │ └── snippets.json ├── libs ├── Ancient.Compiler.Service │ ├── Ancient.Compiler.Service.csproj │ ├── Emit │ │ ├── DebugSymbolsSegment.cs │ │ └── Warning.cs │ ├── Tokens │ │ ├── AssemblerSyntax.cs │ │ ├── ErrorCompileToken.cs │ │ ├── Expression.cs │ │ ├── IInputToken.cs │ │ ├── InstructionExpression.cs │ │ ├── OperatorKind.cs │ │ ├── OperatorToken.cs │ │ ├── ParserExtensions.cs │ │ ├── RefExpression.cs │ │ ├── Syntax │ │ │ ├── Operators.cs │ │ │ ├── Segments.cs │ │ │ └── Transformers.cs │ │ ├── TokenTree.cs │ │ └── Transform │ │ │ ├── ClassicEvolve.cs │ │ │ ├── DefineLabel.cs │ │ │ ├── DefineLabels.cs │ │ │ ├── EmptyEvolve.cs │ │ │ ├── IEvolveEvent.cs │ │ │ ├── IEvolveToken.cs │ │ │ ├── LocalsInitEvolver.cs │ │ │ ├── PushJEvolve.cs │ │ │ ├── SignatureEvolve.cs │ │ │ └── TransformerSyntax.cs │ └── tag.cs └── Ancient.Runtime.Context │ ├── Ancient.Runtime.Context.csproj │ ├── DeviceImageLoadContext.cs │ ├── DeviceLoader.cs │ └── VMFileInfo.cs ├── samples ├── bios │ ├── bios.asm │ └── bios.rune.json ├── led-jumper │ ├── device.scheme │ ├── led-ui.rune.json │ └── led_jumper.asm ├── nyan_coloring.asm ├── rand │ ├── rand.asm │ ├── rand.asm_ │ └── rand.rune.json ├── vector │ ├── device.scheme │ ├── normalize_vector.asm │ └── vector.rune.json ├── while_print.asm └── x3e-firmware │ ├── firmware.asm │ └── x3e-firmware.rune.json ├── test ├── Benchmark │ ├── Benchmark.csproj │ ├── JobCompiling.cs │ ├── JobDeconstruct.cs │ ├── JobInternString.cs │ └── Main.cs ├── RuneTest │ ├── CSharpCompileTest.cs │ ├── ChainOperator.cs │ ├── ChainOperatorEx.cs │ ├── LockFileTest.cs │ └── RuneTest.csproj ├── RuntimeTest │ ├── NativeStringTest.cs │ └── RuntimeTest.csproj ├── acc_test │ ├── AdditionalTokenParseTest.cs │ ├── AssemblyTagTest.cs │ ├── DynamicAssemblyTest.cs │ ├── InstructionTest.cs │ ├── LocalsInitTest.cs │ └── acc_test.csproj └── vm_test │ ├── ExecuteTest.cs │ ├── FixtureState.cs │ ├── FunctionsTest.cs │ ├── ModulesTest.cs │ ├── RegistersTest.cs │ ├── StackTest.cs │ ├── TestDevice.cs │ ├── UnsafeDestructTest.cs │ ├── VMBehaviour.cs │ └── vm_test.csproj └── vm ├── csharp ├── Program.cs ├── component │ ├── BIOS.cs │ ├── Bus.cs │ ├── CPU.cs │ ├── InternalVMFunctions.cs │ ├── Memory.cs │ ├── RangeEx.cs │ ├── Stack.cs │ ├── State.cs │ ├── State.eval.cs │ └── interfaces │ │ └── IHalter.cs ├── tag.cs └── vm.csproj └── devices └── terminal ├── TerminalDevice.cs └── terminal.csproj /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @0xF6 2 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | ko_fi: rijndael 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: publish release 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*' 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v2 13 | with: 14 | submodules: 'recursive' 15 | - name: Setup .NET Core 16 | uses: actions/setup-dotnet@v1 17 | with: 18 | dotnet-version: 5.0.100-preview.3.20216.6 19 | - name: Install dependencies 20 | run: dotnet restore 21 | 22 | # publish for all support RID 23 | - run: dotnet publish ./acc/acc.csproj -o out/acc/osx.10.14-x64 -c release -r osx.10.14-x64 24 | - run: dotnet publish ./vm/csharp/vm.csproj -o out/vm/osx.10.14-x64 -c release -r osx.10.14-x64 25 | - run: dotnet publish ./acc/acc.csproj -o out/acc/linux-x64 -c release -r linux-x64 26 | - run: dotnet publish ./acc/acc.csproj -o out/acc/linux-arm -c release -r linux-arm 27 | - run: dotnet publish ./vm/csharp/vm.csproj -o out/vm/linux-x64 -c release -r linux-x64 28 | - run: dotnet publish ./vm/csharp/vm.csproj -o out/vm/linux-arm -c release -r linux-arm 29 | - run: dotnet publish ./acc/acc.csproj -o out/acc/win10-x64 -c release -r win10-x64 30 | - run: dotnet publish ./acc/acc.csproj -o out/acc/win10-arm64 -c release -r win10-arm64 31 | - run: dotnet publish ./acc/acc.csproj -o out/acc/win10-arm -c release -r win10-arm 32 | - run: dotnet publish ./vm/csharp/vm.csproj -o out/vm/win10-x64 -c release -r win10-x64 33 | - run: dotnet publish ./vm/csharp/vm.csproj -o out/vm/win10-arm64 -c release -r win10-arm64 34 | - run: dotnet publish ./vm/csharp/vm.csproj -o out/vm/win10-arm -c release -r win10-arm 35 | # end 36 | 37 | # pack VM 38 | - run: zip vm-osx.10.14-x64.zip . -r -9 39 | working-directory: ./out/vm/osx.10.14-x64 40 | - run: zip vm-linux-x64.zip . -r -9 41 | working-directory: ./out/vm/linux-x64 42 | - run: zip vm-linux-arm.zip . -r -9 43 | working-directory: ./out/vm/linux-arm 44 | - run: zip vm-win10-x64.zip . -r -9 45 | working-directory: ./out/vm/win10-x64 46 | - run: zip vm-win10-arm64.zip . -r -9 47 | working-directory: ./out/vm/win10-arm64 48 | - run: zip vm-win10-arm.zip . -r -9 49 | working-directory: ./out/vm/win10-arm 50 | # pack acc 51 | - run: zip acc-osx.10.14-x64.zip . -r -9 52 | working-directory: ./out/acc/osx.10.14-x64 53 | - run: zip acc-linux-x64.zip . -r -9 54 | working-directory: ./out/acc/linux-x64 55 | - run: zip acc-linux-arm.zip . -r -9 56 | working-directory: ./out/acc/linux-arm 57 | - run: zip acc-win10-x64.zip . -r -9 58 | working-directory: ./out/acc/win10-x64 59 | - run: zip acc-win10-arm64.zip . -r -9 60 | working-directory: ./out/acc/win10-arm64 61 | - run: zip acc-win10-arm.zip . -r -9 62 | working-directory: ./out/acc/win10-arm 63 | 64 | - run: find ./out/**/* -name "*.zip" -exec mv "{}" ./ \; 65 | 66 | 67 | - name: Create Release 68 | id: create_release_linux 69 | uses: ncipollo/release-action@v1 70 | env: 71 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 72 | with: 73 | artifacts: "./**/*.zip" 74 | allowUpdates: true 75 | commit: master 76 | token: ${{ secrets.GITHUB_TOKEN }} 77 | tag_name: ${{ github.ref }} 78 | release_name: rune-cli release 79 | draft: false 80 | prerelease: true 81 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Run test 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | with: 16 | submodules: 'recursive' 17 | - name: Setup .NET Core 18 | uses: actions/setup-dotnet@v1 19 | with: 20 | dotnet-version: 5.0.100-preview.3.20216.6 21 | - name: Install dependencies 22 | run: dotnet restore 23 | - name: Build 24 | run: dotnet build --configuration Release --no-restore 25 | - name: Test 26 | run: dotnet test --no-restore --verbosity normal 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | .yarn/ 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | [Dd]eps/ 27 | 28 | out/** 29 | 30 | # Visual Studio 2015/2017 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # Visual Studio 2017 auto generated files 36 | Generated\ Files/ 37 | 38 | # MSTest test Results 39 | [Tt]est[Rr]esult*/ 40 | [Bb]uild[Ll]og.* 41 | 42 | # NUNIT 43 | *.VisualState.xml 44 | TestResult.xml 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | **/Properties/launchSettings.json 59 | 60 | # StyleCop 61 | StyleCopReport.xml 62 | 63 | # Files built by Visual Studio 64 | *_i.c 65 | *_p.c 66 | *_i.h 67 | *.ilk 68 | *.meta 69 | *.obj 70 | *.iobj 71 | *.pch 72 | *.pdb 73 | *.ipdb 74 | *.pgc 75 | *.pgd 76 | *.rsp 77 | *.sbr 78 | *.tlb 79 | *.tli 80 | *.tlh 81 | *.tmp 82 | *.tmp_proj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | *.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | 235 | # RIA/Silverlight projects 236 | Generated_Code/ 237 | 238 | # Backup & report files from converting an old project file 239 | # to a newer Visual Studio version. Backup files are not needed, 240 | # because we have git ;-) 241 | _UpgradeReport_Files/ 242 | Backup*/ 243 | UpgradeLog*.XML 244 | UpgradeLog*.htm 245 | ServiceFabricBackup/ 246 | *.rptproj.bak 247 | 248 | # SQL Server files 249 | *.mdf 250 | *.ldf 251 | *.ndf 252 | 253 | # Business Intelligence projects 254 | *.rdl.data 255 | *.bim.layout 256 | *.bim_*.settings 257 | *.rptproj.rsuser 258 | 259 | # Microsoft Fakes 260 | FakesAssemblies/ 261 | 262 | # GhostDoc plugin setting file 263 | *.GhostDoc.xml 264 | 265 | # Node.js Tools for Visual Studio 266 | .ntvs_analysis.dat 267 | node_modules/ 268 | 269 | # Visual Studio 6 build log 270 | *.plg 271 | 272 | # Visual Studio 6 workspace options file 273 | *.opt 274 | 275 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 276 | *.vbw 277 | 278 | # Visual Studio LightSwitch build output 279 | **/*.HTMLClient/GeneratedArtifacts 280 | **/*.DesktopClient/GeneratedArtifacts 281 | **/*.DesktopClient/ModelManifest.xml 282 | **/*.Server/GeneratedArtifacts 283 | **/*.Server/ModelManifest.xml 284 | _Pvt_Extensions 285 | 286 | # Paket dependency manager 287 | .paket/paket.exe 288 | paket-files/ 289 | 290 | # FAKE - F# Make 291 | .fake/ 292 | 293 | # JetBrains Rider 294 | .idea/ 295 | *.sln.iml 296 | 297 | # CodeRush 298 | .cr/ 299 | 300 | # Python Tools for Visual Studio (PTVS) 301 | __pycache__/ 302 | *.pyc 303 | 304 | # Cake - Uncomment if you are using it 305 | # tools/** 306 | # !tools/packages.config 307 | 308 | # Tabs Studio 309 | *.tss 310 | 311 | # Telerik's JustMock configuration file 312 | *.jmconfig 313 | 314 | # BizTalk build output 315 | *.btp.cs 316 | *.btm.cs 317 | *.odx.cs 318 | *.xsd.cs 319 | 320 | # OpenCover UI analysis results 321 | OpenCover/ 322 | 323 | # Azure Stream Analytics local run output 324 | ASALocalRun/ 325 | 326 | # MSBuild Binary and Structured Log 327 | *.binlog 328 | 329 | # NVidia Nsight GPU debugger configuration file 330 | *.nvuser 331 | 332 | # MFractors (Xamarin productivity tool) working folder 333 | .mfractor/ 334 | 335 | build/ 336 | 337 | etc/aip/ancient-sdk-cache/ 338 | 339 | etc/aip/ancient-sdk\.back\.aip 340 | 341 | *.vsix 342 | 343 | *.lock 344 | 345 | vm/rust/target/ 346 | 347 | etc/visual-code/AncientAssembly/package-lock.json 348 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "submodules/runtime"] 2 | path = submodules/runtime 3 | url = https://github.com/ancientproject/runtime.git 4 | -------------------------------------------------------------------------------- /8bit.sln.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | True 3 | True 4 | True 5 | True 6 | True 7 | True 8 | True 9 | True 10 | True -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Yuuki Wesp 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 |

3 | 4 | 5 | 6 |

7 |

8 | 9 | 10 | 11 |

12 | 13 | 14 |

15 | 16 | 17 | 18 |

19 | 20 | 21 |

22 | AncientVM 🔥 23 |

24 | 25 |

26 | 8bit Virtual Machine & Ancient Assembler-style language 27 |

28 | 29 | 30 |

31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |

44 | 45 | 46 |

47 | 48 | Visual Studio Marketplace Version 49 | 50 | 51 | 52 | 53 |

54 | 55 | 56 |

57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 |

65 | 66 | ![image](https://user-images.githubusercontent.com/13326808/60311909-e71fa900-9961-11e9-96f0-bf4c4a45681c.png) 67 | 68 | 69 |
70 | Spoiler 71 | 72 | ![meme](https://user-images.githubusercontent.com/13326808/72352994-55586d00-36f4-11ea-8667-39475c9fd69f.png) 73 | 74 | by 75 | [@ViktorChernyaev](https://github.com/ViktorChernyaev) 76 |
77 | 78 | 79 | --- 80 | 81 | > Ancient VM proof of concept of the language, toolskit, virtual machine and ecosystem 82 | > A VM with 50+ instructions, SIMD Vector calculation, modularity, language and compiler, cli tool and package register of modules and extensions 83 | 84 | --- 85 | 86 | 87 | # 📡 Installation 88 | 89 | ```bash 90 | $ yarn global add @rune/cli 91 | $ rune install vm 92 | ``` 93 | 94 | # 💻 OS Support 95 | 96 | OS | Version | Architectures 97 | ------------------------------|-------------------------------|---------------- 98 | Windows 10 | 1607+ | x64, ARM32 99 | OSX | 10.14+ | x64 100 | Linux | | x64, ARM32, ARM64 101 | 102 | 103 | # Documentation 104 | See [Docs](https://docs.vm.runic.cloud) 105 | 106 | [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2F0xF6%2Fancient_cpu.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2F0xF6%2Fancient_cpu?ref=badge_large) 107 | 108 |

109 | 110 | 111 | 112 |

113 | -------------------------------------------------------------------------------- /VirtualMachine.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28822.285 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "acc", "acc\acc.csproj", "{4FA84905-6A02-4FDD-9CDF-468588F1D6D8}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{24CBAF1C-EBD3-47DB-89BC-AD7F407DE760}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "acc_test", "test\acc_test\acc_test.csproj", "{737A19B5-7197-4B8C-82D2-2765C81D38CB}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmark", "test\Benchmark\Benchmark.csproj", "{08396B74-082E-44BA-9A91-E62A50F172C9}" 13 | EndProject 14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "vm", "vm\csharp\vm.csproj", "{D99C3D06-C9B9-4759-BDA9-1FC433DEB33F}" 15 | EndProject 16 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "vm_test", "test\vm_test\vm_test.csproj", "{A1538F63-D4D4-45E8-8A97-8EA7E6073EB8}" 17 | EndProject 18 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ancient.Compiler.Service", "libs\Ancient.Compiler.Service\Ancient.Compiler.Service.csproj", "{E2D48827-C38C-4689-B0A1-9FD395904FB3}" 19 | EndProject 20 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "apps", "apps", "{F619DE0B-A984-43B2-B873-29651B48C549}" 21 | EndProject 22 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libs", "libs", "{3E153A17-EBC1-4471-BD65-0C306499D3F2}" 23 | EndProject 24 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ancient.Runtime.Context", "libs\Ancient.Runtime.Context\Ancient.Runtime.Context.csproj", "{00506E30-C4CB-4734-BA64-920CEE5CE926}" 25 | EndProject 26 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "submodules", "submodules", "{B29BF648-1A51-4597-BE5E-E96D2C9EDD34}" 27 | EndProject 28 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ancient.Runtime", "submodules\runtime\src\Ancient.Runtime.csproj", "{267CF9D7-0E11-45D6-82E0-72B0B2B66673}" 29 | EndProject 30 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RuntimeTest", "test\RuntimeTest\RuntimeTest.csproj", "{5646B0E1-10FA-41F3-9110-8C616307DD6C}" 31 | EndProject 32 | Global 33 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 34 | Debug|Any CPU = Debug|Any CPU 35 | Release|Any CPU = Release|Any CPU 36 | EndGlobalSection 37 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 38 | {4FA84905-6A02-4FDD-9CDF-468588F1D6D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {4FA84905-6A02-4FDD-9CDF-468588F1D6D8}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {4FA84905-6A02-4FDD-9CDF-468588F1D6D8}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {4FA84905-6A02-4FDD-9CDF-468588F1D6D8}.Release|Any CPU.Build.0 = Release|Any CPU 42 | {737A19B5-7197-4B8C-82D2-2765C81D38CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 43 | {737A19B5-7197-4B8C-82D2-2765C81D38CB}.Debug|Any CPU.Build.0 = Debug|Any CPU 44 | {737A19B5-7197-4B8C-82D2-2765C81D38CB}.Release|Any CPU.ActiveCfg = Release|Any CPU 45 | {737A19B5-7197-4B8C-82D2-2765C81D38CB}.Release|Any CPU.Build.0 = Release|Any CPU 46 | {08396B74-082E-44BA-9A91-E62A50F172C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 47 | {08396B74-082E-44BA-9A91-E62A50F172C9}.Debug|Any CPU.Build.0 = Debug|Any CPU 48 | {08396B74-082E-44BA-9A91-E62A50F172C9}.Release|Any CPU.ActiveCfg = Release|Any CPU 49 | {08396B74-082E-44BA-9A91-E62A50F172C9}.Release|Any CPU.Build.0 = Release|Any CPU 50 | {D99C3D06-C9B9-4759-BDA9-1FC433DEB33F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 51 | {D99C3D06-C9B9-4759-BDA9-1FC433DEB33F}.Debug|Any CPU.Build.0 = Debug|Any CPU 52 | {D99C3D06-C9B9-4759-BDA9-1FC433DEB33F}.Release|Any CPU.ActiveCfg = Release|Any CPU 53 | {D99C3D06-C9B9-4759-BDA9-1FC433DEB33F}.Release|Any CPU.Build.0 = Release|Any CPU 54 | {A1538F63-D4D4-45E8-8A97-8EA7E6073EB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 55 | {A1538F63-D4D4-45E8-8A97-8EA7E6073EB8}.Debug|Any CPU.Build.0 = Debug|Any CPU 56 | {A1538F63-D4D4-45E8-8A97-8EA7E6073EB8}.Release|Any CPU.ActiveCfg = Release|Any CPU 57 | {A1538F63-D4D4-45E8-8A97-8EA7E6073EB8}.Release|Any CPU.Build.0 = Release|Any CPU 58 | {E2D48827-C38C-4689-B0A1-9FD395904FB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 59 | {E2D48827-C38C-4689-B0A1-9FD395904FB3}.Debug|Any CPU.Build.0 = Debug|Any CPU 60 | {E2D48827-C38C-4689-B0A1-9FD395904FB3}.Release|Any CPU.ActiveCfg = Release|Any CPU 61 | {E2D48827-C38C-4689-B0A1-9FD395904FB3}.Release|Any CPU.Build.0 = Release|Any CPU 62 | {00506E30-C4CB-4734-BA64-920CEE5CE926}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 63 | {00506E30-C4CB-4734-BA64-920CEE5CE926}.Debug|Any CPU.Build.0 = Debug|Any CPU 64 | {00506E30-C4CB-4734-BA64-920CEE5CE926}.Release|Any CPU.ActiveCfg = Release|Any CPU 65 | {00506E30-C4CB-4734-BA64-920CEE5CE926}.Release|Any CPU.Build.0 = Release|Any CPU 66 | {267CF9D7-0E11-45D6-82E0-72B0B2B66673}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 67 | {267CF9D7-0E11-45D6-82E0-72B0B2B66673}.Debug|Any CPU.Build.0 = Debug|Any CPU 68 | {267CF9D7-0E11-45D6-82E0-72B0B2B66673}.Release|Any CPU.ActiveCfg = Release|Any CPU 69 | {267CF9D7-0E11-45D6-82E0-72B0B2B66673}.Release|Any CPU.Build.0 = Release|Any CPU 70 | {5646B0E1-10FA-41F3-9110-8C616307DD6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 71 | {5646B0E1-10FA-41F3-9110-8C616307DD6C}.Debug|Any CPU.Build.0 = Debug|Any CPU 72 | {5646B0E1-10FA-41F3-9110-8C616307DD6C}.Release|Any CPU.ActiveCfg = Release|Any CPU 73 | {5646B0E1-10FA-41F3-9110-8C616307DD6C}.Release|Any CPU.Build.0 = Release|Any CPU 74 | EndGlobalSection 75 | GlobalSection(SolutionProperties) = preSolution 76 | HideSolutionNode = FALSE 77 | EndGlobalSection 78 | GlobalSection(NestedProjects) = preSolution 79 | {4FA84905-6A02-4FDD-9CDF-468588F1D6D8} = {F619DE0B-A984-43B2-B873-29651B48C549} 80 | {737A19B5-7197-4B8C-82D2-2765C81D38CB} = {24CBAF1C-EBD3-47DB-89BC-AD7F407DE760} 81 | {08396B74-082E-44BA-9A91-E62A50F172C9} = {24CBAF1C-EBD3-47DB-89BC-AD7F407DE760} 82 | {D99C3D06-C9B9-4759-BDA9-1FC433DEB33F} = {F619DE0B-A984-43B2-B873-29651B48C549} 83 | {A1538F63-D4D4-45E8-8A97-8EA7E6073EB8} = {24CBAF1C-EBD3-47DB-89BC-AD7F407DE760} 84 | {E2D48827-C38C-4689-B0A1-9FD395904FB3} = {3E153A17-EBC1-4471-BD65-0C306499D3F2} 85 | {00506E30-C4CB-4734-BA64-920CEE5CE926} = {3E153A17-EBC1-4471-BD65-0C306499D3F2} 86 | {267CF9D7-0E11-45D6-82E0-72B0B2B66673} = {B29BF648-1A51-4597-BE5E-E96D2C9EDD34} 87 | {5646B0E1-10FA-41F3-9110-8C616307DD6C} = {24CBAF1C-EBD3-47DB-89BC-AD7F407DE760} 88 | EndGlobalSection 89 | GlobalSection(ExtensibilityGlobals) = postSolution 90 | SolutionGuid = {77DF946F-0A1C-4A24-8A58-E2136BF8FC38} 91 | EndGlobalSection 92 | EndGlobal 93 | -------------------------------------------------------------------------------- /VirtualMachine.sln.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | True 3 | True 4 | True 5 | True 6 | True 7 | True 8 | True 9 | True 10 | True 11 | True 12 | True 13 | True -------------------------------------------------------------------------------- /acc/Properties/tag.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | [assembly: InternalsVisibleTo("acc_test")] -------------------------------------------------------------------------------- /acc/_term.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Text; 8 | using emit; 9 | using Pastel; 10 | using Pixie; 11 | using Pixie.Code; 12 | using Pixie.Markup; 13 | using Pixie.Terminal; 14 | using Pixie.Terminal.Devices; 15 | using Pixie.Terminal.Render; 16 | using runtime; 17 | using tokens; 18 | using static System.Console; 19 | using Color = System.Drawing.Color; 20 | 21 | internal class _term 22 | { 23 | private static readonly object Guarder = new object(); 24 | 25 | public static void Trace(string message) 26 | { 27 | lock (Guarder) 28 | { 29 | WriteLine($"trace: {message}".Pastel( Color.Gray)); 30 | } 31 | } 32 | 33 | public static void Success(string message) 34 | { 35 | lock (Guarder) 36 | { 37 | Write("["); 38 | Write($"SUCCESS".Pastel(Color.YellowGreen)); 39 | Write("]: "); 40 | WriteLine($" {message}"); 41 | } 42 | } 43 | public static void Warn(Warning keyCode, string message) 44 | { 45 | lock (Guarder) 46 | { 47 | Write("["); 48 | Write($"WARN".Pastel(Color.Orange)); 49 | Write("]: "); 50 | Write($"{keyCode.Format()}".Pastel(Color.Orange)); 51 | WriteLine($" {message}"); 52 | } 53 | } 54 | public static string getFromMiddle(string value, int indexMiddle, int count, bool isStopWhenEmptySpace = false) 55 | { 56 | try 57 | { 58 | indexMiddle -= 1; 59 | var str = new List(); 60 | for (var i = indexMiddle; i != indexMiddle + count + 1; i++) 61 | { 62 | if(value.Length <= i) 63 | break; 64 | if(value[i] == ' ' && isStopWhenEmptySpace) 65 | break; 66 | str.Add(value[i]); 67 | } 68 | for (var i = indexMiddle-1; i != indexMiddle - count - 1; i--) 69 | { 70 | if(value[i] == ' ' && isStopWhenEmptySpace) 71 | break; 72 | str.Insert(0, value[i]); 73 | } 74 | return string.Join("", str.ToArray()); 75 | } 76 | catch 77 | { 78 | return value; 79 | } 80 | } 81 | 82 | #region shit-code 83 | 84 | public static void Error(ErrorToken token, string source) 85 | { 86 | lock (Guarder) 87 | { 88 | _error(token, source); 89 | } 90 | } 91 | 92 | private static void _error(ErrorToken token, string source) 93 | { 94 | var col = token.ErrorResult.Remainder.Column; 95 | var lin = token.ErrorResult.Remainder.Line; 96 | var exp = token.ErrorResult.Expectations.First(); 97 | var rem = token.ErrorResult.Remainder.Current; 98 | 99 | var nestedLine = source.Split('\n')[lin-1]; 100 | var fuck = getFromMiddle(nestedLine, col, nestedLine.Length - col, true); 101 | var startOffset = source.IndexOf(nestedLine, StringComparison.InvariantCultureIgnoreCase); 102 | var nameOffset = (startOffset + col - 1); 103 | 104 | var doc2 = new StringDocument("", source); 105 | var highlightRegion = new SourceRegion(new SourceSpan(doc2, startOffset, nestedLine.Length)); 106 | 107 | var focusRegion = new SourceRegion( 108 | new SourceSpan(doc2, nameOffset, fuck.Length)); 109 | var title = $"{token.ErrorResult.getWarningCode().To().Pastel(Color.Orange)}"; 110 | var message = $"character '{exp}' expected".Pastel(Color.Orange); 111 | 112 | string Render(MarkupNode node, params NodeRenderer[] extraRenderers) 113 | { 114 | var writer = new StringWriter(); 115 | var terminal = new TextWriterTerminal(writer, 160, Encoding.ASCII); 116 | var log = new TerminalLog(terminal).WithRenderers(extraRenderers); 117 | log.Log(node); 118 | return writer.ToString(); 119 | } 120 | 121 | var result = Render( 122 | new HighlightedSource(highlightRegion, focusRegion), 123 | new HighlightedSourceRenderer(3, Colors.Red)); 124 | WriteLine($" :: {title} - {message}"); 125 | var ses = result.Split('\n'); 126 | var flag1 = false; 127 | foreach (var (value, index) in ses.Select((value, index) => (value, index))) 128 | { 129 | var next = ses.Select((value, index) => new {value, index}).FirstOrDefault(x => x.index == index + 1); 130 | if (next != null && (next.value.Contains('~') && next.value.Contains('^')) && !flag1) 131 | WriteLine(value.Replace(fuck, fuck.Pastel(Color.Red))); 132 | else if (value.Contains('~') && value.Contains('^')) 133 | { 134 | if (flag1) 135 | continue; 136 | WriteLine(value.Pastel(Color.Red)); 137 | flag1 = true; 138 | } 139 | else 140 | WriteLine($"{value} "); 141 | } 142 | } 143 | #endregion 144 | public static void Error(Warning keyCode, string message) 145 | { 146 | lock (Guarder) 147 | { 148 | Write("["); 149 | Write($"ERROR".Pastel(Color.Red)); 150 | Write("]: "); 151 | Write($"{keyCode.Format()}".Pastel(Color.Red)); 152 | WriteLine($" {message}"); 153 | } 154 | } 155 | } 156 | } -------------------------------------------------------------------------------- /acc/acc.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net5.0 6 | flame.compiler 7 | win10-x64;osx.10.14-x64;linux-x64 8 | 0.70.800 9 | Yuuki Wesp 10 | flame.compiler 11 | Yuuki Wesp (C) 2020 12 | false 13 | ancient.compiler.Host 14 | true 15 | preview 16 | 17 | 18 | 19 | false 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | all 37 | runtime; build; native; contentfiles; analyzers; buildtransitive 38 | 39 | 40 | 41 | true 42 | 43 | 44 | -------------------------------------------------------------------------------- /acc/exceptions/AncientCompileException.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.exceptions 2 | { 3 | using System; 4 | [Serializable] 5 | public class AncientCompileException : Exception 6 | { 7 | public AncientCompileException(string msg) : base(msg){} 8 | } 9 | } -------------------------------------------------------------------------------- /acc/exceptions/AncientEvolveException.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.exceptions 2 | { 3 | using System; 4 | [Serializable] 5 | public class AncientEvolveException : Exception 6 | { 7 | public AncientEvolveException(string msg) : base(msg){} 8 | } 9 | } -------------------------------------------------------------------------------- /build.ps1: -------------------------------------------------------------------------------- 1 | cd .\vm\csharp 2 | dotnet publish -r win10-x64 3 | cd .. 4 | cd .. 5 | cd .\acc 6 | dotnet publish -r win10-x64 7 | cd .. 8 | cd .\Rune 9 | dotnet publish -r win10-x64 10 | cd .. -------------------------------------------------------------------------------- /cheatsheet.md: -------------------------------------------------------------------------------- 1 | ## REPL 2 | 3 | `0xB00B50000` - halt off [`Bootable sector not found`] 4 | 5 | `0x1110010A0`/`0x1110000A0` - enable/disable trace log 6 | 7 | `0x1190010A0`/`0x1190000A0` - enable/disable stack forward flag 8 | `0x1180010A0`/`0x1180000A0` - enable/disable float flag 9 | 10 | `0x1220010A0`/`0x1220000A0` - enable/disable southFlag 11 | `0x1210010A0`/`0x1210000A0` - enable/disable eastFlag 12 | `0x1200010A0`/`0x1200000A0` - enable/disable northFlag 13 | 14 | ### Check status of bios-guard 15 | `0x1220010A0` - enable south flag 16 | (`.ldx 0x12 0x1`) 17 | `0xA4450F600` - reading from bios this flag and insert into stack 18 | (`.rfd 0x45 0xF6`) 19 | `0xA19000000` - pulling from stack and insert value into 0x9 memory cell 20 | (`.pull 0x9`) 21 | `0xF14E900F0` - reading from 0x9 memory cell and send to terminal device for print value on screen 22 | (`.mvx 0x1 0x4 0x9`) 23 | -------------------------------------------------------------------------------- /chocolatey/ancient-vm/_TODO.txt: -------------------------------------------------------------------------------- 1 | TODO 2 | 3 | 1. Determine Package Use: 4 | 5 | Organization? Internal Use? - You are not subject to distribution 6 | rights when you keep everything internal. Put the binaries directly 7 | into the tools directory (as long as total nupkg size is under 1GB). 8 | When bigger, look to use from a share or download binaries from an 9 | internal location. Embedded binaries makes for the most reliable use 10 | of Chocolatey. Use `$fileLocation` (`$file`/`$file64`) and 11 | `Install-ChocolateyInstallPackage`/`Get-ChocolateyUnzip` in 12 | tools\chocolateyInstall.ps1. 13 | 14 | You can also choose to download from internal urls, see the next 15 | section, but ignore whether you have distribution rights or not, it 16 | doesn't apply. Under no circumstances should download from the 17 | internet, it is completely unreliable. See 18 | https://chocolatey.org/docs/community-packages-disclaimer#organizations 19 | to understand the limitations of a publicly available repository. 20 | 21 | Community Repository? 22 | Have Distribution Rights? 23 | If you are the software vendor OR the software EXPLICITLY allows 24 | redistribution and the total nupkg size will be under 200MB, you 25 | have the option to embed the binaries directly into the package to 26 | provide the most reliable install experience. Put the binaries 27 | directly into the tools folder, use `$fileLocation` (`$file`/ 28 | `$file64`) and `Install-ChocolateyInstallPackage`/ 29 | `Get-ChocolateyUnzip` in tools\chocolateyInstall.ps1. Additionally, 30 | fill out the LICENSE and VERIFICATION file (see 3 below and those 31 | files for specifics). 32 | 33 | NOTE: You can choose to download binaries at runtime, but be sure 34 | the download location will remain stable. See the next section. 35 | 36 | Do Not Have Distribution Rights? 37 | - Note: Packages built this way cannot be 100% reliable, but it's a 38 | constraint of publicly available packages and there is little 39 | that can be done to change that. See 40 | https://chocolatey.org/docs/community-packages-disclaimer#organizations 41 | to better understand the limitations of a publicly available 42 | repository. 43 | Download Location is Publicly Available? 44 | You will need to download the runtime files from their official 45 | location at runtime. Use `$url`/`$url64` and 46 | `Install-ChocolateyPackage`/`Install-ChocolateyZipPackage` in 47 | tools\chocolateyInstall.ps1. 48 | Download Location is Not Publicly Available? 49 | Stop here, you can't push this to the community repository. You 50 | can ask the vendor for permission to embed, then include a PDF of 51 | that signed permission directly in the package. Otherwise you 52 | will need to seek alternate locations to non-publicly host the 53 | package. 54 | Download Location Is Same For All Versions? 55 | You still need to point to those urls, but you may wish to set up 56 | something like Automatic Updater (AU) so that when a new version 57 | of the software becomes available, the new package version 58 | automatically gets pushed up to the community repository. See 59 | https://chocolatey.org/docs/automatic-packages#automatic-updater-au 60 | 61 | 2. Determine Package Type: 62 | 63 | - Installer Package - contains an installer (everything in template is 64 | geared towards this type of package) 65 | - Zip Package - downloads or embeds and unpacks archives, may unpack 66 | and run an installer using `Install-ChocolateyInstallPackage` as a 67 | secondary step. 68 | - Portable Package - Contains runtime binaries (or unpacks them as a 69 | zip package) - cannot require administrative permissions to install 70 | or use 71 | - Config Package - sets config like files, registry keys, etc 72 | - Extension Package - Packages that add PowerShell functions to 73 | Chocolatey - https://chocolatey.org/docs/how-to-create-extensions 74 | - Template Package - Packages that add templates like this for `choco 75 | new -t=name` - https://chocolatey.org/docs/how-to-create-custom-package-templates 76 | - Other - there are other types of packages as well, these are the main 77 | package types seen in the wild 78 | 79 | 3. Fill out the package contents: 80 | 81 | - tools\chocolateyBeforeModify.ps1 - remove if you have no processes 82 | or services to shut down before upgrade/uninstall 83 | - tools\LICENSE.txt / tools\VERIFICATION.txt - Remove if you are not 84 | embedding binaries. Keep and fill out if you are embedding binaries 85 | in the package AND pushing to the community repository, even if you 86 | are the author of software. The file becomes easier to fill out 87 | (does not require changes each version) if you are the software 88 | vendor. If you are building packages for internal use (organization, 89 | etc), you don't need these files as you are not subject to 90 | distribution rights internally. 91 | - tools\chocolateyUninstall.ps1 - remove if autouninstaller can 92 | automatically uninstall and you have nothing additional to do during 93 | uninstall 94 | - Readme.txt - delete this file once you have read over and used 95 | anything you've needed from here 96 | - nuspec - fill this out, then clean out all the comments (you may wish 97 | to leave the headers for the package vs software metadata) 98 | - tools\chocolateyInstall.ps1 - instructions in next section. 99 | 100 | 4. ChocolateyInstall.ps1: 101 | 102 | - For embedded binaries - use `$fileLocation` (`$file`/`$file64`) and 103 | `Install-ChocolateyInstallPackage`/ `Get-ChocolateyUnzip`. 104 | - Downloading binaries at runtime - use `$url`/`$url64` and 105 | `Install-ChocolateyPackage` / `Install-ChocolateyZipPackage`. 106 | - Other needs (creating files, setting registry keys), use regular 107 | PowerShell to do so or see if there is a function already defined: 108 | https://chocolatey.org/docs/helpers-reference 109 | - There may also be functions available in extension packages, see 110 | https://chocolatey.org/packages?q=id%3A.extension for examples and 111 | availability. 112 | - Clean out the comments and sections you are not using. 113 | 114 | 5. Test the package to ensure install/uninstall work appropriately. 115 | There is a test environment you can use for this - 116 | https://github.com/chocolatey/chocolatey-test-environment 117 | 118 | 6. Learn more about Chocolatey packaging - go through the workshop at 119 | https://github.com/ferventcoder/chocolatey-workshop 120 | You will learn about 121 | - General packaging 122 | - Customizing package behavior at runtime (package parameters) 123 | - Extension packages 124 | - Custom packaging templates 125 | - Setting up an internal Chocolatey.Server repository 126 | - Adding and using internal repositories 127 | - Reporting 128 | - Advanced packaging techniques when installers are not friendly to 129 | automation 130 | 131 | 7. Delete this file. 132 | -------------------------------------------------------------------------------- /chocolatey/ancient-vm/ancient-vm.nuspec: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | ancient-vm 26 | 27 | 28 | 29 | 0.50.386 30 | https://github.com/0xF6/ancient_cpu 31 | 32 | Yuuki Wesp 33 | 34 | 35 | 36 | 37 | ancient-vm (Install) 38 | Yuuki Wesp 39 | 40 | https://github.com/0xF6/ancient_cpu 41 | 42 | https://raw.githubusercontent.com/0xF6/ancient_cpu/master/Rune/resource/icon.png 43 | 2019-2020 (C) Yuuki Wesp 44 | 45 | https://raw.githubusercontent.com/0xF6/ancient_cpu/master/LICENSE 46 | true 47 | https://github.com/0xF6/ancient_cpu 48 | https://github.com/0xF6/ancient_cpu/blob/master/README.md 49 | 50 | 51 | vm csharp hardware 8bit assembler 52 | 53 | 8bit CPU Virtual Machine and Ancient Assembler-style language 54 | 55 | 56 | 57 | 58 | 66 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /chocolatey/ancient-vm/tools/LICENSE.txt: -------------------------------------------------------------------------------- 1 |  2 | Note: Include this file if including binaries you have the right to distribute. 3 | Otherwise delete. this file. 4 | 5 | ===DELETE ABOVE THIS LINE AND THIS LINE=== 6 | 7 | From: 8 | 9 | LICENSE 10 | 11 | 12 | -------------------------------------------------------------------------------- /chocolatey/ancient-vm/tools/VERIFICATION.txt: -------------------------------------------------------------------------------- 1 |  2 | Note: Include this file if including binaries you have the right to distribute. 3 | Otherwise delete. this file. If you are the software author, you can change this 4 | mention you are the author of the software. 5 | 6 | ===DELETE ABOVE THIS LINE AND THIS LINE=== 7 | 8 | VERIFICATION 9 | Verification is intended to assist the Chocolatey moderators and community 10 | in verifying that this package's contents are trustworthy. 11 | 12 | 13 | -------------------------------------------------------------------------------- /chocolatey/ancient-vm/tools/chocolateybeforemodify.ps1: -------------------------------------------------------------------------------- 1 | # This runs in 0.9.10+ before upgrade and uninstall. 2 | # Use this file to do things like stop services prior to upgrade or uninstall. 3 | # NOTE: It is an anti-pattern to call chocolateyUninstall.ps1 from here. If you 4 | # need to uninstall an MSI prior to upgrade, put the functionality in this 5 | # file without calling the uninstall script. Make it idempotent in the 6 | # uninstall script so that it doesn't fail when it is already uninstalled. 7 | # NOTE: For upgrades - like the uninstall script, this script always runs from 8 | # the currently installed version, not from the new upgraded package version. 9 | 10 | -------------------------------------------------------------------------------- /chocolatey/ancient-vm/tools/chocolateyuninstall.ps1: -------------------------------------------------------------------------------- 1 | # IMPORTANT: Before releasing this package, copy/paste the next 2 lines into PowerShell to remove all comments from this file: 2 | # $f='c:\path\to\thisFile.ps1' 3 | # gc $f | ? {$_ -notmatch "^\s*#"} | % {$_ -replace '(^.*?)\s*?[^``]#.*','$1'} | Out-File $f+".~" -en utf8; mv -fo $f+".~" $f 4 | 5 | ## NOTE: In 80-90% of the cases (95% with licensed versions due to Package Synchronizer and other enhancements), 6 | ## AutoUninstaller should be able to detect and handle registry uninstalls without a chocolateyUninstall.ps1. 7 | ## See https://chocolatey.org/docs/commands-uninstall 8 | ## and https://chocolatey.org/docs/helpers-uninstall-chocolatey-package 9 | 10 | ## If this is an MSI, ensure 'softwareName' is appropriate, then clean up comments and you are done. 11 | ## If this is an exe, change fileType, silentArgs, and validExitCodes 12 | 13 | $ErrorActionPreference = 'Stop'; # stop on all errors 14 | $packageArgs = @{ 15 | packageName = $env:ChocolateyPackageName 16 | softwareName = 'ancient-vm*' #part or all of the Display Name as you see it in Programs and Features. It should be enough to be unique 17 | fileType = 'EXE_MSI_OR_MSU' #only one of these: MSI or EXE (ignore MSU for now) 18 | # MSI 19 | silentArgs = "/qn /norestart" 20 | validExitCodes= @(0, 3010, 1605, 1614, 1641) # https://msdn.microsoft.com/en-us/library/aa376931(v=vs.85).aspx 21 | # OTHERS 22 | # Uncomment matching EXE type (sorted by most to least common) 23 | #silentArgs = '/S' # NSIS 24 | #silentArgs = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-' # Inno Setup 25 | #silentArgs = '/s' # InstallShield 26 | #silentArgs = '/s /v"/qn"' # InstallShield with MSI 27 | #silentArgs = '/s' # Wise InstallMaster 28 | #silentArgs = '-s' # Squirrel 29 | #silentArgs = '-q' # Install4j 30 | #silentArgs = '-s -u' # Ghost 31 | # Note that some installers, in addition to the silentArgs above, may also need assistance of AHK to achieve silence. 32 | #silentArgs = '' # none; make silent with input macro script like AutoHotKey (AHK) 33 | # https://chocolatey.org/packages/autohotkey.portable 34 | #validExitCodes= @(0) #please insert other valid exit codes here 35 | } 36 | 37 | $uninstalled = $false 38 | # Get-UninstallRegistryKey is new to 0.9.10, if supporting 0.9.9.x and below, 39 | # take a dependency on "chocolatey-core.extension" in your nuspec file. 40 | # This is only a fuzzy search if $softwareName includes '*'. Otherwise it is 41 | # exact. In the case of versions in key names, we recommend removing the version 42 | # and using '*'. 43 | [array]$key = Get-UninstallRegistryKey -SoftwareName $packageArgs['softwareName'] 44 | 45 | if ($key.Count -eq 1) { 46 | $key | % { 47 | $packageArgs['file'] = "$($_.UninstallString)" #NOTE: You may need to split this if it contains spaces, see below 48 | 49 | if ($packageArgs['fileType'] -eq 'MSI') { 50 | # The Product Code GUID is all that should be passed for MSI, and very 51 | # FIRST, because it comes directly after /x, which is already set in the 52 | # Uninstall-ChocolateyPackage msiargs (facepalm). 53 | $packageArgs['silentArgs'] = "$($_.PSChildName) $($packageArgs['silentArgs'])" 54 | 55 | # Don't pass anything for file, it is ignored for msi (facepalm number 2) 56 | # Alternatively if you need to pass a path to an msi, determine that and 57 | # use it instead of the above in silentArgs, still very first 58 | $packageArgs['file'] = '' 59 | } else { 60 | # NOTES: 61 | # - You probably will need to sanitize $packageArgs['file'] as it comes from the registry and could be in a variety of fun but unusable formats 62 | # - Split args from exe in $packageArgs['file'] and pass those args through $packageArgs['silentArgs'] or ignore them 63 | # - Ensure you don't pass double quotes in $file (aka $packageArgs['file']) - otherwise you will get "Illegal characters in path when you attempt to run this" 64 | # - Review the code for auto-uninstaller for all of the fun things it does in sanitizing - https://github.com/chocolatey/choco/blob/bfe351b7d10c798014efe4bfbb100b171db25099/src/chocolatey/infrastructure.app/services/AutomaticUninstallerService.cs#L142-L192 65 | } 66 | 67 | Uninstall-ChocolateyPackage @packageArgs 68 | } 69 | } elseif ($key.Count -eq 0) { 70 | Write-Warning "$packageName has already been uninstalled by other means." 71 | } elseif ($key.Count -gt 1) { 72 | Write-Warning "$($key.Count) matches found!" 73 | Write-Warning "To prevent accidental data loss, no programs will be uninstalled." 74 | Write-Warning "Please alert package maintainer the following keys were matched:" 75 | $key | % {Write-Warning "- $($_.DisplayName)"} 76 | } 77 | 78 | ## OTHER POWERSHELL FUNCTIONS 79 | ## https://chocolatey.org/docs/helpers-reference 80 | #Uninstall-ChocolateyZipPackage $packageName # Only necessary if you did not unpack to package directory - see https://chocolatey.org/docs/helpers-uninstall-chocolatey-zip-package 81 | #Uninstall-ChocolateyEnvironmentVariable # 0.9.10+ - https://chocolatey.org/docs/helpers-uninstall-chocolatey-environment-variable 82 | #Uninstall-BinFile # Only needed if you used Install-BinFile - see https://chocolatey.org/docs/helpers-uninstall-bin-file 83 | ## Remove any shortcuts you added in the install script. 84 | 85 | -------------------------------------------------------------------------------- /etc/visual-code/AncientAssembly/.vsixmanifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Ancient Assembly 6 | Ancient Assembly developmemnt environment (8bit cpu) 7 | ancient,8bit,assembly,8bit assembly,__ext_.asm,__ext_.ancient 8 | Languages 9 | Public 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | extension/LICENSE 24 | extension/images/icon.png 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /etc/visual-code/AncientAssembly/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Yuuki Wesp 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. -------------------------------------------------------------------------------- /etc/visual-code/AncientAssembly/README.md: -------------------------------------------------------------------------------- 1 | 2 |

3 | 4 | 5 | 6 |

7 | 8 | 9 |

10 | AncientVM 🔥 11 |

12 | 13 |

14 | 8bit Virtual Machine & Ancient Assembler-style language 15 |

16 | 17 | 18 |

19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |

32 | 33 | 34 |

35 | 36 | Visual Studio Marketplace Version 37 | 38 | 39 | 40 | 41 |

42 | 43 | 44 | ![image](https://user-images.githubusercontent.com/13326808/60311909-e71fa900-9961-11e9-96f0-bf4c4a45681c.png) 45 | 46 | 47 |
48 | Spoiler 49 | 50 | ![meme](https://user-images.githubusercontent.com/13326808/72352994-55586d00-36f4-11ea-8667-39475c9fd69f.png) 51 | 52 | by 53 | [@ViktorChernyaev](https://github.com/ViktorChernyaev) 54 |
55 | 56 | 57 | --- 58 | 59 | > Ancient VM proof of concept of the language, toolskit, virtual machine and ecosystem 60 | > A VM with 50+ instructions, SIMD Vector calculation, modularity, language and compiler, cli tool and package register of modules and extensions 61 | 62 | --- 63 | 64 | 65 | # 📡 Installation 66 | 67 | ```bash 68 | $ yarn global add @rune/cli 69 | $ rune install vm 70 | ``` 71 | 72 | # 💻 OS Support 73 | 74 | OS | Version | Architectures 75 | ------------------------------|-------------------------------|---------------- 76 | Windows 10 | 1607+ | x64, ARM32 77 | OSX | 10.14+ | x64 78 | Linux | | x64, ARM32, ARM64 79 | 80 | 81 | # Documentation 82 | See [Docs](https://docs.vm.runic.cloud) 83 | -------------------------------------------------------------------------------- /etc/visual-code/AncientAssembly/ancient.configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "comments": { 3 | "lineComment": [ ";" ], 4 | "blockComment": [ "{|", "|}" ] 5 | }, 6 | "brackets": [ 7 | ["{", "}"], 8 | ["[", "]"], 9 | ["(", ")"] 10 | ], 11 | "autoClosingPairs": [ 12 | ["{", "}"], 13 | ["[", "]"], 14 | ["(", ")"], 15 | ["\"", "\""], 16 | ["'", "'"] 17 | ], 18 | "surroundingPairs": [ 19 | ["{", "}"], 20 | ["[", "]"], 21 | ["(", ")"], 22 | ["\"", "\""], 23 | ["'", "'"] 24 | ] 25 | } -------------------------------------------------------------------------------- /etc/visual-code/AncientAssembly/extension.js: -------------------------------------------------------------------------------- 1 | var vscode = require('vscode'); 2 | function activate(context) { 3 | console.log('AncientAssembly extension activated!'); 4 | console.log("path " + vscode.workspace.rootPath); 5 | } 6 | function deactivate() { } 7 | exports.deactivate = deactivate; 8 | exports.activate = activate; -------------------------------------------------------------------------------- /etc/visual-code/AncientAssembly/images/badges/ages-18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ancientproject/VM/368520c13e32ebaaf46a7c5bb1c7c52944f98818/etc/visual-code/AncientAssembly/images/badges/ages-18.png -------------------------------------------------------------------------------- /etc/visual-code/AncientAssembly/images/badges/ages-18.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /etc/visual-code/AncientAssembly/images/badges/designed-in-ms-paint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ancientproject/VM/368520c13e32ebaaf46a7c5bb1c7c52944f98818/etc/visual-code/AncientAssembly/images/badges/designed-in-ms-paint.png -------------------------------------------------------------------------------- /etc/visual-code/AncientAssembly/images/badges/designed-in-ms-paint.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /etc/visual-code/AncientAssembly/images/badges/gluten-free.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ancientproject/VM/368520c13e32ebaaf46a7c5bb1c7c52944f98818/etc/visual-code/AncientAssembly/images/badges/gluten-free.png -------------------------------------------------------------------------------- /etc/visual-code/AncientAssembly/images/badges/gluten-free.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /etc/visual-code/AncientAssembly/images/badges/made-with-c-sharp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ancientproject/VM/368520c13e32ebaaf46a7c5bb1c7c52944f98818/etc/visual-code/AncientAssembly/images/badges/made-with-c-sharp.png -------------------------------------------------------------------------------- /etc/visual-code/AncientAssembly/images/badges/made-with-c-sharp.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /etc/visual-code/AncientAssembly/images/badges/winter-is-coming.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ancientproject/VM/368520c13e32ebaaf46a7c5bb1c7c52944f98818/etc/visual-code/AncientAssembly/images/badges/winter-is-coming.png -------------------------------------------------------------------------------- /etc/visual-code/AncientAssembly/images/badges/winter-is-coming.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /etc/visual-code/AncientAssembly/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ancientproject/VM/368520c13e32ebaaf46a7c5bb1c7c52944f98818/etc/visual-code/AncientAssembly/images/icon.png -------------------------------------------------------------------------------- /etc/visual-code/AncientAssembly/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ancient-asm", 3 | "displayName": "Ancient VM Language", 4 | "description": "Ancient VM developmemnt environment", 5 | "version": "0.70.4", 6 | "icon": "images/icon.png", 7 | "galleryBanner": { 8 | "color": "#18c7b1", 9 | "theme": "dark" 10 | }, 11 | "publisher": "rijndael", 12 | "license": "MIT", 13 | "bugs": { 14 | "url": "https://github.com/0xF6/ancient_cpu/issues" 15 | }, 16 | "homepage": "https://github.com/0xF6/ancient_cpu/", 17 | "repository": { 18 | "type": "git", 19 | "url": "https://github.com/0xF6/ancient_cpu.git" 20 | }, 21 | "engines": { 22 | "vscode": "^1.4.0" 23 | }, 24 | "categories": [ 25 | "Programming Languages" 26 | ], 27 | "keywords": [ 28 | "assembly", 29 | "virtual-machine", 30 | "cli", 31 | "intermediate-language", 32 | "il", 33 | "assembler-language", 34 | "language" 35 | ], 36 | "activationEvents": [ 37 | "onLanguage:asm", 38 | "onCommand:extension.target.create", 39 | "onCommand:extension.target.select", 40 | "onCommand:extension.target.run", 41 | "onCommand:extension.target.build" 42 | ], 43 | "main": "./extension", 44 | "contributes": { 45 | "languages": [ 46 | { 47 | "id": "asm", 48 | "aliases": [ 49 | "Ancient Assembly" 50 | ], 51 | "extensions": [ 52 | ".asm", 53 | ".ancient" 54 | ], 55 | "configuration": "./ancient.configuration.json" 56 | } 57 | ], 58 | "grammars": [ 59 | { 60 | "language": "asm", 61 | "scopeName": "source.asm.ancient", 62 | "path": "./syntaxes/asm.tmLanguage" 63 | } 64 | ], 65 | "snippets": [ 66 | { 67 | "language": "asm", 68 | "path": "./syntaxes/snippets.json" 69 | } 70 | ] 71 | }, 72 | "scripts": { 73 | "postinstall": "node ./node_modules/vscode/bin/install" 74 | }, 75 | "devDependencies": { 76 | "vscode": "^0.11.0" 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /etc/visual-code/AncientAssembly/syntaxes/_.csx: -------------------------------------------------------------------------------- 1 | Enum.GetNames(typeof(IID)).Select(x => x.Replace("_", ".")).Select(x => $".{x}").ToArray().Where(x => !Keys().Contains(x)).ToArray() 2 | List Keys() 3 | { 4 | var list = new List(); 5 | foreach (KeyValuePair i in jo) list.Add(i.Key); 6 | return list; 7 | } -------------------------------------------------------------------------------- /etc/visual-code/AncientAssembly/syntaxes/asm.tmLanguage: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | fileTypes 6 | 7 | asm 8 | anc 9 | 10 | name 11 | Ancient Assembly 12 | patterns 13 | 14 | 15 | include 16 | #comments 17 | 18 | 19 | include 20 | #constants 21 | 22 | 23 | include 24 | #control 25 | 26 | 27 | include 28 | #ancientasm 29 | 30 | 31 | include 32 | #quotes 33 | 34 | 35 | include 36 | #operators 37 | 38 | 39 | include 40 | #labels 41 | 42 | 43 | include 44 | #support 45 | 46 | 47 | repository 48 | 49 | control 50 | 51 | patterns 52 | 53 | 54 | match 55 | (?i)((^|\s+)\~label|#use|.sig|@|.ret|.warm|init|.prune|.halt|\s+ert)\b 56 | name 57 | keyword.control.error 58 | 59 | 60 | 61 | ancientasm 62 | 63 | patterns 64 | 65 | 66 | match 67 | (?i)(\s+|((^|\s+|(?<=\())))(@float_t|\$|\#\(|\(|\)|@char_t|@string_to)(?=\.[bzwaqlt]|\s+|[:$#(\\]) 68 | name 69 | keyword 70 | 71 | 72 | match 73 | (?i)(\s+|((^|\s+|(?<=\())))(\#\{|\})(?=\.[bzwaqlt]|\s+|[:$#(\\]) 74 | name 75 | storage.modifier 76 | 77 | 78 | match 79 | \!\[\~\w+\] 80 | name 81 | constant.regexp 82 | 83 | 84 | match 85 | (?i)(\s+|((^|\s+|(?<=\())))(true|false|pi|p%)(?=\.[bzwaqlt]|\s+|[:$#(\\]) 86 | name 87 | constant.regexp 88 | 89 | 90 | 91 | labels 92 | 93 | patterns 94 | 95 | 96 | 97 | match 98 | (?i)\.[a-zA-Z_\.]+\b 99 | name 100 | entity.other.attribute-name.struct 101 | 102 | 103 | 104 | comments 105 | 106 | patterns 107 | 108 | 109 | 110 | begin 111 | \{\| 112 | end 113 | \|\} 114 | name 115 | comment.block 116 | 117 | 118 | match 119 | ;.* 120 | name 121 | comment.line.semicolon 122 | 123 | 124 | 125 | quotes 126 | 127 | 128 | patterns 129 | 130 | 131 | begin 132 | ' 133 | end 134 | ' 135 | name 136 | string.quoted.single 137 | 138 | 139 | begin 140 | " 141 | end 142 | " 143 | name 144 | string.quoted.double 145 | 146 | 147 | begin 148 | !{ 149 | end 150 | } 151 | name 152 | string.quoted.double 153 | 154 | 155 | 156 | constants 157 | 158 | patterns 159 | 160 | 161 | match 162 | (?i)(?<=,)\s*[xy]\b(?!.*\.reg) 163 | name 164 | constant.language.registers 165 | 166 | 167 | match 168 | \b[0-9]+\b 169 | name 170 | constant.numeric.decimal 171 | 172 | 173 | match 174 | (?i)\$\b\h+\b|\&\b\h+\b|\b0x\h+\b 175 | name 176 | constant.numeric.hexadecimal 177 | 178 | 179 | match 180 | %\b[0-1]+\b 181 | name 182 | constant.numeric.binary 183 | 184 | 185 | 186 | operators 187 | 188 | patterns 189 | 190 | 191 | match 192 | (?i)[+\-*/%!|^=~\:&<>]|equ|\.(and|not|(lo|hi)(?=\s*\()) 193 | name 194 | keyword.operators 195 | 196 | 197 | 198 | support 199 | 200 | patterns 201 | 202 | 203 | match 204 | (str|void|[uif]((2|8|16|32|64|128)))\b 205 | name 206 | support.type.asm 207 | 208 | 209 | match 210 | (?i)\b(\.?(alignb?|bits|cpu|fpu)|use(16|32|64))\b 211 | name 212 | support.directive.asm 213 | 214 | 215 | match 216 | \b(strict|nosplit|near|far|abs|rel|seg|wrt|absolute|common)\b 217 | name 218 | support.modifier.asm 219 | 220 | 221 | match 222 | \b([ao](16|32|64))\b 223 | name 224 | support.prefix.asm 225 | 226 | 227 | match 228 | \b__(u((8|16|32|64)([lb]e)?)|str|f(8|16|32|64|80[me]|128[lh])|Infinity|[QS]?NaN)__\b 229 | name 230 | support.function.asm 231 | 232 | 233 | match 234 | \b%?(sys|external|module)\b 235 | name 236 | invalid.deprecated 237 | 238 | 239 | 240 | 241 | 242 | scopeName 243 | source.asm.ancient 244 | uuid 245 | EFAA4088-12AA-40EA-B51F-DD5211BE9B46 246 | 247 | 248 | -------------------------------------------------------------------------------- /etc/visual-code/AncientAssembly/syntaxes/neeed.js: -------------------------------------------------------------------------------- 1 | .mvd 2 | .mvx 3 | .wtd 4 | .rfd 5 | .jump.p 6 | .page -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/Ancient.Compiler.Service.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | netstandard2.1 6 | x64 7 | true 8 | https://raw.githubusercontent.com/ancientproject/cli/master/resource/icon.png 9 | https://github.com/0xF6/ancient_cpu 10 | https://github.com/0xF6/ancient_cpu 11 | git 12 | (C) 2019 Yuuki Wesp 13 | MIT 14 | Yuuki Wesp 15 | Ancient Project 16 | 0.70.850 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | all 25 | runtime; build; native; contentfiles; analyzers; buildtransitive 26 | 27 | 28 | 29 | 30 | 31 | 32 | true 33 | 34 | 35 | -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/Emit/DebugSymbolsSegment.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.emit 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using tokens; 6 | 7 | [Obsolete] 8 | public class DebugSymbolsSegment : IChainSegment 9 | { 10 | public string Transform(IReadOnlyCollection tokens) 11 | { 12 | foreach (var token in tokens) 13 | { 14 | switch (token) 15 | { 16 | case InstructionExpression _: 17 | break; 18 | } 19 | } 20 | 21 | return null; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/Emit/Warning.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.emit 2 | { 3 | using System.Linq; 4 | using Sprache; 5 | 6 | public enum Warning 7 | { 8 | Undefined = -1, 9 | InternalError = 1, 10 | NoSource = 2, 11 | CouldNotWrite = 3, 12 | OutFileNotSpecified = 4, 13 | SourceFileNotFound = 5, 14 | UnexpectedToken = 6, 15 | PrecompiledSymbolNotFound = 7, 16 | IgnoredToken 17 | } 18 | public static class WarningEx 19 | { 20 | public static string Format(this Warning w) => $"FC{(int)w:0000}"; 21 | 22 | public static Warning getWarningCode(this IResult s) 23 | { 24 | var expect = s.Expectations.First(); 25 | // TODO 26 | return Warning.UnexpectedToken; 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/Tokens/ErrorCompileToken.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.tokens 2 | { 3 | using Sprache; 4 | 5 | public class ErrorCompileToken : ErrorToken, IInputToken 6 | { 7 | public ErrorCompileToken(IResult error) : base(error){} 8 | } 9 | public class ErrorEvolveToken : ErrorToken, IEvolveToken 10 | { 11 | public ErrorEvolveToken(IResult error) : base(error){} 12 | } 13 | 14 | public abstract class ErrorToken 15 | { 16 | public readonly IResult ErrorResult; 17 | public Position InputPosition { get; set; } 18 | 19 | protected ErrorToken(IResult error) => ErrorResult = error; 20 | public override string ToString() => ErrorResult.ToString(); 21 | } 22 | } -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/Tokens/Expression.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.tokens 2 | { 3 | public class Expression { } 4 | 5 | internal class IdentifierExpression : Expression 6 | { 7 | public string Identifier { get; } 8 | 9 | public IdentifierExpression(string identifier) => Identifier = identifier; 10 | 11 | public override string ToString() => $"{Identifier}"; 12 | } 13 | } -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/Tokens/IInputToken.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.tokens 2 | { 3 | using Sprache; 4 | 5 | public interface IInputToken 6 | { 7 | Position InputPosition { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/Tokens/InstructionExpression.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.tokens 2 | { 3 | using runtime; 4 | using Sprache; 5 | 6 | public class InstructionExpression : IInputToken 7 | { 8 | public Position InputPosition { get; set; } 9 | public Instruction Instruction { get; set; } 10 | 11 | public InstructionExpression(Instruction ins) => Instruction = ins; 12 | } 13 | 14 | public class NullExpression : IInputToken 15 | { 16 | public Position InputPosition { get; set; } 17 | } 18 | } -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/Tokens/OperatorKind.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.tokens 2 | { 3 | public enum OperatorKind 4 | { 5 | Dot, 6 | PipeLeft, 7 | PipeRight, 8 | Ref, 9 | AltRef, 10 | OpenParen, 11 | CloseParen, 12 | Value, 13 | When 14 | } 15 | } -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/Tokens/OperatorToken.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.tokens 2 | { 3 | using Sprache; 4 | 5 | public class OperatorToken : IInputToken 6 | { 7 | public OperatorToken(OperatorKind kind) => Kind = kind; 8 | public OperatorKind Kind { get; set; } 9 | public Position InputPosition { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/Tokens/ParserExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.tokens 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using Sprache; 7 | using static Sprache.Result; 8 | 9 | public class None : IOption 10 | { 11 | public T GetOrDefault() => default; 12 | public T Get() => throw new NotImplementedException(); 13 | public bool IsEmpty => true; 14 | public bool IsDefined => false; 15 | } 16 | public class Some : IOption 17 | { 18 | private readonly T _t; 19 | 20 | public Some(T t) => _t = t; 21 | public T GetOrDefault() => _t; 22 | public T Get() => _t; 23 | public bool IsEmpty => false; 24 | public bool IsDefined => true; 25 | } 26 | 27 | public static class ParserExtensions 28 | { 29 | 30 | public static T? Unwrap(this IOption t) where T : struct 31 | { 32 | if (t.IsDefined) 33 | return t.Get(); 34 | return null; 35 | } 36 | public static Parser Not(this Parser parser, string expectations) 37 | { 38 | if (parser == null) 39 | throw new ArgumentNullException(nameof(parser)); 40 | return i => 41 | { 42 | var result = parser(i); 43 | if (!result.WasSuccessful) 44 | return Success((object)null, i); 45 | var message = "`" + string.Join(", ", result.Expectations) + "' was not expected"; 46 | return Failure(i, message, new []{ expectations }); 47 | }; 48 | } 49 | public static Parser> OptionalWhenNotStart(this Parser parser) 50 | { 51 | if (parser == null) 52 | throw new ArgumentNullException(nameof(parser)); 53 | return (i => 54 | { 55 | var result = parser(i); 56 | 57 | if (result.WasSuccessful) 58 | return Success(new Some(result.Value), result.Remainder) as IResult>; 59 | if (result.Expectations.Any() && result.Remainder.Source.Length != result.Remainder.Position) 60 | return Failure>(result.Remainder, "", result.Expectations) as IResult>; 61 | return Success(new None(), i) as IResult>; 62 | }); 63 | } 64 | 65 | public static Parser NamedOperator(this Parser parser, OperatorKind kind) 66 | { 67 | return parser.Named( 68 | $"{kind} operator ({AssemblerSyntax.Operators.First(x => x.Value == kind).Key})"); 69 | } 70 | 71 | public static Parser WithPosition(this Parser parser) where T : class, IInputToken 72 | { 73 | return i => 74 | { 75 | var r = parser(i); 76 | if (r.WasSuccessful) 77 | r.Value.InputPosition = new Position(i.Position, i.Line, i.Column); 78 | 79 | return r; 80 | }; 81 | } 82 | 83 | public static Parser> ContinueMany(this Parser parser) 84 | { 85 | if (parser == null) throw new ArgumentNullException(nameof(parser)); 86 | 87 | return i => 88 | { 89 | var remainder = i; 90 | var result = new List(); 91 | var r = parser(i); 92 | 93 | while (true) 94 | { 95 | if (remainder.Equals(r.Remainder)) break; 96 | result.Add(r.WasSuccessful ? r.Value : new ErrorEvolveToken(r)); 97 | remainder = r.Remainder; 98 | r = parser(remainder); 99 | } 100 | return Success>(result, remainder); 101 | }; 102 | } 103 | public static Parser> ContinueMany(this Parser parser) 104 | { 105 | if (parser == null) throw new ArgumentNullException(nameof(parser)); 106 | 107 | return i => 108 | { 109 | var remainder = i; 110 | var result = new List(); 111 | var r = parser(i); 112 | 113 | while (true) 114 | { 115 | if (remainder.Equals(r.Remainder)) break; 116 | result.Add(r.WasSuccessful ? r.Value : new ErrorCompileToken(r)); 117 | remainder = r.Remainder; 118 | r = parser(remainder); 119 | } 120 | return Success>(result, remainder); 121 | }; 122 | } 123 | } 124 | } -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/Tokens/RefExpression.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.tokens 2 | { 3 | using System.Globalization; 4 | 5 | public class RefExpression : OperatorToken 6 | { 7 | public readonly byte Cell; 8 | 9 | public RefExpression(string cell) : base(OperatorKind.Ref) 10 | { 11 | if (byte.TryParse(cell, NumberStyles.AllowHexSpecifier,null, out var result)) 12 | Cell = result; 13 | } 14 | } 15 | public class ValueExpression : OperatorToken 16 | { 17 | public readonly ushort Value; 18 | 19 | public ValueExpression(string value) : base(OperatorKind.Ref) 20 | { 21 | if (ushort.TryParse(value, NumberStyles.AllowHexSpecifier,null, out var result)) 22 | Value = result; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/Tokens/Syntax/Operators.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.tokens 2 | { 3 | using System.Globalization; 4 | using Sprache; 5 | 6 | public partial class AssemblerSyntax 7 | { 8 | public virtual Parser PipeLeft => 9 | (from _ in Parse.String("|>") 10 | select OperatorKind.PipeLeft) 11 | .Token() 12 | .NamedOperator(OperatorKind.PipeLeft); 13 | public virtual Parser PipeRight => 14 | (from _ in Parse.String("<|") 15 | select OperatorKind.PipeRight) 16 | .Token() 17 | .NamedOperator(OperatorKind.PipeRight); 18 | 19 | public virtual Parser When => 20 | (from _ in Parse.String(OperatorsReversed[OperatorKind.When]) 21 | select OperatorKind.When) 22 | .Token() 23 | .NamedOperator(OperatorKind.When); 24 | public virtual Parser RefToken => 25 | (from refSym in Parse.Char('&') 26 | from openParen in Parse.Char('(') 27 | from cellID in HexToken 28 | from closeParen in Parse.Char(')') 29 | select new RefExpression(cellID)) 30 | .Token() 31 | .WithPosition() 32 | .Named("ref_token"); 33 | public virtual Parser ValueToken => 34 | (from refSym in Parse.Char('$') 35 | from openParen in Parse.Char('(') 36 | from value in HexToken 37 | from closeParen in Parse.Char(')') 38 | select new ValueExpression(value)) 39 | .Token() 40 | .WithPosition() 41 | .Named("value_token"); 42 | public virtual Parser CastCharToken => 43 | (from refSym in Parse.String("@char_t") 44 | from openParen in Parse.Char('(') 45 | from @char in CharToken 46 | from closeParen in Parse.Char(')') 47 | select (ushort)@char) 48 | .Token() 49 | .Named("char_t expression"); 50 | 51 | public virtual Parser SignatureToken => 52 | (from refSym in Parse.String("!{") 53 | from sign in Parse.AnyChar.Except(Parse.Char('}')).Many().Text() 54 | from closeParen in Parse.Char('}') 55 | select sign) 56 | .Token() 57 | .Named("signature expression"); 58 | 59 | public virtual Parser CastStringToken => 60 | (from refSym in Parse.String("@string_t") 61 | from openParen in Parse.Char('(') 62 | from @string in StringToken 63 | from closeParen in Parse.Char(')') 64 | select @string) 65 | .Token() 66 | .Named("string_t expression"); 67 | 68 | public virtual Parser CastFloat => 69 | (from refSym in Parse.String("@float_t") 70 | from openParen in Parse.Char('(') 71 | from @string in FloatToken 72 | from closeParen in Parse.Char(')') 73 | select float.Parse(@string, CultureInfo.InvariantCulture)) 74 | .Token() 75 | .Named("string_t expression"); 76 | } 77 | } -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/Tokens/Syntax/Segments.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.tokens 2 | { 3 | using System.Linq; 4 | using runtime; 5 | using Sprache; 6 | 7 | public partial class AssemblerSyntax 8 | { 9 | public virtual Parser UseToken => 10 | (from dword in 11 | from sharp in Parse.Char('#') 12 | from word in Parse.String("use") 13 | select "" 14 | from modulePath in StringToken 15 | select new InstructionExpression(new use(modulePath))) 16 | .Token() 17 | .Named("use expression"); 18 | 19 | 20 | public virtual Parser TypeToken => 21 | Parse.String("u8").Text().Or( 22 | Parse.String("u16").Text()).Or( 23 | Parse.String("u32").Text()).Or( 24 | Parse.String("u64").Text()).Or( 25 | Parse.String("f64").Text()).Or( 26 | Parse.String("void").Text()).Or( 27 | Parse.String("str").Text()).Or( 28 | Parse.String("u2").Text()).Token(); 29 | 30 | public virtual Parser ManyParser => ( 31 | from many in 32 | Parser 33 | select many) 34 | .ContinueMany() 35 | .Select(x => x.ToArray()); 36 | /// 37 | /// Comment token 38 | /// 39 | /// 40 | /// CharToken.Parse("; this is single-line comment"); 41 | /// 42 | public virtual Parser CommentToken => 43 | (from comment in new CommentParser(";", "{|", "|}", "\n").SingleLineComment 44 | select new CommentToken(comment)) 45 | .Token() 46 | .Named("comment token"); 47 | /// 48 | /// Single char wrapped in quote character 49 | /// 50 | /// 51 | /// CharToken.Parse("'1'"); 52 | /// 53 | public virtual Parser CharToken => 54 | (from @char in Wrap(Parse.AnyChar, Parse.Char('\'')) 55 | select @char) 56 | .Token() 57 | .Named("char token"); 58 | /// 59 | /// Single quote wrapped identifier token 60 | /// 61 | /// 62 | /// QuoteIdentifierToken.Parse("'test identifier token'"); 63 | /// 64 | public virtual Parser QuoteIdentifierToken => ( 65 | from @string in Wrap(Parse.AnyChar.Except(Parse.Char('\'')).Many().Text(), Parse.Char('\'')) 66 | select @string) 67 | .Token() 68 | .Named("quote string token"); 69 | /// 70 | /// string wrapped in double quote chars 71 | /// 72 | /// 73 | /// StringToken.Parse("\"str\"") -> "str" 74 | /// 75 | public virtual Parser StringToken => ( 76 | from @string in Wrap(Parse.AnyChar.Except(Parse.Char('"')).Many().Text(), Parse.Char('"')) 77 | select @string) 78 | .Token().Named("string token"); 79 | 80 | /// 81 | /// Keyword token 82 | /// 83 | /// 84 | /// keyword string 85 | /// 86 | /// 87 | /// Keyword("var").Parse("var") 88 | /// 89 | public virtual Parser Keyword(string keyword) => 90 | (from word in Parse.String(keyword).Text() select word) 91 | .Token().Named($"keyword {keyword} token"); 92 | /// 93 | /// Float number token 94 | /// 95 | /// 96 | /// FloatToken.Parse("12.45") -> "12.45" 97 | /// FloatToken.Parse("-12.45") -> "-12.45" 98 | /// 99 | public virtual Parser FloatToken => ( 100 | from minus in Parse.Char('-').Optional() 101 | from @string in Parse.DecimalInvariant 102 | select $"{minus.GetOrElse('+')}{@string}") 103 | .Token().Named("string token"); 104 | 105 | /// 106 | /// hex number token 107 | /// 108 | /// 109 | /// HexToken.Parse("0xDA") -> DA 110 | /// 111 | public virtual Parser HexToken => 112 | (from zero in Parse.Char('0') 113 | from x in Parse.Chars("x") 114 | from number in Parse.Chars("ABCDEF1234567890").Many().Text() 115 | select number) 116 | .Token() 117 | .Named("hex number"); 118 | } 119 | } -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/Tokens/Syntax/Transformers.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.tokens 2 | { 3 | using System.Collections.Generic; 4 | using System.Globalization; 5 | using System.Linq; 6 | using runtime; 7 | using runtime.emit.sys; 8 | using Sprache; 9 | 10 | public partial class AssemblerSyntax 11 | { 12 | public virtual Parser Signature => 13 | (from dword in InstructionToken(IID.sig) 14 | from name in (from c in Parse.Char('@') 15 | from name in Parse.AnyChar.Except(Parse.Char('(')).Many().Text() 16 | select name) 17 | from args in ( 18 | from open in Parse.Char('(') 19 | from list in TypeListToken 20 | from close in Parse.Char(')') 21 | select list 22 | ).Token().Named("argument list") 23 | from lambda in Parse.String("->").Token().Named("lambda") 24 | from type in TypeToken 25 | select new SignatureEvolve(args.ToList(), name, type)) 26 | .Token() 27 | .WithPosition() 28 | .Named($"sig expression"); 29 | 30 | private Parser> TypeListToken => 31 | ( 32 | from type in TypeToken 33 | select type 34 | ).DelimitedBy(Parse.Char(',')); 35 | 36 | public virtual Parser Locals => 37 | (from dword in InstructionToken(IID.locals) 38 | from init in Parse.String("init").Token() 39 | from s in Parse.String("#(").Text() 40 | from g in ( 41 | from hex in (from c1 in Parse.Char('[') 42 | from hex in HexToken 43 | from c2 in Parse.Char(']') 44 | select hex).Token().Named("hex tail token") 45 | from type in 46 | Parse.String("u8").Text().Or( 47 | Parse.String("u16").Text()).Or( 48 | Parse.String("u32").Text()).Or( 49 | Parse.String("u64").Text()).Or( 50 | Parse.String("f64").Text()).Or( 51 | Parse.String("str").Text()).Or( 52 | Parse.String("u2").Text()) 53 | from dd in Parse.Char(',').Optional() 54 | select new EvaluationSegment(byte.Parse(hex, NumberStyles.AllowHexSpecifier), type) 55 | ).Token().Named("segment evaluation stack token").AtLeastOnce() 56 | from end in Parse.Char(')') 57 | select new LocalsInitEvolver(g.ToArray())) 58 | .Token() 59 | .WithPosition() 60 | .Named("locals transform expression"); 61 | 62 | 63 | public virtual Parser Group(Parser @group) => 64 | from s in Parse.String("#{").Text() 65 | from g in @group.AtLeastOnce() 66 | from end in Parse.Char('}') 67 | select g.ToArray(); 68 | 69 | public virtual Parser Label => 70 | (from dword in ProcToken("label") 71 | from name in QuoteIdentifierToken 72 | from hex in HexToken 73 | from auto in Keyword("auto").Optional() 74 | select new DefineLabel(name, hex)) 75 | .Token() 76 | .Named("label token"); 77 | } 78 | } -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/Tokens/TokenTree.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.tokens 2 | { 3 | using System; 4 | using System.Collections.Concurrent; 5 | using System.Collections.Generic; 6 | using System.Linq.Expressions; 7 | 8 | public interface IAssemblyFactory 9 | { 10 | void Bind(IChainSegment segment, Action complete); 11 | } 12 | 13 | public class AssemblyFactoryDefault : IAssemblyFactory 14 | { 15 | private readonly IReadOnlyCollection _tokens; 16 | private readonly ConcurrentQueue>>> queue = new ConcurrentQueue>>>(); 17 | 18 | public AssemblyFactoryDefault(IReadOnlyCollection tokens) => _tokens = tokens; 19 | 20 | public void Bind(IChainSegment segment, Action complete) 21 | => queue.Enqueue((x) => complete(segment.Transform(x))); 22 | 23 | public void Process() 24 | { 25 | foreach (var segment in queue) 26 | segment.Compile()(_tokens); 27 | } 28 | } 29 | public interface IChainSegment 30 | { 31 | TOut Transform(IReadOnlyCollection tokens); 32 | } 33 | } -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/Tokens/Transform/ClassicEvolve.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.tokens 2 | { 3 | using System.Collections.Generic; 4 | using runtime; 5 | using Sprache; 6 | 7 | public abstract class ClassicEvolve : IEvolveToken, IEvolveEvent 8 | { 9 | public Position InputPosition { get; set; } 10 | private readonly List cache = new List(); 11 | 12 | 13 | void IEvolveEvent.OnBuild() 14 | { 15 | cache.Clear(); 16 | OnBuild(cache); 17 | } 18 | 19 | protected abstract void OnBuild(List jar); 20 | 21 | public IReadOnlyCollection GetInstructions() => cache.AsReadOnly(); 22 | } 23 | } -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/Tokens/Transform/DefineLabel.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.tokens 2 | { 3 | using Sprache; 4 | 5 | public class DefineLabel : IEvolveToken 6 | { 7 | public string Name { get; set; } 8 | public string Hex { get; set; } 9 | public Position InputPosition { get; set; } 10 | 11 | public DefineLabel(string name, string hex) 12 | { 13 | Name = name; 14 | Hex = hex; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/Tokens/Transform/DefineLabels.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.tokens 2 | { 3 | using System.Linq; 4 | using Sprache; 5 | 6 | public class DefineLabels : IEvolveToken 7 | { 8 | public DefineLabel[] Labels { get; set; } 9 | 10 | public DefineLabels(IEvolveToken[] labels) => Labels = labels.Cast().ToArray(); 11 | public Position InputPosition { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/Tokens/Transform/EmptyEvolve.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.tokens 2 | { 3 | using Sprache; 4 | 5 | public class EmptyEvolve : IEvolveToken 6 | { 7 | public Position InputPosition { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/Tokens/Transform/IEvolveEvent.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.tokens 2 | { 3 | public interface IEvolveEvent 4 | { 5 | void OnBuild(); 6 | } 7 | } -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/Tokens/Transform/IEvolveToken.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.tokens 2 | { 3 | public interface IEvolveToken : IInputToken { } 4 | } -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/Tokens/Transform/LocalsInitEvolver.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.tokens 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using runtime; 7 | using runtime.emit.sys; 8 | using Sprache; 9 | 10 | public class LocalsInitEvolver : IEvolveToken 11 | { 12 | public LocalsInitEvolver(IReadOnlyCollection seg) 13 | { 14 | if(seg.Count > 255) 15 | throw new Exception("seg more 255 len"); 16 | 17 | var mem = new List(); 18 | 19 | mem.Add(new locals((byte) seg.Count)); 20 | mem.AddRange(seg.SelectMany(x => new []{x.OpCode.idx, x.OpCode.type})); 21 | 22 | this.Result = mem.Select(x => x.Assembly()).Select(x => $".raw 0x{x:X}").ToArray(); 23 | } 24 | 25 | public string[] Result; 26 | 27 | public Position InputPosition { get; set; } 28 | } 29 | 30 | 31 | } -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/Tokens/Transform/PushJEvolve.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.tokens 2 | { 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using runtime; 6 | 7 | public class PushJEvolve : ClassicEvolve 8 | { 9 | private readonly string _value; 10 | private readonly byte _cellDev; 11 | private readonly byte _actionDev; 12 | 13 | public PushJEvolve(string value, byte cellDev, byte ActionDev) 14 | { 15 | _value = value; 16 | _cellDev = cellDev; 17 | _actionDev = ActionDev; 18 | } 19 | 20 | protected override void OnBuild(List jar) 21 | => jar.AddRange(_value.Select(x => new mva(_cellDev, _actionDev, x))); 22 | } 23 | } -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/Tokens/Transform/SignatureEvolve.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.tokens 2 | { 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using runtime; 6 | using runtime.emit.sys; 7 | 8 | public class SignatureEvolve : ClassicEvolve 9 | { 10 | internal readonly List _argumentTypes; 11 | internal readonly string _signatureName; 12 | private readonly string _returnType; 13 | 14 | public SignatureEvolve(List argumentTypes, string signatureName, string returnType) 15 | { 16 | _argumentTypes = argumentTypes; 17 | _signatureName = signatureName; 18 | _returnType = returnType; 19 | } 20 | 21 | 22 | protected override void OnBuild(List jar) 23 | { 24 | jar.AddRange(new Instruction[] 25 | { 26 | new sig(_signatureName, _argumentTypes.Count, _returnType), 27 | new lpstr(_signatureName) 28 | }); 29 | jar.AddRange(_argumentTypes.Select(x => new raw(ExternType.FindAndConstruct(x)))); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/Tokens/Transform/TransformerSyntax.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.compiler.tokens 2 | { 3 | using System.Globalization; 4 | using System.Linq; 5 | using runtime; 6 | using runtime.emit.sys; 7 | using Sprache; 8 | 9 | public class TransformerSyntax : AssemblerSyntax 10 | { 11 | public virtual Parser PushJ => 12 | (from dword in InstructionToken(IID.mvj) 13 | from cell1 in RefToken 14 | from cell2 in RefToken 15 | from op2 in PipeRight 16 | from cell3 in CastStringToken 17 | select new PushJEvolve(cell3, cell1.Cell, cell2.Cell)) 18 | .Token() 19 | .WithPosition() 20 | .Named("mvj transform expression"); 21 | 22 | public override Parser HexToken => 23 | (from zero in Parse.Char('0') 24 | from x in Parse.Chars("x") 25 | from number in Parse.Chars("0xABCDEF123456789").Many().Text() 26 | select number) 27 | .Token() 28 | .Named("hex number").Or(RefLabel); 29 | public virtual Parser RefLabel => 30 | (from sym in Parse.String("![~") 31 | from name in Parse.LetterOrDigit.Or(Parse.Char('_')).Many().Text() 32 | from end in Parse.String("]") 33 | select name).Token().Named("ref_label token"); 34 | public Parser Evolver => 35 | PushJ 36 | .Or(Locals) 37 | .Or(Group(Label).Select(x => new DefineLabels(x))) 38 | .Or(Parser.Return(new EmptyEvolve())); 39 | 40 | 41 | public Parser ManyEvolver => 42 | (from many in Evolver select many) 43 | .ContinueMany() 44 | .Select(x => x.ToArray()); 45 | } 46 | } -------------------------------------------------------------------------------- /libs/Ancient.Compiler.Service/tag.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | [assembly: InternalsVisibleTo("acc_test")] 4 | [assembly: InternalsVisibleTo("vm_test")] -------------------------------------------------------------------------------- /libs/Ancient.Runtime.Context/Ancient.Runtime.Context.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Library 6 | netcoreapp3.1 7 | 0.70.850 8 | true 9 | https://raw.githubusercontent.com/ancientproject/cli/master/resource/icon.png 10 | https://github.com/0xF6/ancient_cpu 11 | https://github.com/0xF6/ancient_cpu 12 | git 13 | MIT 14 | Yuuki Wesp 15 | Ancient Project 16 | (C) 2020 Yuuki Wesp 17 | 18 | 19 | 20 | 21 | 22 | 23 | all 24 | runtime; build; native; contentfiles; analyzers; buildtransitive 25 | 26 | 27 | 28 | 29 | 30 | 31 | true 32 | 33 | 34 | -------------------------------------------------------------------------------- /libs/Ancient.Runtime.Context/DeviceImageLoadContext.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.runtime.context 2 | { 3 | using MoreLinq; 4 | using System; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Reflection; 8 | using System.Runtime.Loader; 9 | using System.Threading; 10 | 11 | public class DeviceImageLoadContext : AssemblyLoadContext 12 | { 13 | private readonly Action _trace; 14 | public DeviceImageLoadContext(Action trace = null) 15 | : base("dev-loader", true) 16 | => _trace = trace ?? (x => {}); 17 | 18 | public DirectoryInfo CacheDir 19 | { 20 | get 21 | { 22 | var dir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".ancient"); 23 | return Directory.CreateDirectory(dir).CreateSubdirectory("packages"); 24 | } 25 | } 26 | 27 | private void log(string s) => _trace($"[image-load-context] {s}"); 28 | 29 | public FileSystemInfo FindImage(string devName, Version version) 30 | { 31 | var corePath = $"deps/{devName}/{version.ToString(3)}/any/{devName}.image"; 32 | return new FileSystemInfo[] 33 | { 34 | new VMFileInfo(Path.Combine(CacheDir.FullName, corePath).Replace("\\", "/")), 35 | new FileInfo($"{Environment.GetEnvironmentVariable("VM_DEV_HOME") ?? "vm:/home"}/{corePath}"), 36 | new FileInfo($"./../../{corePath}"), 37 | new FileInfo($"./../{corePath}"), 38 | new FileInfo($"./{corePath}") 39 | }.Pipe(x => log($"try find '{devName}' in '{x}'")).FirstOrDefault(x => x.Exists); 40 | 41 | } 42 | 43 | protected override Assembly Load(AssemblyName assemblyName) 44 | { 45 | var imageName = assemblyName.Name; 46 | var fullImageName = $"{assemblyName.Name}.image"; 47 | var imageVersion = assemblyName.Version; 48 | var file = FindImage(imageName, imageVersion); 49 | if (file is null) 50 | throw new Exception($"can't load '{fullImageName}' - [not found]."); 51 | log($"'{fullImageName}' was found in '{file}' and success loaded"); 52 | var asm = Assembly.Load(File.ReadAllBytes(file.FullName)); 53 | return asm; 54 | } 55 | 56 | protected override IntPtr LoadUnmanagedDll(string unmanagedDllName) 57 | => throw new Exception($"can't load '{unmanagedDllName}.native' - loader is not supported."); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /libs/Ancient.Runtime.Context/DeviceLoader.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.runtime.context 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Reflection; 8 | using System.Runtime.Loader; 9 | using Ancient.ProjectSystem; 10 | using Newtonsoft.Json; 11 | 12 | public static class DeviceLoader 13 | { 14 | public static DeviceImageLoadContext Context { get; internal set; } 15 | public static event Action OnTrace; 16 | 17 | static DeviceLoader() 18 | { 19 | if(AppFlag.GetVariable("VM_TRACE")) 20 | OnTrace += Console.WriteLine; 21 | 22 | AssemblyLoadContext.Default.Resolving += (context, name) => 23 | { 24 | var assemblyPath = $"./{name.Name}.dll"; 25 | return context.LoadFromAssemblyPath(assemblyPath); 26 | }; 27 | } 28 | 29 | public static void Boot(Action hook) 30 | { 31 | if(!Directory.Exists("deps")) 32 | { 33 | trace($"[device-loader] directory '{new DirectoryInfo("deps").FullName}' not found"); 34 | return; 35 | } 36 | if(!new FileInfo("./deps/ancient.lock").Exists) 37 | { 38 | trace($"[device-loader] lock file not found."); 39 | return; 40 | } 41 | var locks = new List(); 42 | try 43 | { 44 | locks = JsonConvert.DeserializeObject(File.ReadAllText("./deps/ancient.lock")).ToList(); 45 | } 46 | catch (Exception e) 47 | { 48 | trace($"[device-loader] {e}"); 49 | } 50 | 51 | if (!locks.Any()) 52 | { 53 | trace($"[device-loader] lock file is empty."); 54 | return; 55 | } 56 | 57 | Grub(hook, locks.Select(x => 58 | new AssemblyName($"{x.id}, Version={x.version}")) 59 | .ToArray()); 60 | } 61 | public static void Grub(Action hook, params AssemblyName[] additionalImage) 62 | { 63 | Context ??= new DeviceImageLoadContext(trace); 64 | var asmList = additionalImage 65 | .Select(imageName => Context.LoadFromAssemblyName(imageName)) 66 | .ToList(); 67 | 68 | 69 | 70 | var devList = asmList 71 | .SelectMany(x => x.GetExportedTypes()) 72 | .Where(x => !x.IsAbstract) 73 | .Where(x => typeof(IDevice).IsAssignableFrom(x)) 74 | .Select(Activator.CreateInstance) 75 | .Select(x => (IDevice) x); 76 | foreach (var dev in devList) hook(dev); 77 | } 78 | 79 | private static void trace(string str) => OnTrace?.Invoke(str); 80 | } 81 | } -------------------------------------------------------------------------------- /libs/Ancient.Runtime.Context/VMFileInfo.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.runtime.context 2 | { 3 | using System.IO; 4 | 5 | public class VMFileInfo : FileSystemInfo 6 | { 7 | public VMFileInfo(string fileName) 8 | { 9 | Name = fileName; 10 | try 11 | { 12 | raw = new FileInfo(fileName); 13 | Exists = raw.Exists; 14 | } 15 | catch { } 16 | } 17 | 18 | private FileInfo raw { get; } 19 | 20 | public override void Delete() => raw?.Delete(); 21 | 22 | public override bool Exists { get; } 23 | public override string Name { get; } 24 | public override string ToString() => Name; 25 | } 26 | } -------------------------------------------------------------------------------- /samples/bios/bios.asm: -------------------------------------------------------------------------------- 1 | #{ 2 | ~label 'memory' 0x0 3 | ~label 'bios' 0xF 4 | ~label 'hpet' 0x1 5 | ~label 'channel' 0x2 6 | ~label 'boot' 0xF 7 | } 8 | ; set page to 0x400 (bios stage) 9 | .raw 0x3304000EF 10 | ; set memory channel zero 11 | .mva &(![~memory]) &(0x0) <| $(0x1) 12 | ; enable hpet 13 | .mva &(![~bios]) &(![~hpet]) <| $(0x1) 14 | ; set memory channel reading 15 | .mva &(![~bios]) &(![~channel]) <| $(0x0) 16 | ; start booting 17 | .mva &(![~bios]) &(![~boot]) <| $(0x0) 18 | ; jump to page 0x600 (executing stage) 19 | .raw 0x090600000 -------------------------------------------------------------------------------- /samples/bios/bios.rune.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "start": "echo 1" 4 | }, 5 | "name": "bios", 6 | "version": "0.31.101", 7 | "author": "Yuuki Wesp", 8 | "extension": "bios" 9 | } -------------------------------------------------------------------------------- /samples/led-jumper/device.scheme: -------------------------------------------------------------------------------- 1 | { 2 | "scheme": { 3 | "memory": "0x0", 4 | "bios": "0x45" 5 | } 6 | } -------------------------------------------------------------------------------- /samples/led-jumper/led-ui.rune.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "start": "echo 1" 4 | }, 5 | "name": "led-ui", 6 | "version": "0.0", 7 | "author": "Yuuki Wesp" 8 | } -------------------------------------------------------------------------------- /samples/led-jumper/led_jumper.asm: -------------------------------------------------------------------------------- 1 | #{ 2 | ~label 'on' 0xD 3 | ~label 'off' 0xE 4 | ~label 'led' 0xB 5 | } 6 | .ldi &(0x2) <| $(0x11) 7 | .ldi &(0x3) <| $(0x01) 8 | .ldi &(0xE) <| $(0x0C) 9 | 10 | ; if 0x2 == 0xF then set 0x0 11 | .ref.t &(0xD) 12 | ; bug 13 | .sub &(0x2) &(0x2) &(0x2) 14 | 15 | .ref.t &(0xA) 16 | ; enable disable LED 17 | .mvd &(![~led]) &(![~on] ) |> &(0x2) 18 | .mvd &(![~led]) &(![~off]) |> &(0x2) 19 | 20 | ; if 0xE(0xC value) >= 0x2 (0x2++) 21 | .jump.e &(0xD) ~- &(0x2) &(0xE) 22 | 23 | .add &(0x2) &(0x2) &(0x3) 24 | 25 | .jump.t &(0xA) 26 | .halt 27 | 28 | -------------------------------------------------------------------------------- /samples/nyan_coloring.asm: -------------------------------------------------------------------------------- 1 | .warm 2 | 3 | ; label to 0xF 4 | .ref_t &(0xF) 5 | 6 | ; push setting color to device 7 | .push_a &(0x1) &(0x9) <| $(0x1A) 8 | ; push char to device 9 | .push_a &(0x1) &(0x5) <| @char_t('n') 10 | .push_a &(0x1) &(0x9) <| $(0x1B) 11 | .push_a &(0x1) &(0x5) <| @char_t('y') 12 | .push_a &(0x1) &(0x9) <| $(0x1C) 13 | .push_a &(0x1) &(0x5) <| @char_t('a') 14 | .push_a &(0x1) &(0x9) <| $(0x1D) 15 | .push_a &(0x1) &(0x5) <| @char_t('n') 16 | .push_a &(0x1) &(0x9) <| $(0x1E) 17 | .push_a &(0x1) &(0x5) <| @char_t('!') 18 | ; clear setting color in device 19 | .push_a &(0x1) &(0x9) <| $(0x3F) 20 | 21 | ; jump to 0xF 22 | .jump_t &(0xF) 23 | ; shutdown 24 | .halt -------------------------------------------------------------------------------- /samples/rand/rand.asm: -------------------------------------------------------------------------------- 1 | #{ 2 | ~label 'z' 0x05 ~label 'a' 0x06 ~label 'b' 0x07 3 | ~label 'bios' 0x45 ~label 'tick' 0x05 4 | } 5 | .dup &(![~z]) &(0x1) 6 | 7 | .locals init #( 8 | [0x0] u32 9 | [0x1] u8 10 | ) 11 | ; ... 12 | .prune 13 | .dup &(![~z]) &(0x1) 14 | 15 | .locals init #( 16 | [0x0] f64, 17 | [0x1] u8, 18 | [0x2] u8, 19 | [0x3] u8, 20 | [0x4] u8, 21 | [0x5] u8 22 | ) 23 | ; ... 24 | .prune 25 | .dup &(![~z]) &(0x1) 26 | 27 | .locals init #( 28 | [0x0] f64 29 | [0x1] u8 30 | [0x2] u8 31 | [0x3] u8 32 | [0x4] u8 33 | [0x5] u8 34 | ) 35 | ; ... 36 | .prune 37 | .dup &(![~z]) &(0x1) -------------------------------------------------------------------------------- /samples/rand/rand.asm_: -------------------------------------------------------------------------------- 1 | #{ 2 | ~label 'z' 0x05 ~label 'a' 0x06 ~label 'b' 0x07 3 | ~label 'bios' 0x45 ~label 'tick' 0x05 4 | } 5 | {| this is fucking comment line |} 6 | .page ![0x600] 7 | .prune (0x0E1)<->(0x0D2) 8 | .warm 9 | .unlock &(0x000) 10 | .rf.d &(![~bios]) &(![~tick]) 11 | .pull &(![~z]) 12 | .ld.x &(0x009) $(0x4CE3) 13 | .mul $(0x01F) &(![~z]) 14 | .ixor &(0x009) &(![~z]) 15 | .dup &(![~z]) |> &(0x012) 16 | .stl.c &(0x012) 17 | .call.i !{sys:external:module(u32)} 18 | .add $(0xD00) &(![~z]) 19 | .mull $(0xAD0) &(![~z]) 20 | .lp.str &[{"random value: "}] 21 | .pull &(0x008) 22 | .mv.x &(0x015) <| &(0x008) 23 | .mv.x &(0x015) <| &(![~z]) 24 | .halt 25 | 0x38|01|0000 0x00|00|0000 0x00|75|33|32|00|00|00|00 26 | ; | | | | | | | | 27 | ; | len | index | u 3 2 28 | ; opcode segment typeof 29 | .locals init #( 30 | [0x0] u32 31 | [0x1] u8 32 | ) 33 | 34 | 35 | .prune 36 | .jump_e &(cell) ~- &(targetCell) &(targetValue) 37 | 38 | @float_t(12.2) -------------------------------------------------------------------------------- /samples/rand/rand.rune.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "start": "echo 1" 4 | }, 5 | "name": "rand", 6 | "version": "1", 7 | "author": "Yuuki Wesp" 8 | } -------------------------------------------------------------------------------- /samples/vector/device.scheme: -------------------------------------------------------------------------------- 1 | {"scheme":{}} -------------------------------------------------------------------------------- /samples/vector/normalize_vector.asm: -------------------------------------------------------------------------------- 1 | #{ 2 | ~label 'x' 0x1 3 | ~label 'y' 0x2 4 | ~label 'z' 0x3 5 | ~label 'ln' 0x0A 6 | ~label 'buf' 0x8 7 | } 8 | 9 | .mva &(0x5) &(0xF) <| $(0x0) 10 | ; load values 11 | .ldi &(![~x]) <| $(0x1) 12 | .ldi &(![~y]) <| $(0x2) 13 | .ldi &(![~z]) <| $(0x5) 14 | 15 | 16 | ; print info 17 | .lpstr !{"Vector values:"} 18 | .unlock &(![~buf]) str 19 | .mvx &(0x1) &(0x6) |> &(![~buf]) 20 | .mva &(0x1) &(0x6) <| $(0x0A) 21 | 22 | .mvj &(0x1) &(0x6) <| @string_t("x: ") 23 | .mvx &(0x1) &(0x6) |> &(![~x]) 24 | .mva &(0x1) &(0x6) <| $(![~ln]) 25 | 26 | .mvj &(0x1) &(0x6) <| @string_t("y: ") 27 | .mvx &(0x1) &(0x6) |> &(![~y]) 28 | .mva &(0x1) &(0x6) <| $(![~ln]) 29 | 30 | .mvj &(0x1) &(0x6) <| @string_t("z: ") 31 | .mvx &(0x1) &(0x6) |> &(![~z]) 32 | .mva &(0x1) &(0x6) <| $(![~ln]) 33 | 34 | 35 | ; normalize vector 36 | .add &(0x4) &(0x1) &(0x2) 37 | .swap &(0x4) &(0x2) 38 | .add &(0x4) &(0x2) &(0x3) 39 | .swap &(0x4) &(0x5) 40 | .sqrt &(0x4) &(0x5) 41 | 42 | ; result 43 | .mvj &(0x1) &(0x6) <| @string_t("Normalize value: ") 44 | .mvx &(0x1) &(0x6) |> &(0x4) 45 | .mva &(0x1) &(0x6) <| $(0x20) 46 | ; stage 47 | .mva &(0x1) &(0x7) <| $(0x0) 48 | ; clear 49 | .mva &(0x1) &(0x3) <| $(0x0) 50 | ; shutdown 51 | .halt -------------------------------------------------------------------------------- /samples/vector/vector.rune.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "start": "echo 1" 4 | }, 5 | "name": "vector", 6 | "version": "1.0", 7 | "author": "Yuuki Wesp", 8 | "deps": { 9 | "terminal": "^0.0.0.0", 10 | "beep": "^0.0.0.0" 11 | } 12 | } -------------------------------------------------------------------------------- /samples/while_print.asm: -------------------------------------------------------------------------------- 1 | ; set label to index in cell 0xC 2 | .ref_t &(0xC) 3 | ; push to device char 'n'(0x6E) 4 | .push_a &(0x1) &(0x6) @>> $(0x6E) 5 | ; push to device char 'a'(0x79) 6 | .push_a &(0x1) &(0x6) @>> $(0x79) 7 | ; push to device char 'y'(0x61) 8 | .push_a &(0x1) &(0x6) @>> $(0x61) 9 | ; push to device char ' '(0x20) 10 | .push_a &(0x1) &(0x6) @>> $(0x20) 11 | 12 | ; stash memory in device 13 | .push_a &(0x1) &(0x7) @>> $(0x00) 14 | ; clear memory in device 15 | .push_a &(0x1) &(0x3) @>> $(0x00) 16 | 17 | ; jump to label by index in cell 0xC 18 | .jump_t &(0xC) -------------------------------------------------------------------------------- /samples/x3e-firmware/firmware.asm: -------------------------------------------------------------------------------- 1 | #{ 2 | ~label 'reactor_bios' 0x46 3 | ~label 'pc0' 0xF3 4 | ~label 'buffer' 0x0 5 | ~label 'float_flag' 0x18 6 | ~label 'fast_forward' 0x19 7 | ~label 'true' 0x1 8 | ~label 'false' 0x0 9 | } 10 | .ldx &(![~float_flag]) <| $(![~true]) 11 | 12 | ; load power-value 13 | .rfd &(![~reactor_bios]) &(![~pc0]) 14 | .pull &(![~buffer]) 15 | 16 | ; |x arctan(x) cos(x)| 17 | .cos &(![~buffer]) 18 | .atan &(![~buffer]) 19 | 20 | .pull &(0x2) 21 | .pull &(0x3) 22 | 23 | .mul &(0x1) &(0x2) &(0x3) 24 | .ldi &(0x2) <| $(![~false]) 25 | .ldi &(0x3) <| $(![~false]) 26 | .swap &(0x1) &(0x2) 27 | .mul &(![~buffer]) &(![~buffer]) &(0x1) 28 | .ldx &(![~fast_forward]) <| $(![~true]) 29 | .abs &(![~buffer]) 30 | ; result in ~buffer cell 31 | .brk.s 32 | 33 | -------------------------------------------------------------------------------- /samples/x3e-firmware/x3e-firmware.rune.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "start": "echo 1" 4 | }, 5 | "name": "x3e-firmware", 6 | "version": "0.0.0", 7 | "author": "Yuuki Wesp" 8 | } -------------------------------------------------------------------------------- /test/Benchmark/Benchmark.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | true 7 | 8 | 9 | 10 | true 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /test/Benchmark/JobCompiling.cs: -------------------------------------------------------------------------------- 1 | //namespace Benchmark 2 | //{ 3 | // using System; 4 | // using System.Text; 5 | // using BenchmarkDotNet.Attributes; 6 | // using BenchmarkDotNet.Running; 7 | // using ancient.runtime; 8 | // using ancient.runtime.hardware; 9 | // using vm.component; 10 | 11 | // [InProcess] 12 | // [RPlotExporter, RankColumn] 13 | // public class JobCompiling 14 | // { 15 | // private Bus bus; 16 | // private uint push_a_to_null; 17 | // private uint push_a_to_rel; 18 | // private uint loadi; 19 | 20 | // [Benchmark(Description = ".ldi")] 21 | // public void S1() => bus.cpu.Step(loadi); 22 | 23 | // [Benchmark(Description = ".mva fast-off")] 24 | // public void S2() => bus.cpu.Step(push_a_to_null); 25 | 26 | // [Benchmark(Description = ".mva fast-off")] 27 | // public void S3() => bus.cpu.Step(push_a_to_rel); 28 | 29 | // [Benchmark(Description = ".mva fast-on")] 30 | // public void S4() => bus.cpu.Step(push_a_to_null); 31 | 32 | // [Benchmark(Description = ".mva fast-on")] 33 | // public void S5() => bus.cpu.Step(push_a_to_rel); 34 | 35 | // [GlobalSetup(Targets = new[] {nameof(S5), nameof(S4)})] 36 | // public void EnableFastWrite() 37 | // { 38 | // MemoryManagement.FastWrite = true; 39 | // Setup(); 40 | // } 41 | 42 | // [GlobalSetup(Targets = new[] {nameof(S1), nameof(S2), nameof(S3)})] 43 | // public void DisableFastWrite() 44 | // { 45 | // MemoryManagement.FastWrite = false; 46 | // Setup(); 47 | // } 48 | 49 | // private void Setup() 50 | // { 51 | // IntConverter.Register(); 52 | // bus = new Bus(); 53 | // bus.Add(new NullDevice()); 54 | // bus.Add(new RelDevice()); 55 | // push_a_to_rel = (uint)new mva(0x4, 0x6, 'x').Assembly(); 56 | // push_a_to_null = (uint)new mva(0x5, 0x6, 'x').Assembly(); 57 | // loadi = (uint)new ldi(0x5, 0x6).Assembly(); 58 | // } 59 | // } 60 | // public class RelDevice : Device 61 | // { 62 | // public RelDevice() : base(0x4, "") { } 63 | 64 | // private readonly StringBuilder relMemory = new StringBuilder(); 65 | 66 | // [ActionAddress(0x6)] 67 | // public void StageChar(char c) 68 | // { 69 | // if (c == 0xA) 70 | // relMemory.Append(Environment.NewLine); 71 | // else 72 | // relMemory.Append(c); 73 | 74 | // if (relMemory.Length > uint.MaxValue / 10) 75 | // relMemory.Clear(); 76 | // } 77 | // } 78 | // public class NullDevice : Device 79 | // { 80 | // public NullDevice() : base(0x5, "") { } 81 | 82 | // [ActionAddress(0x6)] 83 | // public void StageChar(char c) => Console.Out.Write(c); 84 | // } 85 | 86 | 87 | //} 88 | -------------------------------------------------------------------------------- /test/Benchmark/JobDeconstruct.cs: -------------------------------------------------------------------------------- 1 | namespace Benchmark 2 | { 3 | using ancient.runtime; 4 | using ancient.runtime.tools; 5 | using BenchmarkDotNet.Attributes; 6 | 7 | [InProcess] 8 | [RPlotExporter, RankColumn] 9 | public class JobDeconstruct 10 | { 11 | public static readonly Unicast u16 = new Unicast(); 12 | 13 | [Benchmark(Description = "deconstruct (old) [mask, bit array, take-while, alloc, u16 unicast]")] 14 | public void Dec1() 15 | { 16 | BitwiseContainer container = 0xABCDEF12345678; 17 | var pfx = u16 & ((container & 0x00F0000000000000)); 18 | var iid = u16 & ((container & 0x000F000000000000)); 19 | var r1 = u16 & ((container & 0x0000F00000000000)); 20 | var r2 = u16 & ((container & 0x00000F0000000000)); 21 | var r3 = u16 & ((container & 0x000000F000000000)); 22 | var u1 = u16 & ((container & 0x0000000F00000000)); 23 | var u2 = u16 & ((container & 0x00000000F0000000)); 24 | var x1 = u16 & ((container & 0x000000000F000000)); 25 | var x2 = u16 & ((container & 0x0000000000F00000)); 26 | var x3 = u16 & ((container & 0x00000000000F0000)); 27 | var x4 = u16 & ((container & 0x000000000000F000)); 28 | var o1 = u16 & ((container & 0x0000000000000F00)); 29 | var o2 = u16 & ((container & 0x00000000000000F0)); 30 | var o3 = u16 & ((container & 0x000000000000000F)); 31 | iid = u16 & ((pfx << 4) | iid ); 32 | } 33 | [Benchmark(Description = "deconstruct (new) [mask, shift container, u16 unicast]")] 34 | public void Dec2() 35 | { 36 | var shifter = ShiftFactory.CreateByIndex(52); 37 | 38 | ulong container = 0xABCDEF12345678; 39 | var pfx = u16 & ((container & 0x00F0000000000000) >> shifter.Shift()); 40 | var iid = u16 & ((container & 0x000F000000000000) >> shifter.Shift()); 41 | var r1 = u16 & ((container & 0x0000F00000000000) >> shifter.Shift()); 42 | var r2 = u16 & ((container & 0x00000F0000000000) >> shifter.Shift()); 43 | var r3 = u16 & ((container & 0x000000F000000000) >> shifter.Shift()); 44 | var u1 = u16 & ((container & 0x0000000F00000000) >> shifter.Shift()); 45 | var u2 = u16 & ((container & 0x00000000F0000000) >> shifter.Shift()); 46 | var x1 = u16 & ((container & 0x000000000F000000) >> shifter.Shift()); 47 | var x2 = u16 & ((container & 0x0000000000F00000) >> shifter.Shift()); 48 | var x3 = u16 & ((container & 0x00000000000F0000) >> shifter.Shift()); 49 | var x4 = u16 & ((container & 0x000000000000F000) >> shifter.Shift()); 50 | var o1 = u16 & ((container & 0x0000000000000F00) >> shifter.Shift()); 51 | var o2 = u16 & ((container & 0x00000000000000F0) >> shifter.Shift()); 52 | var o3 = u16 & ((container & 0x000000000000000F) >> shifter.Shift()); 53 | iid = u16 & ((pfx << 4) | iid ); 54 | } 55 | [Benchmark(Description = "deconstruct (new) [mask, u16 unicast]")] 56 | public void Dec3() 57 | { 58 | ulong container = 0xABCDEF12345678; 59 | var pfx = u16 & ((container & 0x00F0000000000000) >> 52); 60 | var iid = u16 & ((container & 0x000F000000000000) >> 48); 61 | var r1 = u16 & ((container & 0x0000F00000000000) >> 44); 62 | var r2 = u16 & ((container & 0x00000F0000000000) >> 40); 63 | var r3 = u16 & ((container & 0x000000F000000000) >> 36); 64 | var u1 = u16 & ((container & 0x0000000F00000000) >> 32); 65 | var u2 = u16 & ((container & 0x00000000F0000000) >> 28); 66 | var x1 = u16 & ((container & 0x000000000F000000) >> 24); 67 | var x2 = u16 & ((container & 0x0000000000F00000) >> 20); 68 | var x3 = u16 & ((container & 0x00000000000F0000) >> 16); 69 | var x4 = u16 & ((container & 0x000000000000F000) >> 12); 70 | var o1 = u16 & ((container & 0x0000000000000F00) >> 8); 71 | var o2 = u16 & ((container & 0x00000000000000F0) >> 4); 72 | var o3 = u16 & ((container & 0x000000000000000F) >> 0); 73 | iid = u16 & ((pfx << 4) | iid ); 74 | } 75 | [Benchmark(Description = "deconstruct (new) [mask, without u16 unicast]")] 76 | public void Dec4() 77 | { 78 | ulong container = 0xABCDEF12345678; 79 | var pfx = ((container & 0x00F0000000000000) >> 52); 80 | var iid = ((container & 0x000F000000000000) >> 48); 81 | var r1 = ((container & 0x0000F00000000000) >> 44); 82 | var r2 = ((container & 0x00000F0000000000) >> 40); 83 | var r3 = ((container & 0x000000F000000000) >> 36); 84 | var u1 = ((container & 0x0000000F00000000) >> 32); 85 | var u2 = ((container & 0x00000000F0000000) >> 28); 86 | var x1 = ((container & 0x000000000F000000) >> 24); 87 | var x2 = ((container & 0x0000000000F00000) >> 20); 88 | var x3 = ((container & 0x00000000000F0000) >> 16); 89 | var x4 = ((container & 0x000000000000F000) >> 12); 90 | var o1 = ((container & 0x0000000000000F00) >> 8); 91 | var o2 = ((container & 0x00000000000000F0) >> 4); 92 | var o3 = ((container & 0x000000000000000F) >> 0); 93 | iid = ((pfx << 4) | iid ); 94 | } 95 | [Benchmark(Description = "deconstruct (new) [mask, classic u16 cast]")] 96 | public void Dec5() 97 | { 98 | ulong container = 0xABCDEF12345678; 99 | var pfx = (ushort)((container & 0x00F0000000000000) >> 52); 100 | var iid = (ushort)((container & 0x000F000000000000) >> 48); 101 | var r1 = (ushort)((container & 0x0000F00000000000) >> 44); 102 | var r2 = (ushort)((container & 0x00000F0000000000) >> 40); 103 | var r3 = (ushort)((container & 0x000000F000000000) >> 36); 104 | var u1 = (ushort)((container & 0x0000000F00000000) >> 32); 105 | var u2 = (ushort)((container & 0x00000000F0000000) >> 28); 106 | var x1 = (ushort)((container & 0x000000000F000000) >> 24); 107 | var x2 = (ushort)((container & 0x0000000000F00000) >> 20); 108 | var x3 = (ushort)((container & 0x00000000000F0000) >> 16); 109 | var x4 = (ushort)((container & 0x000000000000F000) >> 12); 110 | var o1 = (ushort)((container & 0x0000000000000F00) >> 8); 111 | var o2 = (ushort)((container & 0x00000000000000F0) >> 4); 112 | var o3 = (ushort)((container & 0x000000000000000F) >> 0); 113 | iid = (ushort)((pfx << 4) | iid ); 114 | } 115 | } 116 | } -------------------------------------------------------------------------------- /test/Benchmark/JobInternString.cs: -------------------------------------------------------------------------------- 1 | //namespace Benchmark 2 | //{ 3 | // using System.Collections.Generic; 4 | // using ancient.runtime.@unsafe; 5 | // using BenchmarkDotNet.Attributes; 6 | // public static class StringLiteralMapClassic 7 | // { 8 | // public static string GetInternedString(string str, bool AddIfNotFound) 9 | // { 10 | // if (literalStorage.Contains(str)) 11 | // return str; 12 | // if (AddIfNotFound) 13 | // { 14 | // literalStorage.Add(str); 15 | // return str; 16 | // } 17 | // return null; 18 | // } 19 | 20 | // private static readonly HashSet literalStorage = new HashSet(); 21 | 22 | // public static void Clear() => literalStorage.Clear(); 23 | // } 24 | // [InProcess] 25 | // [RPlotExporter, RankColumn] 26 | // public class JobInternString 27 | // { 28 | // private static NativeString native; 29 | 30 | // [Benchmark(Description = "intern string [managed non-insert]")] 31 | // public void NonNativeFalseFound() 32 | // { 33 | // StringLiteralMapClassic.GetInternedString("test_string", false); 34 | // } 35 | // [Benchmark(Description = "intern string [native non-insert]")] 36 | // public unsafe void NativeFalseFound() 37 | // { 38 | // //fixed(NativeString* p = &native) 39 | // // StringLiteralMap.GetInternedString(p, false); 40 | // } 41 | // [GlobalSetup] 42 | // public static void Asd() 43 | // { 44 | // native = NativeString.Wrap("test_string"); 45 | // } 46 | // [Benchmark(Description = "intern string [native insert, auto free]")] 47 | // public unsafe void AddNative() 48 | // { 49 | // //fixed(NativeString* p = &native) 50 | // // StringLiteralMap.GetInternedString(p, true); 51 | // //StringLiteralMap.Clear(); 52 | // } 53 | 54 | // [Benchmark(Description = "intern string [managed insert, auto free]")] 55 | // public void AddClassic() 56 | // { 57 | // StringLiteralMapClassic.GetInternedString("test_string", true); 58 | // StringLiteralMapClassic.Clear(); 59 | // } 60 | // } 61 | //} -------------------------------------------------------------------------------- /test/Benchmark/Main.cs: -------------------------------------------------------------------------------- 1 | namespace Benchmark 2 | { 3 | using System; 4 | using System.Linq; 5 | using BenchmarkDotNet.Running; 6 | 7 | public class Program 8 | { 9 | public static void Main(string[] args) 10 | { 11 | if (!args.Any()) 12 | { 13 | Console.WriteLine(BenchmarkRunner.Run()); 14 | return; 15 | } 16 | 17 | switch (args.First()) 18 | { 19 | //case "compiling": 20 | // Console.WriteLine(BenchmarkRunner.Run()); return; 21 | //case "interned": 22 | // Console.WriteLine(BenchmarkRunner.Run()); return; 23 | } 24 | 25 | 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /test/RuneTest/CSharpCompileTest.cs: -------------------------------------------------------------------------------- 1 | namespace Tests 2 | { 3 | using NUnit.Framework; 4 | using rune.etc; 5 | 6 | public class CSharpCompileTest 7 | { 8 | [Test] 9 | public void Compile() 10 | { 11 | var result = CSharpCompile.Build("term", @" 12 | using System; 13 | using System.Runtime.InteropServices; 14 | using System.Text; 15 | using ancient.runtime; 16 | using static System.Console; 17 | 18 | [Guid(""2F380069-1951-41DF-9500-3FE4610FA924"")] 19 | 20 | 21 | public class TerminalDevice : Device 22 | { 23 | private StringBuilder relMemory = new StringBuilder(); 24 | 25 | public override void shutdown() => relMemory = null; 26 | public TerminalDevice() : base(0x1, ""term"") { } 27 | 28 | public override void write(long address, long data) 29 | { 30 | switch (address) 31 | { 32 | case 0x5: 33 | var c1 = (char)data; 34 | if(c1 == 0xA) 35 | Write(Environment.NewLine); 36 | else 37 | Write(c1); 38 | break; 39 | case 0x6: 40 | var c2 = (char)data; 41 | if (c2 == 0xA) 42 | relMemory.Append(Environment.NewLine); 43 | else 44 | relMemory.Append(c2); 45 | break; 46 | case 0x7: 47 | Out.Write(relMemory); 48 | break; 49 | case 0x8: 50 | relMemory.Clear(); 51 | break; 52 | case 0x9: 53 | var u1 = ((short)data & 0xF0) >> 4; 54 | var u2 = (short)data & 0xF; 55 | 56 | switch (u1) 57 | { 58 | case 0x1: 59 | ForegroundColor = (ConsoleColor)u2; 60 | break; 61 | case 0x2: 62 | BackgroundColor = (ConsoleColor)u2; 63 | break; 64 | case 0x3: 65 | ForegroundColor = ConsoleColor.White; 66 | break; 67 | case 0x4: 68 | BackgroundColor = ConsoleColor.Black; 69 | break; 70 | } 71 | break; 72 | } 73 | } 74 | } 75 | "); 76 | Assert.IsNotEmpty(result); 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /test/RuneTest/ChainOperator.cs: -------------------------------------------------------------------------------- 1 | namespace Tests 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | internal sealed class ChainOperator : ChainOperator 7 | { 8 | public ChainOperator(ChainOperator outerChain, T value) 9 | { 10 | this.data = outerChain.data; 11 | this.index = outerChain.index + 1; 12 | this.data.Add(value); 13 | } 14 | 15 | public ChainOperator(T value) 16 | { 17 | this.index = 0; 18 | this.data = new List { value }; 19 | } 20 | 21 | internal ChainOperator Pipe(Action act) 22 | { 23 | act(data[index].As()); 24 | return this; 25 | } 26 | } 27 | 28 | internal abstract class ChainOperator 29 | { 30 | protected internal IList data { get; set; } 31 | protected internal int index { get; set; } 32 | } 33 | } -------------------------------------------------------------------------------- /test/RuneTest/ChainOperatorEx.cs: -------------------------------------------------------------------------------- 1 | namespace Tests 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | internal static class ChainOperatorEx 7 | { 8 | public static N As(this object s) 9 | => (N) s; 10 | public static T Return(this ChainOperator chain) 11 | => chain.data[chain.index].As(); 12 | public static R Return(this ChainOperator chain, Func actor) 13 | => actor(chain.data[chain.index].As()); 14 | public static ChainOperator Chain(this List o, T t, Action, T> actor) 15 | => new ChainOperator(t).Pipe(x => actor(o, t)); 16 | public static ChainOperator And(this ChainOperator chain, Action actor) 17 | => chain.Pipe(actor); 18 | public static ChainOperator Mutate(this ChainOperator chain, Func actor) 19 | => new ChainOperator(chain, actor(chain.Return())); 20 | } 21 | } -------------------------------------------------------------------------------- /test/RuneTest/LockFileTest.cs: -------------------------------------------------------------------------------- 1 | namespace Tests 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Linq; 7 | using Ancient.ProjectSystem; 8 | using NUnit.Framework; 9 | using Pose; 10 | public class LockFileTest 11 | { 12 | [Test] 13 | [Author("Yuuki Wesp", "ls-micro@ya.ru")] 14 | [Description("ensure create lock file in virtual file system and assert exist file")] 15 | public void CreateIndexFileTest() 16 | { 17 | var dirs = new List(); 18 | var files = new List(); 19 | var shims = new List(); 20 | shims.Add(Shim 21 | .Replace(() => Pose.Is.A().FullName) 22 | .With((FileSystemInfo @this) => @this.ToString())); 23 | shims.Add(Shim 24 | .Replace(() => Directory.CreateDirectory(Pose.Is.A())) 25 | .With((string s) => dirs.Chain(s, (list, v) => list.Add(v)).Mutate(x => new DirectoryInfo(x)).Return())); 26 | shims.Add(Shim 27 | .Replace(() => File.WriteAllText(Pose.Is.A(), Pose.Is.A())) 28 | .With((string path, string content) => files.Add(path))); 29 | shims.Add(Shim 30 | .Replace(() => Directory.Exists(Pose.Is.A())) 31 | .With((string s) => dirs.Contains(s))); 32 | shims.Add(Shim 33 | .Replace(() => Pose.Is.A().Exists) 34 | .With((DirectoryInfo @this) => dirs.Contains(@this.ToString()))); 35 | shims.Add(Shim 36 | .Replace(() => Pose.Is.A().Exists) 37 | .With((FileInfo @this) => files.Contains(@this.ToString()))); 38 | 39 | try 40 | { 41 | 42 | PoseContext.Isolate(() => 43 | { 44 | Indexer.FromLocal(); 45 | 46 | }, shims.ToArray()); 47 | 48 | Assert.AreEqual("./deps/.ancient.lock", files.First()); 49 | } 50 | catch (Exception e) 51 | { 52 | Assert.Inconclusive(e.Message); 53 | } 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /test/RuneTest/RuneTest.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.1 5 | 6 | false 7 | x64 8 | true 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /test/RuntimeTest/NativeStringTest.cs: -------------------------------------------------------------------------------- 1 | namespace Tests 2 | { 3 | using System; 4 | using System.Collections; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using ancient.runtime; 9 | using ancient.runtime.@unsafe; 10 | using Xunit; 11 | 12 | public unsafe class NativeStringTest 13 | { 14 | [Fact] 15 | public void AllocateTest() 16 | { 17 | var str = "foo-bar"; 18 | var p = NativeString.Wrap(str); 19 | Assert.Equal(str.Length, p.GetLen()); 20 | Assert.Equal(Encoding.UTF8.GetByteCount(str), p.GetBuffer().Length); 21 | Assert.Equal(Encoding.UTF8, p.GetEncoding()); 22 | Assert.Equal(NativeString.GetHashCode(str), p.GetHashCode()); 23 | } 24 | public class StringGenerator : IEnumerable, IEnumerable 25 | { 26 | public string[][] Data() => 27 | Enumerable.Range(0, 1) 28 | .Select(i => Enumerable.Range(0, (int) Math.Pow(10, i)) 29 | .Select(v => Guid.NewGuid().ToString()) 30 | .ToArray()).ToArray(); 31 | 32 | 33 | public IEnumerator GetEnumerator() 34 | => Data().ToList().GetEnumerator(); 35 | IEnumerator IEnumerable.GetEnumerator() 36 | => GetEnumerator(); 37 | IEnumerator IEnumerable.GetEnumerator() 38 | => Data().Select(x => new object[]{x}).GetEnumerator(); 39 | } 40 | 41 | //[Theory(Timeout = 1000 * 120)] 42 | //[ClassData(typeof(StringGenerator))] 43 | public void LoadTest(string[] data) 44 | { 45 | var hashMap = new HashSet(); 46 | 47 | foreach (var s in data) 48 | Assert.True(hashMap.Add(NativeString.GetHashCode(s))); 49 | 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /test/RuntimeTest/RuntimeTest.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.1 5 | 6 | false 7 | x64 8 | true 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | all 19 | runtime; build; native; contentfiles; analyzers; buildtransitive 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /test/acc_test/AdditionalTokenParseTest.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.runtime.compiler.test 2 | { 3 | using System.Linq; 4 | using ancient.compiler.tokens; 5 | using Sprache; 6 | using Xunit; 7 | 8 | public class AdditionalTokenParseTest 9 | { 10 | [Theory] 11 | [InlineData(".sig @test(u2, u32) -> void")] 12 | public void CallStaticInternalFunctions(string code) 13 | { 14 | var result = new AssemblerSyntax().Signature.End().Parse(code); 15 | 16 | Assert.IsType(result); 17 | if (result is SignatureEvolve ev) 18 | { 19 | Assert.Equal(2, ev._argumentTypes.Count); 20 | Assert.Equal("u2", ev._argumentTypes.First()); 21 | Assert.Equal("u32", ev._argumentTypes.Last()); 22 | Assert.Equal("test", ev._signatureName); 23 | 24 | Assert.IsAssignableFrom(result); 25 | 26 | (ev as IEvolveEvent).OnBuild(); 27 | 28 | var instructions = ev.GetInstructions(); 29 | 30 | 31 | } 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /test/acc_test/AssemblyTagTest.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.runtime.compiler.test 2 | { 3 | using emit; 4 | using Xunit; 5 | 6 | public class AssemblyTagTest 7 | { 8 | [Fact] 9 | public void IsTag() 10 | => Assert.True(AssemblyTag.IsTag("EF0109JG00")); 11 | 12 | [Fact(Skip = "fucking datetime, todo")] 13 | public void EF0119K() => 14 | Assert.Contains("EF0119K", new AssemblyTag(AssemblyTag.SignType.Signed, AssemblyTag.ArchType.Any, 1).ToString()); 15 | 16 | [Fact(Skip = "fucking datetime, todo")] 17 | public void EF0500K() 18 | => Assert.Contains("EF0500K", new AssemblyTag(AssemblyTag.SignType.UnSecurity, AssemblyTag.ArchType.x64, 5).ToString()); 19 | } 20 | } -------------------------------------------------------------------------------- /test/acc_test/DynamicAssemblyTest.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.runtime.compiler.test 2 | { 3 | using System; 4 | using emit; 5 | using System.Linq; 6 | using Xunit; 7 | 8 | public class DynamicAssemblyTest 9 | { 10 | [Fact] 11 | public void Create() 12 | { 13 | var d = new DynamicAssembly("test", ("foo", "bar")); 14 | Assert.Equal("test", d.Name); 15 | Assert.Equal(("foo", "bar"), d.Metadata.First()); 16 | Assert.Throws(() => { d.GetBytes(); }); 17 | Assert.NotNull(d.GetGenerator()); 18 | Assert.IsType(d.GetGenerator()); 19 | d.GetGenerator().Emit(new ldi(0xF, 0xC)); 20 | Assert.Equal(sizeof(ulong), d.GetILCode().Length); 21 | Assert.Equal($"{0x1F00C00000000:X}", $"{BitConverter.ToUInt64(d.GetILCode().Reverse().ToArray()):X}"); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /test/acc_test/LocalsInitTest.cs: -------------------------------------------------------------------------------- 1 | namespace ancient.runtime.compiler.test 2 | { 3 | using emit.sys; 4 | using Xunit; 5 | 6 | public class LocalsInitTest 7 | { 8 | [Fact] 9 | public void LocalsSegmentTest() 10 | { 11 | var (o1, o2) = new EvaluationSegment(0xAB, "f64").OpCode; 12 | var eva = EvaluationSegment.Construct((ulong) o1.Assembly(), (ulong) o2.Assembly()); 13 | Assert.Equal("f64", eva.Type); 14 | Assert.Equal(0xAB, eva.Index); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /test/acc_test/acc_test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net5.0 5 | 6 | false 7 | 1.0.7.0 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | all 17 | runtime; build; native; contentfiles; analyzers; buildtransitive 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /test/vm_test/FixtureState.cs: -------------------------------------------------------------------------------- 1 | namespace vm_test 2 | { 3 | using ancient.runtime.@base; 4 | using ancient.runtime.emit.sys; 5 | using ancient.runtime.tools; 6 | 7 | public class FixtureState : IState 8 | { 9 | public void LoadMeta(byte[] meta) 10 | { 11 | throw new System.NotImplementedException(); 12 | } 13 | 14 | public ulong? next(ulong pc_ref) 15 | { 16 | throw new System.NotImplementedException(); 17 | } 18 | 19 | public ulong fetch() 20 | { 21 | throw new System.NotImplementedException(); 22 | } 23 | 24 | public ushort AcceptOpCode(BitwiseContainer container) 25 | { 26 | throw new System.NotImplementedException(); 27 | } 28 | 29 | public long SP { get; set; } 30 | public ulong pc { get; set; } 31 | public ushort r1 { get; set; } 32 | public ushort r2 { get; set; } 33 | public ushort r3 { get; set; } 34 | public ushort u1 { get; set; } 35 | public ushort u2 { get; set; } 36 | public ushort x1 { get; set; } 37 | public ushort x2 { get; set; } 38 | public ushort x3 { get; set; } 39 | public ushort x4 { get; set; } 40 | public ushort o1 { get; set; } 41 | public ushort o2 { get; set; } 42 | public ushort o3 { get; set; } 43 | public ushort iid { get; set; } 44 | public bool tc { get; set; } 45 | public bool ec { get; set; } 46 | public bool km { get; set; } 47 | public bool fw { get; set; } 48 | public bool of { get; set; } 49 | public bool nf { get; set; } 50 | public bool bf { get; set; } 51 | public bool ff { get; set; } 52 | public bool sf { get; set; } 53 | public bool northFlag { get; set; } 54 | public bool eastFlag { get; set; } 55 | public bool southFlag { get; set; } 56 | public ulong curAddr { get; set; } 57 | public ulong lastAddr { get; set; } 58 | public ulong step { get; set; } 59 | public sbyte halt { get; set; } 60 | public ulong[] mem { get; } = new ulong[64]; 61 | public ExternType[] mem_types { get; } = new ExternType[64]; 62 | } 63 | } -------------------------------------------------------------------------------- /test/vm_test/ModulesTest.cs: -------------------------------------------------------------------------------- 1 | namespace vm_test 2 | { 3 | using System.Linq; 4 | using ancient.runtime; 5 | using ancient.runtime.emit; 6 | using ancient.runtime.emit.sys; 7 | using ancient.runtime.hardware; 8 | using NUnit.Framework; 9 | 10 | [TestFixture] 11 | public class ModulesTest : VMBehaviour 12 | { 13 | [OneTimeSetUp] 14 | public void Setup() => IntConverter.Register(); 15 | 16 | 17 | [Test] 18 | [Author("Yuuki Wesp", "ls-micro@ya.ru")] 19 | [Description("parse functions in module class test")] 20 | public void ParseFunctionsTest() 21 | { 22 | Module.Boot(bus); 23 | var mem = new Instruction[] 24 | { 25 | new ldx(0x11, 0x1), 26 | new sig("test1", 0, "void"), 27 | new lpstr("test1"), 28 | new ldi(0x0, 0x5), 29 | new ret(), 30 | new sig("test2", 0, "void"), 31 | new lpstr("test2"), 32 | new ldi(0x1, 0x6), 33 | new call_i("test1()"), 34 | new ret(), 35 | new sig("test3", 0, "void"), new lpstr("test3"), 36 | new call_i("test2()"), 37 | new mul(0x3, 0x0, 0x1), 38 | new ret(), 39 | new call_i("test3()"), 40 | new nop(), 41 | }.ToArray(); 42 | 43 | var assembly = new DynamicAssembly("test"); 44 | var ilGen = assembly.GetGenerator(); 45 | ilGen.Emit(mem.Select(x => (OpCode)x).ToArray()); 46 | var module = new Module("test.module"); 47 | Module.modules.Add(module.GetHashCode(), module); 48 | state.LoadMeta(mem.SelectMany(x => x.GetMetaDataILBytes()).ToArray()); 49 | 50 | var functions = Module.ImportFunctions(assembly.GetILCode(), module); 51 | 52 | Assert.AreEqual(3, functions.Length); 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /test/vm_test/RegistersTest.cs: -------------------------------------------------------------------------------- 1 | namespace vm_test 2 | { 3 | using ancient.runtime.@base; 4 | using NUnit.Framework; 5 | 6 | [TestFixture] 7 | public class RegistersTest 8 | { 9 | [Test] 10 | public void ControlRegisterTest() 11 | { 12 | var state = new FixtureState 13 | { 14 | pc = 0x77 15 | }; 16 | 17 | var cr = new ControlRegister(state); 18 | 19 | Assert.AreEqual(0x77, cr.Recoil()); 20 | cr.Branch(0x95); 21 | Assert.AreEqual(0x95, cr.Recoil()); 22 | Assert.AreEqual(0x77, cr.Recoil()); 23 | cr.Branch(0x95); 24 | cr.Branch(0x145); 25 | cr.Branch(0x175); 26 | Assert.AreEqual(0x77, cr.Recoil(3)); 27 | cr.Branch(0x95); 28 | cr.Branch(0x145); 29 | cr.Branch(0x175); 30 | Assert.AreEqual(0x95, cr.Recoil(2)); 31 | 32 | } 33 | 34 | 35 | 36 | 37 | 38 | } 39 | } -------------------------------------------------------------------------------- /test/vm_test/StackTest.cs: -------------------------------------------------------------------------------- 1 | namespace vm_test 2 | { 3 | using NUnit.Framework; 4 | using vm.component; 5 | 6 | public class StackTest : VMBehaviour 7 | { 8 | public Stack stack; 9 | 10 | [SetUp] 11 | public void setUp() => stack = new Stack(bus) {__halter = this}; 12 | 13 | [Test] 14 | public void UseVirtualForward() 15 | { 16 | // use virtual stack 17 | state.southFlag = true; 18 | bios.virtual_stack = true; 19 | bios.memory_stack_forward = false; 20 | stack.push(0x1234567890ABCDEF); 21 | Assert.AreEqual(1, state.SP); 22 | Assert.AreEqual(0x1234567890ABCDEF, stack.pop()); 23 | 24 | } 25 | [Test] 26 | public void UseMemStackForward() 27 | { 28 | state.southFlag = true; 29 | bios.virtual_stack = false; 30 | bios.memory_stack_forward = true; 31 | stack.push(0x1234567890ABCDEF); 32 | Assert.AreEqual(1, state.SP); 33 | Assert.AreEqual(0x1234567890ABCDEF, stack.pop()); 34 | } 35 | [Test] 36 | public void WithoutVirtualForward() 37 | { 38 | // using memory stack forward 39 | state.southFlag = true; 40 | bios.virtual_stack = false; 41 | bios.memory_stack_forward = false; 42 | stack.push(0x1234567890ABCDEF); 43 | Assert.AreEqual(8, state.SP); 44 | Assert.AreEqual(0x1234567890ABCDEF, stack.pop()); 45 | } 46 | 47 | } 48 | } -------------------------------------------------------------------------------- /test/vm_test/TestDevice.cs: -------------------------------------------------------------------------------- 1 | namespace vm_test 2 | { 3 | using System.Collections.Generic; 4 | using ancient.runtime; 5 | using ancient.runtime.hardware; 6 | 7 | public class TestDevice : Device 8 | { 9 | public TestDevice() : base(0x1, "") { } 10 | 11 | public Stack stack = new Stack(); 12 | 13 | [ActionAddress(0x5)] 14 | public void Call(char t) => stack.Push(t); 15 | } 16 | } -------------------------------------------------------------------------------- /test/vm_test/UnsafeDestructTest.cs: -------------------------------------------------------------------------------- 1 | namespace vm_test 2 | { 3 | using ancient.runtime; 4 | using ancient.runtime.emit.@unsafe; 5 | using NUnit.Framework; 6 | 7 | public class UnsafeDestructTest 8 | { 9 | [Test] 10 | [Author("Yuuki Wesp", "ls-micro@ya.ru")] 11 | [Description("test of destruct of u8 number")] 12 | public void d8uTest() 13 | { 14 | var destructor = new d8u(0xFC); 15 | Assert.AreEqual(8, destructor.full_size); 16 | Assert.AreEqual(4, destructor.size); 17 | Assert.AreEqual(sizeof(byte), destructor.unmanaged_size); 18 | 19 | Assert.AreEqual(4, destructor.shift()); 20 | Assert.AreEqual(0, destructor.shift()); 21 | destructor.resetShifter(); 22 | var (r1, r2) = destructor; 23 | Assert.AreEqual($"0xF", $"0x{r1:X}"); 24 | Assert.AreEqual($"0xC", $"0x{r2:X}"); 25 | } 26 | 27 | [Test] 28 | [Author("Yuuki Wesp", "ls-micro@ya.ru")] 29 | [Description("test of destruct of u16 number")] 30 | public void d16uTest() 31 | { 32 | var destructor = new d16u(0xABCD); 33 | Assert.AreEqual(12, destructor.size); 34 | Assert.AreEqual(16, destructor.full_size); 35 | Assert.AreEqual(sizeof(ushort), destructor.unmanaged_size); 36 | 37 | Assert.AreEqual(12, destructor.shift()); 38 | Assert.AreEqual(8, destructor.shift()); 39 | Assert.AreEqual(4, destructor.shift()); 40 | Assert.AreEqual(0, destructor.shift()); 41 | destructor.resetShifter(); 42 | var (r1, r2, r3, r4) = destructor; 43 | Assert.AreEqual($"0xA", $"0x{r1:X}"); 44 | Assert.AreEqual($"0xB", $"0x{r2:X}"); 45 | Assert.AreEqual($"0xC", $"0x{r3:X}"); 46 | Assert.AreEqual($"0xD", $"0x{r4:X}"); 47 | } 48 | 49 | [Test] 50 | [Author("Yuuki Wesp", "ls-micro@ya.ru")] 51 | [Description("test of destruct of u32 number")] 52 | public void d32uTest() 53 | { 54 | var destructor = new d32u(0xABCDEF12); 55 | Assert.AreEqual(28, destructor.size); 56 | Assert.AreEqual(32, destructor.full_size); 57 | Assert.AreEqual(sizeof(uint), destructor.unmanaged_size); 58 | 59 | Assert.AreEqual(28, destructor.shift()); 60 | Assert.AreEqual(24, destructor.shift()); 61 | Assert.AreEqual(20, destructor.shift()); 62 | Assert.AreEqual(16, destructor.shift()); 63 | Assert.AreEqual(12, destructor.shift()); 64 | Assert.AreEqual(8, destructor.shift()); 65 | Assert.AreEqual(4, destructor.shift()); 66 | Assert.AreEqual(0, destructor.shift()); 67 | destructor.resetShifter(); 68 | var (r1, r2, r3, r4, r5, r6, r7, r8) = destructor; 69 | Assert.AreEqual($"0xA", $"0x{r1:X}"); 70 | Assert.AreEqual($"0xB", $"0x{r2:X}"); 71 | Assert.AreEqual($"0xC", $"0x{r3:X}"); 72 | Assert.AreEqual($"0xD", $"0x{r4:X}"); 73 | Assert.AreEqual($"0xE", $"0x{r5:X}"); 74 | Assert.AreEqual($"0xF", $"0x{r6:X}"); 75 | Assert.AreEqual($"0x1", $"0x{r7:X}"); 76 | Assert.AreEqual($"0x2", $"0x{r8:X}"); 77 | 78 | } 79 | } 80 | } -------------------------------------------------------------------------------- /test/vm_test/VMBehaviour.cs: -------------------------------------------------------------------------------- 1 | namespace vm_test 2 | { 3 | using System; 4 | using System.Linq; 5 | using System.Linq.Expressions; 6 | using ancient.runtime; 7 | using ancient.runtime.emit.sys; 8 | using ancient.runtime.tools; 9 | using MoreLinq; 10 | using NUnit.Framework; 11 | using vm.component; 12 | 13 | public abstract class VMBehaviour : IHalter 14 | { 15 | public Bus bus { get; private set; } 16 | public CPU cpu => bus.cpu; 17 | public State state => bus.State; 18 | public TestDevice dev => bus.find(0x1) as TestDevice; 19 | public BIOS bios => bus.find(0x45) as BIOS; 20 | 21 | protected VMBehaviour() 22 | { 23 | Module.Context.Add("assert->pass()", typeof(VMBehaviour).GetMethod("CallSuccess")); 24 | Module.Context.Add("assert->value()", typeof(VMBehaviour).GetMethod("CallValue")); 25 | reset(); 26 | Module.Boot(bus); 27 | } 28 | [TearDown] 29 | public void reset() 30 | { 31 | bus = new Bus(); 32 | bus.State.stack.__halter = this; 33 | bus.Add(new TestDevice()); 34 | state.southFlag = true; 35 | bios.virtual_stack = true; 36 | } 37 | 38 | public static void CallSuccess() => Assert.Pass("call_success"); 39 | public static int CallValue() => 0xDDD; 40 | 41 | public void load(params Instruction[] values) => load(values.Select(x => (ulong)x).ToArray()); 42 | public void load(params ulong[] values) => bus.State.Load("",values); 43 | 44 | public void loadMeta(params Instruction[] values) 45 | => state.LoadMeta(values.SelectMany(x => x.GetMetaDataILBytes()).ToArray()); 46 | 47 | public bool IsHalt() => state.halt == 1; 48 | public bool IsFastWrite() => state.fw; 49 | public bool IsOverflow() => state.of; 50 | public bool IsNegative() => state.nf; 51 | 52 | public void shot(int count) 53 | => shot((uint) count); 54 | public void shot(uint count = 1) => 55 | Enumerable.Range(0, (int) count).Pipe(x => cpu.Step()).Consume(); 56 | 57 | public void AssertRegister(Expression> exp, T value) where T : struct, IFormattable 58 | { 59 | var name = RuntimeUtilities.GetFieldPath(exp); 60 | var selector = exp.Compile(); 61 | var val = selector(state); 62 | if (value is float) 63 | Assert.AreEqual($"[{name}] {value}", $"[{name}] {val}"); 64 | else 65 | Assert.AreEqual($"[{name}] 0x{value:X}", $"[{name}] 0x{val:X}"); 66 | } 67 | 68 | public int halt(int reason, string text = "") 69 | { 70 | Assert.Fail($"HALT: {CPU.AssociationHaltCode(reason, text)}"); 71 | return reason; 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /test/vm_test/vm_test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net5.0 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /vm/csharp/Program.cs: -------------------------------------------------------------------------------- 1 | namespace vm 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Drawing; 6 | using System.Globalization; 7 | using System.IO; 8 | using System.Linq; 9 | using System.Runtime.InteropServices; 10 | using System.Text; 11 | using System.Threading; 12 | using System.Threading.Tasks; 13 | using ancient.compiler.emit; 14 | using ancient.runtime; 15 | using ancient.runtime.context; 16 | using component; 17 | using ancient.runtime.emit; 18 | using ancient.runtime.hardware; 19 | using ancient.runtime.tools; 20 | using MoreLinq; 21 | using Pastel; 22 | using ancient.compiler.tokens; 23 | using ancient.runtime.emit.sys; 24 | using Sprache; 25 | 26 | internal class Program 27 | { 28 | public static void InitializeProcess() 29 | { 30 | if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) 31 | Console.Title = "vm_host"; 32 | IntConverter.Register(); 33 | 34 | Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); 35 | if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) 36 | Console.OutputEncoding = Encoding.Unicode; 37 | } 38 | 39 | public static void InitializeFlags(Bus bus) 40 | { 41 | /* @0x11 */ 42 | bus.State.tc = AppFlag.GetVariable("VM_TRACE", false); 43 | /* @0x12 */ 44 | bus.State.ec = AppFlag.GetVariable("VM_ERROR", false); 45 | /* @0x13 */ 46 | bus.State.km = AppFlag.GetVariable("VM_KEEP_MEMORY"); 47 | /* @0x14 */ 48 | bus.State.fw = AppFlag.GetVariable("VM_MEM_FAST_WRITE"); 49 | } 50 | 51 | private static void HandleDebugger() 52 | { 53 | Console.WriteLine("Waiting for debugger to attach".Pastel(Color.Red)); 54 | while (!System.Diagnostics.Debugger.IsAttached) 55 | Thread.Sleep(100); 56 | Console.WriteLine("Debugger attached".Pastel(Color.Green)); 57 | } 58 | 59 | public static void InitializeMemory(Bus bus, params string[] args) 60 | { 61 | if (bus.State.halt != 0) 62 | return; 63 | if (!args.Any()) 64 | bus.State.Load("", 0xB00B50000); 65 | else 66 | { 67 | var nameFile = Path.Combine(Path.GetDirectoryName(args.First()), Path.GetFileNameWithoutExtension(args.First())); 68 | var file = new FileInfo($"{nameFile}.dlx"); 69 | var bios = new FileInfo($"{nameFile}.bios"); 70 | var pdb = new FileInfo($"{nameFile}.pdb"); 71 | 72 | if (AppFlag.GetVariable("VM_ATTACH_DEBUGGER") && pdb.Exists) 73 | bus.AttachDebugger(new Debugger(DebugSymbols.Open(File.ReadAllBytes(pdb.FullName)))); 74 | if (bios.Exists) 75 | { 76 | var asm = AncientAssembly.LoadFrom(bios.FullName); 77 | var bytes = asm.GetILCode(); 78 | var meta = asm.GetMetaILCode(); 79 | bus.State.Load("", CastFromBytes(bytes)); 80 | bus.State.LoadMeta(meta); 81 | } 82 | if (file.Exists) 83 | { 84 | var asm = AncientAssembly.LoadFrom(file.FullName); 85 | var bytes = asm.GetILCode(); 86 | var meta = asm.GetMetaILCode(); 87 | bus.State.Load("", CastFromBytes(bytes)); 88 | bus.State.LoadMeta(meta); 89 | } 90 | else 91 | bus.State.Load("", 0xB00B5000); 92 | } 93 | } 94 | 95 | public static async Task Main(string[] args) 96 | { 97 | if (AppFlag.GetVariable("MANAGED_DEBUGGER_WAIT")) 98 | HandleDebugger(); 99 | 100 | InitializeProcess(); 101 | var bus = new Bus(); 102 | 103 | InitializeFlags(bus); 104 | 105 | if (AppFlag.GetVariable("VM_TRACE")) 106 | DeviceLoader.OnTrace += Console.WriteLine; 107 | 108 | Module.Boot(bus); 109 | InternalVMFunctions.Boot(bus); 110 | DeviceLoader.Boot(bus.Add); 111 | 112 | if (AppFlag.GetVariable("REPL")) 113 | { 114 | Console.WriteLine("@ Ancient VM Interactive @".Pastel(Color.Green)); 115 | InteractiveConstruction(bus); 116 | } 117 | else 118 | InitializeMemory(bus, args); 119 | 120 | while (bus.State.halt == 0) 121 | bus.cpu.Step(); 122 | bus.Unload(); 123 | } 124 | 125 | public static ulong[] CastFromBytes(byte[] bytes) 126 | { 127 | if (bytes.Length % sizeof(ulong) == 0) 128 | return bytes.Batch(sizeof(ulong)).Select(x => BitConverter.ToUInt64(x.Reverse().ToArray())).Reverse().ToArray(); 129 | throw new Exception("invalid offset file."); 130 | } 131 | 132 | public static void InteractiveConstruction(Bus bus) 133 | { 134 | bus.State.km = true; 135 | bus.State.fw = true; 136 | Console.WriteLine($"keem memory has {"enabled".Pastel(Color.GreenYellow)}"); 137 | Console.WriteLine($"fast write has {"enabled".Pastel(Color.GreenYellow)}"); 138 | while (true) 139 | { 140 | Console.Write("> ".Pastel(Color.Gray)); 141 | var input = Console.ReadLine(); 142 | if (input is null) 143 | continue; 144 | if (input == "exit") 145 | return; 146 | 147 | if (input.StartsWith("0x")) 148 | { 149 | if (!ulong.TryParse(input.Remove(0, 2), NumberStyles.HexNumber, null, out _)) 150 | { 151 | Console.WriteLine("Invalid op code".Pastel(Color.Red)); 152 | continue; 153 | } 154 | 155 | // shit))0 156 | if (input.Length < 11) 157 | { 158 | var need = 12; 159 | var current = input.Length; 160 | var diff = (need - current); 161 | input = $"{input}{new string('0', diff)}"; 162 | } 163 | 164 | var decoded = ulong.Parse(input.Remove(0, 2), NumberStyles.HexNumber); 165 | bus.State.halt = 0; 166 | bus.State.Append(decoded); 167 | bus.cpu.Step(); 168 | } 169 | else 170 | { 171 | var token = new AssemblerSyntax().Parser.Parse(input); 172 | if (token is InstructionExpression instruction) 173 | { 174 | bus.State.halt = 0; 175 | bus.State.Append(instruction.Instruction.Assembly()); 176 | bus.cpu.Step(); 177 | } 178 | 179 | if (token is ErrorCompileToken error) 180 | { 181 | var exp = error.ErrorResult.Expectations.First(); 182 | var title = $"{error.ErrorResult.getWarningCode().To().Pastel(Color.Orange)}"; 183 | var message = $"character '{exp}' expected".Pastel(Color.Orange); 184 | Console.WriteLine($" :: {title} - {message}"); 185 | } 186 | } 187 | 188 | } 189 | } 190 | } 191 | } -------------------------------------------------------------------------------- /vm/csharp/component/BIOS.cs: -------------------------------------------------------------------------------- 1 | namespace vm.component 2 | { 3 | using System; 4 | using System.Diagnostics; 5 | using System.Drawing; 6 | using System.Threading; 7 | using ancient.runtime; 8 | using ancient.runtime.emit.@unsafe; 9 | using Pastel; 10 | using static State; 11 | 12 | public class BIOS : Device 13 | { 14 | private readonly Bus _bus; 15 | public Stopwatch systemTimer; 16 | public DateTime startTime; 17 | 18 | private readonly ulong[] mem = new ulong[32]; 19 | /// 20 | /// 0x1, using hpet timer 21 | /// 22 | public bool hpet 23 | { 24 | set => mem[0x1] = value ? 0x1UL : 0x0UL; 25 | get => mem[0x1] == 0x1; 26 | } 27 | /// 28 | /// 0x2, using virtual forwarding 29 | /// 30 | public bool virtual_stack 31 | { 32 | set => mem[0x2] = value ? 0x1UL : 0x0UL; 33 | get => mem[0x2] == 0x1; 34 | } 35 | /// 36 | /// 0x3, using forward in standalone memory sector 37 | /// 38 | public bool memory_stack_forward 39 | { 40 | set => mem[0x3] = value ? 0x1UL : 0x0UL; 41 | get => mem[0x3] == 0x1; 42 | } 43 | /// 44 | /// 0x6, using guarding with violation memory write 45 | /// 46 | public bool bios_guard 47 | { 48 | set => mem[0x6] = value ? 0x1UL : 0x0UL; 49 | get => mem[0x6] == 0x1; 50 | } 51 | 52 | /// 53 | /// Ticks count after started system 54 | /// 55 | public long Ticks 56 | => hpet ? systemTimer.ElapsedTicks : Environment.TickCount; 57 | 58 | public BIOS(Bus bus) : base(0x45, "") 59 | { 60 | _bus = bus; 61 | bios_guard = true; 62 | this.hpet = AppFlag.GetVariable("c69_bios_hpet"); 63 | } 64 | /// 65 | /// read 64 bit data from internal bios memory 66 | /// 67 | public override ulong read(long address) 68 | { 69 | var (u1, u2) = new d8u((byte) address); 70 | return (u1, _bus.State.southFlag) switch 71 | { 72 | (0x0, _) => i64 | unchecked((int) Ticks), 73 | (0x1, _) => i64 | (hpet ? 0x1 : 0x0), 74 | (0x2, _) => i64 | _bus.State.memoryChannel, 75 | (0xF, true) => mem[u2], 76 | _ => throw ThrowMemoryRead(_bus.State.curAddr, address) 77 | }; 78 | } 79 | /// 80 | /// write 64bit data to internal bios memory 81 | /// 82 | public override void write(long address, ulong data) 83 | { 84 | var (adr, u2) = new d8u((byte)address); 85 | _ = (adr, bios_guard, _bus.State.southFlag) switch { 86 | (0x1, _, _) => X(() => hpet = data == 0x1), 87 | (0xA, _, _) => X(warmUp), 88 | (0xC, true, false) => X(clearRAM), 89 | (0xD, _, _) => X(() => Thread.Sleep((int)data)), 90 | (0xF, _, true) => X(() => mem[u2] = data), 91 | _ => X(() => ThrowMemoryWrite(_bus.State.curAddr, address)) 92 | }; 93 | } 94 | /// 95 | /// clear memory in default slot 96 | /// 97 | private void clearRAM() 98 | { 99 | if(_bus.find(0x0) is Memory slot) 100 | Array.Fill(slot.mem, 0UL); 101 | } 102 | /// 103 | /// Shutdown system 104 | /// 105 | public override void shutdown() 106 | { 107 | systemTimer.Stop(); 108 | var line = $" VM is stopped, total operating time: {systemTimer.Elapsed:g} "; 109 | 110 | var len = $"|{new string('-', line.Length)}|".Length; 111 | Console.SetCursorPosition((Console.WindowWidth - len) / 2, Console.CursorTop); 112 | Console.WriteLine($"|{new string('-', line.Length)}|".PastelBg(Color.DarkRed)); 113 | Console.SetCursorPosition((Console.WindowWidth - len) / 2, Console.CursorTop); 114 | Console.WriteLine($"|{line}|".PastelBg(Color.DarkRed)); 115 | Console.SetCursorPosition((Console.WindowWidth - len) / 2, Console.CursorTop); 116 | Console.WriteLine($"|{new string('-', line.Length)}|".PastelBg(Color.DarkRed)); 117 | } 118 | 119 | public int X(Action _) // the fuck 120 | { 121 | _(); 122 | return 0; 123 | } 124 | /// 125 | /// warm up system 126 | /// 127 | public override void warmUp() 128 | { 129 | systemTimer = Stopwatch.StartNew(); 130 | startTime = DateTime.UtcNow; 131 | } 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /vm/csharp/component/Bus.cs: -------------------------------------------------------------------------------- 1 | namespace vm.component 2 | { 3 | using System.Collections.Generic; 4 | using System.Diagnostics; 5 | using System.Linq; 6 | using Ancient.ProjectSystem; 7 | using ancient.runtime; 8 | using ancient.runtime.@base; 9 | using MoreLinq; 10 | 11 | public class Bus : IBus 12 | { 13 | public State State { get; set; } 14 | public CPU cpu { get; } 15 | public DeviceScheme scheme { get; } 16 | 17 | public Debugger debugger { get; set; } = Debugger.Default; 18 | 19 | public List Devices = new List(16); 20 | 21 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 22 | public bool WarmUpDevices { get; set; } = AppFlag.GetVariable("VM_WARMUP_DEV", true); 23 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 24 | public bool ShutdownDevices { get; set; } = AppFlag.GetVariable("VM_SHUTDOWN_DEV", true); 25 | 26 | public Bus() 27 | { 28 | State = new State(this); 29 | cpu = new CPU(this); 30 | 31 | scheme = DeviceScheme.Default; 32 | 33 | Add(new BIOS(this)); 34 | Add(new Memory(0x0, 0x90000, this)); 35 | } 36 | 37 | public void Add(IDevice device) 38 | { 39 | device.startAddress = scheme.getOffsetByDevice(device.name, device.startAddress); 40 | 41 | if (Devices.FirstOrDefault(x => x.startAddress == device.startAddress) != null) 42 | { 43 | cpu.halt(0x4, $"<0x{device.startAddress:X}>"); 44 | return; 45 | } 46 | Devices.Add(device); 47 | Devices.Sort(); 48 | device.assignBus(this); 49 | if(WarmUpDevices) device.warmUp(); 50 | } 51 | 52 | public IDevice find(int address) 53 | => Devices.FirstOrDefault(x => x.startAddress == address) 54 | ?? new CorruptedDevice(cpu); 55 | internal void AttachDebugger(Debugger dbg) => this.debugger = dbg; 56 | 57 | public void Unload() 58 | { 59 | if(ShutdownDevices) 60 | Devices.Pipe(x => x.shutdown()).Consume(); 61 | } 62 | 63 | public override string ToString() => $"bus [{Devices.Count:00}/{Devices.Capacity:00}]"; 64 | } 65 | } -------------------------------------------------------------------------------- /vm/csharp/component/CPU.cs: -------------------------------------------------------------------------------- 1 | namespace vm.component 2 | { 3 | using System; 4 | using System.Diagnostics; 5 | using System.Linq; 6 | using System.Text; 7 | using ancient.runtime; 8 | using MoreLinq; 9 | using static System.Console; 10 | 11 | public class CPU : IHalter 12 | { 13 | private Bus _bus { get; } 14 | 15 | public CPU(Bus bus) => _bus = bus; 16 | 17 | public State State => _bus.State; 18 | 19 | public event Action OnError; 20 | 21 | public void Step() 22 | { 23 | try 24 | { 25 | State.Accept(State.fetch()); 26 | State.Eval(); 27 | } 28 | catch (Exception e) 29 | { 30 | OnError?.Invoke(e); 31 | halt(0xFFFF, e.Message.ToLowerInvariant()); 32 | if(State.ec) 33 | WriteLine(e.ToString()); 34 | Trace.TraceError(e.ToString()); 35 | } 36 | } 37 | 38 | 39 | public void Step(ulong address) 40 | { 41 | State.Accept(address); 42 | State.Eval(); 43 | } 44 | 45 | public int halt(int reason, string text = "") 46 | { 47 | if (State.halt != 0) return reason; 48 | Error(Environment.NewLine); 49 | _bus.State.halt = 1; 50 | Error(AssociationHaltCode(reason, text)); 51 | var l1 = _bus.State; 52 | Error($"L1 Cache, PC: 0x{l1.pc:X8}, OpCode: {l1.iid} [{l1.iid.getInstruction()}]"); 53 | Error($"\t0x{l1.r1:X} 0x{l1.r2:X} 0x{l1.r3:X} 0x{l1.u1:X} 0x{l1.u2:X} 0x{l1.x1:X} 0x{l1.x2:X}"); 54 | return reason; 55 | } 56 | 57 | public static string AssociationHaltCode(int reason, string text) => reason switch 58 | { 59 | 0x0 => $"Power off", 60 | 0x1 => $"Bootable sector not found.", 61 | 0x2 => $"Reaching step limit exception.", 62 | 0x4 => $"Bus offset conflict. {text}", 63 | 0xC => $"Divide by zero - YOU JUST CREATED A BLACK HOLE!", 64 | 0xF => $"Corrupted memory.", 65 | 0xA1 => $"Overflow exception.", 66 | 0xA2 => $"Overflow stack exception.", 67 | 0xA3 => $"Low stack exception.", 68 | 0xFC => $"Invalid Opcode.", 69 | 0xA9 => $"x87 float exception", 70 | 0xBD => $"Overflow heap memory exception", 71 | 0xD6 => $"x9 segmentation fault", 72 | 0xD7 => $"decompose opcode mode fault", 73 | 0xD8 => $"Overflow argument opcode", 74 | 0x77 => $"Unexpected end of executable memory", 75 | 0xA18 => $"Signature fault, method '{text}' not found", 76 | 0xA19 => $"Signature fault, method '{text}' not valid", 77 | 0xA1A => $"Signature fault, method '{text}' not static", 78 | 0xA1B => $"Signature fault, method '{text}' access denied", 79 | 0xDE3 => $"Memory manage fault, {text}", 80 | 0xA22 => $"Signature fault, '{text}'", 81 | 0xFFFF => $"Shift fault, {text}", 82 | _ => $"Unknown state 0x{reason:X}", 83 | }; 84 | 85 | public string getStateOfCPU() 86 | { 87 | var str = new StringBuilder(); 88 | var l1 = _bus.State; 89 | 90 | str.AppendLine($"L1 Cache, PC: 0x{l1.pc:X8}, OpCode: {l1.iid} [{l1.iid.getInstruction()}]"); 91 | str.AppendLine($"\t0x{l1.r1:X} 0x{l1.r2:X} 0x{l1.r3:X} 0x{l1.u1:X} 0x{l1.u2:X} 0x{l1.x1:X} 0x{l1.x2:X}"); 92 | 93 | str.AppendLine("Table of memory:"); 94 | 95 | foreach (var v in _bus.State.mem.Batch(4).Select(x => x.ToArray())) 96 | str.AppendLine($"\t 0x{v[0]:X4},0x{v[1]:X4},0x{v[2]:X4},0x{v[3]:X4}"); 97 | 98 | str.AppendLine(); 99 | 100 | str.AppendLine("bus:"); 101 | 102 | foreach (var v in _bus.Devices) 103 | str.AppendLine($"\tDevice: {v.name}, 0x{v.startAddress:X8}"); 104 | 105 | str.AppendLine(); 106 | 107 | 108 | return str.ToString(); 109 | } 110 | private void Error(string str) 111 | { 112 | Trace.TraceError(str); 113 | ForegroundColor = ConsoleColor.Red; 114 | WriteLine(str); 115 | ForegroundColor = ConsoleColor.White; 116 | } 117 | 118 | public override string ToString() 119 | { 120 | var haltText = State.halt != 0 ? "OFF" : "ON"; 121 | return $"cpu [{haltText} - {State.step} ticks]"; 122 | } 123 | } 124 | } -------------------------------------------------------------------------------- /vm/csharp/component/InternalVMFunctions.cs: -------------------------------------------------------------------------------- 1 | namespace vm.component 2 | { 3 | using System.Text; 4 | using ancient.runtime.emit.sys; 5 | using static System.Console; 6 | 7 | public static class InternalVMFunctions 8 | { 9 | private static Bus _bus { get; set; } 10 | 11 | 12 | public static void Boot(Bus bus) 13 | { 14 | _bus = bus; 15 | Module.Context.Add("sys->DumpCallStack()", typeof(InternalVMFunctions).GetMethod("DumpCallStack")); 16 | } 17 | 18 | 19 | 20 | public static void DumpCallStack() 21 | { 22 | var callStack = _bus.State.CallStack; 23 | var frames = callStack.GetFrames(); 24 | var text = new StringBuilder(); 25 | 26 | foreach (var frame in frames) 27 | WriteLine($"at {frame}"); 28 | 29 | WriteLine(text.ToString()); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /vm/csharp/component/Memory.cs: -------------------------------------------------------------------------------- 1 | namespace vm.component 2 | { 3 | using System; 4 | using System.Diagnostics; 5 | using System.Linq; 6 | using ancient.runtime; 7 | using JetBrains.Annotations; 8 | using MoreLinq; 9 | 10 | 11 | // TODO add more memory range 12 | [DebuggerTypeProxy(typeof(MemoryView))] 13 | public class Memory : Device 14 | { 15 | private readonly CPU _cpu; 16 | internal readonly ulong[] mem; 17 | 18 | public Memory(int startAddress, int endAddress, Bus bus) : base(0x0, "") 19 | { 20 | _cpu = bus.cpu; 21 | // 512kb max 22 | if (endAddress >= 0x100000) 23 | _cpu.halt(0xBD); 24 | mem = new ulong[endAddress - startAddress + 1]; 25 | } 26 | 27 | 28 | public override void write(long address, ulong data) 29 | { 30 | if (address > 0x900 && read(0x899) < (ulong)address) 31 | write(0x899, address); 32 | 33 | if (address >= mem.Length) 34 | { 35 | _cpu.halt(0xBD); 36 | return; 37 | } 38 | mem[address] = data; 39 | } 40 | public override ulong read(long address) 41 | { 42 | if (address < mem.Length) 43 | return mem[address]; 44 | _cpu.halt(0xBD); 45 | return 0; 46 | } 47 | 48 | public void load(byte[] binary, int memOffset, int maxLen) 49 | { 50 | if (binary.Length % sizeof(long) != 0) 51 | _cpu.halt(0xD6); 52 | var bin = binary.Batch(sizeof(long)).Select(x => BitConverter.ToInt64(x.ToArray())).Reverse().ToArray(); 53 | Array.Copy(bin, 0, mem, memOffset, maxLen); 54 | } 55 | 56 | [UsedImplicitly] 57 | internal class MemoryView 58 | { 59 | private readonly Memory obj_ref; 60 | 61 | public MemoryView(Memory @ref) => obj_ref = @ref; 62 | 63 | 64 | public ulong[] all => obj_ref.mem; 65 | public ulong[] execute => obj_ref.mem.Select((i, z) => (i, z)).SkipWhile(x => x.z != 0x600).Select(x => x.i).ToArray(); 66 | public ulong execute_len => obj_ref.mem[0x599]; 67 | public ulong[] bios => obj_ref.mem.Select((i, z) => (i, z)).SkipWhile(x => x.z != 0x300).Select(x => x.i).ToArray(); 68 | public ulong[] stack => obj_ref.mem.Select((i, z) => (i, z)).SkipWhile(x => x.z != 0x100).Select(x => x.i).ToArray(); 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /vm/csharp/component/RangeEx.cs: -------------------------------------------------------------------------------- 1 | namespace vm.component 2 | { 3 | using System; 4 | 5 | public static class RangeEx 6 | { 7 | public static bool In(this Range from, int to) 8 | => from.Start.Value <= to && from.End.Value >= to; 9 | public static bool In(this ushort from, Range to) 10 | => to.Start.Value <= from && to.End.Value >= from; 11 | } 12 | } -------------------------------------------------------------------------------- /vm/csharp/component/Stack.cs: -------------------------------------------------------------------------------- 1 | namespace vm.component 2 | { 3 | using System.Collections.Generic; 4 | public sealed class Stack 5 | { 6 | internal IHalter __halter; 7 | 8 | private readonly Bus _bus; 9 | private IHalter _cpuHalter => __halter ?? _bus.cpu; 10 | private State _provider => _bus.State; 11 | public Stack(Bus bus) => _bus = bus; 12 | 13 | internal readonly Stack cells = new Stack(); 14 | 15 | 16 | public void push(ulong data) 17 | { 18 | if (_provider.SP >= 0x400) 19 | _cpuHalter.halt(0xA2); 20 | 21 | if (_provider.southFlag && _bus.find(0x45).read(0xF3) == 0x1) 22 | { 23 | _bus.find(0x0).write( _provider.SP + 0x100, data); 24 | _provider.SP++; 25 | return; 26 | } 27 | if (_provider.southFlag && _bus.find(0x45).read(0xF2) == 0x1) 28 | { 29 | cells.Push(data); 30 | _provider.SP++; 31 | return; 32 | } 33 | push16(data); 34 | } 35 | 36 | internal void push2(ulong data) 37 | { 38 | if (_provider.SP >= 0x400) 39 | _cpuHalter.halt(0xA2); 40 | data &= 0xFF; 41 | _provider.SP++; 42 | _bus.find(0x0).write(_provider.SP + 0x100, data); 43 | } 44 | internal void push4(ulong data) 45 | { 46 | push2((data >> 8) & 0xff); 47 | push2(data & 0xff); 48 | } 49 | internal void push8(ulong data) 50 | { 51 | push4((data >> 16) & 0xffff); 52 | push4(data & 0xffff); 53 | } 54 | internal void push16(ulong data) 55 | { 56 | push8((data >> 32) & 0xffff_ffff); 57 | push8(data & 0xffff_ffff); 58 | } 59 | 60 | public ulong pop() 61 | { 62 | if (_provider.SP <= 0) 63 | _cpuHalter.halt(0xA3); 64 | if (_provider.southFlag && _bus.find(0x45).read(0xF3) == 0x1) 65 | { 66 | _provider.SP--; 67 | return _bus.find(0x0).read(_provider.SP + 0x100); 68 | } 69 | if (_provider.southFlag && _bus.find(0x45).read(0xF2) == 0x1) 70 | { 71 | _provider.SP--; 72 | return cells.Pop(); 73 | } 74 | return pop16(); 75 | } 76 | 77 | internal ulong pop2() 78 | { 79 | if (_provider.SP <= 0) 80 | _cpuHalter.halt(0xA3); 81 | if (_provider.SP >= 0x400) 82 | _cpuHalter.halt(0xA2); 83 | var res = _bus.find(0x0).read(_provider.SP--+ 0x100); 84 | return res; 85 | } 86 | 87 | internal ulong pop4() => pop2() | (pop2() << 8); 88 | internal ulong pop8() => pop4() | (pop4() << 16); 89 | internal ulong pop16() => pop8() | (pop8() << 32); 90 | } 91 | } -------------------------------------------------------------------------------- /vm/csharp/component/interfaces/IHalter.cs: -------------------------------------------------------------------------------- 1 | namespace vm.component 2 | { 3 | public interface IHalter 4 | { 5 | int halt(int reason, string text = ""); 6 | } 7 | } -------------------------------------------------------------------------------- /vm/csharp/tag.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | [assembly: InternalsVisibleTo("acc_test")] 4 | [assembly: InternalsVisibleTo("vm_test")] -------------------------------------------------------------------------------- /vm/csharp/vm.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | osx.10.14-x64; 8 | linux-x64; 9 | linux-arm; 10 | win10-x64; 11 | win10-arm64; 12 | win10-arm; 13 | 14 | 0.70.850 15 | true 16 | Yuuki Wesp (C) 2020 17 | 18 | 19 | 20 | full 21 | true 22 | prompt 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | all 42 | runtime; build; native; contentfiles; analyzers; buildtransitive 43 | 44 | 45 | 46 | true 47 | 48 | 49 | -------------------------------------------------------------------------------- /vm/devices/terminal/TerminalDevice.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using System.Text; 4 | using ancient.runtime; 5 | using static System.Console; 6 | 7 | 8 | [Guid("2F380069-1951-41DF-9500-3FE4610FA924")] 9 | public class TerminalDevice : Device 10 | { 11 | private StringBuilder relMemory = new StringBuilder(); 12 | 13 | public override void shutdown() => relMemory = null; 14 | public TerminalDevice() : base(0x1, "term") { } 15 | 16 | public override void write(long address, long data) 17 | { 18 | switch (address) 19 | { 20 | case 0x5: 21 | var c1 = (char)data; 22 | if(c1 == 0xA) 23 | Write(Environment.NewLine); 24 | else 25 | Write(c1); 26 | break; 27 | case 0x6: 28 | var c2 = (char)data; 29 | if (c2 == 0xA) 30 | relMemory.Append(Environment.NewLine); 31 | else 32 | relMemory.Append(c2); 33 | break; 34 | case 0x7: 35 | Out.Write(relMemory); 36 | break; 37 | case 0x8: 38 | relMemory.Clear(); 39 | break; 40 | case 0x9: 41 | var u1 = ((short)data & 0xF0) >> 4; 42 | var u2 = (short)data & 0xF; 43 | 44 | switch (u1) 45 | { 46 | case 0x1: 47 | ForegroundColor = (ConsoleColor)u2; 48 | break; 49 | case 0x2: 50 | BackgroundColor = (ConsoleColor)u2; 51 | break; 52 | case 0x3: 53 | ForegroundColor = ConsoleColor.White; 54 | break; 55 | case 0x4: 56 | BackgroundColor = ConsoleColor.Black; 57 | break; 58 | } 59 | break; 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /vm/devices/terminal/terminal.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | true 6 | Yuuki Wesp 7 | 0.24 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | --------------------------------------------------------------------------------