rubymotionlisp 1.0.11 → 1.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10c9718f339ca93186dafa8165c1770ed3ac54ae
4
- data.tar.gz: cbb7459b2700bd3e754e67a376be801cf9d8a554
3
+ metadata.gz: edf460c69b7a6c37ad3d8e0ba6b7f7ae3fee1d66
4
+ data.tar.gz: d91504f34b6d53f559724eb0eb0b54bb3b8c1820
5
5
  SHA512:
6
- metadata.gz: 9d1a6fb500711bb718ecd443a00dd49ae7e1da7262ea36e587c3d1c30e604b8d89ba88a08ed8df6beb03b240f163153409f5ee781adad39a7753f4818fbe5a0f
7
- data.tar.gz: b08b3633a0fad3ccfda4e6824d40400cc983c4dfc7dc5aeeee2867dc8395241c83256f6b67697b162007e0e6add6bc64aaa992cc3f75c3ad199343fbfa3b43dc
6
+ metadata.gz: 932e99eba3ed5bed2a8c783e2275c2907b1abea1076952964edfed3ef1e1fe92843f4c06b1aedf956b05144657d81e92089e9af7f89ab4ebbea05ca05737128b
7
+ data.tar.gz: 191e9847203785b2bdae6dba875fabab5ce4f4aa8b97b954dd72addd8627caf0569d6a9b9421db69b57871e227a6b0d7c6b9730ce1a04f2f07ed22700a1f6ee1
@@ -17,197 +17,6 @@ module Lisp
17
17
  def value
18
18
  self
19
19
  end
20
-
21
- def set_car!(d)
22
- @car = d
23
- end
24
-
25
- def lisp_object?
26
- true
27
- end
28
-
29
- def set_cdr!(d)
30
- @cdr = d
31
- end
32
-
33
-
34
- def set_nth!(n, d)
35
- return nil if empty?
36
- c = self
37
- n.times {|i| c = c.cdr}
38
- c.set_car!(d)
39
- end
40
-
41
-
42
- def empty?
43
- @car.nil? && @cdr.nil?
44
- end
45
-
46
- def string?
47
- false
48
- end
49
-
50
- def character?
51
- false
52
- end
53
-
54
- def number?
55
- false
56
- end
57
-
58
- def positive?
59
- false
60
- end
61
-
62
- def zero?
63
- false
64
- end
65
-
66
- def negative?
67
- false
68
- end
69
-
70
- def symbol?
71
- false
72
- end
73
-
74
- def primitive?
75
- false
76
- end
77
-
78
- def special?
79
- false
80
- end
81
-
82
- def function?
83
- false
84
- end
85
-
86
- def macro?
87
- false
88
- end
89
-
90
- def pair?
91
- true
92
- end
93
-
94
- def list?
95
- true
96
- end
97
-
98
- def frame?
99
- false
100
- end
101
-
102
- def vector?
103
- false
104
- end
105
-
106
- def eq?(other)
107
- return true if empty? && (other.nil? || (other.pair? && other.empty?))
108
- other.pair? && self == other
109
- end
110
-
111
- def eqv?(other)
112
- return true if empty? && (other.nil? || (other.pair? && other.empty?))
113
- other.pair? && self == other
114
- end
115
-
116
- def equal?(other)
117
- return true if empty? && (other.nil? || (other.pair? && other.empty?))
118
- return false unless other.pair?
119
- @car.equal?(other.car) && @cdr.equal?(other.cdr)
120
- end
121
-
122
- def type
123
- :pair
124
- end
125
-
126
- def to_s_helper
127
- return "#{@car.to_s}" if @cdr.nil?
128
- return "#{@car.to_s} . #{@cdr.to_s}" unless @cdr.pair?
129
- "#{@car.to_s} #{@cdr.to_s_helper}"
130
- end
131
-
132
- def to_s
133
- return "()" if self.empty?
134
- return "'#{@cdr.car.to_s}" if @car.symbol? && @car.name == "quote"
135
- return "{#{@cdr.to_s_helper}}" if @car.symbol? && @car.name == "make-frame"
136
- return "#(#{@cdr.to_s_helper})" if @car.symbol? && @car.name == "make-vector"
137
- return "(#{@car.to_s} . #{@cdr.to_s})" if !@cdr.nil? && !@cdr.pair?
138
- return "(#{self.to_s_helper})"
139
- end
140
-
141
- def print_string_helper
142
- @cdr.nil? ? "#{@car.print_string}" : "#{@car.print_string} #{@cdr.print_string_helper}"
143
- end
144
-
145
- def print_string
146
- return "()" if self.empty?
147
- return "'#{@cdr.car.print_string}" if @car.symbol? && @car.name == "quote"
148
- return "{#{@cdr.print_string_helper}}" if @car.symbol? && @car.name == "make-frame"
149
- return "#(#{@cdr.print_string_helper})" if @car.symbol? && @car.name == "make-vector"
150
- return "(#{@car.print_string} . #{@cdr.print_string})" if !@cdr.nil? && !@cdr.pair?
151
- return "(#{self.print_string_helper})"
152
- end
153
-
154
- def to_a
155
- a = []
156
- return a if empty?
157
- c = self
158
- until c.nil?
159
- a << c.car
160
- c = c.cdr
161
- end
162
- a
163
- end
164
-
165
- def each &block
166
- return if empty?
167
- c = self
168
- if self.length > 0
169
- until c.nil?
170
- yield c.car
171
- c = c.cdr
172
- end
173
- end
174
- end
175
-
176
- def self.array_to_list(cells, tail=nil)
177
- return cons() if cells.empty? && tail.nil?
178
- head = ConsCell.new
179
- last_cell = head
180
- (0...cells.length).each do |i|
181
- new_cell = self.cons(cells[i], nil)
182
- last_cell.set_cdr!(new_cell)
183
- last_cell = new_cell
184
- end
185
- last_cell.set_cdr!(tail)
186
- head.cdr
187
- end
188
-
189
- def traverse(path)
190
- next_cell = self
191
- path.chars.each do |p|
192
- return nil if next_cell.nil? || !next_cell.pair?
193
- next_cell = ((p == ?a) ? next_cell.car : next_cell.cdr)
194
- end
195
- next_cell
196
- end
197
-
198
- def method_missing(name, *args, &block)
199
- if name[0] == ?c && name[-1] == ?r && (name[1..-2].chars.all? {|e| "ad".include?(e)})
200
- self.traverse(name[1..-2].reverse)
201
- else
202
- super
203
- end
204
- end
205
-
206
- def nth(n)
207
- c = self
208
- n.times {|i| c = c.cdr}
209
- c.car
210
- end
211
20
 
