-
Notifications
You must be signed in to change notification settings - Fork 11
/
common.rb
69 lines (62 loc) · 910 Bytes
/
common.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
61
62
63
64
65
66
67
68
69
if ENV['BFS24']
$bfs24 = true
BITS = 24
else
BITS = 16
end
UINT_MAX = (1 << BITS) - 1
INT_MIN = -(1 << (BITS - 1))
while true
if ARGV[0] == '-v'
$verbose = true
ARGV.shift
elsif ARGV[0] == '-q'
$quiet = true
ARGV.shift
elsif ARGV[0] == '-m'
$bfs24 = true
ARGV.shift
else
break
end
end
RUNNING = 0
PC = 2
NPC = 8
A = 14
B = 20
C = 26
D = 32
BP = 38
SP = 44
OP = 50
WRK = 60
LOAD_REQ = 67
STORE_REQ = 68
MEM = 70
MEM_V = 0
if $bfs24
MEM_A = 3
MEM_WRK = 6
MEM_USE = 12
MEM_CTL_LEN = 15
MEM_BLK_LEN = (256*3) + MEM_CTL_LEN
else
MEM_A = 2
MEM_WRK = 4
MEM_USE = 8
MEM_CTL_LEN = 9
MEM_BLK_LEN = (256*2) + MEM_CTL_LEN
end
def sym?(o)
o.class == Symbol
end
def error(loc, msg)
filename, lineno, column, len = *loc
r = "#{filename}:#{lineno}:#{column}"
if len > 1
r += "-#{column+len-1}"
end
STDERR.puts("#{r}: #{msg}")
exit 1
end