Git Product home page Git Product logo

sharplab's Introduction

This repository contains source code for https://sharplab.io.

SharpLab is a .NET code playground that shows intermediate steps and results of code compilation. Some language features are thin wrappers on top of other features -- e.g. using() becomes try/finally. SharpLab allows you to see the code as compiler sees it, and get a better understanding of .NET languages.

Recent versions include experimental support for running code, with some limitations.

Languages

SharpLab supports three source languages:

  1. C#
  2. Visual Basic
  3. F#

Due to complexity of F#'s compiler library, some features might not be available for F#.

Decompilation/Disassembly

There are currently three targets for decompilation/disassembly:

  1. C#
  2. IL
  3. JIT Asm (Native Asm Code)

Note that VB=>C# disassembly shouldn't be used to convert between languages, as the produced code is intentionally overly verbose.

Execution

You can use "Run" target to execute your code and see the output.
Execution enables a few nice features such as flow arrows โ€” see here:
https://twitter.com/ashmind/status/894058159223955456.

Execution is intentionally limited, however the limits are continuously improved and corrected.

Contributing

See CONTRIBUTING.md.

sharplab's People

Contributors

abenimatteo avatar agocke avatar am11 avatar antitcb avatar ashmind avatar controlflow avatar darkbullnull avatar davidwengier avatar dogac00 avatar dpen2000 avatar i3arnon avatar jkim506 avatar jsk95 avatar kkokosa avatar muojp avatar rikkigibson avatar rosenbjerg avatar svick avatar teo-tsirpanis avatar tessenr avatar thomastay avatar tyoverby avatar vbfox avatar yohdeadfall avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sharplab's Issues

Branch 'tuples' is broken

http://tryroslyn.azurewebsites.net/#b:features-tuples/K4Zwlgdg5gBAygTxAFwKYFsDcBYAUAB2ACMAbMAYxnJIEMQQYBhGAbzxg5kNIpgDcA9mAAmMALIAKAJSt2nAL555QA==


(,,,): error : An error occurred when trying to create a controller of type 'RoslynController'. Make sure that the controller has a parameterless public constructor.
 at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
 at System.Web.Http.Tracing.Tracers.HttpControllerActivatorTracer.<>c__DisplayClass2.<System.Web.Http.Dispatcher.IHttpControllerActivator.Create>b__0()
 at System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEnd(ITraceWriter traceWriter, HttpRequestMessage request, String category, TraceLevel level, String operatorName, String operationName, Action`1 beginTrace, Action execute, Action`1 endTrace, Action`1 errorTrace)
 at System.Web.Http.Tracing.Tracers.HttpControllerActivatorTracer.System.Web.Http.Dispatcher.IHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
 at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request)
 at System.Web.Http.Tracing.Tracers.HttpControllerDescriptorTracer.<>c__DisplayClass2.<CreateController>b__0()
 at System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEnd(ITraceWriter traceWriter, HttpRequestMessage request, String category, TraceLevel level, String operatorName, String operationName, Action`1 beginTrace, Action execute, Action`1 endTrace, Action`1 errorTrace)
 at System.Web.Http.Tracing.Tracers.HttpControllerDescriptorTracer.CreateController(HttpRequestMessage request)
 at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()

Probably related to #24.

Error when trying to compile using master

When compiling code on Roslyn's master branch, I get the following error:

An error occurred when trying to create a controller of type 'RoslynController'. Make sure that the controller has a parameterless public constructor.
 at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
 at System.Web.Http.Tracing.Tracers.HttpControllerActivatorTracer.<>c__DisplayClass2.<System.Web.Http.Dispatcher.IHttpControllerActivator.Create>b__0()
 at System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEnd(ITraceWriter traceWriter, HttpRequestMessage request, String category, TraceLevel level, String operatorName, String operationName, Action`1 beginTrace, Action execute, Action`1 endTrace, Action`1 errorTrace)
 at System.Web.Http.Tracing.Tracers.HttpControllerActivatorTracer.System.Web.Http.Dispatcher.IHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
 at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request)
 at System.Web.Http.Tracing.Tracers.HttpControllerDescriptorTracer.<>c__DisplayClass2.<CreateController>b__0()
 at System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEnd(ITraceWriter traceWriter, HttpRequestMessage request, String category, TraceLevel level, String operatorName, String operationName, Action`1 beginTrace, Action execute, Action`1 endTrace, Action`1 errorTrace)
 at System.Web.Http.Tracing.Tracers.HttpControllerDescriptorTracer.CreateController(HttpRequestMessage request)
 at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()

