{"size": 2575, "ext": "scrbl", "max_stars_repo_path": "cpsc411-doc/cpsc411/scribblings/info-lib.scrbl", "max_stars_repo_name": "cpsc411/cpsc411-pub", "max_stars_repo_stars_event_min_datetime": "2021-03-25T21:32:20.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-02T10:52:41.000Z", "max_issues_repo_path": "cpsc411-doc/cpsc411/scribblings/info-lib.scrbl", "max_issues_repo_name": "cpsc411/cpsc411-pub", "max_issues_repo_issues_event_min_datetime": "2021-01-21T09:18:04.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T19:56:07.000Z", "max_forks_repo_path": "cpsc411-doc/cpsc411/scribblings/info-lib.scrbl", "max_forks_repo_name": "cpsc411/cpsc411-pub", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": 15, "max_forks_count": null, "avg_line_length": 31.0240963855, "max_line_length": 79, "alphanum_fraction": 0.6353398058}
#lang scribble/manual

@(require
  (for-label
   cpsc411/info
   racket/base
   racket/contract)
  scribble/eval)

@(define cpsc411-eval
  (make-base-eval "(require cpsc411/compiler-lib)"))

@title{Info Data Structure}
@defmodule[cpsc411/info-lib]
This library defines the @tech{info} datatype.
An @deftech{info} is a datatype used to represent dictionaries or maps in a
convenient readable way.
It is similar to an association list, but uses proper lists rather than pairs.
This makes it more memory intensive, but means we do not need to introduce
dotted pair notation.

@defproc[(info? [v any/c]) any/c]{
Returns @racket[#t] if @racket[v] is an @tech{info}, and @racket[#f] otherwise.

@examples[#:eval cpsc411-eval
(info? '())
(info? '((a . 5)))
(info? '((a 5)))]
}

@defform[(info/c (key-name spec) ...)]{
Creates an @tech{info} @racket[contract?], specifying that the @tech{info} must
contain a mapping for each @racket[key-name], and the value for each key must
satsify @racket[spec].
The @racket[spec] language is roughly the same as the BNF pattern language used
in this course, except all terminals must be @racket[contract?]s.

@examples[#:eval cpsc411-eval
(require racket/contract)
((info/c) '())
((info/c) 5)
((info/c (locals (aloc? ...))) '())
((info/c (locals (aloc? ...))) '((locals ())))
((info/c (locals (aloc? ...))) '((locals (x.1))))
((info/c (locals (aloc? ...))) '((locals (5))))
((info/c (locals (aloc? ...)))
 '((locals (x.1)) (assignments ((x.1 5)))))
(define loc? (or/c register? fvar?))
((info/c (locals (aloc? ...)) (assignment ((aloc? loc?) ...)))
 '((locals (x.1)) (assignment ((x.1 5)))))
((info/c (locals (aloc? ...)) (assignment ((aloc? loc?) ...)))
'((locals (x.1)) (assignment ((x.1 rax)))))
((info/c (locals (aloc? ...)) (assignment ((aloc? loc?) ...)))
'((assignment ((x.1 rax) (y.3 fv1) (x.2 rax)))
  (locals (x.1 x.2 y.3))))
]
}

@defproc[(info-ref [v info?] [key any/c]) (or/c #f any/c)]{
Returns the value associated with @racket[key] in @racket[v].

@examples[#:eval cpsc411-eval
(info-ref '((assignment ((x.1 rbx) (y.2 r)))) 'assignment)
(info-ref
  (info-ref '((assignment ((x.1 rbx) (y.2 r)))) 'assignment)
  'x.1)
]
}

@defproc[(info-set [v info?] [key any/c] [value any/c]) info?]{
Adds a mapping from @racket[key] to @racket[value] in the info @racket[v].

@examples[#:eval cpsc411-eval
(info-set '() 'x.1 'rbx)
(info-set (info-set '() 'x.1 'rbx) 'y.2 'r9)
(info-set '() 'assignment '((x.1 rbx) (y.2 r9)))
]
}

@defproc[(info-remove [v info?] [key any/c]) info?]{
Removed a mapping for @racket[key] in the info @racket[v].
}
