-
Notifications
You must be signed in to change notification settings - Fork 25
Reformat using scalafmt
#41
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
Open
Kraks
wants to merge
1
commit into
master
Choose a base branch
from
reformatting
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| version = 2.6.4 | ||
| maxColumn = 120 | ||
| align.preset = none | ||
| assumeStandardLibraryStripMargin = true | ||
| align.stripMargin = true | ||
| optIn.configStyleArguments = true | ||
| runner.optimizer.forceConfigStyleOnOffset = 5 | ||
| runner.optimizer.forceConfigStyleMinArgCount = 10 | ||
| newlines.alwaysBeforeMultilineDef = false | ||
| newlines.alwaysBeforeElseAfterCurlyIf = false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.0") // "2.4.0" is just sbt plugin version |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,28 +10,43 @@ import lms.macros.SourceContext | |
|
|
||
| trait ArrayOps { b: Base => | ||
|
|
||
| def NewArray[T:Manifest](x: Rep[Int]): Rep[Array[T]] = { | ||
| def NewArray[T: Manifest](x: Rep[Int]): Rep[Array[T]] = { | ||
| Wrap[Array[T]](Adapter.g.reflectMutable("NewArray", Unwrap(x))) | ||
| } | ||
| def Array[T:Manifest](xs: Rep[T]*): Rep[Array[T]] = { | ||
| Wrap[Array[T]](Adapter.g.reflectMutable("Array", xs.map(Unwrap(_)):_*)) | ||
| def Array[T: Manifest](xs: Rep[T]*): Rep[Array[T]] = { | ||
| Wrap[Array[T]](Adapter.g.reflectMutable("Array", xs.map(Unwrap(_)): _*)) | ||
| } | ||
| implicit class ArrayOps[A:Manifest](x: Rep[Array[A]]) { | ||
| def apply(i: Rep[Int]): Rep[A] = x match { | ||
| case Wrap(_) => Wrap[A](Adapter.g.reflectRead("array_get", Unwrap(x), Unwrap(i))(Unwrap(x))) | ||
| case EffectView(x, base) => Wrap[A](Adapter.g.reflectRead("array_get", Unwrap(x), Unwrap(i))(Unwrap(base))) | ||
| } | ||
| def update(i: Rep[Int], y: Rep[A]): Unit = x match { | ||
| case Wrap(_) => Adapter.g.reflectWrite("array_set", Unwrap(x), Unwrap(i), Unwrap(y))(Unwrap(x)) | ||
| case EffectView(x, base) => Adapter.g.reflectWrite("array_set", Unwrap(x), Unwrap(i), Unwrap(y))(Unwrap(base)) | ||
| } | ||
| implicit class ArrayOps[A: Manifest](x: Rep[Array[A]]) { | ||
| def apply(i: Rep[Int]): Rep[A] = | ||
| x match { | ||
| case Wrap(_) => Wrap[A](Adapter.g.reflectRead("array_get", Unwrap(x), Unwrap(i))(Unwrap(x))) | ||
| case EffectView(x, base) => Wrap[A](Adapter.g.reflectRead("array_get", Unwrap(x), Unwrap(i))(Unwrap(base))) | ||
| } | ||
| def update(i: Rep[Int], y: Rep[A]): Unit = | ||
| x match { | ||
| case Wrap(_) => Adapter.g.reflectWrite("array_set", Unwrap(x), Unwrap(i), Unwrap(y))(Unwrap(x)) | ||
| case EffectView(x, base) => Adapter.g.reflectWrite("array_set", Unwrap(x), Unwrap(i), Unwrap(y))(Unwrap(base)) | ||
| } | ||
| def length: Rep[Int] = Wrap[Int](Adapter.g.reflect("array_length", Unwrap(x))) | ||
| def slice(s: Rep[Int], e: Rep[Int]): Rep[Array[A]] = EffectView[Array[A]](Wrap[Array[A]](Adapter.g.reflect("array_slice", Unwrap(x), Unwrap(s), Unwrap(e))), x) // (Unwrap(x), Adapter.STORE)()) | ||
| def slice(s: Rep[Int], e: Rep[Int]): Rep[Array[A]] = | ||
| EffectView[Array[A]]( | ||
| Wrap[Array[A]](Adapter.g.reflect("array_slice", Unwrap(x), Unwrap(s), Unwrap(e))), | ||
| x | ||
| ) // (Unwrap(x), Adapter.STORE)()) | ||
| def free: Unit = Adapter.g.reflectFree("array_free", Unwrap(x))(Unwrap(x)) | ||
| def copyToArray(arr: Rep[Array[A]], start: Rep[Int], len: Rep[Int]) = Adapter.g.reflectEffect("array_copyTo", Unwrap(x), Unwrap(arr), Unwrap(start), Unwrap(len))(Unwrap(x))(Unwrap(arr)) | ||
| def copyToLongArray(arr: Rep[LongArray[A]], start: Rep[Long], len: Rep[Int]) = Adapter.g.reflectEffect("array_copyTo", Unwrap(x), Unwrap(arr), Unwrap(start), Unwrap(len))(Unwrap(x))(Unwrap(arr)) | ||
| def copyToArray(arr: Rep[Array[A]], start: Rep[Int], len: Rep[Int]) = | ||
| Adapter.g.reflectEffect("array_copyTo", Unwrap(x), Unwrap(arr), Unwrap(start), Unwrap(len))(Unwrap(x))( | ||
| Unwrap(arr) | ||
| ) | ||
| def copyToLongArray(arr: Rep[LongArray[A]], start: Rep[Long], len: Rep[Int]) = | ||
| Adapter.g.reflectEffect("array_copyTo", Unwrap(x), Unwrap(arr), Unwrap(start), Unwrap(len))(Unwrap(x))( | ||
| Unwrap(arr) | ||
| ) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These formatting changes also don't seem like improvements to me. It may be worth looking at refactoring the code for clarity, but just putting the last |
||
| // FIXME: currently copy!! | ||
| def sort(size: Rep[Int] /* , sort: (Rep[A], Rep[A]) => Rep[Int] */) = Wrap[Array[A]](Adapter.g.reflectMutable("array_sort_scala", Unwrap(x), Unwrap(size))) //, Adapter.g.reify((x, y) => Unwrap(sort(Wrap[A](x), Wrap[A](y)))))(Unwrap(x))(Unwrap(x)) | ||
| def sort(size: Rep[Int] /* , sort: (Rep[A], Rep[A]) => Rep[Int] */ ) = | ||
| Wrap[Array[A]]( | ||
| Adapter.g.reflectMutable("array_sort_scala", Unwrap(x), Unwrap(size)) | ||
| ) //, Adapter.g.reify((x, y) => Unwrap(sort(Wrap[A](x), Wrap[A](y)))))(Unwrap(x))(Unwrap(x)) | ||
| } | ||
| implicit class CharArrayOps(x: Rep[Array[Char]]) { | ||
| def ArrayOfCharToString(): Rep[String] = { | ||
|
|
@@ -40,25 +55,33 @@ trait ArrayOps { b: Base => | |
| } | ||
|
|
||
| trait LongArray[+T] | ||
| def NewLongArray[T:Manifest](x: Rep[Long], init: Option[Int] = None): Rep[LongArray[T]] = init match { | ||
| case Some(v) => Wrap[LongArray[T]](Adapter.g.reflectMutable("NewArray", Unwrap(x), Backend.Const(v))) | ||
| case _ => Wrap[LongArray[T]](Adapter.g.reflectMutable("NewArray", Unwrap(x))) | ||
| } | ||
| def LongArray[T:Manifest](xs: Rep[T]*): Rep[LongArray[T]] = { | ||
| Wrap[LongArray[T]](Adapter.g.reflectMutable("Array", xs.map(Unwrap(_)):_*)) | ||
| } | ||
| implicit class LongArrayOps[A:Manifest](x: Rep[LongArray[A]]) { | ||
| def apply(i: Rep[Long]): Rep[A] = x match { | ||
| case Wrap(_) => Wrap[A](Adapter.g.reflectRead("array_get", Unwrap(x), Unwrap(i))(Unwrap(x))) | ||
| case EffectView(x, base) => Wrap[A](Adapter.g.reflectRead("array_get", Unwrap(x), Unwrap(i))(Unwrap(base))) | ||
| } | ||
| def update(i: Rep[Long], y: Rep[A]): Unit = x match { | ||
| case Wrap(_) => Adapter.g.reflectWrite("array_set", Unwrap(x), Unwrap(i), Unwrap(y))(Unwrap(x)) | ||
| case EffectView(x, base) => Adapter.g.reflectWrite("array_set", Unwrap(x), Unwrap(i), Unwrap(y))(Unwrap(base)) | ||
| def NewLongArray[T: Manifest](x: Rep[Long], init: Option[Int] = None): Rep[LongArray[T]] = | ||
| init match { | ||
| case Some(v) => Wrap[LongArray[T]](Adapter.g.reflectMutable("NewArray", Unwrap(x), Backend.Const(v))) | ||
| case _ => Wrap[LongArray[T]](Adapter.g.reflectMutable("NewArray", Unwrap(x))) | ||
| } | ||
| def LongArray[T: Manifest](xs: Rep[T]*): Rep[LongArray[T]] = { | ||
| Wrap[LongArray[T]](Adapter.g.reflectMutable("Array", xs.map(Unwrap(_)): _*)) | ||
| } | ||
| implicit class LongArrayOps[A: Manifest](x: Rep[LongArray[A]]) { | ||
| def apply(i: Rep[Long]): Rep[A] = | ||
| x match { | ||
| case Wrap(_) => Wrap[A](Adapter.g.reflectRead("array_get", Unwrap(x), Unwrap(i))(Unwrap(x))) | ||
| case EffectView(x, base) => Wrap[A](Adapter.g.reflectRead("array_get", Unwrap(x), Unwrap(i))(Unwrap(base))) | ||
| } | ||
| def update(i: Rep[Long], y: Rep[A]): Unit = | ||
| x match { | ||
| case Wrap(_) => Adapter.g.reflectWrite("array_set", Unwrap(x), Unwrap(i), Unwrap(y))(Unwrap(x)) | ||
| case EffectView(x, base) => Adapter.g.reflectWrite("array_set", Unwrap(x), Unwrap(i), Unwrap(y))(Unwrap(base)) | ||
| } | ||
| def length: Rep[Long] = Wrap[Long](Adapter.g.reflect("array_length", Unwrap(x))) | ||
| def slice(s: Rep[Long], e: Rep[Long] = unit(-1L)): Rep[LongArray[A]] = EffectView[LongArray[A]](Wrap[LongArray[A]](Adapter.g.reflect("array_slice", Unwrap(x), Unwrap(s), Unwrap(e))), x) // FIXME: borrowing effect? | ||
| def resize(s: Rep[Long]): Rep[LongArray[A]] = Wrap[LongArray[A]](Adapter.g.reflectRealloc("array_resize", Unwrap(x), Unwrap(s))(Unwrap(x))) | ||
| def slice(s: Rep[Long], e: Rep[Long] = unit(-1L)): Rep[LongArray[A]] = | ||
| EffectView[LongArray[A]]( | ||
| Wrap[LongArray[A]](Adapter.g.reflect("array_slice", Unwrap(x), Unwrap(s), Unwrap(e))), | ||
| x | ||
| ) // FIXME: borrowing effect? | ||
| def resize(s: Rep[Long]): Rep[LongArray[A]] = | ||
| Wrap[LongArray[A]](Adapter.g.reflectRealloc("array_resize", Unwrap(x), Unwrap(s))(Unwrap(x))) | ||
| def free: Unit = Adapter.g.reflectFree("array_free", Unwrap(x))(Unwrap(x)) | ||
| } | ||
| } | ||
|
|
@@ -68,31 +91,33 @@ trait ArrayOps { b: Base => | |
| // StackArray is the array using stack (i.e. int a[5] = {1,2,3,4,5};) | ||
| trait StackArrayOps extends ArrayOps { b: Base => | ||
|
|
||
| def NewStackArray[T:Manifest](x: Rep[Int]): Rep[Array[T]] = { | ||
| def NewStackArray[T: Manifest](x: Rep[Int]): Rep[Array[T]] = { | ||
| Wrap[Array[T]](Adapter.g.reflectMutable("NewStackArray", Unwrap(x))) | ||
| } | ||
|
|
||
| def StackArray[T:Manifest](xs: Rep[T]*): Rep[Array[T]] = { | ||
| def StackArray[T: Manifest](xs: Rep[T]*): Rep[Array[T]] = { | ||
| Wrap[Array[T]](Adapter.g.reflectMutable("StackArray", xs.map(Unwrap(_)): _*)) | ||
| } | ||
| } | ||
|
|
||
| trait CCodeGenStackArray extends ExtendedCCodeGen { | ||
|
|
||
| override def traverse(n: Node): Unit = n match { | ||
| case n @ Node(s, "NewStackArray", List(x), _) => | ||
| val tpe = remap(typeMap.get(s).map(_.typeArguments.head).getOrElse(manifest[Unknown])) | ||
| emit(s"$tpe "); shallow(s); emit("["); shallow(x); emitln("];") | ||
| case n @ Node(s, "StackArray", xs, _) => | ||
| val tpe = remap(typeMap.get(s).map(_.typeArguments.head).getOrElse(manifest[Unknown])) | ||
| emit(s"$tpe "); shallow(s); emit("[] = {"); shallow(xs.head) | ||
| xs.tail.foreach(x => {emit(", "); shallow(x)}); emitln("};") | ||
| case _ => super.traverse(n) | ||
| } | ||
| override def traverse(n: Node): Unit = | ||
| n match { | ||
| case n @ Node(s, "NewStackArray", List(x), _) => | ||
| val tpe = remap(typeMap.get(s).map(_.typeArguments.head).getOrElse(manifest[Unknown])) | ||
| emit(s"$tpe "); shallow(s); emit("["); shallow(x); emitln("];") | ||
| case n @ Node(s, "StackArray", xs, _) => | ||
| val tpe = remap(typeMap.get(s).map(_.typeArguments.head).getOrElse(manifest[Unknown])) | ||
| emit(s"$tpe "); shallow(s); emit("[] = {"); shallow(xs.head) | ||
| xs.tail.foreach(x => { emit(", "); shallow(x) }); emitln("};") | ||
| case _ => super.traverse(n) | ||
| } | ||
|
|
||
| override def mayInline(n: Node): Boolean = n match { | ||
| case Node(s, "NewStackArray", _, _) => false | ||
| case Node(s, "StackArray", _, _) => false | ||
| case _ => super.mayInline(n) | ||
| } | ||
| override def mayInline(n: Node): Boolean = | ||
| n match { | ||
| case Node(s, "NewStackArray", _, _) => false | ||
| case Node(s, "StackArray", _, _) => false | ||
| case _ => super.mayInline(n) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer the old format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean
x match {should be on the same line ofdef ...?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I tried to fix it myself but didn't got too much time to read the documentation for formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree - the
x match {should be on the same line