changeset 20: |
3166a511fafb |
parent: |
2bbf5ce73537
|
author: |
ellis <ellis@rwest.io> |
date: |
Sat, 03 Jun 2023 19:57:10 -0400 |
permissions: |
-rw-r--r-- |
description: |
notes and dockerfile init |
3 ;; So basically, this was born out of personal frustration with how 4 ;; cbindgen and Rust macros work (they don't). Rust macros in general 5 ;; are something of a pain in my opinion, so I thought why not just 6 ;; generate Rust code from Lisp instead? 10 (defvar *cargo-target* #p"/Users/ellis/dev/otom8/demo/target/") 11 (defvar *rs-macros* nil) 14 (defmacro rs-defmacro (name args &body body) 15 "Define a macro which can be used within the body of a 'with-rs' form." 17 (defmacro ,name ,@(mapcar #`(,a1) args) ,@body) 18 (push ',name *rs-macros*))) 20 (defun rs-mod-form (crate &optional mods pub) 21 "Generate a basic mod form (CRATE . [MODS] [PUB])" 24 (defmacro with-rs-env (imports &body body) 25 "Generate an environment for use within a Rust generator macro." 26 `(let ((imports ,(mapcar #'rs-mod-form imports))) 27 (format nil "~A~&~A" imports ',body))) 29 (defun rs-use (crate &optional mods pub) 30 "Generate a single Rust use statement." 38 (lambda (x y) (format nil "~A,~A" x y)) 43 (defun rs-mod (mod &optional pub) 44 "Generate a single Rust mod statement." 50 (defun rs-imports (&rest imports) 51 "Generate a string of Rust 'use' statements." 54 (mapcar (lambda (x) (apply #'rs-use (apply #'rs-mod-form x))) imports)) 57 (defmacro rs-extern-c-fn (name args &optional pub unsafe no-mangle &body body) 58 "Generate a Rust extern 'C' fn." 61 ,(when no-mangle (format nil "#[no_mangle]~&")) 63 ,(when unsafe "unsafe ") 64 "extern \"C\" fn " ,name "(" 66 ((consp args) (reduce (lambda (x y) (format nil "~A,~A" x y)) args)) 70 (defun rs-obj-impl (obj) 71 "Implement Objective for give OBJ." 72 (format nil "impl Objective for ~A {};" obj)) 74 ;; (defun rs-macroexpand-1 (form &optional env)) 76 ;; (defun rs-macroexpand (env &rest body)