Page 1 of 3

NXC: can't pass expression to ArrayInit

Posted: 15 Jul 2011, 18:36
by HaWe
NXC: can't pass expression to ArrayInit

This doesn't work:

Code: Select all

  int i=0, S, R;
  ArrayInit(C, 0, R*S);
This works:

Code: Select all

  int i=0, S, R;
  int dim=R*S;
  ArrayInit(C, 0, dim);

Re: NXC: can't pass expression to ArrayInit

Posted: 15 Jul 2011, 19:38
by afanofosc
Doc, ArrayInit along with many other NXC API functions cannot take NXC expressions since they are simply #define macros that emit an NBC asm block. I will try to improve the documentation to make this clear.

John Hansen

Re: NXC: can't pass expression to ArrayInit

Posted: 15 Jul 2011, 21:54
by HaWe
what a pity!
(for the wish list: every function (edit: AND expression) should be allowed to get expressions (variables, functions) passed to it!)

Re: NXC: can't pass expression to ArrayInit

Posted: 15 Jul 2011, 23:01
by muntoo
doc-helmut wrote:(for the wish list: every function should be allowed to get expressions (variables, functions) passed to it!)
Yeah, but then we lose the awesome optimizations. If the NBC intermediate code optimizer was improved, we could have inline NXC API functions instead.

Re: NXC: can't pass expression to ArrayInit

Posted: 16 Jul 2011, 07:38
by HaWe
Maybe we could drop NBC some day at all because NXC can generate byte code directly? :))
And will be able to program awesome optimizations even using C code by our own? :))))
(let NXC become such a C compiler, not a code interpreter for NBC!)

Re: NXC: can't pass expression to ArrayInit

Posted: 16 Jul 2011, 11:34
by linusa
doc-helmut wrote: (let NXC become a compiler
Your wish has been granted! NXC has become a compiler.

Re: NXC: can't pass expression to ArrayInit

Posted: 16 Jul 2011, 20:59
by muntoo
First of all: NXC is not a "code interpreter" for NBC.
doc-helmut wrote:Maybe we could drop NBC some day at all because NXC can generate byte code directly? :)
Erm... Any good compiler (most likely [almost] any compiler) will generate an intermediate code representation - like NBC.

Not technically correct:
NXC->Lexer->Syntax Analyzer->Semantic Analyzer->Parser->Intermediate Optimization->Intermediate Representation (NBC)->Byte code (RXE)->Byte code optimization?

Simpler version:
NXC->NBC->RXE

It's a hell lot easier to fix compiler bugs, maintain, optimize, etc. As a bonus, you can look at the NBC code too, and see what the compiler's thinking! :D

Re: NXC: can't pass expression to ArrayInit

Posted: 17 Jul 2011, 09:00
by HaWe
well, though NBC is actually the byte code compiler, not NXC, while NXC appears to me more or less to be a code parser to NBC (as far as I can recognize it ( - parser; interpreter was surely the wrong word - )), and many of NXC keywords seem to be wraps around NBC code, we're getting OT.
To me it would be sufficient for the 1st step if
every function (edit: AND expression!) should be allowed to get expressions (variables, functions) passed to it

Re: NXC: can't pass expression to ArrayInit

Posted: 17 Jul 2011, 15:35
by afanofosc
The API library is not the compiler. You are welcome to write function wrappers around NXC API library routines that do not have the behavior or functionality that you are looking for.

The primary reason why many API functions are #define macros that emit asm blocks is because this allows for what the help refers to as "variant" arguments. Function overloading is not coming any time soon since it is EXTREMELY HARD for me to figure out how to support it. The #define macros give you that ability and result in faster code with the limitation that you can't pass NXC expressions into them.

FYI, especially of late you are not making me eager to help you or to implement items from your NXC wish list.

John Hansen

Re: NXC: can't pass expression to ArrayInit

Posted: 17 Jul 2011, 15:41
by HaWe
#defines do not help if I want to pass a A[] instead of a A[][] to a function, because they are calculating internally by different formulas (e.g., for a[k] x B[k][n] a[k] has to be transformed to a[k]Tbefore, the same it's for a[k] x b[k].

BTW, what means "especially of late you are not making me eager to help you or to implement items from your NXC wish list"? why am I late?