changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > demo / tk.lisp

changeset 8: bebb76da449c
parent: 315fedf35bc7
child: 79737134254d
author: ellis <ellis@rwest.io>
date: Sun, 07 May 2023 20:42:26 -0400
permissions: -rw-r--r--
description: tests and stuff
1 (in-package #:demo)
2 
3 (defvar *cargo-target* #P"/Users/ellis/dev/otom8/demo/target/")
4 
5 (defvar *rs-macros* nil)
6 
7 (defmacro rs-find-dll (name &optional debug)
8  "Find the rust dll specified by NAME."
9  (cond
10  ((uiop:directory-exists-p (merge-pathnames *cargo-target* "release"))
11  `,(mkstr "./target/release/" name))
12  ((uiop:directory-exists-p (merge-pathnames *cargo-target* "debug"))
13  `,(mkstr "./target/debug/" name))
14  (t (progn
15  (uiop:run-program `("cargo" "build" ,(unless debug "--release")) :output t)
16  `,(find-rust-dll name debug)))))
17 
18 (defmacro rs-defmacro (args &body body)
19  "Define a macro which expands to a string of Rust code.")
20 
21 (defun rs-macroexpand-1 (form &optional env))
22 
23 (defun rs-macroexpand (env &rest body)
24  "Cbindgen is quite the menace and really doesn't like our macros used
25 to generate C FFI bindings. To compensate for this, we use a tool
26 called cargo-expand by the most excellent dtolnay which expands Rust
27 macros. The expansions are assembled into an equivalent Rust source
28 file which cbindgen won't get stuck in an infinite compile loop on.")
29 
30 (defun random-id ()
31  (format NIL "~8,'0x-~8,'0x" (random #xFFFFFFFF) (get-universal-time)))
32 
33 (defun scan-dir (dir filename callback)
34  (dolist (path (directory (merge-pathnames (merge-pathnames filename "**/") dir)))
35  (funcall callback path)))
36 
37 (defun mkstr (&rest args)
38  (with-output-to-string (s)
39  (dolist (a args) (princ a s))))
40 
41 (defun symb (&rest args)
42  (values (intern (apply #'mkstr args))))
43 
44 (defun sbq-reader (stream sub-char numarg)
45  "The anaphoric sharp-backquote reader: #`((,a1))"
46  (declare (ignore sub-char))
47  (unless numarg (setq numarg 1))
48  `(lambda ,(loop for i from 1 to numarg
49  collect (symb 'a i))
50  ,(funcall
51  (get-macro-character #\`) stream nil)))
52 
53 (eval-when (:execute)
54  (set-dispatch-macro-character
55  #\# #\` #'demo:sbq-reader))