Skip to content
This repository has been archived by the owner on Aug 24, 2022. It is now read-only.

Commit

Permalink
Merge pull request #857 from iskiselev/TranslatedBootstrap_NumberFormats
Browse files Browse the repository at this point in the history
Bootstrap from C#. Number formats
  • Loading branch information
kg committed Oct 8, 2015
2 parents 4e13fa4 + 0c8daa5 commit 46ac870
Show file tree
Hide file tree
Showing 39 changed files with 3,825 additions and 1,077 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ Tests.DCE/obj
Tests.DCE//bin
JSIL.Libraries/node_modules
JSIL.Libraries/obj
JSIL.Libraries/Generated
JSIL.Libraries/bin
Libraries/
.vs/
/mono
/mono
JSIL.mscorlib/obj/
JSIL.mscorlib/bin/
2 changes: 1 addition & 1 deletion Compiler/Compiler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<SubType>Designer</SubType>
</None>
<None Include="defaults.jsilconfig">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
Expand Down
2 changes: 1 addition & 1 deletion Compiler/defaults.jsilconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"ProxyWarnings": false,
"Assemblies": {
"Stubbed": [
"mscorlib,",
"^mscorlib,",
"^System,",
"^System\\.(.+),",
"^Microsoft\\.(.+),",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,13 @@ JSIL.ImplementExternals("System.BitConverter", function ($) {
(new JSIL.MethodSignature($.Double, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])),
$jsilcore.BytesToDouble
);

$.Method({ Static: true, Public: true }, "DoubleToInt64Bits",
(new JSIL.MethodSignature($.Int64, [$.Double], [])),
function DoubleToInt64Bits(double) {
return $jsilcore.BytesToInt64($jsilcore.BytesFromDouble(double), 0);
}
);
});

//? if ('GENERATE_STUBS' in __out) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ JSIL.ImplementExternals(
return (typeof (value) === "number");
});

$jsilcore.$MakeParseExternals($, $.Single, $jsilcore.$ParseFloat, $jsilcore.$TryParseFloat);
$jsilcore.$MakeParseExternals($, $.Double, $jsilcore.$ParseFloat, $jsilcore.$TryParseFloat);

$.Constant({ Public: true, Static: true }, "MinValue", -1.7976931348623157E+308);
$.Constant({ Public: true, Static: true }, "MaxValue", 1.7976931348623157E+308);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ $jsilcore.$MakeParseExternals = function ($, type, parse, tryParse) {
parse
);

$.Method({ Static: true, Public: true }, "Parse",
(new JSIL.MethodSignature(type, [$.String, $jsilcore.TypeRef("System.IFormatProvider")], [])),
function (input, formatProvider) {
// TODO: Really use fromat provider
return parse(input, null);
}
);

$.Method({ Static: true, Public: true }, "TryParse",
(new JSIL.MethodSignature($.Boolean, [$.String, $jsilcore.TypeRef("JSIL.Reference", [type])], [])),
tryParse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ JSIL.ImplementExternals("System.UInt64", function ($) {
$.Method({ Static: true, Public: false }, "FromNumber",
(new JSIL.MethodSignature($.Type, [$.Double], [])),
function UInt64_FromNumber(n) {
return me().FromNumberImpl(n, ctor);
var sum = n < 0 ? 0x100000000 : 0;
return me().FromNumberImpl(sum + n, ctor);
});

// Not present in mscorlib
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,23 @@ JSIL.ImplementExternals("System.Globalization.CultureInfo", function ($) {
return $jsilcore.System.Globalization.CultureInfo.GetCultureInfo(name);
}
);


$.Method({ Static: false, Public: true }, "get_IsReadOnly",
(new JSIL.MethodSignature($.Boolean, [], [])),
function get_IsReadOnly() {
return true;
}
);

$.Method({ Static: false, Public: true }, "get_NumberFormat",
(new JSIL.MethodSignature($jsilcore.TypeRef("System.Globalization.NumberFormatInfo"), [], [])),
function get_NumberFormat() {
if (this.numInfo === null) {
this.numInfo = new $jsilcore.System.Globalization.NumberFormatInfo();
}
return this.numInfo;
}
);
});

JSIL.ImplementExternals("System.Globalization.CultureInfo", function ($) {
Expand All @@ -93,4 +109,8 @@ JSIL.ImplementExternals("System.Globalization.CultureInfo", function ($) {
return $jsilcore.getCurrentUICultureImpl();
}
);
});
});

