Commit 86b10c75
86b10c7525baMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 4 files · +1 added · ~3 modified
Description
feat: global variable ($) support
Implement general global variable read/write for Ruby $-prefixed variables. Emitted as static C variables at file scope, accessible from all functions.
Rewrites fasta benchmark to use idiomatic $last instead of state array workaround.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 86b10c7525ba
- Parent
- 331782721c81
benchmark/bm_fasta.rbmodifiedView file
@@ -5,10 +5,11 @@
55
IA = 387766
IC = 2957377
8-
# Mutable state via array cell (no global variables)9-
def gen_random(max, state)10-
state[0] = (state[0] * IA + IC) % IM11-
max * state[0] / IM8+
$last = 429+
10+
def gen_random(max)11+
$last = ($last * IA + IC) % IM12+
max * $last / IM1213
end1314
1415
def make_repeat_fasta(id, desc, src, n)@@ -32,7 +33,7 @@
3233
end3334
end3435
35-
def make_random_fasta(id, desc, table_chars, table_probs, n, state)36+
def make_random_fasta(id, desc, table_chars, table_probs, n)3637
puts ">" + id + " " + desc3738
# Build cumulative probabilities3839
cp = Array.new(table_probs.length, 0.0)@@ -52,7 +53,7 @@
5253
line = ""5354
j = 05455
while j < len55-
r = gen_random(1.0, state)56+
r = gen_random(1.0)5657
# Linear search5758
c = 05859
while c < cp.length - 1@@ -72,16 +73,15 @@
7273
ALU = "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGGGAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGACCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAATACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCAGCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGGAGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCCAGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAAAA"7374
7475
n = Integer(ARGV[0] || 1000)75-
state = [42]7676
7777
make_repeat_fasta("ONE", "Homo sapiens alu", ALU, n * 2)7878
7979
iub_chars = ["a", "c", "g", "t", "B", "D", "H", "K", "M", "N", "R", "S", "V", "W", "Y"]8080
iub_probs = [0.27, 0.12, 0.12, 0.27, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02]8181
82-
make_random_fasta("TWO", "IUB ambiguity codes", iub_chars, iub_probs, n * 3, state)82+
make_random_fasta("TWO", "IUB ambiguity codes", iub_chars, iub_probs, n * 3)8383
8484
homo_chars = ["a", "c", "g", "t"]8585
homo_probs = [0.3029549426680, 0.1979883004921, 0.1975473066391, 0.3015094502008]8686
87-
make_random_fasta("THREE", "Homo sapiens frequency", homo_chars, homo_probs, n * 5, state)87+
make_random_fasta("THREE", "Homo sapiens frequency", homo_chars, homo_probs, n * 5)spinel_codegen.rbmodifiedView file
Loading diff…
test/bm_fasta.rbmodifiedView file
Loading diff…
test/gvar.rbaddedView file
Loading diff…