nendo 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,120 @@
1
+ ;;-*- mode: nendo; syntax: scheme -*-;;
2
+ ;;;
3
+ ;;; nendo.experimental - experimental API for init.nnd
4
+ ;;;
5
+ ;;; Copyright (c) 2011-2011 Kiyoka Nishiyama <kiyoka@sumibi.org>
6
+ ;;;
7
+ ;;; Redistribution and use in source and binary forms, with or without
8
+ ;;; modification, are permitted provided that the following conditions
9
+ ;;; are met:
10
+ ;;;
11
+ ;;; 1. Redistributions of source code must retain the above copyright
12
+ ;;; notice, this list of conditions and the following disclaimer.
13
+ ;;;
14
+ ;;; 2. Redistributions in binary form must reproduce the above copyright
15
+ ;;; notice, this list of conditions and the following disclaimer in the
16
+ ;;; documentation and/or other materials provided with the distribution.
17
+ ;;;
18
+ ;;; 3. Neither the name of the authors nor the names of its contributors
19
+ ;;; may be used to endorse or promote products derived from this
20
+ ;;; software without specific prior written permission.
21
+ ;;;
22
+ ;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23
+ ;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
+ ;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25
+ ;;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26
+ ;;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27
+ ;;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
28
+ ;;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29
+ ;;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30
+ ;;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31
+ ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32
+ ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
+ ;;;
34
+
35
+
36
+ ;; Checking (Ruby's Enumerable?) and (not Nendo's list?)
37
+ (define (%%enumerable? x)
38
+ (and (x.is_a? Enumerable)
39
+ (not (x.is_a? Cell))))
40
+
41
+
42
+ ;; higher-order function for vector with Ruby's native method.
43
+ (define (%%map-able? proc . lists)
44
+ (if (= 1 (length lists))
45
+ (%%enumerable? (car lists))
46
+ #f))
47
+
48
+ (define (%%map proc vec)
49
+ (vec.map
50
+ (&block (x)
51
+ (proc x))))
52
+
53
+ (define (%map proc . lists)
54
+ (let1 args (cons proc lists)
55
+ (if (apply %%map-able? args)
56
+ (%%map proc (car lists))
57
+ (apply %map-original args))))
58
+
59
+
60
+ (define (%%for-each-able? proc . lists)
61
+ (if (= 1 (length lists))
62
+ (%%enumerable? (car lists))
63
+ #f))
64
+
65
+ (define (%%for-each proc vec)
66
+ (vec.each
67
+ (&block (x)
68
+ (proc x))))
69
+
70
+ (define (%for-each proc . lists)
71
+ (let1 args (cons proc lists)
72
+ (if (apply %%for-each-able? args)
73
+ (%%for-each proc (car lists))
74
+ (apply %for-each-original args))))
75
+
76
+
77
+ (define (%%filter-able? proc lst)
78
+ (%%enumerable? lst))
79
+
80
+ (define (%%filter proc vec)
81
+ (vec.select
82
+ (&block (x)
83
+ (proc x))))
84
+
85
+ (define (%filter proc lst)
86
+ (if (%%filter-able? proc lst)
87
+ (%%filter proc lst)
88
+ (%filter-original proc lst)))
89
+
90
+
91
+ (define map %map)
92
+ (define for-each %for-each)
93
+ (define filter %filter)
94
+
95
+
96
+
97
+ ;; dis-assembler
98
+ (define (disasm varname . opt)
99
+ (let ((kind (get-optional opt 'compiled))
100
+ (alist (get-source-info (varname.to_s))))
101
+ (cond
102
+ ((eqv? kind 'compiled)
103
+ (assv-ref "compiled_str" alist))
104
+ ((eqv? kind 'source)
105
+ (assv-ref "source" alist))
106
+ ((eqv? kind 'expanded)
107
+ (assv-ref "expanded" alist))
108
+ ((eqv? kind 'info)
109
+ (string-join
110
+ (list
111
+ (sprintf " file: %s \n" (assv-ref "sourcefile" alist))
112
+ (sprintf " lineno: %s \n" (assv-ref "lineno" alist))
113
+ (sprintf " source: \n" )
114
+ (pretty-print-to-string
115
+ (assv-ref "source" alist))
116
+ (sprintf " expanded: \n" )
117
+ (pretty-print-to-string
118
+ (assv-ref "expanded" alist))))))))
119
+
120
+