field started with % in struct in Specman - struct

I am new to Specman, just don't know what the "%" prefix of a field in struct mean?
for example, the codes below.
struct packet_s like any_sequence_item {
%addr : uint(bits: 2);
%data : list of byte;
...
};
What's the difference if we removed the "%"?
Thanks.

https://support1.cadence.com/api/CosWeb/TechPubDocViewerCosLite/fc3d80347c2f211300916bfa538b076651c4801891f9ea50632a49a087be22bdb643c4344882eaa17a4f8911ffeae7ae4b135bd5c651280b198cdf0fd45653fbb58f41e83ef196b05bc14ce64bdbe65f0cf4d2da8a027d933155221675c881fba3d831ea161e8d008c25cb280d677e9451f5aa8a0451a1ef2b0946a87c48f62860c3700f80457adc49c9b0edc1cd04118c01e7fcfcf36e1518240c3117007cd3886d869848346b919165453ac5e2d13c/Docs/sn_eref/sn_eref21.09/sn_eref.pdf
To get all support\docs related Specman you should first register to their website

Related

How to escape a closing tag in block comments /** */?

I want to have an example regex in a comment:
/**
* Example = ".*/full/.*" }}`
*/
pub fn my_fun() {}
I get a broken comment since */ is considered as ending the comment.
What would be a proper way to escape this so that some autogenerated docs don't display the escape character?
You can do something like
/**
* Example = ".\*\/full/.*" }}
*/
pub fn my_fun(){}
It'll get rendered as
This should do.
But the recommended ways in rust are
https://doc.rust-lang.org/book/ch03-04-comments.html
https://doc.rust-lang.org/book/ch14-02-publishing-to-crates-io.html#making-useful-documentation-comments

How can I insert a key-value pair in an unordered map that is present in the innermost struct in rust programming language?

This is my data model:
pub struct RaffleDetails {
prize: Balance,
start: Timestamp,
end: Timestamp,
participants: UnorderedMap<AccountId, Balance>,
}
pub struct RaffleDapp {
raffles: UnorderedMap<AccountId, RaffleDetails>,
}
How can I insert a key-value pair in the 'participants' variable?
I tried self.raffles.get(&raffle_account_id).unwrap().participants.insert(&env::predecessor_account_id(), &confidence); but it's not persistent.
References:
UnorderedMap
NEAR Rust SDK
You need to make sure you are updating the RaffleDetails instance that is in the map, not a copy/clone of it.
I'm not familiar with UnorderedMap, but it seems to me the get() method returns a copy of the value that is in the map, so you are only updating the copied value. I don't know if UnorderedMap allows you to mutate a value in it directly (skimming through the docs, I don't see such a method). What you can do though is re-insert the modified RaffleDetails into the raffles map (so as to replace the old one with the modified one).
I'm talking about something like this (I haven't tested compiling it):
let o = self.raffles.get(&raffle_account_id);
if let copied_rd = Some(o) {
copied_rd.participants.insert(&env::predecessor_account_id(), &confidence);
self.raffles.insert(&raffle_account_id, &copied_rd);
}

How to implement a struct in Rust that has a list of itself as a field

I have started out learning Rust and is currently trying to write a small neural network as personal exercise. I want to define a struct for my forthcoming Layers/Clusters/Groups of nodes. My initial definition looks like this:
struct Layer {
name: String, // Human readable name
id: String, // UUID in the future
order: u8, // int for sorting
width: u8, // Number of nodes
input: [&'Self], // References to other Layers that feed input into this
}
The thing I am struggling with is the input field which should contain a list of references to other Layer-instances. I will know at compile time how many each Layer will have in the list so it wont have to me mutable. Is it possible to do this? I cant find a solution on the Google machine or in "the book".
Please advise.
Is it possible to do this? I cant find a solution on the Google machine or in "the book".
Possible yes, though I would not recommend it.
Let's start with the possible: &Self would be a "layer reference" with an unnamed lifetime, a lifetime name is for the form '<symbol>, so when you write &'Self you're specifying a reference of lifetime 'Self, but you're never specifying the type being refered to, which is why rustc complains about "expected type".
If you add a "proper" lifetime name, and parametrize the structure, it compiles fine:
struct Layer<'sublayers> {
name: String, // Human readable name
id: String, // UUID in the future
order: u8, // int for sorting
width: u8, // Number of nodes
input: [&'sublayers Self], // References to other Layers that feed input into this
}
However I would not recommend it as the last member being a slice means it's a DST which are difficult to work with at the best of time -- as the nomicon specifically notes "custom DSTs are a largely half-baked feature for now".
Since Rust doesn't yet have const generics proper you can't use an array you'd parameterize through layer either (e.g. Layer<const Size> and input: [&Self;Size], maybe one day), so you probably want something like a vector or a slice reference e.g.
struct Layer<'slice, 'sublayers: 'slice> {
name: String, // Human readable name
id: String, // UUID in the future
order: u8, // int for sorting
width: u8, // Number of nodes
input: &'slice [&'sublayers Self], // References to other Layers that feed input into this
}

What's the reason behind "structure has extra field" error

Consider this code:
var t: {a: Int} = {a:100, b:200};
It does not compile with error: { b : Int, a : Int } has extra field b
But this code compiles fine:
class Foo {
public var a: Int = 100;
public var b: Int = 200;
public function new() {}
}
...
var t: {a: Int} = new Foo();
Why is the first case forbidden?
What can go wrong if there are some extra fields? And if something can go wrong why they are allowed in second case.
This has previously been discussed in this issue, where Nicolas gives the following reasoning for the current behavior:
The idea is that constant structures are not allowed to be reduced. This allows for instance to check for the following:
function foo(o:{?x:Int,?y:Int}) {
}
var pt = { x: 0, yy : 1 }; // typo
foo(pt); // goes unnoticed
Also, it will gives error if you modify the signature of foo, for instance by removing a field.
However, the issue is still open and it looks like the behavior might be changed to allow this in the future.
I think this is answered here: https://groups.google.com/forum/#!topic/haxelang/KQO4eFUb-N0
Nicolas explained:
In your example both are considered constant values, and then an error
is printed because it has extra fields. That error was added in order
to enable code cleanup when you remove a field from a required
structure : it will tell you every place this field is still passed
(when passing a constant, which happen most of the time).
I agree the error is a bit misleading when making simple tests such as
your own, but in actual code it rarely occur.

providing structs in class diagram

I have struct chartManager which contains struct of series and struct series which contain struct of points. and they are all in Chart class.
something like this
Class Chart
{
protected:
struct points
{
int seriesPoints[10];
};
struct series
{
points seriespoints;
char seriesName[20];
};
struct pageManager
{
char chartName[20];
series totalSeries[5];
};
};
How do i show this in class diagram??
A good answer is : never go from specific language to UML :)
Nevertheless, composition/aggregation with cardinality is for me the way to go (a struct is pretty the same as a class).
I see this is a old post, but maybe I can help someone with my answer.
The best way to describe the above example is with "Nesting" connections.
Composition or Aggregation prerequisite that they are independent and not within the class itself.

Resources