Skip to content

Updates #521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ jobs:
- '3.0'
- '3.1'
- '3.2'
- head
- '3.3'
- '3.4'
- truffleruby-head
name: CI
runs-on: ubuntu-latest
Expand Down
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ Style/KeywordParametersOrder:
Style/MissingRespondToMissing:
Enabled: false

Style/MultipleComparison:
Enabled: false

Style/MutableConstant:
Enabled: false

Expand All @@ -157,6 +160,9 @@ Style/PerlBackrefs:
Style/RedundantArrayConstructor:
Enabled: false

Style/RedundantParentheses:
Enabled: false

Style/SafeNavigation:
Enabled: false

Expand Down
1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
source "https://rubygems.org"

gemspec

gem "fiddle"
46 changes: 26 additions & 20 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,47 @@ PATH
GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
docile (1.4.0)
json (2.6.3)
language_server-protocol (3.17.0.3)
ast (2.4.3)
docile (1.4.1)
fiddle (1.1.8)
json (2.12.2)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
minitest (5.25.5)
parallel (1.23.0)
parser (3.2.2.4)
parallel (1.27.0)
parser (3.3.8.0)
ast (~> 2.4.1)
racc
prettier_print (1.2.1)
racc (1.7.1)
prism (1.4.0)
racc (1.8.1)
rainbow (3.1.1)
rake (13.3.0)
regexp_parser (2.8.2)
rexml (3.2.6)
rubocop (1.57.2)
regexp_parser (2.10.0)
rubocop (1.78.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (~> 1.10)
parser (>= 3.2.2.4)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.1, < 2.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.45.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.45.1)
parser (>= 3.3.7.2)
prism (~> 1.4)
ruby-progressbar (1.13.0)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov-html (0.13.1)
simplecov_json_formatter (0.1.4)
unicode-display_width (2.5.0)
unicode-display_width (3.1.4)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)

PLATFORMS
arm64-darwin-21
Expand All @@ -53,6 +58,7 @@ PLATFORMS

DEPENDENCIES
bundler
fiddle
minitest
rake
rubocop
Expand Down
2 changes: 1 addition & 1 deletion lib/syntax_tree/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class CTags < Action
attr_reader :entries

def initialize(options)
super(options)
super
@entries = []
end

Expand Down
4 changes: 4 additions & 0 deletions lib/syntax_tree/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11644,6 +11644,10 @@ def pin(parent, pin)
elsif value.is_a?(Array) && (index = value.index(self))
parent.public_send(key)[index] = replace
break
elsif value.is_a?(Array) &&
(index = value.index { |(_k, v)| v == self })
parent.public_send(key)[index][1] = replace
break
end
end
end
Expand Down
10 changes: 7 additions & 3 deletions lib/syntax_tree/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,11 @@ def visit(node)

visit_methods do
def visit_var_ref(node)
node.pin(stack[-2], pins.shift)
if node.start_char > pins.first.start_char
node.pin(stack[-2], pins.shift)
else
super
end
end
end

Expand Down Expand Up @@ -1732,13 +1736,13 @@ def on_fcall(value)
# :call-seq:
# on_field: (
# untyped parent,
# (:"::" | Op | Period) operator
# (:"::" | Op | Period | 73) operator
# (Const | Ident) name
# ) -> Field
def on_field(parent, operator, name)
Field.new(
parent: parent,
operator: operator,
operator: operator == 73 ? :"::" : operator,
name: name,
location: parent.location.to(name.location)
)
Expand Down
1 change: 1 addition & 0 deletions lib/syntax_tree/pattern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def compile
raise CompilationError, query
end

raise CompilationError, query if program.nil?
compile_node(program.statements.body.first.consequent.pattern)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/syntax_tree/yarv/assembler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def assemble_iseq(iseq, lines)
def find_local(iseq, operands)
name_string, level_string = operands.split(/,\s*/)
name = name_string.to_sym
level = level_string&.to_i || 0
level = level_string.to_i

iseq.local_table.plain(name)
iseq.local_table.find(name, level)
Expand Down Expand Up @@ -455,7 +455,7 @@ def parse_calldata(value)
CallData::CALL_ARGS_SIMPLE
end

