File: concrete-syntax/core/declaration/function.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Umu#6
  module: ConcreteSyntax#8
  module: Core#10
  module: Declaration#12
has properties
function: make_function / 2 #83
function: make_recursive_function / 2 #90
  module: Function#14
  class: Abstract#16
inherits from
  Abstract ( Umu::ConcreteSyntax::Core::Declaration )
has properties
attribute: lam_expr [R] #17
method: initialize / 2 #20
method: to_s #29
method: exported_vars #34
method: __desugar__ / 2 #41
  class: Simple#52
inherits from
  Abstract ( Umu::ConcreteSyntax::Core::Declaration::Function )
has properties
method: to_s #53
method: pretty_print / 1 #58
  class: Recursive#66
inherits from
  Abstract ( Umu::ConcreteSyntax::Core::Declaration::Function )
has properties
method: to_s #67
method: pretty_print / 1 #72

Code

   1  # coding: utf-8
   2  # frozen_string_literal: true
   3 
   4 
   5 
   6  module Umu
   7 
   8  module ConcreteSyntax
   9 
  10  module Core
  11 
  12  module Declaration
  13 
  14  module Function
  15 
  16  class Abstract < Declaration::Abstract
  17      attr_reader :lam_expr
  18 
  19 
  20      def initialize(loc, lam_expr)
  21          ASSERT.kind_of lam_expr, CSCEN::Lambda::Named
  22 
  23          super(loc)
  24 
  25          @lam_expr = lam_expr
  26      end
  27 
  28 
  29      def to_s
  30          format "%%FUN %s", self.lam_expr.to_s
  31      end
  32 
  33 
  34      def exported_vars
  35          [CSCP.make_variable(self.loc, self.lam_expr.sym)].freeze
  36      end
  37 
  38 
  39  private
  40 
  41      def __desugar__(env, event)
  42          ASCD.make_value(
  43              self.loc,
  44              self.lam_expr.sym,
  45              self.lam_expr.desugar(env.enter(event))
  46          )
  47      end
  48  end
  49 
  50 
  51 
  52  class Simple < Abstract
  53      def to_s
  54          format "%%FUN %s", self.lam_expr.to_s
  55      end
  56 
  57 
  58      def pretty_print(q)
  59          q.text '%FUN '
  60          q.pp self.lam_expr
  61      end
  62  end
  63 
  64 
  65 
  66  class Recursive < Abstract
  67      def to_s
  68          self.lam_expr.to_s
  69      end
  70 
  71 
  72      def pretty_print(q)
  73          q.pp self.lam_expr
  74      end
  75  end
  76 
  77  end # Umu::ConcreteSyntax::Core::Declaration::Function
  78 
  79 
  80 
  81  module_function
  82 
  83      def make_function(loc, lam_expr)
  84          ASSERT.kind_of lam_expr, CSCEN::Lambda::Named
  85 
  86          Function::Simple.new(loc, lam_expr).freeze
  87      end
  88 
  89 
  90      def make_recursive_function(loc, lam_expr)
  91          ASSERT.kind_of lam_expr, CSCEN::Lambda::Named
  92 
  93          Function::Recursive.new(loc, lam_expr).freeze
  94      end
  95 
  96  end # Umu::ConcreteSyntax::Core::Declaration
  97 
  98  end # Umu::ConcreteSyntax::Core
  99 
 100  end # Umu::ConcreteSyntax
 101 
 102  end # Umu