begin implementing callback mode
This commit is contained in:
parent
57e2dfe29c
commit
0610a472ea
|
@ -1,6 +1,6 @@
|
||||||
#lang racket/base
|
#lang racket/base
|
||||||
|
|
||||||
(require racket/runtime-path
|
(require racket/match racket/runtime-path
|
||||||
scribble/text (rename-in scribble/text/output [output scribble-output]))
|
scribble/text (rename-in scribble/text/output [output scribble-output]))
|
||||||
|
|
||||||
(provide pattern-codegen)
|
(provide pattern-codegen)
|
||||||
|
@ -11,8 +11,9 @@
|
||||||
(define cs (current-namespace))
|
(define cs (current-namespace))
|
||||||
(define output-exp
|
(define output-exp
|
||||||
(parameterize ([current-namespace (make-base-namespace)])
|
(parameterize ([current-namespace (make-base-namespace)])
|
||||||
(namespace-attach-module cs 'scribble/text)
|
(for ([mod (in-list '(scribble/text racket/match))])
|
||||||
(namespace-require 'scribble/text)
|
(namespace-attach-module cs mod)
|
||||||
|
(namespace-require mod))
|
||||||
(hash-for-each vars namespace-set-variable-value!)
|
(hash-for-each vars namespace-set-variable-value!)
|
||||||
(eval `(include/text ,file))))
|
(eval `(include/text ,file))))
|
||||||
(scribble-output output-exp port))
|
(scribble-output output-exp port))
|
||||||
|
@ -23,9 +24,10 @@
|
||||||
|
|
||||||
;; ok gamer move time
|
;; ok gamer move time
|
||||||
(define-runtime-path codegen-template "codegen.template")
|
(define-runtime-path codegen-template "codegen.template")
|
||||||
(define (pattern-codegen pattern pp-start pp-end)
|
(define (pattern-codegen pattern mode pp-start pp-end)
|
||||||
(eval-template
|
(eval-template
|
||||||
`(file ,(path->string codegen-template))
|
`(file ,(path->string codegen-template))
|
||||||
(hash 'pattern pattern
|
(hash 'pattern pattern
|
||||||
|
'mode mode
|
||||||
'pp-start pp-start
|
'pp-start pp-start
|
||||||
'pp-end pp-end)))
|
'pp-end pp-end)))
|
||||||
|
|
|
@ -3,11 +3,13 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
@(define c-type "uint64_t")
|
@(define c-type "uint64_t")
|
||||||
@(define c-type-fmt "%lx")
|
@(define c-type-fmt "%lx")
|
||||||
|
|
||||||
typedef @c-type vartype;
|
typedef @c-type vartype;
|
||||||
|
typedef bool (*callback)( @(add-between (for/list ([_ (in-vector pattern)]) "vartype") ",") );
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
vartype start;
|
vartype start;
|
||||||
|
@ -32,7 +34,7 @@ typedef struct {
|
||||||
@(for/list ([i (in-naturals)] [iset (in-vector pattern)])
|
@(for/list ([i (in-naturals)] [iset (in-vector pattern)])
|
||||||
(output-iset i iset))
|
(output-iset i iset))
|
||||||
|
|
||||||
int main() {
|
int inputgen_main(callback cb) {
|
||||||
char buf [ @(* 20 (vector-length pattern)) ];
|
char buf [ @(* 20 (vector-length pattern)) ];
|
||||||
@(for/list ([num (in-naturals)] [iset-pos (in-vector pp-start)])
|
@(for/list ([num (in-naturals)] [iset-pos (in-vector pp-start)])
|
||||||
@list{size_t @(format "i~a" num) = @(car iset-pos) ;
|
@list{size_t @(format "i~a" num) = @(car iset-pos) ;
|
||||||
|
@ -54,6 +56,8 @@ int main() {
|
||||||
|
|
||||||
@(define vs
|
@(define vs
|
||||||
(string-join (for/list ([i (in-range (vector-length pattern))]) (format "v~a" i)) ","))
|
(string-join (for/list ([i (in-range (vector-length pattern))]) (format "v~a" i)) ","))
|
||||||
|
@(define arg-vs
|
||||||
|
(string-join (for/list ([i (in-range (vector-length pattern))]) (format "vartype v~a" i)) ","))
|
||||||
@(define fmt
|
@(define fmt
|
||||||
(string-join (for/list ([i (in-range (vector-length pattern))]) c-type-fmt) " "))
|
(string-join (for/list ([i (in-range (vector-length pattern))]) c-type-fmt) " "))
|
||||||
l_inner:
|
l_inner:
|
||||||
|
@ -70,10 +74,27 @@ l_inner:
|
||||||
goto l_end;
|
goto l_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t res = snprintf(buf, sizeof(buf), @(format "\"~a\\n\"" fmt), @vs );
|
@(match mode
|
||||||
fwrite(buf, res, 1, stdout);
|
['stdout
|
||||||
|
@list{ssize_t res = snprintf(buf, sizeof(buf), @(format "\"~a\\n\"" fmt), @vs );
|
||||||
|
fwrite(buf, res, 1, stdout);}]
|
||||||
|
['callback
|
||||||
|
@list{ if (cb( @vs )) { report_success( @vs ); return 0; } }])
|
||||||
|
|
||||||
@(for/list ([iset (in-vector pattern)]) "}}")
|
@(for/list ([iset (in-vector pattern)]) "}}")
|
||||||
l_end:
|
l_end:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@(if (equal? mode 'stdout)
|
||||||
|
@list{
|
||||||
|
int main() {
|
||||||
|
return inputgen_main(NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@list{
|
||||||
|
void report_success( @arg-vs ) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
|
@ -67,9 +67,9 @@
|
||||||
(define-values [name mode command pattern]
|
(define-values [name mode command pattern]
|
||||||
(parse-manifest
|
(parse-manifest
|
||||||
'((name "test")
|
'((name "test")
|
||||||
(mode stdin)
|
(mode callback)
|
||||||
(command ("meme"))
|
(command ("meme"))
|
||||||
(pattern "test?d?a?a?s"))))
|
(pattern "test?d?a?a?s"))))
|
||||||
|
|
||||||
(pattern-codegen pattern (pattern-start pattern) (pattern-end pattern))
|
(pattern-codegen pattern mode (pattern-start pattern) (pattern-end pattern))
|
||||||
(printf "// total: ~a\n" (pattern-count pattern))
|
(printf "// total: ~a\n" (pattern-count pattern))
|
||||||
|
|
Loading…
Reference in New Issue