• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Apt
        • Error-checking
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Set
        • C
          • Syntax-for-tools
            • Formalized-subset
            • Mapping-to-language-definition
            • Input-files
            • Compilation-database
            • Printer
            • Output-files
            • Abstract-syntax-operations
            • Implementation-environments
            • Abstract-syntax
            • Concrete-syntax
            • Disambiguation
            • Validation
            • Gcc-builtins
            • Preprocessing
              • Preprocessor
                • Preprocessor-states
                  • Plexeme
                  • Ppstate
                  • Pnumber
                  • Macro-info
                  • Macro-add
                    • Init-ppstate
                    • Plexeme-token/newline-p
                    • Newline
                    • Plexeme-option
                    • Macro-info-option
                    • Macro-table
                    • Plexeme+span
                    • Update-ppstate->lexemes-unread
                    • Update-ppstate->lexemes-read
                    • Update-ppstate->lexemes-length
                    • Update-ppstate->chars-unread
                    • Update-ppstate->chars-read
                    • Update-ppstate->version
                    • Update-ppstate->position
                    • Update-ppstate->macros
                    • Update-ppstate->chars-length
                    • Macro-lookup
                    • Update-ppstate->bytes
                    • Update-ppstate->size
                    • Plexeme-token/space-p
                    • Plexeme-tokenp
                    • Ppstate->gcc
                    • Plexeme-list-token/space-p
                    • Ppstate->size
                    • Ppstate->lexemes-unread
                    • Ppstate->lexemes-read
                    • Ppstate->lexemes-length
                    • Ppstate->chars-unread
                    • Ppstate->bytes
                    • Plexeme-list-token/newline-p
                    • Plexeme-list-not-token/newline-p
                    • Ident-macroinfo-alist
                    • Update-ppstate->lexeme
                    • Update-ppstate->char
                    • Ppstate->version
                    • Ppstate->macros
                    • Ppstate->chars-read
                    • Ppstate->chars-length
                    • Plexeme-list-tokenp
                    • Plexeme-list-not-tokenp
                    • Macro-table-init
                    • Ppstate->lexeme
                    • Ppstate->char
                    • Ppstate-fix
                    • Plexeme+span-list
                    • Plexeme-list
                    • Irr-pnumber
                    • Irr-plexeme
                    • Irr-macro-table
                    • Ppstate->position
                  • Preprocessor-printer
                  • Pread-token/newline
                  • Pread-token
                  • Preprocessor-lexer
                  • Pproc-files
                  • Pproc-file
                  • Filepath-plexeme-list-alist-to-filepath-filedata-map
                  • Filepath-plexeme-list-alist
                  • Preprocessor-reader
                  • Preprocessor-messages
                • External-preprocessing
              • Parsing
            • Atc
            • Transformation-tools
            • Language
            • Representation
            • Insertion-sort
            • Pack
          • Soft
          • Bv
          • Imp-language
          • Ethereum
          • Event-macros
          • Java
          • Riscv
          • Bitcoin
          • Zcash
          • Yul
          • ACL2-programming-language
          • Prime-fields
          • Json
          • Syntheto
          • File-io-light
          • Cryptography
          • Number-theory
          • Axe
          • Lists-light
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Preprocessor-states

    Macro-add

    Add a macro to the macro table.

    Signature
    (macro-add name info table) → (mv erp new-table)
    Arguments
    name — Guard (identp name).
    info — Guard (macro-infop info).
    table — Guard (macro-tablep table).
    Returns
    new-table — Type (macro-tablep new-table).

    If the table already contains a macro with the given name, the associated information must be the same: this realizes the requirement in [C17:6.10.3/2], namely that multiple definitions are allowed so long as they are of the same kind (both object-like or both function-like), they have the same parameters if both function-like, and they have identical replacement list. The latter notion [C17:6.10.3/1] amounts to equality for us, because, as explained in macro-info, we normalize all whitespace to single spaces. If all these conditions are satisfied, the table does not change; otherwise, we return an error.

    If the table does not already contain a macro with the given name, it is added to the table.

    Definitions and Theorems

    Function: macro-add

    (defun macro-add (name info table)
     (declare (xargs :guard (and (identp name)
                                 (macro-infop info)
                                 (macro-tablep table))))
     (b* (((reterr) (irr-macro-table))
          (name (ident-fix name))
          (info (macro-info-fix info))
          (alist (macro-table->alist table))
          (name+info (assoc-equal name alist)))
      (if name+info
       (if (equal info (cdr name+info))
           (retok (macro-table-fix table))
        (reterr
         (msg
          "Duplicate macro ~x0 ~
                            with incompatible definitions ~x1 and ~x2."
          name info (cdr name+info))))
       (retok (macro-table (acons name info alist))))))

    Theorem: macro-tablep-of-macro-add.new-table

    (defthm macro-tablep-of-macro-add.new-table
      (b* (((mv acl2::?erp ?new-table)
            (macro-add name info table)))
        (macro-tablep new-table))
      :rule-classes :rewrite)

    Theorem: macro-add-of-ident-fix-name

    (defthm macro-add-of-ident-fix-name
      (equal (macro-add (ident-fix name) info table)
             (macro-add name info table)))

    Theorem: macro-add-ident-equiv-congruence-on-name

    (defthm macro-add-ident-equiv-congruence-on-name
      (implies (ident-equiv name name-equiv)
               (equal (macro-add name info table)
                      (macro-add name-equiv info table)))
      :rule-classes :congruence)

    Theorem: macro-add-of-macro-info-fix-info

    (defthm macro-add-of-macro-info-fix-info
      (equal (macro-add name (macro-info-fix info)
                        table)
             (macro-add name info table)))

    Theorem: macro-add-macro-info-equiv-congruence-on-info

    (defthm macro-add-macro-info-equiv-congruence-on-info
      (implies (macro-info-equiv info info-equiv)
               (equal (macro-add name info table)
                      (macro-add name info-equiv table)))
      :rule-classes :congruence)

    Theorem: macro-add-of-macro-table-fix-table

    (defthm macro-add-of-macro-table-fix-table
      (equal (macro-add name info (macro-table-fix table))
             (macro-add name info table)))

    Theorem: macro-add-macro-table-equiv-congruence-on-table

    (defthm macro-add-macro-table-equiv-congruence-on-table
      (implies (macro-table-equiv table table-equiv)
               (equal (macro-add name info table)
                      (macro-add name info table-equiv)))
      :rule-classes :congruence)