SByC - Investigating Specialization by Constraint

synopsis

SByC is an investigation about Specialization by Constraint as an alternative to common type systems that we found in (object-oriented) programming languages. The library is written as a collection of Ruby tools described below. Those tools are in fact sub-gems of SByC that can often be used in isolation.

gem install sbyc

code tree

This part of SByC provides a safe, reusable, extensible, mashallable, and non-intrusive (no monkey patching of Ruby core classes) implementation of block expressions. Block expressions are parsed using a generic DSL and converted to a parse tree, which may be analyzed, rewrited, compiled, and so on. The example below illustrates typical usage of CodeTree.

code = CodeTree::parse{ x > 10 & y < 20 }   
# => (& (> x, 10), (< y, 20))

# See the evaluation section for details
code.eval{:x => 5, :y => 5}                
# => true

# See the code-generation section for details
code.object_compile('scope', :[])          
# => "scope[:x].>(10) & scope[:y].<(20)"

# CodeTree expressions may be marshaled
Marshal.dump(code)

Read more about CodeTree

type system

This part of SByC implements a TypeSystem abstraction. A type is simply collection of values. A type system is to generate and parse literals and to coerce from String values.

TypeSystem::Ruby::type_of(-125)
# => Fixnum

lit = TypeSystem::Ruby::to_literal(-125)
# => "-125"

TypeSystem::Ruby::parse_literal("-125")
# => -125

TypeSystem::Ruby::coerce('-125', Integer)
# => -125

Read more about TypeSystem

credits

SByC © 2010 by Bernard Lambeau. SByC is distributed under the MIT licence. Please see the LICENCE.md document for details.