Skip to content

Commit

Permalink
feat(simpleactor): compile away contract-out
Browse files Browse the repository at this point in the history
  • Loading branch information
bramvdbogaerde committed Dec 18, 2024
1 parent 0978517 commit 5ae0bde
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
3 changes: 2 additions & 1 deletion analyses/simpleactor/racket/run/translate-full.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
(require racket/pretty)
(require (prefix-in cc: "../translations/cc-combinator.rkt"))
(require (prefix-in ac: "../translations/actor-translation.rkt"))
(require (prefix-in co: "../translations/contract-out-translation.rkt"))

;; A full translation from Racket actors
;; with their contracts to λα/c
Expand All @@ -22,4 +23,4 @@

(pretty-display (cc:translate
#:meta #f
(ac:translate (read))))
(ac:translate (co:translate (read)))))
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)

0 comments on commit 5ae0bde

Please sign in to comment.