-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
113 lines (102 loc) · 2.5 KB
/
Rakefile
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# coding: utf-8
require 'yaml'
PROGRAMS = ["lelev", "lconst", "omegau", "atomip", "up", "hhgcut", "hhgexc", "keldysh"]
RAWS = PROGRAMS.map { |p| "build/raw/#{p}.raw" }
BUNDLE = "build/42s-atomic.raw"
task :default => BUNDLE
directory "build"
task BUNDLE => RAWS do |task|
`cat #{task.sources.join ' '} > #{task.name}`
end
rule ".raw" => [->(f){gen_source_for_raw(f)}, "build"] do |task|
mkdir_p task.name.pathmap("%d")
`./txt2raw.pl #{task.source} #{task.name}`
end
rule ".raw" => [->(f){source_for_raw(f)}, "build"] do |task|
puts "Building #{task.name}"
mkdir_p task.name.pathmap("%d")
`./txt2raw.pl #{task.source} #{task.name}`
end
task "build/hp42s/lelev.hp42s" => "data/eVs.txt" do |task|
mkdir_p task.name.pathmap("%d")
lines = File.open(task.source).each_line
File.open(task.name, "w") do |file|
file.write("LBL \"LELEV\"\n")
save_stack_regs(file) do
[lines.count, 1, "NEWMAT",
"STO \"ELEV\"",
"INDEX \"ELEV\""].each do |x|
file.write("#{x}\n")
end
lines.rewind
lines.each do |l|
[l.strip, "STOEL", "I+"].each do |x|
file.write("#{x}\n")
end
end
end
file.write("END")
end
end
task "build/hp42s/lconst.hp42s" => "data/constants.yaml" do |task|
mkdir_p task.name.pathmap("%d")
constants = File.open(task.source) do |file|
YAML.load(file.read)
end
File.open(task.name, "w") do |file|
file.write("LBL \"LCONST\"\n")
save_stack_regs(file) do
constants.each do |k,v|
# txt2raw.pl requires uppercase E in scientific notation
["#{v}".sub("e", "E"),"STO \"#{k}\""].each do |x|
file.write("#{x}\n")
end
end
end
file.write("END")
end
end
def gen_source_for_raw(raw_file)
raw_file.pathmap("%{^build/raw/,build/hp42s/}X.hp42s")
end
def source_for_raw(raw_file)
raw_file.pathmap("%{^build/raw/,src/}X.hp42s")
end
def save_stack_regs(file)
["STO \"QES_X\"",
"Rv",
"STO \"QES_Y\"",
"Rv",
"STO \"QES_Z\"",
"Rv",
"STO \"QES_T\"",
"Rv",
"LASTX",
"STO \"QES_L\"",
"Rv",
"RCL \"REGS\"",
"STO \"QREGS\"",
"Rv",
25, 1,
"NEWMAT",
"STO \"REGS\""].each do |x|
file.write("#{x}\n")
end
yield
["RCL \"QREGS\"",
"CLV \"QREGS\"",
"STO \"REGS\"",
"RCL \"QES_L\"",
"CLV \"QES_L\"",
"STO ST L",
"RCL \"QES_T\"",
"CLV \"QES_T\"",
"RCL \"QES_Z\"",
"CLV \"QES_Z\"",
"RCL \"QES_Y\"",
"CLV \"QES_Y\"",
"RCL \"QES_X\"",
"CLV \"QES_X\""].each do |x|
file.write("#{x}\n")
end
end