Module: Yadriggy::C

Defined in:
lib/yadriggy/c.rb,
lib/yadriggy/c/c.rb,
lib/yadriggy/c/ffi.rb,
lib/yadriggy/c/ctype.rb,
lib/yadriggy/c/config.rb,
lib/yadriggy/c/opencl.rb,
lib/yadriggy/c/codegen.rb,
lib/yadriggy/c/program.rb,
lib/yadriggy/c/ctypecheck.rb

Overview

C language embedded in Ruby

Defined Under Namespace

Modules: CType, Config Classes: ArrayType, BuildError, ClangTypeChecker, CodeGen, FFIArray, Float32Array, FloatArray, ForeignMethodType, IntArray, NativeMethodType, OclCodeGen, OclTypeChecker, Program, WithReturnType

Class Method Summary collapse

Class Method Details

.compile(obj, lib_name = nil, dir = Config::WorkDir, module_name = nil) ⇒ Module

Compiles methods into binary code.

Parameters:

  • obj (Proc|Method|UnboundMethod|Object)

    the exposed method or a block. If obj is neither a method or a block, all the public methods available on obj are exposed. The methods invoked by the exposed methods are also compiled.

  • lib_name (String) (defaults to: nil)

    the library name.

  • dir (String) (defaults to: Config::WorkDir)

    the directory name.

  • module_name (String) (defaults to: nil)

    the module name where the exposed methods are attached when the generated Ruby script is executed. If method_name is nil, no Ruby script is generated.

Returns:

  • (Module)

    the module object where the exposed methods are attached. It does not have a name.



92
93
94
95
96
# File 'lib/yadriggy/c/c.rb', line 92

def self.compile(obj, lib_name=nil, dir=Config::WorkDir, module_name=nil)
  mod, funcs = compile0(obj, lib_name, dir, module_name,
                        ClangTypeChecker, CodeGen)[0]
  mod
end

.ocl_compile(obj, lib_name = nil, dir = Config::WorkDir, module_name = nil) ⇒ Object

Compiles OpenCL methods into binary code.



13
14
15
16
17
18
# File 'lib/yadriggy/c/opencl.rb', line 13

def self.ocl_compile(obj, lib_name=nil, dir=Config::WorkDir,
                     module_name=nil)
  mod, funcs = compile0(obj, lib_name, dir, module_name,
                        OclTypeChecker, OclCodeGen)
  mod
end

.run(lib_name = nil, *args, dir: Config::WorkDir, &block) ⇒ Object

Compiles and runs a block.

Parameters:

  • lib_name (String) (defaults to: nil)

    the library name.

  • dir (String) (defaults to: Config::WorkDir)

    the directory name.

  • args (Object...)

    the arguments to the block.

Returns:

  • (Object)

    the result of running the given block.

Raises:



213
214
215
216
217
218
# File 'lib/yadriggy/c/c.rb', line 213

def self.run(lib_name=nil, *args, dir: Config::WorkDir, &block)
  raise BuildError.new('no block given') if block.nil?
  mod, mths = compile0(block, lib_name, dir, nil,
                       ClangTypeChecker, CodeGen)
  mod.method(mths[0]).call(*args)
end

.syntaxSyntax

Returns the syntax.

Returns:



75
76
77
# File 'lib/yadriggy/c/c.rb', line 75

def self.syntax
  @syntax
end