Skip to content

Commit

Permalink
update to julia v1 syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Oct 16, 2020
1 parent c21a673 commit beec39e
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions dataflow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,38 @@

import Base: convert

abstract Exp
abstract type Exp end

immutable Sym <: Exp
struct Sym <: Exp
name::Symbol
end

immutable Num <: Exp
struct Num <: Exp
val::Int
end

type Call <: Exp
struct Call <: Exp
head::Sym
args::Vector{Exp}
end

abstract Stmt
abstract type Stmt end

type Assign <: Stmt
struct Assign <: Stmt
lhs::Sym
rhs::Exp
end

type Goto <: Stmt
struct Goto <: Stmt
label::Int
end

type GotoIf <: Stmt
struct GotoIf <: Stmt
label::Int
cond::Exp
end

type Ret <: Stmt
end
struct Ret <: Stmt end

convert(::Type{Exp}, s::Symbol) = Sym(s)
convert(::Type{Sym}, s::Symbol) = Sym(s)
Expand All @@ -48,7 +47,7 @@ convert(::Type{Num}, n::Int) = Num(n)

import Base: <=, ==, <, show

abstract LatticeElement
abstract type LatticeElement end

# Note: == and < are defined such that future LatticeElements only
# need to implement <=
Expand All @@ -59,8 +58,8 @@ abstract LatticeElement

<(x::LatticeElement, y::LatticeElement) = x<=y && !(y<=x)

immutable TopElement <: LatticeElement; end
immutable BotElement <: LatticeElement; end
struct TopElement <: LatticeElement end
struct BotElement <: LatticeElement end

const= TopElement()
const= BotElement()
Expand All @@ -87,22 +86,23 @@ show(io::IO, ::BotElement) = print(io, "⊥")

# Note: the paper uses U+1D56E MATHEMATICAL BOLD FRAKTUR CAPITAL C for this
typealias AbstractValue Dict{Symbol,LatticeElement}
const AbstractValue = Dict{Symbol,LatticeElement}

# Here we extend lattices of values to lattices of mappings of variables
# to values. meet and join operate elementwise, and from there we only
# need equality on dictionaries to get <= and <.

(X::AbstractValue, Y::AbstractValue) = [ v => X[v] Y[v] for v in keys(X) ]
(X::AbstractValue, Y::AbstractValue) = [ v => X[v] Y[v] for v in keys(X) ]
(X::AbstractValue, Y::AbstractValue) = AbstractValue( v => X[v] Y[v] for v in keys(X) )
(X::AbstractValue, Y::AbstractValue) = AbstractValue( v => X[v] Y[v] for v in keys(X) )

<=(X::AbstractValue, Y::AbstractValue) = XY == X
< (X::AbstractValue, Y::AbstractValue) = X!=Y && X<=Y
<(X::AbstractValue, Y::AbstractValue) = X<=Y && X!=Y

function max_fixed_point(P::Vector, a₁::AbstractValue, eval)
function max_fixed_point(P::Program, a₁::AbstractValue, eval) where {Program<:AbstractVector{Stmt}}
n = length(P)
bot = AbstractValue([ v =>for v in keys(a₁) ])
bot = AbstractValue( v =>for v in keys(a₁) )
s = [ a₁; [ bot for i = 2:n ] ]
W = IntSet(1)
W = BitSet(1)

while !isempty(W)
pc = first(W)
Expand Down Expand Up @@ -143,7 +143,7 @@ end

# flat lattice of variable definedness

immutable IsDefined <: LatticeElement
struct IsDefined <: LatticeElement
is::Bool
end

Expand Down

0 comments on commit beec39e

Please sign in to comment.