3 GC Mutator Scheme
#lang plai/mutator | package: plai-lib |
The GC Mutator Scheme language is used to test garbage collectors written with the GC Collector Scheme language. Since collectors support a subset of Scheme’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.
3.1 Building Mutators
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.
3.2 Mutator API
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
syntax
value
value
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)
3.3 Testing Mutators
GC Mutator Scheme provides two forms for testing mutators:
syntax
(test/location=? mutator-expr1 mutator-expr2)
syntax
(test/value=? mutator-expr scheme-datum/quoted)
syntax
(printf format mutator-expr ...)
format = literal-string