Skip to content

Commit

Permalink
Remove brackets around array ranges.
Browse files Browse the repository at this point in the history
Closes #445.
  • Loading branch information
athas committed Jan 28, 2018
1 parent 330308c commit dc093e3
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 37 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* Only entry points defined directly in the file given to the
compiler will be visible.

* Range literals are now written without brackets: `x...y`.

* `futhark-test` and `futhark-bench` will no longer append `.bin` to
executables.

Expand Down
11 changes: 7 additions & 4 deletions docs/language-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ literals and variables, but also more complicated forms.
: | `exp` `qualbinop` `exp`
: | `exp` `exp`
: | `exp` ":" `type`
: | `exp` [ ".." `exp` ] "..." `exp`
: | `exp` [ ".." `exp` ] "..<" `exp`
: | `exp` [ ".." `exp` ] "..>" `exp`
: | "if" `exp` "then" `exp` "else" `exp`
: | "let" `type_param`* `pat` "=" `exp` "in" `exp`
: | "let" `id` "[" `index` ("," `index`)* "]" "=" `exp` "in" `exp`
Expand Down Expand Up @@ -383,7 +386,7 @@ empty arrays must be constructed with the ``empty`` construct. This
restriction is due to limited type inference in the Futhark compiler,
and will hopefully be fixed in the future.

``[x..y...z]``
``x..y...z``
..............

Construct an integer array whose first element is ``x`` and which
Expand All @@ -392,16 +395,16 @@ proceeds stride of ``y-x`` until reaching ``z`` (inclusive). The
stride may not be zero. An empty array is returned in cases where
``z`` would never be reached or ``x`` and ``y`` are the same value.

``[x..y..<z]``
...............
``x..y..<z``
............

Construct an integer array whose first elements is ``x``, and which
proceeds upwards with a stride of ``y`` until reaching ``z``
(exclusive). The ``..y`` part can be elided in which case a stride of
1 is used. An empty array is returned in cases where ``z`` would
never be reached or ``x`` and ``y`` are the same value.

``[x..y..>z]``
``x..y..>z``
...............

Construct an integer array whose first elements is ``x``, and which
Expand Down
16 changes: 8 additions & 8 deletions futlib/math.fut
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ module i8: (size with t = i8) = {
let set_bit (bit: i32) (x: t) (b: i32) =
((x & i32 (intrinsics.~ (1 intrinsics.<< b))) | x intrinsics.<< i32 b)

let iota (n: i8) = [0i8..1i8..<n]
let iota (n: i8) = 0i8..1i8..<n
let replicate 'v (n: i8) (x: v) = map (const x) (iota n)
}

Expand Down Expand Up @@ -266,7 +266,7 @@ module i16: (size with t = i16) = {
let set_bit (bit: i32) (x: t) (b: i32) =
((x & i32 (intrinsics.~(1 intrinsics.<< b))) | x intrinsics.<< i32 b)

let iota (n: i16) = [0i16..1i16..<n]
let iota (n: i16) = 0i16..1i16..<n
let replicate 'v (n: i16) (x: v) = map (const x) (iota n)
}

Expand Down Expand Up @@ -331,7 +331,7 @@ module i32: (size with t = i32) = {
let set_bit (bit: i32) (x: t) (b: i32) =
((x & i32 (intrinsics.~(1 intrinsics.<< b))) | x intrinsics.<< i32 b)

let iota (n: i32) = [0..1..<n]
let iota (n: i32) = 0..1..<n
let replicate 'v (n: i32) (x: v) = map (const x) (iota n)
}

Expand Down Expand Up @@ -396,7 +396,7 @@ module i64: (size with t = i64) = {
let set_bit (bit: i32) (x: t) (b: i32) =
((x & i32 (intrinsics.~(1 intrinsics.<< b))) | x intrinsics.<< i32 b)

let iota (n: i64) = [0i64..1i64..<n]
let iota (n: i64) = 0i64..1i64..<n
let replicate 'v (n: i64) (x: v) = map (const x) (iota n)
}

Expand Down Expand Up @@ -461,7 +461,7 @@ module u8: (size with t = u8) = {
let set_bit (bit: i32) (x: t) (b: i32) =
((x & i32 (intrinsics.~(1 intrinsics.<< b))) | x intrinsics.<< i32 b)

let iota (n: u8) = [0u8..1u8..<n]
let iota (n: u8) = 0u8..1u8..<n
let replicate 'v (n: u8) (x: v) = map (const x) (iota n)
}

Expand Down Expand Up @@ -526,7 +526,7 @@ module u16: (size with t = u16) = {
let set_bit (bit: i32) (x: t) (b: i32) =
((x & i32 (intrinsics.~(1 intrinsics.<< b))) | x intrinsics.<< i32 b)

let iota (n: u16) = [0u16..1u16..<n]
let iota (n: u16) = 0u16..1u16..<n
let replicate 'v (n: u16) (x: v) = map (const x) (iota n)
}

Expand Down Expand Up @@ -591,7 +591,7 @@ module u32: (size with t = u32) = {
let set_bit (bit: i32) (x: t) (b: i32) =
((x & i32 (intrinsics.~(1 intrinsics.<< b))) | x intrinsics.<< i32 b)

let iota (n: u32) = [0u32..1u32..<n]
let iota (n: u32) = 0u32..1u32..<n
let replicate 'v (n: u32) (x: v) = map (const x) (iota n)
}

