crossfire/crossfire/main.rkt

90 lines
2.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 racket/bool racket/function racket/match
(for-syntax racket/base racket/syntax)
"pattern.rkt" "codegen.rkt")
(module+ test
(require rackunit))
(module+ test
(check-equal? (+ 2 2) 4))
(module+ main
(require racket/cmdline)
(define who (box "world"))
(command-line
#:program "my-program"
#:once-each
[("-n" "--name") name "Who to say hello to" (set-box! who name)]
#:args ()
(void)))
;; manifest.rkt processing
(define (parse-manifest manifest-def)
(struct manifest [name mode command isets pattern] #:transparent)
(define-syntax (check-false stx)
(syntax-case stx ()
[(_ what)
(with-syntax ([id (format-id stx "manifest-~a" #'what)]
[idsym #''what])
#'(when (false? (id mf))
(error "manifest attribute missing:" idsym)))]))
(define mf
(for/fold ([mf (manifest #f 'stdin #f builtin-isets #f)])
([line (in-list manifest-def)])
(match line
[(list 'name name) (struct-copy manifest mf [name name])]
[(list 'mode mode) (struct-copy manifest mf [mode mode])]
[(list 'command command) (struct-copy manifest mf [command command])]
[(list 'iset name val)
(struct-copy manifest mf
[isets (hash-set (manifest-isets mf)
(symbol->string name) (string->integer-set val))])]
[(list 'pattern pattern) (struct-copy manifest mf [pattern pattern])])))
(check-false name)
(check-false command)
(check-false pattern)
(define isets (manifest-isets mf))
(define pattern
(for/vector ([x (in-list (regexp-match* #rx"\\??." (manifest-pattern mf)))])
(if (= 1 (string-length x))
(char->integer-set (string-ref x 0))
(hash-ref isets x (lambda () (error "no such iset defined" x))))))
(values (manifest-name mf) (manifest-mode mf) (manifest-command mf) pattern))
;; test code
(define-values [name mode command pattern]
(parse-manifest
'((name "test")
(mode stdio)
(command ("meme"))
(pattern "?d_?d"))))
(pattern-codegen pattern mode (pattern-start pattern) (pattern-end pattern))
(printf "// total: ~a\n" (pattern-count pattern))