1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[Feature #16254] Use Primitive.func style

This commit is contained in:
Nobuyoshi Nakada 2020-05-31 15:52:32 +09:00
parent 49f0fd21e4
commit 63aadc237f
Notes: git 2020-06-19 18:47:19 +09:00
9 changed files with 58 additions and 58 deletions

View file

@ -13,7 +13,7 @@ class Array
#
# a.shuffle!(random: Random.new(1)) #=> [1, 3, 2]
def shuffle!(random: Random)
__builtin.rb_ary_shuffle_bang(random)
Primitive.rb_ary_shuffle_bang(random)
end
# call-seq:
@ -30,7 +30,7 @@ class Array
#
# a.shuffle(random: Random.new(1)) #=> [1, 3, 2]
def shuffle(random: Random)
__builtin.rb_ary_shuffle(random)
Primitive.rb_ary_shuffle(random)
end
# call-seq:
@ -57,6 +57,6 @@ class Array
# a.sample(random: Random.new(1)) #=> 6
# a.sample(4, random: Random.new(1)) #=> [6, 10, 9, 2]
def sample(n = (ary = false), random: Random)
__builtin.rb_ary_sample(random, n, ary)
Primitive.rb_ary_sample(random, n, ary)
end
end

20
ast.rb
View file

@ -32,7 +32,7 @@ class RubyVM
# RubyVM::AbstractSyntaxTree.parse("x = 1 + 2")
# # => #<RubyVM::AbstractSyntaxTree::Node:SCOPE@1:0-1:9>
def self.parse string
__builtin.ast_s_parse string
Primitive.ast_s_parse string
end
# call-seq:
@ -47,7 +47,7 @@ class RubyVM
# RubyVM::AbstractSyntaxTree.parse_file("my-app/app.rb")
# # => #<RubyVM::AbstractSyntaxTree::Node:SCOPE@1:0-31:3>
def self.parse_file pathname
__builtin.ast_s_parse_file pathname
Primitive.ast_s_parse_file pathname
end
# call-seq:
@ -66,7 +66,7 @@ class RubyVM
# RubyVM::AbstractSyntaxTree.of(method(:hello))
# # => #<RubyVM::AbstractSyntaxTree::Node:SCOPE@1:0-3:3>
def self.of body
__builtin.ast_s_of body
Primitive.ast_s_of body
end
# RubyVM::AbstractSyntaxTree::Node instances are created by parse methods in
@ -88,7 +88,7 @@ class RubyVM
# call = lasgn.children[1]
# call.type # => :OPCALL
def type
__builtin.ast_node_type
Primitive.ast_node_type
end
# call-seq:
@ -96,7 +96,7 @@ class RubyVM
#
# The line number in the source code where this AST's text began.
def first_lineno
__builtin.ast_node_first_lineno
Primitive.ast_node_first_lineno
end
# call-seq:
@ -104,7 +104,7 @@ class RubyVM
#
# The column number in the source code where this AST's text began.
def first_column
__builtin.ast_node_first_column
Primitive.ast_node_first_column
end
# call-seq:
@ -112,7 +112,7 @@ class RubyVM
#
# The line number in the source code where this AST's text ended.
def last_lineno
__builtin.ast_node_last_lineno
Primitive.ast_node_last_lineno
end
# call-seq:
@ -120,7 +120,7 @@ class RubyVM
#
# The column number in the source code where this AST's text ended.
def last_column
__builtin.ast_node_last_column
Primitive.ast_node_last_column
end
# call-seq:
@ -131,7 +131,7 @@ class RubyVM
#
# The returned array may contain other nodes or <code>nil</code>.
def children
__builtin.ast_node_children
Primitive.ast_node_children
end
# call-seq:
@ -139,7 +139,7 @@ class RubyVM
#
# Returns debugging information about this node as a string.
def inspect
__builtin.ast_node_inspect
Primitive.ast_node_inspect
end
end
end

10
dir.rb
View file

@ -12,12 +12,12 @@ class Dir
# directory is closed at the end of the block, and Dir::open returns
# the value of the block.
def self.open(name, encoding: nil, &block)
dir = __builtin.dir_s_open(name, encoding)
dir = Primitive.dir_s_open(name, encoding)
if block
begin
yield dir
ensure
__builtin.dir_s_close(dir)
Primitive.dir_s_close(dir)
end
else
dir
@ -32,7 +32,7 @@ class Dir
# The optional <i>encoding</i> keyword argument specifies the encoding of the directory.
# If not specified, the filesystem encoding is used.
def initialize(name, encoding: nil)
__builtin.dir_initialize(name, encoding)
Primitive.dir_initialize(name, encoding)
end
# Dir[ string [, string ...] [, base: path] [, sort: true] ] -> array
@ -40,7 +40,7 @@ class Dir
# Equivalent to calling
# <code>Dir.glob([</code><i>string,...</i><code>], 0)</code>.
def self.[](*args, base: nil, sort: true)
__builtin.dir_s_aref(args, base, sort)
Primitive.dir_s_aref(args, base, sort)
end
# Dir.glob( pattern, [flags], [base: path] [, sort: true] ) -> array
@ -133,6 +133,6 @@ class Dir
# librbfiles = File.join("**", "lib", "*.rb")
# Dir.glob(librbfiles) #=> ["lib/song.rb"]
def self.glob(pattern, _flags = 0, flags: _flags, base: nil, sort: true)
__builtin.dir_s_glob(pattern, flags, base, sort)
Primitive.dir_s_glob(pattern, flags, base, sort)
end
end

24
gc.rb
View file

@ -31,11 +31,11 @@ module GC
# are not guaranteed to be future-compatible, and may be ignored if the
# underlying implementation does not support them.
def self.start full_mark: true, immediate_mark: true, immediate_sweep: true
__builtin.gc_start_internal full_mark, immediate_mark, immediate_sweep
Primitive.gc_start_internal full_mark, immediate_mark, immediate_sweep
end
def garbage_collect full_mark: true, immediate_mark: true, immediate_sweep: true
__builtin.gc_start_internal full_mark, immediate_mark, immediate_sweep
Primitive.gc_start_internal full_mark, immediate_mark, immediate_sweep
end
# call-seq:
@ -49,7 +49,7 @@ module GC
# GC.enable #=> false
#
def self.enable
__builtin.gc_enable
Primitive.gc_enable
end
# call-seq:
@ -61,7 +61,7 @@ module GC
# GC.disable #=> false
# GC.disable #=> true
def self.disable
__builtin.gc_disable
Primitive.gc_disable
end
# call-seq:
@ -69,7 +69,7 @@ module GC
#
# Returns current status of GC stress mode.
def self.stress
__builtin.gc_stress_get
Primitive.gc_stress_get
end
# call-seq:
@ -87,7 +87,7 @@ module GC
# 0x02:: no immediate sweep
# 0x04:: full mark after malloc/calloc/realloc
def self.stress=(flag)
__builtin.gc_stress_set_m flag
Primitive.gc_stress_set_m flag
end
# call-seq:
@ -97,7 +97,7 @@ module GC
#
# It returns the number of times GC occurred since the process started.
def self.count
__builtin.gc_count
Primitive.gc_count
end
# call-seq:
@ -146,7 +146,7 @@ module GC
#
# This method is only expected to work on C Ruby.
def self.stat hash_or_key = nil
__builtin.gc_stat hash_or_key
Primitive.gc_stat hash_or_key
end
# call-seq:
@ -160,11 +160,11 @@ module GC
# it is overwritten and returned.
# This is intended to avoid probe effect.
def self.latest_gc_info hash_or_key = nil
__builtin.gc_latest_gc_info hash_or_key
Primitive.gc_latest_gc_info hash_or_key
end
def self.compact
__builtin.rb_gc_compact
Primitive.rb_gc_compact
end
# call-seq:
@ -182,13 +182,13 @@ module GC
# object, that object should be pushed on the mark stack, and will
# make a SEGV.
def self.verify_compaction_references(toward: nil, double_heap: false)
__builtin.gc_verify_compaction_references(toward, double_heap)
Primitive.gc_verify_compaction_references(toward, double_heap)
end
end
module ObjectSpace
def garbage_collect full_mark: true, immediate_mark: true, immediate_sweep: true
__builtin.gc_start_internal full_mark, immediate_mark, immediate_sweep
Primitive.gc_start_internal full_mark, immediate_mark, immediate_sweep
end
module_function :garbage_collect

4
io.rb
View file

@ -60,7 +60,7 @@ class IO
# return the symbol +:wait_readable+ instead. At EOF, it will return nil
# instead of raising EOFError.
def read_nonblock(len, buf = nil, exception: true)
__builtin.io_read_nonblock(len, buf, exception)
Primitive.io_read_nonblock(len, buf, exception)
end
# call-seq:
@ -118,6 +118,6 @@ class IO
# that write_nonblock should not raise an IO::WaitWritable exception, but
# return the symbol +:wait_writable+ instead.
def write_nonblock(buf, exception: true)
__builtin.io_write_nonblock(buf, exception)
Primitive.io_write_nonblock(buf, exception)
end
end

View file

@ -24,7 +24,7 @@ module Kernel
# the class.
#
def clone(freeze: nil)
__builtin.rb_obj_clone2(freeze)
Primitive.rb_obj_clone2(freeze)
end
module_function
@ -48,6 +48,6 @@ module Kernel
# Float("123.0_badstring", exception: false) #=> nil
#
def Float(arg, exception: true)
__builtin.rb_f_float(arg, exception)
Primitive.rb_f_float(arg, exception)
end
end

View file

@ -131,7 +131,7 @@ class Array
# X | --- | back up a byte
# x | --- | null byte
def pack(fmt, buffer: nil)
__builtin.pack_pack(fmt, buffer)
Primitive.pack_pack(fmt, buffer)
end
end
@ -254,7 +254,7 @@ class String
# * Q_, Q!, q_, and q! are available since Ruby 2.1.
# * I!<, i!<, I!>, and i!> are available since Ruby 1.9.3.
def unpack(fmt)
__builtin.pack_unpack(fmt)
Primitive.pack_unpack(fmt)
end
# call-seq:
@ -278,6 +278,6 @@ class String
# Thus unpack1 is convenient, makes clear the intention and signals
# the expected return value to those reading the code.
def unpack1(fmt)
__builtin.pack_unpack1(fmt)
Primitive.pack_unpack1(fmt)
end
end

View file

@ -93,7 +93,7 @@ class TracePoint
# Access from other threads is also forbidden.
#
def self.new(*events)
__builtin.tracepoint_new_s(events)
Primitive.tracepoint_new_s(events)
end
# call-seq:
@ -102,7 +102,7 @@ class TracePoint
# Return a string containing a human-readable TracePoint
# status.
def inspect
__builtin.tracepoint_inspect
Primitive.tracepoint_inspect
end
# call-seq:
@ -115,7 +115,7 @@ class TracePoint
#
# This method is only for debugging TracePoint itself.
def self.stat
__builtin.tracepoint_stat_s
Primitive.tracepoint_stat_s
end
# Document-method: trace
@ -132,7 +132,7 @@ class TracePoint
# trace.enabled? #=> true
#
def self.trace(*events)
__builtin.tracepoint_trace_s(events)
Primitive.tracepoint_trace_s(events)
end
# call-seq:
@ -193,7 +193,7 @@ class TracePoint
# #=> RuntimeError: access from outside
#
def enable(target: nil, target_line: nil, target_thread: nil)
__builtin.tracepoint_enable_m(target, target_line, target_thread)
Primitive.tracepoint_enable_m(target, target_line, target_thread)
end
# call-seq:
@ -229,7 +229,7 @@ class TracePoint
# trace.disable { p tp.lineno }
# #=> RuntimeError: access from outside
def disable
__builtin.tracepoint_disable_m
Primitive.tracepoint_disable_m
end
# call-seq:
@ -237,40 +237,40 @@ class TracePoint
#
# The current status of the trace
def enabled?
__builtin.tracepoint_enabled_p
Primitive.tracepoint_enabled_p
end
# Type of event
#
# See TracePoint@Events for more information.
def event
__builtin.tracepoint_attr_event
Primitive.tracepoint_attr_event
end
# Line number of the event
def lineno
__builtin.tracepoint_attr_lineno
Primitive.tracepoint_attr_lineno
end
# Path of the file being run
def path
__builtin.tracepoint_attr_path
Primitive.tracepoint_attr_path
end
# Return the parameters definition of the method or block that the
# current hook belongs to. Format is the same as for Method#parameters
def parameters
__builtin.tracepoint_attr_parameters
Primitive.tracepoint_attr_parameters
end
# Return the name at the definition of the method being called
def method_id
__builtin.tracepoint_attr_method_id
Primitive.tracepoint_attr_method_id
end
# Return the called name of the method being called
def callee_id
__builtin.tracepoint_attr_callee_id
Primitive.tracepoint_attr_callee_id
end
# Return class or module of the method being called.
@ -306,12 +306,12 @@ class TracePoint
# C.foo
# end
def defined_class
__builtin.tracepoint_attr_defined_class
Primitive.tracepoint_attr_defined_class
end
# Return the generated binding object from event
def binding
__builtin.tracepoint_attr_binding
Primitive.tracepoint_attr_binding
end
# Return the trace object during event
@ -319,23 +319,23 @@ class TracePoint
# Same as TracePoint#binding:
# trace.binding.eval('self')
def self
__builtin.tracepoint_attr_self
Primitive.tracepoint_attr_self
end
# Return value from +:return+, +c_return+, and +b_return+ event
def return_value
__builtin.tracepoint_attr_return_value
Primitive.tracepoint_attr_return_value
end
# Value from exception raised on the +:raise+ event
def raised_exception
__builtin.tracepoint_attr_raised_exception
Primitive.tracepoint_attr_raised_exception
end
# Compiled source code (String) on *eval methods on the +:script_compiled+ event.
# If loaded from a file, it will return nil.
def eval_script
__builtin.tracepoint_attr_eval_script
Primitive.tracepoint_attr_eval_script
end
# Compiled instruction sequence represented by a RubyVM::InstructionSequence instance
@ -343,6 +343,6 @@ class TracePoint
#
# Note that this method is MRI specific.
def instruction_sequence
__builtin.tracepoint_attr_instruction_sequence
Primitive.tracepoint_attr_instruction_sequence
end
end

View file

@ -40,6 +40,6 @@ module Kernel
# baz.rb:6: warning: invalid call to foo
#
def warn(*msgs, uplevel: nil)
__builtin.rb_warn_m(msgs, uplevel)
Primitive.rb_warn_m(msgs, uplevel)
end
end