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