Class: Erlang::ETF::Fun
Overview
1 | 4 | N1 | N2 | N3 | N4 | N5 |
---|---|---|---|---|---|---|
117 | NumFree | Pid | Module | Index | Uniq | Free vars ... |
Pid
is a process identifier as in
PID_EXT
. It represents the process in which the fun was created.
Module
is an encoded as an atom, using
ATOM_EXT
,SMALL_ATOM_EXT
orATOM_CACHE_REF
. This is the module that the fun is implemented in.
Index
is an integer encoded using
SMALL_INTEGER_EXT
orINTEGER_EXT
. It is typically a small index into the module's fun table.
Uniq
is an integer encoded using
SMALL_INTEGER_EXT
orINTEGER_EXT
.Uniq
is the hash value of the parse for the fun.
Free vars
is
NumFree
number of terms, each one encoded according to its type.
(see FUN_EXT
)
Constant Summary collapse
Constants included from Term
Term::ATOM_CACHE_REF, Term::ATOM_EXT, Term::ATOM_INTERNAL_REF2, Term::ATOM_INTERNAL_REF3, Term::ATOM_UTF8_EXT, Term::BINARY_ENCODING, Term::BINARY_EXT, Term::BINARY_INTERNAL_REF, Term::BIT_BINARY_EXT, Term::BIT_BINARY_INTERNAL_REF, Term::COMPRESSED, Term::DIST_HEADER, Term::DOUBLE, Term::DOUBLEBE, Term::DOUBLELE, Term::ERLANG_MAGIC_BYTE, Term::EXPORT_EXT, Term::FLOAT_EXT, Term::FUN_EXT, Term::INT128, Term::INT128BE, Term::INT128LE, Term::INT16, Term::INT16BE, Term::INT16LE, Term::INT32, Term::INT32BE, Term::INT32LE, Term::INT64, Term::INT64BE, Term::INT64LE, Term::INT8, Term::INTEGER_EXT, Term::LARGE_BIG_EXT, Term::LARGE_TUPLE_EXT, Term::LIST_EXT, Term::MAP_EXT, Term::NEW_FLOAT_EXT, Term::NEW_FUN_EXT, Term::NEW_REFERENCE_EXT, Term::NIL_EXT, Term::PID_EXT, Term::PORT_EXT, Term::REFERENCE_EXT, Term::SINGLE, Term::SINGLEBE, Term::SINGLELE, Term::SMALL_ATOM_EXT, Term::SMALL_ATOM_UTF8_EXT, Term::SMALL_BIG_EXT, Term::SMALL_INTEGER_EXT, Term::SMALL_TUPLE_EXT, Term::STRING_EXT, Term::UINT128, Term::UINT128BE, Term::UINT128LE, Term::UINT16, Term::UINT16BE, Term::UINT16LE, Term::UINT32, Term::UINT32LE, Term::UINT64, Term::UINT64BE, Term::UINT64LE, Term::UINT8
Class Method Summary collapse
- .[](term, pid = nil, mod = nil, index = nil, uniq = nil, free_vars = nil) ⇒ Object
- .erlang_load(buffer) ⇒ Object
Instance Method Summary collapse
- #erlang_dump(buffer = ::String.new.force_encoding(BINARY_ENCODING)) ⇒ Object
-
#initialize(term, pid = nil, mod = nil, index = nil, uniq = nil, free_vars = nil) ⇒ Fun
constructor
A new instance of Fun.
- #inspect ⇒ Object
- #pretty_print(pp) ⇒ Object
Methods included from Term
#<=>, binary_encoding, #eql?, #erlang_external_type, #hash, included, #to_erlang_etf
Constructor Details
#initialize(term, pid = nil, mod = nil, index = nil, uniq = nil, free_vars = nil) ⇒ Fun
Returns a new instance of Fun.
62 63 64 65 66 67 68 69 70 |
# File 'lib/erlang/etf/fun.rb', line 62 def initialize(term, pid = nil, mod = nil, index = nil, uniq = nil, free_vars = nil) raise ArgumentError, "term must be of type Erlang::Function" if not term.kind_of?(Erlang::Function) or term.new_function? @term = term @pid = pid @mod = mod @index = index @uniq = uniq @free_vars = free_vars end |
Class Method Details
.[](term, pid = nil, mod = nil, index = nil, uniq = nil, free_vars = nil) ⇒ Object
46 47 48 |
# File 'lib/erlang/etf/fun.rb', line 46 def [](term, pid = nil, mod = nil, index = nil, uniq = nil, free_vars = nil) return new(term, pid, mod, index, uniq, free_vars) end |
.erlang_load(buffer) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/erlang/etf/fun.rb', line 50 def erlang_load(buffer) num_free, = buffer.read(4).unpack(UINT32BE) pid = Erlang::ETF.read_term(buffer) mod = Erlang::ETF.read_term(buffer) index = Erlang::ETF.read_term(buffer) uniq = Erlang::ETF.read_term(buffer) free_vars = Array.new(num_free); num_free.times { |i| free_vars[i] = Erlang::ETF.read_term(buffer) } term = Erlang::Function[pid: Erlang.from(pid), mod: Erlang.from(mod), index: Erlang.from(index), uniq: Erlang.from(uniq), free_vars: Erlang.from(free_vars)] return new(term, pid, mod, index, uniq, free_vars) end |
Instance Method Details
#erlang_dump(buffer = ::String.new.force_encoding(BINARY_ENCODING)) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/erlang/etf/fun.rb', line 72 def erlang_dump(buffer = ::String.new.force_encoding(BINARY_ENCODING)) buffer << FUN_EXT free_vars = @free_vars || @term.free_vars num_free = free_vars.length buffer << [num_free].pack(UINT32BE) Erlang::ETF.write_term(@pid || @term.pid, buffer) Erlang::ETF.write_term(@mod || @term.mod, buffer) Erlang::ETF.write_term(@index || @term.index, buffer) Erlang::ETF.write_term(@uniq || @term.uniq, buffer) num_free.times { |i| Erlang::ETF.write_term(free_vars[i], buffer) } return buffer end |
#inspect ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/erlang/etf/fun.rb', line 85 def inspect if @pid.nil? and @mod.nil? and @index.nil? and @uniq.nil? and @free_vars.nil? return super else return "#{self.class}[#{@term.inspect}, #{@pid.inspect}, #{@mod.inspect}, #{@index.inspect}, #{@uniq.inspect}, #{@free_vars.inspect}]" end end |
#pretty_print(pp) ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/erlang/etf/fun.rb', line 93 def pretty_print(pp) state = [@term] state.push(@pid, @mod, @index, @uniq, @free_vars) if not @pid.nil? or not @mod.nil? or not @index.nil? or not @uniq.nil? or not @free_vars.nil? return pp.group(1, "#{self.class}[", "]") do pp.breakable '' pp.seplist(state) { |obj| obj.pretty_print(pp) } end end |