git @ Cat's Eye Technologies Velo / 4d67dee
Exceptions, rewrite attribute lookup to be more sane, method stubs. catseye 12 years ago
4 changed file(s) with 45 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
8888 def eval obj
8989 debug "eval #{self}"
9090 receiver = @receiver.eval obj
91 receiver.lookup @ident, []
91 receiver.lookup @ident
9292 end
9393
9494 def to_s
109109 args.push(expr.eval obj)
110110 end
111111 method = @method_expr.eval obj
112 debug "arguments evaluated, now calling #{@method_expr} -> #{method}"
112113 receiver = @method_expr.find_receiver obj
113114 if method.is_a? VeloMethod
114115 debug "running real method #{method} w/args #{args}, receiver=#{receiver}"
115116 method.run receiver, args
116117 else
117 debug "just returning non-method on call #{method}"
118 debug "just returning non-method (#{method}) on call, receiver=#{receiver}"
118119 method
119120 end
120121 end
0 require 'velo/debug'
1
2 class VeloSyntaxError < StandardError
3 end
4
5 class VeloAttributeNotFound < StandardError
6 end
7
8 class VeloMethodNotImplemented < StandardError
9 end
00 require 'velo/debug'
11
2 require 'velo/exceptions'
23 require 'velo/scanner'
34 require 'velo/ast'
45
56 debug "loading parser"
6
7 class VeloSyntaxError < StandardError
8 end
97
108 # Grammar:
119
00 require 'velo/debug'
11
2 require 'velo/exceptions'
23 require 'velo/parser'
34 require 'velo/ast'
45
5051 end
5152
5253 # look up an identifier on this object, or any of its delegates
53 def lookup ident, trail
54 def lookup ident
5455 debug "lookup #{ident} on #{self}"
56 result = lookup_impl ident, []
57 debug "lookup result: #{result}"
58 if result.nil?
59 raise VeloAttributeNotFound, "could not locate '#{ident}' on #{self}"
60 end
61 result
62 end
63
64 # look up an identifier on this object, or any of its delegates
65 def lookup_impl ident, trail
66 debug "lookup_impl #{ident} on #{self}"
5567 if trail.include? self
5668 debug "we've already seen this object, stopping search"
57 nil
69 return nil
5870 end
5971 trail.push self
6072 if @attrs.has_key? ident
61 debug "found here (#{self})"
73 debug "found here (#{self}), it's #{@attrs[ident]}"
6274 @attrs[ident]
6375 else
6476 x = nil
6577 for parent in @parents
66 x = parent.lookup ident, trail
78 x = parent.lookup_impl ident, trail
6779 break if not x.nil?
6880 end
6981 x
8597 $Object.set 'extend', VeloMethod.new('extend', proc { |obj, args|
8698 obj.extend args[0]
8799 })
100 $Object.set 'self', VeloMethod.new('self', proc { |obj, args|
101 raise VeloMethodNotImplemented
102 })
103 $Object.set 'new', VeloMethod.new('new', proc { |obj, args|
104 raise VeloMethodNotImplemented
105 })
88106
89107 $String = VeloObject.new 'String'
90108 $String.set 'concat', VeloMethod.new('concat', proc { |obj, args|
92110 obj.contents = obj.contents + args[0].contents
93111 # XXX should this create a new object, maybe?
94112 obj
113 })
114 $String.set 'class', VeloMethod.new('class', proc { |obj, args|
115 raise VeloMethodNotImplemented
116 })
117 $String.set 'method', VeloMethod.new('method', proc { |obj, args|
118 raise VeloMethodNotImplemented
119 })
120 $String.set 'if', VeloMethod.new('if', proc { |obj, args|
121 raise VeloMethodNotImplemented
95122 })
96123
97124 $IO = VeloObject.new 'IO'