Skip to content

Commit

Permalink
Updated fable-standalone to latest FCS
Browse files Browse the repository at this point in the history
  • Loading branch information
ncave committed Oct 19, 2023
1 parent a291873 commit 276d805
Show file tree
Hide file tree
Showing 224 changed files with 25,760 additions and 14,486 deletions.
892 changes: 892 additions & 0 deletions build_old.fsx

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions src/Fable.Transforms/Dart/Replacements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,19 @@ let resizeArrays (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (this
Helper.InstanceCall(ar, "sublist", t, [makeIntConst 0], ?loc=r) |> Some
| _ -> None

let collectionExtensions (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg: Expr option) (args: Expr list) =
match i.CompiledName, thisArg, args with
| "AddRange", None, [ar; arg] ->
Helper.LibCall(com, "Array", "addRangeInPlace", t, [arg; ar], genArgs=i.GenericArgs, ?loc=r) |> Some
| "InsertRange", None, [ar; idx; arg] ->
Helper.InstanceCall(ar, "insertAll", t, [idx; arg], ?loc=r) |> Some
| _ -> None

let readOnlySpans (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg: Expr option) (args: Expr list) =
match i.CompiledName, args with
| "op_Implicit", [arg] -> arg |> Some
| _ -> None

let tuples (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg: Expr option) (args: Expr list) =
let changeKind isStruct = function
| Value(NewTuple(args, _), r)::_ -> Value(NewTuple(args, isStruct), r) |> Some
Expand Down Expand Up @@ -2688,6 +2701,8 @@ let private replacedModules =
"System.Collections.IList", resizeArrays
Types.icollectionGeneric, resizeArrays
Types.icollection, resizeArrays
"System.Collections.Generic.CollectionExtensions", collectionExtensions
"System.ReadOnlySpan`1", readOnlySpans
Types.hashset, hashSets
Types.stack, bclType
Types.queue, bclType
Expand Down
17 changes: 17 additions & 0 deletions src/Fable.Transforms/Python/Replacements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1775,6 +1775,21 @@ let resizeArrays (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (this
|> Some
| _ -> None

let collectionExtensions (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg: Expr option) (args: Expr list) =
match i.CompiledName, thisArg, args with
| "AddRange", None, [ar; arg] ->
Helper.LibCall(com, "Array", "addRangeInPlace", t, [ arg; ar ], ?loc = r)
|> Some
| "InsertRange", None, [ar; idx; arg] ->
Helper.LibCall(com, "array", "insert_range_in_place", t, [ idx; arg; ar ], ?loc = r)
|> Some
| _ -> None

let readOnlySpans (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg: Expr option) (args: Expr list) =
match i.CompiledName, args with
| "op_Implicit", [arg] -> arg |> Some
| _ -> None

let nativeArrayFunctions =
dict [| //"Exists", "some"
//"Filter", "filter"
Expand Down Expand Up @@ -3796,6 +3811,8 @@ let private replacedModules =
"System.Collections.IList", resizeArrays
Types.icollectionGeneric, resizeArrays
Types.icollection, resizeArrays
"System.Collections.Generic.CollectionExtensions", collectionExtensions
"System.ReadOnlySpan`1", readOnlySpans
Types.hashset, hashSets
Types.stack, bclType
Types.queue, bclType
Expand Down
15 changes: 15 additions & 0 deletions src/Fable.Transforms/Replacements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,19 @@ let resizeArrays (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (this
Helper.InstanceCall(ar, "slice", t, args, ?loc=r) |> Some
| _ -> None

let collectionExtensions (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg: Expr option) (args: Expr list) =
match i.CompiledName, thisArg, args with
| "AddRange", None, [ar; arg] ->
Helper.LibCall(com, "Array", "addRangeInPlace", t, [arg; ar], ?loc=r) |> Some
| "InsertRange", None, [ar; idx; arg] ->
Helper.LibCall(com, "Array", "insertRangeInPlace", t, [idx; arg; ar], ?loc=r) |> Some
| _ -> None

let readOnlySpans (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg: Expr option) (args: Expr list) =
match i.CompiledName, args with
| "op_Implicit", [arg] -> arg |> Some
| _ -> None

let nativeArrayFunctions =
dict [| "Exists", "some"
"Filter", "filter"
Expand Down Expand Up @@ -2920,6 +2933,8 @@ let private replacedModules =
"System.Collections.IList", resizeArrays
Types.icollectionGeneric, resizeArrays
Types.icollection, resizeArrays
"System.Collections.Generic.CollectionExtensions", collectionExtensions
"System.ReadOnlySpan`1", readOnlySpans
Types.hashset, hashSets
Types.stack, bclType
Types.queue, bclType
Expand Down
15 changes: 15 additions & 0 deletions src/Fable.Transforms/Rust/Replacements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,19 @@ let resizeArrays (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (this
Helper.LibCall(com, "NativeArray", "new_copy", t, [ar], ?loc=r) |> Some
| _ -> None

let collectionExtensions (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg: Expr option) (args: Expr list) =
match i.CompiledName, thisArg, args with
| "AddRange", None, [ar; arg] ->
Helper.LibCall(com, "Array", "addRangeInPlace", t, [arg; ar], ?loc=r) |> Some
| "InsertRange", None, [ar; idx; arg] ->
Helper.LibCall(com, "Array", "insertRangeInPlace", t, [idx; arg; ar], ?loc=r) |> Some
| _ -> None

let readOnlySpans (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg: Expr option) (args: Expr list) =
match i.CompiledName, args with
| "op_Implicit", [arg] -> arg |> Some
| _ -> None

let tuples (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg: Expr option) (args: Expr list) =
let changeKind isStruct = function
| Value(NewTuple(args, _), r)::_ -> Value(NewTuple(args, isStruct), r) |> Some
Expand Down Expand Up @@ -2962,6 +2975,8 @@ let private replacedModules =
"System.Collections.IList", resizeArrays
Types.icollectionGeneric, collections
Types.icollection, collections
"System.Collections.Generic.CollectionExtensions", collectionExtensions
"System.ReadOnlySpan`1", readOnlySpans
Types.hashset, hashSets
Types.stack, bclType
Types.queue, bclType
Expand Down
2 changes: 1 addition & 1 deletion src/fable-standalone/src/Lexer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ let tokenizeLine (args: string[]) lineStr =
let defines =
args |> Seq.choose (fun s -> if s.StartsWith "--define:" then Some s[9..] else None)
|> Seq.toList
let sourceTokenizer = FSharpSourceTokenizer(defines, Some "/tmp.fsx")
let sourceTokenizer = FSharpSourceTokenizer(defines, Some "/tmp.fsx", None, None)
let lineTokenizer = sourceTokenizer.CreateLineTokenizer lineStr
let rec loop lexState acc =
match lineTokenizer.ScanToken lexState with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="source-map-sharp" Version="1.0.8" />
<PackageReference Include="source-map-sharp" Version="1.0.9" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 0 additions & 6 deletions src/fable-standalone/test/bench-compiler/global.json

This file was deleted.

6 changes: 6 additions & 0 deletions src/fcs-fable/FSStrings.fs
Original file line number Diff line number Diff line change
Expand Up @@ -998,4 +998,10 @@ let resources =
( "ErrorFromAddingTypeEquationTuples",
"Type mismatch. Expecting a tuple of length {0} of type\n {1} \nbut given a tuple of length {2} of type\n {3} {4}\n"
);
( "ArgumentsInSigAndImplMismatch",
"The argument names in the signature '{0}' and implementation '{1}' do not match. The argument name from the signature file will be used. This may cause problems when debugging or profiling."
);
( "Parser.TOKEN.WHILE.BANG",
"keyword 'while!'"
);
]
127 changes: 96 additions & 31 deletions src/fcs-fable/System.Collections.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,113 @@ namespace System.Collections

module Generic =

type Queue<'T> =
inherit ResizeArray<'T>
type Queue<'T>() =
let xs = ResizeArray<'T>()

new () = Queue<'T>()
member _.Clear () = xs.Clear()

member x.Enqueue (item: 'T) =
x.Add(item)
member _.Enqueue (item: 'T) =
xs.Add(item)

member x.Dequeue () =
let item = x.Item(0)
x.RemoveAt(0)
member _.Dequeue () =
let item = xs.Item(0)
xs.RemoveAt(0)
item

interface System.Collections.IEnumerable with
member _.GetEnumerator(): System.Collections.IEnumerator =
(xs.GetEnumerator() :> System.Collections.IEnumerator)

interface System.Collections.Generic.IEnumerable<'T> with
member _.GetEnumerator(): System.Collections.Generic.IEnumerator<'T> =
xs.GetEnumerator()

module Immutable =
open System.Collections.Generic

// not immutable, just a ResizeArray // TODO: immutable implementation
type ImmutableArray<'T> =
static member CreateBuilder() = ResizeArray<'T>()

// not immutable, just a Dictionary // TODO: immutable implementation
type ImmutableDictionary<'Key, 'Value>(comparer: IEqualityComparer<'Key>) =
inherit Dictionary<'Key, 'Value>(comparer)
static member Create(comparer) = ImmutableDictionary<'Key, 'Value>(comparer)
static member Empty = ImmutableDictionary<'Key, 'Value>(EqualityComparer.Default)
member x.Add (key: 'Key, value: 'Value) = x[key] <- value; x
member x.SetItem (key: 'Key, value: 'Value) = x[key] <- value; x
type ImmutableHashSet<'T>(values: 'T seq) =
let xs = HashSet<'T>(values)

static member Create<'T>(values) = ImmutableHashSet<'T>(values)
static member Empty = ImmutableHashSet<'T>(Array.empty)

member _.Add (value: 'T) =
let copy = HashSet<'T>(xs)
copy.Add(value) |> ignore
ImmutableHashSet<'T>(copy)

member _.Union (values: seq<'T>) =
let copy = HashSet<'T>(xs)
copy.UnionWith(values)
ImmutableHashSet<'T>(copy)

member _.Overlaps (values: seq<'T>) =
// xs.Overlaps(values)
values |> Seq.exists (fun x -> xs.Contains(x))

interface System.Collections.IEnumerable with
member _.GetEnumerator(): System.Collections.IEnumerator =
(xs.GetEnumerator() :> System.Collections.IEnumerator)

interface IEnumerable<'T> with
member _.GetEnumerator(): IEnumerator<'T> =
xs.GetEnumerator()

type ImmutableDictionary<'Key, 'Value when 'Key: equality>(pairs: KeyValuePair<'Key, 'Value> seq) =
let xs = Dictionary<'Key, 'Value>()
do for pair in pairs do xs.Add(pair.Key, pair.Value)

static member CreateRange(items) = ImmutableDictionary<'Key, 'Value>(items)
static member Empty = ImmutableDictionary<'Key, 'Value>(Array.empty)

member _.Item with get (key: 'Key): 'Value = xs[key]
member _.ContainsKey (key: 'Key) = xs.ContainsKey(key)

member _.Add (key: 'Key, value: 'Value) =
let copy = Dictionary<'Key, 'Value>(xs)
copy.Add(key, value)
ImmutableDictionary<'Key, 'Value>(copy)

member _.SetItem (key: 'Key, value: 'Value) =
let copy = Dictionary<'Key, 'Value>(xs)
copy[key] <- value
ImmutableDictionary<'Key, 'Value>(copy)

member _.TryGetValue (key: 'Key): bool * 'Value =
match xs.TryGetValue(key) with
| true, v -> (true, v)
| false, v -> (false, v)

interface System.Collections.IEnumerable with
member _.GetEnumerator(): System.Collections.IEnumerator =
(xs.GetEnumerator() :> System.Collections.IEnumerator)

interface IEnumerable<KeyValuePair<'Key, 'Value>> with
member _.GetEnumerator(): IEnumerator<KeyValuePair<'Key, 'Value>> =
xs.GetEnumerator()

module Concurrent =
open System.Collections.Generic

// not thread safe, just a ResizeArray // TODO: threaded implementation
type ConcurrentStack<'T> =
inherit ResizeArray<'T>

new () = ConcurrentStack<'T>()
type ConcurrentStack<'T>() =
let xs = ResizeArray<'T>()

member x.Push (item: 'T) =
x.Add(item)
member _.Push (item: 'T) = xs.Add(item)
member _.PushRange (items: 'T[]) = xs.AddRange(items)
member _.Clear () = xs.Clear()
member _.ToArray () = xs.ToArray()

member x.PushRange (items: 'T[]) =
x.AddRange(items)
interface System.Collections.IEnumerable with
member _.GetEnumerator(): System.Collections.IEnumerator =
(xs.GetEnumerator() :> System.Collections.IEnumerator)
interface IEnumerable<'T> with
member _.GetEnumerator(): IEnumerator<'T> =
xs.GetEnumerator()

// not thread safe, just a Dictionary // TODO: threaded implementation
[<AllowNullLiteral>]
Expand Down Expand Up @@ -88,22 +153,22 @@ module Concurrent =
// | true, v -> v
// | _ -> let v = valueFactory(key, arg) in x.Add(key, v); v

// member x.TryUpdate (key: 'Key, value: 'Value, comparisonValue: 'Value): bool =
// match x.TryGetValue(key) with
// | true, v when v = comparisonValue -> x.[key] <- value; true
// | _ -> false
member x.TryUpdate (key: 'Key, value: 'Value, comparisonValue: 'Value): bool =
match x.TryGetValue(key) with
| true, v when Unchecked.equals v comparisonValue -> x[key] <- value; true
| _ -> false

member x.AddOrUpdate (key: 'Key, value: 'Value, updateFactory: System.Func<'Key, 'Value, 'Value>): 'Value =
match x.TryGetValue(key) with
| true, v -> let v = updateFactory.Invoke(key, v) in x.[key] <- v; v
| true, v -> let v = updateFactory.Invoke(key, v) in x[key] <- v; v
| _ -> let v = value in x.Add(key, v); v

// member x.AddOrUpdate (key: 'Key, valueFactory: 'Key -> 'Value, updateFactory: 'Key * 'Value -> 'Value): 'Value =
// match x.TryGetValue(key) with
// | true, v -> let v = updateFactory(key, v) in x.[key] <- v; v
// | true, v -> let v = updateFactory(key, v) in x[key] <- v; v
// | _ -> let v = valueFactory(key) in x.Add(key, v); v

// member x.AddOrUpdate (key: 'Key, valueFactory: 'Key * 'Arg -> 'Value, updateFactory: 'Key * 'Arg * 'Value -> 'Value, arg: 'Arg): 'Value =
// match x.TryGetValue(key) with
// | true, v -> let v = updateFactory(key, arg, v) in x.[key] <- v; v
// | _ -> let v = valueFactory(key, arg) in x.Add(key, v); v
// | true, v -> let v = updateFactory(key, arg, v) in x[key] <- v; v
// | _ -> let v = valueFactory(key, arg) in x.Add(key, v); v
Loading

0 comments on commit 276d805

Please sign in to comment.