From 126de096bedf4f0a26d6ac5f6bdc648ee0f2e3e8 Mon Sep 17 00:00:00 2001 From: haskal Date: Sun, 25 Oct 2020 01:49:31 -0400 Subject: [PATCH] initial commit --- .gitignore | 7 ++ README.md | 17 ++++ crossfire/info.rkt | 10 +++ crossfire/main.rkt | 110 ++++++++++++++++++++++++++ crossfire/scribblings/crossfire.scrbl | 10 +++ 5 files changed, 154 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 crossfire/info.rkt create mode 100644 crossfire/main.rkt create mode 100644 crossfire/scribblings/crossfire.scrbl diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..977ff14 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +*~ +\#* +.\#* +*.zo +*.dep +/crossfire/compiled/ +/crossfire/doc/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..89ac6a1 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# AScrossfire + +hello world + +## components + +- base: #lang for configuration/definitions +- server: distribute jobs to workers + - base definitions of input classes and how to divide them + - dynamic slicing and scheduling based on agents' reported work rate + - fairly randomized distribution +- agent: accepts and runs jobs + - optional: containerization + - optional: appimage-like behavior + - required: run binary with infrastructure to get assigned brute force range, log and report + progress. via library interface as well as stdio interface +- client: submit jobs and view progress via command line (and maybe racket/gui and framework???) diff --git a/crossfire/info.rkt b/crossfire/info.rkt new file mode 100644 index 0000000..8b9b75a --- /dev/null +++ b/crossfire/info.rkt @@ -0,0 +1,10 @@ +#lang info + +(define pkg-desc "a package. whoa") +(define version "0.1") +(define pkg-authors '(haskal)) + +(define collection "crossfire") +(define deps '("base")) +(define build-deps '("scribble-lib" "racket-doc" "rackunit-lib")) +(define scribblings '(("scribblings/crossfire.scrbl" ()))) diff --git a/crossfire/main.rkt b/crossfire/main.rkt new file mode 100644 index 0000000..cdbc354 --- /dev/null +++ b/crossfire/main.rkt @@ -0,0 +1,110 @@ +#lang racket/base + +(require racket/bool racket/function racket/match racket/set racket/vector + (for-syntax racket/base racket/syntax)) + +(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 () + (printf "hello ~a~n" (unbox who)))) + + +;; manifest.rkt processing + +(define (string->charset str) + (for/set ([ch (in-string str)]) + (char->integer ch))) + +(define (range->charset a b) + (for/set ([i (in-range a b)]) i)) + +(define builtin-charsets + (hash "?l" (string->charset "abcdefghijklmnopqrstuvwxyz") + "?u" (string->charset "ABCDEFGHIJKLMNOPQRSTUVWXYZ") + "?d" (string->charset "0123456789") + "?s" (string->charset " !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~") + "?a" (range->charset 32 127) + "?b" (range->charset 0 256))) + +(define (parse-manifest manifest-def) + (struct manifest [name mode command charsets pattern] #:transparent) + + (define (eq/m x) (curry equal? x)) + + (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-charsets #f)]) + ([line (in-list manifest-def)]) + (match line + [(list (? (eq/m 'name)) name) (struct-copy manifest mf [name name])] + [(list (? (eq/m 'mode)) mode) (struct-copy manifest mf [mode mode])] + [(list (? (eq/m 'command)) command) (struct-copy manifest mf [command command])] + [(list (? (eq/m 'charset)) name val) + (struct-copy manifest mf + [charsets (hash-set (manifest-charsets mf) + (symbol->string name) (string->charset val))])] + [(list (? (eq/m 'pattern)) pattern) (struct-copy manifest mf [pattern pattern])]))) + + (check-false name) + (check-false command) + (check-false pattern) + + (define charsets (manifest-charsets mf)) + (define pattern + (for/vector ([x (in-list (regexp-match* #rx"\\??." (manifest-pattern mf)))]) + (if (= 1 (string-length x)) + (list (char->integer (string-ref x 0))) + (set->list (hash-ref charsets x (lambda () (error "no such charset defined" x))))))) + (values (manifest-name mf) (manifest-mode mf) (manifest-command mf) pattern)) + + +;; pattern processing + +(define (pattern-count pattern) + (for/fold ([sum 1]) ([p (in-vector pattern)]) + (* sum (set-count p)))) + +;; design recipe violations follow +;; (sorry) +;; (i wanted this to be fast so i try to avoid spamming the heap) +(define (pattern-generate pattern out-port) + (define len (vector-length pattern)) + (define gen (make-bytes len)) + (define (output gen) + (write-bytes gen out-port) + (printf "\n")) + (define (permute i gen) + (cond [(= i len) (output gen)] + [else + (for ([chr (in-set (vector-ref pattern i))]) + (bytes-set! gen i chr) + (permute (add1 i) gen))])) + (permute 0 gen)) + +(define-values [name mode command pattern] + (parse-manifest + '((name "test") + (mode stdin) + (command ("meme")) + (pattern "test?dx?d")))) + +(displayln (pattern-count pattern)) +(pattern-generate pattern (current-output-port)) diff --git a/crossfire/scribblings/crossfire.scrbl b/crossfire/scribblings/crossfire.scrbl new file mode 100644 index 0000000..ae2f4b7 --- /dev/null +++ b/crossfire/scribblings/crossfire.scrbl @@ -0,0 +1,10 @@ +#lang scribble/manual +@require[@for-label[crossfire + racket/base]] + +@title{crossfire} +@author{haskal} + +@defmodule[crossfire] + +Package Description Here