Skip to content

Commit

Permalink
#5 clean
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jul 31, 2023
1 parent 485eea2 commit bddca67
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 17 deletions.
1 change: 1 addition & 0 deletions .github/workflows/rake.yml
Expand Up @@ -16,6 +16,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: teatimeguest/setup-texlive-action@v2.5.1
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
Expand Down
6 changes: 4 additions & 2 deletions fixtures/sum.dfg
@@ -1,5 +1,7 @@
send :sum, a:10
send :sum, b:15
recv :start do
send :sum, a:10
send :sum, b:15
end
recv :sum do |a, b|
send :mul, x: (a+b)
end
Expand Down
18 changes: 11 additions & 7 deletions lib/damsi/dfg.rb
Expand Up @@ -29,6 +29,8 @@ def initialize(prog)
@prog = prog
@cells = {}
@ops = {}
@ticks = Damsi::Ticks.new
@tick = 0
end

def cell(vtx)
Expand All @@ -37,7 +39,10 @@ def cell(vtx)

def send(vtx, args)
@cells[vtx] = {} if @cells[vtx].nil?
args.each { |k, a| @cells[vtx][k] = a }
args.each do |k, a|
@cells[vtx][k] = a
@ticks.push(@tick, "\\texttt{#{a}} $\\to$ \\texttt{#{vtx}\\textbar{}1.#{k}}")
end
end

def recv(vtx, &block)
Expand All @@ -49,8 +54,7 @@ def simulate(log)
# rubocop:disable Security/Eval
eval(@prog)
# rubocop:enable Security/Eval
ticks = Damsi::Ticks.new
tick = 0
send(:start, {})
loop do
execs = 0
before = @cells.clone
Expand All @@ -61,14 +65,14 @@ def simulate(log)
args = reqs.map { |p| c[p[1]] }.compact
next if args.size < reqs.size
blk.call(*args)
log.debug("#{tick}: #{v} called with #{args}")
log.debug("#{@tick}: #{v} called with #{args}")
execs += 1
@cells.delete(v)
end
break if execs.zero?
tick += 1
raise 'Ran out of ticks' if tick > 100
@tick += 1
raise 'Ran out of ticks' if @tick > 100
end
ticks
@ticks
end
end
2 changes: 1 addition & 1 deletion lib/damsi/ticks.rb
Expand Up @@ -40,7 +40,7 @@ def to_latex(log)
end
log.info("\\begin{tabular}{#{'l' * total}}")
pos = 0
@ticks.each do |n, t|
@ticks.each do |_n, t|
log.info("#{'&' * pos} \\multicolumn{#{total - pos}}{l}{\\begin{tabular}{|l}")
t.each do |e|
log.info(e)
Expand Down
10 changes: 6 additions & 4 deletions test/test_dfg.rb
Expand Up @@ -32,18 +32,20 @@ class TestDFG < Minitest::Test
def test_primitive_summator
dfg = Damsi::DFG.new(
'
send :sum, a:10
send :sum, b:15
recv :start do
send :sum, a:10
send :sum, b:15
end
recv :sum do |a, b|
send :mul, x: (a+b)
end
recv :mul do |x|
send :out, x: x
send :stop, x: x
end
'
)
ticks = dfg.simulate(Loog::NULL)
assert_equal(25, dfg.cell(:out)[:x])
assert_equal(25, dfg.cell(:stop)[:x])
tex = TeX.new
ticks.to_latex(tex)
tex.to_pdf(path: '/tmp/damsi.pdf')
Expand Down
4 changes: 2 additions & 2 deletions test/test_tex.rb
Expand Up @@ -28,8 +28,8 @@
class TestTeX < Minitest::Test
def test_primitive_document
tex = TeX.new
tex.info("Hello, world!")
tex.info("Hello, \\LaTeX!")
tex.info('Hello, world!')
tex.info('Hello, \\LaTeX!')
Dir.mktmpdir do |dir|
pdf = File.join(dir, 'a.pdf')
tex.to_pdf(path: pdf)
Expand Down
2 changes: 1 addition & 1 deletion test/tex.rb
Expand Up @@ -30,7 +30,7 @@ def to_pdf(path: '/tmp/damsi.pdf')
Dir.mktmpdir do |dir|
name = 'paper.tex'
tex = File.join(dir, name)
body = "\\documentclass{article}\\begin{document}#{to_s}\\end{document}"
body = "\\documentclass{article}\\usepackage[T1]{fontenc}\\begin{document}#{self}\\end{document}"
File.write(tex, body)
cmd = "set -x && cd #{dir} && ls -al && pdflatex -shell-escape -halt-on-error #{name} 2>&1"
system(cmd)
Expand Down

0 comments on commit bddca67

Please sign in to comment.