-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathai-proc.rkt
56 lines (44 loc) · 1.41 KB
/
ai-proc.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#lang racket/base
(require "tools.rkt"
"ai-array-c.rkt"
"libproc.rkt"
racket/runtime-path
racket/file
racket/system)
(provide
ai-proc-debug
ai-proc
ai-sp
ai-sp/.g.h)
(define ai-proc-debug (make-parameter #f))
;; Convert stream function to C code, compile and run.
(define-runtime-path rai-dir ".")
(define-runtime-path rules.mk "src/rules.mk")
(define build-dir (find-system-path 'temp-dir))
(define (ai-sp/.g.h proc .g.h nsi)
(let* ((.g.h (if (path? .g.h) (path->string .g.h) .g.h))
(.sp (regexp-replace ".g.h$" .g.h ".sp")))
(with-output-to-file .g.h
(lambda ()
(display (ai-array-c proc #:nsi nsi)))
#:exists 'truncate)
(let ((compile-out
(with-output-to-string
(lambda ()
(let ((cmd (format "make RAI=~a -f ~a -C ~a ~a"
rai-dir rules.mk build-dir .sp)))
(printf "~a\n" cmd)
(system cmd))))))
(when (ai-proc-debug)
(display compile-out)
(system (format "cat ~a" .g.h)))
(delete-file .g.h)
.sp)))
(define (ai-sp proc #:nsi [nsi #f])
(let* ((.g.h (make-temporary-file "proc_~a.g.h" #f build-dir)))
(ai-sp/.g.h proc .g.h nsi)))
(define (ai-proc proc #:nsi [nsi #f])
(let ((.sp (ai-sp proc #:nsi nsi)))
(let ((proc-class (proc-load-sp .sp)))
(delete-file .sp)
proc-class)))