Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moar dart collections #2862

Merged
merged 9 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,13 @@
},
"files.trimTrailingWhitespace": true,
"files.trimFinalNewlines": true,
"gitlens.codeLens.enabled": false
"gitlens.codeLens.enabled": false,
"FSharp.excludeProjectDirectories": [
".git",
"paket-files",
"fable_modules",
"packages",
"node_modules",
"src/fcs-fable"
]
}
35 changes: 25 additions & 10 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ let BUILD_ARGS_LOWER =
module Util =
let cleanDirs dirs =
for dir in dirs do
printfn $"Clean {dir}"
removeDirRecursive dir

let resolveDir dir =
Expand Down Expand Up @@ -175,6 +176,7 @@ let buildLibraryTs() =

// TODO: move to PublishUtils.fs ?
let copyFiles sourceDir searchPattern destDir =
printfn $"Copy {sourceDir </> searchPattern} to {destDir}"
for source in IO.Directory.GetFiles(sourceDir, searchPattern) do
let fileName = IO.Path.GetFileName(source)
let target = destDir </> fileName
Expand Down Expand Up @@ -236,12 +238,16 @@ let buildLibraryRust() =
// if not (pathExists (baseDir </> "build/fable-library-rust")) then
// buildLibraryRust()

let buildLibraryDart() =
let buildLibraryDart(clean: bool) =
let sourceDir = resolveDir "src/fable-library-dart"
let buildDir = resolveDir "build/fable-library-dart"
cleanDirs [buildDir]

if clean then
cleanDirs [buildDir]
makeDirRecursive buildDir
copyFiles sourceDir "pubspec.*" buildDir
copyFiles sourceDir "analysis_options.yaml" buildDir

makeDirRecursive buildDir
copyFiles sourceDir "*.dart" buildDir

