Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Algol68
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C with Coccinelle
C++ with Coccinelle
C++ (Circle)
CIRCT
Clean
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
GLSL
Go
Haskell
HLSL
Hook
Hylo
IL
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Mojo
Nim
Numba
Nix
Objective-C
Objective-C++
OCaml
Odin
OpenCL C
Pascal
Pony
PTX
Python
Racket
Raku
Ruby
Rust
Sail
Snowball
Scala
Slang
Solidity
Spice
SPIR-V
Swift
LLVM TableGen
Toit
Triton
TypeScript Native
V
Vala
Visual Basic
Vyper
WASM
Zig
Javascript
GIMPLE
Ygen
sway
csharp source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
.NET (main)
.NET (main) CoreCLR
.NET (main) Crossgen2
.NET (main) ILDasm
.NET (main) ILSpy
.NET (main) Mono
.NET (main) NativeAOT
.NET 6.0 CoreCLR
.NET 6.0 Crossgen2
.NET 6.0 ILDasm
.NET 6.0 ILSpy
.NET 6.0 Mono
.NET 6.0.110
.NET 6.0.113
.NET 6.0.116
.NET 7.0 CoreCLR
.NET 7.0 Crossgen2
.NET 7.0 ILDasm
.NET 7.0 ILSpy
.NET 7.0 Mono
.NET 7.0.100
.NET 7.0.102
.NET 7.0.105
.NET 8.0 CoreCLR
.NET 8.0 Crossgen2
.NET 8.0 ILDasm
.NET 8.0 ILSpy
.NET 8.0 Mono
.NET 9.0 CoreCLR
.NET 9.0 Crossgen2
.NET 9.0 ILDasm
.NET 9.0 ILSpy
.NET 9.0 Mono
Options
Source code
using System; using System.Numerics; using System.IO; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using CompilerExplorer; interface IHex { abstract static int Value { get; } } interface INum<T> { abstract static T Value { get; } } struct Hex0 : IHex { public static int Value => 0; } struct Hex1 : IHex { public static int Value => 1; } struct Hex2 : IHex { public static int Value => 2; } struct Hex3 : IHex { public static int Value => 3; } struct Hex4 : IHex { public static int Value => 4; } struct Hex5 : IHex { public static int Value => 5; } struct Hex6 : IHex { public static int Value => 6; } struct Hex7 : IHex { public static int Value => 7; } struct Hex8 : IHex { public static int Value => 8; } struct Hex9 : IHex { public static int Value => 9; } struct HexA : IHex { public static int Value => 10; } struct HexB : IHex { public static int Value => 11; } struct HexC : IHex { public static int Value => 12; } struct HexD : IHex { public static int Value => 13; } struct HexE : IHex { public static int Value => 14; } struct HexF : IHex { public static int Value => 15; } struct Int<H7, H6, H5, H4, H3, H2, H1, H0> : INum<int> where H7 : IHex where H6 : IHex where H5 : IHex where H4 : IHex where H3 : IHex where H2 : IHex where H1 : IHex where H0 : IHex { public static int Value { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => H7.Value << 28 | H6.Value << 24 | H5.Value << 20 | H4.Value << 16 | H3.Value << 12 | H2.Value << 8 | H1.Value << 4 | H0.Value; } } interface IOp { abstract static int Run(int address, Span<byte> memory, Stream input, Stream output); } struct Stop : IOp { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Run(int address, Span<byte> memory, Stream input, Stream output) { return address; } } struct Loop<Body, Next> : IOp where Body : IOp where Next : IOp { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Run(int address, Span<byte> memory, Stream input, Stream output) { while (memory.UnsafeAt(address) != 0) { address = Body.Run(address, memory, input, output); } return Next.Run(address, memory, input, output); } } struct AddPointer<Offset, Next> : IOp where Offset : INum<int> where Next : IOp { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Run(int address, Span<byte> memory, Stream input, Stream output) { return Next.Run(address + Offset.Value, memory, input, output); } } [GenericArguments( typeof(Int<Hex0, Hex0, Hex0, Hex0, Hex0, Hex0, Hex3, Hex1>), typeof(AddPointer<Int<Hex0, Hex0, Hex0, Hex0, Hex0, Hex0, Hex0, Hex1>, AddData<Int<Hex0, Hex0, Hex0, Hex0, Hex0, Hex0, Hex3, Hex2>, AddPointer<Int<Hex0, Hex0, Hex0, Hex0, Hex0, Hex0, Hex0, Hex1>, AddData<Int<Hex0, Hex0, Hex0, Hex0, Hex0, Hex0, Hex3, Hex3>, AddPointer<Int<HexF, HexF, HexF, HexF, HexF, HexF, HexF, HexE>, OutputData<AddPointer<Int<Hex0, Hex0, Hex0, Hex0, Hex0, Hex0, Hex0, Hex1>, OutputData<AddPointer<Int<Hex0, Hex0, Hex0, Hex0, Hex0, Hex0, Hex0, Hex1>, OutputData<Stop>>>>>>>>>>) )] struct AddData<Data, Next> : IOp where Data : INum<int> where Next : IOp { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Run(int address, Span<byte> memory, Stream input, Stream output) { memory.UnsafeAt(address) += (byte)Data.Value; return Next.Run(address, memory, input, output); } } struct OutputData<Next> : IOp where Next : IOp { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Run(int address, Span<byte> memory, Stream input, Stream output) { output.WriteByte(memory.UnsafeAt(address)); return Next.Run(address, memory, input, output); } } struct InputData<Next> : IOp where Next : IOp { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Run(int address, Span<byte> memory, Stream input, Stream output) { var data = input.ReadByte(); if (data == -1) { return address; } memory.UnsafeAt(address) = (byte)data; return Next.Run(address, memory, input, output); } } static class SpanExtensions { internal static ref T UnsafeAt<T>(this Span<T> span, int address) { return ref Unsafe.Add(ref MemoryMarshal.GetReference(span), address); } }
Become a Patron
Sponsor on GitHub
Donate via PayPal
Compiler Explorer Shop
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
CE on Bluesky
Statistics
Changelog
Version tree