Code Monkey home page Code Monkey logo

cs2x's Introduction

NOTE: IL2X is being re-investigated for CPU targets

https://github.com/reignstudios/IL2X
This would end up making CS2X mostly for GPU targets.

CS2X (Under development)

Transpiles a C# subset to non .NET languages, platforms, runtimes and enviroments. (Powered by Roslyn)

CS2X is activily being tested in the development of the Orbital-Framework:
https://github.com/reignstudios/Orbital-Framework
This provides real-world tests and as things progress more features will tested and supported here.

WASM Demo

Renders a 1280x720 image then prints how long it took in seconds.
http://reign-studios.com/wasm/cs2x/ray-trace-benchmark/cs2x.html

Goals

This project will focus on transpiling a C# subset with a modified type system for writing CPU and GPU programs.

  • Custom Standard lib(s) for various targets.
  • Documentation

CPU targets

  • C89
    • Native C performance
    • C89: modern, legacy and embedded platforms (x86, MIPS, SPARC, RISC-V, PPC, M68K, AVR, etc)
    • CC65: 6502 platforms (Atari, C64, NES, Apple II, etc)
    • SDCC: Many targets (ColecoVision, ZX Spectrum, etc)
    • z88dk: Z80 platforms
  • LLVM
  • LLVM IR => Assembly: CP1610 (Intellivision)
  • LLVM IR => Assembly: Intel 8048 (Magnavox Odyssey 2)
  • LLVM IR => Retarget: Custom assembly targets (FPGA CPU, 16bit bytes, etc)
  • Java
  • Kotlin
  • javaScript
  • Python
  • ActionScript

GPU targets

  • HLSL (DirectX Shader Assembly Language) [D3D9.0c +]
  • ALS (DirectX Shader Assembly Language) [D3D8.0 - D3D9.0c]
  • GLSL (OpenGL shading language) [OpenGL2.0 / GLES2 +]
  • ARB (ARB assembly language) [legacy / homebrew systems]
  • CG (Cg programming language) [PSVita, Nvidia / other]
  • PSSL (PlayStation Shader Language) [PS4]
  • MSL (Metal Shading Language) [macOS / iOS]
  • AGAL (Adobe Graphics Assembly Language)
  • Custom: Plugin system

Primary Project libraries

  • CS2X.Core: .NET transpiler lib
  • CS2X.CLI: CLI interface for CS2X.Core
  • CS2X.Analyzer: C# syntax analyzer to limit unsuported features.
  • CS2X.CoreLib: Portable CoreLib subset

How does it basically work?

  • C89
    • Each executable gets built to a single '.c' source file including all dependencies.
    • String literals on embedded devices, cartridges, etc can be stored in program memory / ROM to save ram.
    • All GC methods are agnostic allowing any built-in or custom GC backend.
  • Other: TODO

Performance

Almost zero performance loss. C# code will generate in a manner as if hand written in the target language in many respects. There are a couple key differences in the CS2X runtime / type system vs .NET CLR

  • Structs are not part of the object system as they are in the .NET runtime.
    • No auto boxing for value types are supported (.NET has many easy to fall in syntax performance pitfalls here).
    • System.Object can never equal a 'struct', 'enum' or 'primitive' type.
    • Virtuals like 'MyStruct.GetType()' or 'MyEnum.GetType()' give compile time errors (use typeof instead).
    • Cannot bind a delegate to a structs non-static method.
  • Interfaces are considered 'type-classes' and are compile time only.
    • Used for generics or general code consistency.
    • No casting to them or variable declarations of them.
  • No up-casting performance loss in C and down-casting checks can be disabled for C output.
  • Auto-Marshalling of managed types not supported.
    • Varies to much between platforms in contrast to .NET making writing portable code confusing.
    • Auto string marshalling has way to many implicits that depend on to many factors to keep track of.
    • Redundant allocations. If you want to pass the same string multiple times in multiple methods for example auto-marshaling it everytime doesn't make sense. Its far better to be explicit here and make that obvious by pre-marshalling the type once.
    • Portability. Forcing PInvokes to be used this way ensures code functions the same in all runtimes.

Building

  • Prerequisites
    • Visual Studios 2019 (VS for Mac / MonoDevelop or VSCode have not yet been tested)
    • .NET Core 5
    • .NET Compiler Platform SDK
  • Run: CS2X.Core.Test proj in VS. This will build "PortableTestApp.csproj" to "TestOutput" folder
  • NOTE: Early stages so nothing else is supported yet.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.