Skip to content

Commit 559ed91

Browse files
committed
fix TODOs
1 parent e39b012 commit 559ed91

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ project/plugins/project/
2121
# Tmp files
2222
*.tac
2323
*.s
24+
*.jar
2425
TestCases/
2526
src/main/antlr4/.antlr/
2627

28+
# No MS docs
29+
*.doc
30+
*.docx

src/main/scala/decaf/frontend/typecheck/Typer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ class Typer(implicit config: Config) extends Phase[Tree, Tree]("typer", config)
243243
case Syn.NewArray(elemType, length) =>
244244
val t = typeTypeLit(elemType)
245245
val l = typeExpr(length)
246-
if (t.typ.isVoidType) issue(new BadArrElementError(elemType.pos)) // TODO: err
247-
if (l.typ !== IntType) issue(new BadNewArrayLength(length.pos)) // TODO: if no error
246+
if (t.typ.isVoidType) issue(new BadArrElementError(elemType.pos))
247+
if (l.typ !== IntType) issue(new BadNewArrayLength(length.pos))
248248
NewArray(t, l)(ArrayType(t.typ)) // make a fair guess
249249

250250
case Syn.NewClass(id) =>

src/main/scala/decaf/jvm/Util.scala

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,34 @@ import decaf.frontend.annot._
44
import decaf.frontend.tree.TreeNode
55
import org.objectweb.asm.{Label, MethodVisitor, Opcodes, Type => ASMType}
66

7+
/**
8+
* Utilities for emitting JVM bytecode.
9+
*/
710
trait Util {
811

12+
/**
13+
* Internal name of Java's super class -- the well-known `java.lang.Object`.
14+
*/
915
val JAVA_SUPER_INTERNAL_NAME = ASMType.getInternalName(classOf[java.lang.Object])
16+
17+
/**
18+
* Default name of constructors.
19+
*/
1020
val CONSTRUCTOR_NAME = "<init>"
21+
22+
/**
23+
* Type descriptor of constructors.
24+
*/
1125
val CONSTRUCTOR_DESC = ASMType.getMethodDescriptor(ASMType.VOID_TYPE)
26+
27+
/**
28+
* Type descriptor of main method.
29+
*/
1230
val MAIN_DESCRIPTOR: String = "([Ljava/lang/String;)V"
1331

1432
/**
33+
* Emit bytecode for if-then-else branching. The boolean value of condition shall now be on the stack top.
34+
* Pseudo code:
1535
* {{{
1636
* if != 0 goto true
1737
* falseBranch
@@ -20,6 +40,10 @@ trait Util {
2040
* trueBranch
2141
* exit:
2242
* }}}
43+
*
44+
* @param trueBranch code (to be generated) of the true branch
45+
* @param falseBranch code (to be generated) of the true branch
46+
* @param mv method visitor
2347
*/
2448
def ifThenElse(trueBranch: => Unit, falseBranch: => Unit)(implicit mv: MethodVisitor): Unit = {
2549
val trueLabel = new Label
@@ -34,6 +58,8 @@ trait Util {
3458
}
3559

3660
/**
61+
* Emit bytecode for while-loop.
62+
* Pseudo code:
3763
* {{{
3864
* enter:
3965
* cond
@@ -43,9 +69,10 @@ trait Util {
4369
* exit:
4470
* }}}
4571
*
46-
* @param body
47-
* @param exit
48-
* @param mv
72+
* @param cond code (to be generated) for evaluating the condition
73+
* @param body code (to be generated) of the loop body
74+
* @param exit label of loop exit
75+
* @param mv method visitor
4976
*/
5077
def loop(cond: => Unit, exit: Label)(body: => Unit)(implicit mv: MethodVisitor): Unit = {
5178
val enter = new Label
@@ -114,6 +141,7 @@ trait Util {
114141
ASMType.getMethodDescriptor(system_out.getDeclaredMethod("print", string)), false)
115142
}
116143

144+
/** Translate a Decaf type to JVM assembly type. */
117145
def toASMType(typ: Type): ASMType = typ match {
118146
case IntType => ASMType.INT_TYPE
119147
case BoolType => ASMType.BOOLEAN_TYPE
@@ -125,15 +153,15 @@ trait Util {
125153
}
126154

127155
/**
128-
* Get the ASM internal name of a class symbol.
156+
* Get the internal name of a class symbol.
129157
*
130158
* @param clazz the class symbol
131159
* @return its internal name
132160
*/
133161
def internalName(clazz: ClassSymbol): String = toASMType(clazz.typ).getInternalName
134162

135163
/**
136-
* Get the JVM (type) descriptor of a field symbol.
164+
* Get the (type) descriptor of a field symbol.
137165
* See https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.3 for descriptor syntax.
138166
*
139167
* @param field the field symbol, i.e. member var/method

0 commit comments

Comments
 (0)