Classes and Objects

Templates

Classes and objects are both defined in terms of templates, whose body is represented using BLOCK(...) in treehugger DSL.

In general, treehugger DSL uses BLOCK(...) wherever curly braces ({}) appear in Scala. BLOCK(...) accepts vararg of trees, such as class member definitions and expressions:

val IntQueue: ClassSymbol = RootClass.newClass("IntQueue")
 
CLASSDEF(IntQueue) withFlags(Flags.ABSTRACT) := BLOCK(
  DEF("get", IntClass),
  DEF("put") withParams(PARAM("x", IntClass))
)

This example prints as:

abstract class IntQueue {
  def get: Int
  def put(x: Int)
}