class Ven::Optimizer
- Ven::Optimizer
- Reference
- Object
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.crConstructors
-
.new(chunks : Chunks)
Makes an Optimizer from chunks, an array of unstitched chunks.
Class Method Summary
-
.optimize(chunks, passes = 1)
Given an array of unstitched chunks, chunks, optimizes them in passes passes.
Instance Method Summary
-
#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).
-
#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).
-
#optimize(chunk : Chunk)
Goes over chunk's snippets, performing exactly one optimization first for threes, and then for twos of instructions in each snippet.
-
#optimize(passes)
Optimizes the chunks of this Optimizer in several passes.
Constructor Detail
Makes an Optimizer from chunks, an array of unstitched chunks.
Class Method Detail
Given an array of unstitched chunks, chunks, optimizes them in passes passes. Stitches the optimized chunks and returns them.
Instance Method Detail
Computes, if possible, a binary operator, operator, with left and right being known BigDecimals (thus nums in Ven).
Returns nil if haven't optimized.
Computes, if possible, a binary operator, operator, with left and right being known Strings (thus strs in Ven).
Returns nil if haven't optimized.
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.