vidarh / writing-a-compiler-in-ruby

Code from my series on writing a Ruby compiler in Ruby
http://www.hokstad.com/compiler
273 stars 22 forks source link

Handling Symbol and Fixnum (and true, false and nil) #6

Open vidarh opened 15 years ago

vidarh commented 15 years ago

MRI uses type tagging for those. Need to decide whether to do type tagging (more complex code) or do what Python does (memoize small integers) - the benefit of the latter is simpler code. Another alternative is to do method calls, but handle Fixnum "specially" for inline caching... This will cause crashes when we get the compiler to compile.

The simplest may be to implement Fixnum/Symbol as normal classes to start with.

True, false and nil are much simpler as they're single objects so avoiding type tagging is ok to start with, though not necessarily good in terms of performance.