-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(simpleactor): compile away
contract-out
- Loading branch information
1 parent
0978517
commit 5ae0bde
Showing
2 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
analyses/simpleactor/racket/translations/contract-out-translation.rkt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#lang racket | ||
|
||
;; This module translates files containing `contract-out` | ||
;; definitions to equivalent files ready for verification. | ||
;; | ||
;; To this end, contract-out definitions are compiled | ||
;; to function definitions that are then applied with symbolic | ||
;; inputs. | ||
|
||
|
||
;; Attempt to derrive the arity of the function | ||
;; monitored by the contract, returns an arity of | ||
;; zero if the contract does not depict a function | ||
;; but is a constant, in that case a function | ||
;; call is not generated | ||
(define (contract-arity contract) | ||
(match contract | ||
[(quasiquote (-> ,@contracts)) | ||
(- (length contracts) 1)] | ||
[_ 0])) | ||
|
||
;; Translate a single contract | ||
(define (translate-contract contract) | ||
(match contract | ||
[(quasiquote (,identifier ,contract)) | ||
(let ((monitor `(mon module importer ,contract ,identifier)) | ||
(arity (contract-arity contract))) | ||
(if (= arity 0) | ||
monitor | ||
`(,monitor ,@(build-list arity (lambda ags '(input))))))] | ||
[_ (error "invalid contract-out specification")])) | ||
|
||
;; Translate a list of contracts | ||
(define (translate-contracts contracts) | ||
(map translate-contract contracts)) | ||
|
||
;; Translate a program that could contain a contract-out statement | ||
(define (translate exp) | ||
(match exp | ||
[(quasiquote (contract-out ,@contracts)) | ||
(translate-contracts contracts)] | ||
[(quasiquote (,exp1 ,@exs)) | ||
`(,(translate exp1) ,@(map translate exs))] | ||
[literal literal])) | ||
|
||
(provide | ||
translate) |