|
1 | | -# Decaf in Scala |
| 1 | +# The Decaf Compiler, in Scala |
2 | 2 |
|
3 | | -Rewriting the Decaf compiler in Scala. |
| 3 | +Decaf is a Java-like, but much smaller programming language mainly for educational purpose. |
| 4 | +We now have at least three different implementations of the compiler in Java, Scala and Rust. |
| 5 | +Since the standard language has quite a limited set of language features, students are welcome to add their own new features. |
4 | 6 |
|
5 | | -Implementing... |
| 7 | +## Getting Started |
| 8 | + |
| 9 | +This project requires JDK 12, because the package `decaf.lowlevel` is shared with Java's. |
| 10 | + |
| 11 | +Other dependencies will be automatically downloaded from the maven central repository by the build script. |
| 12 | + |
| 13 | +## Build |
| 14 | + |
| 15 | +Type standard [sbt](https://www.scala-sbt.org) commands after you launch the REPL with `sbt`. |
| 16 | + |
| 17 | +To compile, type: |
| 18 | + |
| 19 | +``` |
| 20 | +sbt:decaf-in-scala> compile |
| 21 | +``` |
| 22 | + |
| 23 | +To build a standalone jar, type: |
| 24 | + |
| 25 | +``` |
| 26 | +sbt:decaf-in-scala> assembly |
| 27 | +``` |
| 28 | + |
| 29 | +To start a scala REPL, type: |
| 30 | + |
| 31 | +``` |
| 32 | +sbt:decaf-in-scala> console |
| 33 | +``` |
| 34 | + |
| 35 | +Or, import the project in IDEA and use sbt plugin, if available. |
| 36 | + |
| 37 | +## Run |
| 38 | + |
| 39 | +In sbt console, type: |
| 40 | + |
| 41 | +``` |
| 42 | +sbt:decaf-in-scala> run --help |
| 43 | +``` |
| 44 | + |
| 45 | +to show the usage help. Or you first build a standalone jar and run it in CLI. |
| 46 | + |
| 47 | +Possible targets/tasks are: |
| 48 | + |
| 49 | +- PA1: parse source code and output the pretty printed tree, or error messages |
| 50 | +- PA2: type check and output the pretty printed scopes, or error messages |
| 51 | +- PA3: generate TAC (three-address code), dump it to a .tac file, and then output the execution result using our built-in simulator |
| 52 | +- PA3-JVM: generate JVM bytecode |
| 53 | +- PA4: currently same with PA3, will be reserved for students to do a bunch of optimizations on TAC |
| 54 | +- PA5: (default target) allocate registers and emit assembly code, currently we are using a very brute-force algorithm and only generates MIPS assembly code (with pseudo-ops, and no delayed branches) |
| 55 | + |
| 56 | +To run the MIPS assembly code, you may need [spim](http://spimsimulator.sourceforge.net), a MIPS32 simulator. |
| 57 | +For Mac OS users, simply install `spim` with `brew install spim` and run with `spim -file your_file.s`. |
0 commit comments