Skip to content

Commit 13c07cf

Browse files
committed
Assemble other instructions
1 parent 8b87bb9 commit 13c07cf

File tree

1 file changed

+37
-12
lines changed

1 file changed

+37
-12
lines changed

lib/syntax_tree/yarv/assembler.rb

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ def assemble_iseq(iseq, lines)
7979
iseq.branchnil(labels[operands])
8080
when "branchunless"
8181
iseq.branchunless(labels[operands])
82+
when "checkkeyword"
83+
kwbits_index, keyword_index = operands.split(/,\s*/)
84+
iseq.checkkeyword(
85+
parse_number(kwbits_index),
86+
parse_number(keyword_index)
87+
)
8288
when "checkmatch"
8389
iseq.checkmatch(parse_number(operands))
8490
when "checktype"
@@ -98,6 +104,8 @@ def assemble_iseq(iseq, lines)
98104
class_iseq = iseq.class_child_iseq(name.to_s, Location.default)
99105
assemble_iseq(class_iseq, body)
100106
iseq.defineclass(name, class_iseq, flags)
107+
when "defined"
108+
raise NotImplementedError
101109
when "definemethod"
102110
body = parse_nested(lines[line_index..])
103111
line_index += body.length
@@ -127,6 +135,12 @@ def assemble_iseq(iseq, lines)
127135
when "expandarray"
128136
number, flags = operands.split(/,\s*/)
129137
iseq.expandarray(parse_number(number), parse_number(flags))
138+
when "getblockparam"
139+
lookup = find_local(iseq, operands)
140+
iseq.getblockparam(lookup.index, lookup.level)
141+
when "getblockparamproxy"
142+
lookup = find_local(iseq, operands)
143+
iseq.getblockparamproxy(lookup.index, lookup.level)
130144
when "getclassvariable"
131145
iseq.getclassvariable(parse_symbol(operands))
132146
when "getconstant"
@@ -136,18 +150,16 @@ def assemble_iseq(iseq, lines)
136150
when "getinstancevariable"
137151
iseq.getinstancevariable(parse_symbol(operands))
138152
when "getlocal"
139-
name_string, level_string = operands.split(/,\s*/)
140-
name = name_string.to_sym
141-
level = level_string&.to_i || 0
142-
143-
iseq.local_table.plain(name)
144-
lookup = iseq.local_table.find(name, level)
153+
lookup = find_local(iseq, operands)
145154
iseq.getlocal(lookup.index, lookup.level)
146155
when "getspecial"
147156
key, type = operands.split(/,\s*/)
148157
iseq.getspecial(parse_number(key), parse_number(type))
149158
when "intern"
150159
iseq.intern
160+
when "invokeblock"
161+
cdata = operands ? calldata(operands) : YARV.calldata(nil, 0)
162+
iseq.invokeblock(cdata)
151163
when "invokesuper"
152164
cdata =
153165
if operands
@@ -305,17 +317,15 @@ def assemble_iseq(iseq, lines)
305317
end
306318

307319
iseq.send(calldata(operands), block_iseq)
320+
when "setblockparam"
321+
lookup = find_local(iseq, operands)
322+
iseq.setblockparam(lookup.index, lookup.level)
308323
when "setconstant"
309324
iseq.setconstant(parse_symbol(operands))
310325
when "setglobal"
311326
iseq.setglobal(parse_symbol(operands))
312327
when "setlocal"
313-
name_string, level_string = operands.split(/,\s*/)
314-
name = name_string.to_sym
315-
level = level_string&.to_i || 0
316-
317-
iseq.local_table.plain(name)
318-
lookup = iseq.local_table.find(name, level)
328+
lookup = find_local(iseq, operands)
319329
iseq.setlocal(lookup.index, lookup.level)
320330
when "setn"
321331
iseq.setn(parse_number(operands))
@@ -329,6 +339,8 @@ def assemble_iseq(iseq, lines)
329339
iseq.splatarray(parse_options(operands, [true, false]))
330340
when "swap"
331341
iseq.swap
342+
when "throw"
343+
iseq.throw(parse_number(operands))
332344
when "topn"
333345
iseq.topn(parse_number(operands))
334346
when "toregexp"
@@ -337,12 +349,25 @@ def assemble_iseq(iseq, lines)
337349
when "ARG_REQ"
338350
iseq.argument_size += 1
339351
iseq.local_table.plain(operands.to_sym)
352+
when "ARG_BLOCK"
353+
iseq.argument_options[:block_start] = iseq.argument_size
354+
iseq.local_table.block(operands.to_sym)
355+
iseq.argument_size += 1
340356
else
341357
raise "Could not understand: #{line}"
342358
end
343359
end
344360
end
345361

362+
def find_local(iseq, operands)
363+
name_string, level_string = operands.split(/,\s*/)
364+
name = name_string.to_sym
365+
level = level_string&.to_i || 0
366+
367+
iseq.local_table.plain(name)
368+
iseq.local_table.find(name, level)
369+
end
370+
346371
def parse(value)
347372
program = SyntaxTree.parse(value)
348373
raise if program.statements.body.length != 1

0 commit comments

Comments
 (0)