Module: Jade::Codegen::Emitter
- Included in:
- Jade::Codegen, Emitter
- Defined in:
- lib/jade/codegen/emitter.rb
Constant Summary
Constants included from Helpers
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
#emit(ir) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/jade/codegen/emitter.rb', line 9 def emit(ir) case ir in [:var, expr] expr in [:!, expr] "!(#{emit(expr)})" in [:and, expr1, expr2] "#{emit(expr1)} && #{emit(expr2)}" in Integer | TrueClass | FalseClass | Float ir.to_s in String ir.inspect in [:case, subject, branches] branches .map { [:case_branch, *it] } .map { emit(it) } .join("\n") .then { "case #{emit(subject)}\n#{it}\nend" } in [:case_branch, pattern, body] body .map { emit(it) }.join('; ') .then { "in #{emit(pattern)} then #{it}" } in [:call, callee, args] args .map { emit(it) } .join(', ') .then { "#{emit(callee)}.call(#{it})"} in [:impl_arg, index, fn] "impl_arg[#{index}]['#{fn}']" in [:stdlib_fn, name] "Jade::Runtime.intr(#{name.inspect})" in [:struct_constructor, qualified_name, arity] "#{to_qualified(qualified_name)}.method(:[]).curry(#{arity})" in [:anon_record_constructor, keys] "#{data_define(keys)}.method(:[]).curry(#{keys.size})" in [:list, exprs] exprs .map { emit(it) } .join(', ') .then { "[#{it}]" } in [:access, expr, key] "#{emit(expr)}.#{key}" # patterns in [:constructor, name, args] args .map { "#{it}" } .join(',') .then { "#{to_qualified(name)}(#{it})" } in [:_] '_' end end |