eleetscript 0.0.24 → 0.0.30

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.
@@ -31,16 +31,7 @@ module EleetScript
31
31
 
32
32
  def call(method_name, arguments = [])
33
33
  method = lookup(method_name.to_s)
34
- if method
35
- if method.arity == 3
36
- method.call(self, arguments, @context)
37
- else
38
- method.call(self, arguments)
39
- end
40
- else
41
- es_method_name = @context['String'].new_with_value(method_name.to_s, @context.namespace_context)
42
- call(NO_METHOD, arguments.dup.unshift(es_method_name))
43
- end
34
+ call_method(method_name, method, arguments)
44
35
  end
45
36
 
46
37
  def lookup(method_name)
@@ -60,6 +51,22 @@ module EleetScript
60
51
  method
61
52
  end
62
53
 
54
+ def super_call(method_name, arguments = [])
55
+ if super_class == self
56
+ @context['Errors'].call(
57
+ :<,
58
+ @context['String'].new_with_value(
59
+ "Cannot call super implmentation for #{method_name} if there is no super class",
60
+ @context
61
+ )
62
+ )
63
+ @context['nil']
64
+ else
65
+ method = super_class.lookup(method_name)
66
+ call_method(method_name, method, arguments)
67
+ end
68
+ end
69
+
63
70
  def super_class
64
71
  @super_class || @context['Object']
65
72
  end
@@ -106,6 +113,19 @@ module EleetScript
106
113
 
107
114
  private
108
115
 
116
+ def call_method(method_name, method, arguments)
117
+ if method
118
+ if method.arity == 3
119
+ method.call(self, arguments, @context)
120
+ else
121
+ method.call(self, arguments)
122
+ end
123
+ else
124
+ es_method_name = @context['String'].new_with_value(method_name.to_s, @context.namespace_context)
125
+ call(NO_METHOD, arguments.dup.unshift(es_method_name))
126
+ end
127
+ end
128
+
109
129
  def has_super_class?
110
130
  @super_class || (@super_class.nil? && name != 'Object')
111
131
  end
@@ -20,15 +20,22 @@ module EleetScript
20
20
 
21
21
  def call(method_name, arguments = [])
22
22
  method = find_method(method_name)
23
- if method
24
- if method.arity == 3
25
- method.call(self, arguments, @context)
26
- else
27
- method.call(self, arguments)
28
- end
23
+ call_method(method_name, method, arguments)
24
+ end
25
+
26
+ def super_call(method_name, arguments = [])
27
+ kls = @runtime_class
28
+ super_kls = kls.super_class
29
+ if kls == super_kls
30
+ str = @context['String'].new_with_value(
31
+ "Cannot call super implementation for #{method_name} without a super class",
32
+ @context
33
+ )
34
+ @context['Errors'].call(:<, str)
35
+ @context['nil']
29
36
  else
30
- es_method_name = @context["String"].new_with_value(method_name.to_s, @context.namespace_context)
31
- call(NO_METHOD, arguments.dup.unshift(es_method_name))
37
+ method = super_kls.instance_lookup(method_name)
38
+ call_method(method_name, method, arguments)
32
39
  end
33
40
  end
34
41
 
@@ -64,5 +71,20 @@ module EleetScript
64
71
  def class_name
65
72
  @runtime_class.name
66
73
  end
74
+
75
+ private
76
+
77
+ def call_method(method_name, method, arguments)
78
+ if method
79
+ if method.arity == 3
80
+ method.call(self, arguments, @context)
81
+ else
82
+ method.call(self, arguments)
83
+ end
84
+ else
85
+ es_method_name = @context["String"].new_with_value(method_name.to_s, @context.namespace_context)
86
+ call(NO_METHOD, arguments.dup.unshift(es_method_name))
87
+ end
88
+ end
67
89
  end
68
90
  end
@@ -232,10 +232,10 @@ module EleetScript
232
232
  ctx
233
233
  end
234
234
 
235
- def new_method_context(lambda_context = nil)
236
- ctx = MethodContext.new(current_self, current_class, lambda_context)
237
- ctx.parent_context = self
238
- ctx
235
+ def new_method_context(name, lambda_context = nil)
236
+ MethodContext.new(current_self, current_class, name, lambda_context).tap do |ctx|
237
+ ctx.parent_context = self
238
+ end
239
239
  end
240
240
  end
241
241
 
@@ -264,10 +264,10 @@ module EleetScript
264
264
  ns_context
265
265
  end
266
266
 
267
- def new_method_context(lambda_context = nil)
268
- ctx = MethodContext.new(current_self, current_class, lambda_context)
269
- ctx.parent_context = self
270
- ctx
267
+ def new_method_context(name, lambda_context = nil)
268
+ MethodContext.new(current_self, current_class, name, lambda_context).tap do |ctx|
269
+ ctx.parent_context = self
270
+ end
271
271
  end
272
272
 
273
273
  private
@@ -278,11 +278,13 @@ module EleetScript
278
278
  end
279
279
 
280
280
  class MethodContext < BaseContext
281
- init_with :handle_lambda_context
281
+ attr_reader :name
282
+
283
+ init_with :init_method_context
282
284
 
283
285
  def local_var(name, value = nil)
284
286
  if value
285
- if @lambda_context && (val = @lambda_context.local_var(name))
287
+ if @lambda_context && @lambda_context.local_var(name)
286
288
  @lambda_context.local_var(name, value)
287
289
  else
288
290
  local_vars[name] = value
@@ -303,10 +305,15 @@ module EleetScript
303
305
  @parent_context.namespace_context
304
306
  end
305
307
 
308
+ def lambda?
309
+ !@lambda_context.nil?
310
+ end
311
+
306
312
  private
307
313
 
308
- def handle_lambda_context(lambda_context)
314
+ def init_method_context(name, lambda_context)
315
+ @name = name
309
316
  @lambda_context = lambda_context
310
317
  end
311
318
  end
312
- end
319
+ end
@@ -1,26 +1,29 @@
1
+ # frozen_string_literal: false
2
+
1
3
  module EleetScript
2
4
  class EleetScriptMethod
3
- def initialize(params, body, lambda_context = nil)
5
+ def initialize(name, params, body, lambda_context = nil)
6
+ @name = name
4
7
  @params = params
5
8
  @body = body
6
9
  @lambda_context = lambda_context
7
10
  end
8
11
 
9
12
  def call(receiver, arguments, parent_context)
10
- context = parent_context.new_method_context(@lambda_context)
13
+ context = parent_context.new_method_context(@name, @lambda_context)
11
14
 
12
- context["lambda?"] = context["false"]
15
+ context['lambda?'] = context['false']
13
16
  @params.each_with_index do |param, index|
14
17
  arg = arguments[index]
15
18
  next unless arg
16
19
  context[param] = arg
17
20
  end
18
- if arguments.length > 0 && arguments.last.is_a?("Lambda")
19
- context["lambda?"] = context["true"]
20
- context["lambda"] = arguments.last
21
+ if arguments.length > 0 && arguments.last.is_a?('Lambda')
22
+ context['lambda?'] = context['true']
23
+ context['lambda'] = arguments.last
21
24
  end
22
25
 
23
- context["arguments"] = context["List"].call(:new, arguments)
26
+ context['arguments'] = context['List'].call(:new, arguments)
24
27
 
25
28
  @body.eval(context)
26
29
  end
@@ -29,4 +32,4 @@ module EleetScript
29
32
  3
30
33
  end
31
34
  end
32
- end
35
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eleetscript
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.24
4
+ version: 0.0.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Buck