Skip to content

Commit

Permalink
very close
Browse files Browse the repository at this point in the history
  • Loading branch information
StachuDotNet committed Apr 26, 2024
1 parent 8a68d2b commit b9fd49e
Show file tree
Hide file tree
Showing 25 changed files with 903 additions and 1,177 deletions.
18 changes: 0 additions & 18 deletions backend/src/BuiltinCli/Libs/Output.fs
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,6 @@ let fns : List<BuiltInFn> =
| _ -> incorrectArgs ())
sqlSpec = NotQueryable
previewable = Impure
deprecated = NotDeprecated }


{ name = fn "debug" 0
typeParams = []
parameters =
[ Param.make "value" (TVariable "a") "The value to be printed."
Param.make "label" TString "The label to be printed." ]
returnType = TVariable "a"
description = "Prints the given <param value> to the standard output"
fn =
(function
| _, _, [ value; DString label ] ->
print $"DEBUG: {label} - {value}"
Ply value
| _ -> incorrectArgs ())
sqlSpec = NotQueryable
previewable = Impure
deprecated = NotDeprecated } ]


Expand Down
34 changes: 32 additions & 2 deletions backend/src/BuiltinExecution/Libs/LanguageTools.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,39 @@ let typ
FQTypeName.fqPackage "Darklang" ([ "LanguageTools" ] @ addlModules) name version


let typeNameToStr = DvalReprDeveloper.typeName

