Design & Implementation Overview language design Language as - - PowerPoint PPT Presentation

design implementation overview
SMART_READER_LITE
LIVE PREVIEW

Design & Implementation Overview language design Language as - - PowerPoint PPT Presentation

P rogramming L anguages Design & Im- plementation Overview COS 301 Influences on Design & Implementation Overview language design Language as VM Compilation COS 301 Interpretation Hybrid imple- mentation Fall 2017


slide-1
SLIDE 1

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Design & Implementation Overview

COS 301 Fall 2017

COS 301 Design & Implementation Overview

slide-2
SLIDE 2

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Outline

1

Influences on language design

2

Language as VM

3

Compilation

4

Interpretation

5

Hybrid implementation

6

Preprocessors

7

Programming environments

COS 301 Design & Implementation Overview

slide-3
SLIDE 3

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Influences on language design

COS 301 Design & Implementation Overview

slide-4
SLIDE 4

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Ontological commitments

Imperative languages Architecture: Memory cells variables Data movement (memory→memory, CPU→memory) assignment Sequential machine instruction execution sequential statements Conditional execution if-then-else constructs, goto Iteration via conditionals + jump loops

COS 301 Design & Implementation Overview

slide-5
SLIDE 5

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Ontological commitments

Functional languages Variables “standing for” value binding, not pointers/addresses Function application → produce new values No notion of “executing” sequential statements No statements, only functions (with values) Function composition as major characteristic Recursion as primary way of repeating function application

COS 301 Design & Implementation Overview

slide-6
SLIDE 6

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Ontological commitments

Object-oriented languages World consists of objects classes, instances, inheritance, instantiation No notion of address: variables hold value or references ∃ classes of objects inheritance, instantiation Instance variables as properties or relations to other objects Objects affordances (things they can do) methods

COS 301 Design & Implementation Overview

slide-7
SLIDE 7

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Factors affecting design: early (< mid-1960s)

Computer time extremely valuable ≫ programmers’ time languages tailored toward machine, not humans Computers relatively slow Thousands–millions of instructions/s (kIPS – MIPS) E.g.: IBM 360 mainframe, mid-60s, ~ 34 kIPS – ~ 17 MIPS extreme concern for efficiency

compilation rather than interpretation simple languages

Relatively simple applications small programs

COS 301 Design & Implementation Overview

slide-8
SLIDE 8

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Factors affecting design: late 60s–mid-70s

Cheaper processors cost of programmer time ≫ computer time Demand for capable/sophisticated software applications More programming time Larger programs harder to design, debug, maintain Result: Focus on

Human-friendly languages Languages supporting design, debugging, maintenance

Structured programming:

Top-down design Stepwise refinement More sophisticated control structures

Prominence of ALGOL-like languages (PL/I, C, Pascal, etc.)

COS 301 Design & Implementation Overview

slide-9
SLIDE 9

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Factors affecting design: more recently

Data abstraction (Modula-2, Ada, etc.) Object-orientation Revived early work on CLU, Smalltalk, etc. C++, Objective-C, Java. . . More powerful computers More sophisticated compilers possible more sophisticated/complex languages Practical interpreters rapid prototyping/incremental (iterative) development Widespread availability of multi-core systems, clusters new languages (C*, StarLisp, Parallel Euclid,. . . )

COS 301 Design & Implementation Overview

slide-10
SLIDE 10

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Language as VM

COS 301 Design & Implementation Overview

slide-11
SLIDE 11

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Virtual machine

Programming language ⇒ virtual machine VM can be implemented as a compiler, interpreter or a hybrid

COS 301 Design & Implementation Overview

slide-12
SLIDE 12

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Virtual machine: layers

COS 301 Design & Implementation Overview

slide-13
SLIDE 13

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Compilation

COS 301 Design & Implementation Overview

slide-14
SLIDE 14

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Compilation

Compiler: program that translates HLL ⇒ object code Link editor: Gathers multiple object modules (e.g., subprograms, libraries) Patches (links) unresolved references in object modules ⇒ executable Loader: Part of OS Allocates (virtual) memory Loads (copies) executable file into (virtual) memory May treat parts of executable differently May create memory not present in executable (heap, uninitialized data)

COS 301 Design & Implementation Overview

slide-15
SLIDE 15

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Overview

