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 ...@@ -4607,13 +4607,17 @@ where
(qual_filename, pState) = accScanState getFilename pState (qual_filename, pState) = accScanState getFilename pState
(lhs_expr, pState) = wantPattern pState (lhs_expr, pState) = wantPattern pState
(token, pState) = nextToken FunctionContext pState (token, pState) = nextToken FunctionContext pState
| token =: LeftArrowToken = case token of
= want_generators IsListGenerator (toLineAndColumn qual_position) qual_filename lhs_expr pState LeftArrowToken
| token =: LeftArrowColonToken -> want_generators IsListGenerator (toLineAndColumn qual_position) qual_filename lhs_expr pState
= want_generators IsArrayGenerator (toLineAndColumn qual_position) qual_filename lhs_expr pState LeftArrowWithExclamationToken
| token =: LeftArrowWithBarToken -> want_generators IsStrictListGenerator (toLineAndColumn qual_position) qual_filename lhs_expr pState
= want_generators IsOverloadedListGenerator (toLineAndColumn qual_position) qual_filename lhs_expr pState LeftArrowColonToken
= ({qual_generators = [], qual_let_defs=LocalParsedDefs [], qual_filter = No, qual_position = {lc_line = 0, lc_column = 0}, qual_filename = "" }, -> 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) parseError "comprehension: qualifier" (Yes token) "qualifier(s)" pState)
want_generators :: !GeneratorKind !LineAndColumn !FileName !ParsedExpr !ParseState -> (!Qualifier, !ParseState) want_generators :: !GeneratorKind !LineAndColumn !FileName !ParsedExpr !ParseState -> (!Qualifier, !ParseState)
......
...@@ -455,8 +455,14 @@ transformLambda lam_ident args rhs pos ...@@ -455,8 +455,14 @@ transformLambda lam_ident args rhs pos
= MakeNewImpOrDefFunction lam_ident (length args) lam_body (FK_Function cNameLocationDependent) NoPrio No pos = MakeNewImpOrDefFunction lam_ident (length args) lam_body (FK_Function cNameLocationDependent) NoPrio No pos
makeConsExpressionForGenerator :: GeneratorKind ParsedExpr ParsedExpr -> ParsedExpr 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 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] = PE_List [PE_Ident cons_id, a1, a2]
makeNilExpression :: Int -> ParsedExpr makeNilExpression :: Int -> ParsedExpr
...@@ -493,9 +499,6 @@ is_zero_expression (PE_Basic (BVI "0")) = True ...@@ -493,9 +499,6 @@ is_zero_expression (PE_Basic (BVI "0")) = True
is_zero_expression (PE_Basic (BVInt 0)) = True is_zero_expression (PE_Basic (BVInt 0)) = True
is_zero_expression _ = False 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 :: Generator String IndexGenerator *CollectAdmin -> (!TransformedGenerator,!IndexGenerator,!Int,!*CollectAdmin)
transformGenerator {gen_kind=IsArrayGenerator, gen_expr, gen_pattern, gen_position} qual_filename index_generator ca transformGenerator {gen_kind=IsArrayGenerator, gen_expr, gen_pattern, gen_position} qual_filename index_generator ca
# (array, ca) = prefixAndPositionToIdentExp "g_a" gen_position ca # (array, ca) = prefixAndPositionToIdentExp "g_a" gen_position ca
...@@ -562,7 +565,8 @@ transformGenerator {gen_kind=IsArrayGenerator, gen_expr, gen_pattern, gen_positi ...@@ -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) (PE_List [n,PE_Ident sub,PE_Basic (BVInt 1)]),n2)
-> (transformed_generator,Yes (i,[size_expression:size_expressions]),0,ca) -> (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 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 # (n, ca) = prefixAndPositionToIdentExp "g_s" gen_position ca
(gen_var_case1, ca) = prefixAndPositionToIdent "g_c1" gen_position ca (gen_var_case1, ca) = prefixAndPositionToIdent "g_c1" gen_position ca
(gen_var_case2, ca) = prefixAndPositionToIdent "g_c2" 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_ ...@@ -632,7 +636,8 @@ transformGenerator {gen_kind, gen_expr=PE_Sequ (SQ_FromTo pd_from_to_index from_
} }
= (transformed_generator,index_generator,0,ca) = (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 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_case1, ca) = prefixAndPositionToIdent "g_c1" gen_position ca
(gen_var_case2, ca) = prefixAndPositionToIdent "g_c2" gen_position ca (gen_var_case2, ca) = prefixAndPositionToIdent "g_c2" gen_position ca
| is_zero_expression from_exp | is_zero_expression from_exp
...@@ -934,20 +939,26 @@ makeUpdateOrSizeComprehension transformed_qualifiers success identExprs result_e ...@@ -934,20 +939,26 @@ makeUpdateOrSizeComprehension transformed_qualifiers success identExprs result_e
size_of_generator_can_be_computed_quickly {gen_pattern,gen_kind=IsArrayGenerator} size_of_generator_can_be_computed_quickly {gen_pattern,gen_kind=IsArrayGenerator}
= pattern_will_always_match gen_pattern = pattern_will_always_match gen_pattern
size_of_generator_can_be_computed_quickly {gen_pattern,gen_kind=IsListGenerator,gen_expr=PE_Sequ (SQ_FromTo PD_FromTo (PE_Basic (BVInt 0)) to_exp)} size_of_generator_can_be_computed_quickly {gen_pattern,gen_kind=IsListGenerator,gen_expr=PE_Sequ (SQ_FromTo PD_FromTo (PE_Basic (BVInt 0)) to_exp)}
= pattern_will_always_match gen_pattern = 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)} 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 = 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)} 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 = 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)} size_of_generator_can_be_computed_quickly {gen_pattern,gen_kind=IsOverloadedListGenerator,gen_expr=PE_Sequ (SQ_From _ from_exp)}
= pattern_will_always_match gen_pattern = pattern_will_always_match gen_pattern
size_of_generator_can_be_computed_quickly _ size_of_generator_can_be_computed_quickly _
= False = False
size_of_generators_can_be_computed_quickly qualifiers=:[qualifier=:{qual_generators,qual_filter=No}] 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) = All size_of_generator_can_be_computed_quickly qual_generators && not (All is_from_generator qual_generators)
where 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 = True
is_from_generator {gen_pattern,gen_kind=IsOverloadedListGenerator,gen_expr=PE_Sequ (SQ_From _ from_exp)} is_from_generator {gen_pattern,gen_kind=IsOverloadedListGenerator,gen_expr=PE_Sequ (SQ_From _ from_exp)}
= True = True
......
...@@ -50,6 +50,7 @@ instance <<< FilePosition ...@@ -50,6 +50,7 @@ instance <<< FilePosition
| BackSlashToken // \ | BackSlashToken // \
| DoubleBackSlashToken // \\ | DoubleBackSlashToken // \\
| LeftArrowToken // <- | LeftArrowToken // <-
| LeftArrowWithExclamationToken // <-
| LeftArrowColonToken // <-: | LeftArrowColonToken // <-:
| LeftArrowWithBarToken // <|- | LeftArrowWithBarToken // <|-
| DotDotToken // .. | DotDotToken // ..
......
...@@ -131,6 +131,7 @@ ScanOptionNoNewOffsideForSeqLetBit:==4; ...@@ -131,6 +131,7 @@ ScanOptionNoNewOffsideForSeqLetBit:==4;
| BackSlashToken // \ | BackSlashToken // \
| DoubleBackSlashToken // \\ | DoubleBackSlashToken // \\
| LeftArrowToken // <- | LeftArrowToken // <-
| LeftArrowWithExclamationToken // <-
| LeftArrowColonToken // <-: | LeftArrowColonToken // <-:
| LeftArrowWithBarToken // <|- | LeftArrowWithBarToken // <|-
| DotDotToken // .. | DotDotToken // ..
...@@ -651,19 +652,31 @@ Scan c0=:'<' input co ...@@ -651,19 +652,31 @@ Scan c0=:'<' input co
# (eof, c1, input) = ReadNormalChar input # (eof, c1, input) = ReadNormalChar input
| eof = (IdentToken "<", input) | eof = (IdentToken "<", input)
| c1 <> '-' | c1 <> '-'
| c1<>'|' | c1=='|'
# (eof, c2, input) = ReadNormalChar input
| eof
= (IdentToken "<|",input)
| c2=='-'
# (eof, c3, input) = ReadNormalChar input
| eof = (LeftArrowWithBarToken, input)
| isSpecialChar c3 = ScanOperator 3 input [c3, c2, c1, c0] co
= (LeftArrowWithBarToken, charBack input)
| 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 = ScanOperator 0 (charBack input) [c0] co
# (eof, c2, input) = ReadNormalChar input
| eof
= (IdentToken "<|",input)
| c2=='-'
# (eof, c3, input) = ReadNormalChar input
| eof = (LeftArrowWithBarToken, input)
| isSpecialChar c3 = ScanOperator 3 input [c3, c2, c1, c0] co
= (LeftArrowWithBarToken, charBack input)
| isSpecialChar c2
= ScanOperator 2 input [c2, c1, c0] co
= (IdentToken "<|", charBack input)
# (eof, c2, input) = ReadNormalChar input # (eof, c2, input) = ReadNormalChar input
| eof = (LeftArrowToken, input) | eof = (LeftArrowToken, input)
| c2 == ':' | c2 == ':'
...@@ -1653,6 +1666,7 @@ where ...@@ -1653,6 +1666,7 @@ where
toString BackSlashToken = "\\" toString BackSlashToken = "\\"
toString DoubleBackSlashToken = "\\\\" toString DoubleBackSlashToken = "\\\\"
toString LeftArrowToken = "<-" toString LeftArrowToken = "<-"
toString LeftArrowWithExclamationToken = "<!-"
toString LeftArrowColonToken = "<-:" toString LeftArrowColonToken = "<-:"
toString LeftArrowWithBarToken = "<|-" toString LeftArrowWithBarToken = "<|-"
toString DotDotToken = ".." toString DotDotToken = ".."
......
...@@ -1322,7 +1322,7 @@ instance toString KindInfo ...@@ -1322,7 +1322,7 @@ instance toString KindInfo
:: ArrayKind = OverloadedArray | StrictArray | UnboxedArray | PackedArray; :: ArrayKind = OverloadedArray | StrictArray | UnboxedArray | PackedArray;
:: GeneratorKind = IsListGenerator | IsOverloadedListGenerator | IsArrayGenerator :: GeneratorKind = IsListGenerator | IsStrictListGenerator | IsOverloadedListGenerator | IsArrayGenerator
:: LineAndColumn = {lc_line :: !Int, lc_column :: !Int} :: LineAndColumn = {lc_line :: !Int, lc_column :: !Int}
......
...@@ -333,6 +333,7 @@ where ...@@ -333,6 +333,7 @@ where
= file <<< gen_pattern <<< (gen_kind_to_string gen_kind) <<< gen_expr = file <<< gen_pattern <<< (gen_kind_to_string gen_kind) <<< gen_expr
where where
gen_kind_to_string IsListGenerator = "<-" gen_kind_to_string IsListGenerator = "<-"
gen_kind_to_string IsStrictListGenerator = "<!-"
gen_kind_to_string IsOverloadedListGenerator = "<|-" gen_kind_to_string IsOverloadedListGenerator = "<|-"
gen_kind_to_string IsArrayGenerator = "<-:" 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