compilers-course
compilers-course copied to clipboard
Practical part of the compilers course
compilers-course
Practical part of the compilers course (2017)
Common tasks and tests
The common tasks are tested with JUnit Parameterized
tests generated from
anlun/comiler-tests
, see FileTestCases.kt
. There's also a pack of my own tests in the same source set.
Implementation details
To precisely track boxed and unboxed values, the x86 back-end stores each value along with its kind (which is either scalar or reference).
The value kind is also passed to and returned from functions (the intrinsics show this in their signatures) along with the value. A type is returned
from a function in the ebx
register.
Memory management is done through reference counting. There's a memory stress test here: arrayMemoryStressTest
.
Personal task – Java-like exceptions
Check the ExceptionTestCases.kt. The following is supported:
-
throw (E e)
statement whereE
is an identifier for an exception type, ande
is the exception data -
try <...> catch (E1 e1) <...> catch (E2 e2) <...> finally <...> yrt
statement with optionalcatch
andfinally
blocks
The semantics are derived from Java, in particular:
-
the
finally
block is always triggered when the control flow leaves thetry
block or itscatch
blocks (indcludingreturn
statements); -
throwing an exception from a
try
orcatch
goes through thefinally
block as well; -
throwing an exception from a
finally
block replaces the currently uncaught exception with a new one (no suppressed exceptions for now);
The implementation tracks exit points within the scopes and compiles them into if-else-if-like catch blocks. The exception type is returned by writing to the caller's stack frame (the value is returned normally).