Skip to content

Commit

Permalink
add types for return, assign, gotoifnot
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Feb 25, 2016
1 parent ea92526 commit 1061f1d
Show file tree
Hide file tree
Showing 13 changed files with 513 additions and 339 deletions.
19 changes: 18 additions & 1 deletion base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@
# name::Symbol
#end

#immutable ReturnNode
# expr
#end

#immutable AssignNode
# lhs
# rhs
#end

#immutable GotoIfNotNode
# cond
# label::Int
#end

# type Task
# parent::Task
# storage::Any
Expand Down Expand Up @@ -140,7 +154,7 @@ export
StackOverflowError, SegmentationFault, UndefRefError, UndefVarError, TypeError,
# AST representation
Expr, GotoNode, LabelNode, LineNumberNode, QuoteNode, TopNode,
GlobalRef, NewvarNode, GenSym, Slot,
GlobalRef, NewvarNode, GenSym, Slot, ReturnNode, AssignNode, GotoIfNotNode,
# object model functions
fieldtype, getfield, setfield!, nfields, throw, tuple, is, ===, isdefined, eval,
# arrayref, arrayset, arraysize,
Expand Down Expand Up @@ -308,6 +322,9 @@ eval(:((::Type{LineNumberNode})(f::Symbol, l::Int) = $(Expr(:new, :LineNumberNod
eval(:((::Type{GlobalRef})(m::Module, s::Symbol) = $(Expr(:new, :GlobalRef, :m, :s))))
eval(:((::Type{Slot})(n::Int) = $(Expr(:new, :Slot, :n, Any))))
eval(:((::Type{Slot})(n::Int, t::ANY) = $(Expr(:new, :Slot, :n, :t))))
eval(:((::Type{ReturnNode})(ex::ANY) = $(Expr(:new, :ReturnNode, :ex))))
eval(:((::Type{AssignNode})(l::ANY, r::ANY) = $(Expr(:new, :AssignNode, :l, :r))))
eval(:((::Type{GotoIfNotNode})(cond::ANY, label::Int) = $(Expr(:new, :GotoIfNotNode, :cond, :label))))

Module(name::Symbol=:anonymous, std_imports::Bool=true) = ccall(:jl_f_new_module, Any, (Any, Bool), name, std_imports)::Module

Expand Down
5 changes: 4 additions & 1 deletion base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ copy(e::Expr) = (n = Expr(e.head);
n.typ = e.typ;
n)
copy(s::Slot) = Slot(s.id, s.typ)
copy(x::AssignNode) = AssignNode(astcopy(x.lhs), astcopy(x.rhs))
copy(x::ReturnNode) = ReturnNode(astcopy(x.expr))
copy(x::GotoIfNotNode) = GotoIfNotNode(astcopy(x.cond), x.label)

# copy parts of an AST that the compiler mutates
astcopy(x::Union{Slot,Expr}) = copy(x)
astcopy(x::Union{Slot,Expr,AssignNode,ReturnNode,GotoIfNotNode}) = copy(x)
astcopy(x::Array{Any,1}) = Any[astcopy(a) for a in x]
astcopy(x) = x

Expand Down
Loading

0 comments on commit 1061f1d

Please sign in to comment.