212
21
  def nth_tail(n)
213
22
  c = self
@@ -220,12 +29,16 @@ module Lisp
220
29
  return obj.value
221
30
  end
222
31
 
32
+
33
+ def push_current_code
34
+ env.current_code.unshift(self.print_string)
35
+ end
223
36
 
224
37
 
225
38
  def inner_eval(env)
226
39
  func = @car.evaluate(env)
227
40
  return Lisp::Debug.process_error("There is no function or macro named #{@car}", env) if func.nil?
228
- env.current_code.unshift(self.print_string()) if !Lisp::Debug.eval_in_debug_repl && Lisp::Debug.interactive
41
+ push_current_code if !Lisp::Debug.eval_in_debug_repl && Lisp::Debug.interactive
229
42
 
230
43
  Lisp::Debug.log_eval(self, env)
231
44
 
@@ -5,28 +5,40 @@ module Lisp
5
5
  def initialize
6
6
  end
7
7
 
8
- def make_number(str)
9
- Lisp::Number.with_value(str.to_i)
8
+ def make_number(str, pos)
9
+ Lisp::Number.with_value(str.to_i).tap do |obj|
10
+ obj.set_location(pos, str.length)
11
+ end
10
12
  end
11
13
 
12
14
  def make_hex_number(str)
13
- Lisp::Number.with_value(["0x", str].join.to_i(0))
15
+ Lisp::Number.with_value(["0x", str].join.to_i(0)).tap do |obj|
16
+ obj.set_location(pos, str.length)
17
+ end
14
18
  end
15
19
 
16
20
  def make_float(str)
17
- Lisp::Number.with_value(str.to_f)
21
+ Lisp::Number.with_value(str.to_f).tap do |obj|
22
+ obj.set_location(pos, str.length)
23
+ end
18
24
  end
