The project AutoC ships a collection of Ruby classes related to automagic C source code generation.
Specifically, it provides a means of generating strongly-typed general purpose C data containers (vectors, lists, maps etc.) similar to those provided by the C++'s STL template containers but implemented in pure ANSI C language.
Unlike similar attempts to introduce type-generic data containers to the C language which are typically the macro libraries, the AutoC is an explicit source code generator with 100% of provided functionality is implemented as (inline or extern) C functions making the code explicit, browseable and debuggable.
Install the autoc Ruby package from RubyGems
gem install autocGenerate a documentation header auto.h with reference of what can be provided by the AutoC
ruby -r autoc/scaffold -e docsExtract the documentation with Doxygen
doxygen .Explore the rendered HTML documentation starting at html/index.html
Create auto code descriptor in Ruby sample.rb
require 'autoc/module'
require 'autoc/hash_set'
AutoC::Module.render(:sample) do |m|
m << AutoC::HashSet.new(:IntSet, :int)
endGenerate C code into sample_auto.[ch]
ruby sample.rbCreate sample C code sample.c
#include <stdio.h>
#include "sample_auto.h"
int main(int argc, char** argv) {
IntSet set;
IntSetCreate(&set);
IntSetPut(&set, 1);
IntSetPut(&set, 0);
IntSetPut(&set, 1);
IntSetPut(&set, -1);
printf("size = %d\\n", IntSetSize(&set));
for(IntSetRange r = IntSetRangeNew(&set); !IntSetRangeEmpty(&r); IntSetRangePopFront(&r)) {
printf("%d\\n", IntSetRangeTakeFront(&r));
}
IntSetDestroy(&set);
}Build sample program
cc -g -o sample sample.c sample_auto.cTest sample with Valgrind
valgrind sampleGenerate C test suite into tests_auto.[ch]
ruby -r autoc/scaffold -e testsBuild test suite
cc -g -o tests tests_auto.cWitness the test suite run time correctness
valgrind testsCreate CMake-powered skeleton project named runme in the current directory
ruby -r autoc/scaffold -e project runmeConfigure the generated project
cmake .Build the generated project
cmake --build .This code is distributed under terms of the 2-clause BSD {file:LICENSE}.
The project's home page is GitHub.
The released ruby gems are published in RubyGems.
The condensed description of the changes is in the {file:CHANGES.md}.
Cheers && happy coding!
Oleg A. Khlybov [email protected]