To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.nxtOpen lugnet.robotics.nxt in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / NXT / 687
686  |  688
Subject: 
Re: NBC/NXC beta news
Newsgroups: 
lugnet.robotics.nxt
Date: 
Wed, 25 Apr 2007 19:38:34 GMT
Viewed: 
18250 times
  
In lugnet.robotics.nxt, Doug Eaton wrote:
Is an array of struct expected to work?  When I try to access a field within an
element I get an error:

# Error: parser error
File "test.nxc" ; line 217
#    val=cell[index].b
#----------------------------------------------------------
# Error: ')' expected

Of note, the field name is truncated to the first character in the error.

The problem with code of this sort is that the opcodes for manipulating values
do not readily allow for this type of operation. To set the variable val to the
value of the bxxx field of the structure type stored in your array of structs I
ultimately need to generate a mov opcode.

mov val, somevariablename

The VM doesn't have variants of the mov opcode which allow for offsets or
indirects of any sort.  So I would need to generate code which copies out
cell[index] into a temporary variable of the correct structure type and then I
would need to generate the mov opcode using the temporary variable.  I'd need at
least one unique temporary for each thread and each structure type.  Not
impossible but rather complicated.  The workaround is to simply declare a
variable explicitly of the correct structure type and set it to cell[index] then
set val in a second statement.

John Hansen



Message has 2 Replies:
  Re: NBC/NXC beta news
 
(...) Well that technique does compile, but produces interesting results: --- #include "NXCDefs.h" struct st { string s1; int i1; } st a1[]; st v1,v2; task main() { v1.s1 = "test"; v1.i1 = 9; NumOut(0,0,v1.i1); TextOut(40,0,v1.s1); (...) (18 years ago, 25-Apr-07, to lugnet.robotics.nxt)
  Re: NBC/NXC beta news
 
(...) I keep forgetting the not-quite part of your language is an attempt to map operations directly onto the underlying VM. I was hoping to avoid rewriting code but now realize that making all elements of this structure top-level elements will (...) (18 years ago, 29-Apr-07, to lugnet.robotics.nxt)

Message is in Reply To:
  Re: NBC/NXC beta news
 
(...) Structure support is a feature I have been waiting for. I have some large programs that should port easily once structs work. Is an array of struct expected to work? When I try to access a field within an element I get an error: # Error: (...) (18 years ago, 17-Apr-07, to lugnet.robotics.nxt)

7 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