emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/native-comp ec88bdb 1/4: * Add a simple growable vector like typ


From: Andrea Corallo
Subject: feature/native-comp ec88bdb 1/4: * Add a simple growable vector like type
Date: Tue, 23 Feb 2021 18:24:55 -0500 (EST)

branch: feature/native-comp
commit ec88bdba6fea4af18e5662d4d4a4339ebc1f81ff
Author: Andrea Corallo <akrl@sdf.org>
Commit: Andrea Corallo <akrl@sdf.org>

    * Add a simple growable vector like type
    
        * lisp/emacs-lisp/comp.el (comp-vec): Define struct.
        (comp-vec-copy, comp-vec-length, comp-vec--verify-idx)
        (comp-vec-aref, comp-vec-append, comp-vec-prepend): New functions.
---
 lisp/emacs-lisp/comp.el | 53 ++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 50 insertions(+), 3 deletions(-)

diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index e2b1d04..267b67f 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -600,6 +600,53 @@ Useful to hook into pass checkers.")
 (define-error 'native-compiler-error-empty-byte
   "empty byte compiler output"
   'native-compiler-error)
+
+
+(cl-defstruct (comp-vec (:copier nil))
+  "A re-sizable vector like object."
+  (data (make-hash-table :test #'eql) :type hash-table
+        :documentation "Payload data.")
+  (beg 0 :type integer)
+  (end 0 :type natnum))
+
+(defsubst comp-vec-copy (vec)
+  "Return a copy of VEC."
+  (make-comp-vec :data (copy-hash-table (comp-vec-data vec))
+                 :beg (comp-vec-beg vec)
+                 :end (comp-vec-end vec)))
+
+(defsubst comp-vec-length (vec)
+  "Return the number of elements of VEC."
+  (+ (comp-vec-beg vec) (comp-vec-end vec)))
+
+(defsubst comp-vec--verify-idx (vec idx)
+  "Check idx is in bounds for VEC."
+  (cl-assert (and (< idx (comp-vec-end vec))
+                  (>= idx (comp-vec-beg vec)))))
+
+(defsubst comp-vec-aref (vec idx)
+  "Return the element of VEC at index IDX."
+  (declare (gv-setter (lambda (val)
+                        `(comp-vec--verify-idx ,vec ,idx)
+                       `(puthash ,idx ,val (comp-vec-data ,vec)))))
+  (comp-vec--verify-idx vec idx)
+  (gethash idx (comp-vec-data vec)))
+
+(defsubst comp-vec-append (vec elt)
+  "Append ELT into VEC.
+ELT is returned."
+  (puthash (comp-vec-end vec) elt (comp-vec-aref vec))
+  (cl-incf (comp-vec-end vec))
+  elt)
+
+(defsubst comp-vec-prepend (vec elt)
+  "Prepend ELT into VEC.
+ELT is returned."
+  (puthash (comp-vec-beg vec) elt (comp-vec-aref vec))
+  (cl-decf (comp-vec-beg vec))
+  elt)
+
+
 
 (eval-when-compile
   (defconst comp-op-stack-info
@@ -2772,9 +2819,9 @@ blocks."
     (cl-loop for i from 0 below (comp-func-frame-size comp-func)
              ;; List of blocks with a definition of mvar i
              for defs-v = (cl-loop with blocks = (comp-func-blocks comp-func)
-                                    for b being each hash-value of blocks
-                                    when (slot-assigned-p i b)
-                                    collect b)
+                                   for b being each hash-value of blocks
+                                   when (slot-assigned-p i b)
+                                   collect b)
              ;; Set of basic blocks where phi is added.
              for f = ()
              ;; Worklist, set of basic blocks that contain definitions of v.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]