robert-strandh / SICL

A fresh implementation of Common Lisp
Other
1.07k stars 79 forks source link

Define primop, AST, and HIR instruction for taking the class of a standard object #187

Closed robert-strandh closed 4 years ago

robert-strandh commented 4 years ago

We would like to implement CLASS-OF as something like:

(defun class-of (object)
  (cond ((cleavir-primop:standard-object-p object)
         (cleavir-primop:class-of object))
        ((cleavir-primop:fixnump object)
         (load-time-value (find-class 'fixnum)))
        ((cleavir-primop:consp object)
         (load-time-value (find-class 'cons)))
        ((cleavir-primop:single-float-p object)
         (load-time-value (find-class 'single-float)))
        ((cleavir-primop:characterp object)
         (load-time-value (find-class 'character)))))

For that, we need a primop, an AST class, and a HIR instruction for returning the class of a standard object.

robert-strandh commented 4 years ago

I defined the primop, the AST class, and the instruction class. I also defined methods on CST-TO-AST, and COMPILE-AST.

I ended up calling the operator STANDARD-OBJECT-CLASS-OF to emphasize that it can handle only standard objects.