0 | 0 |
require 'velo/debug'
|
1 | 1 |
|
|
2 |
require 'velo/exceptions'
|
2 | 3 |
require 'velo/parser'
|
3 | 4 |
require 'velo/ast'
|
4 | 5 |
|
|
50 | 51 |
end
|
51 | 52 |
|
52 | 53 |
# look up an identifier on this object, or any of its delegates
|
53 | |
def lookup ident, trail
|
|
54 |
def lookup ident
|
54 | 55 |
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}"
|
55 | 67 |
if trail.include? self
|
56 | 68 |
debug "we've already seen this object, stopping search"
|
57 | |
nil
|
|
69 |
return nil
|
58 | 70 |
end
|
59 | 71 |
trail.push self
|
60 | 72 |
if @attrs.has_key? ident
|
61 | |
debug "found here (#{self})"
|
|
73 |
debug "found here (#{self}), it's #{@attrs[ident]}"
|
62 | 74 |
@attrs[ident]
|
63 | 75 |
else
|
64 | 76 |
x = nil
|
65 | 77 |
for parent in @parents
|
66 | |
x = parent.lookup ident, trail
|
|
78 |
x = parent.lookup_impl ident, trail
|
67 | 79 |
break if not x.nil?
|
68 | 80 |
end
|
69 | 81 |
x
|
|
85 | 97 |
$Object.set 'extend', VeloMethod.new('extend', proc { |obj, args|
|
86 | 98 |
obj.extend args[0]
|
87 | 99 |
})
|
|
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 |
})
|
88 | 106 |
|
89 | 107 |
$String = VeloObject.new 'String'
|
90 | 108 |
$String.set 'concat', VeloMethod.new('concat', proc { |obj, args|
|
|
92 | 110 |
obj.contents = obj.contents + args[0].contents
|
93 | 111 |
# XXX should this create a new object, maybe?
|
94 | 112 |
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
|
95 | 122 |
})
|
96 | 123 |
|
97 | 124 |
$IO = VeloObject.new 'IO'
|