Monday, March 21, 2011

gcc -Winline and --param name=value

While tuning my language, Impulse, I found the gcc inline-optimization parameters. Look for --param name=value at the bottom of the page.

http://tigcc.ticalc.org/doc/comopts.html#SEC10
-Winline --param inline-unit-growth=10000 --param large-function-growth=10000
 --param max-inline-insns-single=10000
0m2.450s 40000000 'self' message sends with --param options
0m2.650s 40000000 'self' message sends without options

That's a 7.5% boost. While the binary is now twice as large, in my case the binary is still small - 100K stripped.

Friday, March 11, 2011

Kaffeine.js - A cleaned up JavaScript

Well, I found one language pretty close to what I was looking for in a better JavaScript:

http://weepy.github.com/kaffeine/

  • Backwards compatible with JavaScript
  • Uses @foo to to get the "real" this.foo
  • Uses CPS folding to flatten callbacks
  • Multiline strings, which come in handy
  • for(n of [1, 2, 3]) array iteration
  • String interpolation: "#{foo} was here"
  • Implicit functions: (foo) { alert(foo); }
  • Pipe operator for chaining the first arg
  • Default arguments, optional call parens
  • Implicit return (nice with implicit funcs)

Out of those, I think callback unfolding and the pipe operator are the most interesting beyond adding some niceties:
  ok = stomach.save!()
  meal.complete = ok
translates to:
  stomach.save(function(ok) {
    meal.complete = ok
  })
and...
  result = input | fn args
translates to:
  result = __.fn.call(this, input, args) 

C++ nested class that inherits parent

Ever wanted to nest a class that inherits from its parent class? It can be done simply by using a forward declaration:
class Value {

 public:

    Value( Frame& frame );

    template <typename T> class Type;

};

template <typename T>
class Value::Type : public Value {
 
 public:
  
    Type( T& frame ) : Value( frame ) { }

    T& getFrame() { return get<T>(); }

};
I use it to make Impulse values more specific and type safe:
Value value;  // Could be 10, "foo", WhoKnowsWhat
Value::Type<Symbol> symbol;  // Must be a Symbol

Monday, March 7, 2011

Limited numeric types in C++

I don't want random indicies to be passed to a custom array, so this is the closest thing I could think of. It basically creates a few static member variables, and doesn't allow you to create any more of those types by making the constructor private. The "explicit" is optional, but demonstrates how to disable implicit conversion.
Value foo( const Array& args )
{
    return args[Index::_0];  // Don't give me any int!
}

class Index {

 public:

    const size_t index() const { return _index; }

    static const Index _0;
    static const Index _1;
    static const Index _2;

 private:

    explicit Index( const size_t index ) : _index( index ) { }

    const size_t _index;

};

const Index Index::_0( 0 );
const Index Index::_1( 1 );
const Index Index::_2( 2 );

Monday, February 21, 2011

LESS: CSS done right

I wanted to start a new browser-based project out right - with tools to make me uber-productive. I found LESS, and will never turn back to plain CSS. Mighty as CSS3 is, LESS extends it with:

  • Variables
  • Mixins
  • Nesting
  • Math
  • Comments

Example:
.box {
  // Assign a variable
  @base: #f938ab;

  // Color functions
  color: saturate(@base, 5%);
  border-color: lighten(@base, 30%);

  // Same as .box div
  div {
    .box-shadow(0, 0, 5px, 0.4)
  }
}
http://lesscss.org/

The Joy of HTM5

...when most browsers support it :)
.button:before {
  display: block;
  content: attr(label);
  border-top: 1px solid #ffffff;
}

<div class="button" label="Save"></div>
http://www.w3schools.com/html5/tag_input.asp