pre_c 0.1.0

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: 0c9c5773613593a9021040b2b2bf4f6342d082fbdb5367f4eaf4f8d0d4b12833
4
+ data.tar.gz: 817d1cb42016917f660d137a611577c36a4b5798466a38d647ed2a5940ab8aed
5
+ SHA512:
6
+ metadata.gz: 7c1d895fdabb8273b7f878fd872bcb9cb731a3211eafccc1f55d1a1c95f3a0dbae3de77956dc32eec6f15e27097dfd66c50877b764d500babd4fc633e491c15b
7
+ data.tar.gz: 9c1cb7904f8fcd7c2cf7cb5ac5e5e3b69e676bec23fadd5894434b6df4c7d88b4e3e15b81777a8d3f8936712f9644def30427fa365ee162c741e9dda4af6d957
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-12-02
4
+
5
+ - Initial release
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # PreC
2
+
3
+ PreC aims to solve all the problems created by every C successor.
4
+
5
+ The two main advantages of C are abstraction and simplicity.
6
+ Abstraction means that C code can be easily ported to many different hardware.
7
+ Simplicity means that it is easy to learn C (despite the fact that the language is hard to master), and a compiler for the language can be easily implemented.
8
+
9
+ The problem with C successors is that they offer many features to ease software development, but it is impossible to add such features without influencing the code design and without making the language more complex.
10
+ Also, it is common for such features to negatively impact runtime performance.
11
+ And many times, such new features are not exactly what you need, since software design requirements are vastly different for each software.
12
+ In the end, each language becomes an API, so having many new languages trying to succeed C became its own problem, since libraries need to be ported and rewritten several times.
13
+
14
+ The fundamental principle for PreC is that a C successor must be a simpler language, or a language that produces more efficient binaries, or both.
15
+ Anything beyond that is unnecessary bloat.
16
+ Instead of offering ad hoc features that may improve your productivity, the goal is to provide metaprogramming tools that allow you to create the exact features you need for your project.
17
+ If you find that a meta-language is not working for a project, you can keep the generated C code and move to another meta-language without having to rewrite your entire software.
18
+ PreC uses ERB as a meta-programming language on top of C.
19
+ It is named PreC because it compiles ERB code to C before the C code is compiled to binary.
20
+
21
+
22
+ ## Installation
23
+
24
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
25
+
26
+ Install the gem and add to the application's Gemfile by executing:
27
+
28
+ ```bash
29
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
30
+ ```
31
+
32
+ If bundler is not being used to manage dependencies, install the gem by executing:
33
+
34
+ ```bash
35
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ TODO: Write usage instructions here
41
+
42
+ ## Development
43
+
44
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
45
+
46
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
47
+
48
+ ## Contributing
49
+
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pre_c.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ task default: :test
@@ -0,0 +1,50 @@
1
+ require_relative "template"
2
+
3
+ module PreC
4
+ module MetaCode
5
+ def compile input_path, output_path
6
+ self.read input_path
7
+
8
+ begin
9
+ File.write(output_path, @output)
10
+ rescue Errno::ENOENT => e
11
+ path = File.dirname(output_path)
12
+ Dir.mkdir(path)
13
+ File.write(output_path, @output)
14
+ end
15
+ end
16
+
17
+ def read file_path
18
+ @templates = []
19
+
20
+ erb = ERB.new(File.read(file_path), eoutvar: "@erb_out")
21
+ erb.result(binding)
22
+ @templates << @erb_out
23
+
24
+ @output = @templates.inject("") do |r, i|
25
+ if i.is_a? String then
26
+ r + i
27
+ else
28
+ r + read(i.file_path) {i.content}
29
+ end
30
+ end
31
+
32
+ return @output
33
+ end
34
+
35
+ def partial file_path
36
+ content = nil
37
+
38
+ @templates << @erb_out
39
+ @erb_out = ""
40
+
41
+ if block_given?
42
+ yield
43
+ content = @erb_out
44
+ @erb_out = ""
45
+ end
46
+
47
+ @templates << Template.new(file_path, content)
48
+ end
49
+ end
50
+ end
data/lib/pre_c/raw.rb ADDED
@@ -0,0 +1,11 @@
1
+ require_relative "meta_code"
2
+
3
+ module PreC
4
+ class Raw
5
+ include MetaCode
6
+
7
+ def initialize file_path
8
+ self.compile file_path, file_path.delete_suffix(".erb")
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module PreC
2
+ class Template
3
+ attr_reader :file_path, :content
4
+
5
+ def initialize file_path, content
6
+ @file_path = "#{PreC.path}/template/#{file_path}.erb"
7
+ @content = content
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PreC
4
+ VERSION = "0.1.0"
5
+ end
data/lib/pre_c.rb ADDED
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "erb"
4
+
5
+ require_relative "pre_c/meta_code"
6
+ require_relative "pre_c/raw"
7
+ require_relative "pre_c/version"
8
+
9
+ module PreC
10
+ class Error < StandardError; end
11
+
12
+ Generic = Struct.new('Generic', :classes, :args)
13
+
14
+ @@generics = []
15
+
16
+ def self.path = @@path
17
+
18
+ def self.generic classes, args
19
+ @@generics << Generic.new(classes, args)
20
+ end
21
+
22
+ def self.pre_compile
23
+ @@path = Dir.pwd
24
+
25
+ @@generics.each do |generic|
26
+ generic.classes.each {_1.new(@@path, generic.args)}
27
+ end
28
+
29
+ meta_code = Dir["#{path}/src/**/*.erb"]
30
+ meta_code.each {Raw.new _1}
31
+ end
32
+ end
data/sig/pre_c.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module PreC
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pre_c
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Frederico Linhares
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: erb
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '5.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '5.0'
26
+ email:
27
+ - fred@linhares.blue
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - CHANGELOG.md
33
+ - README.md
34
+ - Rakefile
35
+ - lib/pre_c.rb
36
+ - lib/pre_c/meta_code.rb
37
+ - lib/pre_c/raw.rb
38
+ - lib/pre_c/template.rb
39
+ - lib/pre_c/version.rb
40
+ - sig/pre_c.rbs
41
+ homepage: https://gitlab.com/fredlinhares/pre_c
42
+ licenses:
43
+ - Apache-2.0
44
+ metadata:
45
+ homepage_uri: https://gitlab.com/fredlinhares/pre_c
46
+ source_code_uri: https://gitlab.com/fredlinhares/pre_c
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.0
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 4.0.10
62
+ specification_version: 4
63
+ summary: A metaprogramming tool for low-level languages such as C and Assembly.
64
+ test_files: []