Skip to content

Commit

Permalink
get to a working REPL with closure redesign
Browse files Browse the repository at this point in the history
see discussion in #11452

[ci skip]
  • Loading branch information
JeffBezanson committed Dec 15, 2015
1 parent 62f1481 commit 6ed80a4
Show file tree
Hide file tree
Showing 13 changed files with 309 additions and 28 deletions.
10 changes: 5 additions & 5 deletions base/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ end
# Edit functionality
is_non_word_char(c) = c in " \t\n\"\\'`@\$><=:;|&{}()[].,+-*/?%^~"

function reset_key_repeats(f::Function, s::MIState)
function reset_key_repeats(f, s::MIState)
key_repeats_sav = s.key_repeats
try
s.key_repeats = 0
Expand Down Expand Up @@ -747,7 +747,7 @@ immutable KeyAlias
KeyAlias(seq) = new(normalize_key(seq))
end

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

keymap_fcn(f::Void, s, c) = (s, p) -> return :ok
function keymap_fcn(f::Function, s, c)
function keymap_fcn(f, s, c)
return (s, p) -> begin
r = f(s, p, c)
if isa(r, Symbol)
Expand Down Expand Up @@ -1102,7 +1102,7 @@ function reset_state(s::PrefixSearchState)
end
end

function transition(f::Function, s::PrefixSearchState, mode)
function transition(f, s::PrefixSearchState, mode)
if isdefined(s,:mi)
transition(f,s.mi,mode)
end
Expand Down Expand Up @@ -1532,7 +1532,7 @@ activate(m::ModalInterface, s::MIState, termbuf, term::TextTerminal) =
activate(s.current_mode, s, termbuf, term)

commit_changes(t::UnixTerminal, termbuf) = write(t, takebuf_array(termbuf.out_stream))
function transition(f::Function, s::MIState, mode)
function transition(f, s::MIState, mode)
if mode == :abort
s.aborted = true
return
Expand Down
1 change: 1 addition & 0 deletions base/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function finalizer(o::ANY, f::Union{Function,Ptr})
end
ccall(:jl_gc_add_finalizer, Void, (Any,Any), o, f)
end
finalizer(o::ANY, f::ANY) = finalizer(o, eval(:(o->($f)(o))))

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

Expand Down
2 changes: 2 additions & 0 deletions base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ _new(:TopNode, :Symbol)
_new(:NewvarNode, :Symbol)
_new(:QuoteNode, :ANY)
_new(:GenSym, :Int)
_new(:Box, :ANY)
eval(:(Core.call(::Type{Box}) = $(Expr(:new, :Box))))
eval(:(Core.call(::Type{LineNumberNode}, f::Symbol, l::Int) = $(Expr(:new, :LineNumberNode, :f, :l))))
eval(:(Core.call(::Type{GlobalRef}, m::Module, s::Symbol) = $(Expr(:new, :GlobalRef, :m, :s))))

Expand Down
2 changes: 1 addition & 1 deletion base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ end
syntax_deprecation_warnings(warn::Bool) =
ccall(:jl_parse_depwarn, Cint, (Cint,), warn) == 1

function syntax_deprecation_warnings(f::Function, warn::Bool)
function syntax_deprecation_warnings(f, warn::Bool)
prev = syntax_deprecation_warnings(warn)
try
f()
Expand Down
2 changes: 2 additions & 0 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ call(T::Type{LineNumberNode}, f::Symbol, n::Int) = Core.call(T, f, n)
call(T::Type{LabelNode}, n::Int) = Core.call(T, n)
call(T::Type{GotoNode}, n::Int) = Core.call(T, n)
call(T::Type{QuoteNode}, x::ANY) = Core.call(T, x)
call(T::Type{Box}, x::ANY) = Core.call(T, x)
call(T::Type{Box}) = Core.call(T)
call(T::Type{NewvarNode}, s::Symbol) = Core.call(T, s)
call(T::Type{TopNode}, s::Symbol) = Core.call(T, s)
call(T::Type{Module}, args...) = Core.call(T, args...)
Expand Down
4 changes: 2 additions & 2 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ const n_ifunc = reinterpret(Int32,arraylen)+1
const t_ifunc = Array{Tuple{Int,Int,Function},1}(n_ifunc)
const t_ffunc_key = Array{Function,1}(0)
const t_ffunc_val = Array{Tuple{Int,Int,Function},1}(0)
function add_tfunc(f::IntrinsicFunction, minarg::Int, maxarg::Int, tfunc::Function)
function add_tfunc(f::IntrinsicFunction, minarg::Int, maxarg::Int, tfunc::ANY)
t_ifunc[reinterpret(Int32,f)+1] = (minarg, maxarg, tfunc)
end
function add_tfunc(f::Function, minarg::Int, maxarg::Int, tfunc::Function)
function add_tfunc(f::Function, minarg::Int, maxarg::Int, tfunc::ANY)
push!(t_ffunc_key, f)
push!(t_ffunc_val, (minarg, maxarg, tfunc))
end
Expand Down
4 changes: 2 additions & 2 deletions base/iostream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,14 @@ function takebuf_raw(s::IOStream)
return buf, sz
end

