Commit 9d374568 authored by John van Groningen's avatar John van Groningen
Browse files

add <!- generator in comprehensions for strict lists

parent 44782daf
......@@ -4607,13 +4607,17 @@ where
(qual_filename, pState) = accScanState getFilename pState
(lhs_expr, pState) = wantPattern pState
(token, pState) = nextToken FunctionContext pState
| token =: LeftArrowToken
= want_generators IsListGenerator (toLineAndColumn qual_position) qual_filename lhs_expr pState
| token =: LeftArrowColonToken
= want_generators IsArrayGenerator (toLineAndColumn qual_position) qual_filename lhs_expr pState
| token =: LeftArrowWithBarToken
= want_generators IsOverloadedListGenerator (toLineAndColumn qual_position) qual_filename lhs_expr pState
= ({qual_generators = [], qual_let_defs=LocalParsedDefs [], qual_filter = No, qual_position = {lc_line = 0, lc_column = 0}, qual_filename = "" },
= case token of
LeftArrowToken
-> want_generators IsListGenerator (toLineAndColumn qual_position) qual_filename lhs_expr pState
LeftArrowWithExclamationToken
-> want_generators IsStrictListGenerator (toLineAndColumn qual_position) qual_filename lhs_expr pState
LeftArrowColonToken
-> want_generators IsArrayGenerator (toLineAndColumn qual_position) qual_filename lhs_expr pState
LeftArrowWithBarToken
-> want_generators IsOverloadedListGenerator (toLineAndColumn qual_position) qual_filename lhs_expr pState
_
-> ({qual_generators = [], qual_let_defs=LocalParsedDefs [], qual_filter = No, qual_position = {lc_line = 0, lc_column = 0}, qual_filename = "" },
parseError "comprehension: qualifier" (Yes token) "qualifier(s)" pState)
want_generators :: !GeneratorKind !LineAndColumn !FileName !ParsedExpr !ParseState -> (!Qualifier, !ParseState)
......
......@@ -455,8 +455,14 @@ transformLambda lam_ident args rhs pos
= MakeNewImpOrDefFunction lam_ident (length args) lam_body (FK_Function cNameLocationDependent) NoPrio No pos
makeConsExpressionForGenerator :: GeneratorKind ParsedExpr ParsedExpr -> ParsedExpr
makeConsExpressionForGenerator IsListGenerator a1 a2
#! cons_id = predefined_idents.[PD_ConsSymbol]
= PE_List [PE_Ident cons_id, a1, a2]
makeConsExpressionForGenerator IsStrictListGenerator a1 a2
#! cons_id = predefined_idents.[PD_StrictConsSymbol]
= PE_List [PE_Ident cons_id, a1, a2]
makeConsExpressionForGenerator gen_kind a1 a2
#! cons_id = predefined_idents.[case gen_kind of IsListGenerator -> PD_ConsSymbol ; _ -> PD_OverloadedConsSymbol]
#! cons_id = predefined_idents.[PD_OverloadedConsSymbol]
= PE_List [PE_Ident cons_id, a1, a2]
makeNilExpression :: Int -> ParsedExpr
......@@ -493,9 +499,6 @@ is_zero_expression (PE_Basic (BVI "0")) = True
is_zero_expression (PE_Basic (BVInt 0)) = True
is_zero_expression _ = False
is_overloaded_list_generator IsOverloadedListGenerator = True
is_overloaded_list_generator _ = False
transformGenerator :: Generator String IndexGenerator *CollectAdmin -> (!TransformedGenerator,!IndexGenerator,!Int,!*CollectAdmin)
transformGenerator {gen_kind=IsArrayGenerator, gen_expr, gen_pattern, gen_position} qual_filename index_generator ca
# (array, ca) = prefixAndPositionToIdentExp "g_a" gen_position ca
......@@ -562,7 +565,8 @@ transformGenerator {gen_kind=IsArrayGenerator, gen_expr, gen_pattern, gen_positi
(PE_List [n,PE_Ident sub,PE_Basic (BVInt 1)]),n2)
-> (transformed_generator,Yes (i,[size_expression:size_expressions]),0,ca)
transformGenerator {gen_kind, gen_expr=PE_Sequ (SQ_FromTo pd_from_to_index from_exp to_exp), gen_pattern, gen_position} qual_filename index_generator ca
| is_overloaded_list_generator gen_kind || pd_from_to_index==PD_FromTo
| gen_kind=:IsOverloadedListGenerator || (pd_from_to_index==PD_FromTo && not gen_kind=:IsStrictListGenerator)
|| (pd_from_to_index==PD_FromToS && not gen_kind=:IsListGenerator)
# (n, ca) = prefixAndPositionToIdentExp "g_s" gen_position ca
(gen_var_case1, ca) = prefixAndPositionToIdent "g_c1" gen_position ca
(gen_var_case2, ca) = prefixAndPositionToIdent "g_c2" gen_position ca
......@@ -632,7 +636,8 @@ transformGenerator {gen_kind, gen_expr=PE_Sequ (SQ_FromTo pd_from_to_index from_
}
= (transformed_generator,index_generator,0,ca)
transformGenerator {gen_kind, gen_expr=PE_Sequ (SQ_From pd_from_index from_exp), gen_pattern, gen_position} qual_filename index_generator ca
| is_overloaded_list_generator gen_kind || pd_from_index==PD_From
| gen_kind=:IsOverloadedListGenerator || (pd_from_index==PD_From && not gen_kind=:IsStrictListGenerator)
|| (pd_from_index==PD_FromS && not gen_kind=:IsListGenerator)
# (gen_var_case1, ca) = prefixAndPositionToIdent "g_c1" gen_position ca
(gen_var_case2, ca) = prefixAndPositionToIdent "g_c2" gen_position ca
| is_zero_expression from_exp
......@@ -937,6 +942,10 @@ size_of_generator_can_be_computed_quickly {gen_pattern,gen_kind=IsListGenerator,
= pattern_will_always_match gen_pattern
size_of_generator_can_be_computed_quickly {gen_pattern,gen_kind=IsListGenerator,gen_expr=PE_Sequ (SQ_From PD_From from_exp)}
= pattern_will_always_match gen_pattern
size_of_generator_can_be_computed_quickly {gen_pattern,gen_kind=IsStrictListGenerator,gen_expr=PE_Sequ (SQ_FromTo PD_FromToS (PE_Basic (BVInt 0)) to_exp)}
= pattern_will_always_match gen_pattern
size_of_generator_can_be_computed_quickly {gen_pattern,gen_kind=IsStrictListGenerator,gen_expr=PE_Sequ (SQ_From PD_FromS from_exp)}
= pattern_will_always_match gen_pattern
size_of_generator_can_be_computed_quickly {gen_pattern,gen_kind=IsOverloadedListGenerator,gen_expr=PE_Sequ (SQ_FromTo _ (PE_Basic (BVInt 0)) to_exp)}
= pattern_will_always_match gen_pattern
size_of_generator_can_be_computed_quickly {gen_pattern,gen_kind=IsOverloadedListGenerator,gen_expr=PE_Sequ (SQ_From _ from_exp)}
......@@ -947,7 +956,9 @@ size_of_generator_can_be_computed_quickly _
size_of_generators_can_be_computed_quickly qualifiers=:[qualifier=:{qual_generators,qual_filter=No}]
= All size_of_generator_can_be_computed_quickly qual_generators && not (All is_from_generator qual_generators)
where
is_from_generator {gen_pattern,gen_kind=IsListGenerator,gen_expr=PE_Sequ (SQ_From _ from_exp)}
is_from_generator {gen_pattern,gen_kind=IsListGenerator,gen_expr=PE_Sequ (SQ_From PD_From from_exp)}
= True
is_from_generator {gen_pattern,gen_kind=IsStrictListGenerator,gen_expr=PE_Sequ (SQ_From PD_FromS from_exp)}
= True
is_from_generator {gen_pattern,gen_kind=IsOverloadedListGenerator,gen_expr=PE_Sequ (SQ_From _ from_exp)}
= True
......
......@@ -50,6 +50,7 @@ instance <<< FilePosition
| BackSlashToken // \
| DoubleBackSlashToken // \\
| LeftArrowToken // <-
| LeftArrowWithExclamationToken // <-
| LeftArrowColonToken // <-:
| LeftArrowWithBarToken // <|-
| DotDotToken // ..
......
......@@ -131,6 +131,7 @@ ScanOptionNoNewOffsideForSeqLetBit:==4;
| BackSlashToken // \
| DoubleBackSlashToken // \\
| LeftArrowToken // <-
| LeftArrowWithExclamationToken // <-
| LeftArrowColonToken // <-:
| LeftArrowWithBarToken // <|-
| DotDotToken // ..
......@@ -651,8 +652,7 @@ Scan c0=:'<' input co
# (eof, c1, input) = ReadNormalChar input
| eof = (IdentToken "<", input)
| c1 <> '-'
| c1<>'|'
= ScanOperator 0 (charBack input) [c0] co
| c1=='|'
# (eof, c2, input) = ReadNormalChar input
| eof
= (IdentToken "<|",input)
......@@ -664,6 +664,19 @@ Scan c0=:'<' input co
| isSpecialChar c2
= ScanOperator 2 input [c2, c1, c0] co
= (IdentToken "<|", charBack input)
| c1=='!'
# (eof, c2, input) = ReadNormalChar input
| eof
= (IdentToken "<!",input)
| c2=='-'
# (eof, c3, input) = ReadNormalChar input
| eof = (LeftArrowWithExclamationToken, input)
| isSpecialChar c3 = ScanOperator 3 input [c3, c2, c1, c0] co
= (LeftArrowWithExclamationToken, charBack input)
| isSpecialChar c2
= ScanOperator 2 input [c2, c1, c0] co
= (IdentToken "<!", charBack input)
= ScanOperator 0 (charBack input) [c0] co
# (eof, c2, input) = ReadNormalChar input
| eof = (LeftArrowToken, input)
| c2 == ':'
......@@ -1653,6 +1666,7 @@ where
toString BackSlashToken = "\\"
toString DoubleBackSlashToken = "\\\\"
toString LeftArrowToken = "<-"
toString LeftArrowWithExclamationToken = "<!-"
toString LeftArrowColonToken = "<-:"
toString LeftArrowWithBarToken = "<|-"
toString DotDotToken = ".."
......
......@@ -1322,7 +1322,7 @@ instance toString KindInfo
:: ArrayKind = OverloadedArray | StrictArray | UnboxedArray | PackedArray;
:: GeneratorKind = IsListGenerator | IsOverloadedListGenerator | IsArrayGenerator
:: GeneratorKind = IsListGenerator | IsStrictListGenerator | IsOverloadedListGenerator | IsArrayGenerator
:: LineAndColumn = {lc_line :: !Int, lc_column :: !Int}
......
......@@ -333,6 +333,7 @@ where
= file <<< gen_pattern <<< (gen_kind_to_string gen_kind) <<< gen_expr
where
gen_kind_to_string IsListGenerator = "<-"
gen_kind_to_string IsStrictListGenerator = "<!-"
gen_kind_to_string IsOverloadedListGenerator = "<|-"
gen_kind_to_string IsArrayGenerator = "<-:"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment