crossfire/crossfire/codegen.rkt

49 lines
1.9 KiB
Racket

#lang racket/base
;; crossfire: distributed brute force infrastructure
;;
;; Copyright (C) 2020 haskal
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU Affero General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU Affero General Public License for more details.
;;
;; You should have received a copy of the GNU Affero General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
(require (only-in data/integer-set integer-set-contents)
racket/match racket/runtime-path racket/vector
scribble/text (rename-in scribble/text/output [output scribble-output]))
(provide pattern-codegen)
;; templating infrastructure
(define (eval-template file vars [port (current-output-port)])
(define cs (current-namespace))
(define output-exp
(parameterize ([current-namespace (make-base-namespace)])
(for ([mod (in-list '(scribble/text racket/match))])
(namespace-attach-module cs mod)
(namespace-require mod))
(hash-for-each vars namespace-set-variable-value!)
(eval `(include/text ,file))))
(scribble-output output-exp port))
;; there used to be a racket implementation of the input generator but it majorly violated the
;; design recipe and got obsoleted by the template C version (which is intended to be more portable
;; and faster)
;; ok gamer move time
(define-runtime-path codegen-template "codegen.rktc")
(define (pattern-codegen pattern mode)
(eval-template
`(file ,(path->string codegen-template))
(hash 'pattern (vector-map integer-set-contents pattern)
'mode mode)))