darklang / dark

Darklang main repo, including language, backend, and infra
https://darklang.com
Other
1.65k stars 90 forks source link

Use the new parser when running functions and scripts from the cli #5392

Closed OceanOak closed 1 month ago

OceanOak commented 2 months ago
OceanOak commented 1 month ago

This script was used as a test for this PR

module Test =
  type MyInt = Int64
  let test0 () : MyInt =
    let _ = Builtin.printLine ("Test Nested test0")
    0L
  module Nested =
    let test1 () : Int64 =
      let _ = Builtin.printLine ("Test Nested test1")
      0L

    module Nested2 =
      type MyString = List<String>

      let fizzbuzz (n: Int64) : MyString =
        let list = PACKAGE.Darklang.Stdlib.List.range 1L n

        PACKAGE.Darklang.Stdlib.List.map list (fun i ->
          match ((i % 3L == 0L), (i % 5L == 0L)) with
          | (true, false) -> "Fizz"
          | (false, true) -> "Buzz"
          | (true, true) -> "FizzBuzz"
          | (false, false) -> PACKAGE.Darklang.Stdlib.Int64.toString i)

      let wrapperFunction (n: Int64) : MyType =
        let result = fizzbuzz n

        let _ =
          PACKAGE.Darklang.Stdlib.List.map result (fun x -> Builtin.printLine x)

        0L

      module Nested3 =
        module Nested4 =
          let test3 () : Int64 =
            let _ = Builtin.printLine ("Test Nested Nested3 Nested4 test3")
            0L

type MyType = Int64

let helloworld () : MyType =
  let _ = Builtin.printLine ("Hello, World!")
  0L

Test.Nested.Nested2.Nested3.Nested4.test3 ()
helloworld ()
Test.Nested.Nested2.wrapperFunction 15L
Test.Nested.test1 ()
Test.test0 ()

Result:

Test Nested Nested3 Nested4 test3
Hello, World!
Test Nested test1
Test Nested test0
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz

Time to run the script (seems a little slow)

Screenshot 2024-07-13 at 15 47 45
OceanOak commented 1 month ago

I am not sure how to avoid adding CliScript. when calling a newly declared function in the script. Do you have any idea why we didn’t have to do this when we used libParser?