chelsy 0.0.3 → 0.0.4

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.
@@ -1,3 +1,3 @@
1
1
  module Chelsy
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -5,10 +5,9 @@ include Chelsy
5
5
  doc = Document.new
6
6
 
7
7
  doc.fragments << Directive::Include.new("stdio.h", system: true)
8
- doc.fragments << ''
9
8
 
10
9
  doc << Function.new(:main, Type::Int.new, [:void]) do |b|
11
- b << FunctionCall.new(:printf, [Constant::String.new("Hello, Chelsy!\n")])
10
+ b << Operator::Call.new(:printf, [Constant::String.new("Hello, Chelsy!\n")])
12
11
  b << Return.new(Constant::Int.new(0))
13
12
  end
14
13
 
@@ -0,0 +1,17 @@
1
+ #include <stdio.h>
2
+
3
+ /*
4
+ * Print Fahrenheit to Celsius table
5
+ * (fahr = 0, 20, ..., 300)
6
+ */
7
+ #define LOWER 0
8
+ #define UPPER 300
9
+ #define STEP 20
10
+
11
+ int main(int argc, const char **argv) {
12
+ for (int fahr = LOWER; fahr <= UPPER; fahr += STEP) {
13
+ int celsius = 5 * (fahr - 32) / 9;
14
+ printf("%d\t%d\n", fahr, celsius);
15
+ }
16
+ return 0;
17
+ }
@@ -0,0 +1,39 @@
1
+ require 'chelsy'
2
+
3
+ include Chelsy
4
+
5
+ doc = Document.new
6
+
7
+ doc.fragments << Directive::Include.new("stdio.h", system: true)
8
+ doc.fragments << ''
9
+ doc.fragments << Comment::Multi.new([
10
+ "Print Fahrenheit to Celsius table",
11
+ "(fahr = 0, 20, ..., 300)"
12
+ ])
13
+ doc.fragments << Directive::Define.new(:LOWER, '0')
14
+ doc.fragments << Directive::Define.new(:UPPER, '300')
15
+ doc.fragments << Directive::Define.new(:STEP, '20')
16
+
17
+ doc << Function.new(:main,
18
+ Type::Int.new, [
19
+ Param.new(:argc, Type::Int.new),
20
+ Param.new(:argv, Type::Pointer.new(Type::Pointer.new(Type::Char.new(const: true)))),
21
+ ]) do |b|
22
+ init = Declaration.new(:fahr, Type::Int.new, 'LOWER')
23
+ cond = Operator::LessThanOrEqual.new(:fahr, 'UPPER')
24
+ step = Operator::AssignAdd.new(:fahr, 'STEP')
25
+
26
+ stmt = Block.new.tap do |b|
27
+ celsius = Operator::Sub.new(:fahr, Constant::Int.new(32))
28
+ celsius = Operator::Mul.new(Constant::Int.new(5), celsius)
29
+ celsius = Operator::Div.new(celsius, Constant::Int.new(9))
30
+
31
+ b << Declaration.new(:celsius, Type::Int.new, celsius)
32
+ b << Operator::Call.new(:printf, [Constant::String.new("%d\t%d\n"), :fahr, :celsius])
33
+ end
34
+
35
+ b << For.new(init, cond, step, stmt)
36
+ b << Return.new(Constant::Int.new(0))
37
+ end
38
+
39
+ puts Translator.new(indent_string: ' ').translate(doc)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chelsy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takanori Ishikawa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-16 00:00:00.000000000 Z
11
+ date: 2016-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,7 +66,21 @@ dependencies:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.10.4
69
- description: C code generator written in Ruby (Work in progress)
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 0.9.5
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 0.9.5
83
+ description: C code generator written in Ruby
70
84
  email:
71
85
  - takanori.ishikawa@gmail.com
72
86
  executables: []
@@ -75,6 +89,7 @@ extra_rdoc_files: []
75
89
  files:
76
90
  - .gitignore
77
91
  - .travis.yml
92
+ - .yardopts
78
93
  - Gemfile
79
94
  - LICENSE.txt
80
95
  - README.md
@@ -89,6 +104,8 @@ files:
89
104
  - lib/chelsy/version.rb
90
105
  - sample/hello_chelsy.c
91
106
  - sample/hello_chelsy.rb
107
+ - sample/temperature.c
108
+ - sample/temperature.rb
92
109
  homepage: https://github.com/ishikawa/chelsy
93
110
  licenses:
94
111
  - MIT
@@ -112,5 +129,5 @@ rubyforge_project:
112
129
  rubygems_version: 2.0.14.1
113
130
  signing_key:
114
131
  specification_version: 4
115
- summary: C code generator
132
+ summary: C code generator written in Ruby
116
133
  test_files: []