Repository navigation
Expand file tree
/
Copy pathinline-processor.lisp
More file actions
77 lines (62 loc) · 2.26 KB
/
Copy pathinline-processor.lisp
File metadata and controls
77 lines (62 loc) · 2.26 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
;; An inline processor node defines a node which expands to a macro
;; which performs some user-defined processing and passes the result
;; to a single handler function.
(in-package :picflow)
(defclass inline-processor (node)
((entry-point :reader entry-point
:initarg :entry-point
:initform (c-gensym "INLINE"))
(argument-name :reader argument-name
:initarg :argument-name
:initform "x"
:documentation "The name of the argument to the macro")
(processor-content :reader processor-content
:initarg :processor-content
:documentation "The macro-expansion text")))
(defmethod prototype-code-emit ((node inline-processor))
(emit "#define ~A(~A) ~A"
(entry-point node)
(argument-name node)
(let* ((output-name (car (output-names node)))
(output (gethash output-name (outputs node))))
(if output
(call-output output (processor-content node))
(error "Inline processor node ~S needs a single output connection, but has none" node)))))
(defmacro defcode-inline (name (arg) &body body)
`(defun ,name () (make-instance 'inline-processor
:argument-name (format nil "~(~A~)" ',arg)
:processor-content (progn ,@body)
:output-names '(:default)
:input-names '(:default))))
(defcode-inline inverter (x)
"~(x)")
(defun adder (n)
"Return a block that adds N to each value. N can be negative."
(make-instance 'inline-processor
:argument-name "x"
:processor-content (format nil "x + (~D)" n)
:output-names '(:default)
:input-names '(:default)))
(defcode-inline bits-10-to-8 (x)
"(unsigned char)((x) >> 2)")
(defcode-inline bits-16-to-8 (x)
"(unsigned char)((x) >> 8)")
(defcode-inline to-unsigned-char (x)
"(unsigned char)(x)")
(defcode-inline to-unsigned-int (x)
"(unsigned int)(x)")
(defcode-inline to-unsigned-long (x)
"(unsigned long)(x)")
(defcode-inline to-char (x)
"(char)(x)")
(defcode-inline to-int (x)
"(int)(x)")
(defcode-inline to-long (x)
"(long)(x)")
(defun fixed-gain (g)
"Return a block that multiplies each value by a fixed gain G"
(make-instance 'inline-processor
:argument-name "x"
:processor-content (format nil "x * (~D)" g)
:output-names '(:default)
:input-names '(:default)))