-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcc.rb
62 lines (52 loc) · 1.15 KB
/
cc.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require 's20'
module CC
TCC = Seiran20.lm('tcc')
BUF = Seiran20.lm('buffer')
class StringProc
def initialize(text, alloc = BUF.alloc(16384))
@text = text
@alloc = alloc
end
def call(*a)
to_proc.call *a
end
def error
@ptr = BUF.to_ptr @alloc
Seiran20.readstr @ptr
end
def to_proc
if !@proc
@ptr = BUF.to_ptr @alloc
@addr = TCC.compile @alloc, @text
if @addr && @addr != 0
return @proc = Seiran20.callproc(@addr)
else
raise Seiran20.readstr @ptr
end
end
@proc
end
end
def self.allocbuf(size)
x = BUF.alloc(size)
yield x
BUF.decref(x)
end
def self.allocbufs(*size)
buf = size.map{|x| BUF.alloc(x)}
yield buf
buf.each{|x| BUF.decref x}
end
def self.fromBitmap(bitmap)
CC::BUF.fromBitmap(bitmap)
end
INVERT = StringProc.new(<<-'EOF')
int func(int prebuf){
if(!(prebuf & 1)) return 1;
int **buf = (int **)(prebuf >> 1);
int *addr = buf[0], len = (int)buf[1] / 4, *end = addr + len;
while(addr != end){*addr++^=0xFFFFFF;}
return 0;
}
EOF
end