C++ Template Meta Programming

Total Page:16

File Type:pdf, Size:1020Kb

C++ Template Meta Programming C++ Template Meta Programming Introduction C++ Template Meta Programming Template Metaprogram- ming A Bad Francesco Nidito Example A Good Example Conclusions Programmazione Avanzata AA 2005/06 Outline C++ Template Meta Programming 1 Introduction Introduction 2 Template Metaprogramming Template Metaprogram- ming 3 A Bad Example A Bad Example A Good 4 A Good Example Example Conclusions 5 Conclusions Reference: K. Czarnecki, U. W. Eisenecker, “Generative Programming: Methods, Tools, and Applications”, Chapter 10 What Is Template Metaprogramming? C++ Template Meta Programming Introduction Template At this moment is quite difficult to give a definition. First Metaprogram- ming define two terms: A Bad Template Example Metaprogramming A Good Example Conclusions What Are Templates? C++ Template Meta Programming Templates are a C++ technique to create Generic Code Introduction Template Some templates are in C++ Standard and can be found in Metaprogram- STL ming A Bad The first version of STL architecture was made by Example A Good Alexander Stepanov Example Some examples of templates in STL are: std::vector, Conclusions std::map and std::list C++ Templates Example: Very Simple Array C++ Template Meta template <typename T, unsigned int L> Programming class VerySimpleArray{ T a[L]; Introduction public: Template Metaprogram- VerySimpleArray(){ ming for(int i=0; i < L; ++i) a[i] = T(); A Bad } Example A Good T& Get(unsigned int i){return a[i];} Example void Set(unsigned int i, T& v){a[i] = v;} Conclusions }; VerySimpleArray<float, 42> vsa; vsa.Set(3, 6.0); C++ Templates Example: Template specialization C++ Template template<typename _Tp, typename _Alloc=allocator<_Tp> > Meta class vector : protected _Vector_base<_Tp, _Alloc> Programming { __glibcpp_class_requires(_Tp, _SGIAssignableConcept) Introduction Template Metaprogram- typedef _Vector_base<_Tp, _Alloc> _Base; ming ... A Bad template <typename _Alloc> Example class vector<bool,_Alloc>: public _Bvector_base<_Alloc> A Good Example { Conclusions public: typedef bool value_type; ... /usr/include/c++/3.3.2/bits/std vector.h /usr/include/c++/3.3.2/bits/std bvector.h What Is Metaprogramming? C++ Template Meta Metaprogramming means writing programs that can Programming modify other programs or themselves The modification can happen at run time or at compile Introduction Template time Metaprogram- ming Compilers are an example of metaprograming: they take a A Bad program in an input language (C, Java...) and produce Example A Good another program (with same semantic) in an output Example language (machine code, bytecode... ) Conclusions Metaprograms have three advantages: Produce code quickly Lift abstraction Produce correct code (if the metaprogram is correct) What Is Template Metaprogramming? C++ Template Meta Programming Introduction Now it is time for the replay, Template Metaprograming Template Metaprogram- is... ming A Bad Producing metaprograms in C++ using templates Example But... wait a second... why do I need Template A Good Example Metaprogramming? Conclusions The Need For Speed C++ Template int Fact(int x){ Meta Programming int acc = 1; for(;x>0;--x) acc*=x; Introduction return acc; Template Metaprogram- } ming A Bad int a, b; Example A Good a = read_int_from_stdin(); Example b = Fact(a); //we compute at run time Conclusions ... b = Fact(5); //we can compute at compile //time but we do not We pay the time to compute something that is a constant! Naive Solution C++ ... Template Meta Programming b = 120; //b = Fact(5); Introduction Template The solution is not elegant. We need to place a lot Magic Metaprogram- ming Numbers in the code. And the magic number does not keep its A Bad meaning (5! = 120 or 42 + 78 = 120 ...). Example We can use a but it is not better: we must provide a A Good #define Example define for all possible value of the input of Fact. Conclusions ... #define FACT_4 (24) #define FACT_5 (120) ... b = FACT_5; Template Metaprogramming Solution C++ Template Meta Programming The general idea is to use the compiler to do some computation at compile time. Introduction Template To do this we need a only a C++ compiler that provides Metaprogram- ming Templates A Bad This can be done because the compiler, when compiles Example A Good Templates, produces code Example If we produce the right code (e.g. the sum of constant Conclusions terms), the compiler optimize and do constant folding But we can do more... First Step C++ Template Meta Programming template< int i> Introduction struct C { Template Metaprogram- enum { RES = i }; ming }; A Bad Example A Good cout <<_ C<2>::RES; Example Conclusions C<2>::RES is substituted by the compiler with 2: it is a cost ant and we can optimize. Back To Factorial C++ Template Meta template<int n> Programming struct Fact { enum { RET = n * Fact<n-1>::RET }; Introduction }; Template Metaprogram- ming template<> A Bad struct Fact<1> { Example A Good enum { RET = 1 }; Example }; Conclusions int b = Fact<5>::RET; // == 120 To do computation we must unroll templates: a kind of recursion Where is The Trick? C++ Template Meta Programming enum { RET = 5 * Fact<4>::RET }; Introduction enum { RET = 5 * 4 * Fact<3>::RET }; Template Metaprogram- enum { RET = 5 * 4 * 3 * Fact<2>::RET }; ming enum { RET = 5 * 4 * 3 * 2 * Fact<1>::RET }; A Bad enum { RET = 5 * 4 * 3 * 2 * 1 }; Example A Good enum { RET = 120 }; Example Conclusions b = 120; //Fact<5>::RET; C++ Template Metaprogramming Operators C++ Template Meta Programming template <bool C, class T, class E> struct IF { Introduction Template typedef T RET; Metaprogram- }; ming A Bad Example template <class T, class E> A Good Example struct IF<false, T, E> { Conclusions typedef E RET; }; C++ Template Metaprogramming Operators C++ Template Meta class CopyingGC { Programming public: void Collect() /*...*/ Introduction Template }; Metaprogram- ming A Bad class MarkAndSweepGC { Example public: A Good void Collect() /*...*/ Example }; Conclusions IF<GC == COPY, CopyingGC, MarkAndSweepGC>::RET gc; gc.Collect(); C++ Template Metaprogramming Functions C++ Template Meta Programming Introduction Template<int n1, int n2> Template struct Max { Metaprogram- ming enum { RET = (n1 > n2) ? n1 : n2 }; A Bad }; Example A Good Example _ cout << Max<42, 6>::RET; //prints 42 Conclusions C++ Template Metaprogramming Code Generation C++ inline int Power(const int x, int n){ Template Meta int p = 1; Programming for(;n>0; --n) p *= x; return p; Introduction } Template Metaprogram- ming A Bad We can specialize Power code for particular cases: Example A Good inline int Power3(const int x){ Example int p = 1; Conclusions p *= x; p *= x; p *= x; return p; } C++ Template Metaprogramming Code Generation C++ template<int n> Template Meta inline int Power(const int x){ Programming return Power<n-1>(x) * x; } Introduction Template Metaprogram- template<> ming A Bad inline int Power<1>(const int x){ Example return 1; A Good } Example Conclusions template<> inline int Power<0>(const int x){ return 1; } cout <<_ Power<4>(m); C++ Template Metaprogramming Code Generation C++ Template Meta _ cout << Power<4>(m); Programming _ cout << Power<3>(m) * m; Introduction Template Metaprogram- cout <<_ Power<2>(m) * m * m; ming A Bad cout <<_ Power<2>(m) * m * m * m; Example A Good Example cout <<_ Power<1>(m) * m * m * m * m; Conclusions cout <<_ 1 * m * m * m * m; cout <<_ m * m * m * m; C++ Template Metaprogramming Loop Unrolling(1) C++ Template Meta Programming template<int n, class B> struct FOR { Introduction static void loop(int m) { Template for (int i = 0; i < m/n; i++) { Metaprogram- ming UNROLL<n, B>::iteration(i * n); A Bad } Example A Good for (int i = 0; i < m%n; i++) { Example B::body(n * m/n + i); Conclusions } } }; C++ Template Metaprogramming Loop Unrolling(2) C++ Template Meta template <int n, class B> Programming struct UNROLL{ static void iteration(int i) { Introduction Template B::body(i); Metaprogram- UNROLL<n-1, B>::iteration(i + 1); ming A Bad } Example }; A Good Example template <class B> Conclusions struct UNROLL<0, B> { static void iteration(int i){ } }; C++ Template Metaprogramming Code Generation C++ Template Meta Programming Introduction We can generate code for multiple purposes: Template Metaprogram- Vector operations ming Math functions A Bad ... Example A Good Exercise: try to write some C++ Template Example Metaprograming functions and control structures (WHILE) Conclusions C++ Template Metaprogramming Data Structures C++ Template Meta Programming Introduction Lisp lovers know very well this code: Template Metaprogram- (cons 1 (cons 2 (cons 3 (cons 4 (cons nil)))) ming A Bad The previous code represents the list: Example (1 2 3 4) A Good Example C++ Template Metaprogrammers have this too... Conclusions C++ Template Metaprogramming Data Structures C++ Template Meta template <int n, class T> Programming struct Cons { enum { item = n }; Introduction typedef T next; Template Metaprogram- }; ming A Bad struct Nil { }; Example A Good typedef Cons<1, Cons<2, Nil()> > V; Example //V::item == 1; Conclusions //V::next::item == 2; //V::next::next == Nil; Exercise: try to create a Tree Total Loop Unroll C++ Template Meta Programming Introduction Template We want to copy all elements of an int array into another Metaprogram- ming We want to do it fast A Bad Example We can use an approach similar to FOR template A Good metastructure Example Conclusions Total Loop Unroll (C++ Code 1) C++ Template Meta Programming template<int N> inline void Copy(int n, int* from, int* to){ Introduction Template for (int i = 0; i < n/N; ++i) { Metaprogram- TMP_COPY_UNROLL<N>::iteration(i * N, from, to);ming A Bad } Example for (int i = 0; i < n%N; ++i) { A Good Example *to++ = *from++; Conclusions } } Total Loop Unroll (C++ Code 2) C++ Template template <int N> Meta struct TMP_COPY_UNROLL { Programming static void iteration(int i, int *f, int* t){ *t++ = *f++; Introduction Template TMP_COPY_UNROLL<N-1>::iteration(i + 1, f, t); Metaprogram- } ming A Bad }; Example A Good template <> Example Conclusions struct TMP_COPY_UNROLL<1> { static void iteration(int i, int* f, int* t){ *t++ = *f++; } }; Performance Results C++ Template Meta We measure the “Execution Time” of various values of Programming unroll and..
Recommended publications
  • Chapter 1 Introduction to Computers, Programs, and Java
    Chapter 1 Introduction to Computers, Programs, and Java 1.1 Introduction • The central theme of this book is to learn how to solve problems by writing a program . • This book teaches you how to create programs by using the Java programming languages . • Java is the Internet program language • Why Java? The answer is that Java enables user to deploy applications on the Internet for servers , desktop computers , and small hand-held devices . 1.2 What is a Computer? • A computer is an electronic device that stores and processes data. • A computer includes both hardware and software. o Hardware is the physical aspect of the computer that can be seen. o Software is the invisible instructions that control the hardware and make it work. • Computer programming consists of writing instructions for computers to perform. • A computer consists of the following hardware components o CPU (Central Processing Unit) o Memory (Main memory) o Storage Devices (hard disk, floppy disk, CDs) o Input/Output devices (monitor, printer, keyboard, mouse) o Communication devices (Modem, NIC (Network Interface Card)). Bus Storage Communication Input Output Memory CPU Devices Devices Devices Devices e.g., Disk, CD, e.g., Modem, e.g., Keyboard, e.g., Monitor, and Tape and NIC Mouse Printer FIGURE 1.1 A computer consists of a CPU, memory, Hard disk, floppy disk, monitor, printer, and communication devices. CMPS161 Class Notes (Chap 01) Page 1 / 15 Kuo-pao Yang 1.2.1 Central Processing Unit (CPU) • The central processing unit (CPU) is the brain of a computer. • It retrieves instructions from memory and executes them.
    [Show full text]
  • Language Translators
    Student Notes Theory LANGUAGE TRANSLATORS A. HIGH AND LOW LEVEL LANGUAGES Programming languages Low – Level Languages High-Level Languages Example: Assembly Language Example: Pascal, Basic, Java Characteristics of LOW Level Languages: They are machine oriented : an assembly language program written for one machine will not work on any other type of machine unless they happen to use the same processor chip. Each assembly language statement generally translates into one machine code instruction, therefore the program becomes long and time-consuming to create. Example: 10100101 01110001 LDA &71 01101001 00000001 ADD #&01 10000101 01110001 STA &71 Characteristics of HIGH Level Languages: They are not machine oriented: in theory they are portable , meaning that a program written for one machine will run on any other machine for which the appropriate compiler or interpreter is available. They are problem oriented: most high level languages have structures and facilities appropriate to a particular use or type of problem. For example, FORTRAN was developed for use in solving mathematical problems. Some languages, such as PASCAL were developed as general-purpose languages. Statements in high-level languages usually resemble English sentences or mathematical expressions and these languages tend to be easier to learn and understand than assembly language. Each statement in a high level language will be translated into several machine code instructions. Example: number:= number + 1; 10100101 01110001 01101001 00000001 10000101 01110001 B. GENERATIONS OF PROGRAMMING LANGUAGES 4th generation 4GLs 3rd generation High Level Languages 2nd generation Low-level Languages 1st generation Machine Code Page 1 of 5 K Aquilina Student Notes Theory 1. MACHINE LANGUAGE – 1ST GENERATION In the early days of computer programming all programs had to be written in machine code.
    [Show full text]
  • C++ Metastring Library and Its Applications⋆
    C++ Metastring Library and its Applications! Zal´anSz˝ugyi, Abel´ Sinkovics, Norbert Pataki, and Zolt´anPorkol´ab Department of Programming Languages and Compilers, E¨otv¨osLor´andUniversity P´azm´any P´eter s´et´any 1/C H-1117 Budapest, Hungary {lupin, abel, patakino, gsd}@elte.hu Abstract. C++ template metaprogramming is an emerging direction of generative programming: with proper template definitions wecanenforce the C++ compiler to execute algorithms at compilation time. Template metaprograms have become essential part of today’s C++ programs of industrial size; they provide code adoptions, various optimizations, DSL embedding, etc. Besides the compilation time algorithms, template metaprogram data-structures are particularly important. From simple typelists to more advanced STL-like data types there are a variety of such constructs. Interesting enough, until recently string, as one of the most widely used data type of programming, has not been supported. Al- though, boost::mpl::string is an advance in this area, it still lacks the most fundamental string operations. In this paper, we analysed the pos- sibilities of handling string objects at compilation time with a metastring library. We created a C++ template metaprogram library that provides the common string operations, like creating sub-strings, concatenation, replace, and similar. To provide real-life use-cases we implemented two applications on top of our Metastring library. One use case utilizes com- pilation time inspection of input in the domain of pattern matching al- gorithms, thus we are able to select the more optimal search method at compilation time. The other use-case implements safePrint, a type-safe version of printf –awidelyinvestigatedproblem.Wepresentboththe performance improvements and extended functionality we haveachieved in the applications of our Metastring library.
    [Show full text]
  • 13 Templates-Generics.Pdf
    CS 242 2012 Generic programming in OO Languages Reading Text: Sections 9.4.1 and 9.4.3 J Koskinen, Metaprogramming in C++, Sections 2 – 5 Gilad Bracha, Generics in the Java Programming Language Questions • If subtyping and inheritance are so great, why do we need type parameterization in object- oriented languages? • The great polymorphism debate – Subtype polymorphism • Apply f(Object x) to any y : C <: Object – Parametric polymorphism • Apply generic <T> f(T x) to any y : C Do these serve similar or different purposes? Outline • C++ Templates – Polymorphism vs Overloading – C++ Template specialization – Example: Standard Template Library (STL) – C++ Template metaprogramming • Java Generics – Subtyping versus generics – Static type checking for generics – Implementation of Java generics Polymorphism vs Overloading • Parametric polymorphism – Single algorithm may be given many types – Type variable may be replaced by any type – f :: tt => f :: IntInt, f :: BoolBool, ... • Overloading – A single symbol may refer to more than one algorithm – Each algorithm may have different type – Choice of algorithm determined by type context – Types of symbol may be arbitrarily different – + has types int*intint, real*realreal, ... Polymorphism: Haskell vs C++ • Haskell polymorphic function – Declarations (generally) require no type information – Type inference uses type variables – Type inference substitutes for variables as needed to instantiate polymorphic code • C++ function template – Programmer declares argument, result types of fctns – Programmers
    [Show full text]
  • Complete Code Generation from UML State Machine
    Complete Code Generation from UML State Machine Van Cam Pham, Ansgar Radermacher, Sebastien´ Gerard´ and Shuai Li CEA, LIST, Laboratory of Model Driven Engineering for Embedded Systems, P.C. 174, Gif-sur-Yvette, 91191, France Keywords: UML State Machine, Code Generation, Semantics-conformance, Efficiency, Events, C++. Abstract: An event-driven architecture is a useful way to design and implement complex systems. The UML State Machine and its visualizations are a powerful means to the modeling of the logical behavior of such an archi- tecture. In Model Driven Engineering, executable code can be automatically generated from state machines. However, existing generation approaches and tools from UML State Machines are still limited to simple cases, especially when considering concurrency and pseudo states such as history, junction, and event types. This paper provides a pattern and tool for complete and efficient code generation approach from UML State Ma- chine. It extends IF-ELSE-SWITCH constructions of programming languages with concurrency support. The code generated with our approach has been executed with a set of state-machine examples that are part of a test-suite described in the recent OMG standard Precise Semantics Of State Machine. The traced execution results comply with the standard and are a good hint that the execution is semantically correct. The generated code is also efficient: it supports multi-thread-based concurrency, and the (static and dynamic) efficiency of generated code is improved compared to considered approaches. 1 INTRODUCTION Completeness: Existing tools and approaches mainly focus on the sequential aspect while the concurrency The UML State Machine (USM) (Specification and of state machines is limitedly supported.
    [Show full text]
  • Chapter 1 Introduction to Computers, Programs, and Java
    Chapter 1 Introduction to Computers, Programs, and Java 1.1 Introduction • Java is the Internet program language • Why Java? The answer is that Java enables user to deploy applications on the Internet for servers, desktop computers, and small hand-held devices. 1.2 What is a Computer? • A computer is an electronic device that stores and processes data. • A computer includes both hardware and software. o Hardware is the physical aspect of the computer that can be seen. o Software is the invisible instructions that control the hardware and make it work. • Programming consists of writing instructions for computers to perform. • A computer consists of the following hardware components o CPU (Central Processing Unit) o Memory (Main memory) o Storage Devices (hard disk, floppy disk, CDs) o Input/Output devices (monitor, printer, keyboard, mouse) o Communication devices (Modem, NIC (Network Interface Card)). Memory Disk, CD, and Storage Input Keyboard, Tape Devices Devices Mouse CPU Modem, and Communication Output Monitor, NIC Devices Devices Printer FIGURE 1.1 A computer consists of a CPU, memory, Hard disk, floppy disk, monitor, printer, and communication devices. 1.2.1 Central Processing Unit (CPU) • The central processing unit (CPU) is the brain of a computer. • It retrieves instructions from memory and executes them. • The CPU usually has two components: a control Unit and Arithmetic/Logic Unit. • The control unit coordinates the actions of the other components. • The ALU unit performs numeric operations (+ - / *) and logical operations (comparison). • The CPU speed is measured by clock speed in megahertz (MHz), with 1 megahertz equaling 1 million pulses per second.
    [Show full text]
  • Functional Programming with C++ Template Metaprograms
    Functional Programming with C++ Template Metaprograms Zolt´an Porkol´ab E¨otv¨os Lor´and University, Faculty of Informatics Dept. of Programming Languages and Compilers P´azm´any P´eter s´et´any 1/C H-1117 Budapest, Hungary [email protected] Abstract. Template metaprogramming is an emerging new direction of generative programming: with the clever definitions of templates we can enforce the C++ compiler to execute algorithms at compilation time. Among the application areas of template metaprograms are the expres- sion templates, static interface checking, code optimization with adap- tion, language embedding and active libraries. However, as this feature of C++ was not an original design goal, the language is not capable of elegant expression of template metaprograms. The complicated syn- tax leads to the creation of code that is hard to write, understand and maintain. Despite that template metaprogramming has a strong rela- tionship with functional programming paradigm, language syntax and the existing libraries do not follow these requirements. In this paper we give a short and incomplete introduction to C++ templates and the ba- sics of template metaprogramming. We will enlight the role of template metaprograms, some important and widely used idioms and techniques. 1 Introduction Templates are key elements of the C++ programming language [3, 32]. They enable data structures and algorithms to be parameterized by types, thus cap- turing commonalities of abstractions at compilation time without performance penalties at runtime [37]. Generic programming [28, 27, 17] is a recently popu- lar programming paradigm, which enables the developer to implement reusable codes easily. Reusable components { in most cases data structures and algo- rithms { are implemented in C++ with the heavy use of templates.
    [Show full text]
  • What Is a Computer Program? 1 High-Level Vs Low-Level Languages
    What Is A Computer Program? Scientific Computing Fall, 2019 Paul Gribble 1 High-level vs low-level languages1 2 Interpreted vs compiled languages3 What is a computer program? What is code? What is a computer language? A computer program is simply a series of instructions that the computer executes, one after the other. An instruction is a single command. A program is a series of instructions. Code is another way of referring to a single instruction or a series of instructions (a program). 1 High-level vs low-level languages The CPU (central processing unit) chip(s) that sit on the motherboard of your computer is the piece of hardware that actually executes instructions. A CPU only understands a relatively low-level language called machine code. Often machine code is generated automatically by translating code written in assembly language, which is a low-level programming language that has a relatively direcy relationship to machine code (but is more readable by a human). A utility program called an assembler is what translates assembly language code into machine code. In this course we will be learning how to program in MATLAB, which is a high-level programming language. The “high-level” refers to the fact that the language has a strong abstraction from the details of the computer (the details of the machine code). A “strong abstraction” means that one can operate using high-level instructions without having to worry about the low-level details of carrying out those instructions. An analogy is motor skill learning. A high-level language for human action might be drive your car to the grocery store and buy apples.
    [Show full text]
  • A Tool for the Evaluation of the Complexity of Programs Using C++ Templates
    COMPUTATION TOOLS 2011 : The Second International Conference on Computational Logics, Algebras, Programming, Tools, and Benchmarking A Tool for the Evaluation of the Complexity of Programs Using C++ Templates Nicola Corriero, Emanuele Covino and Giovanni Pani Dipartimento di Informatica Università di Bari Italy Email: (corriero|covino|pani)@di.uniba.it Abstract—We investigate the relationship between C++ tem- template <int X> class pow<0,X> plate metaprogramming and computational complexity, show- {public: enum {result=1};}; ing how templates characterize the class of polynomial-time computable functions, by means of template recursion and specialization. Hence, standard C++ compilers can be used as The command line int z=pow<3,5>::result, produces at a tool to certify polytime-bounded programs. compile time the value 125, since the operator A::B refers to Keywords-Partial evaluation; C++ template metaprogram- the symbol B in the scope of A; when reading the command ming; polynomial-time programs. pow<3,5>::result, the compiler triggers recursively the template for the values <2,5>, <1,5>, until it eventually I. INTRODUCTION hits <0,5>. This final case is handled by the partially According to [7], template metaprograms consist of specialized template pow<0,X>, that returns 1. Instructions classes of templates operating on numbers and types as like enum{result = function<args>::result;} represent the a data. Algorithms are expressed using template recursion step of the recursive evaluation of function, and produce the as a looping construct and template specialization as a intermediate values. This computation happens at compile conditional construct. Template recursion involves the use time, since enumeration values are not l-values, and when of class templates in the construction of its own member one pass them to the recursive call of a template, no static type or member constant.
    [Show full text]
  • Chapter 1 Basic Principles of Programming Languages
    Chapter 1 Basic Principles of Programming Languages Although there exist many programming languages, the differences among them are insignificant compared to the differences among natural languages. In this chapter, we discuss the common aspects shared among different programming languages. These aspects include: programming paradigms that define how computation is expressed; the main features of programming languages and their impact on the performance of programs written in the languages; a brief review of the history and development of programming languages; the lexical, syntactic, and semantic structures of programming languages, data and data types, program processing and preprocessing, and the life cycles of program development. At the end of the chapter, you should have learned: what programming paradigms are; an overview of different programming languages and the background knowledge of these languages; the structures of programming languages and how programming languages are defined at the syntactic level; data types, strong versus weak checking; the relationship between language features and their performances; the processing and preprocessing of programming languages, compilation versus interpretation, and different execution models of macros, procedures, and inline procedures; the steps used for program development: requirement, specification, design, implementation, testing, and the correctness proof of programs. The chapter is organized as follows. Section 1.1 introduces the programming paradigms, performance, features, and the development of programming languages. Section 1.2 outlines the structures and design issues of programming languages. Section 1.3 discusses the typing systems, including types of variables, type equivalence, type conversion, and type checking during the compilation. Section 1.4 presents the preprocessing and processing of programming languages, including macro processing, interpretation, and compilation.
    [Show full text]
  • User's Guide and Reference
    IBM Compiler and Library for REXX on IBM Z Version 1 Release 4 User’s Guide and Reference IBM SH19-8160-06 Note Before using this information and the product it supports, be sure to read the general information under Appendix G, “Notices,” on page 267. Seventh Edition, August 2013 This edition applies to version 1 release 4 of IBM Compiler for REXX on IBM Z (product number 5695-013) and the IBM Library for REXX on IBM Z (product number 5695-014), and to all subsequent releases and modifications until otherwise indicated in new editions. This edition replaces SH19-8160-04. © Copyright International Business Machines Corporation 1991, 2013. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents About This Book..................................................................................................xix How to Read the Syntax Notation............................................................................................................. xix How This Book Is Organized..................................................................................................................... xix How to Send Your Comments.................................................................................................................... xx What's New in Release 4..................................................................................... xxi IBM Compiler for REXX on IBM Z..............................................................................................................xxi
    [Show full text]
  • Virtual Machines for Dynamic Languages Ausgewählte Kapitel Der Systemsoftwaretechnik, WS2021
    Virtual Machines for Dynamic Languages Ausgewählte Kapitel der Systemsoftwaretechnik, WS2021 Mark Deutel Friedrich-Alexander-University Erlangen-Nürnberg (FAU) Erlangen, Germany [email protected] ABSTRACT threading model. It is common that once a dynamic language has A common approach to execute dynamic languages is inside a vir- grown popular enough the interpreter is extended by a just-in-time tual machine (VM), usually implemented in a low level system (JIT) compiler to more efficiently execute interpreted code. language like C. Such VMs have to support the often complex However this approach does not come without problems. The syntax and semantics of the dynamic languages they are hosting. effort required to write a complete virtual machine from scratch Additionally, some properties of dynamic language code can only is huge. It also forces the language implementer to deal with plat- be inferred at runtime making the optimization of code execution form or target architecture specific details. This makes implement- another challenging task. Therefore, it is hardly possible to provide ing a VM time consuming, error prone, and complicated to port general purpose implementations that support a large range of to other systems. Additionally, modern dynamic languages like different dynamic languages. Furthermore, many commonly used Python, Ruby or JavaScript evolve rapidly and have complex syn- dynamic languages such as Python or Javascript are still evolving tax and semantics. This not only makes it hard to represent the which means that their VMs have to adapt constantly. This implies language properly in low level code, but makes maintenance of that it is necessary to write and maintain a sufficiently elaborated existing VM implementations a complicated task as well.
    [Show full text]