quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bullet_green_ball.gif Assignment Rules

Assignment rules define what is a legal assignment and how values are assigned to entities.

   

space.gif

There are several legal ways to assign values:

   

space.gif

  • Assignment actions
  • Return actions
  • Parameter passing
  • Variable declaration
   

space.gif

  ../images/main/bulllet_4dots_orange.gif Assignment of Numeric Types

Any numeric type (for example, uint, int, or one of their subtypes) can be assigned to any other numeric type. Untyped expressions, such as HDL objects, can also appear in assignments of numeric types.

   

space.gif

Example


  1 <'
  2 extend sys {
  3    ! x1: int;
  4   x2: uint (bits: 3);
  5    ! x3: int [10..100];
  6   run() is also { 
  7     print x1;
  8     print x2;
  9     print x3;
 10     x1 = x2; 
 11     x3 = x1;
 12     var x:
 13     int (bits: 48) = x3;
 14     print x1;
 15     print x2;
 16     print x3;
 17   };
 18 }; 
 19 
 20 '>
You could download file assign.e here
   

space.gif

  x1 = 0
  x2 = 7
  x3 = 0
  x1 = 7
  x2 = 7
  x3 = 7
   

space.gif

Automatic casting is performed when a numeric type is assigned to a different numeric type, and automatic extension or truncation is performed if the types have different bit size.

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Assignment of Boolean Types

A Boolean type can only be assigned with another Boolean type.

   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Assignment of Enumerated Types

An enumerated type can be assigned with that same type, or with its scalar subtype. (The scalar subtype differs only in range or bit size from the base type.) The example below shows: An assignment of the same type:

   

space.gif

Example


  1 <'
  2 type color :[red,blue,green,white,yellow];
  3 
  4 extend sys {
  5   local_color : color;
  6   run() is also {
  7     print local_color;
  8     local_color = red;
  9     print local_color;
 10     // Below assignment is wrong
 11     //local_color = 3;
 12   };
 13 };
 14 '>
You could download file enumerated.e here
   

space.gif

  local_color = white
  local_color = red
   

space.gif

  ../images/main/bullet_green_ball.gif Automatic Type Casting

During assignment of a type to a different but compatible type, automatic type casting is performed in the following contexts:

   

space.gif

  • Numeric expressions (unsigned and signed integers) of any size are automatically type cast upon assignment to different numeric types.
  • Untyped expressions are automatically cast on assignment.
  • Sized scalars are automatically type cast to differently sized scalars of the same type.
  • Struct subtypes are automatically type cast to their base struct type.
  • If the two types differ in bit size, then the assigned value is extended or truncated to the required bit size.
  • Casting of small negative numbers (signed integers) to unsigned integers produces large positive numbers.
  • There is no automatic casting to a reference parameter.
   

space.gif

  ../images/main/bullet_green_ball.gif Complex Type Conversions

Since e language allows us to define complex data types, it is sometimes confusing to assign one type to another type. Once such example would be assigning a field of struct, which is declared in sub-type. E language provides as_a() method to do complex type conversion.

   

space.gif

  ../images/main/bulllet_4dots_orange.gif as_a()

Returns the expression, converted into the specified type. Although Specman Elite performs some casting automatically , explicit casting is required in some cases when making assignments between different but compatible types.

   

space.gif

syntax:exp.as_a(type: type name): type

   

space.gif

Type Conversion Between Scalars and Lists of Scalars

Numeric expressions (unsigned and signed integers) of any size are automatically type cast upon assignment to different numeric types. For other scalars and lists of scalars, there are a number of ways to perform type conversion, including the as_a() method, the pack() method, the %{} bit concatenation operator and various string routines.

   

space.gif

int represents int/uint of any size, including bit, byte, and any user-created size. If a solution is specific to bit or byte, then bit or byte is explicitly stated.

   

space.gif

From

To

How to Do it

list of int

string

list_of_int.as_a(string)

list of byte

string

list_of_int.as_a(string)

string

list of int

string.as_a(list of int)

string

list of byte

string.as_a(list of byte)

string

bool

bool = string.as_a(bool) ((Only TRUE and FALSE can be converted to Boolean; all other strings return an error.)

bool

string

string = bool.as_a(string)

string

enum

enum = string.as_a(enum)

enum

string

string = enum.as_a(string)

   

space.gif

  ../images/main/bulllet_4dots_orange.gif all_values()

Returns a list that contains all the legal values of the specified scalar type. When that type is an enumerated type, the order of the items is the same as the order in which they were defined. When the type is a numeric type, the order of the items is from the smallest to the largest.

   

space.gif

Syntax : all_values(scalar-type: type name): list of scalar type

   

space.gif

Note : When the specified type has more than 1million legal values, this routine gives a compile time error to alert you to possible memory abuse.

   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright © 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com