Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » DSDP - Real-Time Software Components (RTSC) » XDCspec: how to use '[string]' map type? Is it only for meta?(Generated target code does not build due to missing initializer.)
XDCspec: how to use '[string]' map type? Is it only for meta? [message #1549954] Tue, 06 January 2015 20:58 Go to next message
Alexei Colin is currently offline Alexei ColinFriend
Messages: 8
Registered: October 2013
Junior Member
This documentation page on XDCspec mentioned the '[string]' map type:

Quote:
the keyword string in conjunction with the [] operator, signifying the type map-into(t) that effectively overlays direct access via string-valued keys on an underlying vector-of(t).


It's fairly self-explanatory in meta domain, and there's some examples spread around XDCtools package repo. All usages appear to be in metaonly code. Does this type apply to target domain at all? If so, how would the data be accessed from target code? If not, then what's the rationale, since there are object dictionaries in meta-land anyway?

Since it's an array, I thought maybe there would be macros generated for the string keys that would identify numeric indices into the array, but doesn't look like that's the case. In fact, it looks like the generated code does not compile (XDCTools v3.30.04.52), because there's no initializer value generated at all (full source, incl. generated code ,attached, just in case):

module TestModule {
    config UInt32 aMap[string] = [["answer", 42], ["notanswer", 43]];
}


cl86U package/cfg/xdctest_p86U.c ...
package/cfg/xdctest_p86U.c:3452:72: error: expected expression before ';' token
 __FAR__ const CT__xdctest_TestModule_aMap xdctest_TestModule_aMap__C = ;


If it's only for meta, maybe an error could be thrown at translation time if the user omits the metaonly specifier on a config value of type map in a module not marked metaonly?
Re: XDCspec: how to use '[string]' map type? Is it only for meta? [message #1552173 is a reply to message #1549954] Thu, 08 January 2015 02:12 Go to previous messageGo to next message
Sasha Slijepcevic is currently offline Sasha SlijepcevicFriend
Messages: 114
Registered: July 2009
Senior Member
Alexei,
I don't remember seeing the map[string] type used on the target. I am guessing it was meant to be used at the config time only, but I'll check little bit more.
Here is one more link that describes how maps can be used http://rtsc.eclipse.org/docs-tip/XDCscript_-_Map-Object. I am not sure to what dictionaries you are referring.
If they are metaonly indeed, I agree an error would be helpful.
Re: XDCspec: how to use '[string]' map type? Is it only for meta? [message #1552316 is a reply to message #1552173] Thu, 08 January 2015 04:07 Go to previous messageGo to next message
Alexei Colin is currently offline Alexei ColinFriend
Messages: 8
Registered: October 2013
Junior Member
The Map-Object type was an interesting read, thanks. The Map-Objectimproves over the built-in object dictionary -- might come in handy. I was refering to the built-in "dictionary" aka. the plain Javascript object which can house key-value pairs as property-value pairs. Given that there are two map types (the built-in and the Map-Object of XDCscript) already available for meta code, it strengthens the question whether '[string]' was intended as a map that could be used in the target domain, analogously to how '[length]' is very useful on the target and similarly not too useful for meta given build-in arrays which already have '.length' property. I'll look out for any details you find. Thanks!
Re: XDCspec: how to use '[string]' map type? Is it only for meta? [message #1554114 is a reply to message #1552316] Fri, 09 January 2015 03:14 Go to previous messageGo to next message
Sasha Slijepcevic is currently offline Sasha SlijepcevicFriend
Messages: 114
Registered: July 2009
Senior Member
The main difference between plain JavaScript and XDCscript is in type checking. A JavaScript object can't restrict the type of value assigned to a key, while maps can. XDCspec requires that every config parameter has a type, so you can't even declare a parameter to be a plain JavaScript object. You could consider this special case of Map to be the closest representation of a JavaScript object in XDCspec:

Any obj[string];

I added an error message for the Map usage without a 'metaonly' decalaration. I think I am late for the next XDCtools release, which should be any day now, but eventually the error message with show up. Thanks for finding this bug.
Re: XDCspec: how to use '[string]' map type? Is it only for meta? [message #1561160 is a reply to message #1554114] Tue, 13 January 2015 01:23 Go to previous messageGo to next message
Alexei Colin is currently offline Alexei ColinFriend
Messages: 8
Registered: October 2013
Junior Member
Ah, for typed params -- that's the intention of these vector and maps. Clear. Thanks for clarifying and adding the error notification.

Quote:
You could consider this special case of Map to be the closest representation of a JavaScript object in XDCspec:
Any obj[string];


What about
metaonly config Any foo = {};
Seems to be accessible from the script as a JS object/map.
Re: XDCspec: how to use '[string]' map type? Is it only for meta? [message #1566388 is a reply to message #1561160] Thu, 15 January 2015 21:08 Go to previous message
Sasha Slijepcevic is currently offline Sasha SlijepcevicFriend
Messages: 114
Registered: July 2009
Senior Member
That works too.
Previous Topic:XDCTools 3.30: core distribution: which repository is x86 'target' package in?
Next Topic:XDCspec: variable length vectors ('[]', '[length]') generate undefined type names when nested
Goto Forum:
  


Current Time: Wed Sep 26 09:15:59 GMT 2018

Powered by FUDForum. Page generated in 0.01792 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top