Compiling using Release (NuGet) works fine.

Invalid code when decompiling string switch statement

Given program:

using System;
public class C {
    public int M() {

        string n = GetDefault<string>();

        switch(n) {
            case null: return 1;
            case "foo": return 2;
            default: return 3;
        }
    }

    private T GetDefault<T>() {
        return default(T);   
    }
}

decompilation to C# returns:

public class C
{
    public int M()
    {
        string @default = this.GetDefault<string>();
        string text = @default;
        int result;
        if (text != null)
        {
            if (!text == "foo")
            {
                result = 3;
            }
            else
            {
                result = 2;
            }
        }
        else
        {
            result = 1;
        }
        return result;
    }
    private T GetDefault<T>()
    {
        return default(T);
    }
}

Line if (!text == "foo") contains syntax error, it should be decompiled to if (text != "foo") or at least to if(! (text == "foo") ).

Exception message should preserve newlines

When Roslyn throws an exception while compiling some code (for example: dotnet/roslyn#13365), the stack trace of the exception is shown with all its lines mushed together as if it was one line:

It would be better if the newlines in the stack trace were preserved, for example by using the whitespace: pre style:

Allow viewing IL differences between compilers

It would be really interesting to be able to use TryRoslyn to learn about differences in the output IL between Roslyn and the C# 5.0 compiler. This would require allowing the user to choose "IL" on the right-hand instead of Decompiled C#, and allowing the user to choose pre-Roslyn versions of the compiler on the left-hand-side.

Invalid disassembly with primary constructor argument

http://tryroslyn.azurewebsites.net/#A4VwRgNglgxgBDCBDAziuBZAngYWWuAChQBcAnKAOwHM5KkBbAUwEo4BvAKDh7mAoBuSEkzikKNOoyYAmOAF4pzANycAvkAA

Given

public class MyClass (string name) {
    private string name2 = name;
}

Getting

using System;
using System.Reflection;
using System.Runtime.CompilerServices;
[assembly: AssemblyVersion("0.0.0.0")]
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
public class MyClass
{
    private string name2 = name;
    public MyClass(string name)
    {
    }
}

Build fails to git pull (no git user detected)

[07/04/2015 07:30:49 > 95cf44: INFO] Syncing D:\home\site\!roslyn-sources\core-clr
[07/04/2015 07:30:51 > 95cf44: ERR ] From https://github.com/dotnet/roslyn
[07/04/2015 07:30:51 > 95cf44: ERR ]  * branch            core-clr   -> FETCH_HEAD
[07/04/2015 07:31:13 > 95cf44: ERR ] 
[07/04/2015 07:31:13 > 95cf44: ERR ] *** Please tell me who you are.
[07/04/2015 07:31:13 > 95cf44: ERR ] 
[07/04/2015 07:31:13 > 95cf44: ERR ] Run
[07/04/2015 07:31:13 > 95cf44: ERR ] 
[07/04/2015 07:31:13 > 95cf44: ERR ]   git config --global user.email "[email protected]"
[07/04/2015 07:31:13 > 95cf44: ERR ]   git config --global user.name "Your Name"
[07/04/2015 07:31:14 > 95cf44: ERR ] 
[07/04/2015 07:31:14 > 95cf44: ERR ] to set your account's default identity.
[07/04/2015 07:31:14 > 95cf44: INFO] Building D:\home\site\!roslyn-sources\core-clr
[07/04/2015 07:31:14 > 95cf44: ERR ] Omit --global to set the identity only in this repository.
[07/04/2015 07:31:14 > 95cf44: ERR ] 
[07/04/2015 07:31:14 > 95cf44: ERR ] fatal: unable to auto-detect email address (got 'tryroslyn@XXXXXXXXXXXXXXX.(none)')

(XXX above masks some id, not sure of security implications of sharing it)

VB.NET missing Microsoft.VisualBasic.dll reference

module M
  ' ...
end module

Do not compiles because of:

error BC35000: Requested operation is not available because the runtime library function 'Microsoft.VisualBasic.CompilerServices.StandardModuleAttribute..ctor' is not defined.

VB.NET support

Looks not so hard to support :)
Also ILSpy supports decompilation to VB, but produced code just sucks a lot...

