• R/O
  • SSH

quipu: Commit

quipu mercurial repository


Commit MetaInfo

Revision54981a38d9be2fcfbad14f0e1b103dee68522528 (tree)
Time2019-10-10 05:15:37
AuthorAgustina Arzille <avarzille@rise...>
CommiterAgustina Arzille

Log Message

Improve method dispatching for optional parameters

Change Summary

Incremental Difference

diff -r c782106cf008 -r 54981a38d9be function.cpp
--- a/function.cpp Wed Oct 09 14:33:24 2019 -0300
+++ b/function.cpp Wed Oct 09 17:15:37 2019 -0300
@@ -287,7 +287,7 @@
287287
288288 valref pred (interp, fixint (0)), succ (interp, fixint (0));
289289 valref rv (interp, tuple_nearest (interp, cache, types.as_obj (),
290- &*pred, &*succ));
290+ &*pred, &*succ));
291291
292292 if (*rv != UNBOUND)
293293 ;
diff -r c782106cf008 -r 54981a38d9be sys.qp
--- a/sys.qp Wed Oct 09 14:33:24 2019 -0300
+++ b/sys.qp Wed Oct 09 17:15:37 2019 -0300
@@ -409,38 +409,41 @@
409409 (defct %meth-flag (fn)
410410 (%meth-ctl 3 fn))
411411
412+(defct %meth-argsmap (args fn)
413+ (let rv nil
414+ (while (cons-p args)
415+ (let arg (car args)
416+ (if (list-p arg)
417+ (break)
418+ (setf rv (cons (fn arg) rv)
419+ args (cdr args)))))
420+ (nreverse rv)))
421+
412422 (defct %meth-args (args)
413423 (let rv nil
414424 (while (cons-p args)
415425 (let arg (car args)
416426 (setf rv (cons (if
417427 (array-p arg) (arg 0)
418- (list-p arg) (list (car arg) nil)
419- arg)
420- rv)
428+ (list-p arg) (list (car arg) '%METH-TOKEN)
429+ arg) rv)
421430 args (cdr args))))
422431 (if args
423432 (nrevconc rv args)
424433 (nreverse rv))))
425434
426435 (defct %meth-types (args)
427- (let rv nil
428- (while (and (cons-p args) (not (kword-p (car args))))
429- (let arg (car args)
430- (setf args (cdr args)
431- rv (cons (if (array-p arg)
432- (if (> (len arg) 2)
433- (raise (%mkexc "arg-error"
434- "invalid method argument: ${arg}"))
435- (arg 1)))
436- rv))))
437- (nreverse rv)))
436+ (%meth-argsmap args
437+ (fct (arg)
438+ (if (array-p arg)
439+ (if (> (len arg) 2)
440+ (raise (%mkexc "arg-error"
441+ "invalid method argument: ${arg}"))
442+ (arg 1))))))
438443
439444 (defct %meth-argnames (args)
440- (let rv nil
441- (each arg args
442- (setf rv (cons (if (list-p arg) (car arg) arg) rv)))
443- (nreverse rv)))
445+ (%meth-argsmap args
446+ (fct (arg) arg)))
444447
445448 (defmac defmeth (name args . body)
446449 (if (or (not args) (not (list-p args)))
@@ -475,10 +478,5 @@
475478 nil ,gmeth)
476479 (list %METH-TOKEN ,gmeth ,@(%meth-types args))
477480 ;; fill the rest of the arguments with nil.
478- ,@((fct (x acc)
479- (if (or (not (list-p x))
480- (list-p (car x)))
481- acc
482- (recur (cdr x) (cons nil acc))))
483- (cdr fct-args) nil))
481+ ,@(%meth-argsmap fct-args (fct (x) nil)))
484482 ) ) )
Show on old repository browser