Oppolzer - Informatik / Stanford Pascal Compiler


Home       Lebenslauf       Schwerpunkte       Kenntnisse       Seminare       Kunden       Projekte       Produkte       Blog       Stanford Pascal       Kontakt

The Stanford Pascal Compiler / Evolution Steps

Back to Compiler main page

Shorter strings (variables) can be assigned to longer strings

Compiler version: 12.2017

When doing some enhancements on the compiler, I had to assign a 20 byte string (a variable identifier) to a 32 byte string (error information of the symbol scanner). "String" at the moment is simply an abbreviation for "array of char", BTW.

But this was not possible until now; the compiler showed an error P129 ("Type conflict of operands").

I tried to make such assignments possible (shorter strings to longer strings); the longer target strings should be filled with blanks.

It turned out that the easiest way will be to create a new P-Code instruction MFI (memory fill). I planned this instruction to have a length argument; it should fetch an address and a char from the stack and fill the storage from the given address with the char pattern, using the (fixed) length from the instruction.

Example:


LDA 1,362 - target address LDC C,' ' - blank = initialization pattern MFI 30 - move 30 blanks to address 362

When I started to use the new P-Code in assignments involving different lengths, it turned out that another additional variant of MFI is needed. The two addresses for the MOV instruction are already on the stack (target first, then source address). Then, before MFI, the Blank (the initialization pattern) is loaded on the stack. The second variant of the MFI instruction should then take the target address from the 3rd position of the stack (the 2nd stack position, which is the source address, should be ignored), and after execution of MFI, only the initialization pattern should be popped; the two addresses should remain on the stack for the subsequent MOV instruction.

To control this, a negative length is specified on MFI.

Example:


LDA 1,362 - target address LDA 1,352 - source address DBG 1 - new DBG instruction, see later LDC C,' ' - blank = initialization pattern MFI -30 - move 30 blanks to address 362 MOV 10 - move 10 bytes from 352 to 362

Using the new MFI instruction, assigning shorter strings to longer strings now is possible without problems; see the following example:


program TESTSVAR ( OUTPUT ) ; type CHAR10 = array [ 1 .. 10 ] of CHAR ; CHAR30 = array [ 1 .. 30 ] of CHAR ; CHAR21 = array [ 20 .. 40 ] of CHAR ; var F10 : CHAR10 ; F30 : CHAR30 ; F21 : CHAR21 ; begin (* HAUPTPROGRAMM *) F10 := 'Oppolzer' ; F30 := F10 ; WRITELN ( F30 ) ; F21 := 'Teststring Length 21' ; F30 := F21 ; WRITELN ( F30 ) ; end (* HAUPTPROGRAMM *) .

Warning: this new feature is not yet available for download; it is only present in the working version and only for Windows, at the moment (11.2017).

Back to Compiler main page