features/extensionEverything branch throws exception for the default code

With the default code in the left pane, the features/extensionEverything branch fails with this exception. Whether this is a fault with this or with that branch I'm not sure.

An error occurred when trying to create a controller of type 'RoslynController'. Make sure that the controller has a parameterless public constructor.
   at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
   at System.Web.Http.Tracing.Tracers.HttpControllerActivatorTracer.<>c__DisplayClass2.<System.Web.Http.Dispatcher.IHttpControllerActivator.Create>b__0()
   at System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEnd(ITraceWriter traceWriter, HttpRequestMessage request, String category, TraceLevel level, String operatorName, String operationName, Action`1 beginTrace, Action execute, Action`1 endTrace, Action`1 errorTrace)
   at System.Web.Http.Tracing.Tracers.HttpControllerActivatorTracer.System.Web.Http.Dispatcher.IHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
   at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request)
   at System.Web.Http.Tracing.Tracers.HttpControllerDescriptorTracer.<>c__DisplayClass2.<CreateController>b__0()
   at System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEnd(ITraceWriter traceWriter, HttpRequestMessage request, String category, TraceLevel level, String operatorName, String operationName, Action`1 beginTrace, Action execute, Action`1 endTrace, Action`1 errorTrace)
   at System.Web.Http.Tracing.Tracers.HttpControllerDescriptorTracer.CreateController(HttpRequestMessage request)
   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()

Release mode has no effect

See for example this. Lots of NOP instructions in the generated IL and there is no difference when choosing Debug or Release.

Please add new C#7 features support

Roslyn updated with support for code like this:

using System;
public class C {
    public ref int M() {
        int [] numbers = { 0b1, 0b0___01 };
        return ref numbers;
    }
}

(released in April)

Please add its support to TryRoslyn.

Navigate to bookmark when already on site fails

When already on the site, if I try to navigate to a saved bookmark, the browser's location bar is updated, but the contents aren't - I have to open each bookmark in a new tab to get the right contents. However, if I hit enter on the changed location bar, the contents are updated.

abspos change in flex spec breaks header

Hey @ashmind,

The header breaks due to the update in the flex spec. This can currently be seen in Project Spartan and Mozilla and Google are currently updating their behavior to match. On twitter you requested screensize, this is on 1920 x 1080. Let me know if you have any questions. Thanks!!
abspos-flex

Lambda not called in array initialisation

Putting the following input in the standard C class/M method

Func<int, int> getInt = s => s;
var list = new [] { 1, 2, 3, getInt(1) };
Console.WriteLine(list[3]);

results in decompiled C# output containing

int[] array = new int[] {
    1,
    2,
    3,
    0
};
Console.WriteLine(array[3]);

in debug mode and

Console.WriteLine(new int[] {
    1,
    2,
    3,
    0
}[3]);

in release mode. The IL output looks like it does show a lambda call.

Invalid decopmilation

using System;
public class Point(int x)
{
    public int X { get; } = x;
    public int M(Point p) 
    {
        return (p?.X).GetValueOrDefault();
    }
}

is decompiled to

using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
[assembly: AssemblyVersion("0.0.0.0")]
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[module: UnverifiableCode]
public class Point
{
    [CompilerGenerated]
    private readonly int <X>k__BackingField;
    public int X
    {
        [CompilerGenerated]
        get
        {
            return this.<X>k__BackingField;
        }
    }
    public Point(int x)
    {
        this.<X>k__BackingField = x;
        base(); // This is not valid C#, but it represents the IL correctly.

    }
    public int M(Point p)
    {
        return p != null ? new int?(p.X) : null.GetValueOrDefault();
    }
}

Should be

return (p != null ? new int?(p.X) : null).GetValueOrDefault();

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.