Language Systems Chapter FourModern Programming Languages 1.

Slides:



Advertisements
Similar presentations
Chapt.2 Machine Architecture Impact of languages –Support – faster, more secure Primitive Operations –e.g. nested subroutine calls »Subroutines implemented.
Advertisements

Agenda Definitions Evolution of Programming Languages and Personal Computers The C Language.
compilers and interpreters
The Assembly Language Level
SYSTEM PROGRAMMING & SYSTEM ADMINISTRATION
Chapter FourModern Programming Languages1 Language Systems.
1 Starting a Program The 4 stages that take a C++ program (or any high-level programming language) and execute it in internal memory are: Compiler - C++
Systems Software.
Language Systems Chapter FourModern Programming Languages, 2nd ed.1.
CSCE 145: Algorithmic Design I Chapter 1 Intro to Computers and Java Muhammad Nazmus Sakib.
Lab Information Security Using Java (Review) Lab#0 Omaima Al-Matrafi.
Lab#1 (14/3/1431h) Introduction To java programming cs425
Software Language Levels Machine Language (Binary) Assembly Language –Assembler converts Assembly into machine High Level Languages (C, Perl, Shell)
1 Lecture 1  Getting ready to program  Hardware Model  Software Model  Programming Languages  The C Language  Software Engineering  Programming.
Computers: Tools for an Information Age
JVM-1 Introduction to Java Virtual Machine. JVM-2 Outline Java Language, Java Virtual Machine and Java Platform Organization of Java Virtual Machine Garbage.
Programming Languages Structure
Chapter 2: Impact of Machine Architectures What is the Relationship Between Programs, Programming Languages, and Computers.
1 Programming Languages Translation  Lecture Objectives:  Be able to list and explain five features of the Java programming language.  Be able to explain.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 1, Lab.
Chapter 10 Application Development. Chapter Goals Describe the application development process and the role of methodologies, models and tools Compare.
COP4020 Programming Languages
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
JAVA v.s. C++ Programming Language Comparison By LI LU SAMMY CHU By LI LU SAMMY CHU.
Introduction to High-Level Language Programming
P51UST: Unix and Software Tools Unix and Software Tools (P51UST) Compilers, Interpreters and Debuggers Ruibin Bai (Room AB326) Division of Computer Science.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Programming Languages and Paradigms Object-Oriented Programming.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
UNIVERSITI TENAGA NASIONAL “Generates Professionals” CHAPTER 4 : Part 2 INTRODUCTION TO SOFTWARE DEVELOPMENT: PROGRAMMING & LANGUAGES.
 Java Programming Environment  Creating Simple Java Application  Lexical Issues  Java Class Library.
Java Introduction Lecture 1. Java Powerful, object-oriented language Free SDK and many resources at
Lecture 10 : Introduction to Java Virtual Machine
1 Comp 104: Operating Systems Concepts Java Development and Run-Time Store Organisation.
CST320 - Lec 11 Why study compilers? n n Ties lots of things you know together: –Theory (finite automata, grammars) –Data structures –Modularization –Utilization.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
1 ENERGY 211 / CME 211 Lecture 26 November 19, 2008.
Lecture 8 February 29, Topics Questions about Exercise 4, due Thursday? Object Based Programming (Chapter 8) –Basic Principles –Methods –Fields.
1.  10% Assignments/ class participation  10% Pop Quizzes  05% Attendance  25% Mid Term  50% Final Term 2.
6/3/2016IT 3271 WhatHow A system (environment) for programmers to develops their programs in a certain programming language on a certain machine Chapter.
Module 4 Part 2 Introduction To Software Development : Programming & Languages Introduction To Software Development : Programming & Languages.
LANGUAGE SYSTEMS Chapter Four Modern Programming Languages 1.
1. 2 Preface In the time since the 1986 edition of this book, the world of compiler design has changed significantly 3.
Chapter 1 Introduction. Chapter 1 -- Introduction2  Def: Compiler --  a program that translates a program written in a language like Pascal, C, PL/I,
1 The Evolution of Major Programming Languages Different Languages Characteristics.
Introduction to OOP CPS235: Introduction.
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
ITP 109 Week 2 Trina Gregory Introduction to Java.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Hello world !!! ASCII representation of hello.c.
OCR A Level F453: The function and purpose of translators Translators a. describe the need for, and use of, translators to convert source code.
Programming 2 Intro to Java Machine code Assembly languages Fortran Basic Pascal Scheme CC++ Java LISP Smalltalk Smalltalk-80.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)
Chapter Goals Describe the application development process and the role of methodologies, models, and tools Compare and contrast programming language generations.
Chapter 10 Application Development
Lecture 3 Translation.
Applications Active Web Documents Active Web Documents.
Visit for more Learning Resources
14 Compilers, Interpreters and Debuggers
Programming languages
CSCI-235 Micro-Computer Applications
Compiler Construction (CS-636)
Java programming lecture one
Accomplishing Executables
CMP 131 Introduction to Computer Programming
Presentation transcript:

Language Systems Chapter FourModern Programming Languages 1

Outline The classical sequence of program construction Variations on the classical sequence Binding times Runtime support Chapter FourModern Programming Languages 2

