Skip to content

Instantly share code, notes, and snippets.

@tompng
Created January 7, 2025 16:18
Show Gist options
  • Save tompng/b311a7373d57a9e833c8f6704f9e0d4b to your computer and use it in GitHub Desktop.
Save tompng/b311a7373d57a9e833c8f6704f9e0d4b to your computer and use it in GitHub Desktop.
require 'prism'
Dir.glob('../**/*.rb').each do |file|
next if file =~ /(^|\/)tmp\//
codes = []
prc = ->(node) {
codes << node.slice
codes << node.unescaped if node.is_a? Prism::StringNode
node.compact_child_nodes.each { prc.call it }
}
prc.call Prism.parse_file(file).value
p file
codes.uniq.sort_by(&:size).each_with_index do |code, i|
[
"defined?((#{code}))",
"#shareable-constant-value: experimental_everything\nA=(#{code})",
"(#{code})=1"
].each do |target|
RubyVM::InstructionSequence.compile target
rescue SyntaxError
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment