|
165 | 165 | "\n", |
166 | 166 | "If you make a mistake and mix up `UInt` and `Int` or `Bool` and `Boolean`, the Scala compiler will generally catch it for you.\n", |
167 | 167 | "This is because of Scala's static typing.\n", |
168 | | - "At compile time, the compiler is able to distinguish between Chisel and Scala types and understand that `if ()` expects a `Boolean` and `when ()` expects a `Bool`.\n" |
| 168 | + "At compile time, the compiler is able to distinguish between Chisel and Scala types and also able to understand that `if ()` expects a `Boolean` and `when ()` expects a `Bool`.\n" |
169 | 169 | ] |
170 | 170 | }, |
171 | 171 | { |
|
288 | 288 | "metadata": {}, |
289 | 289 | "source": [ |
290 | 290 | "It is good to remember that Chisel types generally should not be value matched.\n", |
291 | | - "Scala's match executes during circuit elaboration, but what you probably want is an post-elaboration comparison.\n", |
| 291 | + "Scala's match executes during circuit elaboration, but what you probably want is a post-elaboration comparison.\n", |
292 | 292 | "The following gives a syntax error:" |
293 | 293 | ] |
294 | 294 | }, |
|
367 | 367 | "cell_type": "markdown", |
368 | 368 | "metadata": {}, |
369 | 369 | "source": [ |
370 | | - "If you look at the `delay` function, you should note that addition to matching on the type of each character, we are also:\n", |
371 | | - "- Directly reference internal values of the parameters\n", |
| 370 | + "If you look at the `delay` function, you should note that in addition to matching on the type of each character, we are also:\n", |
| 371 | + "- Directly referencing internal values of the parameters\n", |
372 | 372 | "- Sometimes, are matching directly on the internal values of the parameters\n", |
373 | 373 | "\n", |
374 | 374 | "These are possible due to the compiler implementing an `unapply` method. Note that unapplying the case is just syntactic sugar; e.g. the following two cases examples are equivalent:\n", |
|
429 | 429 | "\n", |
430 | 430 | "Partial functions can be chained together with `orElse`.\n", |
431 | 431 | "\n", |
432 | | - "Note that calling a `PartialFunction` with a undefined input will result in a runtime error. This can happen, for example, if the input to the `PartialFunction` is user-defined. To be more type-safe, we recommend writing functions that return an `Option` instead." |
| 432 | + "Note that calling a `PartialFunction` with an undefined input will result in a runtime error. This can happen, for example, if the input to the `PartialFunction` is user-defined. To be more type-safe, we recommend writing functions that return an `Option` instead." |
433 | 433 | ] |
434 | 434 | }, |
435 | 435 | { |
|
542 | 542 | "\n", |
543 | 543 | "This section will just get your toes wet; to understand more, check out [this tutorial](https://twitter.github.io/scala_school/type-basics.html).\n", |
544 | 544 | "\n", |
545 | | - "Classes can be polymorphic in their types. One good example are sequences, which require knowing what the type of the elements it contains." |
| 545 | + "Classes can be polymorphic in their types. One good example is sequences, which require knowing their contained type." |
546 | 546 | ] |
547 | 547 | }, |
548 | 548 | { |
|
621 | 621 | "\n", |
622 | 622 | "`chisel3.Data` is the base class for Chisel hardware types.\n", |
623 | 623 | "`UInt`, `SInt`, `Vec`, `Bundle`, etc. are all instances of `Data`.\n", |
624 | | - "`Data` can be used in IOs and support `:=`, wires, regs, etc.\n", |
| 624 | + "`Data` can be used in IOs and supports `:=`, wires, regs, etc.\n", |
625 | 625 | "\n", |
626 | 626 | "Registers are a good example of polymorphic code in Chisel.\n", |
627 | 627 | "Look at the implementation of `RegEnable` (a register with a `Bool` enable signal) [here](https://github.com/freechipsproject/chisel3/blob/v3.0.0/src/main/scala/chisel3/util/Reg.scala#L10).\n", |
|
644 | 644 | "These operations cannot be done on arbitrary objects; for example wire := 3 is illegal because 3 is a Scala Int, not a Chisel UInt.\n", |
645 | 645 | "If we use a type constraint to say that type T is a subclass of Data, then we can use := on any objects of type T because := is defined for all Data.\n", |
646 | 646 | "\n", |
647 | | - "Here is an implementations of a shift register that take types as a parameter.\n", |
| 647 | + "Here is an implementation of a shift register that take types as a parameter.\n", |
648 | 648 | "*gen* is an argument of type T that tells what width to use, for example new ShiftRegister(UInt(4.W)) is a shift register for 4-bit UInts.\n", |
649 | 649 | "*gen* also allows the Scala compiler to infer the type T- you can write new ShiftRegister[UInt](UInt(4.W)) if you want to to be more specific, but the Scala compiler is smart enough to figure it out if you leave out the [UInt]." |
650 | 650 | ] |
|
760 | 760 | "source": [ |
761 | 761 | "object Mac {\n", |
762 | 762 | " def apply[T <: Data : Ring](a: T, b: T, c: T): T = {\n", |
| 763 | + " ??? // your code\n", |
763 | 764 | " }\n", |
764 | 765 | "}\n", |
765 | 766 | "\n", |
|
819 | 820 | " val out = Output(genReg)\n", |
820 | 821 | " })\n", |
821 | 822 | " \n", |
822 | | - " val reg = RegInit(genReg, Ring[T].zero) // init to zero\n", |
823 | | - " reg := reg + io.in\n", |
824 | | - " io.out := reg\n", |
| 823 | + " ??? // your code\n", |
825 | 824 | "}\n", |
826 | 825 | "\n", |
827 | 826 | "test(new Integrator(SInt(4.W), SInt(8.W))) { c =>\n", |
|
0 commit comments