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

Quotations transformer refactor #155

Merged
merged 23 commits into from
Jul 31, 2023
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
40 changes: 8 additions & 32 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -33,40 +33,16 @@ trim_trailing_whitespace = true
indent_size = 2

# fantomas conf

[*.fs]
fsharp_semicolon_at_end_of_line=false
fsharp_space_before_parameter=true
fsharp_space_before_lowercase_invocation=true
fsharp_space_before_uppercase_invocation=false
fsharp_space_before_class_constructor=false
fsharp_space_before_member=false
fsharp_space_before_colon=false
fsharp_space_after_comma=true
fsharp_space_before_semicolon=false
fsharp_space_after_semicolon=true
fsharp_indent_on_try_with=false
fsharp_space_around_delimiter=true
fsharp_max_if_then_else_short_width=80
[*.{fs,fsx}]
max_line_length=140
fsharp_newline_between_type_definition_and_members=true
fsharp_max_function_binding_width=40
fsharp_max_if_then_else_short_width=60
fsharp_max_infix_operator_expression=80
fsharp_max_record_width=80
fsharp_max_record_number_of_items=1
fsharp_record_multiline_formatter=character_width
fsharp_max_array_or_list_width=80
fsharp_max_array_or_list_number_of_items=1
fsharp_array_or_list_multiline_formatter=character_width
fsharp_max_value_binding_width=80
fsharp_max_function_binding_width=80
fsharp_max_array_or_list_number_of_items=5
fsharp_max_dot_get_expression_width=80
fsharp_multiline_block_brackets_on_same_column=true
fsharp_newline_between_type_definition_and_members=false
fsharp_keep_if_then_in_same_line=true
fsharp_max_elmish_width=80
fsharp_single_argument_web_mode=true
fsharp_align_function_signature_to_indentation=false
fsharp_alternative_long_member_definitions=false
fsharp_multi_line_lambda_closing_newline=true
fsharp_disable_elmish_syntax=false
fsharp_keep_indent_in_branch=false
fsharp_blank_lines_around_nested_multiline_expressions=false
fsharp_bar_before_discriminated_union_declaration=false
fsharp_strict_mode=false
fsharp_keep_max_number_of_blank_lines=1
14 changes: 14 additions & 0 deletions Brahma.FSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks",
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Brahma.FSharp.Benchmarks", "benchmarks\Brahma.FSharp.Benchmarks\Brahma.FSharp.Benchmarks.fsproj", "{3CB90A8F-D372-426E-930A-65833F46E796}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "build", "build\build.fsproj", "{BB36B500-C0C3-438C-9423-3536BBF1B123}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -148,6 +150,18 @@ Global
{3CB90A8F-D372-426E-930A-65833F46E796}.Release|x64.Build.0 = Release|Any CPU
{3CB90A8F-D372-426E-930A-65833F46E796}.Release|x86.ActiveCfg = Release|Any CPU
{3CB90A8F-D372-426E-930A-65833F46E796}.Release|x86.Build.0 = Release|Any CPU
{BB36B500-C0C3-438C-9423-3536BBF1B123}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BB36B500-C0C3-438C-9423-3536BBF1B123}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BB36B500-C0C3-438C-9423-3536BBF1B123}.Debug|x64.ActiveCfg = Debug|Any CPU
{BB36B500-C0C3-438C-9423-3536BBF1B123}.Debug|x64.Build.0 = Debug|Any CPU
{BB36B500-C0C3-438C-9423-3536BBF1B123}.Debug|x86.ActiveCfg = Debug|Any CPU
{BB36B500-C0C3-438C-9423-3536BBF1B123}.Debug|x86.Build.0 = Debug|Any CPU
{BB36B500-C0C3-438C-9423-3536BBF1B123}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BB36B500-C0C3-438C-9423-3536BBF1B123}.Release|Any CPU.Build.0 = Release|Any CPU
{BB36B500-C0C3-438C-9423-3536BBF1B123}.Release|x64.ActiveCfg = Release|Any CPU
{BB36B500-C0C3-438C-9423-3536BBF1B123}.Release|x64.Build.0 = Release|Any CPU
{BB36B500-C0C3-438C-9423-3536BBF1B123}.Release|x86.ActiveCfg = Release|Any CPU
{BB36B500-C0C3-438C-9423-3536BBF1B123}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{455B3C80-98CD-484A-8AD0-6EB93E504D84} = {569DF79C-F1A0-4AE9-BE73-17628649518C}
Expand Down
6 changes: 3 additions & 3 deletions build/build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ let formatCode _ =
|> dotnet.fantomas

if not result.OK then
printfn "Errors while formatting all files: %A" result.Messages
printfn $"Code: %i{result.ExitCode} Errors while formatting all files: %A{result.Messages}"

