GithubHelp home page GithubHelp logo

derivcoipswich / dsharp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nikhilk/scriptsharp

20.0 20.0 13.0 22.83 MB

A fork of the Script# project.

Home Page: http://www.derivco.co.uk

License: Other

C# 91.74% JavaScript 5.18% CSS 0.12% HTML 2.77% Batchfile 0.04% PowerShell 0.16%

dsharp's People

Contributors

adrianodfo avatar andekande avatar aschoenebeck avatar charlisi avatar donluispanis avatar fred-perkins avatar fredriknils avatar heyarnold7 avatar igochkov avatar isc30 avatar jamescourtney avatar jimmygilles avatar kevreed avatar markstega avatar martinnormark avatar mattclay avatar mattjphillips avatar michaelaird avatar mkillgallon avatar mwe avatar nikhilk avatar prodigysim avatar robitar avatar rsking avatar sgnurf avatar strygo avatar talshani avatar theoutlander avatar vfleitao avatar zacharyj avatar

Stargazers

 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

dsharp's Issues

Add Support for VS2015

Support for VS2015 is required to ensure the latest tooling can be used with DSharp. Features like Static CodeAnalysis can be utilised once this is complete.

ICollection.CopyTo

Support for

void CopyTo(T[] array, int arrayIndex)

since the CLR version requires you to implement it. Also part of Array, etc

Add default comparer methods for Date & RegExp

When comparing Date objects which are constructed the same, we are returned with false.

var date1 = new Date(1);
var date2 = new Date(1);

date1 === date2 //returns false
date1 == date2 //returns false
date1.valueOf() == date2.valueOf() //returns true

The same occurs for RegExp, however value of comparisons fail and only the toString method returns true.

Basic methods are required in the core script to compare these reference types

Add Type Info for Primitives

All system primitives are missing type information about if a value is of type Int32 or Int64 etc.

  • UInt16
  • UInt32
  • UInt64
  • Int16
  • Int32
  • Int64
  • Boolean
  • Decimal
  • Double
  • Float

Add Support for Constructor Property Initialisation

It would be ideal to use a property initialiser with a constructor like so:

public class Person
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string GetFullName()
    {
        return FirstName + " " + LastName;
    }
}

//usage
new Person
{
    FirstName = "Fred",
    LastName = "Perkins"
}

This could be achieved like the following:

function Person(firstName, lastName){
    this.firstName = firstName || "";
    this.lastName = lastName || "";
}
Person.prototype.GetFullName = function(){
    return this.firstName + " " + this.lastName;
}

function initialiseProperties(object, properties){
    if(!object || !properties){
        return object;
    }

    for(var key in properties){
        Object.defineProperty(object, key, { value: properties[key]});
    }

    return object;
}   

whereby you could call the following:

initialiseProperties(new Person(), { firstName: "Fred", lastName: "Perkins"});

which would return a new object with those properties initialised correctly.

Look into Templating Attribute

It would be ideal to add a new script template attribute which can be applied to any emit-able code. The purpose of this is so that you can easily define a method call or variable easily within the context of a specific scope.
You should be able to use the 'this' reference appropriately to pass itself into method calls.
An example of how this could look:

