How many times have you created quick and dirty script to generate C tables, parameterized code, etc. ?

Did the script ended up messy?

Is there a better way?

I've tried quite a lot of solutions but none of them worked really well and because of that I've decided to create a templating engine based on Python specialized for generating source code.

Example input that generates table of prime numbers:

#ifndef PRIMES_H
#define PRIMES_H

@ from math import sqrt
@ max_prime = 1000

unsigned int primes[] = {
        2,
[@for](/users/for) i in range(3, max_prime+1,2)
@ is_prime = True
@ for j in range(3, int(sqrt(i)))
@  if i % j == 0
@   is_prime = False
@  endif
@ endfor
@ if is_prime
        {{ i }},
@ endif
[@endfor](/users/endfor)
};

#endif /* PRIMES_H */

What is this useful for? There are number of use cases. One of the ideas is to generate syscall testcases from high level descriptions (a bit similar to what trinity does, but far more complete).

I already have a proof of concept ready, but it's far from complete solution.

Looking for hackers with the skills:

Nothing? Add some keywords!

This project is part of:

Hack Week 11

Activity

  • almost 10 years ago: pluskalm liked this project.
  • almost 10 years ago: osukup liked this project.
  • almost 10 years ago: ebischoff liked this project.
  • almost 10 years ago: metan started this project.
  • almost 10 years ago: metan originated this project.

  • Comments

    • metan
      almost 10 years ago by metan | Reply

      Git repo with initial code is at https://github.com/metan-ucw/cct

    • metan
      almost 10 years ago by metan | Reply

      Language description, howto, tests and example code are available in the git repository.

      Packages are in obs at:

      https://build.opensuse.org/package/show/home:metan/cct

      And the language and implementation seems to be good enough for 1.0.0 release.

    Similar Projects

    This project is one of its kind!