nendo 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/nendo +2 -2
- data/emacs/nendo-mode.el +126 -0
- data/example/KyotoCabinet/kcbench.rb +20 -0
- data/example/KyotoCabinet/kcbench1.nnd +29 -0
- data/example/KyotoCabinet/kcbench2.nnd +30 -0
- data/example/KyotoCabinet/kcbench3.nnd +31 -0
- data/example/export-lisp-functions.rb +20 -0
- data/example/scratch.nnd +8 -17
- data/example/tak_ruby_version.rb +14 -0
- data/lib/debug/syslog.nndc +1 -1
- data/lib/init.nnd +334 -202
- data/lib/init.nndc +5691 -4128
- data/lib/nendo/test.nnd +165 -0
- data/lib/nendo/test.nndc +1635 -0
- data/lib/nendo.rb +248 -37
- data/lib/srfi-1.nnd +15 -24
- data/lib/srfi-1.nndc +1247 -1607
- data/lib/text/html-lite.nnd +1 -1
- data/lib/text/html-lite.nndc +171 -171
- data/lib/text/tree.nndc +2 -2
- data/test/nendo_spec.rb +1281 -981
- data/test/nendo_util.nnd +98 -0
- data/test/srfi-1-test.nnd +28 -0
- data/test/textlib.nnd +24 -0
- metadata +13 -3
data/lib/init.nnd
CHANGED
@@ -37,25 +37,39 @@
|
|
37
37
|
;; ----------------------------------------
|
38
38
|
;; define
|
39
39
|
;; ----------------------------------------
|
40
|
-
(define define
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
(cons 'define
|
53
|
-
(cons (car arg)
|
54
|
-
(list
|
55
|
-
(cons 'lambda
|
56
|
-
(cons (cdr arg)
|
57
|
-
body)))))))))
|
40
|
+
(define %expand-define-form-lambda
|
41
|
+
(lambda (arg body-list)
|
42
|
+
;; (define (func arg...) body)
|
43
|
+
(if (pair? (cdr arg))
|
44
|
+
(if (pair? (car (cdr arg)))
|
45
|
+
(error "Error: define syntax error.")))
|
46
|
+
(cons 'define
|
47
|
+
(cons (car arg)
|
48
|
+
(list
|
49
|
+
(cons 'lambda
|
50
|
+
(cons (cdr arg)
|
51
|
+
body-list)))))))
|
58
52
|
|
53
|
+
(define define
|
54
|
+
(macro (arg . body)
|
55
|
+
(if (not (pair? arg))
|
56
|
+
;; (define var body)
|
57
|
+
(cons 'define
|
58
|
+
(cons arg
|
59
|
+
body))
|
60
|
+
(%expand-define-form-lambda arg body))))
|
61
|
+
|
62
|
+
(define %expand-define-form
|
63
|
+
(lambda (arg-and-body)
|
64
|
+
(let ((arg (car arg-and-body))
|
65
|
+
(body (cdr arg-and-body)))
|
66
|
+
;; (define (func arg...) body)
|
67
|
+
(if (not (pair? arg))
|
68
|
+
;; (define var body)
|
69
|
+
(cons 'define
|
70
|
+
(cons arg
|
71
|
+
body))
|
72
|
+
(%expand-define-form-lambda arg body)))))
|
59
73
|
|
60
74
|
;; debug-print macro is predefined as NOP.
|
61
75
|
;; for self debugging of init.nnd.
|
@@ -113,10 +127,7 @@
|
|
113
127
|
;; Utility functions
|
114
128
|
;; ----------------------------------------
|
115
129
|
(define (vector . lst) (to-arr lst))
|
116
|
-
(define
|
117
|
-
(if (pair? arg)
|
118
|
-
(list? (cdr arg))
|
119
|
-
(null? arg)))
|
130
|
+
(define list? %list?)
|
120
131
|
(define (even? n) (= (% n 2) 0))
|
121
132
|
(define (odd? n) (not (= (% n 2) 0)))
|
122
133
|
(define (zero? n) (= n 0))
|
@@ -362,6 +373,12 @@
|
|
362
373
|
;; don't touch
|
363
374
|
`(let ,@lst))))
|
364
375
|
|
376
|
+
(define if-let1
|
377
|
+
(macro (var _expr _then . _else)
|
378
|
+
`(let1 ,var ,_expr
|
379
|
+
(if ,var ,_then ,@_else))))
|
380
|
+
|
381
|
+
|
365
382
|
;; ----------------------------------------
|
366
383
|
;; errorf
|
367
384
|
;; ----------------------------------------
|
@@ -370,6 +387,24 @@
|
|
370
387
|
`(error
|
371
388
|
(sprintf ,format ,@args))))
|
372
389
|
|
390
|
+
|
391
|
+
;; ----------------------------------------
|
392
|
+
;; optional argument parser
|
393
|
+
;; ----------------------------------------
|
394
|
+
(define get-optional
|
395
|
+
(macro (restarg default)
|
396
|
+
(let1 _restarg (gensym)
|
397
|
+
`(let1 ,_restarg ,restarg
|
398
|
+
(if (null? ,_restarg)
|
399
|
+
,default
|
400
|
+
(car ,_restarg))))))
|
401
|
+
|
402
|
+
;; pending
|
403
|
+
(define check-arg
|
404
|
+
(macro (a b . c)
|
405
|
+
`(begin)))
|
406
|
+
|
407
|
+
|
373
408
|
;; ----------------------------------------
|
374
409
|
;; List utilities imported from TinyScheme
|
375
410
|
;; ----------------------------------------
|
@@ -469,9 +504,9 @@
|
|
469
504
|
(append cdrs (list cdr1))))))
|
470
505
|
|
471
506
|
|
472
|
-
(define (map proc . lists)
|
507
|
+
(define (%map proc . lists)
|
473
508
|
(letrec ((result '())
|
474
|
-
(map-arg1
|
509
|
+
(%map-arg1
|
475
510
|
(lambda (proc lst)
|
476
511
|
(if (null? lst)
|
477
512
|
#t
|
@@ -479,12 +514,12 @@
|
|
479
514
|
(set! result
|
480
515
|
(cons (proc (car lst))
|
481
516
|
result))
|
482
|
-
(map-arg1 proc (cdr lst)))))))
|
517
|
+
(%map-arg1 proc (cdr lst)))))))
|
483
518
|
(cond
|
484
519
|
((null? lists)
|
485
520
|
(apply proc))
|
486
521
|
((eq? 1 (length lists))
|
487
|
-
(map-arg1 proc (car lists)) ;; tail call optimization version
|
522
|
+
(%map-arg1 proc (car lists)) ;; tail call optimization version
|
488
523
|
(reverse result))
|
489
524
|
(else
|
490
525
|
(if (null? (car lists))
|
@@ -495,21 +530,61 @@
|
|
495
530
|
(cons (apply proc cars)
|
496
531
|
(if (null? cdrs)
|
497
532
|
'()
|
498
|
-
(apply map (cons proc cdrs)))))))))))
|
533
|
+
(apply %map (cons proc cdrs)))))))))))
|
534
|
+
|
535
|
+
(define (%internal-define-to-letrec _sym _src)
|
536
|
+
(if (not (list? (cadr _src)))
|
537
|
+
`(,_sym ,@_src)
|
538
|
+
(let ((body (cdr _src))
|
539
|
+
(defs '())
|
540
|
+
(rest '()))
|
541
|
+
(if (not (list? (car body)))
|
542
|
+
`(,_sym ,@_src)
|
543
|
+
(begin
|
544
|
+
(%map
|
545
|
+
(lambda (x)
|
546
|
+
(if (and (pair? x)
|
547
|
+
(eq? 'define (car x)))
|
548
|
+
(set! defs (cons (%expand-define-form (cdr x)) defs))
|
549
|
+
(set! rest (cons x rest))))
|
550
|
+
body)
|
551
|
+
(let ((defs (reverse defs))
|
552
|
+
(rest (reverse rest)))
|
553
|
+
(if (< 0 (length defs))
|
554
|
+
`(,_sym
|
555
|
+
,(car _src)
|
556
|
+
(letrec
|
557
|
+
,(%map
|
558
|
+
(lambda (x)
|
559
|
+
(list
|
560
|
+
(cadr x)
|
561
|
+
(caddr x)))
|
562
|
+
defs)
|
563
|
+
,@rest))
|
564
|
+
;; found no `internal-define' syntax
|
565
|
+
`(,_sym ,@_src))))))))
|
566
|
+
|
499
567
|
|
568
|
+
(define lambda
|
569
|
+
(macro src
|
570
|
+
(%internal-define-to-letrec 'lambda src)))
|
500
571
|
|
501
|
-
(define
|
502
|
-
(
|
572
|
+
(define macro
|
573
|
+
(macro src
|
574
|
+
(%internal-define-to-letrec 'macro src)))
|
575
|
+
|
576
|
+
(define (%for-each proc . lists)
|
577
|
+
(define (%for-each-arg1 proc lst)
|
503
578
|
(if (null? lst)
|
504
579
|
#t
|
505
580
|
(begin
|
506
581
|
(proc (car lst))
|
507
|
-
(for-each-arg1 proc (cdr lst)))))
|
582
|
+
(%for-each-arg1 proc (cdr lst)))))
|
508
583
|
(cond
|
509
584
|
((null? lists)
|
510
585
|
(apply proc))
|
511
586
|
((eq? 1 (length lists))
|
512
|
-
(for-each-arg1 proc (car lists))) ;; tail call optimization version
|
587
|
+
(%for-each-arg1 proc (car lists))) ;; tail call optimization version
|
513
588
|
(else
|
514
589
|
(if (null? (car lists))
|
515
590
|
#t
|
@@ -519,73 +594,47 @@
|
|
519
594
|
(apply proc cars)
|
520
595
|
(if (null? cdrs)
|
521
596
|
'()
|
522
|
-
(apply for-each (cons proc cdrs)))))))))
|
523
|
-
|
524
|
-
|
525
|
-
(define (filter pred lst)
|
526
|
-
(if (null? lst)
|
527
|
-
'()
|
528
|
-
(if (pred (car lst))
|
529
|
-
(cons
|
530
|
-
(car lst)
|
531
|
-
(filter pred (cdr lst)))
|
532
|
-
(filter pred (cdr lst)))))
|
597
|
+
(apply %for-each (cons proc cdrs)))))))))
|
533
598
|
|
599
|
+
(define (%filter pred lst)
|
600
|
+
(define result '())
|
601
|
+
(define (%filter-arg1 proc lst)
|
602
|
+
(if (null? lst)
|
603
|
+
'()
|
604
|
+
(let1 v (proc (car lst))
|
605
|
+
(when v
|
606
|
+
(set! result (cons (car lst) result)))
|
607
|
+
(%filter-arg1 proc (cdr lst)))))
|
608
|
+
|
609
|
+
(%filter-arg1 pred lst) ;; tail call optimization version
|
610
|
+
(reverse result))
|
611
|
+
|
612
|
+
(define (%filter-map pred lst)
|
613
|
+
(define result '())
|
614
|
+
(define (%filter-map-arg1 proc lst)
|
615
|
+
(if (null? lst)
|
616
|
+
'()
|
617
|
+
(let1 v (proc (car lst))
|
618
|
+
(when v
|
619
|
+
(set! result (cons v result)))
|
620
|
+
(%filter-map-arg1 proc (cdr lst)))))
|
534
621
|
|
535
|
-
(
|
536
|
-
(
|
537
|
-
'()
|
538
|
-
(let1 result (pred (car lst))
|
539
|
-
(if result
|
540
|
-
(cons
|
541
|
-
result
|
542
|
-
(filter-map pred (cdr lst)))
|
543
|
-
(filter-map pred (cdr lst))))))
|
622
|
+
(%filter-map-arg1 pred lst) ;; tail call optimization version
|
623
|
+
(reverse result))
|
544
624
|
|
545
625
|
|
546
626
|
(define (find pred lst)
|
547
|
-
(let1 result (filter pred lst)
|
627
|
+
(let1 result (%filter pred lst)
|
548
628
|
(if (null? result)
|
549
629
|
#f
|
550
630
|
(car result))))
|
551
631
|
|
632
|
+
(define map %map)
|
633
|
+
(define for-each %for-each)
|
634
|
+
(define filter %filter)
|
635
|
+
(define filter-map %filter-map)
|
636
|
+
|
552
637
|
|
553
|
-
(define lambda
|
554
|
-
(macro src
|
555
|
-
(if (not (list? (cadr src)))
|
556
|
-
`(lambda ,@src)
|
557
|
-
(let1 body (cdr src)
|
558
|
-
(if (not (list? (car body)))
|
559
|
-
`(lambda ,@src)
|
560
|
-
(let ((defs
|
561
|
-
(filter
|
562
|
-
(lambda (x)
|
563
|
-
(if (pair? x)
|
564
|
-
(and (eq? 'define (car x))
|
565
|
-
(symbol? (cadr x)))
|
566
|
-
#f))
|
567
|
-
body))
|
568
|
-
(rest
|
569
|
-
(filter
|
570
|
-
(lambda (x)
|
571
|
-
(if (pair? x)
|
572
|
-
(not (and (eq? 'define (car x))
|
573
|
-
(symbol? (cadr x))))
|
574
|
-
#f))
|
575
|
-
body)))
|
576
|
-
(if (< 0 (length defs))
|
577
|
-
`(lambda
|
578
|
-
,(car src)
|
579
|
-
(letrec
|
580
|
-
,(map
|
581
|
-
(lambda (x)
|
582
|
-
(list
|
583
|
-
(cadr x)
|
584
|
-
(caddr x)))
|
585
|
-
defs)
|
586
|
-
,@rest))
|
587
|
-
;; found no `internal-define' syntax
|
588
|
-
`(lambda ,@src))))))))
|
589
638
|
|
590
639
|
|
591
640
|
;; ----------------------------------------
|
@@ -593,54 +642,50 @@
|
|
593
642
|
;; ----------------------------------------
|
594
643
|
(define case
|
595
644
|
(macro (cond-exp . body)
|
596
|
-
(
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
((eq? 1 (length lst))
|
618
|
-
(case-block val (car lst)))
|
645
|
+
(define (case-block val . elem)
|
646
|
+
(let1 block (car elem)
|
647
|
+
(let ((cond-vals (car block))
|
648
|
+
(body (cdr block)))
|
649
|
+
(let1 v
|
650
|
+
(if (eq? 'else cond-vals)
|
651
|
+
cond-vals
|
652
|
+
(cons 'or
|
653
|
+
(map
|
654
|
+
(lambda (x)
|
655
|
+
`(eqv? ,x ,val))
|
656
|
+
cond-vals)))
|
657
|
+
`((,v
|
658
|
+
,@body))))))
|
659
|
+
|
660
|
+
(define (case-iter val lst)
|
661
|
+
(cond
|
662
|
+
((eq? 0 (length lst))
|
663
|
+
'())
|
664
|
+
((eq? 1 (length lst))
|
665
|
+
(case-block val (car lst)))
|
619
666
|
(else
|
620
667
|
(append (case-block val (car lst))
|
621
|
-
(case-iter val (cdr lst))))))
|
668
|
+
(case-iter val (cdr lst))))))
|
622
669
|
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
670
|
+
(let1 sym (gensym)
|
671
|
+
`(let1 ,sym ,cond-exp
|
672
|
+
(cond
|
673
|
+
,@(case-iter sym body))))))
|
627
674
|
|
628
675
|
|
629
676
|
(define let*
|
630
677
|
(macro (exps . body)
|
631
|
-
(
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
(let*-expand exps body))))
|
678
|
+
(define (let*-expand rest body)
|
679
|
+
(case (length rest)
|
680
|
+
((0)
|
681
|
+
'())
|
682
|
+
((1)
|
683
|
+
`(let (,(car rest))
|
684
|
+
,@body))
|
685
|
+
(else
|
686
|
+
`(let (,(car rest))
|
687
|
+
,(let*-expand (cdr rest) body)))))
|
688
|
+
(let*-expand exps body)))
|
644
689
|
|
645
690
|
|
646
691
|
(define begin0
|
@@ -711,36 +756,30 @@
|
|
711
756
|
;; ----------------------------------------
|
712
757
|
(define dot-operator
|
713
758
|
(macro lst
|
714
|
-
(
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
(raise TypeError ". dot-operator requires method name as symbol." (sprintf "%s:%s in dot-operator" (*FILE*) (*LINE*)))))))))
|
759
|
+
(define (generate-method-call-form lst)
|
760
|
+
(let1 tmp (gensym)
|
761
|
+
(if (symbol? (first lst))
|
762
|
+
`(,(string->symbol (+ (to-s (first lst)) "." (to-s (second lst))))
|
763
|
+
,@(cddr lst))
|
764
|
+
`(let ((,tmp ,(first lst)))
|
765
|
+
(,(string->symbol (+ (to-s tmp) "." (to-s (second lst))))
|
766
|
+
,@(cddr lst))))))
|
767
|
+
(cond
|
768
|
+
((> 2 (length lst))
|
769
|
+
(raise ArgumentError ". dot-operator requires 2+ arguments." (sprintf "%s:%s in dot-operator" (*FILE*) (*LINE*))))
|
770
|
+
(else
|
771
|
+
(if (symbol? (second lst))
|
772
|
+
(generate-method-call-form lst)
|
773
|
+
(raise TypeError ". dot-operator requires method name as symbol." (sprintf "%s:%s in dot-operator" (*FILE*) (*LINE*))))))))
|
730
774
|
|
731
775
|
|
732
776
|
(define (with-open filename pred . lst)
|
733
|
-
(let1
|
734
|
-
(
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
(else
|
740
|
-
(error "with-open requires 2 or 3 arguments.")))
|
741
|
-
(let1 result (pred f)
|
742
|
-
(f.close)
|
743
|
-
result))))
|
777
|
+
(let1 opt (get-optional lst #f)
|
778
|
+
(if (< 1 (length lst))
|
779
|
+
(error "with-open requires 2 or 3 arguments.")
|
780
|
+
(if opt
|
781
|
+
(.open filename opt (&block (f) (pred f)))
|
782
|
+
(.open filename (&block (f) (pred f)))))))
|
744
783
|
|
745
784
|
|
746
785
|
;; ----------------------------------------
|
@@ -775,15 +814,10 @@
|
|
775
814
|
(let1 h (make-hash-table)
|
776
815
|
(for-each
|
777
816
|
(lambda (entry)
|
778
|
-
(
|
779
|
-
(hash-table-put! h (car entry) (cadr entry))
|
780
|
-
(hash-table-put! h (car entry) (cdr entry))))
|
817
|
+
(hash-table-put! h (car entry) (cdr entry)))
|
781
818
|
kv-list)
|
782
819
|
h))
|
783
820
|
|
784
|
-
(define (hash-table-exist? h key)
|
785
|
-
(h.has_key? key))
|
786
|
-
|
787
821
|
(define (hash-table-clear! h)
|
788
822
|
(h.clear))
|
789
823
|
|
@@ -820,7 +854,7 @@
|
|
820
854
|
keys))))
|
821
855
|
|
822
856
|
(define (alist->hash-table alist)
|
823
|
-
(if (not (list? alist))
|
857
|
+
(if (not (%list? alist))
|
824
858
|
(error "Error: alist->hash-table expects alist.")
|
825
859
|
(apply hash-table alist)))
|
826
860
|
|
@@ -828,10 +862,10 @@
|
|
828
862
|
;; ----------------------------------------
|
829
863
|
;; Ruby interop librarys
|
830
864
|
;; ----------------------------------------
|
831
|
-
;;
|
832
|
-
(define export
|
833
|
-
(macro (
|
834
|
-
`(
|
865
|
+
;; export Nendo's function to the Ruby world
|
866
|
+
(define export-to-ruby
|
867
|
+
(macro (funcname)
|
868
|
+
`(%export-to-ruby ,funcname.to_s ,funcname)))
|
835
869
|
|
836
870
|
(define (load-library name)
|
837
871
|
(let* ((home (get-nendo-home))
|
@@ -844,6 +878,20 @@
|
|
844
878
|
(else
|
845
879
|
(errorf "Error: can't load library file [%s]\n" path )))))
|
846
880
|
|
881
|
+
;; use macro like Gauche
|
882
|
+
(define use
|
883
|
+
(macro (sym)
|
884
|
+
(if (symbol? sym)
|
885
|
+
(let*
|
886
|
+
((str (symbol->string sym))
|
887
|
+
(pathname (str.gsub "." "/")))
|
888
|
+
`(load-library ,pathname))
|
889
|
+
(errorf "Error: use macro requires a symbol argument."))))
|
890
|
+
|
891
|
+
;; exporting a symbol in the module. (I will implement in the future...)
|
892
|
+
(define export
|
893
|
+
(macro (name)
|
894
|
+
`(define ,name nil)))
|
847
895
|
|
848
896
|
|
849
897
|
;; ----------------------------------------
|
@@ -929,50 +977,111 @@
|
|
929
977
|
;; http://practical-scheme.net/wiliki/wiliki.cgi?Gauche%3APrettyPrint
|
930
978
|
;;
|
931
979
|
;; Subsequently modified for initialize library for nendo: Kiyoka Nishiyama
|
932
|
-
(define (pretty-print s)
|
933
|
-
(define (do-indent level)
|
934
|
-
(for-each (lambda (x) (
|
935
|
-
(define (pp-parenl)
|
936
|
-
(
|
937
|
-
(define (pp-parenr)
|
938
|
-
(
|
939
|
-
(define (pp-atom e prefix)
|
940
|
-
(when prefix (
|
941
|
-
(write e))
|
942
|
-
(define (pp-list s level prefix)
|
943
|
-
(and prefix (do-indent level))
|
944
|
-
(pp-parenl)
|
980
|
+
(define (pretty-print s . f)
|
981
|
+
(define (do-indent f level)
|
982
|
+
(for-each (lambda (x) (f.print " ")) (range level)))
|
983
|
+
(define (pp-parenl f)
|
984
|
+
(f.print "("))
|
985
|
+
(define (pp-parenr f)
|
986
|
+
(f.print ")"))
|
987
|
+
(define (pp-atom f e prefix)
|
988
|
+
(when prefix (f.print " "))
|
989
|
+
(f.print (write-to-string e)))
|
990
|
+
(define (pp-list f s level prefix)
|
991
|
+
(and prefix (do-indent f level))
|
992
|
+
(pp-parenl f)
|
945
993
|
(let loop ((s s)
|
946
994
|
(prefix #f))
|
947
995
|
(if (null? s)
|
948
|
-
(pp-parenr)
|
996
|
+
(pp-parenr f)
|
949
997
|
(let1 e (car s)
|
950
998
|
(if (list? e)
|
951
|
-
(begin (and prefix (
|
952
|
-
(pp-list e (+ level 1) prefix))
|
953
|
-
(pp-atom e prefix))
|
999
|
+
(begin (and prefix (f.print "\n"))
|
1000
|
+
(pp-list f e (+ level 1) prefix))
|
1001
|
+
(pp-atom f e prefix))
|
954
1002
|
(loop (cdr s) #t)))))
|
955
|
-
(
|
956
|
-
|
957
|
-
|
958
|
-
|
1003
|
+
(let1 f (get-optional f STDOUT)
|
1004
|
+
(if (list? s)
|
1005
|
+
(pp-list f s 0 #f)
|
1006
|
+
(f.print (write-to-string s)))
|
1007
|
+
(f.print "\n")))
|
1008
|
+
|
959
1009
|
|
1010
|
+
(define (pretty-print-to-string s)
|
1011
|
+
(let1 io (StringIO.new)
|
1012
|
+
(pretty-print s io)
|
1013
|
+
(io.rewind)
|
1014
|
+
(io.read)))
|
960
1015
|
|
961
1016
|
;; ----------------------------------------
|
962
|
-
;;
|
1017
|
+
;; sort library functions
|
963
1018
|
;; ----------------------------------------
|
964
|
-
(define
|
965
|
-
(
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
(
|
1019
|
+
(define (sort lst . cmpfn)
|
1020
|
+
(if (null? lst)
|
1021
|
+
'()
|
1022
|
+
(let1 cmpfn (get-optional cmpfn #f)
|
1023
|
+
(to-list
|
1024
|
+
(if cmpfn
|
1025
|
+
(lst.to_arr.sort (&block (a b) (cmpfn a b)))
|
1026
|
+
(lst.to_arr.sort))))))
|
1027
|
+
|
1028
|
+
|
1029
|
+
(define (sort-by lst keyfn)
|
1030
|
+
(if (null? lst)
|
1031
|
+
'()
|
1032
|
+
(to-list
|
1033
|
+
(lst.to_arr.sort_by (&block (item) (keyfn item))))))
|
1034
|
+
|
1035
|
+
|
1036
|
+
;; ----------------------------------------
|
1037
|
+
;; string library
|
1038
|
+
;; ----------------------------------------
|
1039
|
+
(define (string-length str) (str.size))
|
1040
|
+
|
1041
|
+
|
1042
|
+
;; ----------------------------------------
|
1043
|
+
;; regexp library functions
|
1044
|
+
;; ----------------------------------------
|
1045
|
+
(define (string->regexp str . casefold)
|
1046
|
+
(if (not (str.is_a? String))
|
1047
|
+
(error "Error: string->regexp requires a String argument.")
|
1048
|
+
(if (get-optional casefold #f)
|
1049
|
+
(Regexp.new str Regexp::IGNORECASE)
|
1050
|
+
(Regexp.new str))))
|
1051
|
+
|
1052
|
+
(define (regexp? obj)
|
1053
|
+
(obj.is_a? Regexp))
|
1054
|
+
|
1055
|
+
(define (regexp->string regexp)
|
1056
|
+
(regexp.source))
|
1057
|
+
|
1058
|
+
;; return: Ruby's MatchData instance
|
1059
|
+
(define (rxmatch regexp str)
|
1060
|
+
(let1 m (regexp.match str)
|
1061
|
+
(if m m #f)))
|
1062
|
+
|
1063
|
+
(define (rxmatch-start match . index)
|
1064
|
+
(let1 index (get-optional index 0)
|
1065
|
+
(match.begin index)))
|
1066
|
+
|
1067
|
+
(define (rxmatch-end match . index)
|
1068
|
+
(let1 index (get-optional index 0)
|
1069
|
+
(match.end index)))
|
1070
|
+
|
1071
|
+
(define (rxmatch-substring match . index)
|
1072
|
+
(let1 index (get-optional index 0)
|
1073
|
+
(nth index (match.to_a.to_list))))
|
1074
|
+
|
1075
|
+
(define (rxmatch-num-matches match)
|
1076
|
+
(match.size))
|
1077
|
+
|
1078
|
+
(define (rxmatch->string regexp str . index)
|
1079
|
+
(let1 index (get-optional index 0)
|
1080
|
+
(let1 m (rxmatch regexp str)
|
1081
|
+
(if m
|
1082
|
+
(rxmatch-substring m index)
|
1083
|
+
#f))))
|
971
1084
|
|
972
|
-
;; pending
|
973
|
-
(define check-arg
|
974
|
-
(macro (a b . c)
|
975
|
-
`(begin)))
|
976
1085
|
|
977
1086
|
;; ----------------------------------------
|
978
1087
|
;; global variables bind checker
|
@@ -987,6 +1096,29 @@
|
|
987
1096
|
;; ----------------------------------------
|
988
1097
|
;; Nendo compiler utility
|
989
1098
|
;; ----------------------------------------
|
1099
|
+
(define (disasm varname . opt)
|
1100
|
+
(let ((kind (get-optional opt 'compiled))
|
1101
|
+
(alist (get-source-info (varname.to_s))))
|
1102
|
+
(cond
|
1103
|
+
((eqv? kind 'compiled)
|
1104
|
+
(assv-ref "compiled_str" alist))
|
1105
|
+
((eqv? kind 'source)
|
1106
|
+
(assv-ref "source" alist))
|
1107
|
+
((eqv? kind 'expanded)
|
1108
|
+
(assv-ref "expanded" alist))
|
1109
|
+
((eqv? kind 'info)
|
1110
|
+
(string-join
|
1111
|
+
(list
|
1112
|
+
(sprintf " file: %s \n" (assv-ref "sourcefile" alist))
|
1113
|
+
(sprintf " lineno: %s \n" (assv-ref "lineno" alist))
|
1114
|
+
(sprintf " source: \n" )
|
1115
|
+
(pretty-print-to-string
|
1116
|
+
(assv-ref "source" alist))
|
1117
|
+
(sprintf " expanded: \n" )
|
1118
|
+
(pretty-print-to-string
|
1119
|
+
(assv-ref "expanded" alist))))))))
|
1120
|
+
|
1121
|
+
|
990
1122
|
(define (compiled-code-string compiled-code filename)
|
991
1123
|
(define (compiled-body-string string-list filename)
|
992
1124
|
(+
|
@@ -1029,7 +1161,7 @@
|
|
1029
1161
|
"core.loadInitFile()"
|
1030
1162
|
"core.setArgv( ARGV )"
|
1031
1163
|
"core.load_compiled_code_from_string( " ,(write-to-string str) " ) "
|
1032
|
-
"core.
|
1164
|
+
"core.evalStr( \"(if (and (global-defined? 'main) (procedure? main)) (main *argv*) #f) \" )"
|
1033
1165
|
"")
|
1034
1166
|
"\n")))
|
1035
1167
|
(else
|
@@ -1193,5 +1325,5 @@
|
|
1193
1325
|
;; global variables
|
1194
1326
|
;; ----------------------------------------
|
1195
1327
|
(define *nendo-version*
|
1196
|
-
"0.3.
|
1328
|
+
"0.3.4" ;;NENDO-VERSION
|
1197
1329
|
)
|