Expand Down Expand Up @@ -656,7 +656,7 @@ module u64: (size with t = u64) = {
let set_bit (bit: i32) (x: t) (b: i32) =
((x & i32 (intrinsics.~(1 intrinsics.<< b))) | x intrinsics.<< i32 b)

let iota (n: u64) = [0u64..1u64..<n]
let iota (n: u64) = 0u64..1u64..<n
let replicate 'v (n: u64) (x: v) = map (const x) (iota n)
}

Expand Down
18 changes: 9 additions & 9 deletions src/Language/Futhark/Parser/Parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ import Language.Futhark.Parser.Lexer
%left ifprec letprec unsafe
%left ','
%left ':'
%right '...' '..<' '..>' '..'
%left '<-'
%left '||...'
%left '&&...'
Expand Down Expand Up @@ -610,6 +611,14 @@ Exp2 :: { UncheckedExp }
| Exp2 '<=' Exp2 { binOp $1 (L $2 (SYMBOL Leq [] (nameFromString "<="))) $3 }
| Exp2 '<' Exp2 { binOp $1 (L $2 (SYMBOL Less [] (nameFromString "<"))) $3 }

| Exp2 '...' Exp2 { Range $1 Nothing (ToInclusive $3) NoInfo (srclocOf $1) }
| Exp2 '..<' Exp2 { Range $1 Nothing (UpToExclusive $3) NoInfo (srclocOf $1) }
| Exp2 '..>' Exp2 { Range $1 Nothing (DownToExclusive $3) NoInfo (srclocOf $1) }
| Exp2 '..' Exp2 '...' Exp2 { Range $1 (Just $3) (ToInclusive $5) NoInfo (srclocOf $1) }
| Exp2 '..' Exp2 '..<' Exp2 { Range $1 (Just $3) (UpToExclusive $5) NoInfo (srclocOf $1) }
| Exp2 '..' Exp2 '..>' Exp2 { Range $1 (Just $3) (DownToExclusive $5) NoInfo (srclocOf $1) }
| Exp2 '..' Atom {% twoDotsRange $2 }
| Atom '..' Exp2 {% twoDotsRange $2 }
| '-' Exp2
{ Negate $2 $1 }

Expand Down Expand Up @@ -645,13 +654,6 @@ Atom : PrimLit { Literal (fst $1) (snd $1) }
| '(' ')' { TupLit [] $1 }
| '[' Exps1 ']' { ArrayLit (fst $2:snd $2) NoInfo $1 }

| '[' Exp '...' Exp ']' { Range $2 Nothing (ToInclusive $4) NoInfo $1 }
| '[' Exp '..<' Exp ']' { Range $2 Nothing (UpToExclusive $4) NoInfo $1 }
| '[' Exp '..>' Exp ']' { Range $2 Nothing (DownToExclusive $4) NoInfo $1 }
| '[' Exp '..' Exp '...' Exp ']' { Range $2 (Just $4) (ToInclusive $6) NoInfo $1 }
| '[' Exp '..' Exp '..<' Exp ']' { Range $2 (Just $4) (UpToExclusive $6) NoInfo $1 }
| '[' Exp '..' Exp '..>' Exp ']' { Range $2 (Just $4) (DownToExclusive $6) NoInfo $1 }

| QualVarSlice { let (v,slice,loc) = $1
in Index (Var v NoInfo loc) slice loc }
| QualName FieldAccesses
Expand Down Expand Up @@ -681,8 +683,6 @@ Atom : PrimLit { Literal (fst $1) (snd $1) }
| '[' ']'
{% emptyArrayError $1 }

| '[' Exp '..' Exp ']' {% twoDotsRange $1 }

Atoms1 :: { (UncheckedExp, [UncheckedExp]) }
: Atom Atoms1 { ($1, fst $2 : snd $2) }
| Atom { ($1, []) }
Expand Down
2 changes: 1 addition & 1 deletion tests/distribution/icfp16-example.fut
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let main [n][m] (pss: [n][m]i32): ([n][m][m]i32, [n][m]i32) =
let (asss, bss) =
unzip(map (\(ps: []i32): ([m][m]i32, [m]i32) ->
let ass = map (\(p: i32): [m]i32 ->
let cs = scan (+) 0 [0..1..<p]
let cs = scan (+) 0 (0..1..<p)
let f = reduce (+) 0 cs
let as = map (+f) ps
in as) ps
Expand Down
12 changes: 6 additions & 6 deletions tests/range0.fut
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
-- }

let main (start: i32) (step: i32) (end: i32) =
([start...end],
[start..<end],
[start..>end],
[start..step...end],
[start..step..<end],
[start..step..>end])
(start...end,
start..<end,
start..>end,
start..step...end,
start..step..<end,
start..step..>end)
6 changes: 3 additions & 3 deletions tests/range1.fut
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@
-- }

let main(start: i32)(end: i32) =
([start..start...end],
[start..start..<end],
[start..start..>end])
(start..start...end,
start..start..<end,
start..start..>end)
12 changes: 6 additions & 6 deletions tests/range2.fut
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@
-- }

let main (start: u8) (step: u8) (end: u8) =
([start...end],
[start..<end],
[start..>end],
[start..step...end],
[start..step..<end],
[start..step..>end])
(start...end,
start..<end,
start..>end,
start..step...end,
start..step..<end,
start..step..>end)

0 comments on commit dc093e3

Please sign in to comment.