Source (HLL) program → lexical analyzer ⇒ lexical units Updates symbol table Lexical units → syntax analyzer Checks syntax for errors Updates symbol table ⇒ parse tree Parse tree → intermediate code generator Semantic analyzer ⇒ intermediate code Interacts with optimizer Intermediate code → code generator ⇒ object code file Machine language program May have unresolved references

COS 301 Design & Implementation Overview

slide-16
SLIDE 16

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Process

Source Code Lexical Analyzer Syntax Analyzer Intermediate Code Generator Code Generator Optimizer Symbol Table lexical units parse tree intermediate code Object File

COS 301 Design & Implementation Overview

slide-17
SLIDE 17

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Properties

Fast execution Running at native machine speed Optimizer ⇒ often faster than hand-coded assembly Compiler has access to entire program at once Can do global optimizations Can have complex languages, easy forward references, etc. Possibly lengthy compilation time Amortized over execution times, ameliorated by faster machines But during debugging/rapid prototyping

compile–test cycle cumbersome source level debugging somewhat difficult hard to change part without recompiling whole

COS 301 Design & Implementation Overview

slide-18
SLIDE 18

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Interpretation

COS 301 Design & Implementation Overview

slide-19
SLIDE 19

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Interpretation

Interpreter: Program that reads source code and carries out actions One of the very first: Lisp No translation of HLL to machine code Supports rapid prototyping Need significant runtime environment (i.e., the interpreter) Slower execution (10–100 times as slow as executable) Historically rare for traditional HLLs (though Lisp, Scheme) Now: Python, JavaScipt, PHP ,. . .

COS 301 Design & Implementation Overview

slide-20
SLIDE 20

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Hybrid implementation

COS 301 Design & Implementation Overview

slide-21
SLIDE 21

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Hybrid implementations

Compromise between compilation and interpretation One way: HLL translated to intermediate language that is easy to interpret Faster than pure interpretation E.g., Perl, Java, Smalltalk, Microsoft Common Language Runtime Another way: Allow both compiled and interpreted code E.g., most Common Lisp systems, some of Perl

COS 301 Design & Implementation Overview

slide-22
SLIDE 22

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Just-in-Time (JIT) compilers

Compile to byte code first (e.g., Java byte code) When subprograms called, byte code compiled to machine code Machine code kept for subsequent calls JIT used for Java, .NET languages Makes Java competitive with fully-compiled languages

COS 301 Design & Implementation Overview

slide-23
SLIDE 23

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Preprocessors

COS 301 Design & Implementation Overview

slide-24
SLIDE 24

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Preprocessors

Preprocessor instructions: handled immediately prior to compilation. . . . . . or prior to loading code in interpreter Types: include other code (e.g., C’s #include) macro commands (e.g., C’s #define) templates (e.g., C++, for generic classes) more complex macros: e.g., Lisp’s defmacro

COS 301 Design & Implementation Overview

slide-25
SLIDE 25

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Programming environments

COS 301 Design & Implementation Overview

slide-26
SLIDE 26

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Programming environments

Collection of tools used for software development Compilers, editors, debuggers, profilers, linkers, etc. E.g., Unix Command line tools (e.g., make, grep, awk, sed, gcc) Editors (e.g., Emacs, vi) and IDEs

COS 301 Design & Implementation Overview

slide-27
SLIDE 27

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

IDEs

Integrated development environemnts (IDEs) Includes a compiler, linker, debugger, editor, and build automator May also include source control system, class browser,

  • bject inspector, profiler, etc.

Some support multiple languages, others single language Examples: PyCharm Eclipse, Emacs Netbeans Xcode MonoDevelop Lisp machine, modern Lisp and Scheme IDEs (e.g., Allegro, PLT Scheme/Racket)

COS 301 Design & Implementation Overview

slide-28
SLIDE 28

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

Microsoft .NET

Collection of languages, technologies, development environment Most common: C++, C#, VB. . . – dozens available Large, complex visual environment (though command line available) .NET SDK available as free download Output language: machine-independent byte code for the Common Language Runtime

COS 301 Design & Implementation Overview

slide-29
SLIDE 29

Design & Im- plementation Overview COS 301 Influences on language design Language as VM Compilation Interpretation Hybrid imple- mentation Preprocessors Programming environments

P L

rogramming anguages

NetBeans

Java answer to .NET Used for Java, but also supports C, PHP , Ruby, C++, others Written in Java Extensible via modules

COS 301 Design & Implementation Overview