nendo 0.5.4 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/nendo.rb +16 -2843
- data/lib/ruby/builtin_functions.rb +510 -0
- data/lib/ruby/core.rb +140 -0
- data/lib/ruby/evaluator.rb +1349 -0
- data/lib/ruby/out_of_module.rb +74 -0
- data/lib/ruby/printer.rb +111 -0
- data/lib/ruby/reader.rb +585 -0
- data/lib/ruby/types.rb +309 -0
- metadata +12 -5
data/lib/ruby/types.rb
ADDED
@@ -0,0 +1,309 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- encoding: utf-8 -*-
|
3
|
+
#
|
4
|
+
# types.rb - "types for nendo core"
|
5
|
+
#
|
6
|
+
# Copyright (c) 2009-2010 Kiyoka Nishiyama <kiyoka@sumibi.org>
|
7
|
+
#
|
8
|
+
# Redistribution and use in source and binary forms, with or without
|
9
|
+
# modification, are permitted provided that the following conditions
|
10
|
+
# are met:
|
11
|
+
#
|
12
|
+
# 1. Redistributions of source code must retain the above copyright
|
13
|
+
# notice, this list of conditions and the following disclaimer.
|
14
|
+
#
|
15
|
+
# 2. Redistributions in binary form must reproduce the above copyright
|
16
|
+
# notice, this list of conditions and the following disclaimer in the
|
17
|
+
# documentation and/or other materials provided with the distribution.
|
18
|
+
#
|
19
|
+
# 3. Neither the name of the authors nor the names of its contributors
|
20
|
+
# may be used to endorse or promote products derived from this
|
21
|
+
# software without specific prior written permission.
|
22
|
+
#
|
23
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
24
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
25
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
26
|
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
27
|
+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
28
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
29
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
30
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
31
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
32
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
33
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
#
|
35
|
+
module Nendo
|
36
|
+
|
37
|
+
class Nil
|
38
|
+
include Enumerable
|
39
|
+
def each() end
|
40
|
+
def to_arr() [] end
|
41
|
+
def length() 0 end
|
42
|
+
def isNull() true end
|
43
|
+
def isDotted() false end
|
44
|
+
def lastAtom() false end
|
45
|
+
def getLastAtom()
|
46
|
+
raise RuntimeError, "Error: Nil#getLastAtom method: this cell is not dotted list."
|
47
|
+
end
|
48
|
+
def to_s() "" end
|
49
|
+
def car()
|
50
|
+
raise "Error: Nil#car method: pair required, but got ()"
|
51
|
+
end
|
52
|
+
def cdr()
|
53
|
+
raise "Error: Nil#cdr method: pair required, but got ()"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class LispString < String
|
58
|
+
def LispString.escape( str )
|
59
|
+
if str.is_a? String
|
60
|
+
str.gsub( /\\/, "\\\\\\\\" ).gsub( /["]/, "\\\"" ).gsub( /[\r]/, "\\r" ).gsub( /[\t]/, "\\t" )
|
61
|
+
else
|
62
|
+
raise TypeError
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class LispMacro < Proc
|
68
|
+
end
|
69
|
+
|
70
|
+
class LispSyntax < Proc
|
71
|
+
end
|
72
|
+
|
73
|
+
class LispCoreSyntax
|
74
|
+
def initialize( syntaxName )
|
75
|
+
@syntaxName = syntaxName
|
76
|
+
end
|
77
|
+
attr_reader :syntaxName
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
class Cell
|
82
|
+
include Enumerable
|
83
|
+
|
84
|
+
def initialize( car = Nil.new, cdr = Nil.new )
|
85
|
+
@car = car
|
86
|
+
@cdr = cdr
|
87
|
+
end
|
88
|
+
attr_accessor :car, :cdr
|
89
|
+
|
90
|
+
def each # Supporting iterator
|
91
|
+
h = {}
|
92
|
+
if not isNull
|
93
|
+
it = self
|
94
|
+
while Nil != it.class
|
95
|
+
h[ it.hash ] = true
|
96
|
+
# printf( "%s : %s\n", it.car, it.hash )
|
97
|
+
yield it
|
98
|
+
if it.cdr.is_a? Cell
|
99
|
+
it = it.cdr
|
100
|
+
if h.has_key?( it.hash )
|
101
|
+
# found circular-list.
|
102
|
+
it = Nil.new
|
103
|
+
end
|
104
|
+
else
|
105
|
+
it = Nil.new
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def length() self.to_arr.length end
|
112
|
+
def size() self.length end # alias of length
|
113
|
+
|
114
|
+
def isDotted
|
115
|
+
((Cell != @cdr.class) and (Nil != @cdr.class))
|
116
|
+
end
|
117
|
+
|
118
|
+
def isNull
|
119
|
+
((Nil == @car.class) and (Nil == @cdr.class))
|
120
|
+
end
|
121
|
+
|
122
|
+
def lastCell
|
123
|
+
lastOne = self
|
124
|
+
self.each { |x| lastOne = x }
|
125
|
+
lastOne
|
126
|
+
end
|
127
|
+
|
128
|
+
def lastAtom
|
129
|
+
lastOne = self.lastCell
|
130
|
+
lastOne.isDotted
|
131
|
+
end
|
132
|
+
|
133
|
+
def getLastAtom
|
134
|
+
if self.lastAtom
|
135
|
+
self.lastCell.cdr
|
136
|
+
else
|
137
|
+
Nendo::Nil.new
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def to_arr
|
142
|
+
if isNull
|
143
|
+
[]
|
144
|
+
else
|
145
|
+
self.map {|x| x.car}
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def first
|
150
|
+
self.car
|
151
|
+
end
|
152
|
+
|
153
|
+
def second
|
154
|
+
self.cdr.car
|
155
|
+
end
|
156
|
+
|
157
|
+
def third
|
158
|
+
self.cdr.cdr.car
|
159
|
+
end
|
160
|
+
|
161
|
+
alias :cdar :second
|
162
|
+
alias :cddar :third
|
163
|
+
end
|
164
|
+
|
165
|
+
class LispValues
|
166
|
+
def initialize( arr )
|
167
|
+
if 1 == arr.size
|
168
|
+
raise ArgumentError, "Error: LispValues object expects 0 or 2+ length of array"
|
169
|
+
else
|
170
|
+
@values = arr
|
171
|
+
end
|
172
|
+
end
|
173
|
+
attr_reader :values
|
174
|
+
end
|
175
|
+
|
176
|
+
class LispRegexp
|
177
|
+
def initialize( str )
|
178
|
+
@exp = str[ 1 ... str.size ]
|
179
|
+
@ignoreCase = (str[0] == 'i')
|
180
|
+
end
|
181
|
+
def to_s
|
182
|
+
sprintf( "|%s|", @exp ) + (@ignoreCase ? "i" : "")
|
183
|
+
end
|
184
|
+
def escape
|
185
|
+
@exp.gsub( /\\/, "\\\\\\\\" )
|
186
|
+
end
|
187
|
+
attr_reader :ignoreCase
|
188
|
+
end
|
189
|
+
|
190
|
+
class LispKeyword
|
191
|
+
def initialize( str )
|
192
|
+
@key = str.intern
|
193
|
+
end
|
194
|
+
|
195
|
+
def ==(other)
|
196
|
+
if other.is_a? LispKeyword
|
197
|
+
self.key == other.key
|
198
|
+
else
|
199
|
+
false
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def ===(other)
|
204
|
+
self.==(other)
|
205
|
+
end
|
206
|
+
|
207
|
+
def to_s
|
208
|
+
self.key.to_s
|
209
|
+
end
|
210
|
+
|
211
|
+
attr_reader :key
|
212
|
+
end
|
213
|
+
|
214
|
+
class NendoTestError
|
215
|
+
def initialize( type = RuntimeError )
|
216
|
+
@type = type
|
217
|
+
end
|
218
|
+
|
219
|
+
def to_s
|
220
|
+
type.to_s
|
221
|
+
end
|
222
|
+
attr_accessor :type
|
223
|
+
end
|
224
|
+
|
225
|
+
class SyntacticClosure
|
226
|
+
def initialize( originalSymbol, renamedSymbol )
|
227
|
+
@originalSymbol = originalSymbol
|
228
|
+
@renamedSymbol = renamedSymbol
|
229
|
+
end
|
230
|
+
|
231
|
+
def to_s
|
232
|
+
@renamedSymbol.to_s
|
233
|
+
end
|
234
|
+
|
235
|
+
def intern
|
236
|
+
@renamedSymbol
|
237
|
+
end
|
238
|
+
|
239
|
+
def sourcefile() "dynamic S-expression ( no source )" end
|
240
|
+
def lineno() 1 end
|
241
|
+
|
242
|
+
attr_reader :originalSymbol, :renamedSymbol
|
243
|
+
end
|
244
|
+
|
245
|
+
class SourceInfo
|
246
|
+
def initialize
|
247
|
+
@varname = nil
|
248
|
+
@sourcefile = nil
|
249
|
+
@lineno = nil
|
250
|
+
@source_sexp = Cell.new
|
251
|
+
@expanded_sexp = Cell.new
|
252
|
+
@compiled_str = nil
|
253
|
+
end
|
254
|
+
|
255
|
+
def deepCopy( sexp )
|
256
|
+
Marshal.load(Marshal.dump( sexp ))
|
257
|
+
end
|
258
|
+
|
259
|
+
def setVarname( varname )
|
260
|
+
@varname = varname
|
261
|
+
end
|
262
|
+
|
263
|
+
def setSource( sourcefile, lineno, source_sexp )
|
264
|
+
@sourcefile = sourcefile
|
265
|
+
@lineno = lineno
|
266
|
+
@source_sexp = self.deepCopy( source_sexp )
|
267
|
+
end
|
268
|
+
|
269
|
+
def setExpanded( expanded_sexp )
|
270
|
+
@expanded_sexp = self.deepCopy( expanded_sexp )
|
271
|
+
end
|
272
|
+
|
273
|
+
def setCompiled( compiled_str )
|
274
|
+
@compiled_str = compiled_str
|
275
|
+
end
|
276
|
+
|
277
|
+
def debugPrint
|
278
|
+
printf( "=== sourceInfo === \n" )
|
279
|
+
printf( " varname = %s\n", @varname )
|
280
|
+
printf( " sourcefile = %s\n", @sourcefile )
|
281
|
+
printf( " lineno = %s\n", @lineno)
|
282
|
+
printf( " compiled_str = %s\n", @compiled_str )
|
283
|
+
end
|
284
|
+
|
285
|
+
attr_reader :varname, :sourcefile, :lineno, :source_sexp, :expanded_sexp, :compiled_str
|
286
|
+
end
|
287
|
+
|
288
|
+
class DelayedCallPacket
|
289
|
+
def initialize( _rubysym, _origname, _pred, _args )
|
290
|
+
@rubysym = _rubysym
|
291
|
+
@origname = _origname
|
292
|
+
@pred = _pred
|
293
|
+
@args = _args
|
294
|
+
end
|
295
|
+
attr_reader :rubysym, :origname, :pred, :args
|
296
|
+
end
|
297
|
+
|
298
|
+
class Token
|
299
|
+
def initialize( kind, str, sourcefile, lineno = nil, column = nil )
|
300
|
+
@kind = kind
|
301
|
+
@str = str
|
302
|
+
@sourcefile = sourcefile
|
303
|
+
@lineno = lineno
|
304
|
+
@column = column
|
305
|
+
end
|
306
|
+
attr_accessor :kind, :str, :sourcefile, :lineno, :column
|
307
|
+
end
|
308
|
+
|
309
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nendo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 6
|
9
|
+
- 0
|
10
|
+
version: 0.6.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kiyoka Nishiyama
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-10-
|
18
|
+
date: 2011-10-27 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|
@@ -143,6 +143,13 @@ files:
|
|
143
143
|
- lib/nendo/test.nndc
|
144
144
|
- lib/rfc/json.nnd
|
145
145
|
- lib/rfc/json.nndc
|
146
|
+
- lib/ruby/builtin_functions.rb
|
147
|
+
- lib/ruby/core.rb
|
148
|
+
- lib/ruby/evaluator.rb
|
149
|
+
- lib/ruby/out_of_module.rb
|
150
|
+
- lib/ruby/printer.rb
|
151
|
+
- lib/ruby/reader.rb
|
152
|
+
- lib/ruby/types.rb
|
146
153
|
- lib/srfi-1.nnd
|
147
154
|
- lib/srfi-1.nndc
|
148
155
|
- lib/srfi-2.nnd
|