@@ -53,6 +53,7 @@ let coreModFor =
5353 | BclDateTimeOffset -> " DateTimeOffset"
5454 | BclDateOnly -> " DateOnly"
5555 | BclTimeOnly -> " TimeOnly"
56+ | BclRune -> " Rune"
5657 | BclTimer -> " Timer"
5758 | BclTimeSpan -> " TimeSpan"
5859 | FSharpSet _ -> " Set"
@@ -427,7 +428,8 @@ let applyOp (com: ICompiler) (ctx: Context) r t opName (args: Expr list) =
427428 match argTypes with
428429 // | Number(BigInt as kind,_)::_ ->
429430 // Helper.LibCall(com, "BigInt", opName, t, args, argTypes, ?loc=r)
430- | Builtin( BclDateTime | BclDateTimeOffset | BclTimeOnly | BclTimeSpan) :: _ -> nativeOp opName argTypes args
431+ | Builtin( BclDateTime | BclDateTimeOffset | BclTimeOnly | BclTimeSpan | BclRune) :: _ ->
432+ nativeOp opName argTypes args
431433 | Builtin( FSharpSet _) :: _ ->
432434 let methName =
433435 match opName with
@@ -453,6 +455,7 @@ let isCompatibleWithNativeComparison =
453455 // | List _
454456 | Builtin( BclGuid) -> true
455457 | Builtin( BclTimeSpan) -> true
458+ | Builtin( BclRune) -> true
456459 | _ -> false
457460
458461// Overview of hash rules:
@@ -471,6 +474,8 @@ let referenceHash (com: ICompiler) ctx r (arg: Expr) =
471474let getHashCode ( com : ICompiler ) ctx r ( arg : Expr ) =
472475 match arg.Type with
473476 | HasReferenceEquality com _ -> referenceHash com ctx r arg
477+ | Builtin BclRune -> Helper.LibCall( com, " Rune" , " getHashCode" , Int32.Number, [ arg ], ?loc = r)
478+ | Char -> Helper.LibCall( com, " Char" , " GetHashCode" , Int32.Number, [ arg ], ?loc = r)
474479 | _ -> Helper.InstanceCall( arg, " getHashCode" , Int32.Number, [], [], [], ?loc = r)
475480
476481let objectHash ( com : ICompiler ) ctx r ( arg : Expr ) =
@@ -658,6 +663,7 @@ let rec getZero (com: ICompiler) (ctx: Context) (t: Type) =
658663 | Builtin BclDateTimeOffset -> Helper.LibCall( com, " DateTimeOffset" , " zero" , t, [])
659664 | Builtin BclDateOnly -> Helper.LibCall( com, " DateOnly" , " zero" , t, [])
660665 | Builtin BclTimeOnly -> Helper.LibCall( com, " TimeOnly" , " zero" , t, [])
666+ | Builtin BclRune -> Helper.LibCall( com, " Rune" , " zero" , t, [])
661667 | Builtin BclTimeSpan -> Helper.LibValue( com, " TimeSpan" , " zero" , t)
662668 | Builtin( FSharpSet genArg) -> makeSet com ctx None t [] genArg
663669 | Builtin BclGuid -> Helper.LibValue( com, " Guid" , " empty" , t)
@@ -1424,6 +1430,7 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt
14241430 | _ -> None
14251431 | " get_Length" , Some c, _ -> Helper.LibCall( com, " String" , " length" , t, c :: args, ?loc = r) |> Some
14261432 | " get_Chars" , Some c, _ -> Helper.LibCall( com, " String" , " getCharAt" , t, c :: args, ?loc = r) |> Some
1433+ | " EnumerateRunes" , Some c, _ -> Helper.LibCall( com, " String" , " enumerateRunes" , t, [ c ], ?loc = r) |> Some
14271434 | " CompareOrdinal" , None, _ ->
14281435 match args with
14291436 | [ ExprType String; ExprType String ] ->
@@ -2860,6 +2867,69 @@ let timeOnly (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr op
28602867 | " Add" when args.Length = 2 -> makeInstanceCall r t i thisArg.Value " add2" args |> Some
28612868 | meth -> makeMemberCall com ctx r t i " TimeOnly" meth thisArg args |> Some
28622869
2870+ let rune ( com : ICompiler ) ( ctx : Context ) r t ( i : CallInfo ) ( thisArg : Expr option ) ( args : Expr list ) =
2871+ let libCall memberName callArgs =
2872+ Helper.LibCall( com, " Rune" , memberName, t, callArgs, i.SignatureArgTypes, ?loc = r)
2873+
2874+ let instanceCall memberName callArgs =
2875+ libCall memberName ( thisArg.Value :: callArgs)
2876+
2877+ let firstArg =
2878+ match args with
2879+ | arg :: _ -> [ arg ]
2880+ | [] -> []
2881+
2882+ let isCultureInfoArg ( arg : Expr ) =
2883+ match arg.Type with
2884+ | DeclaredType( ent, _) -> ent.FullName = " System.Globalization.CultureInfo"
2885+ | _ -> false
2886+
2887+ match i.CompiledName, thisArg, args with
2888+ | " .ctor" , None, [ ExprType( Char) ] -> Some args.Head
2889+ | " .ctor" , None, [ ExprType( Number( Int32, _)) ] -> libCall " newInt" args |> Some
2890+ | " .ctor" , None, [ ExprType( Number( UInt32, _)) ] -> libCall " newUInt" args |> Some
2891+ | " .ctor" , None, [ ExprType( Char); ExprType( Char) ] -> libCall " newPair" args |> Some
2892+ | ( " ReplacementChar" | " get_ReplacementChar" ), None, [] -> libCall " replacementChar" [] |> Some
2893+ | " op_Explicit" , None, [ ExprType( Char) ] -> Some args.Head
2894+ | " op_Explicit" , None, [ ExprType( Number( Int32, _)) ] -> libCall " newInt" args |> Some
2895+ | " op_Explicit" , None, [ ExprType( Number( UInt32, _)) ] -> libCall " newUInt" args |> Some
2896+ | " TryCreate" , None, [ ExprType( Char); _ ] -> libCall " tryCreateChar" args |> Some
2897+ | " TryCreate" , None, [ ExprType( Char); ExprType( Char); _ ] -> libCall " tryCreatePair" args |> Some
2898+ | " TryCreate" , None, [ ExprType( Number( Int32, _)); _ ] -> libCall " tryCreateInt" args |> Some
2899+ | " TryCreate" , None, [ ExprType( Number( UInt32, _)); _ ] -> libCall " tryCreateUInt" args |> Some
2900+ | " get_Value" , Some _, [] -> instanceCall " value" [] |> Some
2901+ | " get_Utf8SequenceLength" , Some _, [] -> instanceCall " utf8SequenceLength" [] |> Some
2902+ | " get_Utf16SequenceLength" , Some _, [] -> instanceCall " utf16SequenceLength" [] |> Some
2903+ | " get_IsAscii" , Some _, [] -> instanceCall " isAscii" [] |> Some
2904+ | " get_IsBmp" , Some _, [] -> instanceCall " isBmp" [] |> Some
2905+ | " get_Plane" , Some _, [] -> instanceCall " plane" [] |> Some
2906+ | " GetNumericValue" , None, _ -> libCall " getNumericValue" firstArg |> Some
2907+ | " GetUnicodeCategory" , None, _ -> libCall " getUnicodeCategory" firstArg |> Some
2908+ | ( " IsControl" | " IsDigit" | " IsLetter" | " IsLetterOrDigit" | " IsLower" | " IsNumber" | " IsPunctuation" | " IsSeparator" | " IsSymbol" | " IsUpper" | " IsWhiteSpace" ),
2909+ None,
2910+ _ ->
2911+ let meth = Naming.lowerFirst i.CompiledName
2912+ libCall meth firstArg |> Some
2913+ | " IsValid" , None, [ ExprType( Number( Int32, _)) ] -> libCall " isValidInt" args |> Some
2914+ | " IsValid" , None, [ ExprType( Number( UInt32, _)) ] -> libCall " isValidUInt" args |> Some
2915+ | " ToLower" , None, [ runeArg; cultureInfo ] when isCultureInfoArg cultureInfo ->
2916+ libCall " toLowerInvariant" [ runeArg ] |> Some
2917+ | " ToLowerInvariant" , None, _ -> libCall " toLowerInvariant" firstArg |> Some
2918+ | " ToUpper" , None, [ runeArg; cultureInfo ] when isCultureInfoArg cultureInfo ->
2919+ libCall " toUpperInvariant" [ runeArg ] |> Some
2920+ | " ToUpperInvariant" , None, _ -> libCall " toUpperInvariant" firstArg |> Some
2921+ | " GetRuneAt" , None, _ -> libCall " getRuneAt" args |> Some
2922+ | " TryGetRuneAt" , None, _ -> libCall " tryGetRuneAt" args |> Some
2923+ | " Parse" , None, _ -> libCall " parse" firstArg |> Some
2924+ | " TryParse" , None, _ -> libCall " tryParse" args |> Some
2925+ | " ToString" , Some _, _ -> instanceCall " toString" [] |> Some
2926+ | " CompareTo" , Some _, _ -> instanceCall " compareTo" args |> Some
2927+ | " Compare" , None, _ -> libCall " compareTo" args |> Some
2928+ | " Equals" , Some _, _ -> instanceCall " equals" args |> Some
2929+ | " Equals" , None, _ -> libCall " equals" args |> Some
2930+ | " GetHashCode" , Some _, _ -> libCall " getHashCode" [ thisArg.Value ] |> Some
2931+ | _ -> None
2932+
28632933let timeSpans ( com : ICompiler ) ( ctx : Context ) r t ( i : CallInfo ) ( thisArg : Expr option ) ( args : Expr list ) =
28642934 // let callee = match i.callee with Some c -> c | None -> i.args.Head
28652935 match i.CompiledName with
@@ -3691,6 +3761,8 @@ let tryField com t ownerTyp fieldName =
36913761 let meth = fieldName |> Naming.applyCaseRule Fable.Core.CaseRules.SnakeCase
36923762
36933763 Helper.LibValue( com, " TimeSpan" , meth, t) |> Some
3764+ | Builtin BclRune, " ReplacementChar"
3765+ | Builtin BclRune, " get_ReplacementChar" -> Helper.LibValue( com, " Rune" , " replacementChar" , t) |> Some
36943766 | Builtin BclDateTime, _ ->
36953767 let meth = fieldName |> Naming.lowerFirst
36963768 makeStaticFieldCall com None t " DateTime" " DateTime" meth |> Some
@@ -3805,6 +3877,7 @@ let private replacedModules =
38053877 Types.datetimeOffset, dateTimeOffsets
38063878 Types.dateOnly, dateOnly
38073879 Types.timeOnly, timeOnly
3880+ Types.rune, rune
38083881 Types.timespan, timeSpans
38093882 " System.Timers.Timer" , timers
38103883 " System.Environment" , systemEnv
@@ -3974,6 +4047,7 @@ let tryType typ =
39744047 | BclDateTimeOffset -> Some( Types.datetimeOffset, dateTimeOffsets, [])
39754048 | BclDateOnly -> Some( Types.dateOnly, dateOnly, [])
39764049 | BclTimeOnly -> Some( Types.timeOnly, timeOnly, [])
4050+ | BclRune -> Some( Types.rune, rune, [])
39774051 | BclTimer -> Some( " System.Timers.Timer" , timers, [])
39784052 | BclTimeSpan -> Some( Types.timespan, timeSpans, [])
39794053 | BclHashSet genArg -> Some( Types.hashset, hashSets, [ genArg ])
0 commit comments