diff --git a/crossfire/codegen.rkt b/crossfire/codegen.rkt index bd7c53f..4aa6e70 100644 --- a/crossfire/codegen.rkt +++ b/crossfire/codegen.rkt @@ -41,10 +41,8 @@ ;; ok gamer move time (define-runtime-path codegen-template "codegen.rktc") -(define (pattern-codegen pattern mode pp-start pp-end) +(define (pattern-codegen pattern mode) (eval-template `(file ,(path->string codegen-template)) (hash 'pattern (vector-map integer-set-contents pattern) - 'mode mode - 'pp-start pp-start - 'pp-end pp-end))) + 'mode mode))) diff --git a/crossfire/codegen.rktc b/crossfire/codegen.rktc index 144de2a..4f66c2f 100644 --- a/crossfire/codegen.rktc +++ b/crossfire/codegen.rktc @@ -23,6 +23,7 @@ #include #include +@;; TODO : make configurable @(define c-type "uint64_t") @(define c-type-fmt "%lx") @@ -52,12 +53,28 @@ typedef struct { @(for/list ([i (in-naturals)] [iset (in-vector pattern)]) (output-iset i iset)) -int crossfire_main(callback cb) { +int crossfire_main(int argc, char* argv[], callback cb) { char buf [ @(* 20 (vector-length pattern)) ]; - // @format["~s" pp-start] - @(for/list ([num (in-naturals)] [iset-pos (in-vector pp-start)]) - @list{size_t @(format "i~a" num) = @(car iset-pos) ; - vartype @(format "v~a" num) = @(cdr iset-pos) ; + + @(define req-args (add1 (* (vector-length pattern) 4))) + if (argc < @req-args) { + fprintf(stderr, "missing args\n"); + return -1; + } + + @(for/list ([num (in-range (vector-length pattern))]) + (define iter-s (format "i~a" num)) + (define viter-s (format "v~a" num)) + (define iter-e (format "i~a_e" num)) + (define viter-e (format "v~a_e" num)) + @list{size_t @iter-s ; + sscanf(argv[1 + @num * 4], "%zx", &@iter-s ); + vartype @viter-s ; + sscanf(argv[1 + @num * 4 + 1], @(format "\"~a\"" c-type-fmt) , &@viter-s ); + size_t @iter-e ; + sscanf(argv[1 + @num * 4 + 2], "%zx", &@iter-e ); + vartype @viter-e ; + sscanf(argv[1 + @num * 4 + 3], @(format "\"~a\"" c-type-fmt) , &@viter-e ); }) ssize_t res; @@ -85,11 +102,13 @@ l_inner: @(define (end-conditionals) (add-between - (for/list ([num (in-naturals)] [iset-pos (in-vector pp-end)]) + (for/list ([num (in-range (vector-length pattern))]) (define iter (format "i~a" num)) (define viter (format "v~a" num)) + (define iter-e (format "i~a_e" num)) + (define viter-e (format "v~a_e" num)) @; ranges are inclusive, but since we exit _after_ printing/callbacking we use >= - @list{ @iter >= @(car iset-pos) && @viter >= @(cdr iset-pos) }) + @list{ @iter >= @iter-e && @viter >= @viter-e }) " && ")) @(match mode @@ -99,7 +118,6 @@ l_inner: ['callback @list{ if (cb( @vs )) { cf_report_success( @vs ); return 0; } }]) - // @format["~s" pp-end] if ( @end-conditionals[] ) { goto l_end; } @@ -112,8 +130,8 @@ l_end: @(if (equal? mode 'stdio) @list{ -int main() { - return crossfire_main(NULL); +int main(int argc, char* argv[]) { + return crossfire_main(argc, argv, NULL); } } @list{ diff --git a/crossfire/main.rkt b/crossfire/main.rkt index d2b8832..7cf2042 100644 --- a/crossfire/main.rkt +++ b/crossfire/main.rkt @@ -109,7 +109,12 @@ ;; brute force pattern (pattern ?m "_?d")))) -(pattern-codegen pattern mode (resolve-pattern-pos pattern (pos->pattern-pos pattern 10)) - (resolve-pattern-pos pattern - (pos->pattern-pos pattern 21))) +(pattern-codegen pattern mode) +(define start (resolve-pattern-pos pattern (pos->pattern-pos pattern 10))) +(define end (resolve-pattern-pos pattern (pos->pattern-pos pattern 21))) +(printf "// args: ") +(for ([s (in-vector start)] [e (in-vector end)]) + (apply printf "~a ~a ~a ~a " + (map (lambda (x) (number->string x 16)) (list (car s) (cdr s) (car e) (cdr e))))) +(printf "\n") (printf "// total: ~a\n" (pattern-count pattern))