Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
inconvergent committed Mar 13, 2024
1 parent 34485d0 commit 6223c4c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
54 changes: 33 additions & 21 deletions src/qry.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -119,34 +119,46 @@
(vector (do-vec)) (simple-vector (do-vec))
(otherwise (error "RT: $$ bad type. expected hash-table or vector.~%got: ~a" ,par)))))))

; TODO: vec! does the wrong thing for non-sequence

; rename this to (?@ ) or something?
; change to select from vec of objects? it kinda is alread??
(defun compile/$* (rec conf d) ; #[...] ; sel ; select from vec of hts to vec
(awg (i ires itr dat par)
`(loop with ,ires of-type vector = (mav)
with ,par of-type vector = (vec! ,(gk conf :dat))
for ,itr across ,par for ,i from 0
do (∈ (:par ,par :cnt ,i :itr ,itr)
,(when (car- dat? d) (compile/*add rec conf :+ ires itr))
,@(loop for (m kk expr) in (strip-all d) collect
`(let ((,dat (@@ ,itr ,kk)))
(declare (ignorable ,dat))
(∈ (:key ,kk) ,(compile/*add rec (dat/new conf dat) m ires expr)))))
finally (return ,ires))))
`(let ((,par ,(gk conf :dat)))
(labels ((do-vec (&aux (,ires (mav)))
(loop with ,par of-type vector = (vec! ,par)
for ,itr across ,par for ,i from 0
do (∈ (:par ,par :cnt ,i :itr ,itr)
,(when (car- dat? d) (compile/*add rec conf :+ ires itr))
,@(loop for (m kk expr) in (strip-all d) collect
`(let ((,dat (@@ ,itr ,kk)))
(declare (ignorable ,dat))
(∈ (:key ,kk) ,(compile/*add rec
(dat/new conf dat) m ires expr))))))
,ires))
(typecase ,par ; TODO: support hts
(null nil) (vector (do-vec)) (simple-vector (do-vec)) (list (do-vec))
(otherwise (error "RT: $* bad type. expected vector, got: ~a" ,par)))))))

(defun compile/*$ (rec conf d) ; #{...} ; sel ; select from vec of hts to vec of hts
(awg (i ires kvres itr dat par)
`(loop with ,ires of-type vector = (mav)
with ,par of-type vector = (vec! ,(gk conf :dat))
for ,itr of-type hash-table across ,par for ,i from 0
for ,kvres of-type hash-table = ,(if (car- dat? d) `(make$ ,itr) `(make$))
do (∈ (:par ,par :cnt ,i :itr ,itr)
,@(loop for (m kk expr) in (strip-all d)
collect `(let ((,dat (@@ ,itr ,kk)))
(declare (ignorable ,dat))
(∈ (:key ,kk) ,(compile/$add rec (dat/new conf dat) m kvres kk expr))))
(vex ,ires ($nil ,kvres)))
finally (return ,ires))))
`(let ((,par ,(gk conf :dat)))
(labels ((do-vec (&aux (,ires (mav)))
(loop with ,par of-type vector = (vec! ,par)
for ,itr of-type hash-table across ,par for ,i from 0
for ,kvres of-type hash-table = ,(if (car- dat? d) `(make$ ,itr) `(make$))
do (∈ (:par ,par :cnt ,i :itr ,itr)
,@(loop for (m kk expr) in (strip-all d)
collect `(let ((,dat (@@ ,itr ,kk)))
(declare (ignorable ,dat))
(∈ (:key ,kk) ,(compile/$add rec
(dat/new conf dat) m kvres kk expr))))
(vex ,ires ($nil ,kvres))))
,ires))
(typecase ,par (null nil)
(vector (do-vec)) (simple-vector (do-vec)) (list (do-vec))
(otherwise (error "RT: *$ bad type. expected vector, got: ~a" ,par)))))))

(defun pre/?filter (q &optional (mm :?)) (unless q (warn "?filter: missing args."))
(labels ((unpack- (o) (dsb (m sk) (unpack-mode o mm) `(,m ,(pre/xpr-sel sk :_)))))
Expand Down
4 changes: 2 additions & 2 deletions test/test-lqn.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@
(is (lqn:jsnqryf *test-data-fn* #[(:%@index (?? _ (= _ 0) _))]) #(0) :test #'equalp)
(is-str (lqn::jsnstr (lqn:jsnqryf *test-data-fn* (|| #[:things] (flatn* _) #[:id])))
"[0,10,11,12,31,32]")
(is-str (lqn::jsnstr (lqn:jsnqryf *test-data-fn* (|| #(#[:things]) (flatn* _ 2) #[:id])))
(is-str (lqn::jsnstr (lqn:jsnqryf *test-data-fn* (|| #[:things] (flatn* _ 2) #[:id])))
"[0,10,11,12,31,32]")
(is-str (lqn::jsnstr (lqn:jsnqryf *test-data-fn*
(|| #(#[:things]) (flatn* _ 2) #[:id]
(|| #[:things] (flatn* _ 2) #[:id]
(?fld (list) acc (cons (1+ _) acc)) (reverse _))))
"[1,11,12,13,32,33]"))

Expand Down

0 comments on commit 6223c4c

Please sign in to comment.