Skip to content

Instantly share code, notes, and snippets.

View tenderlove's full-sized avatar
©️
 ​[object Object] :trollface:

Aaron Patterson tenderlove

©️
 ​[object Object] :trollface:
View GitHub Profile
module Visitable
def accept object
object.visit self
end
end
class Visitor
def visit thing
send(:"visit_#{thing.class.name}", thing)
end
@tenderlove
tenderlove / fjit.rb
Last active February 11, 2025 19:59
require "fiddle"
require "ffi"
require "jit_buffer"
require "hacks"
require "aarch64"
require "benchmark/ips"
module FJIT
C = RubyVM::RJIT.const_get(:C)
include AArch64::Registers
require "set"
require "rbconfig"
class Wrapper
def initialize
@a = Set.new
@b = Set.new
end
def write_a
diff --git a/tool/ruby_vm/views/_insn_entry.erb b/tool/ruby_vm/views/_insn_entry.erb
index 6ec33461c4..bc9a1d44b4 100644
--- a/tool/ruby_vm/views/_insn_entry.erb
+++ b/tool/ruby_vm/views/_insn_entry.erb
@@ -64,7 +64,7 @@ INSN_ENTRY(<%= insn.name %>)
INC_SP(INSN_ATTR(sp_inc));
% insn.rets.reverse_each.with_index do |ret, i|
TOPN(<%= i %>) = <%= insn.cast_to_VALUE ret %>;
- VM_ASSERT(!RB_TYPE_P(TOPN(<%= i %>), T_NONE));
+ assert(!RB_TYPE_P(TOPN(<%= i %>), T_NONE));
require 'fiddle'
SIZEOF_HEAP_PAGE_HEADER_STRUCT = Fiddle::SIZEOF_VOIDP
SIZEOF_RVALUE = 40
HEAP_PAGE_ALIGN_LOG = 14
HEAP_PAGE_ALIGN = 1 << HEAP_PAGE_ALIGN_LOG # 2 ^ 14
HEAP_PAGE_ALIGN_MASK = ~(~0 << HEAP_PAGE_ALIGN_LOG) # Mask for getting page address
REQUIRED_SIZE_BY_MALLOC = Fiddle::SIZEOF_SIZE_T * 5 # padding needed by malloc
HEAP_PAGE_SIZE = HEAP_PAGE_ALIGN - REQUIRED_SIZE_BY_MALLOC # Actual page size
require "strscan"
class Scanner
TOK = []
TOK["{".ord] = :LBRACE; TOK["}".ord] = :RBRACE; TOK[";".ord] = :SEMI
def initialize data
@scan = StringScanner.new data
@prev_pos = @scan.pos
end
require "strscan"
class Lexer
IDENTIFIER = /[_A-Za-z][_0-9A-Za-z]*\b/
IGNORE = %r{
(?:
[, \c\r\n\t]+ |
\#.*$
)*
}x
@tenderlove
tenderlove / h2_puma.rb
Last active August 14, 2024 06:10
Demo HTTP/2 server with Puma
require 'socket'
require 'openssl'
require 'puma/server'
require 'ds9'
class Server < DS9::Server
def initialize socket, app
@app = app
@read_streams = {}
@write_streams = {}
require 'webrick'
require 'webrick/https'
require 'ds9'
class HTTP2Server < WEBrick::HTTPServer
SETTINGS = [ [DS9::Settings::MAX_CONCURRENT_STREAMS, 100] ]
class HTTP2Response < WEBrick::HTTPResponse
def initialize config, ctx, stream_id
@ctx = ctx
#!/Users/aaron/.rubies/arm64/ruby-trunk/bin/ruby
# This is a demo language server for Ruby, written in Ruby. It just checks
# the syntax of Ruby programs when you save them.
#
# Configure this in Vim by adding the vim-lsp plugin, then doing this
# in your vimrc:
#
# au User lsp_setup
# \ lsp#register_server({