sq / JSIL

CIL to Javascript Compiler
http://jsil.org/
Other
1.73k stars 241 forks source link

Create UInt64 from UInt32 #855

Open iskiselev opened 9 years ago

iskiselev commented 9 years ago

JSIL translated code fails on next test case:

using System;

public static class Program {
    public static void Main (string[] args)
    {
        ulong l = 0x80000000;
        Console.WriteLine(l);
    }
}

It fails with Error: cannot construct UInt64 from negative number. This code was translated to:

var $T02 = function () {
    return ($T02 = JSIL.Memoize($asm01.System.UInt64)) ();
  };
    $T01().WriteLine($T02().FromNumber(-2147483648));

So, probably we should allow creation of UInt64 from negative numbers with built-in conversion or fix how JSIL translates it.

markusjohnsson commented 9 years ago

Yup, FromNumber should probably interpret -2147483648 as a 32 bit int, take the bits from that and treat it as a 32 bit uint.

See conv_u8: https://github.com/markusjohnsson/cil.js/blob/master/CilJs/Runtime/Runtime.js#L363