I. Introduction, 5 mins., 10:05 to 10:10 More "fun with evaluators:" implementing the core of Java, using Scheme, based on ideas from the Scheme evaluator. - Different syntax, same semantics - Cut out a lot of stuff - Concentrating on flow of control and method lookup II. Review of flow problem, 5 mins., 10:10 to 10:15 SLIDE 1: Old implementation of CATCH and OOPS Note that we went back to the direct EVAL implementation, not the analyze version. SLIDE 2: Bug III. Fixing the Problem, 10 mins, 10:15 to 10:25 SLIDE 3: Eval-Sequence SLIDE 4: J-EVAL-OOPS and J-EVAL-BLOCK IV. Syntax of Decaf Java-In-Scheme, 10 mins, 10:25 to 10:35 SLIDE 5: Syntax, part 1 SLIDE 6: Syntax, part 2 SLIDE 7: Syntax, part 3 SLIDE 8: Syntax, examples V. Implementation Overview, 10 mins., 10:35 to 10:45 There are two kinds of things at runtime: classes and objects. These are represented by Scheme data structures (see java-support.scm). What's in an Object? BOARD: /--------------------------------------------+ v | +---------+ | | OBJECT | | +---------+ | | =========> list of name, type, value for dynamic fields derived | | from its immediate class | +---------+ | | =========> immediate class | +---------+ | | =========> another object (of parent class) | +---------+ | | ================================================| | "this" | +---------+ BOARD: +-----------+ | CLASS | +-----------+ | ========> list of name, type, value for static fields +-----------+ | name | +-----------+ | ========> parent (super) class +-----------+ | ========> INTERFACEs that it implements (like classes) +-----------+ | ========> list of name, signature, method for all methods +-----------+ | ========> list of name, type, initial value expression for | | dynamic fields +-----------+ VI. Environments in Java, 5 mins., 10:45 to 10:50 Frames have a tag (BINDINGS, CLASS, FOR, GLOBAL, INTERFACE, OBJECT, VARIABLES) and an a-list of bindings. They may optionally have additional information. Notice that CLASS and OBJECT (above) are frames. Note: In Scheme, a procedure CONTAINS an environment frame; in Decaf Java-In-Scheme, an object IS an environment frame. An environment is a list of frames, like in Scheme. At the bottom of the environment is a "base frame" that must be eithe GLOBAL (REP loop), OBJECT (dynamic method), or CLASS (static method). New frames are created by: a) VARIABLES (in Java, entering a block that declares variables) b) FOR statements that declare variables c) Invoking a method (new base frame, followed by BINDINGS) d) Creating an object using NEW e) Declaring a CLASS or INTERFACE Variable lookup is like Scheme: start at the first frame, move on to the next. Base frames are special: a) Global frame is like in Scheme: error if not found b) CLASS: look in interfaces that it implements, then super class c) OBJECT: look in class, then interfaces the class implements, but then go to superobject rather than superclass Method lookup is more complicated. It starts like variable lookup to produce eithe ran object or a class that will be used to find the method. Then it finds ALL methods that match the name, number of arguments, and type of arguments. Then it finds the best match, which must be unique or (in Java) you get a compiler error. VII. Summary, 5 mins., 10:50 to 10:55 The Decaf Java-In-Scheme interpreter is a realistic implementation, but not complete. It isn't that large a program: under 50 pages of Scheme. It's very like Scheme: dispatch on the type of expression (we could use ANALYZE technique next year); flow of control requires three arguments (exp, env, next) instead of just two; environments stack and are searched as in Scheme. It has no pointers, garbage collection, and dynamic typing!