5 GC Mutator Language, 2
#lang plai/gc2/mutator | package: plai-lib |
The GC Mutator Scheme language is used to test garbage collectors written with the GC Collector Language, 2 language. Since collectors support a subset of Racket’s values, the GC Mutator Scheme language supports a subset of procedures and syntax. In addition, many procedures that can be written in the mutator are omitted as they make good test cases. Therefore, the mutator language provides only primitive procedures, such as +, cons, etc.
5.1 Building Mutators for GC2
The first expression of a mutator must be:
syntax
(allocator-setup collector-module heap-size)
heap-size = exact-nonnegative-integer
The rest of a mutator module is a sequence of definitions, expressions and test cases. The GC Mutator Scheme language transforms these definitions and statements to use the collector specified in allocator-setup. In particular, many of the primitive forms, such as cons map directly to procedures such as gc:cons, written in the collector.
5.2 Mutator API for GC2
The GC Mutator Scheme language supports the following procedures and syntactic forms:
syntax
syntax
syntax
syntax
syntax
syntax
syntax
syntax
syntax
syntax
syntax
syntax
syntax
(define (id arg-id ...) body-expression ...+)
value
value
value
value
value
+ : procedure?
value
- : procedure?
value
* : procedure?
value
/ : procedure?
value
value
value
= : procedure?
value
< : procedure?
value
> : procedure?
value
<= : procedure?
value
>= : procedure?
value
value
value
value
value
value
procedure
(set-first! c v) → void
c : cons? v : any/c
Calls to this function are allowed only in syntactic positions that would discard its result, e.g., at the top-level or inside a begin expression (but not in the last expression in a begin). Also, this function appear only in the function position of an application expression.
So, in order to pass around a version of this function, you must write something like this (λ (c v) (begin (set-first! c v) 42)), perhaps picking a different value than 42 as the result.
syntax
syntax
syntax
Other common procedures are left undefined as they can be defined in terms of the primitives and may be used to test collectors.
Additional procedures from scheme may be imported with:
syntax
(import-primitives id ...)
For example, the GC Mutator Scheme language does not define modulo:
(import-primitives modulo) (test/value=? (modulo 5 3) 2)
5.3 Testing Mutators with GC2
GC Mutator Scheme provides two forms for testing mutators:
syntax
(test/location=? mutator-expr1 mutator-expr2)
syntax
(test/value=? mutator-expr datum/quoted)
syntax
(printf format mutator-expr ...)
format = literal-string