From aae9a4aed84caf8b50536887401ef3df7d97c09a Mon Sep 17 00:00:00 2001
From: =?utf8?q?David=20V=C3=A1zquez?= <davazp@gmail.com>
Date: Fri, 24 May 2013 01:51:38 +0100
Subject: [PATCH] Move vector-push-extend to arrays.lisp

---
 src/arrays.lisp   |   15 ++++++++++++---
 src/compiler.lisp |    9 ---------
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/arrays.lisp b/src/arrays.lisp
index 9211460..a90a4bc 100644
--- a/src/arrays.lisp
+++ b/src/arrays.lisp
@@ -59,9 +59,6 @@
 (defun array-dimension (array axis)
   (nth axis (array-dimensions array)))
 
-(defun vectorp (x)
-  (and (arrayp x) (null (cdr (array-dimensions x)))))
-
 (defun aref (array index)
   (unless (arrayp array)
     (error "~S is not an array." array))  
@@ -73,3 +70,15 @@
   (storage-vector-set array index value))
 
 
+;;; Vectors
+
+(defun vectorp (x)
+  (and (arrayp x) (null (cdr (array-dimensions x)))))
+
+;;; FIXME: should take optional min-extension.
+;;; FIXME: should use fill-pointer instead of the absolute end of array
+(defun vector-push-extend (new vector)
+  (let ((size (storage-vector-size vector)))
+    (resize-storage-vector vector (1+ size))
+    (aset vector size new)
+    size))
diff --git a/src/compiler.lisp b/src/compiler.lisp
index 7fffe42..a41a85e 100644
--- a/src/compiler.lisp
+++ b/src/compiler.lisp
@@ -1579,15 +1579,6 @@
     "if (i < 0 || i >= x.length) throw 'Out of range';" *newline*
     "return x[i] = " value ";" *newline*))
 
-
-;;; FIXME: should take optional min-extension.
-;;; FIXME: should use fill-pointer instead of the absolute end of array
-(define-builtin vector-push-extend (new vector)
-  (js!selfcall
-    "var v = " vector ";" *newline*
-    "v.push(" new ");" *newline*
-    "return v;"))
-
 (define-builtin afind (value array)
   (js!selfcall
     "var v = " value ";" *newline*
-- 
1.7.10.4