Language Proposal: tail

Similar documents
Language Reference Manual

Java+- Language Reference Manual

Pace University. Fundamental Concepts of CS121 1

egrapher Language Reference Manual

Introduction to Programming Using Java (98-388)

Typescript on LLVM Language Reference Manual

1 Lexical Considerations

Computer Components. Software{ User Programs. Operating System. Hardware

Flow Control. CSC215 Lecture

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

Object oriented programming C++

Introduction to Bioinformatics

SSOL Language Reference Manual

BoredGames Language Reference Manual A Language for Board Games. Brandon Kessler (bpk2107) and Kristen Wise (kew2132)

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Scala : an LLVM-targeted Scala compiler

Language Reference Manual simplicity

Short Notes of CS201

Programming II (CS300)

FRAC: Language Reference Manual

BTE2313. Chapter 2: Introduction to C++ Programming

GOBLAN Language Reference Manual

CS 106 Introduction to Computer Science I

Key Differences Between Python and Java

Instructor: SIR MUHAMMAD NAVEED Created by: ARSLAN AHMED SHAAD ( ) MUHAMMAD BILAL ( ) ISIT:

CS201 - Introduction to Programming Glossary By

Syntax and Variables

ARG! Language Reference Manual

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

Lexical Considerations

Sprite an animation manipulation language Language Reference Manual

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

Decaf Language Reference Manual

Following is the general form of a typical decision making structure found in most of the programming languages:

Programming in C. What is C?... What is C?

Programming in C UVic SEng 265

CHIL CSS HTML Integrated Language

Lexical Considerations

Programming in C. What is C?... What is C?

Intermediate Code Generation

Twister: Language Reference Manual

Java Bytecode (binary file)

GBL Language Reference Manual

C++ Support Classes (Data and Variables)

Programming II (CS300)

(Not Quite) Minijava

DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6)

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards

GOLD Language Reference Manual

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Fundamentals of Programming Session 13

CSC326 Python Imperative Core (Lec 2)

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

COMP-520 GoLite Tutorial

LECTURE 18. Control Flow

Tail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d)

Final exam. Final exam will be 12 problems, drop any 2. Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers)

RTL Reference 1. JVM. 2. Lexical Conventions

Loops. CSE 114, Computer Science 1 Stony Brook University

VLC : Language Reference Manual

BASIC ELEMENTS OF A COMPUTER PROGRAM

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

TML Language Reference Manual

Programming II (CS300)

Lecture 2 Tao Wang 1

Graphiti A Simple Graph Language. Language Reference Manual

Section 2.2 Your First Program in Java: Printing a Line of Text

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

Boolean evaluation and if statements. Making decisions in programs

CS 231 Data Structures and Algorithms, Fall 2016

CS50 Supersection (for those less comfortable)

Basics of Java Programming

VENTURE. Section 1. Lexical Elements. 1.1 Identifiers. 1.2 Keywords. 1.3 Literals

CS11 Java. Fall Lecture 1

PROGRAMMING FUNDAMENTALS

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:

Case by Case. Chapter 3

Decision Making in C

Compiler Construction

Objectives. In this chapter, you will:

Unit 7. Functions. Need of User Defined Functions

Programming in C++ 6. Floating point data types

APCS Semester #1 Final Exam Practice Problems

Review. Primitive Data Types & Variables. String Mathematical operators: + - * / % Comparison: < > <= >= == int, long float, double boolean char

Review of the C Programming Language for Principles of Operating Systems

Review of the C Programming Language

CSE 142 Su 04 Computer Programming 1 - Java. Objects

GraphQuil Language Reference Manual COMS W4115

easel LANGUAGE REFERENCE MANUAL

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

IPCoreL. Phillip Duane Douglas, Jr. 11/3/2010

Tail recursion. Decision. Assignment. Iteration

Basic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces

Data Types, Variables and Arrays. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

G. Tardiani RoboCup Rescue. EV3 Workshop Part 1 Introduction to RobotC

CSc 520 Principles of Programming Languages. 26 : Control Structures Introduction

Transcription:

Language Proposal: tail A tail recursion optimization language Some Wise Gal Team Roles Team Members UNIs Roles Sandra Shaefer Jennifer Lam Serena Shah Simpson Fiona Rowan sns2153 jl3953 ss4354 fmr2112 Project Manager Systems Architect Tester Language Guru Language Description Our language aims to optimize recursion through tail call optimization on the compiler level. Our compiler will eliminate overhead incurred by tail recursive algorithms by bypassing the allocation of new stack frames within recursive function calls. The main idea is to allocate constant stack space for each recursive function, making recursive functions more time and space efficient on average. Our language syntax also explicitly encourages users to conceptualize recursion as a set of base cases and repetition rules. Motivation Tail recursion is a useful aspect of structured programming, but in many general purpose languages, it is less efficient than its iterative counterpart. Implementing tail recursion using Java syntax, for instance, requires using control flow and loops with conditions, general concepts used for implementing non recursive functions as well, and therefore the syntax does not lend itself well to distinguishing between computing tail recursive functions vs. other kinds of functions in the backend. We wish to leverage the standard form of tail recursive functions in order to make them easier to conceptualize in code and more efficient to run. Tail calls are subroutine calls executed at the last line of a function, and tail recursion is when the subroutine call is the function itself. For such functions, we wish to allocate constant stack space, replacing function stack frames by those of subsequent subroutine calls instead of allocating space for new stack frames on the call stack. We drew inspiration for our tail call elimination language from features of Scheme and some tail call optimizing C compiler options.

