Skip to content

Commit a8b23a9

Browse files
committed
Add --dumsymtabs option to dump symbol tables, and improve :deref diagnostics
1 parent 4b62af4 commit a8b23a9

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

compiler.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727
require 'output_functions'
2828
require 'globals'
2929

30+
require 'debugscope'
3031

3132
class Compiler
32-
attr_reader :global_functions
33+
attr_reader :global_functions, :global_scope
3334
attr_writer :trace, :stackfence
3435

3536
# list of all predefined keywords with a corresponding compile-method
@@ -196,7 +197,10 @@ def clean_method_name(name)
196197
#
197198
def compile_deref(scope, left, right)
198199
cscope = scope.find_constant(left)
199-
raise "Unable to resolve: #{left}::#{right} statically (FIXME)" if !cscope || !cscope.is_a?(ClassScope)
200+
if !cscope || !cscope.is_a?(ClassScope)
201+
global_scope.dump
202+
error("Unable to resolve: #{left}::#{right} statically (FIXME)",scope)
203+
end
200204
get_arg(cscope,right)
201205
end
202206

debugscope.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
class Scope
3+
def dump(indent = 0,data = {})
4+
data.sort.each do |k,v|
5+
if v.kind_of?(Scope)
6+
STDERR.puts "#{" "*indent*2}#{k}:"
7+
v.dump(indent + 1)
8+
else
9+
STDERR.puts "#{" "*indent*2}#{k}: #{v.inspect}"
10+
end
11+
end
12+
end
13+
end
14+
15+
class GlobalScope < Scope
16+
def dump(indent = 0,data = {})
17+
super(indent, @globals)
18+
end
19+
end
20+
21+
class ClassScope < Scope
22+
def dump(indent = 0,data = {})
23+
# FIXME: Don't add e.g. Token__Atom, and fix lookup so it's irrelevant
24+
if !@constants.empty?
25+
STDERR.puts "#{" "*indent*2}CONSTANTS:"
26+
super(indent + 1, @constants)
27+
end
28+
if !@instance_vars.empty?
29+
STDERR.puts "#{" "*indent*2}IVARS:"
30+
@instance_vars.sort.each do |ivar|
31+
STDERR.puts "#{" "*(indent + 1)*2}#{ivar}"
32+
end
33+
end
34+
end
35+
end

driver.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
stackfence = ARGV.include?("--stackfence")
77
transform = !ARGV.include?("--notransform")
88
nostabs = ARGV.include?("--nostabs")
9+
dumpsymtabs = ARGV.include?("--dumpsymtabs")
910

1011
# Option to not rewrite the parse tree (breaks compilation, but useful for debugging of the parser)
1112
OpPrec::TreeOutput.dont_rewrite if ARGV.include?("--dont-rewrite")
@@ -66,7 +67,11 @@
6667

6768
c.preprocess(prog) if transform
6869

69-
print_sexp prog if dump
70+
if dump || dumpsymtabs
71+
print_sexp prog if dump
72+
c.global_scope.dump if dumpsymtabs
73+
exit(1)
74+
end
7075

7176
c.compile(prog)
7277
end

0 commit comments

Comments
 (0)