damsi 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2a95c29d3df3bdb7ce0865ccb46ec2543b8f740dd2c0573a9ec2e3f8c3f6a26b
4
+ data.tar.gz: 6677d65b959ebfba371c6c3af8abbe6044e77b96a92860749d87382cef814ffd
5
+ SHA512:
6
+ metadata.gz: 619999e4795c7e1fcd019843bd816c86cfbbf8150043bddea276f3950997ab37aafe81eb9b2419db62d6338acb820056c939a61b3ee7d6ebe75d500621612294
7
+ data.tar.gz: 9b5973c624a55246fc7f9178c9b0f275676fda497637d6aaac44da839b1df38811617930656dccb784544d23e71b74709604ac28264fda6e11be04d8dd9d4a50
@@ -0,0 +1,11 @@
1
+ ---
2
+ name: pdd
3
+ on:
4
+ push:
5
+ pull_request:
6
+ jobs:
7
+ pdd:
8
+ runs-on: ubuntu-20.04
9
+ steps:
10
+ - uses: actions/checkout@v3
11
+ - uses: g4s8/pdd-action@master
@@ -0,0 +1,28 @@
1
+ ---
2
+ name: rake
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ branches:
9
+ - master
10
+ jobs:
11
+ test:
12
+ strategy:
13
+ matrix:
14
+ os: [ubuntu-20.04]
15
+ ruby: ['3.0']
16
+ runs-on: ${{ matrix.os }}
17
+ steps:
18
+ - uses: actions/checkout@v3
19
+ - uses: teatimeguest/setup-texlive-action@v2.6.2
20
+ with:
21
+ update-all-packages: true
22
+ packages: scheme-basic
23
+ - run: pdflatex -version
24
+ - uses: ruby/setup-ruby@v1
25
+ with:
26
+ ruby-version: ${{ matrix.ruby }}
27
+ - run: bundle update
28
+ - run: bundle exec rake
@@ -0,0 +1,11 @@
1
+ ---
2
+ name: xcop
3
+ on:
4
+ push:
5
+ pull_request:
6
+ jobs:
7
+ xcop:
8
+ runs-on: ubuntu-20.04
9
+ steps:
10
+ - uses: actions/checkout@v3
11
+ - uses: g4s8/xcop-action@master
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ coverage/
2
+ Gemfile.lock
3
+ .idea/
4
+ *.gem
5
+ .bundle/
6
+ .DS_Store
7
+ rdoc/
8
+ /damsi/
data/.pdd ADDED
@@ -0,0 +1,7 @@
1
+ --source=.
2
+ --verbose
3
+ --exclude target/**/*
4
+ --exclude coverage/**/*
5
+ --rule min-words:20
6
+ --rule min-estimate:15
7
+ --rule max-estimate:90
data/.rubocop.yml ADDED
@@ -0,0 +1,25 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'bin/**/*'
4
+ - 'assets/**/*'
5
+ DisplayCopNames: true
6
+ TargetRubyVersion: 2.2
7
+ NewCops: enable
8
+ SuggestExtensions: false
9
+
10
+ Metrics/CyclomaticComplexity:
11
+ Max: 20
12
+ Metrics/MethodLength:
13
+ Enabled: false
14
+ Layout/MultilineMethodCallIndentation:
15
+ Enabled: false
16
+ Metrics/AbcSize:
17
+ Enabled: false
18
+ Metrics/PerceivedComplexity:
19
+ Max: 15
20
+ Layout/EmptyLineAfterGuardClause:
21
+ Enabled: false
22
+ Style/ClassAndModuleChildren:
23
+ Enabled: false
24
+ Metrics/BlockLength:
25
+ Max: 50
data/.rultor.yml ADDED
@@ -0,0 +1,20 @@
1
+ docker:
2
+ image: yegor256/rultor-image:1.21.0
3
+ assets:
4
+ rubygems.yml: yegor256/home#assets/rubygems.yml
5
+ install: |
6
+ pdd -f /dev/null
7
+ sudo bundle install --no-color "--gemfile=$(pwd)/Gemfile"
8
+ release:
9
+ script: |-
10
+ bundle exec rake
11
+ rm -rf *.gem
12
+ sed -i "s/0\.0\.0/${tag}/g" lib/damsi/version.rb
13
+ git add lib/damsi/version.rb
14
+ git commit -m "version set to ${tag}"
15
+ gem build damsi.gemspec
16
+ chmod 0600 ../rubygems.yml
17
+ gem push *.gem --config-file ../rubygems.yml
18
+ merge:
19
+ script: |-
20
+ bundle exec rake
data/.simplecov ADDED
@@ -0,0 +1,38 @@
1
+ # Copyright (c) 2023 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ if Gem.win_platform?
22
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
23
+ SimpleCov::Formatter::HTMLFormatter
24
+ ]
25
+ SimpleCov.start do
26
+ add_filter '/test/'
27
+ add_filter '/features/'
28
+ end
29
+ else
30
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
31
+ [SimpleCov::Formatter::HTMLFormatter]
32
+ )
33
+ SimpleCov.start do
34
+ add_filter '/test/'
35
+ add_filter '/features/'
36
+ minimum_coverage 20
37
+ end
38
+ end
data/Gemfile ADDED
@@ -0,0 +1,31 @@
1
+ # Copyright (c) 2023 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ source 'https://rubygems.org'
22
+ gemspec
23
+
24
+ gem 'cucumber', '8.0.0', require: false
25
+ gem 'minitest', '5.19.0', require: false
26
+ gem 'rake', '13.0.6', require: false
27
+ gem 'rdoc', '6.5.0', require: false
28
+ gem 'rubocop', '1.55.1', require: false
29
+ gem 'rubocop-rspec', '2.23.0', require: false
30
+ gem 'simplecov', '0.22.0', require: false
31
+ gem 'xcop', '0.7.1', require: false
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2023 Yegor Bugayenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the 'Software'), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ [![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/damsi)](http://www.rultor.com/p/yegor256/damsi)
2
+ [![We recommend RubyMine](https://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
3
+
4
+ [![rake](https://github.com/yegor256/damsi/actions/workflows/rake.yml/badge.svg)](https://github.com/yegor256/damsi/actions/workflows/rake.yml)
5
+ [![PDD status](http://www.0pdd.com/svg?name=yegor256/damsi)](http://www.0pdd.com/p?name=yegor256/damsi)
6
+ ![Lines of code](https://img.shields.io/tokei/lines/github/yegor256/damsi)
7
+ [![Hits-of-Code](https://hitsofcode.com/github/yegor256/damsi)](https://hitsofcode.com/view/github/yegor256/damsi)
8
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/damsi/blob/master/LICENSE.txt)
9
+
10
+ It's a simulator of a dataflow machine.
11
+
12
+ First, you define a dataflow graph and save it to `fibo.dfg`
13
+ (this is the calculator of the 5th Fibonacci number):
14
+
15
+ ```
16
+ send :fibo n:5
17
+ send :if f:1
18
+ recv :fibo [:n] do
19
+ send :gt n:n
20
+ send :dec1 n:n
21
+ send :dec2 n:n
22
+ send :sum a:n # if tagged
23
+ send :sum b:n # if tagged right
24
+ end
25
+ recv :if [:c, :t, :f] do
26
+ if c
27
+ send :fibo n:t
28
+ else
29
+ send :fibo n:f
30
+ end
31
+ end
32
+ recv :sum [:a, :b] do
33
+ send :if (a + b)
34
+ end
35
+ recv :dec1 [:n] do
36
+ send :fibo n:(n-1)
37
+ end
38
+ recv :dec2 [:n] do
39
+ send :fibo n:(n-2)
40
+ end
41
+ ```
42
+
43
+ This is a Ruby dialect.
data/Rakefile ADDED
@@ -0,0 +1,83 @@
1
+ # Copyright (c) 2023 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require 'rubygems'
22
+ require 'rake'
23
+ require 'rdoc'
24
+ require 'rake/clean'
25
+
26
+ def name
27
+ @name ||= File.basename(Dir['*.gemspec'].first, '.*')
28
+ end
29
+
30
+ def version
31
+ Gem::Specification.load(Dir['*.gemspec'].first).version
32
+ end
33
+
34
+ task default: %i[clean test features rubocop xcop copyright]
35
+
36
+ require 'rake/testtask'
37
+ desc 'Run all unit tests'
38
+ Rake::TestTask.new(:test) do |test|
39
+ Rake::Cleaner.cleanup_files(['coverage'])
40
+ test.libs << 'lib' << 'test'
41
+ test.pattern = 'test/**/test_*.rb'
42
+ test.verbose = false
43
+ end
44
+
45
+ require 'rdoc/task'
46
+ desc 'Build RDoc documentation'
47
+ Rake::RDocTask.new do |rdoc|
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "#{name} #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
53
+
54
+ require 'rubocop/rake_task'
55
+ desc 'Run RuboCop on all directories'
56
+ RuboCop::RakeTask.new(:rubocop) do |task|
57
+ task.fail_on_error = true
58
+ task.requires << 'rubocop-rspec'
59
+ task.options = ['--display-cop-names']
60
+ end
61
+
62
+ require 'xcop/rake_task'
63
+ Xcop::RakeTask.new(:xcop) do |task|
64
+ task.license = 'LICENSE.txt'
65
+ task.includes = ['**/*.xml', '**/*.xsl', '**/*.xsd', '**/*.html']
66
+ task.excludes = ['damsi/**', 'coverage/**']
67
+ end
68
+
69
+ require 'cucumber/rake/task'
70
+ Cucumber::Rake::Task.new(:features) do
71
+ Rake::Cleaner.cleanup_files(['coverage'])
72
+ end
73
+ Cucumber::Rake::Task.new(:'features:html') do |t|
74
+ t.profile = 'html_report'
75
+ end
76
+
77
+ task :copyright do
78
+ sh "grep -q -r '#{Date.today.strftime('%Y')}' \
79
+ --include '*.rb' \
80
+ --include '*.txt' \
81
+ --include 'Rakefile' \
82
+ ."
83
+ end
data/bin/damsi ADDED
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright (c) 2023 Yegor Bugayenko
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the 'Software'), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ # SOFTWARE.
21
+
22
+ STDOUT.sync = true
23
+
24
+ require 'slop'
25
+ require 'loog'
26
+ require 'backtrace'
27
+ require_relative '../lib/damsi/version'
28
+ require_relative '../lib/damsi/dfg'
29
+
30
+ loog = Loog::REGULAR
31
+
32
+ def config(path)
33
+ f = File.expand_path(path)
34
+ args = []
35
+ args += File.readlines(f).map(&:strip).reject { |a| a.empty? } if File.exist?(f)
36
+ args
37
+ end
38
+
39
+ args = config('~/.damsi') + config('.damsi') + ARGV
40
+
41
+ opts = Slop.parse(args, strict: true, help: true) do |o|
42
+ o.banner = "Usage (#{Damsi::VERSION}): damsi [options] <file>"
43
+ o.bool '-h', '--help', 'Show these instructions'
44
+ o.bool '--version', 'Show current version'
45
+ end
46
+
47
+ if opts.help?
48
+ puts opts
49
+ exit
50
+ end
51
+
52
+ if opts.version?
53
+ loog.info(Damsi::VERSION)
54
+ exit
55
+ end
56
+
57
+ tex = Class.new do
58
+ def info(msg)
59
+ puts msg
60
+ end
61
+ def debug(msg)
62
+ puts '% ' + msg
63
+ end
64
+ end.new
65
+
66
+ Encoding.default_external = Encoding::UTF_8
67
+ Encoding.default_internal = Encoding::UTF_8
68
+
69
+ begin
70
+ input = opts.arguments[0]
71
+ raise 'File name is required' if input.nil?
72
+ Damsi::DFG.new(File.read(input)).simulate(tex)
73
+ rescue StandardError => e
74
+ loog.error(Backtrace.new(e))
75
+ exit -1
76
+ end
data/damsi.gemspec ADDED
@@ -0,0 +1,47 @@
1
+ # Copyright (c) 2023 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require 'English'
22
+
23
+ lib = File.expand_path('lib', __dir__)
24
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
25
+ require_relative 'lib/damsi/version'
26
+
27
+ Gem::Specification.new do |s|
28
+ s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
29
+ s.required_ruby_version = '>= 2.2'
30
+ s.name = 'damsi'
31
+ s.version = Damsi::VERSION
32
+ s.license = 'MIT'
33
+ s.metadata = { 'rubygems_mfa_required' => 'true' }
34
+ s.summary = 'Dataflow Machine Simulator'
35
+ s.description = 'Turns DFG into a flow of events'
36
+ s.authors = ['Yegor Bugayenko']
37
+ s.email = 'yegor256@gmail.com'
38
+ s.homepage = 'http://github.com/yegor256/damsi'
39
+ s.files = `git ls-files`.split($RS)
40
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
41
+ s.rdoc_options = ['--charset=UTF-8']
42
+ s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
43
+ s.add_runtime_dependency 'backtrace', '~>0.3'
44
+ s.add_runtime_dependency 'loog', '~>0.5'
45
+ s.add_runtime_dependency 'rainbow', '~>3.0'
46
+ s.add_runtime_dependency 'slop', '~>4.4'
47
+ end
@@ -0,0 +1,28 @@
1
+ Feature: Simple Reporting
2
+ I want to be able to build a report
3
+
4
+ Scenario: Help can be printed
5
+ When I run bin/damsi with "-h"
6
+ Then Exit code is zero
7
+ And Stdout contains "--help"
8
+
9
+ Scenario: Version can be printed
10
+ When I run bin/damsi with "--version"
11
+ Then Exit code is zero
12
+
13
+ Scenario: Simple DFG
14
+ Given I have a "simple.dfg" file with content:
15
+ """
16
+ send :sum, a:10
17
+ send :sum, b:15
18
+ recv :sum do |a, b|
19
+ send :mul, x: (a+b)
20
+ end
21
+ recv :mul do |x|
22
+ send :out, x: x
23
+ end
24
+ """
25
+ When I run bin/damsi simple.dfg
26
+ Then Stdout contains "mul called with [25]"
27
+ And Exit code is zero
28
+
@@ -0,0 +1,23 @@
1
+ Feature: Gem Package
2
+ As a source code writer I want to be able to
3
+ package the Gem into .gem file
4
+
5
+ Scenario: Gem can be packaged
6
+ Given I have a "execs.rb" file with content:
7
+ """
8
+ #!/usr/bin/env ruby
9
+ require 'rubygems'
10
+ spec = Gem::Specification::load('./spec.rb')
11
+ if spec.executables.empty?
12
+ fail 'no executables: ' + File.read('./spec.rb')
13
+ end
14
+ """
15
+ When I run bash with:
16
+ """
17
+ cd damsi
18
+ gem build damsi.gemspec
19
+ gem specification --ruby damsi-*.gem > ../spec.rb
20
+ cd ..
21
+ ruby execs.rb
22
+ """
23
+ Then Exit code is zero
@@ -0,0 +1,86 @@
1
+ # Copyright (c) 2023 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require 'nokogiri'
22
+ require 'tmpdir'
23
+ require 'slop'
24
+ require 'English'
25
+
26
+ Before do
27
+ @cwd = Dir.pwd
28
+ @dir = Dir.mktmpdir('test')
29
+ FileUtils.mkdir_p(@dir)
30
+ Dir.chdir(@dir)
31
+ @opts = Slop.parse ['-v'] do |o|
32
+ o.bool '-v', '--verbose'
33
+ end
34
+ end
35
+
36
+ After do
37
+ Dir.chdir(@cwd)
38
+ FileUtils.rm_rf(@dir)
39
+ end
40
+
41
+ Given(/^I have a "([^"]*)" file with content:$/) do |file, text|
42
+ FileUtils.mkdir_p(File.dirname(file)) unless File.exist?(file)
43
+ File.write(file, text.gsub('\\xFF', 0xFF.chr))
44
+ end
45
+
46
+ When(%r{^I run bin/damsi with "([^"]*)"$}) do |arg|
47
+ home = File.join(File.dirname(__FILE__), '../..')
48
+ @stdout = `ruby -I#{home}/lib #{home}/bin/damsi #{arg}`
49
+ @exitstatus = $CHILD_STATUS.exitstatus
50
+ end
51
+
52
+ Then(/^Stdout contains "([^"]*)"$/) do |txt|
53
+ raise "STDOUT doesn't contain '#{txt}':\n#{@stdout}" unless @stdout.include?(txt)
54
+ end
55
+
56
+ Then(/^Stdout is empty$/) do
57
+ raise "STDOUT is not empty:\n#{@stdout}" unless @stdout == ''
58
+ end
59
+
60
+ Then(/^Exit code is zero$/) do
61
+ raise "Non-zero exit #{@exitstatus}:\n#{@stdout}" unless @exitstatus.zero?
62
+ end
63
+
64
+ Then(/^Exit code is not zero$/) do
65
+ raise 'Zero exit code' if @exitstatus.zero?
66
+ end
67
+
68
+ When(/^I run bash with "([^"]*)"$/) do |text|
69
+ FileUtils.copy_entry(@cwd, File.join(@dir, 'damsi'))
70
+ @stdout = `#{text}`
71
+ @exitstatus = $CHILD_STATUS.exitstatus
72
+ end
73
+
74
+ When(/^I run bash with:$/) do |text|
75
+ FileUtils.copy_entry(@cwd, File.join(@dir, 'damsi'))
76
+ @stdout = `#{text}`
77
+ @exitstatus = $CHILD_STATUS.exitstatus
78
+ end
79
+
80
+ Given(/^It is Unix$/) do
81
+ pending if Gem.win_platform?
82
+ end
83
+
84
+ Given(/^It is Windows$/) do
85
+ pending unless Gem.win_platform?
86
+ end
@@ -0,0 +1,21 @@
1
+ # Copyright (c) 2023 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require 'simplecov'
@@ -0,0 +1,25 @@
1
+ send :fibo, n:5
2
+ send :if, f:1
3
+ recv :fibo do |n|
4
+ send :gt, n:n
5
+ send :dec1, n:n
6
+ send :dec2, n:n
7
+ send :sum, a:n # if tagged
8
+ send :sum, b:n # if tagged right
9
+ end
10
+ recv :if do |c, t, f|
11
+ if c
12
+ send :fibo, n:t
13
+ else
14
+ send :fibo, n:f
15
+ end
16
+ end
17
+ recv :sum do |a, b|
18
+ send :if, t:(a + b)
19
+ end
20
+ recv :dec1 do |n|
21
+ send :fibo, n:(n-1)
22
+ end
23
+ recv :dec2 do |c|
24
+ send :fibo, n:(n-2)
25
+ end
data/fixtures/sum.dfg ADDED
@@ -0,0 +1,10 @@
1
+ recv :start do
2
+ send :sum, a:10
3
+ send :sum, b:15
4
+ end
5
+ recv :sum do |a, b|
6
+ send :mul, x: (a+b)
7
+ end
8
+ recv :mul do |x|
9
+ send :out, x: x
10
+ end
data/lib/damsi/dfg.rb ADDED
@@ -0,0 +1,105 @@
1
+ # Copyright (c) 2023 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require_relative 'ticks'
22
+
23
+ # Dataflow Graph (DFG)
24
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
25
+ # Copyright:: Copyright (c) 2023 Yegor Bugayenko
26
+ # License:: MIT
27
+ class Damsi::DFG
28
+ def initialize(prog, log)
29
+ @prog = prog
30
+ @log = log
31
+ @cells = {}
32
+ @ops = {}
33
+ @ticks = Damsi::Ticks.new
34
+ @tick = 0
35
+ @op = nil
36
+ @started = []
37
+ end
38
+
39
+ def cell(vtx)
40
+ @cells[vtx]
41
+ end
42
+
43
+ def msg(tex)
44
+ @ticks.push(@tick, "\\texttt{\\frenchspacing{}#{@op}: #{tex}}")
45
+ end
46
+
47
+ def send(vtx, args)
48
+ @cells[vtx] = {} if @cells[vtx].nil?
49
+ args.each do |k, a|
50
+ @cells[vtx][k] = a
51
+ @ticks.push(@tick, "\\texttt{\\frenchspacing{}#{@op}: \"#{a}\" → #{vtx}.#{k}}")
52
+ @log.debug("#{@tick}| #{a} -> #{vtx}.#{k}")
53
+ end
54
+ end
55
+
56
+ def recv(vtx, &block)
57
+ @ops[vtx] = block
58
+ end
59
+
60
+ # Returns an instance of +Ticks+.
61
+ def simulate
62
+ # rubocop:disable Security/Eval
63
+ eval(@prog)
64
+ # rubocop:enable Security/Eval
65
+ loop do
66
+ execs = 0
67
+ before = @cells.clone
68
+ before.each do |v, c|
69
+ next if @ops[v].nil?
70
+ blk = @ops[v]
71
+ reqs = blk.parameters.select { |p| p[0] == :opt }.map { |p| p[1] }
72
+ args = reqs.map { |r| [r, c[r]] }.to_h
73
+ bound = args.map { |p| p[1] }.compact
74
+ if bound.size < args.size
75
+ @log.debug("#{@tick}| :#{v}(#{reqs.join(', ')}) is not ready to start with #{args}")
76
+ next
77
+ end
78
+ @log.debug("#{@tick}| :#{v} starts with #{args} ...")
79
+ @op = v
80
+ blk.call(*bound)
81
+ @log.debug("#{@tick}| :#{v} finished")
82
+ execs += 1
83
+ @cells.delete(v)
84
+ end
85
+ @ops.each do |v, blk|
86
+ reqs = blk.parameters.select { |p| p[0] == :opt }.map { |p| p[1] }
87
+ next unless reqs.empty?
88
+ next if @started.include?(v)
89
+ @started.push(v)
90
+ @log.debug("#{@tick}| :#{v} starts empty ...")
91
+ @op = v
92
+ blk.call
93
+ @log.debug("#{@tick}| :#{v} finished")
94
+ execs += 1
95
+ end
96
+ if execs.zero?
97
+ @log.debug("#{@tick}| no executions at #{before.count} operators, we stop here:\n#{before}")
98
+ break
99
+ end
100
+ @tick += 1
101
+ raise 'Ran out of ticks' if @tick > 100
102
+ end
103
+ @ticks
104
+ end
105
+ end
@@ -0,0 +1,56 @@
1
+ # Copyright (c) 2023 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ # Ticks accumulated after the evaluation of a DFG.
22
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
23
+ # Copyright:: Copyright (c) 2023 Yegor Bugayenko
24
+ # License:: MIT
25
+ class Damsi::Ticks
26
+ def initialize
27
+ @ticks = {}
28
+ end
29
+
30
+ # Add a message in properly formatted LaTeX. If the TeX syntax
31
+ # is broken, there will be a runtime problem later.
32
+ def push(tick, tex)
33
+ @ticks[tick] = [] if @ticks[tick].nil?
34
+ @ticks[tick].push(tex)
35
+ end
36
+
37
+ def to_latex(log)
38
+ total = @ticks.count
39
+ if total.zero?
40
+ log.info('no ticks')
41
+ return
42
+ end
43
+ log.debug("This tabular is auto-generated by damsi, at #{Time.now}")
44
+ log.info("\\begin{tabular}{#{'l' * total}}")
45
+ pos = 0
46
+ @ticks.each do |_n, t|
47
+ log.info(" #{'\\hspace*{1em} & ' * pos} \\multicolumn{#{total - pos}}{l}{\\begin{tabular}{|l}")
48
+ t.each do |e|
49
+ log.info(" #{e} \\\\")
50
+ end
51
+ log.info(' \\end{tabular}} \\\\')
52
+ pos += 1
53
+ end
54
+ log.info('\\end{tabular}')
55
+ end
56
+ end
@@ -0,0 +1,27 @@
1
+ # Copyright (c) 2023 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ # Damsi main module.
22
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
23
+ # Copyright:: Copyright (c) 2023 Yegor Bugayenko
24
+ # License:: MIT
25
+ module Damsi
26
+ VERSION = '0.0.1'.freeze
27
+ end
data/renovate.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
+ "extends": [
4
+ "config:base"
5
+ ]
6
+ }
@@ -0,0 +1,26 @@
1
+ # Copyright (c) 2023 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ $stdout.sync = true
22
+
23
+ require 'simplecov'
24
+ SimpleCov.start
25
+
26
+ require 'minitest/autorun'
data/test/test_dfg.rb ADDED
@@ -0,0 +1,98 @@
1
+ # Copyright (c) 2023 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require 'minitest/autorun'
22
+ require 'loog'
23
+ require_relative 'tex'
24
+ require_relative '../lib/damsi/dfg'
25
+ require_relative '../lib/damsi/ticks'
26
+
27
+ # Test for DFG.
28
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
29
+ # Copyright:: Copyright (c) 2023 Yegor Bugayenko
30
+ # License:: MIT
31
+ class TestDFG < Minitest::Test
32
+ def test_primitive_summator
33
+ dfg = Damsi::DFG.new(
34
+ '
35
+ recv :start do
36
+ send :sum, a:10
37
+ send :sum, b:15
38
+ end
39
+ recv :sum do |a, b|
40
+ send :mul, x: (a+b)
41
+ end
42
+ recv :mul do |x|
43
+ send :stop, x: x
44
+ end
45
+ ',
46
+ Loog::NULL
47
+ )
48
+ ticks = dfg.simulate
49
+ assert_equal(25, dfg.cell(:stop)[:x])
50
+ tex = TeX.new
51
+ ticks.to_latex(tex)
52
+ tex.to_pdf(path: '/tmp/damsi.pdf')
53
+ end
54
+
55
+ def test_prng
56
+ dfg = Damsi::DFG.new(
57
+ '
58
+ @data = 42
59
+ def next_random(n)
60
+ (n * n) / 16 & 0xffff
61
+ end
62
+ recv :r1 do
63
+ msg "Read #{@data} from RAM"
64
+ send :nxt1, d:@data
65
+ end
66
+ recv :nxt1 do |d|
67
+ n = next_random(d)
68
+ msg "Shift from #{d} to #{n}"
69
+ send :w1, d:n
70
+ end
71
+ recv :w1 do |d|
72
+ @data = d
73
+ msg "Write #{d} to RAM"
74
+ send :r2, k:1
75
+ end
76
+ recv :r2 do |k|
77
+ msg "Read #{@data} from RAM"
78
+ send :nxt2, d:@data
79
+ end
80
+ recv :nxt2 do |d|
81
+ n = next_random(d)
82
+ msg "Shift from #{d} to #{n}"
83
+ send :w2, d:n
84
+ send :seq, d:n
85
+ end
86
+ recv :seq do |d|
87
+ send :stop, x:d
88
+ end
89
+ ',
90
+ Loog::VERBOSE
91
+ )
92
+ ticks = dfg.simulate
93
+ assert_equal(756, dfg.cell(:stop)[:x])
94
+ tex = TeX.new
95
+ ticks.to_latex(tex)
96
+ tex.to_pdf(path: '/tmp/damsi.pdf', tex: '/tmp/damsi.tex')
97
+ end
98
+ end
data/test/test_tex.rb ADDED
@@ -0,0 +1,39 @@
1
+ # Copyright (c) 2023 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require 'minitest/autorun'
22
+ require_relative 'tex'
23
+
24
+ # Test for TeX.
25
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
26
+ # Copyright:: Copyright (c) 2023 Yegor Bugayenko
27
+ # License:: MIT
28
+ class TestTeX < Minitest::Test
29
+ def test_primitive_document
30
+ tex = TeX.new
31
+ tex.info('Hello, world!')
32
+ tex.info('Hello, \\LaTeX!')
33
+ Dir.mktmpdir do |dir|
34
+ pdf = File.join(dir, 'a.pdf')
35
+ tex.to_pdf(path: pdf)
36
+ assert(File.exist?(pdf))
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,54 @@
1
+ # Copyright (c) 2023 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require 'minitest/autorun'
22
+ require 'loog'
23
+ require_relative 'tex'
24
+ require_relative '../lib/damsi/ticks'
25
+
26
+ # Test for Ticks.
27
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
28
+ # Copyright:: Copyright (c) 2023 Yegor Bugayenko
29
+ # License:: MIT
30
+ class TestTicks < Minitest::Test
31
+ def test_simple_render
32
+ ticks = Damsi::Ticks.new
33
+ ticks.push(1, 'hello')
34
+ ticks.push(2, 'world')
35
+ tex = TeX.new
36
+ ticks.to_latex(tex)
37
+ Dir.mktmpdir do |dir|
38
+ pdf = File.join(dir, 'a.pdf')
39
+ tex.to_pdf(path: pdf)
40
+ assert(File.exist?(pdf))
41
+ end
42
+ end
43
+
44
+ def test_empty
45
+ ticks = Damsi::Ticks.new
46
+ tex = TeX.new
47
+ ticks.to_latex(tex)
48
+ Dir.mktmpdir do |dir|
49
+ pdf = File.join(dir, 'a.pdf')
50
+ tex.to_pdf(path: pdf)
51
+ assert(File.exist?(pdf))
52
+ end
53
+ end
54
+ end
data/test/tex.rb ADDED
@@ -0,0 +1,48 @@
1
+ # Copyright (c) 2023 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require 'loog'
22
+
23
+ # TeX accumulated through a log.
24
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
25
+ # Copyright:: Copyright (c) 2023 Yegor Bugayenko
26
+ # License:: MIT
27
+ class TeX < Loog::Buffer
28
+ def debug(msg)
29
+ super("% #{msg}")
30
+ end
31
+
32
+ # Makes a PDF at the provided +path+, returns nothing. The TeX source
33
+ # will be save to the provided +tex+ location, if it's not nil.
34
+ def to_pdf(path: nil, tex: nil)
35
+ Dir.mktmpdir do |dir|
36
+ name = 'paper.tex'
37
+ doc = File.join(dir, name)
38
+ body = "\\documentclass{article}\n\\usepackage[T1]{fontenc}\n\\begin{document}\n\n#{self}\n\n\\end{document}\n"
39
+ File.write(doc, body)
40
+ cmd = "set -x && cd #{dir} && ls -al && pdflatex -shell-escape -halt-on-error #{name} 2>&1"
41
+ system(cmd)
42
+ pdf = File.join(dir, 'paper.pdf')
43
+ raise "The PDF was not generated at #{pdf}" unless File.exist?(pdf)
44
+ FileUtils.copy(pdf, path) unless path.nil?
45
+ FileUtils.copy(doc, tex) unless tex.nil?
46
+ end
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: damsi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yegor Bugayenko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-08-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: backtrace
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: loog
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rainbow
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: slop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.4'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.4'
69
+ description: Turns DFG into a flow of events
70
+ email: yegor256@gmail.com
71
+ executables:
72
+ - damsi
73
+ extensions: []
74
+ extra_rdoc_files:
75
+ - README.md
76
+ - LICENSE.txt
77
+ files:
78
+ - ".github/workflows/pdd.yml"
79
+ - ".github/workflows/rake.yml"
80
+ - ".github/workflows/xcop.yml"
81
+ - ".gitignore"
82
+ - ".pdd"
83
+ - ".rubocop.yml"
84
+ - ".rultor.yml"
85
+ - ".simplecov"
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - bin/damsi
91
+ - damsi.gemspec
92
+ - features/cli.feature
93
+ - features/gem_package.feature
94
+ - features/step_definitions/steps.rb
95
+ - features/support/env.rb
96
+ - fixtures/fibonacci.dfg
97
+ - fixtures/sum.dfg
98
+ - lib/damsi/dfg.rb
99
+ - lib/damsi/ticks.rb
100
+ - lib/damsi/version.rb
101
+ - renovate.json
102
+ - test/test__helper.rb
103
+ - test/test_dfg.rb
104
+ - test/test_tex.rb
105
+ - test/test_ticks.rb
106
+ - test/tex.rb
107
+ homepage: http://github.com/yegor256/damsi
108
+ licenses:
109
+ - MIT
110
+ metadata:
111
+ rubygems_mfa_required: 'true'
112
+ post_install_message:
113
+ rdoc_options:
114
+ - "--charset=UTF-8"
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '2.2'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubygems_version: 3.2.15
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Dataflow Machine Simulator
132
+ test_files: []