19
25
 
20
26
  def make_string(str)
21
- Lisp::String.with_value(str)
27
+ Lisp::String.with_value(str).tap do |obj|
28
+ obj.set_location(pos, str.length)
29
+ end
22
30
  end
23
31
 
24
32
  def make_symbol(str)
25
- Lisp::Symbol.named(str)
33
+ Lisp::Symbol.named(str).tap do |obj|
34
+ obj.set_location(pos, str.length)
35
+ end
26
36
  end
27
37
 
28
38
  def make_character(ch)
29
- Lisp::Character.with_value(ch)
39
+ Lisp::Character.with_value(ch).tap do |obj|
40
+ obj.set_location(pos, str.length)
41
+ end
30
42
  end
31
43
 
32
44
  def parse_cons_cell(tokens)
@@ -130,15 +142,25 @@ module Lisp
130
142
  when :COMMENT
131
143
  next
132
144
  when :NUMBER
133
- return make_number(lit)
145
+ return make_number(lit).tap do |obj|
146
+ obj.set_location(pos, lit.length) if @parse_for_debugging
147
+ end
134
148
  when :FLOAT
135
- return make_float(lit)
149
+ return make_float(lit).tap do |obj|
150
+ obj.set_location(pos, lit.length) if @parse_for_debugging
151
+ end
136
152
  when :HEXNUMBER
137
- return make_hex_number(lit)
153
+ return make_hex_number(lit).tap do |obj|
154
+ obj.set_location(pos, lit.length) if @parse_for_debugging
155
+ end
138
156
  when :STRING
139
- return make_string(lit)
157
+ return make_string(lit).tap do |obj|
158
+ obj.set_location(pos, lit.length) if @parse_for_debugging
159
+ end
140
160
  when :CHARACTER
141
- return make_character(lit)
161
+ return make_character(lit).tap do |obj|
162
+ obj.set_location(pos, lit.length) if @parse_for_debugging
163
+ end
142
164
  when :LPAREN
143
165
  return parse_cons_cell(tokens)
144
166
  when :LBRACE
@@ -150,35 +172,65 @@ module Lisp
150
172
  when :QUOTE_HASH_LPAREN
151
173
  return parse_vector(tokens, true)
152
174
  when :SYMBOL
153
- return make_symbol(lit)
175
+ return make_symbol(lit).tap do |obj|
176
+ obj.set_location(pos, lit.length) if @parse_for_debugging
177
+ end
154
178
  when :FFI_NEW_SYMBOL
155
- return Lisp::FfiNew.new(lit)
179
+ return Lisp::FfiNew.new(lit).tap do |obj|
180
+ obj.set_location(pos, lit.length) if @parse_for_debugging
181
+ end
156
182
  when :FFI_SEND_SYMBOL
157
- return Lisp::FfiSend.new(lit)
183
+ return Lisp::FfiSend.new(lit).tap do |obj|
184
+ obj.set_location(pos, lit.length) if @parse_for_debugging
185
+ end
158
186
  when :FFI_STATIC_SYMBOL
159
- return Lisp::FfiStatic.new(lit)
187
+ return Lisp::FfiStatic.new(lit).tap do |obj|
188
+ obj.set_location(pos, lit.length) if @parse_for_debugging
189
+ end
160
190
  when :FALSE
161
- return Lisp::FALSE
191
+ if @parse_for_debugging
192
+ return Lisp::Boolean.with_value(false).tap do |obj|
193
+ obj.set_location(pos, 2) if @parse_for_debugging
194
+ end
195
+ else
196
+ return Lisp::FALSE
197
+ end)
162
198
  when :TRUE
163
- return Lisp::TRUE
199
+ if @parse_for_debugging
200
+ return Lisp::Boolean.with_value(false).tap do |obj|
201
+ obj.set_location(pos, 2) if @parse_for_debugging
202
+ end
203
+ else
204
+ return Lisp::TRUE
205
+ end)
164
206
  when :QUOTE
165
207
  expr = parse_sexpr(tokens)
