Skip to content

Commit 2e179c9

Browse files
committed
get to a working REPL with closure redesign
see discussion in #11452 [ci skip]
1 parent 6472a57 commit 2e179c9

13 files changed

+309
-28
lines changed

base/LineEdit.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ end
317317
# Edit functionality
318318
is_non_word_char(c) = c in " \t\n\"\\'`@\$><=:;|&{}()[].,+-*/?%^~"
319319

320-
function reset_key_repeats(f::Function, s::MIState)
320+
function reset_key_repeats(f, s::MIState)
321321
key_repeats_sav = s.key_repeats
322322
try
323323
s.key_repeats = 0
@@ -747,7 +747,7 @@ immutable KeyAlias
747747
KeyAlias(seq) = new(normalize_key(seq))
748748
end
749749

750-
match_input(k::Function, s, term, cs, keymap) = (update_key_repeats(s, cs); return keymap_fcn(k, s, ByteString(cs)))
750+
match_input(k, s, term, cs, keymap) = (update_key_repeats(s, cs); return keymap_fcn(k, s, ByteString(cs)))
751751
match_input(k::Void, s, term, cs, keymap) = (s,p) -> return :ok
752752
match_input(k::KeyAlias, s, term, cs, keymap) = match_input(keymap, s, IOBuffer(k.seq), Char[], keymap)
753753
function match_input(k::Dict, s, term=terminal(s), cs=Char[], keymap = k)
@@ -762,7 +762,7 @@ function match_input(k::Dict, s, term=terminal(s), cs=Char[], keymap = k)
762762
end
763763

764764
keymap_fcn(f::Void, s, c) = (s, p) -> return :ok
765-
function keymap_fcn(f::Function, s, c)
765+
function keymap_fcn(f, s, c)
766766
return (s, p) -> begin
767767
r = f(s, p, c)
768768
if isa(r, Symbol)
@@ -1102,7 +1102,7 @@ function reset_state(s::PrefixSearchState)
11021102
end
11031103
end
11041104

1105-
function transition(f::Function, s::PrefixSearchState, mode)
1105+
function transition(f, s::PrefixSearchState, mode)
11061106
if isdefined(s,:mi)
11071107
transition(f,s.mi,mode)
11081108
end
@@ -1532,7 +1532,7 @@ activate(m::ModalInterface, s::MIState, termbuf, term::TextTerminal) =
15321532
activate(s.current_mode, s, termbuf, term)
15331533

15341534
commit_changes(t::UnixTerminal, termbuf) = write(t, takebuf_array(termbuf.out_stream))
1535-
function transition(f::Function, s::MIState, mode)
1535+
function transition(f, s::MIState, mode)
15361536
if mode == :abort
15371537
s.aborted = true
15381538
return

base/base.jl

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ function finalizer(o::ANY, f::Union{Function,Ptr})
7676
end
7777
ccall(:jl_gc_add_finalizer, Void, (Any,Any), o, f)
7878
end
79+
finalizer(o::ANY, f::ANY) = finalizer(o, eval(:(o->($f)(o))))
7980

8081
finalize(o::ANY) = ccall(:jl_finalize, Void, (Any,), o)
8182

base/boot.jl

+2
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ _new(:TopNode, :Symbol)
296296
_new(:NewvarNode, :Symbol)
297297
_new(:QuoteNode, :ANY)
298298
_new(:GenSym, :Int)
299+
_new(:Box, :ANY)
300+
eval(:(Core.call(::Type{Box}) = $(Expr(:new, :Box))))
299301
eval(:(Core.call(::Type{LineNumberNode}, f::Symbol, l::Int) = $(Expr(:new, :LineNumberNode, :f, :l))))
300302
eval(:(Core.call(::Type{GlobalRef}, m::Module, s::Symbol) = $(Expr(:new, :GlobalRef, :m, :s))))
301303

base/client.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ end
132132
syntax_deprecation_warnings(warn::Bool) =
133133
ccall(:jl_parse_depwarn, Cint, (Cint,), warn) == 1
134134

135-
function syntax_deprecation_warnings(f::Function, warn::Bool)
135+
function syntax_deprecation_warnings(f, warn::Bool)
136136
prev = syntax_deprecation_warnings(warn)
137137
try
138138
f()

base/essentials.jl

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ call(T::Type{LineNumberNode}, f::Symbol, n::Int) = Core.call(T, f, n)
4545
call(T::Type{LabelNode}, n::Int) = Core.call(T, n)
4646
call(T::Type{GotoNode}, n::Int) = Core.call(T, n)
4747
call(T::Type{QuoteNode}, x::ANY) = Core.call(T, x)
48+
call(T::Type{Box}, x::ANY) = Core.call(T, x)
49+
call(T::Type{Box}) = Core.call(T)
4850
call(T::Type{NewvarNode}, s::Symbol) = Core.call(T, s)
4951
call(T::Type{TopNode}, s::Symbol) = Core.call(T, s)
5052
call(T::Type{Module}, args...) = Core.call(T, args...)

