Recent Posts

Pages: [1] 2 3 ... 10
1
Ideas / Struct Function declaration
« Last post by bas on April 15, 2017, 09:22:04 PM »
With the current syntax, I think it's quite unclear when a function is a struct function. I would
like to try to make this more explicit. So hereby some ideas.

Code: [Select]
func void point_add(Point* p, int32 x) { .. }    // current syntax

func void Point_add(Point* p, int32 x) { .. }   // allow Upper-case as first char, so looks more like type Point

func void point_add[Point](Point* p, int32 x) { ..} /// hmm, 3 points in a row..no

func void point_add(Point* p, int32 x) @{structfunc} { ..} // via attribute
func void point_add(Point* p, int32 x) @{struct='Point'} { ..} // via attribute, nr 2

func void Point.add(Point* p, int32 x) { .. }   // most explicit, via member operator

..

I like the last option best. The two arguments against it are:
  • it's harder to see what the c- function name is (point_add in all cases). The is actually currently
        the same for module attributes as well (Foo.bar() -> foo_bar)
  • The syntax breaks more with the ansiC style

What do you think?
2
General Discussion / Re: VLA crash
« Last post by bas on March 15, 2017, 08:37:44 AM »
The issue reproduces nicely indeed. There seem to be several issues here. The first one
is that array subscript expressions were not marked at compile-time-constant (if they were).
That is fixed on a branch now. Since C2 allows more then C sometimes, I'll look carefully
at the order of evaluation, since it's otherwise easy to get loops in constant declarations
that we have to detect/avoid..
3
General Discussion / Re: Diffs to C99 and C11
« Last post by admin on March 13, 2017, 08:05:37 AM »
Since C2 uses the clang preprocessor, all normal C preprocessor command should work. This is more a by-effect than
a real  design target..
4
General Discussion / Re: VLA crash
« Last post by admin on March 13, 2017, 08:04:29 AM »
Good one!
I'll turn it into a unit test and fix it this evening..
5
General Discussion / VLA crash
« Last post by shiv on March 08, 2017, 04:59:55 AM »
The following code:

module test;
import stdio;
public func int32 main () {
   const uint64[2] Dims = {2, 3}
   float32[Dims[0]][Dims[1]] p;
   p[0][0] = 1;
   p[0][1] = 2;
   stdio.printf ("%g %g", p[0][0], p[0][1]);
  return 0;
}

causes the following error:
c2c: /home/shiv/c2compiler/c2c/CGenerator/CCodeGenerator.cpp:485: void C2::CCodeGenerator::EmitDecl(const C2::Decl *, C2::StringBuilder &): Assertion `D' failed.
Aborted (core dumped)

Not sure what Assert 'D' is?
Thanks.
--shiv--
6
General Discussion / Re: Diffs to C99 and C11
« Last post by shiv on March 07, 2017, 12:14:54 AM »
Looking through the source I see that "#define" is allowed. I also tried and noticed that "#include" is allowed too. Just with those two I can get some of functor like generics that I need.
--shiv--
7
General Discussion / Re: Complex numbers
« Last post by shiv on March 07, 2017, 12:03:09 AM »
In the standard (assuming we include complex.h) only "float/double complex" are allowed. GNU also allows "int complex".
All the arithmetic operators *,+,- are overloaded and ~ means complex conjugation.
If we include tgmath.h then we also get "generic" math functions like sin(), cos(), etc. So, it is actually quite nice!

I wonder if in c2 you should follow Rust's example and have separate modules named float32, float64, complex32, complex64, etc.,
and hide the functions inside each module. That way we could avoid names like sin, sinf, sinc, sinz, etc..

Not sure how to call C macros from C2; otherwise there might be another route though that might not work if you target llvm-ir (?) directly.

--shiv--
8
General Discussion / Re: Typo in manual
« Last post by bas on March 06, 2017, 09:36:44 PM »
fixed.
I hope you have a very pleasant flight eh experience from now on ;)
9
General Discussion / Re: Complex numbers
« Last post by admin on March 06, 2017, 08:02:26 AM »
I haven't really thought about that yet. I almost never (read: never) write code with Complex numbers and such.
Are there specific painpoints using them in C?
10
General Discussion / Re: Typo in manual
« Last post by admin on March 06, 2017, 08:00:52 AM »
ouch, I'll fix start right away (this evening)
Pages: [1] 2 3 ... 10