166
- return Lisp::ConsCell.array_to_list([Lisp::Symbol.named('quote'), expr])
208
+ return Lisp::ConsCell.array_to_list([Lisp::Symbol.named('quote'), expr]).tap do |obj|
209
+ obj.set_location(pos, expr.src_length + 1) if @parse_for_debugging
210
+ end
167
211
  when :BACKQUOTE
168
212
  expr = parse_sexpr(tokens)
169
- return Lisp::ConsCell.array_to_list([Lisp::Symbol.named('quasiquote'), expr])
213
+ return Lisp::ConsCell.array_to_list([Lisp::Symbol.named('quasiquote'), expr]).tap do |obj|
214
+ obj.set_location(pos, expr.src_length + 1) if @parse_for_debugging
215
+ end
170
216
  when :COMMA
171
217
  expr = parse_sexpr(tokens)
172
- return Lisp::ConsCell.array_to_list([Lisp::Symbol.named('unquote'), expr])
218
+ return Lisp::ConsCell.array_to_list([Lisp::Symbol.named('unquote'), expr]).tap do |obj|
219
+ obj.set_location(pos, expr.src_length + 1) if @parse_for_debugging
220
+ end
173
221
  when :COMMAAT
174
222
  expr = parse_sexpr(tokens)
175
- return Lisp::ConsCell.array_to_list([Lisp::Symbol.named('unquote-splicing'), expr])
223
+ return Lisp::ConsCell.array_to_list([Lisp::Symbol.named('unquote-splicing'), expr]).tap do |obj|
224
+ obj.set_location(pos, expr.src_length + 2) if @parse_for_debugging
225
+ end
176
226
  when :WHITESPACE
177
227
  next
178
228
  when :ILLEGAL
179
229
  return Lisp::Debug.process_error("Illegal token: #{lit} on line #{tokens.line_number}", Lisp::EnvironmentFrame.global)
180
230
  else
181
- return make_symbol(lit)
231
+ return make_symbol(lit).tap do |obj|
232
+ obj.set_location(pos, lit.length) if @parse_for_debugging
233
+ end
182
234
  end
183
235
  end
184
236
  end
@@ -38,6 +38,7 @@ module Lisp
38
38
  end
39
39
 
40
40
  def evaluate(env)
41
+ super
41
42
  return self if @naked
42
43
  env.value_of(self)
43
44
  end
@@ -51,7 +51,7 @@ module Lisp
51
51
  end
52
52
 
53
53
  def next_token
54
- return @lookahead_token, @lookahead_literal
54
+ return @position, @lookahead_token, @lookahead_literal
55
55
  end
56
56
 
57
57
  def eof?
@@ -112,7 +112,7 @@ module Lisp
112
112
  end
113
113
 
114
114
  tok ||= :SYMBOL
115
- return tok, case tok
115
+ return @position, tok, case tok
116
116
  when :SYMBOL, :FFI_STATIC_SYMBOL
117
117
  lit
118
118
  when :FFI_SEND_SYMBOL
@@ -143,7 +143,7 @@ module Lisp
143
143
  :NUMBER
144
144
  end
145
145
 
146
- return tok, lit
146
+ return @position, tok, lit
147
147
  end
148
148
 
149
149
 
@@ -183,9 +183,9 @@ module Lisp
183
183
  advance
184
184
  end
185
185
 
186
- return :EOF, '' if eof?
186
+ return @position, :EOF, '' if eof?
187
187
  advance
188
- return :STRING, process_escapes(lit)
188
+ return @position, :STRING, process_escapes(lit)
189
189
  end
190
190
 
191
191
 
@@ -203,25 +203,27 @@ module Lisp
203
203
  advance
204
204
  end
205
205
 
206
- return :CHARACTER, lit
206
+ return @position, :CHARACTER, lit
207
207
  end
208
208
 
209
209
 
210
210
  def read_next_token
211
- return :EOF, '' if eof?
211
+ @position = @source.pos
212
+
213
+ return @position, :EOF, '' if eof?
212
214
 
213
215
  if @absorb_whitespace
214
216
  while space?(@current_ch)
215
217
  @line_number += 1 if @current_ch == "\n"
216
218
  advance
217
- return :EOF, '' if eof?
219
+ return @position, :EOF, '' if eof?
218
220
  end
219
221
  end
220
222
 
221
223
  if !@absorb_whitespace && space?(@current_ch)
