erlang-etf 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +3 -0
- data/Gemfile +10 -0
- data/README.md +3 -3
- data/Rakefile +3 -0
- data/erlang-etf.gemspec +0 -3
- data/lib/erlang/etf/atom.rb +28 -3
- data/lib/erlang/etf/atom_utf8.rb +27 -2
- data/lib/erlang/etf/binary.rb +10 -3
- data/lib/erlang/etf/bit_binary.rb +9 -5
- data/lib/erlang/etf/export.rb +12 -4
- data/lib/erlang/etf/extensions.rb +0 -19
- data/lib/erlang/etf/extensions/array.rb +0 -2
- data/lib/erlang/etf/extensions/big_decimal.rb +0 -2
- data/lib/erlang/etf/extensions/erlang-export.rb +0 -2
- data/lib/erlang/etf/extensions/erlang-list.rb +0 -2
- data/lib/erlang/etf/extensions/erlang-nil.rb +0 -2
- data/lib/erlang/etf/extensions/erlang-pid.rb +0 -2
- data/lib/erlang/etf/extensions/erlang-string.rb +13 -4
- data/lib/erlang/etf/extensions/erlang-tuple.rb +0 -2
- data/lib/erlang/etf/extensions/false_class.rb +0 -2
- data/lib/erlang/etf/extensions/float.rb +0 -2
- data/lib/erlang/etf/extensions/hash.rb +0 -2
- data/lib/erlang/etf/extensions/integer.rb +0 -2
- data/lib/erlang/etf/extensions/nil_class.rb +0 -2
- data/lib/erlang/etf/extensions/object.rb +0 -2
- data/lib/erlang/etf/extensions/regexp.rb +0 -2
- data/lib/erlang/etf/extensions/string.rb +0 -2
- data/lib/erlang/etf/extensions/symbol.rb +0 -2
- data/lib/erlang/etf/extensions/time.rb +0 -2
- data/lib/erlang/etf/extensions/true_class.rb +0 -2
- data/lib/erlang/etf/float.rb +9 -4
- data/lib/erlang/etf/fun.rb +26 -12
- data/lib/erlang/etf/integer.rb +7 -3
- data/lib/erlang/etf/large_big.rb +10 -5
- data/lib/erlang/etf/large_tuple.rb +6 -1
- data/lib/erlang/etf/list.rb +10 -5
- data/lib/erlang/etf/new_float.rb +7 -3
- data/lib/erlang/etf/new_fun.rb +47 -25
- data/lib/erlang/etf/new_reference.rb +14 -9
- data/lib/erlang/etf/nil.rb +8 -4
- data/lib/erlang/etf/pid.rb +13 -7
- data/lib/erlang/etf/port.rb +12 -6
- data/lib/erlang/etf/reference.rb +19 -10
- data/lib/erlang/etf/small_atom.rb +13 -6
- data/lib/erlang/etf/small_atom_utf8.rb +8 -3
- data/lib/erlang/etf/small_big.rb +14 -6
- data/lib/erlang/etf/small_integer.rb +7 -3
- data/lib/erlang/etf/small_tuple.rb +6 -2
- data/lib/erlang/etf/string.rb +6 -1
- data/lib/erlang/etf/version.rb +1 -1
- data/spec/erlang/etf/extensions/erlang-string_spec.rb +19 -4
- data/spec/erlang/etf/extensions/erlang-tuple_spec.rb +2 -1
- data/spec/erlang/etf/extensions/hash_spec.rb +3 -3
- data/spec/erlang/etf/large_tuple_spec.rb +1 -1
- data/spec/erlang_spec.rb +2 -1
- metadata +3 -44
@@ -6,16 +6,25 @@ module Erlang
|
|
6
6
|
|
7
7
|
module ErlangString
|
8
8
|
|
9
|
+
STRING_MAX = (+1 << 16) - 1
|
10
|
+
|
9
11
|
def __erlang_type__
|
10
|
-
|
12
|
+
if bytesize > STRING_MAX
|
13
|
+
:list
|
14
|
+
else
|
15
|
+
:string
|
16
|
+
end
|
11
17
|
end
|
12
18
|
|
13
19
|
def __erlang_evolve__
|
14
|
-
|
20
|
+
case __erlang_type__
|
21
|
+
when :list
|
22
|
+
ETF::List.new(unpack('C*'))
|
23
|
+
when :string
|
24
|
+
ETF::String.new(self)
|
25
|
+
end
|
15
26
|
end
|
16
27
|
|
17
|
-
module ClassMethods
|
18
|
-
end
|
19
28
|
end
|
20
29
|
end
|
21
30
|
end
|
data/lib/erlang/etf/float.rb
CHANGED
@@ -4,9 +4,9 @@ module Erlang
|
|
4
4
|
module ETF
|
5
5
|
|
6
6
|
#
|
7
|
-
# 1
|
8
|
-
#
|
9
|
-
# 99
|
7
|
+
# 1 | 31
|
8
|
+
# --- | ------------
|
9
|
+
# 99 | Float String
|
10
10
|
#
|
11
11
|
# A float is stored in string format. the format used in sprintf
|
12
12
|
# to format the float is "%.20e" (there are more bytes allocated
|
@@ -14,7 +14,12 @@ module Erlang
|
|
14
14
|
# "%lf".
|
15
15
|
#
|
16
16
|
# This term is used in minor version 0 of the external format; it
|
17
|
-
# has been superseded by NEW_FLOAT_EXT
|
17
|
+
# has been superseded by [`NEW_FLOAT_EXT`].
|
18
|
+
#
|
19
|
+
# (see [`FLOAT_EXT`])
|
20
|
+
#
|
21
|
+
# [`NEW_FLOAT_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#NEW_FLOAT_EXT
|
22
|
+
# [`FLOAT_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#FLOAT_EXT
|
18
23
|
#
|
19
24
|
class Float
|
20
25
|
include Term
|
data/lib/erlang/etf/fun.rb
CHANGED
@@ -6,23 +6,37 @@ module Erlang
|
|
6
6
|
# --- | ------- | --- | ------ | ----- | ---- | -------------
|
7
7
|
# 117 | NumFree | Pid | Module | Index | Uniq | Free vars ...
|
8
8
|
#
|
9
|
-
# Pid
|
10
|
-
#
|
9
|
+
# `Pid`
|
10
|
+
# > is a process identifier as in [`PID_EXT`]. It represents the
|
11
11
|
# process in which the fun was created.
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
12
|
+
#
|
13
|
+
# `Module`
|
14
|
+
# > is an encoded as an atom, using [`ATOM_EXT`], [`SMALL_ATOM_EXT`] or
|
15
|
+
# [`ATOM_CACHE_REF`]. This is the module that the fun is
|
15
16
|
# implemented in.
|
16
|
-
#
|
17
|
-
#
|
17
|
+
#
|
18
|
+
# `Index`
|
19
|
+
# > is an integer encoded using [`SMALL_INTEGER_EXT`] or [`INTEGER_EXT`].
|
18
20
|
# It is typically a small index into the module's fun table.
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
21
|
+
#
|
22
|
+
# `Uniq`
|
23
|
+
# > is an integer encoded using [`SMALL_INTEGER_EXT`] or [`INTEGER_EXT`].
|
24
|
+
# `Uniq` is the hash value of the parse for the fun.
|
25
|
+
#
|
26
|
+
# `Free vars`
|
27
|
+
# > is `NumFree` number of terms, each one encoded according to its
|
24
28
|
# type.
|
25
29
|
#
|
30
|
+
# (see [`FUN_EXT`])
|
31
|
+
#
|
32
|
+
# [`PID_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#PID_EXT
|
33
|
+
# [`ATOM_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#ATOM_EXT
|
34
|
+
# [`SMALL_ATOM_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#SMALL_ATOM_EXT
|
35
|
+
# [`ATOM_CACHE_REF`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#ATOM_CACHE_REF
|
36
|
+
# [`SMALL_INTEGER_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#SMALL_INTEGER_EXT
|
37
|
+
# [`INTEGER_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#INTEGER_EXT
|
38
|
+
# [`FUN_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#FUN_EXT
|
39
|
+
#
|
26
40
|
class Fun
|
27
41
|
include Term
|
28
42
|
|
data/lib/erlang/etf/integer.rb
CHANGED
@@ -2,12 +2,16 @@ module Erlang
|
|
2
2
|
module ETF
|
3
3
|
|
4
4
|
#
|
5
|
-
# 1
|
6
|
-
#
|
7
|
-
# 98
|
5
|
+
# 1 | 4
|
6
|
+
# --- | ---
|
7
|
+
# 98 | Int
|
8
8
|
#
|
9
9
|
# Signed 32 bit integer in big-endian format (i.e. MSB first)
|
10
10
|
#
|
11
|
+
# (see [`INTEGER_EXT`])
|
12
|
+
#
|
13
|
+
# [`INTEGER_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#INTEGER_EXT
|
14
|
+
#
|
11
15
|
class Integer
|
12
16
|
include Term
|
13
17
|
|
data/lib/erlang/etf/large_big.rb
CHANGED
@@ -2,12 +2,17 @@ module Erlang
|
|
2
2
|
module ETF
|
3
3
|
|
4
4
|
#
|
5
|
-
# 1 | 4
|
6
|
-
# --- |
|
7
|
-
# 111 | n
|
5
|
+
# 1 | 4 | 1 | n
|
6
|
+
# --- | --- | ---- | ---------------
|
7
|
+
# 111 | n | Sign | d(0) ... d(n-1)
|
8
8
|
#
|
9
|
-
# Same as SMALL_BIG_EXT with the difference that the length
|
10
|
-
# is an unsigned 4 byte integer.
|
9
|
+
# Same as [`SMALL_BIG_EXT`] with the difference that the length
|
10
|
+
# field is an unsigned 4 byte integer.
|
11
|
+
#
|
12
|
+
# (see [`LARGE_BIG_EXT`])
|
13
|
+
#
|
14
|
+
# [`SMALL_BIG_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#SMALL_BIG_EXT
|
15
|
+
# [`LARGE_BIG_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#LARGE_BIG_EXT
|
11
16
|
#
|
12
17
|
class LargeBig
|
13
18
|
include Term
|
@@ -6,9 +6,14 @@ module Erlang
|
|
6
6
|
# --- | ----- | --------
|
7
7
|
# 105 | Arity | Elements
|
8
8
|
#
|
9
|
-
# Same as SMALL_TUPLE_EXT with the exception that Arity is an
|
9
|
+
# Same as [`SMALL_TUPLE_EXT`] with the exception that `Arity` is an
|
10
10
|
# unsigned 4 byte integer in big endian format.
|
11
11
|
#
|
12
|
+
# (see [`LARGE_TUPLE_EXT`])
|
13
|
+
#
|
14
|
+
# [`SMALL_TUPLE_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#SMALL_TUPLE_EXT
|
15
|
+
# [`LARGE_TUPLE_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#LARGE_TUPLE_EXT
|
16
|
+
#
|
12
17
|
class LargeTuple
|
13
18
|
include Term
|
14
19
|
|
data/lib/erlang/etf/list.rb
CHANGED
@@ -2,14 +2,19 @@ module Erlang
|
|
2
2
|
module ETF
|
3
3
|
|
4
4
|
#
|
5
|
-
# 1 | 4 | Len |
|
5
|
+
# 1 | 4 | Len | N1
|
6
6
|
# --- | --- | -------- | ----
|
7
7
|
# 108 | Len | Elements | Tail
|
8
8
|
#
|
9
|
-
# Length is the number of elements that follows in the Elements
|
10
|
-
# section. Tail is the final tail of the list; it is NIL_EXT for a
|
9
|
+
# `Length` is the number of elements that follows in the `Elements`
|
10
|
+
# section. `Tail` is the final tail of the list; it is [`NIL_EXT`] for a
|
11
11
|
# proper list, but may be anything type if the list is improper
|
12
|
-
# (for instance [a|b]).
|
12
|
+
# (for instance `[a|b]`).
|
13
|
+
#
|
14
|
+
# (see [`LIST_EXT`])
|
15
|
+
#
|
16
|
+
# [`NIL_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#NIL_EXT
|
17
|
+
# [`LIST_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#LIST_EXT
|
13
18
|
#
|
14
19
|
class List
|
15
20
|
include Term
|
@@ -18,7 +23,7 @@ module Erlang
|
|
18
23
|
|
19
24
|
uint32be :len, always: -> { elements.size }
|
20
25
|
|
21
|
-
term :elements, type: :array
|
26
|
+
term :elements, type: :array, allow_char: true
|
22
27
|
term :tail
|
23
28
|
|
24
29
|
deserialize do |buffer|
|
data/lib/erlang/etf/new_float.rb
CHANGED
@@ -4,14 +4,18 @@ module Erlang
|
|
4
4
|
module ETF
|
5
5
|
|
6
6
|
#
|
7
|
-
# 1
|
8
|
-
#
|
9
|
-
# 70
|
7
|
+
# 1 | 8
|
8
|
+
# --- | ----------
|
9
|
+
# 70 | IEEE Float
|
10
10
|
#
|
11
11
|
# A float is stored as 8 bytes in big-endian IEEE format.
|
12
12
|
#
|
13
13
|
# This term is used in minor version 1 of the external format.
|
14
14
|
#
|
15
|
+
# (see [`NEW_FLOAT_EXT`])
|
16
|
+
#
|
17
|
+
# [`NEW_FLOAT_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#NEW_FLOAT_EXT
|
18
|
+
#
|
15
19
|
class NewFloat
|
16
20
|
include Term
|
17
21
|
|
data/lib/erlang/etf/new_fun.rb
CHANGED
@@ -7,36 +7,58 @@ module Erlang
|
|
7
7
|
# 112 | Size | Arity | Uniq | Index | NumFree | Module | Oldindex | OldUniq | Pid | Free Vars
|
8
8
|
#
|
9
9
|
# This is the new encoding of internal funs:
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
10
|
+
#
|
11
|
+
# ```erlang
|
12
|
+
# fun F/A and fun(Arg1,..) -> ... end.
|
13
|
+
# ```
|
14
|
+
#
|
15
|
+
# `Size`
|
16
|
+
# > is the total number of bytes, including the `Size` field.
|
17
|
+
#
|
18
|
+
# `Arity`
|
19
|
+
# > is the arity of the function implementing the fun.
|
20
|
+
#
|
21
|
+
# `Uniq`
|
22
|
+
# > is the 16 bytes MD5 of the significant parts of the Beam file.
|
23
|
+
#
|
24
|
+
# `Index`
|
25
|
+
# > is an index number. Each fun within a module has an unique
|
26
|
+
# index. `Index` is stored in big-endian byte order.
|
27
|
+
#
|
28
|
+
# `NumFree`
|
29
|
+
# > is the number of free variables.
|
30
|
+
#
|
31
|
+
# `Module`
|
32
|
+
# > is an encoded as an atom, using [`ATOM_EXT`], [`SMALL_ATOM_EXT`] or
|
33
|
+
# [`ATOM_CACHE_REF`]. This is the module that the fun is implemented
|
26
34
|
# in.
|
27
|
-
#
|
28
|
-
#
|
35
|
+
#
|
36
|
+
# `OldIndex`
|
37
|
+
# > is an integer encoded using [`SMALL_INTEGER_EXT`] or [`INTEGER_EXT`].
|
29
38
|
# It is typically a small index into the module's fun table.
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
39
|
+
#
|
40
|
+
# `OldUniq`
|
41
|
+
# > is an integer encoded using [`SMALL_INTEGER_EXT`] or [`INTEGER_EXT`].
|
42
|
+
# `Uniq` is the hash value of the parse tree for the fun.
|
43
|
+
#
|
44
|
+
# `Pid`
|
45
|
+
# > is a process identifier as in [`PID_EXT`]. It represents the
|
35
46
|
# process in which the fun was created.
|
36
|
-
#
|
37
|
-
#
|
47
|
+
#
|
48
|
+
# `Free vars`
|
49
|
+
# > is `NumFree` number of terms, each one encoded according to its
|
38
50
|
# type.
|
39
51
|
#
|
52
|
+
# (see [`NEW_FUN_EXT`])
|
53
|
+
#
|
54
|
+
# [`ATOM_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#ATOM_EXT
|
55
|
+
# [`SMALL_ATOM_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#SMALL_ATOM_EXT
|
56
|
+
# [`ATOM_CACHE_REF`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#ATOM_CACHE_REF
|
57
|
+
# [`SMALL_INTEGER_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#SMALL_INTEGER_EXT
|
58
|
+
# [`INTEGER_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#INTEGER_EXT
|
59
|
+
# [`PID_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#PID_EXT
|
60
|
+
# [`NEW_FUN_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#NEW_FUN_EXT
|
61
|
+
#
|
40
62
|
class NewFun
|
41
63
|
include Term
|
42
64
|
|
@@ -6,22 +6,27 @@ module Erlang
|
|
6
6
|
# --- | --- | ---- | -------- | ------
|
7
7
|
# 114 | Len | Node | Creation | ID ...
|
8
8
|
#
|
9
|
-
# Node and Creation are as in REFERENCE_EXT.
|
9
|
+
# `Node` and `Creation` are as in [`REFERENCE_EXT`].
|
10
10
|
#
|
11
|
-
# ID contains a sequence of big-endian unsigned integers (4 bytes
|
12
|
-
# each, so N' is a multiple of 4), but should be regarded as
|
11
|
+
# `ID` contains a sequence of big-endian unsigned integers (4 bytes
|
12
|
+
# each, so `N'` is a multiple of 4), but should be regarded as
|
13
13
|
# uninterpreted data.
|
14
14
|
#
|
15
|
-
# N' = 4 * Len
|
15
|
+
# `N' = 4 * Len.`
|
16
16
|
#
|
17
|
-
# In the first word (four bytes) of ID
|
18
|
-
# significant, the rest should be 0. In Creation
|
17
|
+
# In the first word (four bytes) of `ID`, only 18 bits are
|
18
|
+
# significant, the rest should be 0. In `Creation`, only 2 bits are
|
19
19
|
# significant, the rest should be 0.
|
20
20
|
#
|
21
|
-
# NEW_REFERENCE_EXT was introduced with distribution version 4. In
|
22
|
-
# version 4, N' should be at most 12.
|
21
|
+
# [`NEW_REFERENCE_EXT`] was introduced with distribution version 4. In
|
22
|
+
# version 4, `N'` should be at most 12.
|
23
23
|
#
|
24
|
-
# See REFERENCE_EXT).
|
24
|
+
# See [`REFERENCE_EXT`]).
|
25
|
+
#
|
26
|
+
# (see [`NEW_REFERENCE_EXT`])
|
27
|
+
#
|
28
|
+
# [`REFERENCE_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#REFERENCE_EXT
|
29
|
+
# [`NEW_REFERENCE_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#NEW_REFERENCE_EXT
|
25
30
|
#
|
26
31
|
class NewReference
|
27
32
|
include Term
|