YARV.calldata(message.to_sym, argc_value&.to_i || 0, flags)
YARV.calldata(message.to_sym, argc_value.to_i, flags)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/syntax_tree/yarv/calldata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def initialize(
end

def flag?(mask)
(flags & mask) > 0
flags.anybits?(mask)
end

def to_h
Expand Down
12 changes: 6 additions & 6 deletions lib/syntax_tree/yarv/decompiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def node_for(value)
when Integer
Int(value.to_s)
when Symbol
SymbolLiteral(Ident(value.to_s))
SymbolLiteral(Ident(value.name))
end
end

Expand Down Expand Up @@ -88,10 +88,10 @@ def decompile(iseq)

clause << HashLiteral(LBrace("{"), assocs)
when GetGlobal
clause << VarRef(GVar(insn.name.to_s))
clause << VarRef(GVar(insn.name.name))
when GetLocalWC0
local = iseq.local_table.locals[insn.index]
clause << VarRef(Ident(local.name.to_s))
clause << VarRef(Ident(local.name.name))
when Jump
clause << Assign(block_label.field, node_for(insn.label.name))
clause << Next(Args([]))
Expand Down Expand Up @@ -123,7 +123,7 @@ def decompile(iseq)
left, right = clause.pop(2)
clause << Binary(left, :"!=", right)
when OptSendWithoutBlock
method = insn.calldata.method.to_s
method = insn.calldata.method.name
argc = insn.calldata.argc

if insn.calldata.flag?(CallData::CALL_FCALL)
Expand Down Expand Up @@ -182,7 +182,7 @@ def decompile(iseq)
when PutSelf
clause << VarRef(Kw("self"))
when SetGlobal
target = GVar(insn.name.to_s)
target = GVar(insn.name.name)
value = clause.pop

clause << if value.is_a?(Binary) && VarRef(target) === value.left
Expand Down Expand Up @@ -256,7 +256,7 @@ def decompile(iseq)
def local_name(index, level)
current = iseq
level.times { current = current.parent_iseq }
current.local_table.locals[index].name.to_s
current.local_table.locals[index].name.name
end
end
end
Expand Down
43 changes: 35 additions & 8 deletions lib/syntax_tree/yarv/instruction_sequence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,19 +252,23 @@ def to_a
dumped_options = argument_options.dup
dumped_options[:opt].map!(&:name) if dumped_options[:opt]

metadata = {
arg_size: argument_size,
local_size: local_table.size,
stack_max: stack.maximum_size,
node_id: -1,
node_ids: [-1] * insns.length
}

metadata[:parser] = :prism if RUBY_VERSION >= "3.3"

# Next, return the instruction sequence as an array.
[
MAGIC,
versions[0],
versions[1],
1,
{
arg_size: argument_size,
local_size: local_table.size,
stack_max: stack.maximum_size,
node_id: -1,
node_ids: [-1] * insns.length
},
metadata,
name,
file,
"<compiled>",
Expand Down Expand Up @@ -689,6 +693,10 @@ def concatstrings(number)
push(ConcatStrings.new(number))
end

def concattoarray(object)
push(ConcatToArray.new(object))
end

def defineclass(name, class_iseq, flags)
push(DefineClass.new(name, class_iseq, flags))
end
Expand Down Expand Up @@ -897,6 +905,14 @@ def pop
push(Pop.new)
end

def pushtoarraykwsplat
push(PushToArrayKwSplat.new)
end

def putchilledstring(object)
push(PutChilledString.new(object))
end

def putnil
push(PutNil.new)
end
Expand Down Expand Up @@ -1079,6 +1095,8 @@ def self.from(source, options = Compiler::Options.new, parent_iseq = nil)
iseq.concatarray
when :concatstrings
iseq.concatstrings(opnds[0])
when :concattoarray
iseq.concattoarray(opnds[0])
when :defineclass
iseq.defineclass(opnds[0], from(opnds[1], options, iseq), opnds[2])
when :defined
Expand Down Expand Up @@ -1191,8 +1209,13 @@ def self.from(source, options = Compiler::Options.new, parent_iseq = nil)
iseq.newarray(opnds[0])
iseq.send(YARV.calldata(:min))
when :opt_newarray_send
mid = opnds[1]
if RUBY_VERSION >= "3.4"
mid = %i[max min hash pack pack_buffer include?][mid - 1]
end

iseq.newarray(opnds[0])
iseq.send(CallData.new(opnds[1]))
iseq.send(CallData.new(mid))
when :opt_neq
iseq.push(
OptNEq.new(CallData.from(opnds[0]), CallData.from(opnds[1]))
Expand All @@ -1207,6 +1230,10 @@ def self.from(source, options = Compiler::Options.new, parent_iseq = nil)
iseq.send(YARV.calldata(:-@))
when :pop
iseq.pop
when :pushtoarraykwsplat
iseq.pushtoarraykwsplat
when :putchilledstring
iseq.putchilledstring(opnds[0])
when :putnil
iseq.putnil
when :putobject
Expand Down
Loading