class Ven::Optimizer

Overview

Peephole optimizer for Ven unstitched chunks.

Matches sequences of bytecode instructions against patterns, and, based on that, folds, removes or modifies them.

puts Optimizer.optimize(unstitched_chunks) # => stitched chunks

Included Modules

Defined in:

ven/optimize.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(chunks : Chunks) #

Makes an Optimizer from chunks, an array of unstitched chunks.


[View source]

Class Method Detail

def self.optimize(chunks, passes = 1) #

Given an array of unstitched chunks, chunks, optimizes them in passes passes. Stitches the optimized chunks and returns them.


[View source]

Instance Method Detail

def binary2n(operator : String, left : BigDecimal, right : BigDecimal) #

Computes, if possible, a binary operator, operator, with left and right being known BigDecimals (thus nums in Ven).

Returns nil if haven't optimized.


[View source]
def binary2s(operator : String, left : String, right : String) #

Computes, if possible, a binary operator, operator, with left and right being known Strings (thus strs in Ven).

Returns nil if haven't optimized.


[View source]
def optimize(chunk : Chunk) #

Goes over chunk's snippets, performing exactly one optimization first for threes, and then for twos of instructions in each snippet.

This method performs what's known as peephole optimization. It finds blobs of redundant or readily computable instructions, and eliminates them in various ways.


[View source]
def optimize(passes) #

Optimizes the chunks of this Optimizer in several passes.


[View source]