222
224
  @line_number += 1 if @current_ch == "\n"
223
225
  advance
224
- return :WHITESPACE, " "
226
+ return @position, :WHITESPACE, " "
225
227
  elsif number?(@current_ch)
226
228
  return read_number(false)
227
229
  elsif @current_ch == '-' && number?(@next_ch)
@@ -240,50 +242,50 @@ module Lisp
240
242
  elsif @current_ch == '\'' && @next_ch == '{'
241
243
  advance
242
244
  advance
243
- return :QUOTE_LBRACE, "'{"
245
+ return @position, :QUOTE_LBRACE, "'{"
244
246
  elsif @current_ch == '\'' && @next_ch == '#' && @next_next_ch == '('
245
247
  advance
246
248
  advance
247
249
  advance
248
- return :QUOTE_HASH_LPAREN, "'#("
250
+ return @position, :QUOTE_HASH_LPAREN, "'#("
249
251
  elsif @current_ch == '\''
250
252
  advance
251
- return :QUOTE, "'"
253
+ return @position, :QUOTE, "'"
252
254
  elsif @current_ch == '`'
253
255
  advance
254
- return :BACKQUOTE, "`"
256
+ return @position, :BACKQUOTE, "`"
255
257
  elsif @current_ch == ',' && @next_ch == '@'
256
258
  advance
257
259
  advance
258
- return :COMMAAT, ",@"
260
+ return @position, :COMMAAT, ",@"
259
261
  elsif @current_ch == ','
260
262
  advance
261
- return :COMMA, ","
263
+ return @position, :COMMA, ","
262
264
  elsif @current_ch == '('
263
265
  advance
264
- return :LPAREN, "("
266
+ return @position, :LPAREN, "("
265
267
  elsif @current_ch == '#' && @next_ch == '('
266
268
  advance
267
269
  advance
268
- return :HASH_LPAREN, "#("
270
+ return @position, :HASH_LPAREN, "#("
269
271
  elsif @current_ch == ')'
270
272
  advance
271
- return :RPAREN, ")"
273
+ return @position, :@position, RPAREN, ")"
272
274
  elsif @current_ch == '{'
273
275
  advance
274
- return :LBRACE, "{"
276
+ regturn @position, :LBRACE, "{"
275
277
  elsif @current_ch == '}'
276
278
  advance
277
- return :RBRACE, "}"
279
+ return @position, :RBRACE, "}"
278
280
  elsif @current_ch == '['
279
281
  advance
280
- return :LBRACKET, "["
282
+ return @position, :LBRACKET, "["
281
283
  elsif @current_ch == ']'
282
284
  advance
283
- return :RBRACKET, "]"
285
+ return @position, :RBRACKET, "]"
284
286
  elsif @current_ch == '.' && space?(@next_ch)
285
287
  advance
286
- return :PERIOD, "."
288
+ return @position, :PERIOD, "."
287
289
  elsif @current_ch == '.' && symbol_character?(@next_ch)
288
290
  return read_symbol
289
291
  elsif symbol_character?(@current_ch)
@@ -291,20 +293,20 @@ module Lisp
291
293
  elsif @current_ch == '#' && @next_ch == 't'
292
294
  advance
293
295
  advance
294
- return :TRUE, "#t"
296
+ return @position, :TRUE, "#t"
295
297
  elsif @current_ch == '#' && @next_ch == 'f'
296
298
  advance
297
299
  advance
298
- return :FALSE, "#f"
300
+ return @position, :FALSE, "#f"
299
301
  elsif @current_ch == ';'
300
302
  lit = ""
301
303
  while true
302
- return :COMMENT, lit if eof? || @current_ch == "\n"
304
+ return @position, :COMMENT, lit if eof? || @current_ch == "\n"
303
305
  lit << @current_ch
304
306
  advance
305
307
  end
306
308
  else
307
- return :ILLEGAL, @current_ch
309
+ return @position, :ILLEGAL, @current_ch
308
310
  end
309
311
  end
310
312
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubymotionlisp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.11
4
+ version: 1.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Astels
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-20 00:00:00.000000000 Z
11
+ date: 2016-03-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: An embeddable Lisp as an extension language for RubyMotion
14
14
  email: dastels@icloud.com