module Klam::CompilationStages::StripTypeDeclarations

Strip Type Declarations

The Kl type primitive is provided to pass type hints from the Shen compiler to the Kl compiler. Klam does not make use of them, so they are removed in this stage to simplify the s-expression and avoid having to take the type primitive into account when optimizing self tail calls.

Public Instance Methods

strip_type_declarations(sexp) click to toggle source
# File lib/klam/compilation_stages/strip_type_declarations.rb, line 10
def strip_type_declarations(sexp)
  if sexp.instance_of?(Array)
    if sexp[0] == :type
      _, form, _ = sexp
      strip_type_declarations(form)
    else
      sexp.map { |form| strip_type_declarations(form) }
    end
  else
    sexp
  end
end