Cleaned up base-env. Added comments about untyped identifiers.

Used one-of/c to clean up some types.

original commit: 1348887bd14a115518a4e0eab053b3bdd348e91b
This commit is contained in:
Eric Dobson 2011-06-16 22:37:40 -04:00 committed by Sam Tobin-Hochstadt
parent ee96de4dce
commit 2c4a553459
2 changed files with 55 additions and 30 deletions

View File

@ -35,17 +35,15 @@
[raise (Univ . -> . (Un))]
[error
(make-Function (list
(make-arr (list Sym -String) (Un) #:rest Univ)
(make-arr (list -String) (Un) #:rest Univ)
(make-arr (list Sym) (Un))))]
(cl->* (-> Sym (Un))
(->* (list -String) Univ (Un))
(->* (list Sym -String) Univ (Un)))]
[raise-user-error
(make-Function (list
(make-arr (list Sym -String) (Un) #:rest Univ)
(make-arr (list -String) (Un) #:rest Univ)
(make-arr (list Sym) (Un))))]
(cl->* (-> Sym (Un))
(->* (list -String) Univ (Un))
(->* (list Sym -String) Univ (Un)))]
;raise-type-error (in index)
[raise-mismatch-error (-> Sym -String Univ (Un))]
@ -642,7 +640,7 @@
(-Pathlike -Nat . -> . -Void)
(-Pathlike (-opt -Nat) (-> Univ) . -> . Univ))]
[file-or-directory-permissions (-> -Pathlike (-lst (Un (-val 'read) (-val 'write) (-val 'execute))))]
[file-or-directory-permissions (-> -Pathlike (-lst (one-of/c 'read 'write 'execute)))]
[file-or-directory-identity (->opt -Pathlike (Univ) -Nat)]
[file-size (-> -Pathlike -Nat)]
@ -824,7 +822,7 @@
[make-directory (-> -Pathlike -Void)]
[delete-file (-> -Pathlike -Void)]
[make-namespace (->opt [(Un (-val 'empty) (-val 'initial))] -Namespace)]
[make-namespace (->opt [(one-of/c 'empty 'initial)] -Namespace)]
[make-base-namespace (-> -Namespace)]
[eval (->opt Univ [-Namespace] Univ)]
@ -968,7 +966,7 @@
;; scheme/path
[explode-path (-SomeSystemPathlike . -> . (-lst (Un -SomeSystemPath (-val 'up) (-val 'same))))]
[explode-path (-SomeSystemPathlike . -> . (-lst (Un -SomeSystemPath (one-of/c 'up 'same))))]
[find-relative-path (-SomeSystemPathlike -SomeSystemPathlike . -> . -SomeSystemPath)]
[simple-form-path (-Pathlike . -> . -Path)]
[normalize-path (cl->* (-Pathlike [-Pathlike] . ->opt . -Path))]
@ -977,7 +975,7 @@
[path-only (-SomeSystemPathlike . -> . (-opt -Path))]
[some-system-path->string (-SomeSystemPath . -> . -String)]
[string->some-system-path
(-String (Un (-val 'unix) (-val 'windows)) . -> . -SomeSystemPath)]
(-String (one-of/c 'unix 'windows) . -> . -SomeSystemPath)]
@ -1197,8 +1195,8 @@
;Section 12.1.3
[flush-output (->opt [-Output-Port] -Void)]
[file-stream-buffer-mode (cl-> [(-Port) (Un (-val 'none) (-val 'line) (-val 'block) (-val #f))]
[(-Port (Un (-val 'none) (-val 'line) (-val 'block))) -Void])]
[file-stream-buffer-mode (cl-> [(-Port) (one-of/c 'none 'line 'block #f)]
[(-Port (one-of/c 'none 'line 'block)) -Void])]
[file-position (cl-> [(-Port) -Nat]
[(-Port -Integer) -Void])]
@ -1208,7 +1206,7 @@
[port-count-lines-enabled (-Param Univ B)]
;Section 12.1.5
[open-input-file (->key -Pathlike #:mode (Un (-val 'binary) (-val 'text)) #f -Input-Port)]
[open-input-file (->key -Pathlike #:mode (one-of/c 'binary 'text) #f -Input-Port)]
[open-output-file
(->key -Pathlike
#:mode (one-of/c 'binary 'text) #f
@ -1230,12 +1228,12 @@
[call-with-input-file (-poly (a) (-Pathlike (-Input-Port . -> . a) #:mode (Un (-val 'binary) (-val 'text)) #f . ->key . a))]
[call-with-output-file (-poly (a) (-Pathlike (-Output-Port . -> . a)
#:exists (one-of/c 'error 'append 'update 'replace 'truncate 'truncate/replace) #f
#:mode (Un (-val 'binary) (-val 'text)) #f
#:mode (one-of/c 'binary 'text) #f
. ->key . a))]
[call-with-input-file* (-poly (a) (-Pathlike (-Input-Port . -> . a) #:mode (Un (-val 'binary) (-val 'text)) #f . ->key . a))]
[call-with-output-file* (-poly (a) (-Pathlike (-Output-Port . -> . a)
#:exists (one-of/c 'error 'append 'update 'replace 'truncate 'truncate/replace) #f
#:mode (Un (-val 'binary) (-val 'text)) #f
#:mode (one-of/c 'binary 'text) #f
. ->key . a))]
[with-input-from-file
@ -1250,7 +1248,7 @@
a))]
[port-try-file-lock? (-> (Un -Input-Port -Output-Port) (Un (-val 'shared) (-val 'exclusive)) B)]
[port-try-file-lock? (-> (Un -Input-Port -Output-Port) (one-of/c 'shared 'exclusive) B)]
[port-file-unlock (-> (Un -Input-Port -Output-Port) -Void)]
[port-file-identity (-> (Un -Input-Port -Output-Port) -PosInt)]
@ -1262,6 +1260,9 @@
([Univ] . ->opt . -Output-Port)]
[open-output-bytes
([Univ] . ->opt . -Output-Port)]
;FIXME
;These should be fixed to only accept output-ports generated by open-output-{string,bytes}
[get-output-bytes (-Output-Port [Univ N N] . ->opt . -Bytes)]
[get-output-string (-> -Output-Port -String)]
@ -1279,6 +1280,10 @@
;12.1.9
;TODO write the types for these
;They are fairly complicated and require events
;make-input-port
;make-output-port
@ -1294,16 +1299,16 @@
[port->bytes (->opt [-Input-Port] -Bytes)]
[port->lines
(cl->*
(->key #:line-mode (Un (-val 'linefeed) (-val 'return) (-val 'return-linefeed) (-val 'any) (-val 'any-one)) #f (-lst -String))
(->key -Input-Port #:line-mode (Un (-val 'linefeed) (-val 'return) (-val 'return-linefeed) (-val 'any) (-val 'any-one)) #f (-lst -String)))]
(->key #:line-mode (one-of/c 'linefeed 'return 'return-linefeed 'any 'any-one) #f (-lst -String))
(->key -Input-Port #:line-mode (one-of/c 'linefeed 'return 'return-linefeed 'any 'any-one) #f (-lst -String)))]
[port->bytes-lines
(cl->*
(->key #:line-mode (Un (-val 'linefeed) (-val 'return) (-val 'return-linefeed) (-val 'any) (-val 'any-one)) #f (-lst -Bytes))
(->key -Input-Port #:line-mode (Un (-val 'linefeed) (-val 'return) (-val 'return-linefeed) (-val 'any) (-val 'any-one)) #f (-lst -Bytes)))]
(->key #:line-mode (one-of/c 'linefeed 'return 'return-linefeed 'any 'any-one) #f (-lst -Bytes))
(->key -Input-Port #:line-mode (one-of/c 'linefeed 'return 'return-linefeed 'any 'any-one) #f (-lst -Bytes)))]
[display-lines (cl->*
((-lst Univ) #:seperator Univ #f . ->key . -Void)
((-lst Univ) -Output-Port #:seperator Univ #f . ->key . -Void))]
((-lst Univ) #:separator Univ #f . ->key . -Void)
((-lst Univ) -Output-Port #:separator Univ #f . ->key . -Void))]
[call-with-output-string (-> (-> -Output-Port ManyUniv) -String)]
@ -1325,6 +1330,10 @@
[input-port-append (->* (list Univ) -Input-Port -Input-Port)]
;TODO write the type for this
;It is fairly complicated and require events
;make-input-port/read-to-peek
[make-limited-input-port (->opt -Input-Port -Nat [Univ] -Input-Port)]
@ -1405,7 +1414,7 @@
[peek-char-or-special (->opt [-Input-Port -Nat] Univ)]
[peek-byte-or-special (->opt [-Input-Port -Nat] Univ)]
;port-progress-evt
;port-progress-evt TODO event
[port-provides-progress-evts? (-> -Input-Port B)]
@ -1426,6 +1435,7 @@
[newline (->opt [-Output-Port] -Void)]
;In index
;write-string
;write-bytes
;write-bytes-avail*
@ -1514,8 +1524,8 @@
(cl->* (-> -Output-Port (-> Univ -Output-Port ManyUniv))
(-> -Output-Port (-> Univ -Output-Port ManyUniv) -Void))]
[global-port-print-handler (-Param (Un (-> Univ -Output-Port ManyUniv) (-> Univ -Output-Port (Un (-val 0) (-val 1)) ManyUniv))
(-> Univ -Output-Port (Un (-val 0) (-val 1)) ManyUniv))]
[global-port-print-handler (-Param (Un (-> Univ -Output-Port ManyUniv) (-> Univ -Output-Port (one-of/c 0 1) ManyUniv))
(-> Univ -Output-Port (one-of/c 0 1) ManyUniv))]
@ -1530,7 +1540,7 @@
;Section 12.8
;; racket/pretty
[pretty-print (Univ [-Output-Port (Un (-val 0) (-val 1))] . ->opt . -Void)]
[pretty-print (Univ [-Output-Port (one-of/c 0 1)] . ->opt . -Void)]
[pretty-write (Univ [-Output-Port] . ->opt . -Void)]
[pretty-display (Univ [-Output-Port] . ->opt . -Void)]
[pretty-format (Univ [-Output-Port] . ->opt . -Void)]
@ -1567,11 +1577,24 @@
;12.9.1
[readtable? (make-pred-ty -Read-Table)]
;[make-readtable (-> -Read-Table ??? -Read-Table)]
[make-readtable
(cl->*
(-> -Read-Table -Read-Table)
(-> -Read-Table
(-opt -Char) (Un (one-of/c 'terminating-macro 'non-terminating-macro 'dispatch-macro) -Char)
(-> -Char -Input-Port (-opt -PosInt) (-opt -Nat) (-opt -PosInt) (-opt -Nat) Univ)
-Read-Table)
(-> -Read-Table
(-opt -Char) (Un (one-of/c 'terminating-macro 'non-terminating-macro 'dispatch-macro) -Char)
(-> -Char -Input-Port (-opt -PosInt) (-opt -Nat) (-opt -PosInt) (-opt -Nat) Univ)
(-opt -Char) (Un (one-of/c 'terminating-macro 'non-terminating-macro 'dispatch-macro) -Char)
(-> -Char -Input-Port (-opt -PosInt) (-opt -Nat) (-opt -PosInt) (-opt -Nat) Univ)
-Read-Table))]
[readtable-mapping (-> -Read-Table -Char
(-values (list
(Un -Char (-val 'terminating-macro) (-val 'non-terminating-macro))
(Un -Char (one-of/c 'terminating-macro 'non-terminating-macro))
(-opt (Un (-> -Char -Input-Port (-opt -PosInt) (-opt -Nat)
(-opt -PosInt) (-opt -Nat) Univ)
(cl->*

View File

@ -181,6 +181,8 @@
;A Type that corresponds to the any contract for the
;return type of functions
;FIXME
;This is not correct as Univ is only a single value.
(define ManyUniv Univ)
(define -Port (*Un -Output-Port -Input-Port))