function sprint(size::Integer, f::Function, args...)
function sprint(size::Integer, f, args...)
s = IOBuffer(Array(UInt8,size), true, true)
truncate(s,0)
f(s, args...)
takebuf_string(s)
end

sprint(f::Function, args...) = sprint(0, f, args...)
sprint(f, args...) = sprint(0, f, args...)

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

Expand Down
8 changes: 4 additions & 4 deletions base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,11 @@ using .Docs
using .Markdown

# deprecated functions
include("deprecated.jl")
#include("deprecated.jl")

# Some basic documentation
include("docs/helpdb.jl")
include("docs/basedocs.jl")
#include("docs/helpdb.jl")
#include("docs/basedocs.jl")

# threads
include("threads.jl")
Expand All @@ -312,7 +312,7 @@ function __init__()
end

include = include_from_node1
include("precompile.jl")
#include("precompile.jl")

end # baremodule Base

Expand Down
2 changes: 1 addition & 1 deletion base/task.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## basic task functions and TLS

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

function show(io::IO, t::Task)
print(io, "Task ($(t.state)) @0x$(hex(convert(UInt, pointer_from_objref(t)), WORD_SIZE>>2))")
Expand Down
2 changes: 1 addition & 1 deletion base/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ eltype{T,_}(::Type{NTuple{_,T}}) = T

## mapping ##

ntuple(f::Function, n::Integer) =
ntuple(f, n::Integer) =
n<=0 ? () :
n==1 ? (f(1),) :
n==2 ? (f(1),f(2),) :
Expand Down
2 changes: 1 addition & 1 deletion base/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ end

## printing with color ##

function with_output_color(f::Function, color::Symbol, io::IO, args...)
function with_output_color(f, color::Symbol, io::IO, args...)
buf = IOBuffer()
have_color && print(buf, get(text_colors, color, color_normal))
try f(buf, args...)
Expand Down
35 changes: 30 additions & 5 deletions src/jlfrontend.scm
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
`(incomplete ,msg)
e))
(begin
;;(newline)
;;(display "unexpected error: ")
;;(prn e)
;;(print-stack-trace (stacktrace))
(newline)
(display "unexpected error: ")
(prn e)
(print-stack-trace (stacktrace))
'(error "malformed expression"))))
thk))

Expand Down Expand Up @@ -103,8 +103,33 @@
(pair? (cadr e)) (eq? (caadr e) '=) (symbol? (cadadr e))
(eq? (cadr (caddr e)) (cadadr e))))

(define (lift-toplevel- e)
(if (atom? e) (cons e '())
(let* ((rec (map lift-toplevel- e))
(e2 (map car rec))
(tl (apply append (map cdr rec))))
(if (eq? (car e) 'toplevel-butlast)
(cons (last e2) (append tl (butlast (cdr e2))))
(cons e2 tl)))))

(define (lift-toplevel x)
(if (and (pair? x) (memq (car x) '(toplevel body)))
(cons (car x)
(apply append (map (lambda (e)
(let ((e (lift-toplevel e)))
(if (and (pair? e) (eq? (car e) 'toplevel))
(cdr e)
(list e))))
(cdr x))))
(let ((e (lift-toplevel- x)))
(if (null? (cdr e))
(car e)
(if (and (pair? (car e)) (eq? (caar e) 'toplevel))
`(toplevel ,@(cdr e) ,@(cdar e))
`(toplevel ,@(cdr e) ,(car e)))))))

(define (expand-toplevel-expr- e)
(let ((ex (expand-toplevel-expr-- e)))
(let ((ex (lift-toplevel (expand-toplevel-expr-- e))))
(cond ((contains (lambda (x) (equal? x '(top ccall))) ex) ex)
((simple-assignment? ex) (cadr ex))
((and (length= ex 2) (eq? (car ex) 'body))
Expand Down
Loading

0 comments on commit 6ed80a4

Please sign in to comment.