Commit 90bf02b0
90bf02b07f53Merged
sacckey <[email protected]> · 6 months ago · 2 files · ~2 modified
Description
fix(codegen): track lexical scope for constant initialization and remove redundant root-builtin check
Details
- Commit
- 90bf02b07f53
- Parent
- 5f3707d3fb46
spinel_codegen.rbmodifiedView file
@@ -129,6 +129,7 @@
129129
@const_names = "".split(",")130130
@const_types = "".split(",")131131
@const_expr_ids = []132+
@const_scope_names = "".split(",")132133
133134
# ---- Scope stack for local variables ----134135
@scope_names = "".split(",")@@ -136,6 +137,7 @@
136137
137138
@current_class_idx = -1138139
@current_method_name = ""140+
@current_lexical_scope = ""139141
@current_method_return = ""140142
@in_main = 0141143
@in_loop = 0@@ -759,16 +761,6 @@
759761
0760762
end761763
762-
def builtin_const_root_name(name)763-
if name == "Float" || name == "Integer" || name == "Math"764-
return 1765-
end766-
if name == "Array" || name == "Hash" || name == "Proc" || name == "StringIO" || name == "Fiber"767-
return 1768-
end769-
0770-
end771-
772764
def const_namespace_exists(name)773765
if name == ""774766
return 0@@ -782,13 +774,13 @@
782774
if module_name_exists(name) == 1783775
return 1784776
end785-
if builtin_const_root_name(name) == 1786-
return 1787-
end788777
0789778
end790779
791780
def current_lexical_scope_name781+
if @current_lexical_scope != ""782+
return @current_lexical_scope783+
end792784
if @current_class_idx >= 0793785
if @current_class_idx < @cls_names.length794786
return @cls_names[@current_class_idx]@@ -1165,6 +1157,10 @@
11651157
if ci >= 011661158
return @const_types[ci]11671159
end1160+
cx = find_class_idx(cpname)1161+
if cx >= 01162+
return "class_" + cpname1163+
end11681164
end11691165
parent = @nd_receiver[nid]11701166
if parent >= 0@@ -3577,17 +3573,22 @@
35773573
end35783574
ct = "int"35793575
if expr_id >= 03576+
old_scope = @current_lexical_scope3577+
@current_lexical_scope = scope_name35803578
ct = infer_type(expr_id)3579+
@current_lexical_scope = old_scope35813580
end35823581
ci = find_const_idx(cname)35833582
if ci >= 035843583
@const_types[ci] = ct35853584
@const_expr_ids[ci] = expr_id3585+
@const_scope_names[ci] = scope_name35863586
return35873587
end35883588
@const_names.push(cname)35893589
@const_types.push(ct)35903590
@const_expr_ids.push(expr_id)3591+
@const_scope_names.push(scope_name)35913592
end35923593
35933594
def collect_class_with_prefix(nid, module_prefix)@@ -4598,6 +4599,7 @@
45984599
@const_names.push(cname2)45994600
@const_types.push(ct)46004601
@const_expr_ids.push(expr_id)4602+
@const_scope_names.push(mname)46014603
end46024604
}46034605
end@@ -11289,7 +11291,14 @@
1128911291
# Constants (initialize global declarations)1129011292
i = 01129111293
while i < @const_names.length11294+
old_scope = @current_lexical_scope11295+
if i < @const_scope_names.length11296+
@current_lexical_scope = @const_scope_names[i]11297+
else11298+
@current_lexical_scope = ""11299+
end1129211300
val = compile_expr(@const_expr_ids[i])11301+
@current_lexical_scope = old_scope1129311302
emit(" cst_" + @const_names[i] + " = " + val + ";")1129411303
if type_is_pointer(@const_types[i]) == 11129511304
emit(" SP_GC_ROOT(cst_" + @const_names[i] + ");")test/constants.rbmodifiedView file
Loading diff…