bugfixes #66
@@ -102,15 +102,22 @@ forms, and what remains."
|
|||||||
;;; hand-written vec2__length would collide, and an identifier holding
|
;;; hand-written vec2__length would collide, and an identifier holding
|
||||||
;;; `__' is reserved in C++, which a pub header may be included from.
|
;;; `__' is reserved in C++, which a pub header may be included from.
|
||||||
;;; Lifted closures carry a ƛ for the same reason.
|
;;; Lifted closures carry a ƛ for the same reason.
|
||||||
|
;;;
|
||||||
|
;;; zero? -> zeroʔ, clear! -> clearꜝ: a glottal stop and a raised
|
||||||
|
;;; exclamation mark, both letters. Not the retroflex click ǃ, which
|
||||||
|
;;; looks more like `!' -- enough that clang warns at every use.
|
||||||
|
(define +name-spellings+
|
||||||
|
'(("-(?!>)" . "_") ("/" . "ː") ("\\?" . "ʔ") ("!" . "ꜝ")))
|
||||||
|
|
||||||
(define (unkebabify sym)
|
(define (unkebabify sym)
|
||||||
(case sym
|
(case sym
|
||||||
((- -- -> -= / /=) sym) ; bare operators, not names
|
((- -- -> -= / /= ! != ?) sym) ; bare operators, not names
|
||||||
(else
|
(else
|
||||||
(string->symbol
|
(string->symbol
|
||||||
(irregex-replace/all
|
(fold (lambda (spelling name)
|
||||||
"/"
|
(irregex-replace/all (car spelling) name (cdr spelling)))
|
||||||
(irregex-replace/all "-(?!>)" (symbol->string sym) "_")
|
(symbol->string sym)
|
||||||
"ː")))))
|
+name-spellings+)))))
|
||||||
|
|
||||||
(define (atom-to-fmt-c atom)
|
(define (atom-to-fmt-c atom)
|
||||||
(case atom
|
(case atom
|
||||||
|
|||||||
@@ -13,6 +13,13 @@
|
|||||||
(test '_this_->_member_ (unkebabify '-this-->-member-))
|
(test '_this_->_member_ (unkebabify '-this-->-member-))
|
||||||
(test '__->>> (unkebabify '--->>>))
|
(test '__->>> (unkebabify '--->>>))
|
||||||
|
|
||||||
|
;; A Lisp predicate and mutator, in letters C takes. The operators
|
||||||
|
;; spelled with the same characters are not names
|
||||||
|
(test 'ident_startʔ (unkebabify 'ident-start?))
|
||||||
|
(test 'resetꜝ (unkebabify 'reset!))
|
||||||
|
(test '! (unkebabify '!))
|
||||||
|
(test '!= (unkebabify '!=))
|
||||||
|
|
||||||
;; Non-ASCII identifiers must survive intact. The `regex' egg's
|
;; Non-ASCII identifiers must survive intact. The `regex' egg's
|
||||||
;; string-substitute drops one trailing character per multi-byte
|
;; string-substitute drops one trailing character per multi-byte
|
||||||
;; character, which renames things silently -- the C still compiles,
|
;; character, which renames things silently -- the C still compiles,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
(input)
|
(input)
|
||||||
(output "café 日本語 🍺" "café1" "naïve: 3")
|
(output "café 日本語 🍺" "café1" "naïve: 3" "predicate: 1 0")
|
||||||
(return 0)
|
(return 0)
|
||||||
|
|
||||||
;;; Non-ASCII string literals and identifiers.
|
;;; Non-ASCII string literals and identifiers.
|
||||||
@@ -13,12 +13,22 @@
|
|||||||
;;; non-ASCII characters must survive unkebabify intact -- getting this
|
;;; non-ASCII characters must survive unkebabify intact -- getting this
|
||||||
;;; wrong truncates the name silently, and the program still compiles
|
;;; wrong truncates the name silently, and the program still compiles
|
||||||
;;; and runs, just under a different name than the one written.
|
;;; and runs, just under a different name than the one written.
|
||||||
|
;;;
|
||||||
|
;;; `?' and `!' end Lisp predicates and mutators, and C takes neither:
|
||||||
|
;;; they become the letters ʔ and ꜝ.
|
||||||
|
|
||||||
(include stdio.h)
|
(include stdio.h)
|
||||||
|
|
||||||
|
(fn zero? ((n int)) bool (return (== n 0)))
|
||||||
|
(fn clear! ((n (* int))) void (= (* n) 0))
|
||||||
|
|
||||||
(pub fn main () int
|
(pub fn main () int
|
||||||
(puts "café 日本語 🍺")
|
(puts "café 日本語 🍺")
|
||||||
(puts "café1")
|
(puts "café1")
|
||||||
(var naïve-count int 3)
|
(var naïve-count int 3)
|
||||||
(printf "naïve: %d\n" naïve-count)
|
(printf "naïve: %d\n" naïve-count)
|
||||||
|
(var n int 5)
|
||||||
|
(var before bool (zero? n))
|
||||||
|
(clear! (& n))
|
||||||
|
(printf "predicate: %d %d\n" (zero? n) before)
|
||||||
(return 0))
|
(return 0))
|
||||||
|
|||||||
Reference in New Issue
Block a user