base/inference.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ const n_ifunc = reinterpret(Int32,arraylen)+1
117117
const t_ifunc = Array{Tuple{Int,Int,Function},1}(n_ifunc)
118118
const t_ffunc_key = Array{Function,1}(0)
119119
const t_ffunc_val = Array{Tuple{Int,Int,Function},1}(0)
120-
function add_tfunc(f::IntrinsicFunction, minarg::Int, maxarg::Int, tfunc::Function)
120+
function add_tfunc(f::IntrinsicFunction, minarg::Int, maxarg::Int, tfunc::ANY)
121121
t_ifunc[reinterpret(Int32,f)+1] = (minarg, maxarg, tfunc)
122122
end
123-
function add_tfunc(f::Function, minarg::Int, maxarg::Int, tfunc::Function)
123+
function add_tfunc(f::Function, minarg::Int, maxarg::Int, tfunc::ANY)
124124
push!(t_ffunc_key, f)
125125
push!(t_ffunc_val, (minarg, maxarg, tfunc))
126126
end

base/iostream.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,14 @@ function takebuf_raw(s::IOStream)
200200
return buf, sz
201201
end
202202

203-
function sprint(size::Integer, f::Function, args...)
203+
function sprint(size::Integer, f, args...)
204204
s = IOBuffer(Array(UInt8,size), true, true)
205205
truncate(s,0)
206206
f(s, args...)
207207
takebuf_string(s)
208208
end
209209

210-
sprint(f::Function, args...) = sprint(0, f, args...)
210+
sprint(f, args...) = sprint(0, f, args...)
211211

212212
write(x) = write(STDOUT::IO, x)
213213

base/sysimg.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,11 @@ using .Docs
290290
using .Markdown
291291

292292
# deprecated functions
293-
include("deprecated.jl")
293+
#include("deprecated.jl")
294294

295295
# Some basic documentation
296-
include("docs/helpdb.jl")
297-
include("docs/basedocs.jl")
296+
#include("docs/helpdb.jl")
297+
#include("docs/basedocs.jl")
298298

299299
# threads
300300
include("threads.jl")
@@ -309,7 +309,7 @@ function __init__()
309309
end
310310

311311
include = include_from_node1
312-
include("precompile.jl")
312+
#include("precompile.jl")
313313

314314
end # baremodule Base
315315

base/task.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## basic task functions and TLS
44

55
# allow tasks to be constructed with arbitrary function objects
6-
Task(f) = Task(()->f())
6+
Task(f) = Task(@eval (()->($f)()))
77

88
function show(io::IO, t::Task)
99
print(io, "Task ($(t.state)) @0x$(hex(convert(UInt, pointer_from_objref(t)), WORD_SIZE>>2))")

base/tuple.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ eltype{T,_}(::Type{NTuple{_,T}}) = T
4141

4242
## mapping ##
4343

44-
ntuple(f::Function, n::Integer) =
44+
ntuple(f, n::Integer) =
4545
n<=0 ? () :
4646
n==1 ? (f(1),) :
4747
n==2 ? (f(1),f(2),) :

base/util.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ end
307307

308308
## printing with color ##
309309

310-
function with_output_color(f::Function, color::Symbol, io::IO, args...)
310+
function with_output_color(f, color::Symbol, io::IO, args...)
311311
buf = IOBuffer()
312312
have_color && print(buf, get(text_colors, color, color_normal))
313313
try f(buf, args...)

src/jlfrontend.scm

+30-5
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
`(incomplete ,msg)
1919
e))
2020
(begin
21-
;;(newline)
22-
;;(display "unexpected error: ")
23-
;;(prn e)
24-
;;(print-stack-trace (stacktrace))
21+
(newline)
22+
(display "unexpected error: ")
23+
(prn e)
24+
(print-stack-trace (stacktrace))
2525
'(error "malformed expression"))))
2626
thk))
2727

@@ -103,8 +103,33 @@
103103
(pair? (cadr e)) (eq? (caadr e) '=) (symbol? (cadadr e))
104104
(eq? (cadr (caddr e)) (cadadr e))))
105105

106+
(define (lift-toplevel- e)
107+
(if (atom? e) (cons e '())
108+
(let* ((rec (map lift-toplevel- e))
109+
(e2 (map car rec))
110+
(tl (apply append (map cdr rec))))
111+
(if (eq? (car e) 'toplevel-butlast)
112+
(cons (last e2) (append tl (butlast (cdr e2))))
113+
(cons e2 tl)))))
114+
115+
(define (lift-toplevel x)
116+
(if (and (pair? x) (memq (car x) '(toplevel body)))
117+
(cons (car x)
118+
(apply append (map (lambda (e)
119+
(let ((e (lift-toplevel e)))
120+
(if (and (pair? e) (eq? (car e) 'toplevel))
121+
(cdr e)
122+
(list e))))
123+
(cdr x))))
124+
(let ((e (lift-toplevel- x)))
125+
(if (null? (cdr e))
126+
(car e)
127+
(if (and (pair? (car e)) (eq? (caar e) 'toplevel))
128+
`(toplevel ,@(cdr e) ,@(cdar e))
129+
`(toplevel ,@(cdr e) ,(car e)))))))
130+
106131
(define (expand-toplevel-expr- e)
107-
(let ((ex (expand-toplevel-expr-- e)))
132+
(let ((ex (lift-toplevel (expand-toplevel-expr-- e))))
108133
(cond ((contains (lambda (x) (equal? x '(top ccall))) ex) ex)
109134
((simple-assignment? ex) (cadr ex))
110135
((and (length= ex 2) (eq? (car ex) 'body))

0 commit comments

Comments
 (0)