DOC PREVIEW
LSU CSC 4101 - Multidimensional Arrays

This preview shows page 1 out of 4 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CSC 4101: Programming Languages 11Multidimensional Arrays as Multidimensional Arrays as ParametersParametersz In C/C++void fun (int matrix [][10]) {// ...}int main () {int mat [5][10];...fun (mat);...}2Multidimensional Arrays as Multidimensional Arrays as ParametersParametersz In Adatype MTYPE is array (INTEGER range <>INTEGER range <>)of FLOAT;MAT : MTYPE (1..100, 1..20);function FOO (M : in MTYPE)return FLOAT is...for ROW in M’range(1) loop...3Implementation of SubprogramsImplementation of Subprogramsz Activation record– local variables– parameters– return value– dynamic link– static link– return addressCSC 4101: Programming Languages 24FORTRAN Activation RecordFORTRAN Activation Recordz Allocated staticallyz Needs only– local variables– parameters– return address5Static and Dynamic LinksStatic and Dynamic Linksz Static Link– activation record of enclosing scope– needed to access non-local variablesz Dynamic Link– activation record of caller– needed to pop the activation record– needed for finding exception handler6DisplaysDisplaysz Alternative (old) implementation for accessing static informationz Instead of static linkz Maintained outside stackz Contains pointers to activation records of all active nesting levelsz Old values are spilled onto stackz No traversal of static linksCSC 4101: Programming Languages 37Implementation of Functional Implementation of Functional LanguagesLanguagesz Activation record must be on heap– if function returns a local function– if a function escapes its scopez Optimized implementations– on heap if absolutely necessary– in registers if possible– otherwise on stackz Garbage collection8Implementation on RISC Implementation on RISC ProcessorsProcessorsz Activation record in registersz On SPARC: 6 parameters in registersz On MIPS: 4 parameters in registersz If registers are exhausted, spill an old activation record onto stackz On SPARC: 8 register windows, spilling needed after 8 callsz Inefficient for recursion9Exception HandlingException Handlingz Alternative mechanism for returning from functionz In C++int main () {try { foo (42); }catch (int x) { ... }}int foo (int i) throw (int) {throw 17;}CSC 4101: Programming Languages 410Exception Handling in JavaException Handling in Javaclass Ex extends Exception { ... }void Main (String[] args) {try { foo(42); }catch (Ex e) { ... }finally { ... }}int foo (int i) throws Ex {if (somethingTerribleHappens())throw new Ex();}11Exception HandlingException Handlingz Handler searched for along call chainz Jumps out across multiple functionsz May require destructor calls in intermediate scopesz Conceptually– Return address is continuation param.– Exception is error continuation– Continuation is function to compute the rest of the


View Full Document

LSU CSC 4101 - Multidimensional Arrays

Download Multidimensional Arrays
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Multidimensional Arrays and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Multidimensional Arrays 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?