Skip to content

Commit

Permalink
Use id rather than var_id for labels
Browse files Browse the repository at this point in the history
  • Loading branch information
c42f committed Jun 22, 2024
1 parent 33e6c24 commit c298c0f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/ast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ function makeleaf(ctx, srcref, k::Kind, value; kws...)
graph = syntax_graph(ctx)
if k == K"Identifier" || k == K"core" || k == K"top" || k == K"Symbol" || k == K"globalref"
makeleaf(graph, srcref, k; name_val=value, kws...)
elseif k == K"SSAValue" || k == K"label"
# FIXME?
elseif k == K"SSAValue"
makeleaf(graph, srcref, k; var_id=value, kws...)
elseif k == K"label"
makeleaf(graph, srcref, k; id=value, kws...)
else
val = k == K"Integer" ? convert(Int, value) :
k == K"Float" ? convert(Float64, value) :
Expand Down
4 changes: 2 additions & 2 deletions src/eval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ function to_lowered_expr(mod, var_info, ex)
elseif k == K"Value"
ex.value
elseif k == K"goto"
Core.GotoNode(ex[1].var_id)
Core.GotoNode(ex[1].id)
elseif k == K"gotoifnot"
Core.GotoIfNot(to_lowered_expr(mod, var_info, ex[1]), ex[2].var_id)
Core.GotoIfNot(to_lowered_expr(mod, var_info, ex[1]), ex[2].id)
else
# Allowed forms according to https://docs.julialang.org/en/v1/devdocs/ast/
#
Expand Down
11 changes: 6 additions & 5 deletions src/linear_ir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ end
function make_label(ctx, srcref)
id = ctx.next_label_id[]
ctx.next_label_id[] += 1
makeleaf(ctx, srcref, K"label", id)
makeleaf(ctx, srcref, K"label", id=id)
end

# flisp: make&mark-label
Expand Down Expand Up @@ -419,12 +419,12 @@ function _renumber(ctx, ssa_rewrites, slot_rewrites, label_table, ex)
TODO(ex, "_renumber $k")
elseif k == K"goto"
@ast ctx ex [K"goto"
label_table[ex[1].var_id]::K"label"
label_table[ex[1].id]::K"label"
]
elseif k == K"gotoifnot"
@ast ctx ex [K"gotoifnot"
_renumber(ctx, ssa_rewrites, slot_rewrites, label_table, ex[1])
label_table[ex[2].var_id]::K"label"
label_table[ex[2].id]::K"label"
]
elseif k == K"lambda"
ex
Expand Down Expand Up @@ -457,7 +457,7 @@ function renumber_body(ctx, input_code, slot_rewrites)
ex_out = ex[2]
end
elseif k == K"label"
label_table[ex.var_id] = length(code) + 1
label_table[ex.id] = length(code) + 1
else
ex_out = ex
end
Expand Down Expand Up @@ -515,7 +515,8 @@ function linearize_ir(ctx, ex)
graph = ensure_attributes(ctx.graph,
slot_rewrites=Dict{VarId,Int},
var_info=Dict{VarId,VarInfo},
mod=Module)
mod=Module,
id=Int)
# TODO: Cleanup needed - `_ctx` is just a dummy context here. But currently
# required to call reparent() ...
_ctx = LinearIRContext(graph, SyntaxList(graph), ctx.next_var_id,
Expand Down
3 changes: 3 additions & 0 deletions src/syntax_graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,9 @@ function _value_string(ex)
k == K"slot" ? "slot" :
repr(get(ex, :value, nothing))
id = get(ex, :var_id, nothing)
if isnothing(id)
id = get(ex, :id, nothing)
end
if !isnothing(id)
idstr = replace(string(id),
"0"=>"", "1"=>"", "2"=>"", "3"=>"", "4"=>"",
Expand Down

0 comments on commit c298c0f

Please sign in to comment.