runFableWithArgsInDir sourceDir [
Expand Down Expand Up @@ -524,7 +530,7 @@ let testRust() =

let testDart(isWatch) =
if not (pathExists "build/fable-library-dart") then
buildLibraryDart()
buildLibraryDart(true)

let runDir = "tests/Dart"
let projectDir = runDir + "/src"
Expand Down Expand Up @@ -675,8 +681,8 @@ let publishPackages restArgs =
else
pushNpm ("src" </> pkg) buildAction

let minify<'T> =
BUILD_ARGS_LOWER |> List.contains "--no-minify" |> not
let hasFlag flag =
BUILD_ARGS_LOWER |> List.contains flag

match BUILD_ARGS_LOWER with
// | "check-sourcemaps"::_ ->
Expand All @@ -688,7 +694,9 @@ match BUILD_ARGS_LOWER with
| "test-mocha"::_ -> compileAndRunTestsWithMocha true "Main"
| "test-mocha-fast"::_ -> compileAndRunTestsWithMocha false "Main"
| "test-react"::_ -> testReact()
| "test-standalone"::_ -> testStandalone(minify)
| "test-standalone"::_ ->
let minify = hasFlag "--no-minify" |> not
testStandalone(minify)
| "test-standalone-fast"::_ -> testStandaloneFast()
| "test-configs"::_ -> testProjectConfigs()
| "test-integration"::_ -> testIntegration()
Expand Down Expand Up @@ -723,9 +731,16 @@ match BUILD_ARGS_LOWER with
| ("fable-library-ts"|"library-ts")::_ -> buildLibraryTs()
| ("fable-library-py"|"library-py")::_ -> buildLibraryPy()
| ("fable-library-rust" | "library-rust")::_ -> buildLibraryRust()
| ("fable-library-dart" | "library-dart")::_ -> buildLibraryDart()
| ("fable-compiler-js"|"compiler-js")::_ -> buildCompilerJs(minify)
| ("fable-standalone"|"standalone")::_ -> buildStandalone {|minify=minify; watch=false|}
| ("fable-library-dart" | "library-dart")::_ ->
let clean = hasFlag "--no-clean" |> not
buildLibraryDart(clean)

| ("fable-compiler-js"|"compiler-js")::_ ->
let minify = hasFlag "--no-minify" |> not
buildCompilerJs(minify)
| ("fable-standalone"|"standalone")::_ ->
let minify = hasFlag "--no-minify" |> not
buildStandalone {|minify=minify; watch=false|}
| "watch-standalone"::_ -> buildStandalone {|minify=false; watch=true|}
| "publish"::restArgs -> publishPackages restArgs
| "github-release"::_ ->
Expand Down
28 changes: 18 additions & 10 deletions src/Fable.AST/Fable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ type Type =
| Number of kind: NumberKind * info: NumberInfo
| Option of genericArg: Type * isStruct: bool
| Tuple of genericArgs: Type list * isStruct: bool
| Array of genericArg: Type
| Array of genericArg: Type * kind: ArrayKind
| List of genericArg: Type
| LambdaType of argType: Type * returnType: Type
| DelegateType of argTypes: Type list * returnType: Type
Expand All @@ -144,7 +144,7 @@ type Type =
member this.Generics =
match this with
| Option(gen, _)
| Array gen
| Array(gen,_)
| List gen -> [ gen ]
| LambdaType(argType, returnType) -> [ argType; returnType ]
| DelegateType(argTypes, returnType) -> argTypes @ [ returnType ]
Expand All @@ -157,7 +157,7 @@ type Type =
member this.MapGenerics f =
match this with
| Option(gen, isStruct) -> Option(f gen, isStruct)
| Array gen -> Array(f gen)
| Array(gen, kind) -> Array(f gen, kind)
| List gen -> List(f gen)
| LambdaType(argType, returnType) -> LambdaType(f argType, f returnType)
| DelegateType(argTypes, returnType) -> DelegateType(List.map f argTypes, f returnType)
Expand Down Expand Up @@ -191,6 +191,7 @@ type MemberDecl = {
/// for a declaration in the root scope
ExportDefault: bool
DeclaringEntity: EntityRef option
XmlDoc: string option
} with
member this.ArgIdents = this.Args |> List.map (fun a -> a.Ident)
member this.ArgTypes = this.Args |> List.map (fun a -> a.Ident.Type)
Expand All @@ -201,6 +202,7 @@ type ClassDecl = {
Constructor: MemberDecl option
BaseCall: Expr option
AttachedMembers: MemberDecl list
XmlDoc: string option
}

type ModuleDecl = {
Expand Down Expand Up @@ -260,6 +262,16 @@ type FuncInfo =
static member Empty =
FuncInfo.Create()

type NewArrayKind =
| ArrayValues of values: Expr list
| ArrayAlloc of size: Expr
| ArrayFrom of expr: Expr

type ArrayKind =
| ResizeArray
| MutableArray
| ImmutableArray

type ValueKind =
// The AST from F# compiler is a bit inconsistent with ThisValue and BaseValue.
// ThisValue only appears in constructors and not in instance members (where `this` is passed as first argument)
Expand All @@ -278,10 +290,7 @@ type ValueKind =
| NumberConstant of value: obj * kind: NumberKind * info: NumberInfo
| RegexConstant of source: string * flags: RegexFlag list
| NewOption of value: Expr option * typ: Type * isStruct: bool
/// isMutable is currently unused but added in case ImmutableArray is added to FSharp.Core
| NewArray of values: Expr list * typ: Type * isMutable: bool
/// TODO: This is ambiguous, value can be the size (allocation) or an iterable, fix?
| NewArrayFrom of value: Expr * typ: Type * isMutable: bool
| NewArray of newKind: NewArrayKind * typ: Type * kind: ArrayKind
| NewList of headAndTail: (Expr * Expr) option * typ: Type
| NewTuple of values: Expr list * isStruct: bool
| NewRecord of values: Expr list * ref: EntityRef * genArgs: Type list
Expand All @@ -300,8 +309,7 @@ type ValueKind =
| NumberConstant (_, kind, info) -> Number(kind, info)
| RegexConstant _ -> Regex
| NewOption (_, t, isStruct) -> Option(t, isStruct)
| NewArray (_, t, _) -> Array t
| NewArrayFrom (_, t, _) -> Array t
| NewArray (_, t, k) -> Array(t, k)
| NewList (_, t) -> List t
| NewTuple (exprs, isStruct) -> Tuple(exprs |> List.map (fun e -> e.Type), isStruct)
| NewRecord (_, ent, genArgs) -> DeclaredType(ent, genArgs)
Expand Down Expand Up @@ -456,7 +464,7 @@ type UnresolvedExpr =
// TODO: Add also MemberKind from the flags?
| UnresolvedTraitCall of sourceTypes: Type list * traitName: string * isInstance: bool * argTypes: Type list * argExprs: Expr list
| UnresolvedReplaceCall of thisArg: Expr option * args: Expr list * info: ReplaceCallInfo * attachedCall: Expr option
| UnresolvedInlineCall of memberUniqueName: string * genArgs: Type list * witnesses: Witness list * callee: Expr option * info: CallInfo
| UnresolvedInlineCall of memberUniqueName: string * witnesses: Witness list * callee: Expr option * info: CallInfo

type Expr =
/// Identifiers that reference another expression
Expand Down
4 changes: 2 additions & 2 deletions src/Fable.Cli/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"profiles": {
"Fable.Cli": {
"commandName": "Project",
"commandLineArgs": "watch src/Quicktest --noCache --exclude Fable.Core",
"workingDirectory": "C:\\Users\\alfon\\repos\\Fable"
"commandLineArgs": "src/quicktest-dart --lang dart --noCache --exclude Fable.Core",
"workingDirectory": "../../../../.."
}
}
}
29 changes: 17 additions & 12 deletions src/Fable.Transforms/Dart/Dart.fs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ type Type =
| Function of argTypes: Type list * returnType: Type

type Ident =
{ Prefix: string option // Namespace
{ ImportModule: string option
Name: string
Type: Type }
Type: Type
IsMutable: bool }
member this.Expr =
IdentExpression this

Expand All @@ -66,6 +67,7 @@ type Annotation = Ident * Literal list
type CallArg = string option * Expression

type Expression =
| CommentedExpression of comment: string * expr: Expression
| SuperExpression of typ: Type
| ThisExpression of typ: Type
| Literal of value: Literal
Expand All @@ -91,6 +93,7 @@ type Expression =
| RethrowExpression of typ: Type
member this.Type =
match this with
| CommentedExpression(_, e) -> e.Type
| IsExpression _ -> Boolean
| LogicalExpression _ -> Boolean
| Literal value -> value.Type
Expand All @@ -117,6 +120,7 @@ type Expression =
| AnonymousFunction(args,_,_,returnType) -> Function(args |> List.map (fun a -> a.Type), returnType)
| AssignmentExpression _ -> Void

static member commented comment expr = CommentedExpression(comment, expr)
static member listLiteral(values, typ, ?isConst) = ListLiteral(values, typ, isConst=defaultArg isConst false) |> Literal
static member integerLiteral(value) = IntegerLiteral value |> Literal
static member integerLiteral(value: int) = IntegerLiteral value |> Literal
Expand Down Expand Up @@ -172,6 +176,7 @@ type CatchClause(body, ?param, ?test) =
member _.Body: Statement list = body

type Statement =
| CommentedStatement of comment: string * statement: Statement
| IfStatement of test: Expression * consequent: Statement list * alternate: Statement list
| ForStatement of init: (Ident * Expression) option * test: Expression option * update: Expression option * body: Statement list
| ForInStatement of param: Ident * iterable: Expression * body: Statement list
Expand All @@ -180,12 +185,14 @@ type Statement =
| TryStatement of body: Statement list * handlers: CatchClause list * finalizer: Statement list
| SwitchStatement of discriminant: Expression * cases: SwitchCase list * defaultCase: Statement list option
| ReturnStatement of Expression
| BreakStatement of label: string option * ignoreDeadCode: bool
| BreakStatement of label: string option
| ContinueStatement of label: string option
| ExpressionStatement of Expression
| LocalVariableDeclaration of ident: Ident * kind: VariableDeclarationKind * value: Expression option
| LocalFunctionDeclaration of FunctionDecl
| LabeledStatement of label: string * body: Statement
static member commented comment statement =
CommentedStatement(comment, statement)
static member returnStatement(arg) =
ReturnStatement(arg)
static member labeledStatement(label, body) =
Expand All @@ -198,8 +205,8 @@ type Statement =
ForInStatement(param, iterable, body)
static member whileStatement(test, body) =
WhileStatement(test, body)
static member breakStatement(?label, ?ignoreDeadCode) =
BreakStatement(label, defaultArg ignoreDeadCode false)
static member breakStatement(?label) =
BreakStatement(label)
static member continueStatement(?label) =
ContinueStatement(label)
static member tryStatement(body, ?handlers, ?finalizer) =
Expand All @@ -214,13 +221,15 @@ type Statement =
ReturnType = returnType
GenericParams = defaultArg genParams []
}
static member switchStatement(discriminant, cases, defaultCase) =
static member switchStatement(discriminant, cases, ?defaultCase) =
SwitchStatement(discriminant, cases, defaultCase)

type FunctionArg(ident: Ident, ?isOptional: bool, ?isNamed: bool) =
type FunctionArg(ident: Ident, ?isOptional: bool, ?isNamed: bool, ?isConsThisArg: bool) =
member _.Ident = ident
member _.IsOptional = defaultArg isOptional false
member _.IsNamed = defaultArg isNamed false
member _.IsConsThisArg = defaultArg isConsThisArg false
member _.AsConsThisArg(name) = FunctionArg({ ident with Name = name }, ?isOptional=isOptional, ?isNamed=isNamed, isConsThisArg=true)

type FunctionDecl =
{
Expand All @@ -231,12 +240,8 @@ type FunctionDecl =
ReturnType: Type
}

type ConsArg =
| ConsArg of Ident
| ConsThisArg of name: string

type Constructor(?args, ?body, ?superArgs, ?isConst, ?isFactory) =
member _.Args: ConsArg list = defaultArg args []
member _.Args: FunctionArg list = defaultArg args []
member _.Body: Statement list = defaultArg body []
member _.SuperArgs: CallArg list = defaultArg superArgs []
member _.IsConst = defaultArg isConst false
Expand Down
Loading