Skip to content

Commit 51bd8aa

Browse files
committed
wip
1 parent e94a305 commit 51bd8aa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+10416
-9189
lines changed

backend/src/BuiltinDarkInternal/Libs/DBs.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ let fns : List<BuiltInFn> =
3333
{ name = fn "darkInternalCanvasDBUnlocked" 0
3434
typeParams = []
3535
parameters = [ Param.make "canvasID" TUuid "" ]
36-
returnType = TList TInt64
36+
returnType = TList TUInt64
3737
description = "Get a list of unlocked DBs"
3838
fn =
3939
(function
4040
| _, _, [ DUuid canvasID ] ->
4141
uply {
4242
let! unlocked = UserDB.unlocked canvasID
43-
return unlocked |> List.map int64 |> List.map DInt64 |> Dval.list KTInt64
43+
return unlocked |> List.map DUInt64 |> Dval.list KTUInt64
4444
}
4545
| _ -> incorrectArgs ())
4646
sqlSpec = NotQueryable

backend/src/BuiltinExecution/Libs/Parser.fs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ module BuiltinExecution.Libs.Parser
33
open FSharp.Control.Tasks
44
open System.Threading.Tasks
55
open System.Text
6+
open System.Globalization
7+
open System
68

79
open Prelude
810
open LibExecution.RuntimeTypes
@@ -29,11 +31,20 @@ let fns : List<BuiltInFn> =
2931
fn =
3032
(function
3133
| _, _, [ DString sourceCode ] ->
32-
// This was added to handle EGCs correctly
3334
let byteIndexToCharIndex (byteIndex : int) (text : string) : int =
3435
let bytes = Encoding.UTF8.GetBytes(text)
3536
let subText = Encoding.UTF8.GetString(bytes, 0, byteIndex)
36-
subText.Length
37+
StringInfo.ParseCombiningCharacters(subText).Length
38+
39+
let processLine (line : string) (startIndex : int) (endIndex : int) =
40+
let textElements = StringInfo.GetTextElementEnumerator(line)
41+
let mutable result = ""
42+
let mutable currentIndex = 0
43+
while textElements.MoveNext() do
44+
if currentIndex >= startIndex && currentIndex < endIndex then
45+
result <- result + (textElements.GetTextElement())
46+
currentIndex <- currentIndex + 1
47+
result
3748

3849
let rec mapNodeAtCursor (cursor : TreeCursor) : Dval =
3950
let mutable children = []
@@ -48,8 +59,9 @@ let fns : List<BuiltInFn> =
4859

4960
let fields =
5061
let mapPoint (point : Point) =
62+
let pointRow = point.row + 1
5163
let fields =
52-
[ "row", DInt64 point.row; "column", DInt64 point.column ]
64+
[ "row", DInt64 pointRow; "column", DInt64 point.column ]
5365
DRecord(pointTypeName, pointTypeName, [], Map fields)
5466

5567
let startPos = cursor.Current.StartPosition
@@ -59,26 +71,29 @@ let fns : List<BuiltInFn> =
5971
let fields = [ "start", mapPoint startPos; "end_", mapPoint endPos ]
6072
DRecord(rangeTypeName, rangeTypeName, [], Map fields)
6173

62-
let startCharIndex = byteIndexToCharIndex startPos.column sourceCode
63-
let endCharIndex = byteIndexToCharIndex endPos.column sourceCode
64-
6574
let sourceText =
6675
let lines = String.splitOnNewline sourceCode
6776
if lines.Length = 0 then
6877
""
6978
else
79+
let startLine = lines[startPos.row]
80+
let endLine = lines[endPos.row]
81+
let startCharIndex = byteIndexToCharIndex startPos.column startLine
82+
let endCharIndex = byteIndexToCharIndex endPos.column endLine
83+
7084
match startPos.row with
7185
| row when row = endPos.row ->
72-
lines[row][startCharIndex .. (endCharIndex - 1)]
86+
processLine startLine startCharIndex endCharIndex
7387
| _ ->
74-
let firstLine = lines[startPos.row][startCharIndex..]
88+
let firstLine =
89+
processLine startLine startCharIndex startLine.Length
7590
let middleLines =
7691
if startPos.row + 1 <= endPos.row - 1 then
7792
lines[startPos.row + 1 .. endPos.row - 1]
93+
|> List.map (fun line -> processLine line 0 line.Length)
7894
else
7995
[]
80-
let lastLine = lines[endPos.row][.. (endCharIndex - 1)]
81-
96+
let lastLine = processLine endLine 0 endCharIndex
8297
String.concat "\n" (firstLine :: middleLines @ [ lastLine ])
8398

8499
let fieldName =

backend/src/LibExecution/PackageIDs.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,9 @@ module Fn =
383383
let parseSingleTestFromFile =
384384
p [] "parseSingleTestFromFile" "53f3fbc6-25fd-427a-ab0d-ba0559543c99"
385385

386+
let parseTestFile =
387+
p [] "parseTestFile" "95dc8d95-dd38-4df2-aaac-9e78187a17be"
388+
386389
// what we expose to the outside world
387390
let idForName
388391
(owner : string)

backend/src/LibExecution/ProgramTypesToRuntimeTypes.fs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,23 @@ module MatchPattern =
163163

164164

165165
module Expr =
166+
let replaceEscapeSequences (s: string) : string =
167+
s
168+
|> fun s -> s.Replace(@"\t", "\t")
169+
|> fun s -> s.Replace(@"\n", "\n")
170+
|> fun s -> s.Replace(@"\r", "\r")
171+
|> fun s -> s.Replace(@"\b", "\b")
172+
|> fun s -> s.Replace(@"\f", "\f")
173+
|> fun s -> s.Replace(@"\v", "\v")
174+
|> fun s -> s.Replace(@"\""", "\"")
175+
|> fun s -> s.Replace(@"\'", "'")
176+
|> fun s -> s.Replace(@"\\", "\\")
177+
166178
let rec toRT (e : PT.Expr) : RT.Expr =
167179
match e with
168-
| PT.EChar(id, char) -> RT.EChar(id, char)
180+
| PT.EChar(id, char) ->
181+
let char = char |> replaceEscapeSequences
182+
RT.EChar(id, char)
169183
| PT.EInt64(id, num) -> RT.EInt64(id, num)
170184
| PT.EUInt64(id, num) -> RT.EUInt64(id, num)
171185
| PT.EInt8(id, num) -> RT.EInt8(id, num)
@@ -350,7 +364,20 @@ module Expr =
350364

351365
and stringSegmentToRT (segment : PT.StringSegment) : RT.StringSegment =
352366
match segment with
353-
| PT.StringText text -> RT.StringText text
367+
| PT.StringText text ->
368+
text
369+
|> fun s ->
370+
System.Text.RegularExpressions.Regex.Replace(s, @"\\x([0-9A-Fa-f]{2})",
371+
fun m ->
372+
let hexValue = System.Convert.ToByte(m.Groups[1].Value, 16)
373+
string (char hexValue))
374+
|> fun s ->
375+
System.Text.RegularExpressions.Regex.Replace(s, @"\\u([0-9A-Fa-f]{4})",
376+
fun m ->
377+
let unicodeValue = System.Convert.ToInt32(m.Groups[1].Value, 16)
378+
string (char unicodeValue))
379+
|> replaceEscapeSequences
380+
|> RT.StringText
354381
| PT.StringInterpolation expr -> RT.StringInterpolation(toRT expr)
355382

356383

backend/src/Prelude/Prelude.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ let readFloat (f : float) : (Sign * string * string) =
290290
let makeFloat (sign : Sign) (whole : string) (fraction : string) : float =
291291
try
292292
if whole <> "" then assert_ "non-zero string" [] (whole[0] <> '-')
293-
if whole <> "0" then assertRe $"makefloat" "[1-9][0-9]*" whole
293+
if whole <> "0" then assertRe $"makefloat" "0*[0-9]+" whole
294294
let sign =
295295
match sign with
296296
| Positive -> ""

backend/testfiles/execution/cloud/_events.dark

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
type FruitRecord = { fruits: List<String> }
55

66
// getQueue works
7-
Builtin.testGetQueue_v0 "TestWorker" = []
7+
Builtin.testGetQueue "TestWorker" = []
88

99
// emit works
1010
(let _ = Builtin.emit "value" "TestWorker"
11-
let queue = Builtin.testGetQueue_v0 "TestWorker"
11+
let queue = Builtin.testGetQueue "TestWorker"
1212
queue) = [ "\"value\"" ]
1313

1414
// emit works with mixed values
1515
(let _ = Builtin.emit "value" "TestWorker"
1616
let _ = Builtin.emit 1 "TestWorker"
1717
let _ = Builtin.emit (FruitRecord { fruits = [ "apple"; "banana" ] }) "TestWorker"
18-
let queue = Builtin.testGetQueue_v0 "TestWorker"
19-
Stdlib.List.sort queue) = [ "\"value\""
20-
"1"
21-
"FruitRecord {\n fruits: [\n \"apple\", \"banana\"\n ]\n}" ]
18+
let queue = Builtin.testGetQueue "TestWorker"
19+
Stdlib.List.sort queue) = [ "\"value\""
20+
"1"
21+
"FruitRecord {\n fruits: [\n \"apple\", \"banana\"\n ]\n}" ]

0 commit comments

Comments
 (0)