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

KindCoveredAll%
expression025 0.0
branch00nil
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 ;;; rs/pkg.lisp --- Rust Code Generator
2
 
3
 ;; Lisp -> Rust
4
 
5
 ;;; Commentary:
6
 
7
 ;; This code is bootstrapped from a tiny DSL I made for working with cbindgen
8
 ;; a few years back. Here's the header comment in that file:
9
 
10
 #|
11
 ;; So basically, this was born out of personal frustration with how
12
 ;; cbindgen and Rust macros work (they don't). Rust macros in general
13
 ;; are something of a pain in my opinion, so I thought why not just
14
 ;; generate Rust code from Lisp instead?
15
 |#
16
 
17
 ;; ref: 
18
 ;; ref: https://rust-lang.github.io/rfcs/3424-cargo-script.html
19
 ;; ref: https://github.com/rust-analyzer/ungrammar/blob/master/rust.ungram
20
 
21
 ;;; Code:
22
 (defpackage :syn/gen/rs
23
   (:nicknames :gen/rs)
24
   (:use :cl :syn/gen :cli/tools/rust :ast :id :std/pipe :std/meta :syn/gen/c)
25
   (:import-from :std :in-readtable :eval-always)
26
   (:import-from :doc :file-header)
27
   (:import-from :syn/gen/c :c-type)
28
   (:shadow :cl-reader :else :body)
29
   (:export
30
    #:*rs-backend*
31
    #:*rs-symbols*
32
    #:*rs-syntax*
33
    #:*rs-reserved*
34
    #:*rs-exports*
35
    #:*rs-swap*
36
    #:rs-syntax
37
    :trait
38
    #:gen-rs
39
    #:read-gen-rs-file
40
    #:read-gen-rs-string
41
    #:rs-reader-switch
42
    #:rs-reader))
43
 
44
 (in-package :syn/gen/rs)
45
 
46
 (defvar *rs-backend*
47
   (append *cl-symbols* '()))
48
 
49
 (export *rs-backend*)
50
 
51
 (defparameter *rs-symbols* 
52
   '(<= >= < > + - * / = 
53
     for while return break continue if type let loop))
54
 
55
 (defparameter *rs-syntax*
56
   '(|| && == != % << >> ^ | & += /= *= %= >>= <<= -= |= &= ^=
57
     pub crate enum struct mod fn extern else super as
58
     const impl in match move mut ref self static safe unsafe use where
59
     ;; weak keywords
60
     macro-rules union
61
     ;; 2018+
62
     async await dyn))
63
 
64
 (defparameter *rs-reserved*
65
   '(abstract become do final macro override priv typeof unsized virtual yield
66
     ;; 2018+
67
     try))
68
 
69
 (defparameter *rs-exports* (append *rs-symbols* *rs-syntax* *cl-symbols*))
70
 
71
 (defparameter *rs-swap* (append *rs-symbols* *rs-syntax*))
72
 
73
 (pkg:defpackage* :syn/gen/rs/swap
74
     (:shadow-symbols *rs-swap*))
75
 
76
 (pkg:defpackage* :syn/gen/rs/sym
77
     (:shadow-symbols *rs-swap* :export-symbols *rs-exports*)
78
   (:nicknames :rs)
79
   (:use :cl)
80
   (:import-from :syn/gen :gen-package)
81
   (:import-from :syn/gen/c :cl-reader :switch-reader :decompose-declaration))