Skip to content

Commit

Permalink
Fix #685.
Browse files Browse the repository at this point in the history
  • Loading branch information
athas committed Dec 23, 2018
1 parent ad638ec commit b47154b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/Futhark/Test/Values.hs
Original file line number Diff line number Diff line change
Expand Up @@ -358,15 +358,15 @@ readFloat f t = do
readFloat32 :: ReadValue Float
readFloat32 = readFloat lexFloat32
where lexFloat32 [F32LIT x] = Just x
lexFloat32 [ID "f32", DOT, ID "inf"] = Just $ 1/0
lexFloat32 [ID "f32", DOT, ID "nan"] = Just $ 0/0
lexFloat32 [ID "f32", PROJ_FIELD "inf"] = Just $ 1/0
lexFloat32 [ID "f32", PROJ_FIELD "nan"] = Just $ 0/0
lexFloat32 _ = Nothing

readFloat64 :: ReadValue Double
readFloat64 = readFloat lexFloat64
where lexFloat64 [F64LIT x] = Just x
lexFloat64 [ID "f64", DOT, ID "inf"] = Just $ 1/0
lexFloat64 [ID "f64", DOT, ID "nan"] = Just $ 0/0
lexFloat64 [ID "f64", PROJ_FIELD "inf"] = Just $ 1/0
lexFloat64 [ID "f64", PROJ_FIELD "nan"] = Just $ 0/0
lexFloat64 _ = Nothing

readBool :: ReadValue Bool
Expand Down
7 changes: 5 additions & 2 deletions src/Language/Futhark/Parser/Lexer.x
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ tokens :-
"_" { tokenC UNDERSCORE }
"->" { tokenC RIGHT_ARROW }
":" { tokenC COLON }
"." { tokenC DOT }
"\" { tokenC BACKSLASH }
"'" { tokenC APOSTROPHE }
"'^" { tokenC APOSTROPHE_THEN_HAT }
Expand Down Expand Up @@ -118,6 +117,9 @@ tokens :-
@binop { tokenM $ return . symbol [] . nameFromText }
@qualbinop { tokenM $ \s -> do (qs,k) <- mkQualId s; return (symbol qs k) }
"." (@identifier|[0-9]+) { tokenM $ return . PROJ_FIELD . nameFromText . T.drop 1 }
"." "[" { tokenC PROJ_INDEX }
{
keyword :: T.Text -> Token
Expand Down Expand Up @@ -298,6 +300,8 @@ data Token = ID Name
| QUALUNOP [Name] Name
| SYMBOL BinOp [Name] Name
| CONSTRUCTOR Name
| PROJ_FIELD Name
| PROJ_INDEX
| INTLIT Integer
| STRINGLIT String
Expand All @@ -319,7 +323,6 @@ data Token = ID Name
| APOSTROPHE
| APOSTROPHE_THEN_HAT
| BACKTICK
| DOT
| TWO_DOTS
| TWO_DOTS_LT
| TWO_DOTS_GT
Expand Down
10 changes: 6 additions & 4 deletions src/Language/Futhark/Parser/Parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ import Language.Futhark.Parser.Lexer

constructor { L _ (CONSTRUCTOR _) }

'.field' { L _ (PROJ_FIELD _) }
'.[' { L _ PROJ_INDEX }

intlit { L _ (INTLIT _) }
i8lit { L _ (I8LIT _) }
i16lit { L _ (I16LIT _) }
Expand Down Expand Up @@ -138,7 +141,6 @@ import Language.Futhark.Parser.Lexer
entry { L $$ ENTRY }
'->' { L $$ RIGHT_ARROW }
':' { L $$ COLON }
'.' { L $$ DOT }
for { L $$ FOR }
do { L $$ DO }
with { L $$ WITH }
Expand Down Expand Up @@ -634,8 +636,8 @@ Atom : PrimLit { Literal (fst $1) (snd $1) }
| '(' FieldAccess FieldAccesses ')'
{ ProjectSection (map fst ($2:$3)) NoInfo (srcspan $1 $>) }

| '(' '.' '[' DimIndices ']' ')'
{ IndexSection $4 NoInfo (srcspan $1 $>) }
| '(' '.[' DimIndices ']' ')'
{ IndexSection $3 NoInfo (srcspan $1 $>) }


PrimLit :: { (PrimValue, SrcLoc) }
Expand Down Expand Up @@ -668,7 +670,7 @@ Exps1_ :: { ([UncheckedExp], UncheckedExp) }
| Exp { ([], $1) }

FieldAccess :: { (Name, SrcLoc) }
: '.' FieldId { (fst $2, srcspan $1 (snd $>)) }
: '.field' { let L loc (PROJ_FIELD f) = $1 in (f, loc) }

FieldAccesses :: { [(Name, SrcLoc)] }
: FieldAccess FieldAccesses { $1 : $2 }
Expand Down
2 changes: 1 addition & 1 deletion tests/proj3.fut
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Can we map a deeper tuple projection?
-- Can we map a deeper record projection?
-- ==
-- input { [1,2] [3,4] }
-- output { [1,2] }
Expand Down
7 changes: 7 additions & 0 deletions tests/proj4.fut
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Can we map a deeper tuple projection?
-- ==
-- input { [1,2] [3,4] }
-- output { [1,2] }

let main (xs: []i32) (ys: []i32): []i32 =
map (.1.1) (map2 (\x y -> ((x,x), y)) xs ys)

0 comments on commit b47154b

Please sign in to comment.