Ruby 有错误吗?点击控制键-/将其调出。如果“没有任何东西在它到达那条线后运行”,这可能就是问题所在
#2、只要你在最后一行将Ruby 有错误吗?点击控制键-/将其调出。如果“没有任何东西在它到达那条线后运行”,这可能就是问题所在,ruby,shoes,Ruby,Shoes,#2、只要你在最后一行将exec_行更改为@exec_行,这对我来说确实有效。以下是我尝试过的: class Manager;end Shoes.app(:title => "Paging Simulator", :width => 800, :height => 450) do @manager = Manager.new stack(:width => 200) do @exec_list = stack { title "Executio
exec_行
更改为@exec_行
,这对我来说确实有效。以下是我尝试过的:
class Manager;end
Shoes.app(:title => "Paging Simulator", :width => 800, :height => 450) do
@manager = Manager.new
stack(:width => 200) do
@exec_list = stack {
title "Execution Queue", :size => 14
@exec_lines = para "click button to load", :size => 9
@file_button = button "Load Process List"
@file_button.click {
filename = ask_open_file
#alert "this makes no sense"
@exec_lines.text = File.read filename
}
}
end
end
希望有帮助 很少有人有穿鞋的经验。如果您没有收到任何有用的信息,我建议您询问鞋子维修人员。如果你的代码中有bug或者鞋子中有bug,他可能是你追踪的最佳人选。我知道他不使用StackOverflow,否则我会在这里指给他看。你应该可以在他的网站上找到他的电子邮件,()或者你可以在鞋类IRC频道找到他?史蒂夫,谢谢你的光临,我真的很感激。问题更多的是,我试图用我用Shoes创建的按钮操纵一些类,但当我试图在Shoes.app中访问它们时,它们似乎失败了。我已经发布了我的程序的完整来源,希望能澄清到底发生了什么。我真的不确定到底是什么解决了这个问题,但史蒂夫帮助我朝着正确的方向前进。据我所知,在我在第一级堆栈之后添加了另一个堆栈之后,它就开始工作了。新代码没有出现,但是第一个代码完成了它应该做的一切,但是如果我删除了该代码,它仍然可以工作。孩子,继续尝试同样的事情,看看会发生什么,我猜。
#!/usr/bin/env shoes
require 'rubygems'
require 'ruby-debug'
class MemSegment
attr_accessor :filled, :pid, :seg, :seg_id
def initialize(filled=false, pid=nil, seg=nil, seg_id=0)
@filled = filled
@pid = pid.to_i
@seg = seg.to_s
@seg_id = seg_id.to_i
self
end
def fill(pid, seg, seg_id)
@filled = true; @pid = pid; @seg = seg; @seg_id = seg_id;
self
end
def clear
self.filled = false; self.pid = nil; self.seg = nil;
self
end
def filled?
@filled
end
def to_s
filled? ? "#{seg} #{seg_id} for pid #{pid}" : "Free"
end
end
class SimProc
include Enumerable
attr_accessor :pid, :code, :data
def initialize(pid, code, data)
@pid = pid.to_i
@code = code.to_i
@data = data.to_i
end
def each
yield :code, code
yield :data, data
end
def to_s
"[SimProc :pid => #{pid}, :code => #{code}, :data => #{data}]"
end
def to_a
[@pid, @code, @data]
end
end
class Manager
attr_reader :segments, :processes, :exec_list, :exec_object
def initialize
@exec_list = [[1, 2], [3, 4], [5, 6]]
@processes = {}
@segments = Array.new(8) { MemSegment.new }
end
def print_activity
@segments.each_with_index {|s, index| puts "Seg #{index} => #{s}" }
@processes.each_value {|s| puts s }
end
def load_process(pcb, exec_index)
if pcb.size == 3
p = SimProc.new(*pcb)
bad_load = false
@processes.store p.pid, p
@processes[p.pid].each do |proc_seg, bsize|
(bsize / 512.0).ceil.times do |seg_id|
@segments.each_with_index do |s, index|
if !s.filled
#find the first empty memory segment
s.fill p.pid, proc_seg, seg_id
break
# if all slots are filled and we couldn't place a proc block
elsif index == @segments.size - 1
bad_load = true
puts "Cannot find a place for #{proc_seg} segment of size #{bsize}. Requeueing..."
break;
end
end
break if bad_load
end
end
# recover pages and queue the process for later
if bad_load
@segments.each_with_index do |seg, seg_index|
# clear any segments that didn't get loaded properly
if seg.pid == p.pid
seg.clear
puts "Seg #{seg_index} => segment cleared: #{seg}"
end
end
# reinsert this process after the next in the execution list
# it will attempt to load and run after the next process is performed
@exec_list.insert(exec_index + 2, p.to_a)
end
print_activity
elsif pcb.size == 2 and pcb[1] == -1
# a process is exiting
puts "removing pid #{pcb[0]}"
@segments.each { |s| s.clear if s.pid == pcb[0] }
@processes.delete pcb[0]
print_activity
end
end
def set_exec_list(filename)
file = File.open filename
file.each { |pcb| @exec_list << pcb.split.map(&:to_i) } unless file.nil?
filename
end
def main
exseq = File.open('exseq2.txt')
set_exec_list exseq
# this is the object that will be used to run each process with .next
@exec_object = @exec_list.each_with_index
# @exec_list.each_with_index { |pcb, exec_index| load_process(pcb, exec_index) }
(@exec_list.size + 1).times do
load_process(*@exec_object.next)
end
end
end
=begin
manager = Manager.new
manager.main
=end
#=begin
Shoes.app(:title => "Paging Simulator", :width => 800, :height => 450) do
@manager = Manager.new
stack(:width => 200) do
@exec_list = stack {
title "Execution Queue", :size => 14
@exec_lines = para "click button to load", :size => 9
@file_button = button "Load Process List"
debugger
@file_button.click {
filename = ask_open_file
@manager.set_exec_list filename
# alert "this makes no sense"
# @exec_lines.text = @manager.exec_list
# @exec_lines.text = File.read filename
@exec_lines.text = @manager.exec_list.join "\n"
}
}
end
end
#=end
class Manager;end
Shoes.app(:title => "Paging Simulator", :width => 800, :height => 450) do
@manager = Manager.new
stack(:width => 200) do
@exec_list = stack {
title "Execution Queue", :size => 14
@exec_lines = para "click button to load", :size => 9
@file_button = button "Load Process List"
@file_button.click {
filename = ask_open_file
#alert "this makes no sense"
@exec_lines.text = File.read filename
}
}
end
end