rebcabin / masr

Meta ASR: replacement for aging ASDL
MIT License
4 stars 0 forks source link

Informative: discriminating types #37

Open rebcabin opened 1 year ago

rebcabin commented 1 year ago

To cut down on the looseness of types like the following:

    | IntegerUnaryMinus(expr arg, ttype type, expr? value)
...
    | RealUnaryMinus(expr arg, ttype type, expr? value)

I am doing the following in full-form (legacy continues to support the more-loose ASDL.

(s/def ::logical-expr
  (s/or :logical-constant   ::LogicalConstant
        :logical-compare    ::LogicalCompare
        :integer-compare    ::IntegerCompare
        :logical-binop      ::LogicalBinOp
        :logical-not        ::LogicalNot
        :cast               ::Cast      ;; TODO check return type!
        :if-expr            ::IfExp     ;; TODO check return type!
        :named-expr         ::NamedExpr ;; TODO check return type!
        :var                ::Var       ;; TODO check return type!
        ;; TODO: integer-compare, etc.
        ))
;; #+end_src

;; #+begin_src clojure

(s/def ::logical-expr?  (.? ::logical-expr))
(s/def ::logical-value?     ::logical-expr?)

(s/def ::logical-left       ::logical-expr)
(s/def ::logical-right      ::logical-expr)
;; #+end_src

;;
;;
;; ### Integer Types
;;
;;

;; #+begin_src clojure

(s/def ::integer-expr
  (s/or :integer-constant    ::IntegerConstant
        :integer-binop       ::IntegerBinOp
        :integer-unary-minus ::IntegerUnaryMinus
        :integer-bit-not     ::IntegerBitNot
        :cast                ::Cast      ;; TODO check return type!
        :if-expr             ::IfExp     ;; TODO check return type!
        :named-expr          ::NamedExpr ;; TODO check return type!
        :var                 ::Var       ;; TODO check return type!
        ))
;; #+end_src

;; #+begin_src clojure

(s/def ::integer-expr?  (.? ::integer-expr))
(s/def ::integer-value?     ::integer-expr?)

(s/def ::integer-left  ::integer-expr)
(s/def ::integer-right ::integer-expr)
;; #+end_src

;;
;;
;; ### Real Types
;;
;;

;; #+begin_src clojure

(s/def ::real-expr
  (s/or :real-constant    ::RealConstant
        :real-binop       ::RealBinOp
        :real-unary-minus ::RealUnaryMinus
        :cast             ::Cast      ;; TODO check return type!
        :if-expr          ::IfExp     ;; TODO check return type!
        :named-expr       ::NamedExpr ;; TODO check return type!
        :var              ::Var       ;; TODO check return type!
        ))
;; #+end_src

;; #+begin_src clojure

(s/def ::real-expr?  (.? ::real-expr))
(s/def ::real-value?     ::real-expr?)

(s/def ::real-left  ::real-expr)
(s/def ::real-right ::real-expr)
;; #+end_src