Socket
Book a DemoInstallSign in
Socket

csquare

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csquare

0.1.0
bundlerRubygems
Version published
Maintainers
1
Created
Source

= CSquare

http://github.com/mohawkjohn/csquare

== Description

C, then D, C++, C# -- now C^2, simple C templates using Ruby.

Consider this to be a sort of carpenter's square. We call it C^2, or csquare. It's a simple tool for simple jobs.

This gem was developed for use in NMatrix (part of the SciRuby Project). We wanted to be able to write a single function and have it be modified to produce C sources for each datatype (rational, complex, integer, float, Ruby object, etc).

It also produces some rudimentary function pointer arrays if you so desire, so that these functions can be accessed using array notation.

Experimental! Use at your own risk. Actually, don't use this at all! It's extremely buggy and probably won't be useful for your purposes. It's really custom-designed to handle a specific use case: NMatrix dtype templates.

== Example

A full example is available in NMatrix starting at line 696: https://github.com/mohawkjohn/nmatrix/blob/csquare/ext/nmatrix/generator.rb

Full examples of templates are available here: https://github.com/mohawkjohn/nmatrix/tree/csquare/ext/nmatrix/templates

(Note that those templates and example are licensed as part of SciRuby.)

Here's a simple CSquare source for complex numbers:

# looks in templates/ directory, outputs "test.c" and "test.h"
g = CSquare::Generator.new("templates", "test") do |c|
  # Do this to register abbreviations for basic types
  c.template_type(:float, 'TYPE') do |t|
    t.type :f32, 'float'
    t.type :f64, 'double'
  end

  c.template_type(:complex, 'TYPE', :r => 'FLOAT', :i => 'FLOAT') do |t|

    t.type :c64, 'complex64', :long => :c128, 'FLOAT' => :f32
    t.type :c128, 'complex128', 'FLOAT' => :f64

    t.sources %w{div2 div4 mul2 mul4}

    t.op :'==', 'TYPE' => '$0.r == $1.r && $0.i == $1.i', [:integer, :float] => '$0.r == $1 && $0.i == 0'

    assign_str =
    t.op :'=', [:integer, :boolean, :float] => '$0 = (struct $t) { $1, 0 }'

    t.op :'*', 'TYPE' => 'mul2($0, $1)', :integer => 'mul4($0.r, $0.i, $1, 0)', :float => 'mul4($0.r, $0.i, $1, 0)'
    t.op :'/', 'TYPE' => 'div2($0, $1)', :integer => 'div4($0.r, $0.i, $1, 0)', :float => 'div4($0.r, $0.i, $1, 0)'
    t.op :'+', 'TYPE' => 'add2($0, $1)'
    t.op :'-', 'TYPE' => 'sub2($0, $1)'
  end
end

== Installation

gem install cast csquare

== License

BSD 2-clause. Copyright John Woods (mohawkjohn on github), 2012.

FAQs

Package last updated on 25 Jun 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.