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 whereEis an identifier for an exception type, andeis the exception data -
try <...> catch (E1 e1) <...> catch (E2 e2) <...> finally <...> yrtstatement with optionalcatchandfinallyblocks
The semantics are derived from Java, in particular:
-
the
finallyblock is always triggered when the control flow leaves thetryblock or itscatchblocks (indcludingreturnstatements); -
throwing an exception from a
tryorcatchgoes through thefinallyblock as well; -
throwing an exception from a
finallyblock 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).