Skip to content

Commit

Permalink
replace hard tabs with soft tabs (tests passed)
Browse files Browse the repository at this point in the history
  • Loading branch information
lindahua committed Mar 6, 2013
1 parent 7fceb22 commit f22b7d7
Show file tree
Hide file tree
Showing 14 changed files with 1,337 additions and 1,337 deletions.
66 changes: 33 additions & 33 deletions src/Devectorize.jl
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
module Devectorize

export
# fun_traits
TFun,
TCallSig,
result_type,
sqr, rcp, blend,

# texpr

DeError,

TExpr, TEWise, TScalar, TGeneralVar, TFunCall,
TEmpty, TNum, TScalarVar, TVar, TQVar, TGeneralScalar,
TRef, TIndex, TRange, TColon, TInterval,
TGeneralRef1, TGeneralRef2, TRef1D, TRef2D, TRefRow, TRefCol,
TMap, TReduc, TColwiseReduc, TRowwiseReduc,
TLValue, TRValue, TAssign, TBlock,

texpr, tnum, tscalarvar, tvar, tqvar,
tref, tcall, tassign, topassign, tblock,
is_trivial_assignment, ju_expr,

tmode, ScalarMode, EWiseMode, ReducMode,
ColwiseReducMode, RowwiseReducMode,

# scalar_backend

ScalarContext, dump_devec,
compile, @devec, @inspect_devec,
# extensions
@devec_transform
# fun_traits
TFun,
TCallSig,
result_type,
sqr, rcp, blend,

# texpr

DeError,

TExpr, TEWise, TScalar, TGeneralVar, TFunCall,
TEmpty, TNum, TScalarVar, TVar, TQVar, TGeneralScalar,
TRef, TIndex, TRange, TColon, TInterval,
TGeneralRef1, TGeneralRef2, TRef1D, TRef2D, TRefRow, TRefCol,
TMap, TReduc, TColwiseReduc, TRowwiseReduc,
TLValue, TRValue, TAssign, TBlock,

texpr, tnum, tscalarvar, tvar, tqvar,
tref, tcall, tassign, topassign, tblock,
is_trivial_assignment, ju_expr,

tmode, ScalarMode, EWiseMode, ReducMode,
ColwiseReducMode, RowwiseReducMode,

# scalar_backend

ScalarContext, dump_devec,
compile, @devec, @inspect_devec,

# extensions

@devec_transform

import Base.==, Base.!=

Expand Down
128 changes: 64 additions & 64 deletions src/compile_base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
#
# Types to express evaluation contexts
#
# A context refers to a specific configuration of the back-end,
# which can be scalar code, SIMD, CUDA, etc, or even hybrid of them.
# A context refers to a specific configuration of the back-end,
# which can be scalar code, SIMD, CUDA, etc, or even hybrid of them.
#
# I organize types into a hierarchy, which may simplify later
# implementation.
# I organize types into a hierarchy, which may simplify later
# implementation.
#
# Here, most contexts are empty types. In practice, it is ok to have
# some information contained in the context
# (e.g. the capability version of CUDA may be useful for code-gen)
# Here, most contexts are empty types. In practice, it is ok to have
# some information contained in the context
# (e.g. the capability version of CUDA may be useful for code-gen)
#
##########################################################################

Expand All @@ -31,80 +31,80 @@ abstract OffshoreContext <: EvalContext
##########################################################################

function compile(ctx::EvalContext, top_expr::Expr)
# generate codes given an expression

h = top_expr.head
if h == :(=) || is_opassign(h) || h == :(block)
te = texpr(top_expr)
compile(ctx, te)
elseif h == :(*=)
throw(DeError("Devectorize does not support *=, please use .*= for element-wise multiplication."))
elseif h == :(/=)
throw(DeError("Devectorize does not support /=, please use ./= for element-wise division."))
else
throw(DeError("Top level expression must be either an assignment, op-assignment, or a block."))
end
# generate codes given an expression

h = top_expr.head
if h == :(=) || is_opassign(h) || h == :(block)
te = texpr(top_expr)
compile(ctx, te)
elseif h == :(*=)
throw(DeError("Devectorize does not support *=, please use .*= for element-wise multiplication."))
elseif h == :(/=)
throw(DeError("Devectorize does not support /=, please use ./= for element-wise division."))
else
throw(DeError("Top level expression must be either an assignment, op-assignment, or a block."))
end
end


function add_deps_to_queue(q::Array{TExpr, 1}, ex::TExpr)
if isa(ex, TFunCall)
for a in ex.args
add_deps_to_queue(q, a)
end
if ex.deps != nothing && !isempty(ex.deps)
for d in ex.deps
add_deps_to_queue(q, d)
push!(q, d)
end
end
elseif isa(ex, TAssign)
add_deps_to_queue(q, ex.rhs)
end
if isa(ex, TFunCall)
for a in ex.args
add_deps_to_queue(q, a)
end
if ex.deps != nothing && !isempty(ex.deps)
for d in ex.deps
add_deps_to_queue(q, d)
push!(q, d)
end
end
elseif isa(ex, TAssign)
add_deps_to_queue(q, ex.rhs)
end
end

