Coverage report: /home/ellis/comp/core/lib/syn/gen/rs/util.lisp

KindCoveredAll%
expression075 0.0
branch06 0.0
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 ;;; util.lisp --- GEN/RS Utils
2
 
3
 ;; 
4
 
5
 ;;; Code:
6
 (in-package :syn/gen/rs)
7
 (in-readtable :std)
8
 (defvar *rs-macros* nil)
9
 (defvar *default-cargo-target-directory* (merge-pathnames "target/" *default-pathname-defaults*))
10
 
11
 (defmacro rs-defmacro (name args &body body)
12
   "Define a macro which can be used within the body of a 'with-rs' form."
13
   `(prog1
14
        (defmacro ,name ,@(mapcar #`(,a1) args) ,@body)
15
      (push ',name *rs-macros*)))
16
 
17
 (defun rs-mod-form (crate &optional mods pub)
18
   "Generate a basic mod form (CRATE . [MODS] [PUB])"
19
   `(,crate ,mods ,pub))
20
 
21
 (defmacro with-rs-env (imports &body body)
22
   "Generate an environment for use within a Rust generator macro."
23
   `(let ((imports ,(mapcar #'rs-mod-form imports)))
24
      (format nil "~A~&~A" imports ',body)))
25
 
26
 (defun rs-use (crate &optional mods pub)
27
   "Generate a single Rust use statement."
28
   (concatenate
29
    'string
30
    (if pub "pub " "")
31
    "use " crate "::{"
32
    (cond
33
      ((consp mods)
34
       (reduce
35
        (lambda (x y) (format nil "~A,~A" x y))
36
        mods))
37
      (t mods))
38
    "};"))
39
 
40
 (defun rs-mod (mod &optional pub)
41
   "Generate a single Rust mod statement."
42
   (concatenate
43
    'string
44
    (if pub "pub " "")
45
    "mod " mod ";"))
46
 
47
 (defun rs-imports (&rest imports)
48
   "Generate a string of Rust 'use' statements."
49
   (cond
50
     ((consp imports)
51
      (mapcar (lambda (x) (apply #'rs-use (apply #'rs-mod-form x))) imports))
52
     (t imports)))
53
 
54
 (defmacro rs-extern-c-fn (name args &optional pub unsafe no-mangle &body body)
55
   "Generate a Rust extern 'C' fn."
56
   `(concatenate
57
     'string
58
     ,(when no-mangle (format nil "#[no_mangle]~&"))
59
     ,(when pub "pub ")
60
     ,(when unsafe "unsafe ")
61
     "extern \"C\" fn " ,name "("
62
     ,(cond
63
        ((consp args) (reduce (lambda (x y) (format nil "~A,~A" x y)) args))
64
        (t args))
65
     ")" "{" ,@body "}"))
66
 
67
 ;; (defun rs-macroexpand-1 (form &optional env))
68
 
69
 ;; (defun rs-macroexpand (env &rest body)