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

Feature/language-improvements-2612 #42

Merged
merged 8 commits into from
Dec 26, 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
14 changes: 7 additions & 7 deletions src/Visp.Compiler/Parser.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -1262,13 +1262,13 @@ rawConstant:

function_def:
| FN function_def_name function_def_args expr_list %prec prec_fn
{ SynExpr.FunctionDef($2, FunctionFlags.None, $3, $4, (lhs parseState)) }
{ SynExpr.FunctionDef($2, FunctionFlags.None, $3, $4, None, (lhs parseState)) }
| FN INLINE function_def_name function_def_args expr_list %prec prec_fn
{ SynExpr.FunctionDef($3, FunctionFlags.Inline, $4, $5, (lhs parseState)) }
{ SynExpr.FunctionDef($3, FunctionFlags.Inline, $4, $5, None, (lhs parseState)) }
| FN REC INLINE function_def_name function_def_args expr_list %prec prec_fn
{ SynExpr.FunctionDef($4, FunctionFlags.Recursive ||| FunctionFlags.Inline, $5, $6, (lhs parseState)) }
{ SynExpr.FunctionDef($4, FunctionFlags.Recursive ||| FunctionFlags.Inline, $5, $6, None, (lhs parseState)) }
| FN REC function_def_name function_def_args expr_list %prec prec_fn
{ SynExpr.FunctionDef($3, FunctionFlags.Recursive, $4, $5, (lhs parseState)) }
{ SynExpr.FunctionDef($3, FunctionFlags.Recursive, $4, $5, None, (lhs parseState)) }
| FN function_def_args expr_list %prec prec_lambda_def
{ SynExpr.LambdaDef(SynLambda($2, $3, (lhs parseState))) }
| FNSTAR function_def_args expr_list
Expand All @@ -1290,15 +1290,15 @@ invalid_function_def:
{ SynExpr.LambdaDef(SynLambda(mkRecoveryPat parseState, [], (lhs parseState))) }
// TODO: Report
| FN function_def_name %prec prec_invalid_fn
{ SynExpr.FunctionDef($2, FunctionFlags.None, mkRecoveryPat parseState, [], lhs parseState) }
{ SynExpr.FunctionDef($2, FunctionFlags.None, mkRecoveryPat parseState, [], None, lhs parseState) }
// TODO: Report
| FN function_def_args %prec prec_invalid_fn
{ SynExpr.LambdaDef(SynLambda(mkRecoveryPat parseState, [], (lhs parseState))) }
// TODO: Report
| FN function_def_name function_def_args %prec prec_invalid_fn
{ SynExpr.FunctionDef($2, FunctionFlags.None, $3, [], (lhs parseState)) }
{ SynExpr.FunctionDef($2, FunctionFlags.None, $3, [], None, (lhs parseState)) }
| FN INLINE function_def_name function_def_args %prec prec_invalid_fn
{ SynExpr.FunctionDef($3, FunctionFlags.Inline, $4, [], (lhs parseState)) }
{ SynExpr.FunctionDef($3, FunctionFlags.Inline, $4, [], None, (lhs parseState)) }