JSIL.MakeClass("System.Object", "System.Globalization.CultureInfo", true, [], function ($) {
$.Field({ Public: false, Static: false }, "numInfo", $jsilcore.TypeRef("System.Globalization.NumberFormatInfo"));
})
2 changes: 1 addition & 1 deletion JSIL.Libraries/Includes/Bootstrap/Resources/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if (!$jsilcore)

$jsilcore.getCurrentUICultureImpl = function () {
var language;
var svc = JSIL.Host.getService("window", false);
var svc = JSIL.Host.getService("window", true);

if (svc) {
language = svc.getNavigatorLanguage() || "en-US";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ JSIL.ImplementExternals("System.Text.StringBuilder", function ($) {
}
);

$.Method({ Static: false, Public: true }, "Remove",
(new JSIL.MethodSignature($.Type, [$.Int32, $.Int32], [])),
function Remove(startIndex, length) {
this._str = this._str.substr(0, startIndex) + this._str.substring(startIndex + length, length);
return this;
}
);

var replace = function (self, oldText, newText, startIndex, count) {
var prefix = self._str.substr(0, startIndex);
var suffix = self._str.substr(startIndex + count);
Expand Down Expand Up @@ -328,6 +336,35 @@ JSIL.ImplementExternals("System.Text.StringBuilder", function ($) {
}
);

var insert = function (self, string, startIndex, count) {
while (startIndex > self._str.length - 1 && self._str.length < self._capacity) {
self._str += "\0";
}

var suffix = self._str.substr(startIndex);
self._str = self._str.substr(0, startIndex);
for (var i = 0; i < count; i++) {
self._str += string;
}
self._str += suffix;
self._capacity = Math.max(self._capacity, self._str.length);
return self;
};

$.Method({ Static: false, Public: true }, "Insert",
(new JSIL.MethodSignature($.Type, [$.Int32, $.String], [])),
function Insert(index, value) {
return insert(this, index, value, 1);
}
);

$.Method({ Static: false, Public: true }, "Insert",
(new JSIL.MethodSignature($.Type, [$.Int32, $.String, $.Int32], [])),
function Insert(index, value, count) {
return insert(this, index, value, count);
}
);

$.Method({ Static: false, Public: true }, "set_Length",
(new JSIL.MethodSignature(null, [$.Int32], [])),
function set_Length(value) {
Expand Down Expand Up @@ -355,6 +392,9 @@ JSIL.ImplementExternals("System.Text.StringBuilder", function ($) {
$.Method({ Static: false, Public: true }, "set_Chars",
(new JSIL.MethodSignature(null, [$.Int32, $.Char], [])),
function set_Chars(i, value) {
while (i > this._str.length - 1) {
this._str += "\0";
}
this._str =
this._str.substr(0, i) +
value +
Expand Down
13 changes: 9 additions & 4 deletions JSIL.Libraries/JSIL.Libraries.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ClassLibrary1</RootNamespace>
<AssemblyName>ClassLibrary1</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>.\</OutputPath>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>.\</OutputPath>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand Down Expand Up @@ -325,7 +325,12 @@
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<ProjectReference Include="..\JSIL.mscorlib\JSIL.mscorlib.csproj">
<Project>{aef2633e-e92c-4a0d-b8e0-a072ed404af7}</Project>
<Name>JSIL.mscorlib</Name>
</ProjectReference>
</ItemGroup>
<Import Project="Targets\Empty.targets" />
<Import Project="Targets\MSBuild.Node.targets" />
<Import Project="Targets\MSBuild.Npm.targets" />
Expand Down
Loading

0 comments on commit 46ac870

Please sign in to comment.