PLC Presentation Slide - Copy

download PLC Presentation Slide - Copy

of 76

Transcript of PLC Presentation Slide - Copy

  • 8/4/2019 PLC Presentation Slide - Copy

    1/76

  • 8/4/2019 PLC Presentation Slide - Copy

    2/76

    6.1 : Introduction6.2 : Primitive Data Type

  • 8/4/2019 PLC Presentation Slide - Copy

    3/76

    Definition

    Collection of data values and a set of predefinedoperations.

    Uses of Type System of programming language Error Detection

    Program Modularization

    Documentation

  • 8/4/2019 PLC Presentation Slide - Copy

    4/76

    Descriptor

    Collection of the attributes of a variable.Static attribute, descriptor required at compile time only.

    Dynamic attribute, descriptor must be maintained duringexecution because it is used by the run-time system.

    In all case, descriptor are used for type checking and tobuild the code for the allocation and deallocationoperations.

  • 8/4/2019 PLC Presentation Slide - Copy

    5/76

    Definition

    Data type that are not defined in terms of other types.Some of primitive type are merely reflections of thehardware.

    Primitive Data type can be divided into 3 categories.

    1. Numeric Type2. Character Type

    3. Boolean Type

  • 8/4/2019 PLC Presentation Slide - Copy

    6/76

    Numeric Type play a central role among the typesupported by any language.

    Numeric Type can be classified into 4 categories.1. Integer

    2. Floating

    3. Complex

    4. Decimal

  • 8/4/2019 PLC Presentation Slide - Copy

    7/76

  • 8/4/2019 PLC Presentation Slide - Copy

    8/76

  • 8/4/2019 PLC Presentation Slide - Copy

    9/76

    Model real numbers, but the representation are onlyapproximations for many real values.

    Floating-point values are represented as fractions andexponents, a form that borrowed from scientific notation.

    Values that can be represented by floating-point isdefined in terms of precision and range.

  • 8/4/2019 PLC Presentation Slide - Copy

    10/76

    Some programming language support a complex datatype such as Fortran and Python.

    Complex values are represented as ordered pairs offloating-point values.

    Language that support complex type include operationsfor arithmetic on complex values.

  • 8/4/2019 PLC Presentation Slide - Copy

    11/76

    Decimal data type store a fixed number of decimal digits.

    Advantages: Able to precisely store decimal values,which cannot be done with floating-point.

    Disadvantages: Range of values is restricted becauseno exponents are allowed.

    Decimal type are stored very much like character strings,using binary codes decimal (BCD) for decimal digits andstored one digit / byte (4bit)

  • 8/4/2019 PLC Presentation Slide - Copy

    12/76

    Boolean are the simplest of all types. Their range ofvalues has only 2 elements (true/false)

    Introduced in ALGOL 60

    All nonzero value considered true C99 and C++ allowed numeric expression as it is

    boolean but not for Java and C#.

    Used to represent switches or flag in program.

    Could be represented by a single bit, but because asingle bit of memory cannot be accessed efficiently onmany machines, they stored in a byte.

  • 8/4/2019 PLC Presentation Slide - Copy

    13/76

    Character data are stored in computers as numericcodings.

    Most used coding was 8-bit ASCII code which usesvalues 0 to 127 to code 128 different character.

    Another coding was 8-bit ISO 8859-1character code thatallows 256 different characters.

    Because of business growing, need for computer alsoincrease. Unicode Consortium published UCS-2, a 16-bitcharacter set.

    First 128 characters of unicode are identical to those ofASCII. Java was the first widely used language to use theUnicode character set.

  • 8/4/2019 PLC Presentation Slide - Copy

    14/76

  • 8/4/2019 PLC Presentation Slide - Copy

    15/76

    Character string types is which consist of sequences of characters.

    In generally, string is array of characters of particular length that representsequences of data values.

    For example , string mystring = "This is a string";

    cout

  • 8/4/2019 PLC Presentation Slide - Copy

    16/76

    Static Length String

    The length can be static and set when string is created. Fixed length strings are automaticallyfilled with spaces to pad them to their fixed-length.

    When a fixed-length string is declared, it will be filled with Null characters until it is used.

    Limited Dynamic Length String This option is allow to declare the length string and fixed maximum set by variables definition.

    Can store any number of characters between zero and maximum and at the end will be markedas Null.

    Limited dynamic string require run-time descriptor to store both fixed max and current length

    Example :

    Class LD_String { //limited dynamic string class

    private:

    char pysical_buffer [1000];

    int logical_size_buff = 100;

    int inc_size = 100;

    int lb_index; // index logical buffer

    int str_len; // current string length

    Limited dynamicstring

    Maximum length

    Current Length

    Address

    Static String

    Length

    Address

  • 8/4/2019 PLC Presentation Slide - Copy

    17/76

    Dynamic Length Strings This option is allowed to varying length with no maximum. This option required to allocate and

    deallocate

    Dynamic length string is a complex storage which it is bound, grow and shrink dynamically.

    2 approaches to support dynamic allocation and deallocation.

    Linked-list

    when string grows, new cells can come from anywhere in the heap

    Extra storage occupied by the links in the list representation Store complete strings in adjacent storage cells

    A new area of memory is found that can store complete new string and the old part is moved to thisarea.

    Old string are deallocated.

    Example :

    #include

    cons int MSIZE = 24; // string grows in MSIZE (bytes)

  • 8/4/2019 PLC Presentation Slide - Copy

    18/76

    Enumeration are named constants that provide defining a group ofcollection.

    For example : Enum days { Mon, Tue, Wed, Thu, Fri, Sat, Sun };

    C and Pascal is the first widely language that use enumeration by set

    internal values for enumeration constant. For example, enum colors{red,blue,green,yellow,black};

    0 , 1 , 2 , 3 , 4

    Different with other, in Ada enumeration type allowed more than onedeclaration in same referencing which it call overloaded literals.

    In Java, enumeration are defined in class Enum that include datafield,constructor and methods.

    In C++, numeric values can be assigned to enumeration type. For example: enum colors { red=1, blue=100, green=1000};

  • 8/4/2019 PLC Presentation Slide - Copy

    19/76

    Subrange type is contiguous subsequence of type.

    In subrange there are no design issues that apecific to subrange types.

    In Ada, subranges are included in the category of types called subtypes. Forexample: Type days is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);

    subtype Weekdays is days range Mon.Fri;

    subtype Index is Integer range 1.100;

    Subrange can increase readability by making clear to readers that variable

    of subtypes can store in certain range of values.

    Assigning values outsides of range can be detect as error.

  • 8/4/2019 PLC Presentation Slide - Copy

    20/76

  • 8/4/2019 PLC Presentation Slide - Copy

    21/76

    6.5 Array TypeArray

    same group of data elements

    individual element is identified by its position in the group (sametype)

    subscript expression are used to make references to each element C, C++, Java, Ada, C#

    o element must be a same typeo pointers are restricted to point a single type

    JavaScript, Python, Rubyo typeless references to object or data value

    Array and Indices Syntactic mechanism

    o Aggregate nameo Dynamic selector

    consists one or more subscripts or indices vice versa to static selector Static selector => all subscript are constants Selection

    finite mapping

  • 8/4/2019 PLC Presentation Slide - Copy

    22/76

    Problem with using parentheses to enclose subscript expressiono often used to enclose parameters in subprogram calls

    o reduced readability In Ada

    o parentheses is used to enclose subscripts Fortran and Ada

    o use brackets to delimit array indices

  • 8/4/2019 PLC Presentation Slide - Copy

    23/76

    Two distinct types in an array typeo Element typeo Type of Subscripts

    subrange of integers

    Ada -> allows Boolean, character and enumeration Subscripts range error are common -> need range checking ->

    reliability Perl subscripting

    @ - for beginning of arrays name $ - for beginning of scalars name and reference to array

    element arrays @subjects, $list[1] can have reference in negative subscript 0..4, $list[-2]

    Subscript Bindings and Array Categories Binding of the subscript type to an array variable is usually static Subscript ranges sometimes dynamically bound Lower bound of subscript range is implicit

    o C-based language is fixed at 0o Fortran 95 is default by 1 but can be set to any integer literal

    o Other Languages are specified by programmer

  • 8/4/2019 PLC Presentation Slide - Copy

    24/76

    Five categories of arrays :o Static Array

    subscript ranges are statically bound storage allocation is static

    Advantage : no dynamic allocation or deallocation is required(efficiency)

    Disadvantage : storage for the array is bound for the entire execution time

    o Fixed stack-dynamic array subscript ranges are statically bound

    allocation is done at declaration elaboration time during execution Advantage : spam efficiency (compare with static array) flexibility Disadvantage : required allocation and deallocation time

  • 8/4/2019 PLC Presentation Slide - Copy

    25/76

    Stack-Dynamic Arrayo both subscript ranges and storage allocation are dynamically bound at

    elaboration time.o Advantage :

    flexibility

    Fixed Heap-Dynamic Arrayo similar to fixed stack-dynamic array but both subscript ranges and

    storage binding are done when the user program requests them duringexecution and the storage is allocated from the heap

    o Advantage : array's size fits the problem(flexibility)

    o Disadvantage : allocation time from the heap is longer than in stack

  • 8/4/2019 PLC Presentation Slide - Copy

    26/76

    Heap-Dynamic Arrayo binding of the subscript ranges and storage allocation is dynamic and can

    be change any number of times during the array's lifetime

    o Advantage : Array can grow and shrink during execution

    o Disadvantage : allocation and deallocation take longer and may happen many times

    o in C#

    o in Java - similar to C # ArrayList but subscripting is not supported

  • 8/4/2019 PLC Presentation Slide - Copy

    27/76

    in Perlo push and unshifto (), empty list -> no elemento length of array = largest subscript + 1

    in Javascripto same like Perlo negative subscript is not supportedo subscript value need not be contiguous

  • 8/4/2019 PLC Presentation Slide - Copy

    28/76

    Array initialization Fortran 95o assigning it an array aggregate in its declaration

    o single dimensional array -> list of literals delimited by parentheses andslashes.

    o example : Integer, Dimension (2) it List = (/1, 2/) C declaration :

    o int arrayList = {1,3,7,9,5,6};o compiler sets the length of the array

    C and C++o initialized character string with arrays of char

    char subject [] = "Programming"; array subject -> 12 elements

    o initialized with a string literal char *subjects [] = ["Formal Method", "Data Structure"]; array of pointers to characters

  • 8/4/2019 PLC Presentation Slide - Copy

    29/76

    In Javao similar syntax is used

    o to define and initialized an array of reference to string objectso Eg:

    String[] subjects = ("Formal Method", "Data Structure"); In Ada

    o listing in the order it is to be stored List : array (1..5) of Integer : = (1, 2, 3, 4, 5)?

    o directly assigning to an index position operator(=>) arrow Bunch : array (1..5) of Integer := (1 => 23, 4 => 20, others => 0);

    In Pythono Example:

    [x * x for x in range(12) if x % 3 == 0]

  • 8/4/2019 PLC Presentation Slide - Copy

    30/76

    Array Operations operates on an array as a unit

    Most common :o Assignment catenationo comparison for equality and inequalityo slices

    In Ada :o allows array assignment and catenation by ampersand (&)

    In Pythono arrays are called listso provide array assignment(reference change)o has operations for array catenation (+) and element membership (in)o includes tuples

    use parentheses to enclose their literals

    immutable

  • 8/4/2019 PLC Presentation Slide - Copy

    31/76

    In Rubyo array are references to objectso '==' is used between to arrays

    true only if 2 arrays have the same length and correspondingelements are equal

    o can be catenated with an Array method Fortran 95

    o includes elementalo include intrinsic, library, functions for matrix multiplications, matrix

    transpose and vector dot product APL

    o the 4 basic operations are defined for vectors and matrices A + B

    o special operators that take other operands as operands A+.xB

  • 8/4/2019 PLC Presentation Slide - Copy

    32/76

    Rectangular and Jagged Arrays Rectangular Array

    o multidimensional arrays

    o all rows have the same number of element, all columns have the samenumber of element

    o model rectangular tableo not supported in C, C++ or Javao supported in Fortran, Ada and C#o subscript expressions in references to elements are placed in a single

    pair of brackets.o ArrayList[2,4]

    Jagged Arrayo the lengths of the rows need not be the sameo supported in C, C++ and Javao use separate brackets for each dimensiono ArrayList[2][4]

  • 8/4/2019 PLC Presentation Slide - Copy

    33/76

    Slices substructure of array mechanism for referencing part of an array as a unit Example :

    o Python declaration

  • 8/4/2019 PLC Presentation Slide - Copy

    34/76

    in Fortran 95o if matis a matrix,specific columns can be specifiedo Example:

    mat[; , 2]

    in Perlo slices in two forms

    list of specific subscripts range of subscript Example :

    @list[1..5] = @list2[1,2,3,4,5]

    in Rubyo supports slices with the slice method of its Array objecto 3 forms of parameter

    single integer expression parameter two integer expression parameter range parameter

    in Adao highly restricted slices are allowedo Example :

    List have index range of List(1..100) List(2..4)is a slice of List consist 3 elements indexed from 2 to 4

  • 8/4/2019 PLC Presentation Slide - Copy

    35/76

    Implementation of Array Types require more compile time

    generalization of this access function for an arbitrary lower boundo

    Compile-time Descriptoro Descriptor

    includes information to constructaccess function

    no descriptor needed run-time checking of index

    ranges is NOT done attributes are all STATIC

  • 8/4/2019 PLC Presentation Slide - Copy

    36/76

    True multidimensional arrayo complex to implemento 2 common ways of mapping multidimensional array

    row major order

    column major order

    o access function base address mapping a set of index values to the address in memory of the element

    specified by the index values

    location(a[i,j] = address of a[1,1]+((((num of rows above the ith row)*(size of row))+(num of element leftof thejth column))*element_size)

  • 8/4/2019 PLC Presentation Slide - Copy

    37/76

    6.6 Associative Array Associative array

    o unordered collection of data elementso indexed by an equal number of values (keys)o user defined keys must be stored in the structureo use of Perl's designo supported by Python, Ruby, Lua, Java, C++, C#

    Non-associative arrayo indices not need to be stored

    Structure and Operations in Perl

    o called hasheso namespace for hashes is distinct

    begin with '%'o hash elements

    key(string type) value(scalar type)

    o hashesin literal value %marks = ("abby" => 78, "bob => 80, "raymond" => 50, "haratio" =>

    100);

  • 8/4/2019 PLC Presentation Slide - Copy

    38/76

    o individual element values are referenced using notation key value - in braces hash name - replaced by a scalar variable name

    o hashesare not scalar but value part of element is scalar Example : note - scalar starts with $ sign

    $marks {"haratio") = 99;o new element is added using the same assignment statement formo remove element

    delete operator delete $marks("abby");

    o empty hash @marks = ();

    o size of Perl dynamic

    exists operator returns true or false if(exists ?marks("robert"))... in Python

    o called dictionarieso values are all referenced to objects

  • 8/4/2019 PLC Presentation Slide - Copy

    39/76

    in Rubyo similar to Pythono keys can be any objects rather than strings

    PHP Arrayso normal arrays and associative arrayo allows indexed and hashes access to elemento element of array

    created with simple numeric indices with string hash keys

    In Luao Lua's table is an associative arrayo keys and values can be any typeo table can use :

    traditional array or associative array brackets are used around the keys

    record keys are field name dot(.) notation for references to field

  • 8/4/2019 PLC Presentation Slide - Copy

    40/76

    Implementing Associative Array Perl's associative array

    o for fast lookupso relatively fast reorganization when array growth requires it

    PHP's arrayo placed in memory through hash functiono all elements are linked togethero support iterative access to elements through the current and next function

  • 8/4/2019 PLC Presentation Slide - Copy

    41/76

  • 8/4/2019 PLC Presentation Slide - Copy

    42/76

    College Student

    Name(string)

    Studentnum. (integer)

    Grade pointaverage

    (float)

    Characteristic of Record :-Different sizeAdjacent memory locationIdentifier

    In C, C#, C++Struct data type

    In Python, RubyHashes

    6.7

    Record

  • 8/4/2019 PLC Presentation Slide - Copy

    43/76

    What is the syntactic form of reference to fields?

    Are elliptical reference allowed?

  • 8/4/2019 PLC Presentation Slide - Copy

    44/76

    COBOL

    01 EMPLOYEE-RECORD.

    02 EMPLOYEE-NAME.

    05 FIRST PICTURE IS X(20) .

    05 MIDDLE PICTURE IS X(10) .05 LAST PICTURE IS X(20) .

    02 HOURLY-RATE PICTURE IS 99V99 .

    Field

    Level numbers

    Format of fieldstorage location

    20Alphanumeri

    c number

    4 Decimal digit withdecimal point in the middle

  • 8/4/2019 PLC Presentation Slide - Copy

    45/76

    ADA

    type Employee_Name_Type isrecordFirst : String (1..20);

    Middle : String (1..10);

    Last : String (1..20);

    end record;

    type Employee_Record_Type is record

    Employee_Name : Employee_Name_Type;

    Hourly_Rate : Float;end record;

    Employee_Record : Employee_Record_Type;

  • 8/4/2019 PLC Presentation Slide - Copy

    46/76

    COBOL field reference

    MIDDLE OF EMPLOYEE-NAME OF EMPLOYEE-RECORD

    ADA field reference (C, C++)

    Employee_Record.Employee_Name.MiddleDOT notation

    Fully QualifiedReference

    COBOL allows Elliptical Reference

    MIDDLEMIDDLE OF EMPLOYEE-NAMEMIDDLE OF EMPLOYEE-RECORD

  • 8/4/2019 PLC Presentation Slide - Copy

    47/76

    Assignment (common)

    -Both side must identical

    Comparison (ADA)

    -Equality and inequality

    Move(COBOL)

    -MOVE CORRESPONDING statementMOVE CORRESPONDING INPUT RECORD TO OUTPUT

    RECORD

    01 INPUT-RECORD.02 NAME.

    05 LAST PICTURE ISX(20).

    05 MIDDLE PICTURE ISX(15).

    05 FIRSTPICTURE IS X(20).

    02 EMPLOYEE-NUMBER PICTURE IS

    9(10).02 HOURS-WORKED PICTURE IS

    01 OUTPUT-RECORD.02 NAME.

    05 FIRST PICTURE ISX(20).

    05 MIDDLE PICTURE ISX(15).

    05 LAST PICTURE ISX(20).

    02 EMPLOYEE-NUMBER PICTURE IS

    9(10).02 GROSS-PAY PICTURE IS

  • 8/4/2019 PLC Presentation Slide - Copy

    48/76

    Array

    Same type & same processed way

    Indices

    Record Heterogeneous & different processed way

    Field Name address

  • 8/4/2019 PLC Presentation Slide - Copy

    49/76

    6.8 Union- Same variable different type value ,different time

    -Safe(ADA)

    -Unsafe (Fortran, C, C++)

    -Not supported (Java, C#)

    Design issues Should type checking be required? Note that any such

    type checking must be dynamic.

    Should unions be embedded in records?

  • 8/4/2019 PLC Presentation Slide - Copy

    50/76

    Discriminated Union (ADA)

    tag / discriminant (type indicator)

    Free Union (Fortran, C, C++)

    complete freedom in type checking

  • 8/4/2019 PLC Presentation Slide - Copy

    51/76

    Constraint variant variable-named constant

    -can be changed(assigning the entire record)

    -disallow inconsistent records

  • 8/4/2019 PLC Presentation Slide - Copy

    52/76

    type Shape is (Circle, Triangle, Rectangle);type Colors is (Red, Green, Blue);

    type Figure (Form : Shape) isrecordFilled : Boolean;Color : Colors;case Form is

    when Circle =>

    Diameter : Float;when Triangle =>Left_Side : Integer;Right_Side : Integer;Angle : Float;

    when Rectangle =>Side_1 : Integer;Side_2 : Integer;

    end case;end record;

  • 8/4/2019 PLC Presentation Slide - Copy

    53/76

    Figure variable declaration.

    Figure_1 : Figure; (unconstrained variant record)

    Figure_2 : Figure(Form => Triangle);

    Figure_1 :=(Filled => True,

    Color => Blue,Form => Rectangle,

    Side_1 => 12,

    Side_2 => 3);

    Figure_2 is constrain to be a triangle and cannot bechanged to another variant.

  • 8/4/2019 PLC Presentation Slide - Copy

    54/76

    Same address for every possible variant Sufficient storage for largest variant is allocated

    Tag of the discriminated union is stored with the variant inrecordlike structure

    Complete description of each variant must be stored(compile time)

  • 8/4/2019 PLC Presentation Slide - Copy

    55/76

    Discriminatedunion

    BOOLEAN

    Offset

    Address

    Count

    Integer

    Sum

    Float

    True

    False

    Tag

    CaseTable

    Name

    Type

    Name

    Type

    ADA exampletypeNode (Tag : Boolean) is

    record

    caseTagiswhenTrue => Count : Integer;whenFalse => Sum : Float;endcase;

  • 8/4/2019 PLC Presentation Slide - Copy

    56/76

  • 8/4/2019 PLC Presentation Slide - Copy

    57/76

    6.9 Pointer and Reference

    Type A Pointer type variable has a range of values thatconsist of memory address and a special, nil. Provide the power of indirect addressing.

    Provide a method to manage dynamic memory.

    A pointer can used to access a location in the areawhere storage is dynamically created(called aheap).

  • 8/4/2019 PLC Presentation Slide - Copy

    58/76

    What are the scope of and lifetime of a pointer variable?

    What is the lifetime of a heap-dynamic variable?

    Are pointers restricted as to the type of value to whichthey can point?

    Are pointers used for dynamic storage management,

    indirect addressing, or both? Should the language support pointer types, referencetypes, or both?

  • 8/4/2019 PLC Presentation Slide - Copy

    59/76

    Two fundamental operations: assignment anddereferencing

    Assignment is used to set a pointer variablesvalue to some useful address

    Dereferencing yields the value stored at thelocation represented by the pointers value

    Dereferencing can be explicit or implicit

    C++ uses an explicit operation via *j = *ptr

    sets j to the value located at ptr

  • 8/4/2019 PLC Presentation Slide - Copy

    60/76

    The assignment operation j = *ptr

    7080

    206

    j

    ptr

    An anonymousdynamic variable

  • 8/4/2019 PLC Presentation Slide - Copy

    61/76

    Dangling pointers (dangerous) A pointer points to a heap-dynamic variable that has been

    deallocated

    Lost heap-dynamic variable An allocated heap-dynamic variable that is no longer accessible

    to the user program (often called garbage) Pointer p1 is set to point to a newly created heap-dynamic

    variable

    Pointer p1 is later set to point to another newly created heap-

    dynamic variable

    The process of losing heap-dynamic variables is called memoryleakage

  • 8/4/2019 PLC Presentation Slide - Copy

    62/76

    Some dangling pointers are disallowed because dynamicobjects can be automatically deallocated at the end ofpointer's type scope

    The lost heap-dynamic variable problem is not eliminated

    by Ada (possible with UNCHECKED_DEALLOCATION)

  • 8/4/2019 PLC Presentation Slide - Copy

    63/76

    Extremely flexible but must be used with care

    Pointers can point at any variable regardless of when orwhere it was allocated

    Used for dynamic storage management and addressing

    Pointer arithmetic is possible

    Explicit dereferencing and address-of operators

    Domain type need not be fixed (void *)

    void * can point to any type and can be typechecked (cannot be de-referenced)

  • 8/4/2019 PLC Presentation Slide - Copy

    64/76

    float stuff[100];

    float *p;

    p = stuff;

    *(p+5) is equivalent tostuff[5] and p[5]*(p+i) is equivalent tostuff[i] and p[i]

  • 8/4/2019 PLC Presentation Slide - Copy

    65/76

    C++ includes a special kind of pointer type called areference typethat is used primarily for formalparameters Advantages of both pass-by-reference and pass-by-value

    Java extends C++s reference variables and allows themto replace pointers entirely References are references to objects, rather than being addresses

    C# includes both the references of Java and the pointersof C++

  • 8/4/2019 PLC Presentation Slide - Copy

    66/76

    Dangling pointers and dangling objects are problems asis heap management

    Pointers are like goto's--they widen the range of cells

    that can be accessed by a variable

    Pointers or references are necessary for dynamic datastructures--so we can't design a language without them

  • 8/4/2019 PLC Presentation Slide - Copy

    67/76

    Large computers use single values Intel microprocessors use segment and offset

  • 8/4/2019 PLC Presentation Slide - Copy

    68/76

    Tombstone: extra heap cell that is a pointer to the heap-dynamic variable The actual pointer variable points only at tombstones

    When heap-dynamic variable de-allocated, tombstone remainsbut set to nil

    Costly in time and space

    .Locks-and-keys: Pointer values are represented as (key,address) pairs Heap-dynamic variables are represented as variable plus cell for

    integer lock value

    When heap-dynamic variable allocated, lock value is created andplaced in lock cell and key cell of pointer

  • 8/4/2019 PLC Presentation Slide - Copy

    69/76

    A very complex run-time process

    Single-size cells vs. variable-size cells

    Two approaches to reclaim garbage Reference counters (eager approach): reclamation is gradual

    Mark-sweep (lazy approach): reclamation occurs when the list ofvariable space becomes empty

  • 8/4/2019 PLC Presentation Slide - Copy

    70/76

    Reference counters: maintain a counter in every cell thatstore the number of pointers currently pointing at the cell Disadvantages: space required, execution time required,

    complications for cells connected circularly

    Advantage: it is intrinsically incremental, so significant delays in

    the application execution are avoided

  • 8/4/2019 PLC Presentation Slide - Copy

    71/76

    The run-time system allocates storage cells asrequested and disconnects pointers from cells asnecessary; mark-sweep then begins Every heap cell has an extra bit used by collection algorithm

    All cells initially set to garbage

    All pointers traced into heap, and reachable cells marked asnot garbage

    All garbage cells returned to list of available cells

    Disadvantages: in its original form, it was done too

    infrequently. When done, it caused significant delays inapplication execution. Contemporary mark-sweep algorithmsavoid this by doing it more oftencalled incremental mark-sweep

  • 8/4/2019 PLC Presentation Slide - Copy

    72/76

    1

    2

    3

    45

    6

    7

    8

    9

    10

    11 12

    xxx

    xx

    x

    x

    xx

    x

    x

    Dashed lines Show the order of node_marking

  • 8/4/2019 PLC Presentation Slide - Copy

    73/76

    Generalize the concept of operands and operators to includesubprograms and assignments

    Type checkingis the activity of ensuring that the operands of anoperator are of compatible types

    A compatible typeis one that is either legal for the operator, or isallowed under language rules to be implicitly converted, by compiler-generated code, to a legal type

    This automatic conversion is called a coercion.

    A type erroris the application of an operator to an operand of aninappropriate type

  • 8/4/2019 PLC Presentation Slide - Copy

    74/76

    If all type bindings are static, nearly all type checking canbe static

    If type bindings are dynamic, type checking must bedynamic

    A programming language is strongly typedif type errorsare always detected

    Advantage of strong typing: allows the detection of themisuses of variables that result in type errors

  • 8/4/2019 PLC Presentation Slide - Copy

    75/76

  • 8/4/2019 PLC Presentation Slide - Copy

    76/76