Thread: Hi, I have created some work that I think will be really valuable to this community..

  1. #1
    Registered User
    Join Date
    Aug 2022
    Posts
    9

    Post Hi, I have created some work that I think will be really valuable to this community..

    Howdy!

    First, let me state that I am very much a perfectionist.


    C is a wonderful language. C is probably the perfect programming language. It is one of the top two most widely used languages for a reason.


    Now, there are some problems with it of course, but it's hard to think of a more elegant language than it.


    It is the language of systems, the language almost all APIs are written in.


    It is the lingua franca of the software world.

    People try to avoid it, but they needn't.

    I think every programmer wants to find out how to do things, or use libraries that make things easier.

    Many programmers have done programming, grown dissatisfied, and then make another language. As a result, there are thousands of different languages.


    Well, recently, I made a preprocessor for C, that makes C incredibly EASY.


    C is fast and straightforward without it, but it has many features.




    If one runs the command line preprocessor, with the "--features" flag, the program shows all of its features


    Code:
    A better C
    C is a fantastic language. C compiles insanely fast, is the fastest language there is, is very clear, is native to all systems, and is useful for all purposes.
    Some people, e.g., Bjarne Stroustrup, consider that C is `not good enough`, and make languages like C++ or D (or thousands of others)
    This is not necessary.
    There is no reason to use Python instead of C for `simple scripting tasks`
    Some functions can be used as methods
    Makes for an excellent `scripting language` (which is really just native C without things making it slow)
    
    
    1      String     Interpolation "String interplation like this #{foo} " Calls the join() function (talked about below to join strings,
    delim is a static global in each module called `sep`.
    Make sure you free() the string after. The string is stored in a static global variable called `last`.
    So you could do puts(...); free(last)
    2      ew     *i.ew "Foo", a.ew "bar" | char* ends with another char*?
    3      sw     *i.sw "Foo", a.sw "bar" | char* starts with another char*?
    4      ==     Comparison of strs, "foo" == "bar"
    5      strip     Returns pointer to string that was stripped, in place
    6      chomp     void function, chomps end of string of spaces, i.chomp or chomp(i), in place
    7      gsub     Just like ruby, there is a gsub function.
    The preprocessor detects if you use and adds -lpcre2-8 to the link flags if you use it. Use $" for substitutions in argument 3 gsub(a, b, c)
    8      join     Joins an array of strings, to split(), use C's strtok (very fast)
    9      Lightweight     regexes are added, almost 15 times as fast as C's built in regex. They are very simple, they only have bracket expressions, like [a-z].
    To use it, you need to pass a buffer of the size of the expansion of the regex. Foo[a-fA-F] would be Foo[abcdefABCDEF]. That would be stored in a buffer.
    From testing, 15x times faster than C's regex POST COMPILATION, if compilation keeps happening, it might be hundreds of times faster. 
    Uses static inline functions, NO HEAP MEMORY unless you malloc before().
    10      print     Like old python print "Hello"(fputs);
    11      print_int     prints a number and returns the number, can be chained
    12      each_line,     Perlish, different names, by_line(s) or each_line(s), iterate over all lines, free after
    13      NOTE     You can use open_memstream() on UNIX to easily concatenate strings.
    asprintf() is another useful function which is UNIX-centric. open_memstream() could be an alternative to std::string.
    It works very well with each_line or by_lines (see above)
    These features seem simple, but they can make C programming much, MUCH easier

    for example (insignificant example)



    Code:
    int main() {
    
    
        stdin.each_line { |line|
            print line;
        }
    
    
        free(line);
    }
    You can iterate over the standard input like Ruby


    The thing with this is that it has 100% speed. The resultant preprocessed program becomes a normal C program



    The compile and run time for a program (if you use tcc and not gcc) can be about 24 milliseconds, which is faster than Ruby to run.


    Even though the program is preprocessed, re-preprocessed, compiled, assembled, linked, turned into an executable, and then run


    Kind of like early C++, this is a preprocessor for C.

    But it's much faster to compile than C++. Significantly so.

    Is anyone else interested in this? (BSD)


    I'm realising this under the BSD license. I'm interested if anyone else else likes this work, and would like to use it, or to work with me.

    Best regards,

    Gregory


    (Current program is written in Crystal (crystal-lang.org) -- it was written in ruby, it could be ported to another language.

    I would like to make this self-hosting, but that would take a little bit of work.)
    Attached Files Attached Files
    Last edited by gregoryc; 08-07-2022 at 09:54 PM. Reason: Typo

  2. #2
    Registered User
    Join Date
    Aug 2022
    Posts
    9
    Feel free to give me an email gregorycohenvideos at gmail dot com if you want to get in touch

    I see that this post has gone semi-viral. I'm happy

  3. #3
    Registered User
    Join Date
    Aug 2022
    Posts
    9
    Feel free to give feedback

  4. #4
    Registered User
    Join Date
    Aug 2022
    Posts
    1
    HI.
    I really like the general idea as I think that C really needs a 21st century preprocessor.
    I struggled a lot in the past to handle code templates and argument lists with the "standard pre-proc".
    Kudos to you.
    What I personally don't like is that the new preprocessor is not written in C (!).
    Moreover, something like Jinja2 would also attract more devs here and maybe be even more powerful.
    Of course, this is my humble opinion.

  5. #5
    Registered User
    Join Date
    Aug 2022
    Posts
    9
    Hi, 0badc0de, thank you for responding!

    >
    I really like the general idea as I think that C really needs a 21st century preprocessor.

    I kind of consider what I've made as a new programming language altogether. I've worked on that kind of thing in the past. Though not as good as this.


    This could actually SPEED UP C code, with the mini regexes, for example.

    >
    Kudos to you.

    Thank you


    > What I personally don't like is that the new preprocessor is not written in C (!).



    Well, Ruby was easier than C, before this. Crystal is a faster version of Ruby. Crystal has really good regexes and a fast start up time.

    Though Crystal is not available for Windows without WSL :/

    I said "
    I would like to make this self-hosting, but that would take a little bit of work."


    >
    Moreover, something like Jinja2 would also attract more devs here and maybe be even more powerful.


    Making C into something like PHP would be really powerful, yes.


    Would you be interesting in contributing code?

    I'm trying to network.


    Best regards,


    Gregory
    Last edited by gregoryc; 08-08-2022 at 11:08 AM.

  6. #6

  7. #7
    Registered User
    Join Date
    Aug 2022
    Posts
    9
    Once I get this sorted out, porting will be easy

    C & Regular Expressions

  8. #8

  9. #9
    Registered User
    Join Date
    Aug 2022
    Posts
    9
    I am just getting started with this project.


    1) I just gave it a name. "Emerald C"


    2) I just made a github.




    Fork and contribute, everyone!




    GitHub - gregoryc/EmeraldC: The Ultimate C Preprocessor

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How valuable is C in the jobmarket?
    By camel-man in forum General Discussions
    Replies: 5
    Last Post: 01-30-2013, 08:08 AM
  2. Sports Community
    By CompiledMonkey in forum Projects and Job Recruitment
    Replies: 5
    Last Post: 07-15-2004, 02:57 PM
  3. my file created wont work when i insert a menu. why????
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 06-22-2002, 12:03 AM
  4. A great community
    By Betazep in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 02-11-2002, 11:16 PM

Tags for this Thread