9.0.0.1

12 — Mixed: Sound🔗

Due Thursday, 27 November 2025, 11:59:59pm, with an automatic extension until Monday, 01 December 2025, 11:59:59pm.

Purpose to build a model of a sound mixed-typed programming language (part 2)

This assignment is part of a mini-project about the pragmatics of mixed-typed programming languages like the TypeScript/JavaScript or Typed Racket/Racket combination.

Delivery Deliver your solutions in a directory called 12 within your assigned GitHub repository. The directory should contain the following items:

  • the executables xtr as specified below;

  • the sub-directory 12/Tests/ with the required integration test; and

  • an optional sub-directory called 12/Other/ for all auxiliary files.

The directory 12/ may also contain a Makefile (see Make) in case you need us to build your executable. An executable should not be checked into a repository.

Programming Task Using your favorite programming language, you are to create a complete model of the Mixed language: its syntax and its Racket-like semantics.

In contrast to the JavaScript-like semantics (of 10 — A La JS), a Racket-like CESK semantics checks interactions between typed and untyped pieces of code. Concretely, the machine has additional instructions to ensure types are sound:
  • Every time the machine instantiates a typed class—whether originally typed and type-checked or synthetic and unchecked—it creates a proxy instead of a plain object. A proxy combines the object with the type of its class.

  • When the machine encounters a proxy as it attempts to evaluate a method call, it checks whether the arguments conform to the parameter types of the method as specified in the proxy—before it enters the method’s body.

    Additionally, the machine puts the return type of the method on the stack in the K register so that after the method returns, it can also check whether the result value conforms to the type.

    Note This second action destroys the space equivalence of tail-calling (gradually typed) methods and while loops as spelled out in 7 — Class: Semantics.

  • When the machine encounters a proxy as it attempts to retrieve a value from a field, it checks whether the retrieved value conforms to the type of the field as specified in the proxy.

  • When the machine encounters a proxy as it attempts to mutate an object field, it checks whether the value to be stored in the field conforms to the type of the field as specified in the proxy.

See CESK: Mixed for the full instruction set.

Checking whether some given value conforms to a type specification has one of three possible outcomes. First, if the value matches the type, the value is returned. Second, if some given object might live up to a type specification in the future, the function creates an appropriate proxy. Otherwise, the function indicates that the value does not conform to the given type. There are six possible scenarios:

value is:

 

number

 

object

 

proxy

 

n

 

obj

 

prx

Number

 

n

 

no

 

no

Shape S

 

no

 

if a first-order check succeeds:

 

if the type in prx is equal to S:

 

 

combine obj and S in a proxy

 

use prx

 

 

else: no

 

else: no

Considered as a function, a first-order check maps an object and a (Shape) type to a Boolean value. Operationally a first-order check confirms that an object obj is going to conform to a Shape type S: Comparing the set of field names should simplify the code for those of you who chose an unordered data representation for objects.

  • the field names in the object and the field names in S have to be the same sets;

  • if so, the field values in obj have to conform to the respective field types in S;

    That is, if checking conformity returns a proxy, it is acceptable; otherwise, the first-order check fails.

  • the method names in obj’s class and the method names in S have to be the same sets; and

  • if so, method m in obj’s class must have as many parameters as the signature of m in S.

The xtr program reads one ExampleGG from STDIN, constructs the AST, performs the validity checks, links the system into a complete program, runs the CESK machine, and writes one of the following strings to STDOUT: The outcomes are listed in the order in which they may occur for a given program.

  • "parser error" if the given ExampleGG is not an element of the Mixed grammar;

  • "duplicate module name" if in the well-formed Mixed system, at least two of the module definitions come with the same name;

  • "duplicate method, field, or parameter name" if in the well-formed Mixed system one class definition one method definition, or one Shape comes with (at least) two fields, methods, or parameters that have the same name;

  • "bad import" if in the well-formed Mixed system one of the validity constraints concerning imports into tmodules is violated;

  • "undeclared variable error" if in the well-formed Mixed system one of the variable references comes without declaration or one reference to a ClassName (in a statement or an expression) comes without a (possibly imported) class definition;

  • "type error" if in the well-formed Mixed system one of the typed pieces of code fails to satisfy one of the typing judgments;

  • a number n if the CESK machine produces a number n for the well-formed and valid Mixed system;

  • "run-time error" if the CESK machine produces an error outcome for the well-formed and valid Mixed system.

Stop! Why is it no longer possible that the CESK machine prints "object"?

Special Reuse (from 10 — A La JS) or create the following systems in Mixed: blatant and insidious. and confirm that your sound CESK machine assigns a run-time error to these two systems. Deliver these test cases in the folder 12/Special/ as 0-*.ss and 1-*.ss, respectively.

Testing Task Create five integration tests for xtr.