yarp 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -2
- data/Makefile +2 -0
- data/README.md +5 -2
- data/config.yml +54 -267
- data/ext/yarp/api_node.c +135 -579
- data/ext/yarp/extension.c +2 -2
- data/ext/yarp/extension.h +1 -1
- data/include/yarp/ast.h +142 -285
- data/include/yarp/defines.h +5 -0
- data/include/yarp/unescape.h +1 -1
- data/include/yarp/util/yp_buffer.h +9 -1
- data/include/yarp/util/yp_constant_pool.h +3 -0
- data/include/yarp/util/yp_list.h +7 -7
- data/include/yarp/util/yp_newline_list.h +4 -0
- data/include/yarp/util/yp_state_stack.h +1 -1
- data/include/yarp/version.h +2 -2
- data/lib/yarp/ffi.rb +62 -47
- data/lib/yarp/node.rb +504 -1399
- data/lib/yarp/serialize.rb +111 -141
- data/lib/yarp.rb +6 -6
- data/src/node.c +70 -250
- data/src/prettyprint.c +41 -185
- data/src/serialize.c +35 -133
- data/src/unescape.c +29 -35
- data/src/util/yp_buffer.c +18 -0
- data/src/util/yp_list.c +7 -16
- data/src/util/yp_state_stack.c +0 -6
- data/src/yarp.c +265 -670
- data/yarp.gemspec +1 -1
- metadata +2 -2
data/include/yarp/version.h
CHANGED
data/lib/yarp/ffi.rb
CHANGED
@@ -75,7 +75,10 @@ module YARP
|
|
75
75
|
|
76
76
|
load_exported_functions_from(
|
77
77
|
"yarp/util/yp_buffer.h",
|
78
|
+
"yp_buffer_sizeof",
|
78
79
|
"yp_buffer_init",
|
80
|
+
"yp_buffer_value",
|
81
|
+
"yp_buffer_length",
|
79
82
|
"yp_buffer_free"
|
80
83
|
)
|
81
84
|
|
@@ -88,34 +91,49 @@ module YARP
|
|
88
91
|
"yp_string_sizeof"
|
89
92
|
)
|
90
93
|
|
91
|
-
# This object represents a yp_buffer_t.
|
92
|
-
#
|
93
|
-
class YPBuffer
|
94
|
-
|
94
|
+
# This object represents a yp_buffer_t. We only use it as an opaque pointer,
|
95
|
+
# so it doesn't need to know the fields of yp_buffer_t.
|
96
|
+
class YPBuffer
|
97
|
+
SIZEOF = LibRubyParser.yp_buffer_sizeof
|
95
98
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
+
attr_reader :pointer
|
100
|
+
|
101
|
+
def initialize(pointer)
|
102
|
+
@pointer = pointer
|
99
103
|
end
|
100
|
-
end
|
101
104
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
105
|
+
def value
|
106
|
+
LibRubyParser.yp_buffer_value(pointer)
|
107
|
+
end
|
108
|
+
|
109
|
+
def length
|
110
|
+
LibRubyParser.yp_buffer_length(pointer)
|
111
|
+
end
|
112
|
+
|
113
|
+
def read
|
114
|
+
value.read_string(length)
|
115
|
+
end
|
116
|
+
|
117
|
+
# Initialize a new buffer and yield it to the block. The buffer will be
|
118
|
+
# automatically freed when the block returns.
|
119
|
+
def self.with(&block)
|
120
|
+
pointer = FFI::MemoryPointer.new(SIZEOF)
|
121
|
+
|
122
|
+
begin
|
123
|
+
raise unless LibRubyParser.yp_buffer_init(pointer)
|
124
|
+
yield new(pointer)
|
125
|
+
ensure
|
126
|
+
LibRubyParser.yp_buffer_free(pointer)
|
127
|
+
pointer.free
|
128
|
+
end
|
113
129
|
end
|
114
130
|
end
|
115
131
|
|
116
132
|
# This object represents a yp_string_t. We only use it as an opaque pointer,
|
117
133
|
# so it doesn't have to be an FFI::Struct.
|
118
134
|
class YPString
|
135
|
+
SIZEOF = LibRubyParser.yp_string_sizeof
|
136
|
+
|
119
137
|
attr_reader :pointer
|
120
138
|
|
121
139
|
def initialize(pointer)
|
@@ -133,23 +151,18 @@ module YARP
|
|
133
151
|
def read
|
134
152
|
source.read_string(length)
|
135
153
|
end
|
136
|
-
end
|
137
154
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
yield YPString.new(string)
|
150
|
-
ensure
|
151
|
-
yp_string_free(string)
|
152
|
-
string.free
|
155
|
+
# Yields a yp_string_t pointer to the given block.
|
156
|
+
def self.with(filepath, &block)
|
157
|
+
pointer = FFI::MemoryPointer.new(SIZEOF)
|
158
|
+
|
159
|
+
begin
|
160
|
+
raise unless LibRubyParser.yp_string_mapped_init(pointer, filepath)
|
161
|
+
yield new(pointer)
|
162
|
+
ensure
|
163
|
+
LibRubyParser.yp_string_free(pointer)
|
164
|
+
pointer.free
|
165
|
+
end
|
153
166
|
end
|
154
167
|
end
|
155
168
|
end
|
@@ -162,10 +175,10 @@ module YARP
|
|
162
175
|
VERSION = LibRubyParser.yp_version.read_string
|
163
176
|
|
164
177
|
def self.dump_internal(source, source_size, filepath)
|
165
|
-
LibRubyParser.
|
178
|
+
LibRubyParser::YPBuffer.with do |buffer|
|
166
179
|
metadata = [filepath.bytesize, filepath.b, 0].pack("LA*L") if filepath
|
167
|
-
LibRubyParser.yp_parse_serialize(source, source_size, buffer, metadata)
|
168
|
-
buffer.
|
180
|
+
LibRubyParser.yp_parse_serialize(source, source_size, buffer.pointer, metadata)
|
181
|
+
buffer.read
|
169
182
|
end
|
170
183
|
end
|
171
184
|
private_class_method :dump_internal
|
@@ -177,35 +190,37 @@ module YARP
|
|
177
190
|
|
178
191
|
# Mirror the YARP.dump_file API by using the serialization API.
|
179
192
|
def self.dump_file(filepath)
|
180
|
-
LibRubyParser.
|
193
|
+
LibRubyParser::YPString.with(filepath) do |string|
|
181
194
|
dump_internal(string.source, string.length, filepath)
|
182
195
|
end
|
183
196
|
end
|
184
197
|
|
185
198
|
# Mirror the YARP.lex API by using the serialization API.
|
186
199
|
def self.lex(code, filepath = nil)
|
187
|
-
LibRubyParser.
|
188
|
-
LibRubyParser.yp_lex_serialize(code, code.bytesize, filepath, buffer)
|
189
|
-
|
190
|
-
source = Source.new(code)
|
191
|
-
Serialize.load_tokens(source, buffer.to_ruby_string).with_source(source)
|
200
|
+
LibRubyParser::YPBuffer.with do |buffer|
|
201
|
+
LibRubyParser.yp_lex_serialize(code, code.bytesize, filepath, buffer.pointer)
|
202
|
+
Serialize.load_tokens(Source.new(code), buffer.read)
|
192
203
|
end
|
193
204
|
end
|
194
205
|
|
195
206
|
# Mirror the YARP.lex_file API by using the serialization API.
|
196
207
|
def self.lex_file(filepath)
|
197
|
-
LibRubyParser.
|
208
|
+
LibRubyParser::YPString.with(filepath) do |string|
|
209
|
+
lex(string.read, filepath)
|
210
|
+
end
|
198
211
|
end
|
199
212
|
|
200
213
|
# Mirror the YARP.parse API by using the serialization API.
|
201
214
|
def self.parse(code, filepath = nil)
|
202
|
-
YARP.load(code, dump(code, filepath))
|
215
|
+
YARP.load(code, dump(code, filepath))
|
203
216
|
end
|
204
217
|
|
205
218
|
# Mirror the YARP.parse_file API by using the serialization API. This uses
|
206
219
|
# native strings instead of Ruby strings because it allows us to use mmap when
|
207
220
|
# it is available.
|
208
221
|
def self.parse_file(filepath)
|
209
|
-
LibRubyParser.
|
222
|
+
LibRubyParser::YPString.with(filepath) do |string|
|
223
|
+
parse(string.read, filepath)
|
224
|
+
end
|
210
225
|
end
|
211
226
|
end
|