From 162bfa35d0b1a8a698dc813f6bc0874a043a225c Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20V=C3=A1zquez?= Date: Fri, 24 May 2013 02:52:16 +0100 Subject: [PATCH] Move concat and char --- src/boot.lisp | 3 --- src/compiler.lisp | 9 --------- src/string.lisp | 10 +++++++++- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/boot.lisp b/src/boot.lisp index 7605a29..dc9b45f 100644 --- a/src/boot.lisp +++ b/src/boot.lisp @@ -526,9 +526,6 @@ (defun get-universal-time () (+ (get-unix-time) 2208988800)) -(defun concat (&rest strs) - (!reduce #'concat-two strs "")) - (defun values-list (list) (values-array (list-to-vector list))) diff --git a/src/compiler.lisp b/src/compiler.lisp index 5dd0084..71ba7a1 100644 --- a/src/compiler.lisp +++ b/src/compiler.lisp @@ -1454,15 +1454,6 @@ (when b (code "b = " (ls-compile b) ";" *newline*)) "return vector.slice(a,b);" *newline*)) -(define-builtin char (string index) - (code string "[" index "]")) - -(define-builtin concat-two (string1 string2) - (js!selfcall - "var r = " string1 ".concat(" string2 ");" *newline* - "r.stringp = 1;" - "return r;" *newline*)) - (define-raw-builtin funcall (func &rest args) (js!selfcall "var f = " (ls-compile func) ";" *newline* diff --git a/src/string.lisp b/src/string.lisp index 1bb322b..e4cd22c 100644 --- a/src/string.lisp +++ b/src/string.lisp @@ -22,6 +22,10 @@ (defun make-string (n &key initial-element) (make-array n :element-type 'character :initial-element initial-element)) +(defun char (string index) + (unless (stringp string) (error "~S is not a string" string)) + (storage-vector-ref string index)) + (defun string (x) (cond ((stringp x) x) ((symbolp x) (symbol-name x)) @@ -57,7 +61,8 @@ `(aset ,g!string ,g!index ,g!value) `(char ,g!string ,g!index)))) -(defun concatenate-two (string1 string2) + +(defun concat-two (string1 string2) (let* ((len1 (length string1)) (len2 (length string2)) (string (make-array (+ len1 len2) :element-type 'character)) @@ -69,3 +74,6 @@ (aset string i (char string2 j)) (incf i)) string)) + +(defun concat (&rest strs) + (!reduce #'concat-two strs "")) -- 1.7.10.4