The BCPL Cintsys and Cintpos User Guide by Martin Richards [email protected]
Total Page:16
File Type:pdf, Size:1020Kb
The BCPL Cintsys and Cintpos User Guide by Martin Richards [email protected] http://www.cl.cam.ac.uk/users/mr10/ Computer Laboratory University of Cambridge Revision date: Thu 19 Aug 16:16:54 BST 2021 Abstract BCPL is a simple systems programming language with a small fast compiler which is easily ported to new machines. The language was first implemented in 1967 and has been in continuous use since then. It is a typeless and provides machine independent pointer arithmetic allowing a simple way to represent vectors and structures. BCPL functions are recursive and variadic but, like C, do not allow dynamic free variables, and so can be represented by just their entry addresses. There is no built-in garbage collector and all input-output is done using library calls. This document describes both the single threaded BCPL Cintcode System (called Cintsys) and the Cintcode version of the Tripos portable operating system (called Cintpos). It gives a definition of the standard BCPL language including the recently added features such as floating point expressions and constructs involving operators such as <> and op:=. This manual describes an extended version of BCPL that include some of the features of MCPL, mainly concerning the pattern matching used in function definitions. This version can be compiled using the mbcpl command. This manual also describes the standard library and running environment. The native code version of the system based on Sial and the Cintpos portable operating system are also described. Installation instructions are included. Since May 2013, the standard BCPL distribution supports both 32 and 64 bit Cintcode versions. Since August 2014, standard Cintcode BCPL includes floating point constants and operators, and since March 2018 it includes the FLT feature to make it easier to perform floating point calculations. Keywords: Systems programming language, BCPL, Cintcode, Cintpos 2 Contents Preface v 1 The System Overview 1 1.1 A Cintsys Console Session . 1 1.2 A Cintpos Console Session . 7 2 The BCPL Language 13 2.1 Language Overview . 14 2.1.1 Comments . 14 2.1.2 The GET Directive . 15 2.1.3 Conditional Compilation . 15 2.1.4 Section Brackets . 16 2.2 Expressions . 16 2.2.1 Names . 16 2.2.2 Constants . 16 2.2.3 Function Calls . 20 2.2.4 Method Calls . 20 2.2.5 Prefixed Expression Operators . 21 2.2.6 Infixed Expression Operators . 21 2.2.7 Boolean Evaluation . 22 2.2.8 VALOF Expressions . 22 2.2.9 Expression Precedence . 23 2.2.10 Manifest Constant Expressions . 24 2.3 Commands . 24 2.3.1 Assignments . 24 2.3.2 Routine Calls . 25 2.3.3 Conditional Commands . 25 2.3.4 Repetitive Commands . 26 2.3.5 SWITCHON command . 26 2.3.6 Flow of Control . 26 2.3.7 Compound Commands . 27 2.3.8 Blocks . 28 2.4 Declarations . 28 i ii CONTENTS 2.4.1 Labels . 28 2.4.2 Manifest Declarations . 28 2.4.3 Global Declarations . 29 2.4.4 Static Declarations . 29 2.4.5 LET Declarations . 30 2.4.6 Dynamic Free Variables . 32 2.5 Separate Compilation . 32 2.6 The FLT Feature . 34 2.7 The objline1 Feature . 35 3 The Library 37 3.1 Manifest constants . 37 3.2 Global Variables . 48 3.3 Global Functions . 49 3.3.1 Streams . 85 3.3.2 The Filing System . 87 3.4 Random Access . 88 3.5 RAM streams . 88 3.6 Environment Variables . 89 3.7 Coroutine examples . 90 3.7.1 A square wave generator . 90 3.7.2 Hamming's Problem . 91 3.7.3 A Discrete Event Simulator . 93 3.8 The BMP Graphics Library . 99 3.8.1 The Graphics Functions . 100 3.9 The SDL Graphics Library . 103 3.9.1 sdl.h details . 103 3.9.2 Functions defined in sdl.b . 105 3.9.3 sys(Sys sdl,...) calls . 110 3.10 The GL Graphics Library . 113 3.11 The Sound Library . 114 3.11.1 The Sound Constants . 114 3.11.2 The Sound Global Variables . 115 3.11.3 The Sound Functions . 115 3.12 The EXT Library . 115 4 The Command Language 117 4.1 Bootstrapping Cintsys . 117 4.2 Bootstrapping Cintpos . 119 4.2.1 The Cintpos BOOT module . 119 4.2.2 startroot . 120 4.3 Commands . 123 4.4 cli.b and cli init.b . 150 CONTENTS iii 5 Console Input and Output 153 5.1 Cintsys console streams . 153 5.2 Cintpos console streams . 154 5.2.1 Devices . 155 5.2.2 Exclusive Input . 155 5.2.3 Direct access to the screen and keyboard . 156 6 Cintpos Devices 157 6.0.1 The Clock Device . 157 6.0.2 The Keyboard Device . 158 6.0.3 The Screen Device . 158 6.0.4 TCP/IP Devices . 158 7 The Debugger 161 7.1 The Cintsys Debugger . 161 7.2 The Cintpos Debugger . 165 7.3 Debugging Techniques . 166 8 The Design of OCODE 173 8.1 Representation of OCODE . 173 8.2 The OCODE Abstract Machine . 174 8.3 Loading and Storing values . 175 8.4 Field Selection Operators . 176 8.5 Expression Operators . 177 8.6 Functions and Routines . 178 8.7 Control . 180 8.8 Directives . 180 8.9 Discussion . 181 9 The Design of Cintcode 183 9.1 Designing for Compactness . 184 9.1.1 Global Variables . 185 9.1.2 Composite Instructions . 186 9.1.3 Relative Addressing . 186 9.2 The Cintcode Instruction Set . 187 9.2.1 Byte Ordering and Alignment . 187 9.2.2 Loading Values . 189 9.2.3 Indirect Load . 190 9.2.4 Expression Operators . 190 9.2.5 Simple Assignment . 191 9.2.6 Indirect Assignment . 192 9.2.7 Function and Routine Calls . 192 9.2.8 Flow of Control and Relations . 194 iv CONTENTS 9.2.9 Switch Instructions . 194 9.2.10 Miscellaneous . 195 9.2.11 Floating-point Instructions . 197 9.2.12 Select Instructions . 197 9.2.13 Undefined Instructions . 197 9.2.14 Corruption of B . 198 9.2.15 Exceptions . 198 10 The Design of Sial 199 10.1 The Sial Specification . 201 10.2 Compaction of Sial . 213 11 The MC Package 215 11.1 MC Example . 215 11.2 MC Library Functions . 219 11.3 The MC Language . 220 11.4 MC Debugging Aids . 228 11.5 The n-queens Demonstration . 228 12 Installation 233 12.1 Linux Installation . 233 12.2 Command Line Arguments . 237.