let fns : List<BuiltInFn> =
[ { name = fn "languageToolsAllBuiltinFns" 0
[ { name = fn "languageToolsAllBuiltinConstants" 0
typeParams = []
parameters = [ Param.make "unit" TUnit "" ]
returnType = TList(TCustomType(Ok(typ [] "BuiltinConstant" 0), []))
description =
"Returns a list of the Builtin constants (usually not to be accessed directly)."
fn =
(function
| state, _, [ DUnit ] ->
let constTypeName = typ [] "BuiltinConstant" 0

let consts =
state.builtins.constants
|> Map.toList
|> List.map (fun (key, data) ->
let fields =
[ "name", DString(FQConstantName.builtinToString key)
"description", DString data.description
"returnType", DString(typeNameToStr data.typ) ]

DRecord(constTypeName, constTypeName, [], Map fields))

DList(VT.customType constTypeName [], consts) |> Ply
| _ -> incorrectArgs ())
sqlSpec = NotQueryable
previewable = Impure
deprecated = NotDeprecated }


{ name = fn "languageToolsAllBuiltinFns" 0
typeParams = []
parameters = [ Param.make "unit" TUnit "" ]
returnType = TList(TCustomType(Ok(typ [] "BuiltinFunction" 0), []))
Expand All @@ -29,7 +60,6 @@ let fns : List<BuiltInFn> =
fn =
(function
| state, _, [ DUnit ] ->
let typeNameToStr = LibExecution.DvalReprDeveloper.typeName

let fnParamTypeName = typ [] "BuiltinFunctionParameter" 0
let fnTypeName = typ [] "BuiltinFunction" 0
Expand Down
21 changes: 20 additions & 1 deletion backend/src/BuiltinExecution/Libs/NoModule.fs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,26 @@ let fns : List<BuiltInFn> =

sqlSpec = NotQueryable
previewable = Pure
deprecated = NotDeprecated } ]
deprecated = NotDeprecated }


{ name = fn "debug" 0
typeParams = []
parameters =
[ Param.make "label" TString "The label to be printed."
Param.make "value" (TVariable "a") "The value to be printed." ]
returnType = TUnit
description = "Prints the given <param value> to the standard output"
fn =
(function
| _, _, [ DString label; value ] ->
// TODO: call upon the Dark equivalent fn instead of rlying on DvalReprDeveloper
print $"DEBUG: {label} - {DvalReprDeveloper.toRepr value}"
Ply DUnit
| _ -> incorrectArgs ())
sqlSpec = NotQueryable
previewable = Impure
deprecated = NotDeprecated }]


let builtins = LibExecution.Builtin.make [] fns
1 change: 0 additions & 1 deletion backend/src/LibExecution/RuntimeTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ module FQTypeName =


let packageToString (s : Package) : string =
debuG "here" s
let name = ("PACKAGE" :: s.owner :: s.modules @ [ s.name ]) |> String.concat "."
if s.version = 0 then name else $"{name}_v{s.version}"

Expand Down
46 changes: 26 additions & 20 deletions backend/src/LibParser/Canvas.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ open Utils
open ParserException

type WTCanvasModule =
{ name : List<string>
{ owner: string
name : List<string>
types : List<WT.PackageType.T>
constants : List<WT.PackageConstant.T>
dbs : List<WT.DB.T>
Expand All @@ -26,8 +27,9 @@ type WTCanvasModule =
handlers : List<WT.Handler.Spec * WT.Expr>
exprs : List<WT.Expr> }

let emptyRootWTModule canvasName =
{ name = ["Canvas"; canvasName]
let emptyRootWTModule owner canvasName =
{ owner = owner
name = [ "Canvas"; canvasName ]
types = []
constants = []
dbs = []
Expand Down Expand Up @@ -87,7 +89,6 @@ let (|SimpleAttribute|_|) (attr : SynAttribute) =
/// Update a CanvasModule by parsing a single F# let binding
/// Depending on the attribute present, this may add a user function, a handler, or a DB
let parseLetBinding
(owner : string)
(m : WTCanvasModule)
(letBinding : SynBinding)
: WTCanvasModule =
Expand All @@ -109,7 +110,7 @@ let parseLetBinding
WT.ELet(gid (), FS2WT.LetPattern.fromSynPat pat, expr, WT.EUnit(gid ()))
{ m with exprs = m.exprs @ [ newExpr ] }
| Some _ ->
let newFn = FS2WT.PackageFn.fromSynBinding owner m.name letBinding
let newFn = FS2WT.PackageFn.fromSynBinding m.owner m.name letBinding
{ m with fns = newFn :: m.fns }

| [ attr ] ->
Expand Down Expand Up @@ -174,7 +175,6 @@ module UserDB =
(Some typeDef.Range)

let parseTypeDefn
(owner : string)
(m : WTCanvasModule)
(typeDefn : SynTypeDefn)
: WTCanvasModule =
Expand All @@ -190,7 +190,7 @@ let parseTypeDefn
if isDB then
[ UserDB.fromSynTypeDefn typeDefn ], []
else
[], [ FS2WT.PackageType.fromSynTypeDefn owner m.name typeDefn ]
[], [ FS2WT.PackageType.fromSynTypeDefn m.owner m.name typeDefn ]

{ m with types = m.types @ newTypes; dbs = m.dbs @ newDBs }

Expand All @@ -210,15 +210,19 @@ let parseTypeDefn
/// or as DBs (i.e. with `[<DB>] DBName = Type`)
/// - ? expressions are parsed as init commands (not currently supported)
/// - anything else fails
let parseDecls (owner : string) (canvasName: string) (decls : List<SynModuleDecl>) : WTCanvasModule =
let parseDecls
(owner : string)
(canvasName : string)
(decls : List<SynModuleDecl>)
: WTCanvasModule =
List.fold
(fun m decl ->
match decl with
| SynModuleDecl.Let(_, bindings, _) ->
List.fold (fun m b -> parseLetBinding owner m b) m bindings
List.fold (fun m b -> parseLetBinding m b) m bindings

| SynModuleDecl.Types(defns, _) ->
List.fold (fun m d -> parseTypeDefn owner m d) m defns
List.fold (fun m d -> parseTypeDefn m d) m defns

| SynModuleDecl.Expr(expr, _) ->
{ m with exprs = m.exprs @ [ FS2WT.Expr.fromSynExpr expr ] }
Expand All @@ -228,7 +232,7 @@ let parseDecls (owner : string) (canvasName: string) (decls : List<SynModuleDecl
"Unsupported declaration"
[ "decl", decl ]
(Some decl.Range))
(emptyRootWTModule canvasName)
(emptyRootWTModule owner canvasName)
decls


Expand All @@ -241,30 +245,30 @@ let toPT
uply {
let! types =
m.types
|> Ply.List.mapSequentially (WT2PT.PackageType.toPT pm onMissing m.name)
|> Ply.List.mapSequentially (WT2PT.PackageType.toPT pm onMissing (m.owner :: m.name))

let! constants =
m.constants
|> Ply.List.mapSequentially (WT2PT.PackageConstant.toPT pm onMissing m.name)
|> Ply.List.mapSequentially (WT2PT.PackageConstant.toPT pm onMissing (m.owner :: m.name))

let! dbs = m.dbs |> Ply.List.mapSequentially (WT2PT.DB.toPT pm onMissing m.name)
let! dbs = m.dbs |> Ply.List.mapSequentially (WT2PT.DB.toPT pm onMissing (m.owner :: m.name))

let! fns =
m.fns
|> Ply.List.mapSequentially (WT2PT.PackageFn.toPT builtins pm onMissing m.name)
|> Ply.List.mapSequentially (WT2PT.PackageFn.toPT builtins pm onMissing (m.owner :: m.name))

let! handlers =
m.handlers
|> Ply.List.mapSequentially (fun (spec, expr) ->
uply {
let spec = WT2PT.Handler.Spec.toPT spec
let! expr = WT2PT.Expr.toPT builtins pm onMissing m.name expr
let! expr = WT2PT.Expr.toPT builtins pm onMissing (m.owner :: m.name) expr
return (spec, expr)
})

let! exprs =
m.exprs
|> Ply.List.mapSequentially (WT2PT.Expr.toPT builtins pm onMissing m.name)
|> Ply.List.mapSequentially (WT2PT.Expr.toPT builtins pm onMissing (m.owner :: m.name))

return
{ types = types
Expand All @@ -278,12 +282,12 @@ let toPT

let parse
(owner : string)
(canvasName: string)
(canvasName : string)
(builtins : RT.Builtins)
(pm : RT.PackageManager)
(onMissing : NR.OnMissing)
(filename : string)
(source: string)
(source : string)
: Ply<PTCanvasModule> =

uply {
Expand Down Expand Up @@ -320,5 +324,7 @@ let parse
(result.fns |> List.map PT2RT.PackageFn.toRT)

// Now, parse again, but with the names in context (so fewer are marked as unresolved)
return! toPT builtins pm onMissing moduleWT
let! result = toPT builtins pm onMissing moduleWT

return result
}
3 changes: 3 additions & 0 deletions backend/src/LibParser/NameResolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ type GenericName = { modules : List<string>; name : string; version : int }
/// - Darklang.Option.Option
/// - Option.Option
/// , in that order (most specific first).
///
/// TODO?: accept an Option<string> of the _owner_ as well.
/// I think that'll be useful in many contexts to help resolve names...
let namesToTry
(currentModule : List<string>)
(given : GenericName)
Expand Down
3 changes: 2 additions & 1 deletion backend/src/LibParser/Package.fs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ let rec parseDecls
constants = m.constants @ nestedDecls.constants }


| _ -> Exception.raiseInternal $"Unsupported declaration" [ "decl", decl ])
| _ ->
Exception.raiseInternal $"Unsupported declaration" [ "decl", decl ])
emptyWTModule
decls

Expand Down
1 change: 1 addition & 0 deletions backend/src/LocalExec/LoadPackagesFromDisk.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ let load (builtins : RT.Builtins) : Ply<PT.Packages> =
filesWithContents
// TODO: parallelize
|> Ply.List.mapSequentially (fun (path, contents) ->
//debuG "parsing" path
LibParser.Parser.parsePackageFile
builtins
RT.PackageManager.empty
Expand Down
8 changes: 7 additions & 1 deletion backend/testfiles/execution/stdlib/list.dark
Original file line number Diff line number Diff line change
Expand Up @@ -502,4 +502,10 @@ Stdlib.List.chunkBySize_v0 [ 1L; 2L; 3L; 4L ] 0L = Stdlib.Result.Result.Error
Stdlib.List.ChunkBySizeError.SizeMustBeGreaterThanZero

Stdlib.List.chunkBySize_v0 [ 1L; 2L; 3L; 4L ] -1L = Stdlib.Result.Result.Error
Stdlib.List.ChunkBySizeError.SizeMustBeGreaterThanZero
Stdlib.List.ChunkBySizeError.SizeMustBeGreaterThanZero


Stdlib.List.splitLast [] = Stdlib.Option.Option.None
Stdlib.List.splitLast [ 1L ] = Stdlib.Option.Option.Some (([], 1L))
Stdlib.List.splitLast [ 1L; 2L ] = Stdlib.Option.Option.Some (([ 1L ], 2L))
Stdlib.List.splitLast [ 1L; 2L; 3L ] = Stdlib.Option.Option.Some (([ 1L; 2L ], 3L))
Loading

0 comments on commit b9fd49e

Please sign in to comment.