Page 1 of 1

semi-new language & compiler for test.

Posted: Tue Jun 01, 2010 7:51 am
by blackoil
hi

i made another vector c-like language compiler recently, and port it to my os. it seems work fine.

little language brief:

int main()
{
int[4] * p;

(*p)[2]=100;
}

Re: semi-new language & compiler for test.

Posted: Tue Jun 01, 2010 12:53 pm
by whowhatwhere
Sorry to rain on your parade, but I don't see the advantage of this. Putting the size of the subsequent array beside the type name instead of the identifier seems like a bad idea. For one, it means that each declaration ends up being ambiguous or creating using stack space in excess for no reason. It creates confusion for the reader and adds extra complexity to the compiler. It's basically the same as C, except that array size is placed beside the type instead of after the identifier. You can accomplish the exact same thing in C by dereferencing 'p' combined with an displacement offset like this:

Code: Select all

int *p[4];
*(p+2) = 100; /* or */
(*p)[2] = 100;

Re: semi-new language & compiler for test.

Posted: Tue Jun 01, 2010 4:13 pm
by qw
I guess that "int[4] * p;" defines a pointer to an array of four ints, not an array of four pointers to an int.

Nevertheless I do not see the advantage over C, and moreover, the pointer isn't initialized so "(*p)[2]=100;" is trashing memory.

Re: semi-new language & compiler for test.

Posted: Tue Jun 01, 2010 8:18 pm
by blackoil
yes, it's a pointer of int[4]. It functions just like traditional C, but in clean syntax.

declaration syntax: typelist variablelist;

int*(int*)* p_function; // a function pointer, function itself return pointer, its argument is a pointer too

vector int [4] vi; // vector int128, operate sse instruction directly

typedef mytype int*[4]* // define new type

Re: semi-new language & compiler for test.

Posted: Wed Jun 02, 2010 5:28 am
by Lithorien
blackoil wrote:yes, it's a pointer of int[4]. It functions just like traditional C, but in clean syntax.
...Where "clean syntax" means "completely unreadable by people who understand C conventions"?

C works. Leave it alone.

Re: semi-new language & compiler for test.

Posted: Wed Jun 02, 2010 5:58 am
by blackoil
Lithorien wrote:
blackoil wrote:yes, it's a pointer of int[4]. It functions just like traditional C, but in clean syntax.
...Where "clean syntax" means "completely unreadable by people who understand C conventions"?

C works. Leave it alone.
well, how difficult to understand?

you can understand something like
int*(*f)(int*p);
but you can not understand otherthing like
int*(int*)* f;

convention is man-made, it doesn't mean it could not be changed.
I am not here to replace C language.

Re: semi-new language & compiler for test.

Posted: Wed Jun 02, 2010 6:00 am
by qw
Like I said, I don't see the advantage, but I don't see why you shouldn't design your own language either. I wish you good luck. Post some documentation if you like.

Re: semi-new language & compiler for test.

Posted: Wed Jun 02, 2010 6:11 am
by blackoil
Hobbes wrote:Like I said, I don't see the advantage, but I don't see why you shouldn't design your own language either. I wish you good luck. Post some documentation if you like.
the most difference is the declaration syntax.
typelist variablelist;
left side is type declarator, right side is identifier. pretty simple.

I haven't finished any documents yet. but the compiler has finished for 1 year, with x86 mips ppc cross compilation available.