To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.nqcOpen lugnet.robotics.rcx.nqc in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / NQC / 1635
1634  |  1636
Subject: 
Re: NQC ideas
Newsgroups: 
lugnet.robotics.rcx.nqc
Date: 
Thu, 11 Mar 2004 03:44:19 GMT
Viewed: 
4720 times
  
In lugnet.robotics.rcx.nqc, John Hansen wrote:
NQC is definitely sticking with its C heritage with respect to semi-colons.
Elisabeth mentioned fancier math and IP features.  Neither of those seem
possible when you consider that the compiler has to generate code that runs on
the LEGO firmware virtual machine which doesn't give you any facilities for
doing much in the way of fancy math or IP stuff.

I am trying to figure out a decent way to support the Spybot stack and
subroutines that can take parameters and call other subroutines.  LEGO
implements support for these features of the Spybot firmware in their Mindscript
compiler.  The way they do this is to push subroutine variables onto the stack
prior to the subroutine call and access each of the parameters via a stack
pointer.  Local variables in a subroutine in the Mindscript language all have to
be declared before any other code in the subroutine (kind of like Pascal).
These local variables are also accessed via the stack (rather than by using the
"local" variables provided by the firmware - which are in very short supply).
Declaring local variables in a subroutine results in adjustments to the stack
pointer value used for each of the subroutine parameters (i.e., the parameters
are pushed further down on the stack).

I'd like to do something like that in NQC for the Spybot target, but in C/C++
you can declare a variable anywhere you like and limit its scope to just a small
subset of the total subroutine scope.  That makes keeping track of the parameter
variable addresses (stack pointer values) very complicated.  Since nobody is
interested in any of this stuff (based on the feedback I've received so far) I'm
inclined to go for a simple solution rather than a complex one.

Would it be too contrary to C/C++ to introduce a construct in NQC which allows
for local stack-based variables to be declared only at the beginning of a
subroutine.  Other variables could be defined anywhere using the existing
syntax, but programmers could take advantage of the stack in the Spybot firmware
using a special keyword that has to occur before any other keyword.  That's one
idea.

Hi John,

  C is more restrictive than C++ when it comes to variable declaration.  In C,
you can only declare variables at the beginning of a block before any
executable.

  Well, lets see..... any variables declared outside a function are by
definition static in C.  In NQC any variables declared inside a function or
subroutine are static, but with local scope.

  If you knew the target was Spybotics, why not just by default make the
variables declared inside a subroutine be automatic (i.e. on the stack).
Programmers could use the "static" keyword to force variables to not be on the
stack.  Alternatively, the "auto" keyword could be used to indicate variables
that go on the stack, and you could have other variables be static.


Insert your better ideas here.  Especially if you can contribute an
implementation which works with the existing syntax.

I'd still love to hear from anyone who may have tried out some of the new
features in NQC 3.0a2.

Thanks,

John Hansen
http://bricxcc.sourceforge.net/nqc/

Kevin



Message has 1 Reply:
  Re: NQC ideas
 
(...) As of C99 that is no longer true, though still current usage to support older compilers. Jürgen (20 years ago, 11-Mar-04, to lugnet.robotics.rcx.nqc)

Message is in Reply To:
  NQC ideas
 
NQC is definitely sticking with its C heritage with respect to semi-colons. Elisabeth mentioned fancier math and IP features. Neither of those seem possible when you consider that the compiler has to generate code that runs on the LEGO firmware (...) (20 years ago, 11-Mar-04, to lugnet.robotics.rcx.nqc)

6 Messages in This Thread:


Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR