Browse files

say goodbye to tuple comprehensions

better to reserve that syntax for something else

also update compile hints
  • Loading branch information...
1 parent 65a1f3d commit 71d75fb7d423d8cb960cbc89542051eb8a3709a1 @JeffBezanson JeffBezanson committed Oct 7, 2012
Showing with 19 additions and 23 deletions.
  1. +6 −5 base/inference.jl
  2. +1 −1 base/operators.jl
  3. +8 −1 base/sysimg.jl
  4. +4 −4 base/tuple.jl
  5. +0 −4 src/julia-parser.scm
  6. +0 −8 src/julia-syntax.scm
View
11 base/inference.jl
@@ -585,7 +585,7 @@ end
function abstract_eval_call(e, vtypes, sv::StaticVarInfo)
fargs = e.args[2:]
- argtypes = (abstract_eval(fargs[i],vtypes,sv) for i=1:length(fargs))
+ argtypes = tuple([abstract_eval(a, vtypes, sv) for a in fargs]...)
if anyp(x->is(x,None), argtypes)
return None
end
@@ -1279,7 +1279,7 @@ function type_annotate(ast::Expr, states::Array{Any,1}, sv::ANY, rettype::ANY,
end
end
na = length(a.args[1])
- typeinf(li, (i>na ? (Tuple)[1] : Any for i=1:na+1),
+ typeinf(li, ntuple(na+1, i->(i>na ? (Tuple)[1] : Any)),
li.sparams, li, false)
end
end
@@ -1440,7 +1440,7 @@ function inlineable(f, e::Expr, sv, enclosing_ast)
return NF
end
argexprs = e.args[2:]
- atypes = limit_tuple_type((exprtype(ae) for ae in argexprs))
+ atypes = limit_tuple_type(tuple(map(exprtype, argexprs)...))
if is(f, convert_default) && length(atypes)==3
# builtin case of convert. convert(T,x::S) => x, when S<:T
@@ -1565,7 +1565,7 @@ function mk_tupleref(texpr, i)
end
function mk_tuplecall(args)
- Expr(:call1, {_jl_top_tuple, args...}, (exprtype(a) for a in args))
+ Expr(:call1, {_jl_top_tuple, args...}, tuple(map(exprtype, args)...))
end
function inlining_pass(e::Expr, sv, ast)
@@ -1700,7 +1700,8 @@ function add_variable(ast, name, typ)
push(vinflist, vinf)
end
-const some_names = {:_var0, :_var1, :_var2, :_var3, :_var4, :_var5, :_var6}
+const some_names = {:_var0, :_var1, :_var2, :_var3, :_var4, :_var5, :_var6,
+ :_var7, :_var8, :_var9, :_var10, :_var11, :_var12}
function unique_name(ast)
locllist = ast.args[2][1]::Array{Any,1}
View
2 base/operators.jl
@@ -180,7 +180,7 @@ end
function ref_shape(I...)
n = length(I)
while n > 0 && isa(I[n],Real); n-=1; end
- (length(I[i]) for i=1:n)
+ tuple([length(I[i]) for i=1:n]...)
end
ref_shape(i::Real) = ()
View
9 base/sysimg.jl
@@ -225,12 +225,13 @@ compile_hint(static_convert, (Nothing, Nothing))
compile_hint(assign, (Array{Any,1}, WeakRef, Int))
compile_hint(assign, (Dict{Any,Any}, WorkItem, (Int,Int)))
compile_hint(isequal, ((Int,Int),(Int,Int)))
+compile_hint(isequal, (Int,Int))
compile_hint(RemoteRef, (Int, Int, Int))
compile_hint(_jl_eval_user_input, (Expr, Bool))
compile_hint(print, (Float64,))
compile_hint(a2t, (Array{Any,1},))
compile_hint(flush, (IOStream,))
-compile_hint(ref, (Type{String}, ASCIIString, ASCIIString, ASCIIString))
+compile_hint(ref, (Type{String}, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString))
compile_hint(int, (Int,))
compile_hint(uint, (Uint,))
compile_hint(_atexit, ())
@@ -252,6 +253,12 @@ compile_hint(CallStack, (Expr, Module, (Nothing,), EmptyCallStack))
compile_hint(convert, (Type{Module}, Module))
compile_hint(effect_free, (Expr,))
compile_hint(effect_free, (TopNode,))
+compile_hint(abs_path, (ASCIIString,))
+compile_hint(isrooted, (ASCIIString,))
+compile_hint(split, (ASCIIString,))
+compile_hint(split, (ASCIIString, ASCIIString, Int, Bool))
+compile_hint(print_joined, (IOStream, Array{String,1}, ASCIIString))
+compile_hint(begins_with, (ASCIIString, ASCIIString))
# invoke type inference, running the existing inference code on the new
# inference code to cache an optimized version of it.
View
8 base/tuple.jl
@@ -4,7 +4,7 @@ length(t::Tuple) = tuplelen(t)
size(t::Tuple, d) = d==1 ? tuplelen(t) : error("invalid tuple dimension")
ref(t::Tuple, i::Int) = tupleref(t, i)
ref(t::Tuple, i::Integer) = tupleref(t, int(i))
-ref(t::Tuple, r::Ranges) = (t[ri] for ri in r)
+ref(t::Tuple, r::Ranges) = tuple([t[ri] for ri in r]...)
## iterating ##
@@ -30,7 +30,7 @@ map(f, t::(Any,)) = (f(t[1]),)
map(f, t::(Any, Any)) = (f(t[1]), f(t[2]))
map(f, t::(Any, Any, Any)) = (f(t[1]), f(t[2]), f(t[3]))
map(f, t::(Any, Any, Any, Any)) = (f(t[1]), f(t[2]), f(t[3]), f(t[4]))
-map(f, t::Tuple) = (f(ti) for ti in t)
+map(f, t::Tuple) = tuple([f(ti) for ti in t]...)
# 2 argument function
map(f, t::(), s::()) = ()
map(f, t::(Any,), s::(Any,)) = (f(t[1],s[1]),)
@@ -40,7 +40,7 @@ map(f, t::(Any,Any,Any), s::(Any,Any,Any)) =
map(f, t::(Any,Any,Any,Any), s::(Any,Any,Any,Any)) =
(f(t[1],s[1]), f(t[2],s[2]), f(t[3],s[3]), f(t[4],s[4]))
# n argument function
-map(f, ts::Tuple...) = (f(map(t->t[n],ts)...) for n=1:length_checked_equal(ts...))
+map(f, ts::Tuple...) = tuple([f(map(t->t[n],ts)...) for n=1:length_checked_equal(ts...)]...)
function length_checked_equal(args...)
n = length(args[1])
@@ -82,4 +82,4 @@ end
isempty(x::()) = true
isempty(x::Tuple) = false
-reverse(x::Tuple) = (n=length(x); (x[n-k+1] for k=1:n))
+reverse(x::Tuple) = (n=length(x); tuple([x[n-k+1] for k=1:n]...))
View
4 src/julia-parser.scm
@@ -1324,10 +1324,6 @@
(error "unexpected line break in tuple"))
((memv t '(#\] #\}))
(error (string "unexpected " t " in tuple")))
- ((eq? t 'for)
- (take-token s)
- (cons 'tuple-comprehension
- (cdr (parse-comprehension s ex #\) ))))
(else
(error "missing separator in tuple")))))))))
View
8 src/julia-syntax.scm
@@ -1193,14 +1193,6 @@
,(construct-loops (reverse ranges) (reverse rs))
,result)))))
- ;; tuple comprehension
- (pattern-lambda
- (tuple-comprehension expr . ranges)
- (begin (if (not (length= ranges 1))
- (error "tuple comprehension must have exactly one range"))
- `(call (top tuple)
- (... (comprehension ,expr ,@ranges)))))
-
)) ;; lower-comprehensions

1 comment on commit 71d75fb

@StefanKarpinski
The Julia Language member

Shortest-lived Julia syntax yet.

Please sign in to comment.