Summary of Goals A high level language for optimizing tail recursion by reducing stack overhead Utilize intuitive syntax to improve readability and accessibility of recursive functions Compile to LLVM for its speed and optimization infrastructure Domain features Constant stack allocation for tail recursive function calls Syntax and function typing to make recursive and iterative functions easier to write and understand Utilize LLVM to communicate with lower levels of control Language Design Our language will eliminate the overhead incurred by tail recursion at the compiler level. We will bypass the need to allocate new stack frames for subroutines in LLVM. By the time a subroutine is called at the end of a function scope, much of the stack frame of the current function call is useless, so instead of allocating memory for a new stack on the call stack, we will pass information down to the subroutine s stack and replace the current stack with the subroutine s stack. At the compiler level, the program can jump to the subroutine call instead of allocating space for a new stack. Our language syntax will lends itself well to conceptualizing recursive algorithms. Code Syntax Built In Types int float char bool int[] float[] char[] A sequence of digits that don t contain decimals. A sequence of digits that do contain decimals. A sequence of characters between quotes. A boolean type that can evaluate to either true or false. An array of ints. An array of floats. An array of chars.

bool[] null An array of booleans. A special value that indicates an uninitialized variable. Function Syntax : < functiontype> <Name> <arg> <arg> { Function definitions will start with one of three function type words, followed by the name of the function. Following the name of the function are any number of arguments, separated by spaces. After the arguments, the braces denote the beginning of the body of the function. User must specify a return statement at the end of each function scope, which consists of a colon ( : ) followed by the value to be returned. Recursive and main functions have predefined return statements. Function Types recursive iterative declarative Designates a function that will use recursive logic. This function type must include the base_case and rec keywords. Designates a function that uses iteration. This function type must include the rep keyword. Designates an declarative function. Declarative functions don t have keywords, they execute code sequentially as one would expect from a traditional programming language such as C or Java. Control Flow <condition> : [<action>] default : [<action>] Colon denotes a case. Conditional to be checked at the left of colon. Action (or list of commands) to be performed at the right. Brackets [] optional if there is only one command (highly recommended). <conditional> : <action> syntax can be listed (with default ) as the last case. See code examples. Drawn from OCaml s if then else and pattern matching concepts. Default case for a list of conditionals, must come at the end of every list of conditions (even if there is only one condition). Can be empty or just null. Comments (* I am a comment *) Same comment syntax for single line and multi line comments. (* I am a (* Allow nested comments with same syntax

nested*) comment *) Keywords Keywords are separated into categories according to the function type. init base_case rec rep Defines the initialization of variables to be used in any function. Variables cannot be defined without this keyword. Defines the base case to be approached in recursive functions. Also defines return values (optional) after each case, as designated by a colon ( : ). Designates the portion of code that will be called recursively in a recursive function. This must include a return, designated by a colon, that calls the function name. Designates the portion of code that will be called repeatedly in an iterative function. Operators We support + * / % for integers, floats, and chars. Precedence is taken to be the standard arithmetic order. We also support the boolean operators AND as && and OR as. Scoping Scoping of variables is taken to be standard c scoping (i.e. between { or [ ], which we call enclosures). Variables defined within curly braces or brackets are visible only inside. Variables defined outside can be modified inside. A variable declared between enclosures that shares a name with variable of more global scope (declared outside, but visible inside) is the one that is used. Code Samples (* Factorial function in recursive form *) recursive Factorial_R n { base_case { n == 1 : 1 rec {

n * Factorial_R n 1 (* Factorial function in iterative form *) iterative Factorial_I n { init { i = 1 prod = 1 rep n { prod = prod * i i = i + 1 : prod (* Recursively perform a binary search on an array A Return value of position if n found, 1 otherwise *) recursive Binary_Search n lo hi A { init { mid = (lo + hi) / 2 base_case{ lo > hi: 1 A[mid] == n: mid rec{ A[mid] < n: Binary_Search n mid+1 hi A[mid] >= n: Binary_Search n lo mid 1 (* Declarative program example. Simply prints Hello World *) declarative Hello_World { print Hello World :null (* Declarative program demonstrating control flow *)

declarative Control_Flow ice_cream { (* Uses single command style until default case for illustration purposes *) ice_cream == mango : print fave ice_cream == chocolate : print allergic ice_cream == taiwanese McDonald s : print Edwards recommends default: [ a = Ice cream is overrated print a ] :null declarative main n { A = [2,5,7,1,4,8] Hello_World Factorial_R 5 Factorial_I 5 Binary_Search 7 0 length(a) 1 A Control_Flow taiwanese McDonald s