- (flet ((dispatch (name args &rest spec)
- ;; Evaluate the ARGS to determine their types and values. Find
- ;; the first SPEC, of the form (RETTY OP ARGTY*), where the
- ;; ARGTYs match the argument types, in order, and apply OP to
- ;; the argument values, return this as a result of type RETTY.
- ;; If no SPEC matches, then report an error.
-
- (oplambda
- (let ((args (mapcar (compose #'funcall #'cons) args)))
- (aif (find-if (lambda (item)
- (every (lambda (type arg)
- (eql type (car arg)))
- (cddr item) args))
- spec)
- (values (car it) (apply (cadr it) (mapcar #'cdr args)))
- (error "Type mismatch: operator `~A' applied to ~
- types ~{~(~A~)~#[~; and ~;, ~]~}"
- name (mapcar #'car args)))))))
+ (labels ((want (type thunk)
+ ;; Evaluate THUNK and convert its result to the given TYPE.
+ (multiple-value-bind (ty val) (funcall thunk)
+ (coerce-property-value val ty type)))
+
+ (int-unop (intop x)
+ ;; Evaluate X to an integer, and apply INTOP to the result,
+ ;; giving another integer.
+ (oplambda (values :int (funcall intop (want :int x)))))
+
+ (int-binop (intop x y)
+ ;; Evaluate X and Y to integers, and apply INTOP to the
+ ;; results, giving another integer.
+ (oplambda
+ (values :int (funcall intop (want :int x) (want :int y))))))