📄 pxin1.n
字号:
entry for the block.The major parts of the stack frame are represented in Figure 1.1..so fig1.1.nNote that the local variables of each blockhave negative offsets from the corresponding display entry,the ``first'' local variable having offset `\-2'..NH 2The block mark.PPThe block mark contains the saved information necessaryto restore the environment when the current block exits.It consists of two parts.The first and top-most part is saved by the.SM CALLinstruction in the interpreter.This information is not present for the main programas it is never ``called''.The second part of the block mark is created by the.SM BEGbegin block operator that also allocates and clears thelocal variable storage.The format of these blocks is represented in Figure 1.2..sp.so fig1.2.n.PPThe data saved by the.SM CALLoperator includes the line number.I linoof the point of call,that is printed if the program execution ends abnormally;the location counter.I lcgiving the return address;and the current display entry address.I dpat the time of call..PPThe.SM BEGbegin operator saves the previous display contents at the levelof this block, so that the display can be restored on block exit.A pointer to the beginning line number and thename of this block is also saved.This information is stored in the interpreter object code in-line after the.SM BEGoperator.It is used in printing a post-mortem backtrace.The saved file name and buffer reference are necessary because ofthe input/output structure(this is discussed in detail in sections 3.3 and 3.4).The top of stack reference gives the value the stack pointer shouldhave when there are no expression temporaries on the stack.It is used for a consistency check in the.SM LINOline number operators in the interpreter, that occurs beforeeach statement executed.This helps to catch bugs in the interpreter, that often manifestthemselves by leaving the stack non-empty between statements..PPNote that there is no explicit static link here.Thus to set up the display correctly after a non-local.B gotostatement one must ``unwind''through all the block marks on the stack to rebuild the display..NH 2Arguments and return values.PPA function returns its value into a space reserved by the callingblock.Arguments to a.B functionare placed on top of this return area.For both.B procedureand.B functioncalls, arguments are placed at the end of the expression evaluation areaof the caller.When a.B functioncompletes, expression evaluation can continueafter popping the arguments to the.B functionoff the stack,exactly as if the function value had been ``loaded''.The arguments to a.B procedureare also popped off the stack by the callerafter its execution ends..KS.PPAs a simple example consider the following stack structurefor a call to a function.I f,of the form ``f(a)''..so fig1.3.n.KE.PPIf we suppose that.I freturns a.I realand that.I ais an integer,the calling sequence for this function would be:.DS.TSlp-2w(8) l.PUSH \-8RV4:\fIl a\fRCALL:\fIl f\fRPOP 4.TE.DE.ZPHere we use the operator.SM PUSHto clear space for the return value,load.I aon the stack with a ``right value'' operator,call the function,pop off the argument.I a ,and can then complete evaluation of the containing expression.The operations used here will be explained in section 2..PPIf the function.I fwere given by.LS 10 \*bfunction\fR f(i: integer): real; 11 \*bbegin\fR 12 f := i 13 \*bend\fR;.LEthen.I fwould have code sequence:.DS.TSlp-2w(8) l.BEG:2 0 11 "f"LV:\fIl\fR 40RV4:\fIl\fR 32AS48END.TE.DE.ZPHere the.SM BEGoperator takes 9 bytes of inline data.The first byte specifies the length of the function name.The second longword specifies theamount of local variable storage, here none.The succeeding two lines give the line number of the.B beginand the name of the blockfor error traceback.The.SM BEGoperator places a name pointer in the block mark.The body of the.B functionfirst takes an address of the.B functionresult variable.I fusing the address of operator.SM LV.I a .The next operation in the interpretation of this function is the loadingof the value of.I i ..I Iis at the level of the.B function.I f ,here symbolically.I l,and the first variable in the local variable area.The.B functioncompletes by assigning the 4 byte integer on the stack to the 8 bytereturn location, hence the.SM AS48assignment operator, and then uses the.SM ENDoperator to exit the current block..NH 2The main interpreter loop.PPThe main interpreter loop is simply:.DS.mDiloop: \fBcaseb\fR (lc)+,$0,$255 <table of opcode interpreter addresses>.DE.ZPThe main opcode is extracted from the first byte of the instructionand used to index into the table of opcode interpreter addresses.Control is then transferred to the specified location.The sub-opcode may be used to index the display,as a small constant,or to specify one of several relational operators.In the cases where a constant is needed, but itis not small enough to fit in the byte sub-operator,a zero is placed there and the constant follows in the next word.Zero is easily tested for,as the instruction that fetches thesub-opcode sets the condition code flags.A construction like:.DS.mD_OPER: \fBcvtbl\fR (lc)+,r0 \fBbneq\fR L1 \fBcvtwl\fR (lc)+,r0L1: ....DEis all that is needed to effect this packing of data.This technique saves space in the Pascal.I objobject code..PPThe address of the instruction at.I iloopis always contained in the register variable .I loop .Thus a return to the main interpreter is simply:.DS \fBjmp\fR (loop).DEthat is both quick and occupies little space..NH 2Errors.PPErrors during interpretation fall into three classes:.DS1) Interpreter detected errors.2) Hardware detected errors.3) External events..DE.PPInterpreter detected errors include I/O errors andbuilt-in function errors. These errors cause a subroutine call to an error routinewith a single parameter indicating the cause of the error.Hardware errors such as range errors and overflows arefielded by a special routine that determines the opcodethat caused the error.It then calls the error routine with an appropriate errorparameter.External events include interrupts and system limits suchas available memory.They generate a call to the error routine with an appropriate error code.The error routine processes the error condition, printing an appropriate error message and usuallya backtrace from the point of the error.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -