2.1--- a/demo.asd Sun May 07 18:06:13 2023 -0400
2.2+++ b/demo.asd Sun May 07 20:42:26 2023 -0400
2.3@@ -22,6 +22,7 @@
2.4 :components ((:file "pkg")
2.5 (:file "ffi")
2.6 (:file "tk")
2.7+ (:file "cfg")
2.8 (:file "db")
2.9 (:file "ui")
2.10 (:file "demo"))
3.1--- a/ffi.lisp Sun May 07 18:06:13 2023 -0400
3.2+++ b/ffi.lisp Sun May 07 20:42:26 2023 -0400
3.3@@ -1,7 +1,7 @@
3.4 (in-package :demo)
3.5
3.6-(define-foreign-library demo_ffi
3.7+(define-foreign-library demo
3.8 (:win32 (:default "demo"))
3.9 (t (:default "libdemo")))
3.10
3.11-;; (use-foreign-library "./target/release/libdemo_ffi.dylib")
3.12+(use-foreign-library "./target/release/libdemo.dylib")
4.1--- a/lib.rs Sun May 07 18:06:13 2023 -0400
4.2+++ b/lib.rs Sun May 07 20:42:26 2023 -0400
4.3@@ -1,17 +1,17 @@
4.4 //! demo/lib.rs --- generated by DEMO:RS-MACROEXPAND
4.5-extern crate obj;
4.6 extern crate libc;
4.7+extern crate obj;
4.8 //pub use fig::*;
4.9-use obj::{Objective,Service,CustomService};
4.10+use libc::{c_char, size_t};
4.11+use obj::{CustomService, Objective, Service};
4.12 use std::ffi::{CStr, CString};
4.13 use std::slice;
4.14-use libc::{c_char, size_t};
4.15 #[no_mangle]
4.16 pub unsafe extern "C" fn free_service(ptr: *mut Service) {
4.17- if ptr.is_null() {
4.18- return;
4.19- }
4.20- let _ = Box::from_raw(ptr);
4.21+ if ptr.is_null() {
4.22+ return;
4.23+ }
4.24+ let _ = Box::from_raw(ptr);
4.25 }
4.26 #[no_mangle]
4.27 pub unsafe extern "C" fn service_from_string(ptr: *const c_char) -> *mut Service {
4.28@@ -23,49 +23,53 @@
4.29 pub unsafe extern "C" fn service_from_json_string(ptr: *const c_char) -> *mut Service {
4.30 assert!(!ptr.is_null());
4.31 let s = CStr::from_ptr(ptr);
4.32- Box::into_raw(Box::new(Service::from_json_str(&s.to_str().unwrap()).unwrap()))
4.33+ Box::into_raw(Box::new(
4.34+ Service::from_json_str(&s.to_str().unwrap()).unwrap(),
4.35+ ))
4.36 }
4.37 #[no_mangle]
4.38 pub unsafe extern "C" fn service_to_json_string(ptr: *const Service) -> *mut c_char {
4.39- let p = &*ptr;
4.40- let x = p.to_json_string().unwrap();
4.41- CString::new(x.as_str().as_bytes()).unwrap().into_raw()
4.42+ let p = &*ptr;
4.43+ let x = p.to_json_string().unwrap();
4.44+ CString::new(x.as_str().as_bytes()).unwrap().into_raw()
4.45 }
4.46 #[no_mangle]
4.47 pub unsafe extern "C" fn service_from_ron_string(ptr: *const c_char) -> *mut Service {
4.48 assert!(!ptr.is_null());
4.49 let s = CStr::from_ptr(ptr);
4.50- Box::into_raw(Box::new(Service::from_ron_str(&s.to_str().unwrap()).unwrap()))
4.51+ Box::into_raw(Box::new(
4.52+ Service::from_ron_str(&s.to_str().unwrap()).unwrap(),
4.53+ ))
4.54 }
4.55 #[no_mangle]
4.56 pub unsafe extern "C" fn service_to_ron_string(ptr: *const Service) -> *mut c_char {
4.57- let p = &*ptr;
4.58- let x = p.to_ron_string().unwrap();
4.59- CString::new(x.as_str().as_bytes()).unwrap().into_raw()
4.60+ let p = &*ptr;
4.61+ let x = p.to_ron_string().unwrap();
4.62+ CString::new(x.as_str().as_bytes()).unwrap().into_raw()
4.63 }
4.64 #[no_mangle]
4.65 pub unsafe extern "C" fn service_decode(ptr: *const u8, len: size_t) -> *mut Service {
4.66- Box::into_raw(Box::new(Service::decode(slice::from_raw_parts(ptr, len)).unwrap()))
4.67+ Box::into_raw(Box::new(
4.68+ Service::decode(slice::from_raw_parts(ptr, len)).unwrap(),
4.69+ ))
4.70 }
4.71 #[no_mangle]
4.72 pub unsafe extern "C" fn service_encode(ptr: *const Service) -> *mut u8 {
4.73- let p = &*ptr;
4.74- let mut x = p.encode().unwrap();
4.75- let r = x.as_mut_ptr();
4.76- std::mem::forget(x);
4.77- r
4.78+ let p = &*ptr;
4.79+ let mut x = p.encode().unwrap();
4.80+ let r = x.as_mut_ptr();
4.81+ std::mem::forget(x);
4.82+ r
4.83 }
4.84 #[no_mangle]
4.85 pub unsafe extern "C" fn free_custom_service(ptr: *mut CustomService) {
4.86- if ptr.is_null() {
4.87- return;
4.88- }
4.89- let _ = Box::from_raw(ptr);
4.90+ if ptr.is_null() {
4.91+ return;
4.92+ }
4.93+ let _ = Box::from_raw(ptr);
4.94 }
4.95 #[no_mangle]
4.96-pub unsafe extern "C" fn custom_service_from_string(
4.97- ptr: *const c_char,
4.98-) -> *mut CustomService {
4.99+pub unsafe extern "C" fn custom_service_from_string(ptr: *const c_char) -> *mut CustomService {
4.100 assert!(!ptr.is_null());
4.101 let p = CStr::from_ptr(ptr).to_str().unwrap();
4.102 Box::into_raw(Box::new(p.into()))
4.103@@ -74,45 +78,41 @@
4.104 pub unsafe extern "C" fn custom_service_from_json_string(ptr: *const c_char) -> *mut CustomService {
4.105 assert!(!ptr.is_null());
4.106 let s = CStr::from_ptr(ptr);
4.107- Box::into_raw(Box::new(CustomService::from_json_str(&s.to_str().unwrap()).unwrap()))}
4.108-#[no_mangle]
4.109-pub unsafe extern "C" fn custom_service_to_json_string(
4.110- ptr: *const CustomService,
4.111-) -> *mut c_char {
4.112- let p = &*ptr;
4.113- let x = p.to_json_string().unwrap();
4.114- CString::new(x.as_str().as_bytes()).unwrap().into_raw()
4.115+ Box::into_raw(Box::new(
4.116+ CustomService::from_json_str(&s.to_str().unwrap()).unwrap(),
4.117+ ))
4.118 }
4.119 #[no_mangle]
4.120-pub unsafe extern "C" fn custom_service_from_ron_string(
4.121- ptr: *const c_char,
4.122-) -> *mut CustomService {
4.123+pub unsafe extern "C" fn custom_service_to_json_string(ptr: *const CustomService) -> *mut c_char {
4.124+ let p = &*ptr;
4.125+ let x = p.to_json_string().unwrap();
4.126+ CString::new(x.as_str().as_bytes()).unwrap().into_raw()
4.127+}
4.128+#[no_mangle]
4.129+pub unsafe extern "C" fn custom_service_from_ron_string(ptr: *const c_char) -> *mut CustomService {
4.130 assert!(!ptr.is_null());
4.131 let s = CStr::from_ptr(ptr);
4.132- Box::into_raw(Box::new(CustomService::from_ron_str(&s.to_str().unwrap()).unwrap()))
4.133+ Box::into_raw(Box::new(
4.134+ CustomService::from_ron_str(&s.to_str().unwrap()).unwrap(),
4.135+ ))
4.136 }
4.137 #[no_mangle]
4.138-pub unsafe extern "C" fn custom_service_to_ron_string(
4.139- ptr: *const CustomService,
4.140-) -> *mut c_char {
4.141- let p = &*ptr;
4.142- let x = p.to_ron_string().unwrap();
4.143- CString::new(x.as_str().as_bytes()).unwrap().into_raw()
4.144+pub unsafe extern "C" fn custom_service_to_ron_string(ptr: *const CustomService) -> *mut c_char {
4.145+ let p = &*ptr;
4.146+ let x = p.to_ron_string().unwrap();
4.147+ CString::new(x.as_str().as_bytes()).unwrap().into_raw()
4.148 }
4.149 #[no_mangle]
4.150-pub unsafe extern "C" fn custom_service_decode(
4.151- ptr: *const u8,
4.152- len: size_t,
4.153-) -> *mut CustomService {
4.154- Box::into_raw(
4.155- Box::new(CustomService::decode(slice::from_raw_parts(ptr, len)).unwrap()),
4.156- )
4.157+pub unsafe extern "C" fn custom_service_decode(ptr: *const u8, len: size_t) -> *mut CustomService {
4.158+ Box::into_raw(Box::new(
4.159+ CustomService::decode(slice::from_raw_parts(ptr, len)).unwrap(),
4.160+ ))
4.161 }
4.162 #[no_mangle]
4.163 pub unsafe extern "C" fn custom_service_encode(ptr: *const CustomService) -> *mut u8 {
4.164- let p = &*ptr;
4.165- let mut x = p.encode().unwrap();
4.166- let r = x.as_mut_ptr();
4.167- std::mem::forget(x);
4.168- r
4.169+ let p = &*ptr;
4.170+ let mut x = p.encode().unwrap();
4.171+ let r = x.as_mut_ptr();
4.172+ std::mem::forget(x);
4.173+ r
4.174 }
5.1--- a/pkg.lisp Sun May 07 18:06:13 2023 -0400
5.2+++ b/pkg.lisp Sun May 07 20:42:26 2023 -0400
5.3@@ -49,12 +49,18 @@
5.4 (:export #:on-new-window
5.5 #:start-ui)
5.6 ;; tk.lisp
5.7- (:export #:random-id
5.8- #:scan-dir
5.9- #:mkstr
5.10- #:symb
5.11- #:sbq-reader
5.12- #:find-rust-dll)
5.13+ (:export
5.14+ #:*cargo-target*
5.15+ #:*rs-macros*
5.16+ #:random-id
5.17+ #:scan-dir
5.18+ #:mkstr
5.19+ #:symb
5.20+ #:sbq-reader
5.21+ #:rs-find-dll
5.22+ #:rs-defmacro
5.23+ #:rs-macroexpand-1
5.24+ #:rs-macroexpand)
5.25 ;; ffi.lisp
5.26 ;; (:export)
5.27 )
6.1--- a/readme.org Sun May 07 18:06:13 2023 -0400
6.2+++ b/readme.org Sun May 07 20:42:26 2023 -0400
6.3@@ -5,6 +5,8 @@
6.4 * Run
6.5 * Play
6.6 * Config
6.7-* COMMENT tasks
6.8-** TODO proc_macros
6.9+* tasks
6.10 ** TODO ros scripts
6.11+** TODO rs-macroexpand
6.12+- rs-gen-file rs-defmacro rs-macros
6.13+- rs-macroexpand-1
7.1--- a/scripts/build.ros Sun May 07 18:06:13 2023 -0400
7.2+++ b/scripts/build.ros Sun May 07 20:42:26 2023 -0400
7.3@@ -14,7 +14,10 @@
7.4
7.5 (defun main (&rest argv)
7.6 (declare (ignorable argv))
7.7+ (write-line "> cargo build --release")
7.8+ (uiop:run-program "cargo build --release")
7.9+ (wrie-line " built rust libs and bindings")
7.10 (asdf:load-asd "cl-demo.asd")
7.11- (asdf:load-system "cl-demo")
7.12- (asdf:make :cl-demo))
7.13+ (asdf:load-system "demo")
7.14+ (asdf:make :demo))
7.15 ;;; vim: set ft=lisp lisp:
8.1--- a/scripts/clean.ros Sun May 07 18:06:13 2023 -0400
8.2+++ b/scripts/clean.ros Sun May 07 20:42:26 2023 -0400
8.3@@ -16,5 +16,8 @@
8.4 (in-package :ros.script.clean.3891893753)
8.5
8.6 (defun main (&rest argv)
8.7- (declare (ignorable argv)))
8.8+ (declare (ignorable argv))
8.9+ (write-line "> cargo clean")
8.10+ (uiop:run-program "cargo clean")
8.11+ (write-line " cleaned rust crates"))
8.12 ;;; vim: set ft=lisp lisp:
9.1--- a/scripts/demo.ros Sun May 07 18:06:13 2023 -0400
9.2+++ b/scripts/demo.ros Sun May 07 20:42:26 2023 -0400
9.3@@ -9,4 +9,4 @@
9.4
9.5 (defun main (&rest argv)
9.6 (declare (ignorable argv))
9.7- (format t "hello world"))
9.8+ (demo:main))
10.1--- a/scripts/fmt.ros Sun May 07 18:06:13 2023 -0400
10.2+++ b/scripts/fmt.ros Sun May 07 20:42:26 2023 -0400
10.3@@ -14,5 +14,7 @@
10.4
10.5 (defun main (&rest argv)
10.6 (declare (ignorable argv))
10.7- (uiop:run-program "cargo fmt"))
10.8+ (write-line "> cargo fmt")
10.9+ (uiop:run-program "cargo fmt")
10.10+ (write-line " formatted rust code"))
10.11 ;;; vim: set ft=lisp lisp:
11.1--- a/scripts/test.ros Sun May 07 18:06:13 2023 -0400
11.2+++ b/scripts/test.ros Sun May 07 20:42:26 2023 -0400
11.3@@ -9,4 +9,6 @@
11.4
11.5 (defun main (&rest argv)
11.6 (declare (ignorable argv))
11.7- (format t "hello world"))
11.8+ (write-line "> cargo test")
11.9+ (uiop:run-program "cargo test")
11.10+ (write-line " tested rust crates"))
12.1--- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2+++ b/tests/demo_test.c Sun May 07 20:42:26 2023 -0400
12.3@@ -0,0 +1,8 @@
12.4+#include <stdio.h>
12.5+#include "demo.h"
12.6+
12.7+int main() {
12.8+ Service *srv = service_from_string("weather");
12.9+ printf!("%s\n",service_to_json_str(srv));
12.10+ free_service(srv);
12.11+}
13.1--- /dev/null Thu Jan 01 00:00:00 1970 +0000
13.2+++ b/tests/demo_test.py Sun May 07 20:42:26 2023 -0400
13.3@@ -0,0 +1,1 @@
13.4+from _demo import lib
14.1--- a/tk.lisp Sun May 07 18:06:13 2023 -0400
14.2+++ b/tk.lisp Sun May 07 20:42:26 2023 -0400
14.3@@ -2,6 +2,8 @@
14.4
14.5 (defvar *cargo-target* #P"/Users/ellis/dev/otom8/demo/target/")
14.6
14.7+(defvar *rs-macros* nil)
14.8+
14.9 (defmacro rs-find-dll (name &optional debug)
14.10 "Find the rust dll specified by NAME."
14.11 (cond
14.12@@ -13,7 +15,12 @@
14.13 (uiop:run-program `("cargo" "build" ,(unless debug "--release")) :output t)
14.14 `,(find-rust-dll name debug)))))
14.15
14.16-(defmacro rs-macroexpand (env &body body)
14.17+(defmacro rs-defmacro (args &body body)
14.18+ "Define a macro which expands to a string of Rust code.")
14.19+
14.20+(defun rs-macroexpand-1 (form &optional env))
14.21+
14.22+(defun rs-macroexpand (env &rest body)
14.23 "Cbindgen is quite the menace and really doesn't like our macros used
14.24 to generate C FFI bindings. To compensate for this, we use a tool
14.25 called cargo-expand by the most excellent dtolnay which expands Rust