code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
#
# tk/winfo.rb : methods for winfo command
#
module TkWinfo
end
require 'tk'
module TkWinfo
include Tk
extend Tk
TkCommandNames = ['winfo'.freeze].freeze
def TkWinfo.atom(name, win=nil)
if win
number(tk_call_without_enc('winfo', 'atom', '-displayof', win,
_get_eva... | Ruby |
#
# tk/winpkg.rb : methods for Tcl/Tk packages for Microsoft Windows
# 2000/11/22 by Hidetoshi Nagai <nagai@ai.kyutech.ac.jp>
#
# ATTENTION !!
# This is NOT TESTED. Because I have no test-environment.
#
require 'tk'
module Tk::WinDDE
end
#TkWinDDE = Tk::WinDDE
#Tk.__set_toplevel_alias... | Ruby |
#
# tk/itemconfig.rb : control item/tag configuration of widget
#
require 'tk'
require 'tkutil'
require 'tk/itemfont.rb'
module TkItemConfigOptkeys
include TkUtil
def __item_optkey_aliases(id)
{}
end
private :__item_optkey_aliases
def __item_numval_optkeys(id)
[]
end
private :__item_numval_optk... | Ruby |
#
# tk/image.rb : treat Tk image objects
#
require 'tk'
class TkImage<TkObject
include Tk
TkCommandNames = ['image'.freeze].freeze
Tk_IMGTBL = TkCore::INTERP.create_table
(Tk_Image_ID = ['i'.freeze, TkUtil.untrust('00000')]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
... | Ruby |
#
# tk/fontchooser.rb -- "tk fontchooser" support (Tcl/Tk8.6 or later)
#
require 'tk'
require 'tk/font'
module TkFont::Chooser
extend TkCore
end
class << TkFont::Chooser
def method_missing(id, *args)
name = id.id2name
case args.length
when 1
if name[-1] == ?=
configure name[0..-2], args[... | Ruby |
#
# tk/message.rb : treat message widget
#
require 'tk'
require 'tk/label'
class Tk::Message<Tk::Label
TkCommandNames = ['message'.freeze].freeze
WidgetClassName = 'Message'.freeze
WidgetClassNames[WidgetClassName] ||= self
#def create_self(keys)
# if keys and keys != None
# tk_call_without_enc('messag... | Ruby |
#
# tk/texttag.rb - methods for treating text tags
#
require 'tk'
require 'tk/text'
require 'tk/tagfont'
class TkTextTag<TkObject
include TkTreatTagFont
include Tk::Text::IndexModMethods
TTagID_TBL = TkCore::INTERP.create_table
(Tk_TextTag_ID = ['tag'.freeze, TkUtil.untrust('00000')]).instance_eval{
@mut... | Ruby |
#
# tk/bind.rb : control event binding
#
require 'tk'
class TkBindTag
include TkBindCore
#BTagID_TBL = {}
BTagID_TBL = TkCore::INTERP.create_table
(Tk_BINDTAG_ID = ["btag".freeze, TkUtil.untrust("00000")]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
TkCore::INTERP.init_... | Ruby |
#
# tk/validation.rb - validation support module for entry, spinbox, and so on
#
require 'tk'
module Tk
module ValidateConfigure
def self.__def_validcmd(scope, klass, keys=nil)
keys = klass._config_keys unless keys
keys.each{|key|
eval("def #{key}(*args, &b)
__validcmd_call(... | Ruby |
#
# tk/scrollbox.rb - Tk Listbox with Scrollbar
# as an example of Composite Widget
# by Yukihiro Matsumoto <matz@netlab.co.jp>
#
require 'tk'
require 'tk/listbox'
class TkScrollbox<Tk::Listbox
include TkComposite
def initialize_composite(keys=nil... | Ruby |
#
# tk/optionobj.rb : control options for a group of widgets
#
# NOTE: If you want to use key-only option (no value),
# use Tk::None for the value of the key-only option.
#
# e.g. hash_kv({'aaa'=>1, 'bbb'=>Tk::None, 'ccc'=>3})
# => ["-aaa", 1, "-bbb", "-ccc", 3]
#
require 'tk'
module Tk
... | Ruby |
#
# tk/radiobutton.rb : treat radiobutton widget
#
require 'tk'
require 'tk/button'
class Tk::RadioButton<Tk::Button
TkCommandNames = ['radiobutton'.freeze].freeze
WidgetClassName = 'Radiobutton'.freeze
WidgetClassNames[WidgetClassName] ||= self
#def create_self(keys)
# if keys and keys != None
# tk_ca... | Ruby |
#
# tk/textmark.rb - methods for treating text marks
#
require 'tk'
require 'tk/text'
class TkTextMark<TkObject
include Tk::Text::IndexModMethods
TMarkID_TBL = TkCore::INTERP.create_table
(Tk_TextMark_ID = ['mark'.freeze, TkUtil.untrust('00000')]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; en... | Ruby |
#
# tk/font.rb - the class to treat fonts on Ruby/Tk
#
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
class TkFont
include Tk
extend TkCore
TkCommandNames = ['font'.freeze].freeze
(Tk_FontID = ["@font".freeze, TkUtil.untrust("00000")]).instance_eval{
@mutex =... | Ruby |
#
# tk/package.rb : package command
#
require 'tk'
module TkPackage
include TkCore
extend TkPackage
TkCommandNames = ['package'.freeze].freeze
def add_path(path)
Tk::AUTO_PATH.value = Tk::AUTO_PATH.to_a << path
end
def forget(package)
tk_call('package', 'forget', package)
nil
end
def if... | Ruby |
#
# tk/labelframe.rb : treat labelframe widget
#
require 'tk'
require 'tk/frame'
class Tk::LabelFrame<Tk::Frame
TkCommandNames = ['labelframe'.freeze].freeze
WidgetClassName = 'Labelframe'.freeze
WidgetClassNames[WidgetClassName] ||= self
#def create_self(keys)
# if keys and keys != None
# tk_call_with... | Ruby |
#
# tk/after.rb : methods for Tcl/Tk after command
#
# $Id: after.rb 25189 2009-10-02 12:04:37Z akr $
#
require 'tk/timer'
| Ruby |
#
# tk/toplevel.rb : treat toplevel widget
#
require 'tk'
require 'tk/wm'
require 'tk/menuspec'
class Tk::Toplevel<TkWindow
include Wm
include TkMenuSpec
TkCommandNames = ['toplevel'.freeze].freeze
WidgetClassName = 'Toplevel'.freeze
WidgetClassNames[WidgetClassName] ||= self
################# old version
... | Ruby |
#
# tk/kinput.rb : control kinput
#
require 'tk'
module TkKinput
include Tk
extend Tk
TkCommandNames = [
'kinput_start'.freeze,
'kinput_send_spot'.freeze,
'kanjiInput'.freeze
].freeze
def TkKinput.start(win, style=None)
tk_call('kinput_start', win, style)
end
def kinput_start(style=None... | Ruby |
#
# tk/menu.rb : treat menu and menubutton
#
require 'tk'
require 'tk/itemconfig'
require 'tk/menuspec'
module TkMenuEntryConfig
include TkItemConfigMethod
def __item_cget_cmd(id)
[self.path, 'entrycget', id]
end
private :__item_cget_cmd
def __item_config_cmd(id)
[self.path, 'entryconfigure', id]
... | Ruby |
#
# tkmacpkg.rb - load tk/macpkg.rb
#
require 'tk/macpkg'
| Ruby |
#
# tkbgerror.rb - load tk/bgerror.rb
#
require 'tk/bgerror'
| Ruby |
#
# tkconsole.rb - load tk/console.rb
#
require 'tk/console'
| Ruby |
#
# tkdialog.rb - load tk/dialog.rb
#
require 'tk/dialog'
| Ruby |
#
# multi-tk.rb - supports multi Tk interpreters
# by Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
require 'tcltklib'
require 'tkutil'
require 'thread'
if defined? Tk
fail RuntimeError,"'multi-tk' library must be required before requiring 'tk'"
end
##################################... | Ruby |
#
# tkentry.rb - load tk/entry.rb
#
require 'tk/entry'
| Ruby |
##############################################################
# extconf.rb for tcltklib
# release date: 2010-07-30
##############################################################
require 'mkmf'
TkLib_Config = {}
TkLib_Config['search_versions'] =
# %w[8.9 8.8 8.7 8.6 8.5 8.4 8.3 8.2 8.1 8.0 7.6 4.2]
# %w[8.7 8.6 8.... | Ruby |
require 'mkmf'
create_makefile('continuation')
| Ruby |
#!/usr/local/bin/ruby
#
# linear.rb
#
# Solves linear equation system(A*x = b) by LU decomposition method.
# where A is a coefficient matrix,x is an answer vector,b is a constant vector.
#
# USAGE:
# ruby linear.rb [input file solved]
#
require "bigdecimal"
require "bigdecimal/ludcmp"
#
# NOTE:
# Change follow... | Ruby |
#!/usr/local/bin/ruby
#
# pi.rb
#
# Calculates 3.1415.... (the number of times that a circle's diameter
# will fit around the circle) using J. Machin's formula.
#
require "bigdecimal"
require "bigdecimal/math.rb"
include BigMath
if ARGV.size == 1
print "PI("+ARGV[0]+"):\n"
p PI(ARGV[0].to_i)
else
print ... | Ruby |
#!/usr/local/bin/ruby
#
# nlsolve.rb
# An example for solving nonlinear algebraic equation system.
#
require "bigdecimal"
require "bigdecimal/newton"
include Newton
class Function
def initialize()
@zero = BigDecimal::new("0.0")
@one = BigDecimal::new("1.0")
@two = BigDecimal::new("2.0")
@ten = B... | Ruby |
# -*- ruby -*-
_VERSION = "1.1.0"
Gem::Specification.new do |s|
s.name = "bigdecimal"
s.version = _VERSION
s.date = "2011-07-30"
s.summary = "Arbitrary-precision decimal floating-point number library."
s.email = "mrkn@mrkn.jp"
s.description = "This library provides arbitrary-precision decimal floating-poin... | Ruby |
require "bigdecimal/ludcmp"
require "bigdecimal/jacobian"
#
# newton.rb
#
# Solves the nonlinear algebraic equation system f = 0 by Newton's method.
# This program is not dependent on BigDecimal.
#
# To call:
# n = nlsolve(f,x)
# where n is the number of iterations required,
# x is the initial value vector
... | Ruby |
require 'bigdecimal'
#
#--
# Contents:
# sqrt(x, prec)
# sin (x, prec)
# cos (x, prec)
# atan(x, prec) Note: |x|<1, x=0.9999 may not converge.
# log (x, prec)
# PI (prec)
# E (prec) == exp(1.0,prec)
#
# where:
# x ... BigDecimal number to be computed.
# |x| must be small enough to get... | Ruby |
require 'bigdecimal'
#
# Solves a*x = b for x, using LU decomposition.
#
module LUSolve
module_function
# Performs LU decomposition of the n by n matrix a.
def ludecomp(a,n,zero=0,one=1)
prec = BigDecimal.limit(nil)
ps = []
scales = []
for i in 0...n do # pick up largest(abs. val.) element ... | Ruby |
#
# require 'bigdecimal/jacobian'
#
# Provides methods to compute the Jacobian matrix of a set of equations at a
# point x. In the methods below:
#
# f is an Object which is used to compute the Jacobian matrix of the equations.
# It must provide the following methods:
#
# f.values(x):: returns the values of all functio... | Ruby |
class Integer < Numeric
# call-seq:
# int.to_d -> bigdecimal
#
# Convert +int+ to a BigDecimal and return it.
#
# require 'bigdecimal'
# require 'bigdecimal/util'
#
# 42.to_d
# # => #<BigDecimal:1008ef070,'0.42E2',9(36)>
#
def to_d
BigDecimal(self)
end
end
class Float... | Ruby |
require 'mkmf'
have_func("labs", "stdlib.h")
have_func("llabs", "stdlib.h")
create_makefile('bigdecimal')
| Ruby |
require 'mkmf'
$defs << "-D""BADMESS=0"
create_makefile("sdbm")
| Ruby |
create_makefile("-test-/bug-3662/bug")
| Ruby |
$srcs = Dir[File.join($srcdir, "*.{#{SRC_EXT.join(%q{,})}}")]
inits = $srcs.map {|s| File.basename(s, ".*")}
inits.delete("init")
inits.map! {|s|"X(#{s})"}
$defs << "-DTEST_INIT_FUNCS(X)=\"#{inits.join(' ')}\""
create_makefile("-test-/string/string")
| Ruby |
create_makefile("-test-/st/numhash")
| Ruby |
create_makefile("-test-/wait_for_single_fd/wait_for_single_fd")
| Ruby |
require 'mkmf'
create_makefile("-test-/funcall/funcall")
| Ruby |
create_makefile("-test-/load/dot.dot/dot.dot")
| Ruby |
if $mingw or $mswin
create_makefile("-test-/win32/fd_setsize")
end
| Ruby |
if $mingw or $mswin
$objs = ["dlntest.o"]
testdll = "$(topdir)/dlntest.dll"
$cleanfiles << testdll
config_string('cleanobjs') {|t| $cleanfiles.concat(t.gsub(/\$\*/, 'dlntest').split)}
create_makefile("-test-/win32/dln")
m = File.read("Makefile")
dlntestlib = "dlntest.#{$LIBEXT}"
m.sub!(/^OBJS =.*/) {"#... | Ruby |
create_makefile("-test-/old_thread_select/old_thread_select")
| Ruby |
create_makefile("-test-/array/resize")
| Ruby |
create_makefile("-test-/bug-3571/bug")
| Ruby |
require 'psych.so'
require 'psych/nodes'
require 'psych/streaming'
require 'psych/visitors'
require 'psych/handler'
require 'psych/tree_builder'
require 'psych/parser'
require 'psych/omap'
require 'psych/set'
require 'psych/coder'
require 'psych/core_ext'
require 'psych/deprecated'
require 'psych/stream'
require 'psych... | Ruby |
module Psych
class Omap < ::Hash
end
end
| Ruby |
module Psych
###
# If an object defines +encode_with+, then an instance of Psych::Coder will
# be passed to the method when the object is being serialized. The Coder
# automatically assumes a Psych::Nodes::Mapping is being emitted. Other
# objects like Sequence and Scalar may be emitted if +seq=+ or +scalar... | Ruby |
module Psych
module Visitors
class DepthFirst < Psych::Visitors::Visitor
def initialize block
@block = block
end
private
def nary o
o.children.each { |x| visit x }
@block.call o
end
alias :visit_Psych_Nodes_Stream :nary
alias :visit_Psych_Nodes... | Ruby |
require 'psych/scalar_scanner'
unless defined?(Regexp::NOENCODING)
Regexp::NOENCODING = 32
end
module Psych
module Visitors
###
# This class walks a YAML AST, converting each node to ruby
class ToRuby < Psych::Visitors::Visitor
def initialize ss = ScalarScanner.new
super()
@st = ... | Ruby |
module Psych
module Visitors
class Visitor
def accept target
visit target
end
private
DISPATCH = Hash.new do |hash, klass|
hash[klass] = "visit_#{klass.name.gsub('::', '_')}"
end
def visit target
send DISPATCH[target.class], target
end
end
... | Ruby |
require 'psych/json/ruby_events'
module Psych
module Visitors
class JSONTree < YAMLTree
include Psych::JSON::RubyEvents
def initialize options = {}, emitter = Psych::JSON::TreeBuilder.new
super
end
def accept target
if target.respond_to?(:encode_with)
dump_code... | Ruby |
module Psych
module Visitors
class Emitter < Psych::Visitors::Visitor
def initialize io, options = {}
opts = [:indentation, :canonical, :line_width].find_all { |opt|
options.key?(opt)
}
if opts.empty?
@handler = Psych::Emitter.new io
else
du = H... | Ruby |
module Psych
module Visitors
###
# YAMLTree builds a YAML ast given a ruby object. For example:
#
# builder = Psych::Visitors::YAMLTree.new
# builder << { :foo => 'bar' }
# builder.tree # => #<Psych::Nodes::Stream .. }
#
class YAMLTree < Psych::Visitors::Visitor
attr_reade... | Ruby |
module Psych
###
# Psych::Handler is an abstract base class that defines the events used
# when dealing with Psych::Parser. Clients who want to use Psych::Parser
# should implement a class that inherits from Psych::Handler and define
# events that they can handle.
#
# Psych::Handler defines all events th... | Ruby |
require 'date'
module Psych
DEPRECATED = __FILE__ # :nodoc:
module DeprecatedMethods # :nodoc:
attr_accessor :taguri
attr_accessor :to_yaml_style
end
def self.quick_emit thing, opts = {}, &block # :nodoc:
warn "#{caller[0]}: YAML.quick_emit is deprecated" if $VERBOSE && !caller[0].start_with?(Fil... | Ruby |
module Psych
module Streaming
###
# Create a new streaming emitter. Emitter will print to +io+. See
# Psych::Stream for an example.
def initialize io
super({}, self.class.const_get(:Emitter).new(io))
end
###
# Start streaming using +encoding+
def start encoding = Nodes::Stream... | Ruby |
module Psych
###
# YAML event parser class. This class parses a YAML document and calls
# events on the handler that is passed to the constructor. The events can
# be used for things such as constructing a YAML AST or deserializing YAML
# documents. It can even be fed back to Psych::Emitter to emit the sam... | Ruby |
require 'psych/nodes/node'
require 'psych/nodes/stream'
require 'psych/nodes/document'
require 'psych/nodes/sequence'
require 'psych/nodes/scalar'
require 'psych/nodes/mapping'
require 'psych/nodes/alias'
module Psych
###
# = Overview
#
# When using Psych.load to deserialize a YAML document, the document is
... | Ruby |
require 'psych/tree_builder'
module Psych
module Handlers
class DocumentStream < Psych::TreeBuilder # :nodoc:
def initialize &block
super
@block = block
end
def start_document version, tag_directives, implicit
n = Nodes::Document.new version, tag_directives, implicit
... | Ruby |
class Object
def self.yaml_tag url
Psych.add_tag(url, self)
end
# FIXME: rename this to "to_yaml" when syck is removed
###
# call-seq: to_yaml(options = {})
#
# Convert an object to YAML. See Psych.dump for more information on the
# available +options+.
def psych_to_yaml options = {}
Psych.... | Ruby |
require 'psych/visitors/visitor'
require 'psych/visitors/to_ruby'
require 'psych/visitors/emitter'
require 'psych/visitors/yaml_tree'
require 'psych/visitors/json_tree'
require 'psych/visitors/depth_first'
| Ruby |
require 'psych/handler'
module Psych
###
# This class works in conjunction with Psych::Parser to build an in-memory
# parse tree that represents a YAML document.
#
# == Example
#
# parser = Psych::Parser.new Psych::TreeBuilder.new
# parser.parse('--- foo')
# tree = parser.handler.root
#
# S... | Ruby |
require 'psych/json/yaml_events'
module Psych
module JSON
###
# Psych::JSON::TreeBuilder is an event based AST builder. Events are sent
# to an instance of Psych::JSON::TreeBuilder and a JSON AST is constructed.
class TreeBuilder < Psych::TreeBuilder
include Psych::JSON::YAMLEvents
end
e... | Ruby |
require 'psych/json/ruby_events'
require 'psych/json/yaml_events'
module Psych
module JSON
class Stream < Psych::Visitors::JSONTree
include Psych::JSON::RubyEvents
include Psych::Streaming
class Emitter < Psych::Stream::Emitter # :nodoc:
include Psych::JSON::YAMLEvents
end
en... | Ruby |
module Psych
module JSON
module YAMLEvents # :nodoc:
def start_document version, tag_directives, implicit
super(version, tag_directives, !streaming?)
end
def end_document implicit_end = !streaming?
super(implicit_end)
end
def start_mapping anchor, tag, implicit, sty... | Ruby |
module Psych
module JSON
module RubyEvents # :nodoc:
def visit_Time o
formatted = format_time o
@emitter.scalar formatted, nil, nil, false, true, Nodes::Scalar::DOUBLE_QUOTED
end
def visit_DateTime o
visit_Time o.to_time
end
def visit_String o
@emitt... | Ruby |
module Psych
class SyntaxError < ::SyntaxError
attr_reader :file, :line, :column, :offset, :problem, :context
def initialize file, line, col, offset, problem, context
err = [problem, context].compact.join ' '
filename = file || '<unknown>'
message = "(%s): %s at line %d column %d" % [... | Ruby |
module Psych
module Nodes
###
# This class represents a {YAML Mapping}[http://yaml.org/spec/1.1/#mapping].
#
# A Psych::Nodes::Mapping node may have 0 or more children, but must have
# an even number of children. Here are the valid children a
# Psych::Nodes::Mapping node may have:
#
#... | Ruby |
module Psych
module Nodes
###
# This class represents a {YAML Alias}[http://yaml.org/spec/1.1/#alias].
# It points to an +anchor+.
#
# A Psych::Nodes::Alias is a terminal node and may have no children.
class Alias < Psych::Nodes::Node
# The anchor this alias links to
attr_accessor ... | Ruby |
module Psych
module Nodes
###
# This class represents a {YAML Scalar}[http://yaml.org/spec/1.1/#id858081].
#
# This node type is a terminal node and should not have any children.
class Scalar < Psych::Nodes::Node
# Any style scalar, the emitter chooses
ANY = 0
# Plain ... | Ruby |
module Psych
module Nodes
###
# This represents a YAML Document. This node must be a child of
# Psych::Nodes::Stream. A Psych::Nodes::Document must have one child,
# and that child may be one of the following:
#
# * Psych::Nodes::Sequence
# * Psych::Nodes::Mapping
# * Psych::Nodes::S... | Ruby |
require 'stringio'
module Psych
module Nodes
###
# The base class for any Node in a YAML parse tree. This class should
# never be instantiated.
class Node
include Enumerable
# The children of this node
attr_reader :children
# An associated tag
attr_reader :tag
... | Ruby |
module Psych
module Nodes
###
# Represents a YAML stream. This is the root node for any YAML parse
# tree. This node must have one or more child nodes. The only valid
# child node for a Psych::Nodes::Stream node is Psych::Nodes::Document.
class Stream < Psych::Nodes::Node
# Encodings sup... | Ruby |
module Psych
module Nodes
###
# This class represents a
# {YAML sequence}[http://yaml.org/spec/1.1/#sequence/syntax].
#
# A YAML sequence is basically a list, and looks like this:
#
# %YAML 1.1
# ---
# - I am
# - a Sequence
#
# A YAML sequence may have an anchor... | Ruby |
module Psych
###
# Psych::Stream is a streaming YAML emitter. It will not buffer your YAML,
# but send it straight to an IO.
#
# Here is an example use:
#
# stream = Psych::Stream.new($stdout)
# stream.start
# stream.push({:foo => 'bar'})
# stream.finish
#
# YAML will be immediately emi... | Ruby |
require 'strscan'
module Psych
###
# Scan scalars for built in types
class ScalarScanner
# Taken from http://yaml.org/type/timestamp.html
TIME = /^\d{4}-\d{1,2}-\d{1,2}([Tt]|\s+)\d{1,2}:\d\d:\d\d(\.\d*)?(\s*Z|[-+]\d{1,2}(:\d\d)?)?/
# Taken from http://yaml.org/type/float.html
FLOAT = /^(?:[-+]?(... | Ruby |
module Psych
class Set < ::Hash
end
end
| Ruby |
require 'mkmf'
# :stopdoc:
dir_config 'libyaml'
def asplode missing
raise "#{missing} is missing. Please install libyaml."
end
asplode('yaml.h') unless find_header 'yaml.h'
asplode('libyaml') unless find_library 'yaml', 'yaml_get_version'
create_makefile 'psych'
# :startdoc:
| Ruby |
require 'mkmf'
$INCFLAGS << " -I$(topdir) -I$(top_srcdir)"
create_makefile('coverage')
| Ruby |
module RDoc
module Page
FONTS = "\"Bitstream Vera Sans\", Verdana, Arial, Helvetica, sans-serif"
STYLE = <<CSS
a {
color: #00F;
text-decoration: none;
}
a:hover {
color: #77F;
text-decoration: underline;
}
body, td, p {
font-family: %fonts%;
background: #FFF;
color: #000;
margin: 0px;
font-size: s... | Ruby |
# Example Rakefile -*- ruby -*-
task :default => [:main]
file "a.o" => ["a.c"] do |t|
src = t.name.sub(/\.o$/, '.c')
sh "gcc #{src} -c -o #{t.name}"
end
file "b.o" => ["b.c"] do |t|
src = t.name.sub(/\.o$/, '.c')
sh "gcc #{src} -c -o #{t.name}"
end
file "main.o" => ["main.c"] do |t|
src = t.name.sub(/\.o$... | Ruby |
# Example Rakefile -*- ruby -*-
# Using the power of Ruby
task :default => [:main]
def ext(fn, newext)
fn.sub(/\.[^.]+$/, newext)
end
SRCFILES = Dir['*.c']
OBJFILES = SRCFILES.collect { |fn| ext(fn,".o") }
OBJFILES.each do |objfile|
srcfile = ext(objfile, ".c")
file objfile => [srcfile] do |t|
sh "gcc #{s... | Ruby |
#
# YARV benchmark driver
#
require 'yarvutil'
require 'benchmark'
require 'rbconfig'
def exec_command type, file, w
<<-EOP
$DRIVER_PATH = '#{File.dirname($0)}'
$LOAD_PATH.replace $LOAD_PATH | #{$LOAD_PATH.inspect}
require 'benchmark'
require 'yarvutil'
# print '#{type}'
begin
puts Benchmark.measure{... | Ruby |
i = 0
obj = Object.new
while i<30_000_000 # while loop 1
i+= 1
!obj
end
| Ruby |
5_000.times{
t = Thread.new{}
while t.alive?
Thread.pass
end
}
| Ruby |
def m &b
b
end
pr = m{
a = 1
}
i=0
while i<6_000_000 # benchmark loop 2
i+=1
pr.call
end
| Ruby |
i=0
while i<200_000
i+=1
Class.new{
def m; end
}
end
| Ruby |
# 1000 threads, one mutex
require 'thread'
m = Mutex.new
r = 0
max = 2000
(1..max).map{
Thread.new{
i=0
while i<max
i+=1
m.synchronize{
r += 1
}
end
}
}.each{|e|
e.join
}
raise r.to_s if r != max * max
| Ruby |
30_000_000.times{|e|}
| Ruby |
#!/usr/bin/ruby
# -*- mode: ruby -*-
# $Id: nestedloop-ruby.code,v 1.4 2004/11/13 07:42:22 bfulgham Exp $
# http://www.bagley.org/~doug/shootout/
# from Avi Bryant
n = 16 # Integer(ARGV.shift || 1)
x = 0
n.times do
n.times do
n.times do
n.times do
n.times do
... | Ruby |
# The Computer Language Shootout Benchmarks
# http://shootout.alioth.debian.org
#
# contributed by Jesse Millikan
# disable output
def STDOUT.write_ *args
end
def item_check(tree)
if tree[0] == nil
tree[1]
else
tree[1] + item_check(tree[0]) - item_check(tree[2])
end
end
def bottom_up_tree(item, depth)
if dep... | Ruby |
i=0
while i<300000
i+=1
begin
raise
rescue
end
end
| Ruby |
# prepare 'wc.input'
def prepare_wc_input
wcinput = File.join(File.dirname($0), 'wc.input')
wcbase = File.join(File.dirname($0), 'wc.input.base')
unless FileTest.exist?(wcinput)
data = File.read(wcbase)
13.times{
data << data
}
open(wcinput, 'w'){|f| f.write data}
end
end
prepare_wc_inp... | Ruby |
require 'thread'
m = Mutex.new
i=0
while i<6_000_000 # benchmark loop 2
i+=1
m.synchronize{}
end
| Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.