-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathglobalscope.rb
73 lines (58 loc) · 1.64 KB
/
globalscope.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Holds globals, and (for now at least), global constants.
# Note that Ruby-like "constants" aren't really - they are "assign-once"
# variables. As such, some of them can be treated as true constants
# (because their value is known at compile time), but some of them are
# not. For now, we'll treat all of them as global variables.
class GlobalScope < Scope
attr_reader :class_scope, :globals
def initialize(offsets)
@vtableoffsets = offsets
@globals = {}
@class_scope = ClassScope.new(self,"Object",@vtableoffsets,nil)
# Despite not following "$name" syntax, these are really global constants.
@globals[:false] = true
@globals[:true] = true
@globals[:nil] = true
# Special "built-in" globals with two-character names starting with $
# that we need to expand to something else.
@aliases = {
:"$:" => "LOAD_PATH",
:"$0" => "__D_0"
}
end
def add_global(c)
@globals[c] = true
end
def add_constant(c,v = true)
@globals[c] = v
end
def find_constant(c)
@globals[c]
end
def rest?
false
end
# Returns an argument within the global scope, if defined here.
# Otherwise returns it as an address (<tt>:addr</tt>)
def get_arg(a)
# Handle $:, $0 etc.
s = @aliases[a]
return [:global, s] if s
return [:arg, 1] if a == :__argv
return [:arg, 0] if a == :__argc
return [:global, a] if @globals.member?(a)
return [:possible_callm, a] if a && !(?A..?Z).member?(a.to_s[0]) # Hacky way of excluding constants
return [:addr, a]
end
def name
""
end
def instance_size
0
end
def lvaroffset
0
end
def include_module m
end
end