Programming Language and Program Synthesis

Table of Contents

Reflection

Mirrors: Design Principles for Meta-level Facilities of Object-Oriented Programming Languages

Language with reflection support allows user to query an instance for its class:

class Car {...}
Car myCar = new Car();
int numberOfDoors = myCar.numberOfDoors();
Class theCarsClass = myCar.getClass();
Car anotherCar = theCarsClass.newInstance();
Class theCarsSuperclass = theCarsClass.getSuperclass();

To support such operations, we should provide following APIs for objects and class:

class Object {
    Class getClass();
    ...
}
class Class {
    Class getSuperclass();
    // many other methods: getMethods(), getFields() etc.
}

Note that base-level operations and meta-level operations co-exists. The same object that exhibits behavior about the problem domain also exhibits behavior about being a member of a class.

This paper argues that the two groups of operations should be implemented separately:

class Object {
    // no reflective methods
    ...
}
class Class {
    // no reflective methods...
}
interface Mirror {
    String name();
    ...
}
class Reflection {
    public static ObjectMirror reflect(Object o) {
        ...
    }
}
interface ObjectMirror extends Mirror {
    ClassMirror getClass();
    ...
}
interface ClassMirror extends Mirror {
    ClassMirror getSuperclass();
    ...
}
ObjectMirror theCarsMirror = Reflection.reflect(myCar);
ClassMirror theCarsClassMirror = theCarsMirror.getClass();
ClassMirror theCarsSuperclassMirror = theCarsClassMirror.getSuperclass();

Abstract Interpretation

Abstracting Abstract Machines

Fast Polyhedra Abstract Domain

Multi-Stage Programming

A Gentle Introduction to Multi-Stage Programming.

TL;DR: MSP support runtime codegen and program execuction, and statically ensure the dynamically generated code are type-safe.

Static stages for heterogeneous programming

Author: Zihao Ye

Email: expye@outlook.com

Date:

Last modified: 2021-02-19 Fri 21:14

Licensed under CC BY-NC 4.0