Creating The programmer uses an editor to create a text file containing the program A high-level language: machine independent This C-like example program calls fred 100 times, passing each i from 1 to 100: Chapter FourModern Programming Languages 3 int i; void main() { for (i=1; i<=100; i++) fred(i); }

Compiling Compiler translates to assembly language ◦ Machine-specific This is the first step in going from source code to an executable… Chapter FourModern Programming Languages 4

Chapter FourModern Programming Languages 5 int i; void main() { for (i=1; i<=100; i++) fred(i); } i: data word 0 main: move 1 to i t1: compare i with 100 jump to t2 if greater push i call fred add 1 to i go to t1 t2: return compiler

Assembling Assembly language is not directly executable ◦ Still text format, readable by (nerdy) people ◦ Still has names, not memory addresses Assembler converts each assembly-language instruction into the machine’s binary format: its machine language ◦ Resulting object file not readable by people This step is not visible in modern compilers ◦ And may even be skipped Chapter FourModern Programming Languages 6

Chapter FourModern Programming Languages 7 i: data word 0 main: move 1 to i t1: compare i with 100 jump to t2 if greater push i call fred add 1 to i go to t1 t2: return assembler

Linking Object file still not directly executable ◦ Still has some names Linker combines all the different parts In our example, fred was compiled separately, may even have been written in a different high-level language Result is the executable file Chapter FourModern Programming Languages 8

Chapter FourModern Programming Languages 9 linker

Loading “Executable” file still not directly executable ◦ Still has some names ◦ Mostly machine language, but not entirely Final step: when the program is run, the loader loads it into memory and replaces remaining names with fixed addresses Chapter FourModern Programming Languages 10

A Word About Memory Before loading, language system does not know where in memory the program will be placed Loader finds an address for every piece and replaces names with addresses ◦ like for static data Chapter FourModern Programming Languages 11

Chapter FourModern Programming Languages 12 loader

Running After loading, the program is entirely machine language ◦ All names have been replaced with memory addresses Processor begins executing its instructions, and the program runs Chapter FourModern Programming Languages 13

The Classical Sequence Chapter FourModern Programming Languages 14

About Optimization Code generated by a compiler is usually optimized to make it faster, smaller, or both Other optimizations may be done by the assembler, linker, and/or loader Chapter FourModern Programming Languages 15

Example Original code: Improved code, with loop invariant moved: Chapter FourModern Programming Languages 16 int i = 0; while (i < 100) { a[i++] = x*x*x; } int i = 0; int temp = x*x*x; while (i < 100) { a[i++] = temp; }

Example Loop invariant removal is handled by most compilers That is, most compilers generate the same efficient code from the previous example So it is a waste of the programmer’s time to make the transformation manually “Premature optimization is the root of all evil” ( -- Knuth) Chapter FourModern Programming Languages 17

Other Optimizations Some, like LIR, add variables Others remove variables, remove code, add code, move code around, etc. All make the connection between source code and object code more complicated A simple question, such as “What assembly language code was generated for this statement?” may have a complicated answer Very important issue with concurrency Chapter FourModern Programming Languages 18

Outline The classical sequence Variations on the classical sequence Binding times Runtime support Chapter FourModern Programming Languages 19

Variation: Hiding The Steps Many language systems make it possible to do the compile-assemble-link part with one command Example: gcc command on a Unix system: Chapter FourModern Programming Languages 20 gcc main.cgcc main.c –S as main.s –o main.o ld … Compile, then assemble, then link Compile-assemble-link

Variation: Integrated Development Environments A single interface for editing, running and debugging programs Integration can add power at every step: ◦ Editor knows language syntax ◦ System may keep a database of source code (not individual text files) and object code ◦ System may maintain versions, coordinate collaboration ◦ Rebuilding after incremental changes can be coordinated, like Unix make but language-specific ◦ Debuggers can benefit Chapter FourModern Programming Languages 21

Variation: Interpreters To interpret a program is to carry out the steps it specifies, without first translating into a lower- level language Interpreters are usually much slower ◦ Compiling takes more time up front, but program runs at hardware speed ◦ Interpreting starts right away, but each step must be processed in software Sounds like a simple distinction… Chapter FourModern Programming Languages 22

Virtual Machines A language system can produce code in a machine language for which there is no hardware: an intermediate code Virtual machine must be simulated in software – interpreted, in fact Language system may do the whole classical sequence, but then interpret the resulting intermediate-code program Why? Chapter FourModern Programming Languages 23

Why Virtual Machines Cross-platform execution ◦ Virtual machine can be implemented in software on many different platforms Heightened security ◦ Your program is never directly in charge  The interpreter is ◦ Interpreter can intervene if the program tries to do something it shouldn’t Chapter FourModern Programming Languages 24

The Java Virtual Machine Java languages systems usually compile to code for a virtual machine: the JVM JVM language is called bytecode Bytecode interpreter is part of almost every Web browser When you browse a page that contains a Java applet, the browser runs the applet by interpreting its bytecode Chapter FourModern Programming Languages 25

