⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pxin2.n

📁 早期freebsd实现
💻 N
📖 第 1 页 / 共 2 页
字号:
.IPA pointer to the specified length inline data is pushedonto the stack.This is primarily used for.I printftype strings used by .SM WRITEF .(see sections 3.6 and 3.8).SHINX* s,w,w.IPThe operators.SM INX2and.SM INX4are used for subscripting.For example, the statement.DSa[i] := 2.0.DE.IPwith.I ian integer and.I aan``array [1..1000] of real''would generate.DS.TSlp-2w(8) l.LV:\fIl	a\fPRV4:\fIl	i\fPINX4:8	1,999CON8	2.0AS8.TE.DE.IPHere the.SM LVoperation takes the address of.I aand places it on the stack.The value of.I iis then placed on top of this on the stack.The array address is indexed by thelength 4 index (a length 2 index would use.SM INX2 )where the individual elements have a size of 8 bytes.The code for .SM INX4is:.DS.mD_INX4:	\fBcvtbl\fR	(lc)+,r0	\fBbneq\fR	L1	\fBcvtwl\fR	(lc)+,r0	#r0 has size of recordsL1:	\fBcvtwl\fR	(lc)+,r1	#r1 has lower bound	\fBmovzwl\fR	(lc)+,r2	#r2 has upper-lower bound	\fBsubl3\fR	r1,(sp)+,r3	#r3 has base subscript	\fBcmpl\fR	r3,r2	#check for out of bounds	\fBbgtru\fR	esubscr	\fBmull2\fR	r0,r3	#calculate byte offset	\fBaddl2\fR	r3,(sp)		#calculate actual address	\fBjmp\fR	(loop)esubscr:	\fBmovw\fR	$ESUBSCR,_perrno	\fBjbr\fR	error.DE.IPHere the lower bound is subtracted, and range checked against theupper minus lower bound.The offset is then scaled to a byte offset into the arrayand added to the base address on the stack.Multi-dimension subscripts are translated as a sequence of single subscriptings..SHIND*.IPFor indirect references through.B varparameters and pointers,the interpreter has a set of indirection operators that convert a pointeron the stack into a value on the stack from that address.different.SM INDoperators are necessary because of the possibility of differentlength operands.The.SM IND14and.SM IND24operators do conversions to longas they push their data..NH 2Arithmetic operators.PPThe interpreter has many arithmetic operators.All operators produce results long enough to prevent overflowunless the bounds of the base type are exceeded.The basic operators available are.DSAddition:	ADD*, SUCC*Subtraction:	SUB*, PRED*Multiplication:	MUL*, SQR*Division:	DIV*, DVD*, MOD*Unary:		NEG*, ABS*.DE.NH 2Range checking.PPThe interpreter has several range checking operators.The important distinction among these operators is between values whoselegal range begins at zero and those that do not begin at zero, for examplea subrange variable whose values range from 45 to 70.For those that begin at zero, a simpler ``logical'' comparison againstthe upper bound suffices.For others, both the low and upper bounds must be checked independently,requiring two comparisons.On the .SM "VAX 11/780"both checks are done using a single index instructionso the only gain is in reducing the inline data..NH 2Case operators.PPThe interpreter includes three operators for.B casestatements that are used depending on the width of the .B caselabel type.For each width, the structure of the case data is the same, andis represented in figure 2.4..sp 1.so fig2.4.n.PPThe.SM CASEOPcase statement operators do a sequential search through thecase label values.If they find the label value, they take the corresponding entryfrom the transfer table and cause the interpreter to branch to thespecified statement.If the specified label is not found, an error results..PPThe.SM CASEoperators take the number of cases as a sub-opcodeif possible.Three different operators are needed to handle single byte,word, and long case transfer table values.For example, the.SM CASEOP1operator has the following code sequence:.DS.mD_CASEOP1:	\fBcvtbl\fR	(lc)+,r0	\fBbneq\fR	L1	\fBcvtwl\fR	(lc)+,r0	#r0 has length of case tableL1:	\fBmovaw\fR	(lc)[r0],r2	#r2 has pointer to case labels	\fBmovzwl\fR	(sp)+,r3	#r3 has the element to find	\fBlocc\fR	r3,r0,(r2)	#r0 has index of located element	\fBbeql\fR	caserr	#element not found	\fBmnegl\fR	r0,r0	#calculate new lc	\fBcvtwl\fR	(r2)[r0],r1	#r1 has lc offset	\fBaddl2\fR	r1,lc	\fBjmp\fR	(loop)caserr:	\fBmovw\fR	$ECASE,_perrno	\fBjbr\fR	error.DE.PPHere the interpreter first computes the address of the beginningof the case label value area by adding twice the number of case labelvalues to the address of the transfer table, since the transfertable entries are 2 byte address offsets.It then searches through the label values, and generates an ECASEerror if the label is not found.If the label is found, the index of the corresponding entryin the transfer table is extracted and that offset is addedto the interpreter location counter..NH 2Operations supporting pxp.PPThe following operations are defined to do execution profiling..SHPXPBUF w.IPCauses the interpreter to allocate a count bufferwith.I wfour byte countersand to clear them to zero.The count buffer is placed within an image of the.I pmon.outfile as described in the.I "PXP Implementation Notes."The contents of this buffer are written to the file.I pmon.outwhen the program ends..SHCOUNT w.IPIncrements the counter specified by.I w ..SHTRACNT w,A.IPUsed at the entry point to procedures and functions,combining a transfer to the entry point of the block withan incrementing of its entry count..NH 2Set operations.PPThe set operations:union.SM ADDT,intersection.SM MULT,element removal.SM SUBT,and the set relationals.SM RELTare straightforward.The following operations are more interesting..SHCARD s.IPTakes the cardinality of a set of size.I sbytes on top of the stack, leaving a 2 byte integer count..SM CARDuses the .B ffsopcode to successively count the number of set bits in the set..SHCTTOT s,w,w.IPConstructs a set.This operation requires a non-trivial amount of work,checking bounds and setting individual bits or ranges of bits.This operation sequence is slow,and motivates the presence of the operator.SM INCTbelow.The arguments to.SM CTTOTinclude the number of elements.I sin the constructed set,the lower and upper bounds of the set,the two.I wvalues,and a pair of values on the stack for each range in the set, singleelements in constructed sets being duplicated with.SM SDUPto form degenerate ranges..SHIN s,w,w.IPThe operator.B infor sets.The value.I sspecifies the size of the set,the two.I wvalues the lower and upper bounds of the set.The value on the stack is checked to be in the set on the stack,and a Boolean value of.I trueor.I falsereplaces the operands..SHINCT.IPThe operator.B inon a constructed set without constructing it.The left operand of.B inis on top of the stack followed by the number of pairs in theconstructed set,and then the pairs themselves, all as single word integers.Pairs designate runs of values and single values are represented bya degenerate pair with both value equal.This operator is generated in grammatical constructs such as.LS\fBif\fR character \fBin\fR [`+', '\-', `*', `/'].LE.IPor.LS\fBif\fR character \fBin\fR [`a'..`z', `$', `_'].LE.IPThese constructs are common in Pascal, and.SM INCTmakes them run much faster in the interpreter,as if they were written as an efficient series of.B ifstatements..NH 2Miscellaneous.PPOther miscellaneous operators that are present in the interpreterare.SM ASRTthat causes the program to end if the Boolean value on the stack is not.I true,and.SM STOI ,.SM STOD ,.SM ITOD ,and.SM ITOSthat convert between different length arithmetic operands foruse in aligning the arguments in.B procedureand.B functioncalls, and with some untyped built-ins, such as.SM SINand.SM COS \&..PPFinally, if the program is run with the run-time testing disabled, thereare special operators for.B forstatementsand special indexing operators for arraysthat have individual element size that is a power of 2.The code can run significantly faster using these operators..NH 2Mathematical Functions.PPThe transcendental functions .SM SIN ,.SM COS ,.SM ATAN ,.SM EXP ,.SM LN ,.SM SQRT ,.SM SEED ,and.SM RANDOMare taken from the standard UNIXmathematical package.These functions take double precision floating pointvalues and return the same..PPThe functions.SM EXPO ,.SM TRUNC ,and.SM ROUNDtake a double precision floating point number..SM EXPOreturns an integer representing the machine representation of its argument's exponent,.SM TRUNCreturns the integer part of its argument, and.SM ROUNDreturns the rounded integer part of its argument..NH 2System functions and procedures.SHLLIMIT.IPA line limit and a file pointer are passed on the stack.If the limit is non-negative the line limit is set to thespecified value, otherwise it is set to unlimited.The default is unlimited..SHSTLIM.IPA statement limit is passed on the stack. The statement limit is set as specified.The default is 500,000.No limit is enforced when the ``p'' option is disabled..SHCLCK.brSCLCK.IP.SM CLCKreturns the number of milliseconds of user time used by the program;.SM SCLCKreturns the number of milliseconds of system time used by the program..SHWCLCK.IPThe number of seconds since some predefined time isreturned. Its primary usefulness is in determiningelapsed time and in providing a unique time stamp..sp.LPThe other system time procedures are.SM DATEand.SM TIMEthat copy an appropriate text string into a pascal string array.The function.SM ARGCreturns the number of command line arguments passed to the program.The procedure.SM ARGVtakes an index on the stack and copies the specifiedcommand line argument into a pascal string array..NH 2Pascal procedures and functions.SHPACK s,w,w,w.brUNPACK s,w,w,w.IPThey function as a memory to memory move with severalsemantic checks. They do no ``unpacking'' or ``packing'' in the true sense as theinterpreter supports no packed data types..SHNEW s.brDISPOSE s.IPAn .SM LVof a pointer is passed. .SM NEWallocates a record of a specified size and puts a pointerto it into the pointer variable..SM DISPOSEdeallocates the record pointed to by the pointerand sets the pointer to .SM NIL ..sp.LPThe function.SM CHR*converts a suitably small integer into an ascii character.Its primary purpose is to do a range check.The function.SM ODD*returns .I trueif its argument is odd and returns.I falseif its argument is even.The function .SM UNDEFalways returns the value.I false .

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -