result/runtime: seal ok/err, macro-ize ~ dispatch
ober
2203a409e51df4fb22f367a1d712a330b230ce02
--- a/lib/jerboa/runtime.sls +++ b/lib/jerboa/runtime.sls @@ -79,8 +79,17 @@ (error 'call-method "no method" name (record-type-name type)))))) ;; ~ is the dispatch operator: (~ obj 'method args...) - (define (~ obj method-name . args) + ;; Expose an identifier macro so direct call sites inline to a plain + ;; call of call-method (no apply, no rest-list allocation), while a + ;; bare `~` still evaluates to a procedure value for higher-order use. + (define (~proc obj method-name . args) (apply call-method obj method-name args)) + (define-syntax ~ + (lambda (stx) + (syntax-case stx () + [(_ obj method-name arg ...) + #'(call-method obj method-name arg ...)] + [id (identifier? #'id) #'~proc]))) ;;;; ---- Hash tables (Gerbil API on Chez hashtables) ---- --- a/lib/std/result.sls +++ b/lib/std/result.sls @@ -32,9 +32,19 @@ (import (chezscheme)) ;; --- Records --- - - (define-record-type result-ok (fields value)) - (define-record-type result-err (fields value)) + ;; Sealed + nongenerative so cp0/cptypes can treat ok? / err? as + ;; singleton RTD checks and fold (ok? (ok x)) at compile time. + ;; The UIDs are stable across boot/compile, which Chez requires for + ;; cross-module constant folding. + + (define-record-type result-ok + (nongenerative std-result-ok-0d2d7f13-8a44-4c5f-9f4e-ok) + (sealed #t) + (fields value)) + (define-record-type result-err + (nongenerative std-result-err-0d2d7f13-8a44-4c5f-9f4e-err) + (sealed #t) + (fields value)) ;; --- Constructors ---