* Added file-options macro

This commit is contained in:
Abdulaziz Ghuloum 2007-10-11 23:43:25 -04:00
parent 4649598a7e
commit fdc0132573
6 changed files with 43 additions and 5 deletions

Binary file not shown.

View File

@ -1,11 +1,12 @@
(library (ikarus codecs) (library (ikarus codecs)
(export latin-1-codec utf-8-codec utf-16-codec native-eol-style (export latin-1-codec utf-8-codec utf-16-codec native-eol-style
make-transcoder native-transcoder buffer-mode?) make-transcoder native-transcoder buffer-mode?
file-options-spec)
(import (import
(except (ikarus) latin-1-codec utf-8-codec utf-16-codec (except (ikarus) latin-1-codec utf-8-codec utf-16-codec
native-eol-style make-transcoder native-transcoder native-eol-style make-transcoder native-transcoder
buffer-mode?) buffer-mode? file-options-spec)
(ikarus system $transcoders)) (ikarus system $transcoders))
(define (latin-1-codec) 'latin-1-codec) (define (latin-1-codec) 'latin-1-codec)
(define (utf-8-codec) 'utf-8-codec) (define (utf-8-codec) 'utf-8-codec)
@ -65,5 +66,31 @@
(define (buffer-mode? x) (define (buffer-mode? x)
(and (memq x '(none line block)) #t)) (and (memq x '(none line block)) #t))
(define file-options-vec
'#(fo:default
fo:no-create
fo:no-fail
fo:no-fail/no-create
fo:no-truncate
fo:no-truncate/no-create
fo:no-truncate/no-fail
fo:no-truncate/no-fail/no-create))
(define file-options-alist
'([no-create . #b001]
[no-fail . #b010]
[no-truncate . #b100]))
(define (file-options-spec ls)
(unless (list? ls)
(error 'file-options-spec "~s is not a list" ls))
(let f ([ls ls] [n 0])
(cond
[(null? ls) (vector-ref file-options-vec n)]
[(assq (car ls) file-options-alist) =>
(lambda (a)
(f (cdr ls) (fxlogor (cdr a) n)))]
[else #f])))
) )

View File

@ -133,6 +133,7 @@
[trace-define (macro . trace-define)] [trace-define (macro . trace-define)]
[eol-style (macro . eol-style)] [eol-style (macro . eol-style)]
[buffer-mode (macro . buffer-mode)] [buffer-mode (macro . buffer-mode)]
[file-options (macro . file-options)]
[error-handling-mode (macro . error-handling-mode)] [error-handling-mode (macro . error-handling-mode)]
)) ))
@ -969,7 +970,7 @@
[close-port r ip] [close-port r ip]
[eol-style i r ip] [eol-style i r ip]
[error-handling-mode i r ip] [error-handling-mode i r ip]
[file-options r ip] [file-options i r ip]
[flush-output-port i r ip] [flush-output-port i r ip]
[get-bytevector-all r ip] [get-bytevector-all r ip]
[get-bytevector-n r ip] [get-bytevector-n r ip]
@ -1199,6 +1200,7 @@
[$transcoder? $transc] [$transcoder? $transc]
[$transcoder->data $transc] [$transcoder->data $transc]
[$data->transcoder $transc] [$data->transcoder $transc]
[file-options-spec i]
)) ))
(define (macro-identifier? x) (define (macro-identifier? x)

View File

@ -1,7 +1,8 @@
(library (psyntax compat) (library (psyntax compat)
(export define-record make-parameter parameterize format gensym (export define-record make-parameter parameterize format gensym
eval-core make-record-type symbol-value set-symbol-value!) eval-core make-record-type symbol-value set-symbol-value!
file-options-spec)
(import (import
(only (ikarus compiler) eval-core) (only (ikarus compiler) eval-core)
(rename (ikarus) (define-record sys.define-record))) (rename (ikarus) (define-record sys.define-record)))

View File

@ -1879,6 +1879,13 @@
((type-descriptor) type-descriptor-transformer) ((type-descriptor) type-descriptor-transformer)
(else (error 'macro-transformer "cannot find ~s" name))))) (else (error 'macro-transformer "cannot find ~s" name)))))
(define file-options-macro
(lambda (x)
(syntax-match x ()
((_ opt* ...)
(and (for-all id? opt*) (file-options-spec (map id->sym opt*)))
(bless `(quote ,(file-options-spec (map id->sym opt*))))))))
(define symbol-macro (define symbol-macro
(lambda (x set) (lambda (x set)
(syntax-match x () (syntax-match x ()
@ -1920,6 +1927,7 @@
((buffer-mode) ((buffer-mode)
(lambda (x) (lambda (x)
(symbol-macro x '(none line block)))) (symbol-macro x '(none line block))))
((file-options) file-options-macro)
((... => _ else unquote unquote-splicing ((... => _ else unquote unquote-splicing
unsyntax unsyntax-splicing) unsyntax unsyntax-splicing)
incorrect-usage-macro) incorrect-usage-macro)

View File

@ -546,7 +546,7 @@
[close-port S ip] [close-port S ip]
[eol-style C ip] [eol-style C ip]
[error-handling-mode C ip] [error-handling-mode C ip]
[file-options S ip] [file-options C ip]
[flush-output-port S ip] [flush-output-port S ip]
[get-bytevector-all S ip] [get-bytevector-all S ip]
[get-bytevector-n S ip] [get-bytevector-n S ip]