[ScriptTemplate("ss.localMethod({this}, {value})"]
public void LocalMethod(string value)
{
}

this could then be called like the following and emitted correctly:

someObject.LocalMethod("asdasd");

Emits to

   ss.localMethod(someObject, "asdasd");

String.format in generated ss.js is not implemented

We tried to use this to format currency amounts as part of culture support, but it didn't work. So we had to work around and format as number and then replace decimal symbols by currency symbols. It is mostly an issue with cultures as Swedish (sv) where the decimal group separator differs for currency.
Cheers,

Add String Construction support

Currently DSharp doesn't support being able to create a fixed string of characters. E.g:

int len = 4;
string enumeration = new string(len, 'c'); //enumeration = "cccc"

In JavaScript a simple way would be to create an array of empty elements and iterate over the length to create a string of those fixed characters:

var len = 4;
var enumeration = new Array(len + 1).join('c');  //returns "cccc"

Or the new ES6 String repeat could be used with a shim

Implement Multiple constructors

To achieve this we could take an array of available constructors and resolve the function calls based on symbol map with unique names. Each constructor would have the same type metadata attached.

Add support for 'default' keyword

The default keyword can be used outside of a generic context, whereby it will try to return the default value of a value or reference type. Default will also need to support the generics feature as in .Net

Allow inheritance of the Dictionary Type

Currently the Dictionary & Dictionary<T,T> is sealed by the core library.
Exposing this for inheritance would mean we can wrap POCO style objects.
For example

public class PocoType : Dictionary<string, object>
{
    public string GetProp(string key)
    {
        //Code here
    }
}

This would allow aliasing of objects with needing to a using statement - For example with known models.

Normalise Object contract & Add GetHashCode

Need to remove the ToStringLocale as this is non standard.
Add default hashcode method to all defined classes programmatically and allow overrides to return a uint value using a built in hashing mechanism

Implement Native Support for Tasking

Implement TPL style tasking library to create microtasks within ScriptSharp.
The tasking framework should support breaking code into blocks to execute in separate chunks. This means we could perform long running operations over time or on another Thread( Web Worker in JS).

Add support for Extension Methods

To properly support IEnumerable we need a set of basic extension methods which allow us to ToArray, ToList or ToDictionary. This would lead the way to utilize LINQ queries in the future.

Add support for the Yield Keyword in Enumerable statements

Currently yield return as an IEnumerable statement causes a csc error in the base compiler:

"csc.exe" exited with code -2146232797.
@ C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Roslyn\Microsoft.CSharp.Core.targets. Line 84
This happens with the following code:

public IEnumerable<object[]> Data
        {
            get
            {
                yield return new object[] { 1, 2, 3 };
                yield return new object[] { 4, 5, 6 };
            }
        }

Look at updating CultureInfo

CultureInfo is currently quite rigid and doesn't allow us to create cultures at runtime. It should be possible to download a culture file with the core script which allows us to create a culture based on its ISO code.
Also add Serialiser contracts or objects which understand how to create the culture object expected by dsharp

Proper Exceptions

  • Support for Custom Exceptions
  • NetStandard Exceptions
    • NullArgumentException
    • InvalidOperationException
    • (investigate more)

List.Contains uses object instead of T

This is making the CLR fail when using List<T>.Contains(...)

We need to switch from
List<T>.Contains(object item)
to
List<T>.Contains(T item)

This is needed to avoid errors like System.MissingMethodException : Method not found: 'Boolean System.Collections.Generic.List``1.Contains(System.Object)'

ss.Queue Implementation does not remove items after calling .dequeue

The ss.Queue implementation seems to not be cleaning up the items as soon as you a .dequeue

It seems to only clean up when we reach half of the available items.
Ie:
10 items it will do 4 clean ups

  • When we request 5 items it removes the ones already requested (so the list is reduced to 5)
  • We then request 3 items and it reduces the items to 2
  • We request 1 more and the items are now only 1
  • We request again and the queue is cleaned up.

The below snippet shows this issue:
`var queue = new ss.Queue();
queue.enqueue("1");
queue.enqueue("2");
queue.enqueue("3");
queue.enqueue("4");
queue.enqueue("5");
queue.enqueue("6");
queue.enqueue("7");
queue.enqueue("8");
queue.enqueue("9");
queue.enqueue("10");

for(i=0, ln = queue.count; i<ln;i++)
{
(function(num){
window.setTimeout(function(){
console.log(queue.dequeue(););
console.log(queue._items);
}, 10 * i);
})(i);
}`

To be noted that this is a mere internal issue. The items are returned in dequeue are correct.

Optimize Enumerator creation

Currently, enumerate(...) is slow due to the local lookup function.
This can be optimized by applying single responsibility principle: DictionaryEnumerator and ArrayEnumerator. With this structure, enumerate(...) will instantiate an optimized enumerator for each case.

Fix Tests

AMD loader was dropped, resulting on many tests failing. We need to fix all of them again.

To Do

  • Fix all the tests
  • Detect problems regarding global references and replace them with $global

Useful stuff

regex to replace
replace with
in files

define\('test', \['ss'\], function\(ss\) \{[\s\n\r]*var \$global = this;[\n]*
var test = (function($global){\n
**/*Baseline*.txt

\}\);[\r\n]*$(?![\n])
})(self);\n
**/*Baseline*.txt

Investigate Browser Build targets

Look into a flexible system which could be used to generate the required polyfills for DSharp depending on the browser targets specified by the project consuming DSharp. This means you could include specific polyfills for specific browsers through a piece of JSON configuration:

{
    IE: "<10.0+[9.4.1]",
    Chrome: "<38"
}

The string could be an expression compiled by the process which defines simply a range of browser versions with the ability to be generic and add specific overrides.
The compiler would then create the correct Polyfill.js and combine with the ss.js output

Add support for Operator Overloading

All types should allow operator overloading so that casting between types can allow us to call the overloaded operator method.
This could generate exactly like static methods.

Add a default hashing mechanism into the mscorlib

Add a default hashing mechanism so that objects can be used as keys within a dictionary. Doing so would allow you to get the hash code value and turn it into an sting to utilise a browsers built in hashing mechanism. Dictionaries from here on in would automatically call the getHashCode mechanism when trying to store the key in the dictionary.

Add proper support for the Enum type

Compile Enums into a key value pair which is easy to use. The could would output the enum property call which returns a value. For example the following:

DSharp.defineEnum("System", "SomeEnum": {
    Value1: 1,
    Value2: 2
});

Then we should be able to do the following:

var enumValue = System.SomeEnum.Value1;

The core library should expose the same core static methods to resolve type names and values from strings.

Generics Support

Adding support for Generics can be achieved by treating the token "T" or any generic type as the intrinsic type within the compiler.
Support should be added for both Contravariance and Covariance.

RequestIdleCallback signature not supported

The RequestIdleCallback function accepts an optional timeout parameter to specify a deadline for maximum wait period before getting a callback. This is not reflected in the interface implemented by dsharp

Unable to use assign private variable on a static object in a static context

For example:

public class CancellationTokenSource
    {
        private static CancellationTokenSource source;
        private int cancellationState;

        static CancellationTokenSource()
        {
            source = new CancellationTokenSource();
            source.cancellationState = 1;
        }
    }

When attempting to call the following a not supported exception is thrown.
The issue boils down to being unable to get the scope of the static instance in the class correctly so the compiler returns null.
Line 561 in the ExpressionGenerator is throwing the null reference when Debug.Assert is called.

Normalise the String Api

The String api surface from mscorlib doesn't match the BCL's. This should be normalised and several additions added. Currently missing the following:

  • Join
  • Compare
    Then any JavaScript additions can be added as automatic extension methods under the Browser namespace.

Add support for Method Overloading

To achieve method overloading we could store all variations of the symbol in the map. Then when we output the symbol we resolve the required parameters and write the specific method call.
For example:

public  void DoSomething() { DoSomething("SomeValue"); }
public  void DoSomething(string parameter) { //Do some code here }

Could compile down to:

function DoSomething$1(){
    this.DoSomething$2("SomeValue");
}
function DoSomething$2(){
    //Do some code here
}

Implement Method Default parameter values

When specifying an optional or default arguments we can hoist the variable assignment inline into the method. For example the following C#:

public void SomeMethod(object instance = null)
{
    //Method Body here
}

Might translate to the following JavaScript:

function SomeMethod(instance){
    instance = instance || null;
    //Method Body here
}

String.format currency based on CultureInfo provided group size returns wrong string

CultureInfo returns an array specifying number of digits in each group to the left of the decimal in currency values. In en-IN (English -India) culture the returned group size array is {3, 2 , 0}, which should create the first group after 3 digits, next after 2 digits and the rest of the values should'nt be grouped at all.

But string format clips the rest of the string when the group size is 0.

Example 89678145321.00 value should be grouped as 896781,45,321.00 but the actual string we get is
45,321.00

This should be noticeable on any culture which returns a 0 group size in this case it was en-IN

Upgrade Language specification

Currently the compiler is targeting against the ISO C#2 standard. To add new features we need to upgrade the target to a more modern language specification.
Ideally we need to target C#4 and above for additions to the compiler.

It should also be possible to target a modern specification and then add a set of client analysers which report where unsupported features are added

Optimise DSharp Build

In the ScriptSharp.targets the BuildScript target will never be evaluated if the GenerateScript condition is not set to true.
This condition could always be true by default.
We also need to migrate away from using $(BuildDependsOn) and instead replace it with AfterTargets="Build"

Add Enum helper methods from mscorlib

The following static helper methods from the source code could be added with ease:

  • public static Object Parse(Type enumType, String value)
  • public static Object Parse(Type enumType, String value, bool ignoreCase)
  • public static Array GetValues(Type enumType)
  • public static String GetName(Type enumType, Object value)
  • public static String[] GetNames(Type enumType)

These could be achieved using custom javascript functions which evaluate the output javascript object - which has keys and values.

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.