bf,長い、遅い

おそいーどうするんだ。文字表示もまだおかしい。
http://codegolf.com/brainfuck
brainfuck-1.1.rb

$mmax=30000
buf=" "*$mmax
$mmax.times{|i|buf[i]=0}
$pos=0
$ibuf=""
$gcount=0
$now=0
$mem=buf
$stack=[]
$sp=0
$debug="-d"

def deb d
 #print d if $#debug=="-d"
end


def get
 #deb ","
 ($ibuf=gets;$now=0) if $gcount==$now
 $gcount= ($ibuf==nil ? 0: $ibuf.length)
 $mem[$pos]=$ibuf[$now]
 $now+=1 if $gcount>$now
end

def ex po
 puts "\n[error. in #{po},"
 p "stack:",$stack
 after
 exit
end

def put
 #deb "."
 print $mem[$pos..$pos] 
 #print "(#{$mem[$pos]})"
end


def run d,po
 case d
 when "+" #*p++
  $mem[$pos]+=1
  po
 when "-" #*p--
  $mem[$pos]-=1
  po
 when ">" #p++
  $pos+=1
  po
 when "<" #p--
  $pos-=1
  po
 when "[" #while
  $stack.push(po)
  $sp+=1
  po
 when "]" #end
  if $mem[$pos]==0;
    $sp-=1
    $stack.pop()
  else
   $sp-=1
   po=$stack.pop()-1
  end
  po
 when "," #getc
  get
  po
 when "." #putc
  put
  po
 else
  #deb "(?)"
  po
 end
end

def after
 return
 puts
 puts "[bf program end.]","buf="+$ibuf,"mem:"+$mem
end
 
point=0
prog=STDIN.gets('')
/!(.*)/=~prog
($ibuf=$1;$gcount=$ibuf.length) if $1!=nil

while 1
 if point>prog.length;break;end
 com=prog[point..point]
 point=run(com,point)+1
end
after