HackerTrans
トップ新着トレンドコメント過去質問紹介求人

gregoryc_

no profile record

投稿

Emerald C – Ultimate C Preprocessor

github.com
2 ポイント·投稿者 gregoryc_·4 年前·2 コメント

How to make C much easier and more powerful (C preprocessor)

cboard.cprogramming.com
10 ポイント·投稿者 gregoryc_·4 年前·9 コメント

コメント

gregoryc_
·4 年前·議論
People can be very rust-centric, but compilation of Rust (or Crystal) can take forever. The fast compilation of this "language" makes running scripts be like a scripting language, like Perl.

Will it be hard for me to find people who want to go in this direction?

I hope not.

This could handle all of your problems, and if you change your mindset a little bit to be willing to use this and to contribute to this project, all of your major programming difficulties might be solved. (And lets be honest, performance ALWAYS matters. Running a script in 5 hours vs 15 hours DOES matter, maybe not to your employer, but to you, it should.)

Thank you.
gregoryc_
·4 年前·議論
I have named this project and I have made a github for it.

I am looking for people to have a discussion about the direction of this.

After that, code formatting and things like that can be fixed.

What functions would you like to add to make this language even better?

String handling is a big problem for C. I handled that.

It would be nice to have 1) backticks like ruby or bash 2) blocks like ruby or crystal

So one could do something like Thread.new {

........

} in C

3) Maybe I can add list comprehensions? That would be cool. 4) I want to have good gsub variants

These are 4 things we have yet to implement.

What other methods would you guys like?

The source code is one file of 437 lines of Crystal code.

It is not hard to fork or modify.

There are no classes or anything complicated.
gregoryc_
·4 年前·議論
https://github.com/gregoryc/EmeraldC/
gregoryc_
·4 年前·議論
I just made a github.

https://github.com/gregoryc/EmeraldC/
gregoryc_
·4 年前·議論
I just made a github.
gregoryc_
·4 年前·議論
https://github.com/gregoryc/EmeraldC
gregoryc_
·4 年前·議論
memcpy is better than strncpy and strcpy ;)
gregoryc_
·4 年前·議論
Depends on the functions used. memcpy is better than strcpy
gregoryc_
·4 年前·議論
The simplest solution is a preprocessor. The original founders of C made one, probably because they needed it. But adding another lightweight one is simple. C++ has bloat. Compilation time can be slow.

I realize that this is radical, but if people could work with me on this, this could solve all your problems, no really, it could solve all your problems. And if it can't solve all your problems yet, then modify it to

https://cboard.cprogramming.com/c-programming/181160-hi-i-ha...

There is no need for another language. Just use this

Gregory
gregoryc_
·4 年前·議論
Check out https://cboard.cprogramming.com/c-programming/181160-hi-i-ha...

I posted this less than 24 hours ago.

This might be what you want, and there's no overhead at all.

It might actually speed up your code. 15x faster regex

I just made this. I'm looking for contributors :)
gregoryc_
·4 年前·議論
Has anyone checked out this?

You can use C, but with better syntax.

https://cboard.cprogramming.com/c-programming/181160-hi-i-ha...

I'm looking for contributors. :)
gregoryc_
·4 年前·議論
I currently use #define true 1 and #define false 0

Do you think I should remove that?
gregoryc_
·4 年前·議論
I'm happy to see that this went semi-viral. I got 2400 views in a few hours :)
gregoryc_
·4 年前·議論
Yes, I am aware that the style of the crystal script is not perfect yet.

That's a TODO
gregoryc_
·4 年前·議論
I'm trying to gather support for this project. Is anyone interested? I seem to have gotten over 2,400 views on the cprogramming site in a few hours.

Give me an email :)
gregoryc_
·4 年前·議論
I can modify that.

Anyone can modify that. I might have a global namespace in some way. I might use a certain prefix.

Or I can have an inline function that gets the pointer.
gregoryc_
·4 年前·議論
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)

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.

( Licensed under the BSD license )