let checkFormatCode _ =
let result =
Expand All @@ -636,7 +636,7 @@ let checkFormatCode _ =
elif result.ExitCode = 99 then
failwith "Some files need formatting, check output for more info"
else
Trace.logf "Errors while formatting: %A" result.Errors
Trace.logf $"Code: %i{result.ExitCode} Errors while formatting: %A{result.Errors}"

let buildDocs _ =
DocsTool.build ()
Expand Down Expand Up @@ -727,7 +727,7 @@ let initTargets () =
==>! "Release"

"DotnetRestore"
//==> "CheckFormatCode"
==> "CheckFormatCode"
==> "DotnetBuild"
//==> "FSharpAnalyzers"
==> "DotnetTest"
Expand Down
6 changes: 3 additions & 3 deletions docsTool/templates/nav.fs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ let navItemIconOnly link ariaLabel inner =
]

let dropDownNavMenu text items =
li [ Class "nav-item dropdown" ][
li [ Class "nav-item dropdown" ] [
a [
Id (sprintf "navbarDropdown-%s" text)
Href "#"
Expand All @@ -57,8 +57,8 @@ let dropDownNavMenu text items =
AriaExpanded false
Class "nav-link dropdown-toggle" ]
[ normalizeStr text ]
ul [ HTMLAttr.Custom ("aria-labelledby", "dropdownMenu1")
Class "dropdown-menu border-0 shadow" ] items ]
ul [ HTMLAttr.Custom ("aria-labelledby", "dropdownMenu1")
Class "dropdown-menu border-0 shadow" ] items ]

let dropDownNavItem text link =
li [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<PropertyGroup>
<Title>Brahma.FSharp.OpenCL.AST</Title>
<Description>OpenCL C AST.</Description>
<NoWarn>1591</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<Optimize>true</Optimize>
Expand Down
5 changes: 3 additions & 2 deletions src/Brahma.FSharp.OpenCL.AST/Common.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ namespace Brahma.FSharp.OpenCL.AST

[<AbstractClass>]
type Node<'lang>() =
abstract Children : List<Node<'lang>>
abstract Children: List<Node<'lang>>

[<AbstractClass>]
type Statement<'lang>() =
inherit Node<'lang>()

type ITopDef<'lang> =
interface end
interface
end

type Lang = | OpenCL
2 changes: 1 addition & 1 deletion src/Brahma.FSharp.OpenCL.AST/Expressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ type Ptr<'lang>(expr: Expression<'lang>) =
type ArrayInitializer<'lang>() =
inherit Expression<'lang>()
override this.Children = []
abstract Length : int
abstract Length: int

type ZeroArray<'lang>(length: int) =
inherit ArrayInitializer<'lang>()
Expand Down
17 changes: 3 additions & 14 deletions src/Brahma.FSharp.OpenCL.AST/FunDecl.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,10 @@ type FunFormalArg<'lang>(declSpecs: DeclSpecifierPack<'lang>, name: string) =

member this.Matches(other: obj) =
match other with
| :? FunFormalArg<'lang> as o ->
this.DeclSpecs.Matches(o.DeclSpecs)
&& this.Name.Equals(o.Name)
| :? FunFormalArg<'lang> as o -> this.DeclSpecs.Matches(o.DeclSpecs) && this.Name.Equals(o.Name)
| _ -> false

type FunDecl<'lang>
(
declSpecs: DeclSpecifierPack<'lang>,
name: string,
args: List<FunFormalArg<'lang>>,
body: Statement<'lang>
) =
type FunDecl<'lang>(declSpecs: DeclSpecifierPack<'lang>, name: string, args: List<FunFormalArg<'lang>>, body: Statement<'lang>) =

inherit Node<'lang>()
interface ITopDef<'lang>
Expand All @@ -50,10 +42,7 @@ type FunDecl<'lang>
let areParamsMatching =
(this.Args, o.Args)
||> List.zip
|> List.fold
(fun eq (x, y) ->
eq && x.Matches(y)
) true
|> List.fold (fun eq (x, y) -> eq && x.Matches(y)) true

this.DeclSpecs.Matches(o.DeclSpecs)
&& this.Name.Equals(o.Name)
Expand Down
23 changes: 3 additions & 20 deletions src/Brahma.FSharp.OpenCL.AST/Statements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@

namespace Brahma.FSharp.OpenCL.AST

type VarDecl<'lang>
(
vType: Type<'lang>,
name: string,
expr: Option<Expression<'lang>>,
?spaceModifier: AddressSpaceQualifier<'lang>
) =
type VarDecl<'lang>(vType: Type<'lang>, name: string, expr: Option<Expression<'lang>>, ?spaceModifier: AddressSpaceQualifier<'lang>) =

