Second part of my article on Crystal lang

The source code for those interested GitHub - MarioAriasC/monyet: An implementation of the monkey language on Crystal

5 Likes

Regarding the optimization of offset, it may be possible to change so that you use a Slice instead of an Array, and therefore get the same behavior as the Go implementation.

1 Like

Exactly! I was going to mention that Slice(UInt8), which is aliased to Bytes because it’s so common, might be a better representation for alias Instructions = Array(UInt8). Taking ranges of a Slice doesn’t allocate memory. And it’s not a coincidence this type is called “Slice” :wink:

Also, do you have a link to the source code? I’m sure me and others will jump into the code and try to further optimize it :smile:

Regarding your type_desc method. There’s really no need to use an actual macro here. Since macro expansion happens on each subclass, you can just define MObject as:

abstract class MObject
  def type_desc : String
    {{@type.name.stringify}}
  end
end

and it’ll just work.

Also Crystal is on TechEmpowered, but not all frameworks: TechEmpower Framework Benchmarks.

I added it

I’ll try it

Also, I’ll correct my mistake about the frameworks on TechEmpower Framework Benchmarks, my bad.

2 Likes

I did read about the Slice type but was unclear to me how to use it. I’ll have another look

1 Like