function_call:
| expr expr_list { Syntax.mkFunctionCallOrCexpr $1 $2 (lhs parseState)}
Expand Down
14 changes: 7 additions & 7 deletions src/Visp.Compiler/Syntax/FsLexYaccOutput/Parser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7281,7 +7281,7 @@ let _fsyacc_reductions = lazy [|
(
(
# 1265 "Parser.fsy"
SynExpr.FunctionDef(_2, FunctionFlags.None, _3, _4, (lhs parseState))
SynExpr.FunctionDef(_2, FunctionFlags.None, _3, _4, None, (lhs parseState))
)
# 1265 "Parser.fsy"
: 'gentype_function_def));
Expand All @@ -7294,7 +7294,7 @@ let _fsyacc_reductions = lazy [|
(
(
# 1267 "Parser.fsy"
SynExpr.FunctionDef(_3, FunctionFlags.Inline, _4, _5, (lhs parseState))
SynExpr.FunctionDef(_3, FunctionFlags.Inline, _4, _5, None, (lhs parseState))
)
# 1267 "Parser.fsy"
: 'gentype_function_def));
Expand All @@ -7307,7 +7307,7 @@ let _fsyacc_reductions = lazy [|
(
(
# 1269 "Parser.fsy"
SynExpr.FunctionDef(_4, FunctionFlags.Recursive ||| FunctionFlags.Inline, _5, _6, (lhs parseState))
SynExpr.FunctionDef(_4, FunctionFlags.Recursive ||| FunctionFlags.Inline, _5, _6, None, (lhs parseState))
)
# 1269 "Parser.fsy"
: 'gentype_function_def));
Expand All @@ -7320,7 +7320,7 @@ let _fsyacc_reductions = lazy [|
(
(
# 1271 "Parser.fsy"
SynExpr.FunctionDef(_3, FunctionFlags.Recursive, _4, _5, (lhs parseState))
SynExpr.FunctionDef(_3, FunctionFlags.Recursive, _4, _5, None, (lhs parseState))
)
# 1271 "Parser.fsy"
: 'gentype_function_def));
Expand Down Expand Up @@ -7444,7 +7444,7 @@ let _fsyacc_reductions = lazy [|
(
(
# 1293 "Parser.fsy"
SynExpr.FunctionDef(_2, FunctionFlags.None, mkRecoveryPat parseState, [], lhs parseState)
SynExpr.FunctionDef(_2, FunctionFlags.None, mkRecoveryPat parseState, [], None, lhs parseState)
)
# 1293 "Parser.fsy"
: 'gentype_invalid_function_def));
Expand All @@ -7467,7 +7467,7 @@ let _fsyacc_reductions = lazy [|
(
(
# 1299 "Parser.fsy"
SynExpr.FunctionDef(_2, FunctionFlags.None, _3, [], (lhs parseState))
SynExpr.FunctionDef(_2, FunctionFlags.None, _3, [], None, (lhs parseState))
)
# 1299 "Parser.fsy"
: 'gentype_invalid_function_def));
Expand All @@ -7479,7 +7479,7 @@ let _fsyacc_reductions = lazy [|
(
(
# 1301 "Parser.fsy"
SynExpr.FunctionDef(_3, FunctionFlags.Inline, _4, [], (lhs parseState))
SynExpr.FunctionDef(_3, FunctionFlags.Inline, _4, [], None, (lhs parseState))
)
# 1301 "Parser.fsy"
: 'gentype_invalid_function_def));
Expand Down
10 changes: 9 additions & 1 deletion src/Visp.Compiler/Syntax/SynWriter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ module Write =

()

| SynExpr.FunctionDef(name_, flags, args, body, range) ->
| SynExpr.FunctionDef(name_, flags, args, body, retty, range) ->
startExpr w st range

string w "let "
Expand All @@ -773,6 +773,14 @@ module Write =
space w
//writeArgsOrEmpty w args
synPat w args

match retty with
| None -> ()
| Some(ty) ->
string w " : "
writeType w ty
()

string w " ="

use _ = withIndent w false
Expand Down
3 changes: 2 additions & 1 deletion src/Visp.Compiler/Syntax/Syntax.fs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ type SynExpr =
flags: FunctionFlags *
args: SynPat *
body: SynExpr list *
returnType: SynType option *
range: range
| FunctionCall of name: SynExpr * args: SynExpr list * range: range
| LambdaShort of expr: SynExpr * range: range
Expand Down Expand Up @@ -657,7 +658,7 @@ module Patterns =
| SynExpr.Symbol(SynSymbol(id)) -> id.idText
| _ -> ""

let (|SymbolText|) (it: SynExpr) =
let (|SymbolText|_|) (it: SynExpr) =
match it with
| SynExpr.Symbol(sym) -> Some(sym.Text)
| _ -> None
Expand Down
2 changes: 1 addition & 1 deletion src/Visp.Compiler/Syntax/SyntaxPrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ let rec exprToDoc =

| SynExpr.LambdaDef(def) -> lambdaToDoc def

| SynExpr.FunctionDef(name, flags, args, body, _) ->
| SynExpr.FunctionDef(name, flags, args, body, _, _) ->

parens
<| hcat
Expand Down
4 changes: 2 additions & 2 deletions src/Visp.Compiler/Transforms/Helpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ let rec transform (func: SynExpr -> SynExpr) expr =
Option.map bound_transform alt,
range
)
| SynExpr.FunctionDef(name, is, args, body, range) ->
SynExpr.FunctionDef(name, is, args, List.map bound_transform body, range)
| SynExpr.FunctionDef(name, is, args, body, retty, range) ->
SynExpr.FunctionDef(name, is, args, List.map bound_transform body, retty, range)
| SynExpr.FunctionCall(name, args, range) ->
SynExpr.FunctionCall(bound_transform name, List.map bound_transform args, range)
| SynExpr.LambdaDef(SynLambda(args, body, lambdaRange)) ->
Expand Down
Loading