📄 pxin1.n
字号:
.\" Copyright (c) 1979 The Regents of the University of California..\" All rights reserved..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\" notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\" notice, this list of conditions and the following disclaimer in the.\" documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\" must display the following acknowledgement:.\" This product includes software developed by the University of.\" California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\" may be used to endorse or promote products derived from this software.\" without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\" @(#)pxin1.n 5.2 (Berkeley) 4/17/91.\".if !\n(xx .so tmac.p.tr _\(ru.nr H1 0.NH Organization.PPMost of.I pxis written in the.SM "VAX 11/780"assembly language, using the.UXassembler.I as.Portions of.I pxare also written in the.UXsystems programming language C..I Pxconsists of a main procedure that reads in the interpreter code,a main interpreter loop that transfers successively to variouscode segments implementing the abstract machine operations,built-in procedures and functions,and several routines that support the implementation of thePascal input-output environment..PPThe interpreter runs at a fraction of the speed of equivalentcompiled C code, with this fraction varying from 1/5 to 1/15.The interpreter occupies 18.5K bytes of instruction space, shared amongall processes executing Pascal, and has 4.6K bytes of data space (constants,error messages, etc.) a copy of which is allocated to each executing process..NH 2Format of the object file.PP.I Pxnormally interprets the code left in an object file by a run of thePascal translator.I pi.The file where the translator puts the object originally, and the mostcommonly interpreted file, is called.I obj.In order that all persons using.I pxshare a common text image, this executable file is a small process that coordinates with the interpreter to startexecution.The interpreter code is placedat the end of a special ``header'' file and the size of the initializeddata area of this header file is expanded to include this code,so that during execution it is located at aneasily determined address in its data space.When executed, the object process creates a.I pipe ,creates another process by doing a.I fork ,and arranges that the resulting parent process becomes an instance of.I px .The child process then writes the interpreter code through the pipe that it has to theinterpreter process parent.When this process is complete, the child exits..PPThe real advantage of this approach is that it does not require modificationsto the shell, and that the resultant objects are ``true objects'' notrequiring special treatment.A simpler mechanism would be to determine the name of the file that wasexecuted and pass this to the interpreter.However it is not possible to determine this namein all cases.\*(Dd.FS\*(dd\ For instance, if the.I pxrefprogram is placed in the directory`/usr/bin'then when the user types``pxref program.p''the first argument to the program, nominally the programs name, is``pxref.''While it would be possible to search in the standard place,i.e. the current directory, and the system directories`/bin'and`/usr/bin'for a corresponding object file,this would be expensive and not guaranteed to succeed.Several shells exist that allow other directories to be searchedfor commands, and there is,in general,no way to determine what these directories are..FE.NH 2General features of object code.PPPascal object code is relocatable as all addressing references forcontrol transfers within the code are relative.The code consists of instructions interspersed with inline data.All instructions have a length that is an even number of bytes.No variables are kept in the object code area..PPThe first byte of a Pascal interpreter instruction contains an operationcode.This allows a total of 256 major operation codes, and 232 of these arein use in the current.I px.The second byte of each interpreter instruction is called the``sub-operation code'',or more commonly the.I sub-opcode.It contains a small integer that may, for example, be used as ablock-structure level for the associated operation.If the instruction can take a longword constant,this constant is often packed into the sub-opcodeif it fits into 8 bits and is not zero.A sub-opcode value of zero specifies that the constant would notfit and therefore follows in the next word.This is a space optimization, the value of zero for flaggingthe longer case being convenient because it is easy to test..PPOther instruction formats are used.The branchinginstructions take an offset in the following word,operators that load constants onto the stack take arbitrarily long inline constant values,and many operations deal exclusively with data on theinterpreter stack, requiring no inline data..NH 2Stack structure of the interpreter.PPThe interpreter emulates a stack-structured Pascal machine.The ``load'' instructions put values onto the stack, where allarithmetic operations take place.The ``store'' instructions take values off the stackand place them in an address that is also contained on the stack.The only way to move data or to compute in the machine is with the stack..PPTo make the interpreter operations more powerfuland to thereby increase the interpreter speed,the arithmetic operations in the interpreter are ``typed''.That is, length conversion of arithmetic values occurs when they areused in an operation.This eliminates interpreter cycles for length conversionand the associated overhead.For example, when adding an integer that fits in one byte to one thatrequires four bytes to store, no ``conversion'' operators are required.The one byte integer is loaded onto the stack, followed by the fourbyte integer, and then an adding operator is used that has, implicitin its definition, the sizes of the arguments..NH 2Data types in the interpreter.PPThe interpreter deals with several different fundamental data types.In the memory of the machine, 1, 2, and 4 byte integers are supported,with only 2 and 4 byte integers being present on the stack.The interpreter always converts to 4 byte integers when there is a possibilityof overflowing the shorter formats.This corresponds to the Pascal language definition of overflow inarithmetic operations that requires that the result be correctif all partial values lie within the bounds of the base integer type:4 byte integer values..PPCharacter constants are treated similarly to 1 byte integers formost purposes, as are Boolean values.All enumerated types are treated as integer values ofan appropriate length, usually 1 byte.The interpreter also has real numbers, occupying 8 bytes of storage,and sets and strings of varying length.The appropriate operations are included for each data type, such asset union and intersection and an operation to write a string..PPNo special.B packeddata formats are supported by the interpreter.The smallest unit of storage occupied by any variable is one byte.The built-ins.I packand.I unpackthus degenerate to simple memory to memory transfers withno special processing..NH 2Runtime environment.PPThe interpreter runtime environment uses a stack data area and a heapdata area, that are kept at opposite ends of memoryand grow towards each other.All global variables and variables local to procedures and functionsare kept in the stack area.Dynamically allocated variables and buffers for input/output areallocated in the heap..PPThe addressing of block structured variables is done by usinga fixed displaythat contains the address of its stack framefor each statically active block.\*(Dg.FS\*(dg\ Here ``block'' is being used to mean any.I procedure ,.I functionor the main program..FEThis display is referenced by instructions that load and storevariables and maintained by the operations forblock entry and exit, and for non-local.B gotostatements..NH 2Dp, lc, loop.PPThree ``global'' variables in the interpreter, in addition to the``display'', are the.I dp,.I lc,and the.I loop.The.I dpis a pointer to the display entry for the current block;the.I lcis the abstract machine location counter;and the.I loopis a register that holds the address of the main interpreterloop so that returning to the loop to fetch the next instruction isa fast operation..NH 2The stack frame structure.PPEach active blockhas a stack frame consisting of three parts:a block mark, local variables, and temporary storage for partiallyevaluated expressions.The stack in the interpreter grows from the high addresses in memoryto the low addresses,so that those parts of the stack frame that are ``on the top''of the stack have the most negative offsets from the display
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -