Evaluate an integer constant.
(eval-iconst ic) → val
This is according to [C:6.4.4.1/5]: based on the suffixes and the base, we find the first type that suffices to represent the value, in the lists indicated in the table, and we return the value of the found type. If the value is too large, we return an error.
This is the dynamic counterpart of check-iconst.
Function:
(defun eval-iconst (ic) (declare (xargs :guard (iconstp ic))) (let ((__function__ 'eval-iconst)) (declare (ignorable __function__)) (b* (((iconst ic) ic) (error (error (list :iconst-out-of-range (iconst-fix ic))))) (if ic.unsignedp (iconst-length-case ic.length :none (cond ((uint-integerp ic.value) (value-uint ic.value)) ((ulong-integerp ic.value) (value-ulong ic.value)) ((ullong-integerp ic.value) (value-ullong ic.value)) (t error)) :long (cond ((ulong-integerp ic.value) (value-ulong ic.value)) ((ullong-integerp ic.value) (value-ullong ic.value)) (t error)) :llong (cond ((ullong-integerp ic.value) (value-ullong ic.value)) (t error))) (iconst-length-case ic.length :none (if (iconst-base-case ic.base :dec) (cond ((sint-integerp ic.value) (value-sint ic.value)) ((slong-integerp ic.value) (value-slong ic.value)) ((sllong-integerp ic.value) (value-sllong ic.value)) (t error)) (cond ((sint-integerp ic.value) (value-sint ic.value)) ((uint-integerp ic.value) (value-uint ic.value)) ((slong-integerp ic.value) (value-slong ic.value)) ((ulong-integerp ic.value) (value-ulong ic.value)) ((sllong-integerp ic.value) (value-sllong ic.value)) ((ullong-integerp ic.value) (value-ullong ic.value)) (t error))) :long (if (iconst-base-case ic.base :dec) (cond ((slong-integerp ic.value) (value-slong ic.value)) ((sllong-integerp ic.value) (value-sllong ic.value)) (t error)) (cond ((slong-integerp ic.value) (value-slong ic.value)) ((ulong-integerp ic.value) (value-ulong ic.value)) ((sllong-integerp ic.value) (value-sllong ic.value)) ((ullong-integerp ic.value) (value-ullong ic.value)) (t error))) :llong (if (iconst-base-case ic.base :dec) (cond ((sllong-integerp ic.value) (value-sllong ic.value)) (t error)) (cond ((sllong-integerp ic.value) (value-sllong ic.value)) ((ullong-integerp ic.value) (value-ullong ic.value)) (t error))))))))
Theorem:
(defthm value-resultp-of-eval-iconst (b* ((val (eval-iconst ic))) (value-resultp val)) :rule-classes :rewrite)
Theorem:
(defthm eval-iconst-of-iconst-fix-ic (equal (eval-iconst (iconst-fix ic)) (eval-iconst ic)))
Theorem:
(defthm eval-iconst-iconst-equiv-congruence-on-ic (implies (iconst-equiv ic ic-equiv) (equal (eval-iconst ic) (eval-iconst ic-equiv))) :rule-classes :congruence)