From: David Vázquez Date: Fri, 24 May 2013 00:47:49 +0000 (+0100) Subject: Unidimensional aref and aset X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=bdc0646398f2719675159778dcb77924fc94374b;p=jscl.git Unidimensional aref and aset --- diff --git a/src/arrays.lisp b/src/arrays.lisp index 0f6698a..9211460 100644 --- a/src/arrays.lisp +++ b/src/arrays.lisp @@ -61,3 +61,15 @@ (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)) + (storage-vector-ref array index)) + +(defun aset (array index value) + (unless (arrayp array) + (error "~S is not an array." array)) + (storage-vector-set array index value)) + + diff --git a/src/compiler.lisp b/src/compiler.lisp index aca3a2b..7fffe42 100644 --- a/src/compiler.lisp +++ b/src/compiler.lisp @@ -1588,19 +1588,6 @@ "v.push(" new ");" *newline* "return v;")) -(define-builtin aref (array n) - (js!selfcall - "var x = " "(" array ")[" n "];" *newline* - "if (x === undefined) throw 'Out of range';" *newline* - "return x;" *newline*)) - -(define-builtin aset (array n value) - (js!selfcall - "var x = " array ";" *newline* - "var i = " n ";" *newline* - "if (i < 0 || i >= x.length) throw 'Out of range';" *newline* - "return x[i] = " value ";" *newline*)) - (define-builtin afind (value array) (js!selfcall "var v = " value ";" *newline*