Module: Jade::Frontend::ForwardDeclaration::StructDeclaration

Extended by:
Helper, StructDeclaration
Included in:
StructDeclaration
Defined in:
lib/jade/frontend/forward_declaration/struct_declaration.rb

Instance Method Summary collapse

Methods included from Helper

deep_declare_node, figure_out_type, shallow_declare_node

Instance Method Details

#deep(node, entry, _) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/jade/frontend/forward_declaration/struct_declaration.rb', line 18

def deep(node, entry, _)
  node => AST::StructDeclaration(name:, record_type:)

  symbol = entry.lookup_type(name)

  figure_out_type(entry, record_type)
    .map do |record_type_symbol|
      constructor_fn_symbol = Symbol.constructor(
        name,
        record_type_symbol.fields.values,
        symbol.to_ref,
        nil,
      )

      record_type_symbol
        .then { symbol.with(record_type: it) }
        .then { entry.define(it) }
        .then { it.define(constructor_fn_symbol) }
    end
    .then { to_declaration_result(entry, it) }
end

#shallow(node, registry, entry) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/jade/frontend/forward_declaration/struct_declaration.rb', line 8

def shallow(node, registry, entry)
  node => AST::StructDeclaration(name:, type_params:)

  type_params
    .map { Symbol.var(it.name, it.range) }
    .then { Symbol.predeclared_struct(name, it, node.range) }
    .then { entry.define(it) }
    .then { Result[it, []] }
end