function compile(ctx::EvalContext, top_expr::TAssign)
dep_queue = TExpr[]
add_deps_to_queue(dep_queue, top_expr)

if isempty(dep_queue)
lhs = top_expr.lhs
rhs = top_expr.rhs

if is_trivial_assignment(top_expr)
code_block( assignment(ju_expr(lhs), ju_expr(rhs)) )

elseif isa(lhs, TGeneralVar)
# to ensure no alias between left and right hand side
tmp = gensym("tmp")
safe_expr = tassign(tvar(tmp), rhs)
flatten_code_block(
code_block(compile(ctx, tmode(safe_expr), safe_expr)),
assignment(ju_expr(lhs), tmp) )

else
compile(ctx, tmode(top_expr), top_expr)
end
else
push!(dep_queue, top_expr)
codes = [compile(ctx, tmode(e), e) for e in dep_queue]
code_block(codes...)
end
dep_queue = TExpr[]
add_deps_to_queue(dep_queue, top_expr)

if isempty(dep_queue)
lhs = top_expr.lhs
rhs = top_expr.rhs

if is_trivial_assignment(top_expr)
code_block( assignment(ju_expr(lhs), ju_expr(rhs)) )

elseif isa(lhs, TGeneralVar)
# to ensure no alias between left and right hand side
tmp = gensym("tmp")
safe_expr = tassign(tvar(tmp), rhs)
flatten_code_block(
code_block(compile(ctx, tmode(safe_expr), safe_expr)),
assignment(ju_expr(lhs), tmp) )

else
compile(ctx, tmode(top_expr), top_expr)
end
else
push!(dep_queue, top_expr)
codes = [compile(ctx, tmode(e), e) for e in dep_queue]
code_block(codes...)
end
end

#####################################################################
#
# Note: the following function:
# Note: the following function:
#
# compile(ctx, mode, assign_ex)
# compile(ctx, mode, assign_ex)
#
# should be provided by the back-end
# should be provided by the back-end
#
#####################################################################


function compile(ctx::EvalContext, ex::TBlock)
codes = [compile(ctx, s) for s in ex.stmts]
code_block(codes...)
codes = [compile(ctx, s) for s in ex.stmts]
code_block(codes...)
end

20 changes: 10 additions & 10 deletions src/extensions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

##########################################################################
#
# @devec_transform - a code-generating macro for associative types
# @devec_transform - a code-generating macro for associative types
#
# Note: this extension was contributed by Tom Short
# Note: this extension was contributed by Tom Short
#
##########################################################################
#
Expand All @@ -24,15 +24,15 @@
# It contains machinery to convert the symbol to a key type
# appropriate for the associative type. For example, DataFrames have
# string keys, so the symbol from the expression needs to be
# converted to a string. Also of issue is
# converted to a string. Also of issue is
#
# The following forms are supported:
#
# @devec_transform d a = x + y b = x + sum(y)
#
# @devec_transform(d, a => x + y, b => x + sum(y))
#
#
#
##########################################################################


Expand All @@ -41,15 +41,15 @@
xhas(d, key) = has(d, key)
xhas{K<:String,V}(d::Associative{K,V}, key) = has(d, string(key))

# The appropriate key for the type
# The appropriate key for the type
bestkey(d, key) = key
bestkey{K<:String,V}(d::Associative{K,V}, key) = string(key)

#### The following will be needed in package DataFrames for support
#
# xhas(d::AbstractDataFrame, key::Symbol) = has(d, string(key))
# bestkey(d::AbstractDataFrame, key) = string(key)
# bestkey(d::NamedArray, key) = string(key)
# xhas(d::AbstractDataFrame, key::Symbol) = has(d, string(key))
# bestkey(d::AbstractDataFrame, key) = string(key)
# bestkey(d::NamedArray, key) = string(key)
#

# This replaces symbols with gensym'd versions and updates
Expand Down Expand Up @@ -88,8 +88,8 @@ function devec_transform_helper(d, args...)
# header
header = Any[]
for (s,v) in var_lookup
push!(header, :($v = Devectorize.xhas(d, Devectorize.bestkey(d, $(Meta.quot(s)))) ?
d[Devectorize.bestkey(d, $(Meta.quot(s)))] : isdefined($(Meta.quot(s))) ? $s : nothing))
push!(header, :($v = Devectorize.xhas(d, Devectorize.bestkey(d, $(Meta.quot(s)))) ?
d[Devectorize.bestkey(d, $(Meta.quot(s)))] : isdefined($(Meta.quot(s))) ? $s : nothing))
end
# trailer
trailer = Any[]
Expand Down
Loading

0 comments on commit f22b7d7

Please sign in to comment.