inherit Statement<'lang>()
let mutable spaceModifier = spaceModifier
Expand Down Expand Up @@ -60,26 +54,15 @@ type Return<'lang>(expression: Expression<'lang>) =
override this.Children = []
member this.Expression = expression

type IfThenElse<'lang>
(
cond: Expression<'lang>,
thenBranch: StatementBlock<'lang>,
elseBranch: Option<StatementBlock<'lang>>
) =
type IfThenElse<'lang>(cond: Expression<'lang>, thenBranch: StatementBlock<'lang>, elseBranch: Option<StatementBlock<'lang>>) =

inherit Statement<'lang>()
override this.Children = []
member this.Condition = cond
member this.Then = thenBranch
member this.Else = elseBranch

type ForIntegerLoop<'lang>
(
var: VarDecl<'lang>,
cond: Expression<'lang>,
countModifier: Statement<'lang>,
body: StatementBlock<'lang>
) =
type ForIntegerLoop<'lang>(var: VarDecl<'lang>, cond: Expression<'lang>, countModifier: Statement<'lang>, body: StatementBlock<'lang>) =

inherit Statement<'lang>()
override this.Children = []
Expand Down
44 changes: 23 additions & 21 deletions src/Brahma.FSharp.OpenCL.AST/Types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ type Type<'lang>() =
inherit Node<'lang>()
override this.Children = []

abstract Size : int
abstract Matches : obj -> bool
abstract Size: int
abstract Matches: obj -> bool

type PrimitiveType<'lang>(pType: PTypes<'lang>) =
inherit Type<'lang>()
Expand Down Expand Up @@ -103,42 +103,46 @@ type UnionClInplaceType<'lang>(name: string, fields: List<Field<'lang>>) =
member this.Fields = fields
member this.Name = name

override this.Size =
this.Fields
|> List.map (fun f -> f.Type.Size)
|> List.fold max 0
override this.Size = this.Fields |> List.map (fun f -> f.Type.Size) |> List.fold max 0

override this.Matches _ = failwith "Not implemented"

type StructInplaceType<'lang>(name: string, fields: List<Field<'lang>>) =
inherit StructType<'lang>(name, fields)

type DiscriminatedUnionType<'lang>(name: string, fields: List<int * Field<'lang>>) =
inherit StructType<'lang>(
name,
[
{ Name = "tag"; Type = PrimitiveType(Int) }
{ Name = "data"; Type = UnionClInplaceType(name + "_Data", List.map snd fields) }
]
)
inherit
StructType<'lang>(
name,
[
{
Name = "tag"
Type = PrimitiveType(Int)
}
{
Name = "data"
Type = UnionClInplaceType(name + "_Data", List.map snd fields)
}
]
)

member this.Tag = this.Fields.[0]
member this.Data = this.Fields.[1]

member this.GetCaseByTag(tag: int) =
List.tryFind (fun (id, _) -> id = tag) fields
|> Option.map snd
List.tryFind (fun (id, _) -> id = tag) fields |> Option.map snd
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А его нельзя заставить пайпы переносить даже если они в онду строку влезают?

Copy link
Member Author

@IgorErin IgorErin Jul 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно ограничить длину выражений для всех инфиксных операторов... Но тогда многое поедет


member this.GetCaseByName(case: string) =
List.tryFind (fun (_, f) -> f.Name = case) fields
|> Option.map snd
List.tryFind (fun (_, f) -> f.Name = case) fields |> Option.map snd

type TupleType<'lang>(baseStruct: StructType<'lang>) =
inherit Type<'lang>()

member this.BaseStruct = baseStruct
override this.Size = baseStruct.Size
override this.Matches _ = failwith "Not implemented: matches for tuples"

override this.Matches _ =
failwith "Not implemented: matches for tuples"

type RefType<'lang>(baseType: Type<'lang>, typeQuals: TypeQualifier<'lang> list) =
inherit Type<'lang>()
Expand All @@ -149,9 +153,7 @@ type RefType<'lang>(baseType: Type<'lang>, typeQuals: TypeQualifier<'lang> list)

override this.Matches(other) =
match other with
| :? RefType<'lang> as o ->
this.BaseType.Matches(o.BaseType)
&& this.TypeQuals.Equals(o.TypeQuals)
| :? RefType<'lang> as o -> this.BaseType.Matches(o.BaseType) && this.TypeQuals.Equals(o.TypeQuals)
| _ -> false

type StructDecl<'lang>(structType: StructType<'lang>) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<Title>Brahma.FSharp.OpenCL.Core</Title>
<Description>Core components of Brahma.FSharp.</Description>
<OtherFlags>--warnon:3390</OtherFlags>
<NoWarn>1591</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<Optimize>true</Optimize>
Expand Down
Loading