Intermediate Language Spectrum Pure interpreter (Old BASIC) ◦ Intermediate language = high-level language Tokenizing interpreter (Python) ◦ Intermediate language = token stream Intermediate-code compiler (Java, C#) ◦ Intermediate language = virtual machine language Native-code compiler (C++, D) ◦ “Intermediate language” = physical machine language Chapter FourModern Programming Languages 26

Delayed Linking Delay linking step Code for library functions is not included in the executable file of the calling program Chapter FourModern Programming Languages 27

Delayed Linking: Windows Libraries of functions for delayed linking are stored in.dll files: dynamic-link library Many language systems share this format Two flavors ◦ Load-time dynamic linking  Loader finds.dll files (which may already be in memory) and links the program to functions it needs, just before running ◦ Run-time dynamic linking  Running program makes explicit system calls to find.dll files and load specific functions UNIX Systems behave similarly (.so) Chapter FourModern Programming Languages 28

Delayed Linking: Java JVM automatically loads and links classes when a program uses them Class loader does a lot of work: ◦ May load across Internet ◦ Thoroughly checks loaded code to make sure it complies with JVM requirements Chapter FourModern Programming Languages 29

Delayed Linking Advantages Multiple programs can share a copy of library functions: only one copy on disk Library functions can be updated independently of programs: all programs use repaired library code next time they run Can avoid loading code that is never used Chapter FourModern Programming Languages 30

Dynamic Compilation Some compiling takes place after the program starts running Many variations: ◦ Compile each function only when called ◦ Start by interpreting, compile only those pieces that are called frequently ◦ Compile roughly at first (for instance, to intermediate code); spend more time on frequently executed pieces (for instance, compile to native code and optimize) Just-in-time (JIT) compilation Chapter FourModern Programming Languages 31

Outline The classical sequence Variations on the classical sequence Binding times Runtime support Chapter FourModern Programming Languages 32

Binding Binding means associating two things—especially, associating some property with an identifier from the program In our example program below: ◦ What set of values is associated with int ? ◦ What is the type of fred ? ◦ What is the address of the object code for main ? ◦ What is the value of i ? Chapter FourModern Programming Languages 33 int i; int main() { for (i=1; i<=100; i++) fred(i); }

Binding Times Different bindings take place at different times There is a standard way of describing binding times with reference to the classical sequence: ◦ Language definition time (standard spec.) ◦ Language implementation time ◦ Compile time ◦ Link time ◦ Load time ◦ Runtime Chapter FourModern Programming Languages 34

Language Definition Time Some properties are bound when the language is defined: ◦ Meanings of keywords: void, for, etc. Chapter FourModern Programming Languages 35 int i; int main() { for (i=1; i<=100; i++) fred(i); }

Language Implementation Time Some properties are bound when the language system is written: ◦ range of values of type int in C (but in Java, these are part of the language definition) ◦ implementation limitations: max identifier length, max number of array dimensions, etc Chapter FourModern Programming Languages 36 int i; int main() { for (i=1; i<=100; i++) fred(i); }

Compile Time Some properties are bound when the program is compiled or prepared for interpretation: ◦ Types of variables, in languages like C and ML that use static typing ◦ Declaration that goes with a given use of a variable, in languages that use static scoping (most languages) Chapter FourModern Programming Languages 37 int i; void main() { for (i=1; i<=100; i++) fred(i); }

Link Time Some properties are bound when separately- compiled program parts are combined into one executable file by the linker: ◦ Object code for external functions Chapter FourModern Programming Languages 38 int i; void main() { for (i=1; i<=100; i++) fred(i); }

Load Time Some properties are bound when the program is loaded into the computer’s memory, but before it runs: ◦ Memory locations for code for functions, static variables ◦ Static => “determined before run time” Chapter FourModern Programming Languages 39 int i; void main() { for (i=1; i<=100; i++) fred(i); }

Run Time Some properties are bound only when the code in question is executed: ◦ Values of variables ◦ Types of variables, in languages like Lisp and Python that use dynamic typing Also called late or dynamic binding (everything before run time is early or static) Chapter FourModern Programming Languages 40

Late Binding, Early Binding The most important question about a binding time: late or early? ◦ Late: generally, this is more flexible at runtime (as with types, dynamic loading, etc.) ◦ Early: generally, this is faster and more secure at runtime (less to do, less that can go wrong) You can tell a lot about a language by looking at the binding times Chapter FourModern Programming Languages 41

Outline The classical sequence Variations on the classical sequence Binding times Runtime support Chapter FourModern Programming Languages 42

Runtime Support Additional code the linker includes even if the program does not refer to it explicitly ◦ Startup processing: initializing the machine state ◦ Exception handling: reacting to exceptions ◦ Memory management: allocating memory, reusing it when the program is finished with it ◦ Operating system interface: communicating between running program and operating system for I/O, etc. An important hidden player in language systems Chapter FourModern Programming Languages 43

Conclusion Language systems implement languages Today: a quick introduction More implementation issues later, especially: ◦ Chapter 12: memory locations for variables ◦ Chapter 14: memory management ◦ Chapter 18: parameters ◦ Chapter 21: cost models Chapter FourModern Programming Languages 44