Skip to content

Commit ed6ba9e

Browse files
mlechuaviatesk
authored andcommitted
Change two-argument IR "const" to K"constdecl"
Differentiate it from AST K"const"
1 parent aa4b2ae commit ed6ba9e

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed

src/desugaring.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ function expand_unionall_def(ctx, srcref, lhs, rhs, is_const=true)
11871187
@ast ctx srcref [
11881188
K"block"
11891189
[K"=" rr [K"where" rhs lhs[2:end]...]]
1190-
[is_const ? K"const" : K"assign_const_if_global" name rr]
1190+
[is_const ? K"constdecl" : K"assign_const_if_global" name rr]
11911191
[K"latestworld_if_toplevel"]
11921192
rr
11931193
]
@@ -1246,7 +1246,7 @@ function expand_assignment(ctx, ex, is_const=false)
12461246
@ast ctx ex [
12471247
K"block"
12481248
sink_assignment(ctx, ex, rr, expand_forms_2(ctx, rhs))
1249-
[K"const" lhs rr]
1249+
[K"constdecl" lhs rr]
12501250
[K"latestworld"]
12511251
[K"removable" rr]
12521252
]
@@ -1290,7 +1290,7 @@ function expand_assignment(ctx, ex, is_const=false)
12901290
T = lhs[2]
12911291
res = if is_const
12921292
expand_forms_2(ctx, ex, @ast ctx ex [
1293-
K"const"
1293+
K"constdecl"
12941294
lhs[1]
12951295
convert_for_type_decl(ctx, ex, rhs, T, true)
12961296
])
@@ -3434,7 +3434,7 @@ function expand_abstract_or_primitive_type(ctx, ex)
34343434
[K"call" "_equiv_typedef"::K"core" name newtype_var]
34353435
]
34363436
nothing_(ctx, ex)
3437-
[K"const" name newtype_var]
3437+
[K"constdecl" name newtype_var]
34383438
]
34393439
[K"latestworld"]
34403440
nothing_(ctx, ex)
@@ -3988,7 +3988,7 @@ function expand_struct_def(ctx, ex, docs)
39883988
newtype_var
39893989
[K"call" "svec"::K"core" field_types...]
39903990
]
3991-
[K"const"
3991+
[K"constdecl"
39923992
global_struct_name
39933993
newtype_var
39943994
]

src/eval.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ function to_lowered_expr(mod, ex, ssa_offset=0)
297297
k == K"splatnew" ? :splatnew :
298298
k == K"=" ? :(=) :
299299
k == K"global" ? :global :
300-
k == K"const" ? :const :
300+
k == K"constdecl" ? :const :
301301
k == K"leave" ? :leave :
302302
k == K"isdefined" ? :isdefined :
303303
k == K"latestworld" ? :latestworld :

src/kinds.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ function _register_kinds()
124124
# References/declares a global variable within a module
125125
"globalref"
126126
"globaldecl"
127+
# Two-argument constant declaration and assignment.
128+
# Translated to :const in the IR for now (we use K"const" already in parsing).
129+
"constdecl"
127130
# Unconditional goto
128131
"goto"
129132
# Conditional goto

src/linear_ir.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ function emit_break(ctx, ex)
325325
emit_jump(ctx, ex, target)
326326
end
327327

328-
# `op` may also be K"const"
328+
# `op` may also be K"constdecl"
329329
function emit_assignment_or_setglobal(ctx, srcref, lhs, rhs, op=K"=")
330330
# (const (globalref _ _) _) does not use setglobal!
331331
binfo = lookup_binding(ctx, lhs.var_id)
@@ -648,8 +648,8 @@ function compile(ctx::LinearIRContext, ex, needs_value, in_tail_pos)
648648
emit(ctx, callex)
649649
nothing
650650
end
651-
elseif k == K"=" || k == K"const"
652-
if k == K"const"
651+
elseif k == K"=" || k == K"constdecl"
652+
if k == K"constdecl"
653653
check_no_local_bindings(ctx, ex[1], "unsupported `const` declaration on local variable")
654654
# other errors (probably this one too) should be handled in previous passes
655655
end

src/scope_analysis.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ function _resolve_scopes(ctx, ex::SyntaxTree)
571571
if bk == :local && numchildren(ex) != 1
572572
@ast ctx ex _resolve_scopes(ctx, [K"=" children(ex)...])
573573
elseif bk != :local # TODO: should this be == :global?
574-
@ast ctx ex _resolve_scopes(ctx, [K"const" children(ex)...])
574+
@ast ctx ex _resolve_scopes(ctx, [K"constdecl" children(ex)...])
575575
else
576576
makeleaf(ctx, ex, K"TOMBSTONE")
577577
end
@@ -656,7 +656,7 @@ function analyze_variables!(ctx, ex)
656656
elseif k == K"local" || k == K"global"
657657
# Presence of BindingId within local/global is ignored.
658658
return
659-
elseif k == K"=" || k == K"const"
659+
elseif k == K"="
660660
lhs = ex[1]
661661
if kind(lhs) != K"Placeholder"
662662
update_binding!(ctx, lhs, add_assigned=1)
@@ -684,7 +684,7 @@ function analyze_variables!(ctx, ex)
684684
if kind(ex[1]) != K"BindingId" || lookup_binding(ctx, ex[1]).kind !== :local
685685
analyze_variables!(ctx, ex[1])
686686
end
687-
elseif k == K"const"
687+
elseif k == K"constdecl"
688688
id = ex[1]
689689
if lookup_binding(ctx, id).kind == :local
690690
throw(LoweringError(ex, "unsupported `const` declaration on local variable"))

0 commit comments

Comments
 (0)