Module: Jade::Codegen::Boundary
- Extended by:
- Boundary, Helpers
- Included in:
- Boundary
- Defined in:
- lib/jade/codegen/boundary.rb,
lib/jade/codegen/boundary/cache.rb,
lib/jade/codegen/boundary/specialized.rb,
lib/jade/codegen/boundary/specialized/list.rb,
lib/jade/codegen/boundary/specialized/maybe.rb,
lib/jade/codegen/boundary/specialized/record.rb,
lib/jade/codegen/boundary/specialized/scalar.rb
Defined Under Namespace
Modules: Cache, Specialized
Constant Summary
collapse
- DECODABLE =
'Decode.Decodable'
- ENCODABLE =
'Encode.Encodable'
- VALUE_PASSTHROUGH_DECODER =
'Jade::Decode::Decoder[Jade::Decode::Desc::Pass[]]'
- VALUE_IDENTITY_ENCODER =
'->(v) { v }'
- NEVER_ENCODER =
'->(_) { fail "Never arm produced a value" }'
Constants included
from Helpers
Helpers::NATIVE_RUBY_CLASSES
Instance Method Summary
collapse
Methods included from Helpers
data_define, dict_constraints, dict_synthetic_name, fn_constraints, fn_impl_synthetic_name, generate_many, generate_node, impl_synthetic_name, param_synthetic_name, resolve_callee_symbol, ruby_classes_for_type, to_qualified
Instance Method Details
#decoder_for(type, registry) ⇒ Object
16
17
18
19
20
21
22
23
24
|
# File 'lib/jade/codegen/boundary.rb', line 16
def decoder_for(type, registry)
case type
in Type::Application(constructor: Type::Constructor(name:), args:)
decode_app(name, args, registry)
else
nil
end
end
|
#eligible?(fn_type, registry) ⇒ Boolean
36
37
38
39
40
|
# File 'lib/jade/codegen/boundary.rb', line 36
def eligible?(fn_type, registry)
args, return_type = Type.signature(fn_type)
args.all? { decoder_for(it, registry) } &&
return_eligible?(return_type, registry)
end
|
#encoder_for(type, registry) ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/jade/codegen/boundary.rb', line 26
def encoder_for(type, registry)
case type
in Type::Application(constructor: Type::Constructor(name:), args:)
encode_app(name, args, registry)
else
nil
end
end
|
#return_eligible?(type, registry) ⇒ Boolean
Task in return position needs both arms encodable — the wrapper discriminates the outcome rather than producing an encoded Task. Everything else checks the type’s own encoder directly.
45
46
47
48
49
50
51
52
53
|
# File 'lib/jade/codegen/boundary.rb', line 45
def return_eligible?(type, registry)
case type
in Type::Application(constructor: Type::Constructor(name: 'Task.Task'), args: [ok_t, err_t])
!encoder_for(ok_t, registry).nil? && !encoder_for(err_t, registry).nil?
else
!encoder_for(type, registry).nil?
end
end
|
#task_arms(task_type, registry) ⇒ Object
55
56
57
58
59
60
61
62
63
|
# File 'lib/jade/codegen/boundary.rb', line 55
def task_arms(task_type, registry)
task_type => Type::Application(
constructor: Type::Constructor(name: 'Task.Task'),
args: [ok_t, err_t],
)
ok_enc = encoder_for(ok_t, registry)
err_enc = encoder_for(err_t, registry)
[ok_enc, err_enc] if ok_enc && err_enc
end
|