Permalink
Browse files

Lots more refactoring. Work on workspaces, and a bunch else.

  • Loading branch information...
Yehuda Katz Yehuda Katz
Yehuda Katz authored and Yehuda Katz committed Nov 25, 2009
1 parent 926d081 commit efc94c38f6eebca4facdf578ee40d1fc0e3823b7
Showing with 515 additions and 578 deletions.
  1. +3 −0 irb.rb
  2. +33 −33 irb/cmd/load.rb
  3. +12 −9 irb/cmd/pushws.rb
  4. +1 −2 irb/context.rb
  5. +15 −46 irb/ext/change-ws.rb
  6. +32 −33 irb/ext/history.rb
  7. +20 −21 irb/ext/loader.rb
  8. +1 −2 irb/ext/multi-irb.rb
  9. +16 −35 irb/ext/save-history.rb
  10. +16 −27 irb/ext/workspaces.rb
  11. +7 −8 irb/init.rb
  12. +1 −1 irb/input-method.rb
  13. +358 −361 irb/ruby-lex.rb
View
3 irb.rb
@@ -56,6 +56,9 @@ def start(path = nil)
self.main_context = irb.context
+ # TODO: Move into history module
+ main_context.save_history = conf[:SAVE_HISTORY]
+
require "irb/ext/multi-irb"
trap("SIGINT") { irb.signal_handle }
View
@@ -1,13 +1,13 @@
#
-# load.rb -
-# $Release Version: 0.9.5$
-# $Revision: 11708 $
-# $Date: 2007-02-13 08:01:19 +0900 (Tue, 13 Feb 2007) $
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
+# load.rb -
+# $Release Version: 0.9.5$
+# $Revision: 11708 $
+# $Date: 2007-02-13 08:01:19 +0900 (Tue, 13 Feb 2007) $
+# by Keiju ISHITSUKA(keiju@ruby-lang.org)
#
# --
#
-#
+#
#
require "irb/cmd/nop.rb"
@@ -19,47 +19,47 @@ class Load<Nop
include IrbLoader
def execute(file_name, priv = nil)
-# return ruby_load(file_name) unless IRB.conf[:USE_LOADER]
- return irb_load(file_name, priv)
+# return ruby_load(file_name) unless IRB.conf[:USE_LOADER]
+ return irb_load(file_name, priv)
end
end
class Require<Nop
include IrbLoader
-
+
def execute(file_name)
-# return ruby_require(file_name) unless IRB.conf[:USE_LOADER]
+# return ruby_require(file_name) unless IRB.conf[:USE_LOADER]
+
+ rex = Regexp.new("#{Regexp.quote(file_name)}(\.o|\.rb)?")
+ return false if $".find{|f| f =~ rex}
- rex = Regexp.new("#{Regexp.quote(file_name)}(\.o|\.rb)?")
- return false if $".find{|f| f =~ rex}
+ case file_name
+ when /\.rb$/
+ begin
+ if irb_load(file_name)
+ $".push file_name
+ return true
+ end
+ rescue LoadError
+ end
+ when /\.(so|o|sl)$/
+ return ruby_require(file_name)
+ end
- case file_name
- when /\.rb$/
- begin
- if irb_load(file_name)
- $".push file_name
- return true
- end
- rescue LoadError
- end
- when /\.(so|o|sl)$/
- return ruby_require(file_name)
- end
-
- begin
- irb_load(f = file_name + ".rb")
- $".push f
- return true
- rescue LoadError
- return ruby_require(file_name)
- end
+ begin
+ irb_load(f = file_name + ".rb")
+ $".push f
+ return true
+ rescue LoadError
+ return ruby_require(file_name)
+ end
end
end
class Source<Nop
include IrbLoader
def execute(file_name)
- source_file(file_name)
+ source_file(file_name)
end
end
end
View
@@ -1,9 +1,9 @@
#
# change-ws.rb -
-# $Release Version: 0.9.5$
-# $Revision: 11708 $
-# $Date: 2007-02-13 08:01:19 +0900 (Tue, 13 Feb 2007) $
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
+# $Release Version: 0.9.5$
+# $Revision: 11708 $
+# $Date: 2007-02-13 08:01:19 +0900 (Tue, 13 Feb 2007) $
+# by Keiju ISHITSUKA(keiju@ruby-lang.org)
#
# --
#
@@ -17,21 +17,24 @@ module IRB
module ExtendCommand
class Workspaces<Nop
def execute(*obj)
- irb_context.workspaces.collect{|ws| ws.main}
+ workspaces = irb_context.workspaces.map {|w| w.main.inspect} + ["[green]#{irb_context.main.inspect}[/]"]
+ puts IRB.colorize("[blue]Workspaces\n----------[/]\n" <<
+ workspaces.join("\n"))
+ IRB::CommandResult
end
end
class PushWorkspace<Workspaces
def execute(*obj)
- irb_context.push_workspace(*obj)
- super
+ irb_context.push_workspace(*obj)
+ super
end
end
class PopWorkspace<Workspaces
def execute(*obj)
- irb_context.pop_workspace(*obj)
- super
+ irb_context.pop_workspace(*obj)
+ super
end
end
end
View
@@ -65,7 +65,6 @@ def initialize(irb, workspace = nil, input_method = nil, output_method = nil)
else
@io = input_method
end
- self.save_history = IRB.conf[:SAVE_HISTORY] if IRB.conf[:SAVE_HISTORY]
if output_method
@output_method = output_method
@@ -138,7 +137,7 @@ def set_last_value(value)
end
def irb_name
- @irb_name ||= "irb" + IRB.job_manager.current_job_ixZd
+ @irb_name ||= "irb" + IRB.job_manager.current_job_id
end
def irb_path
View
@@ -1,62 +1,31 @@
#
-# irb/ext/cb.rb -
-# $Release Version: 0.9.5$
-# $Revision: 11708 $
-# $Date: 2007-02-13 08:01:19 +0900 (Tue, 13 Feb 2007) $
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
+# irb/ext/cb.rb -
+# $Release Version: 0.9.5$
+# $Revision: 11708 $
+# $Date: 2007-02-13 08:01:19 +0900 (Tue, 13 Feb 2007) $
+# by Keiju ISHITSUKA(keiju@ruby-lang.org)
#
# --
#
-#
+#
#
module IRB
class Context
def home_workspace
- if defined? @home_workspace
- @home_workspace
- else
- @home_workspace = @workspace
- end
+ @home_workspace ||= @workspace
end
- def change_workspace(*_main)
- if _main.empty?
- @workspace = home_workspace
- return main
- end
-
- @workspace = WorkSpace.new(_main[0])
-
- if !(class<<main;ancestors;end).include?(ExtendCommandBundle)
- main.extend ExtendCommandBundle
+ def change_workspace(_main = nil)
+ unless _main
+ @workspace = home_workspace
+ return main
end
- end
-# def change_binding(*_main)
-# back = @workspace
-# @workspace = WorkSpace.new(*_main)
-# unless _main.empty?
-# begin
-# main.extend ExtendCommandBundle
-# rescue
-# print "can't change binding to: ", main.inspect, "\n"
-# @workspace = back
-# return nil
-# end
-# end
-# @irb_level += 1
-# begin
-# catch(:SU_EXIT) do
-# @irb.eval_input
-# end
-# ensure
-# @irb_level -= 1
-# @workspace = back
-# end
-# end
-# alias change_workspace change_binding
- end
+ @workspace = WorkSpace.new(_main)
+ @workspace.main.extend ExtendCommandBundle
+ end
+ end
end
View
@@ -1,9 +1,9 @@
#
# history.rb -
-# $Release Version: 0.9.5$
-# $Revision: 11708 $
-# $Date: 2007-02-13 08:01:19 +0900 (Tue, 13 Feb 2007) $
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
+# $Release Version: 0.9.5$
+# $Revision: 11708 $
+# $Date: 2007-02-13 08:01:19 +0900 (Tue, 13 Feb 2007) $
+# by Keiju ISHITSUKA(keiju@ruby-lang.org)
#
# --
#
@@ -21,10 +21,9 @@ class Context
def set_last_value(value)
_set_last_value(value)
-# @workspace.evaluate self, "_ = IRB.CurrentContext.last_value"
- if @eval_history #and !@eval_history_values.equal?(llv)
- @eval_history_values.push @line_no, @last_value
- @workspace.evaluate self, "__ = IRB.CurrentContext.instance_eval{@eval_history_values}"
+ if @eval_history
+ @eval_history_values.push @line_no, @last_value
+ @workspace.evaluate self, "__ = IRB.current_context.instance_eval{@eval_history_values}"
end
@last_value
@@ -33,16 +32,16 @@ def set_last_value(value)
attr_reader :eval_history
def eval_history=(no)
if no
- if defined?(@eval_history) && @eval_history
- @eval_history_values.size(no)
- else
- @eval_history_values = History.new(no)
- IRB.conf[:__TMP__EHV__] = @eval_history_values
- @workspace.evaluate(self, "__ = IRB.conf[:__TMP__EHV__]")
- IRB.conf.delete(:__TMP_EHV__)
- end
+ if defined?(@eval_history) && @eval_history
+ @eval_history_values.size(no)
+ else
+ @eval_history_values = History.new(no)
+ IRB.conf[:__TMP__EHV__] = @eval_history_values
+ @workspace.evaluate(self, "__ = IRB.conf[:__TMP__EHV__]")
+ IRB.conf.delete(:__TMP_EHV__)
+ end
else
- @eval_history_values = nil
+ @eval_history_values = nil
end
@eval_history = no
end
@@ -58,20 +57,20 @@ def initialize(size = 16)
def size(size)
if size != 0 && size < @size
- @contents = @contents[@size - size .. @size]
+ @contents = @contents[@size - size .. @size]
end
@size = size
end
def [](idx)
begin
- if idx >= 0
- @contents.find{|no, val| no == idx}[1]
- else
- @contents[idx][1]
- end
+ if idx >= 0
+ @contents.find{|no, val| no == idx}[1]
+ else
+ @contents[idx][1]
+ end
rescue NameError
- nil
+ nil
end
end
@@ -84,22 +83,22 @@ def push(no, val)
def inspect
if @contents.empty?
- return real_inspect
+ return real_inspect
end
unless (last = @contents.pop)[1].equal?(self)
- @contents.push last
- last = nil
+ @contents.push last
+ last = nil
end
str = @contents.collect{|no, val|
- if val.equal?(self)
- "#{no} ...self-history..."
- else
- "#{no} #{val.inspect}"
- end
+ if val.equal?(self)
+ "#{no} ...self-history..."
+ else
+ "#{no} #{val.inspect}"
+ end
}.join("\n")
if str == ""
- str = "Empty."
+ str = "Empty."
end
@contents.push last if last
str
Oops, something went wrong.

0 comments on commit efc94c3

Please sign in to comment.