Introduction

P is a small garbage collected programming language whose programs run in a virtual machine. I have been inspired by Borland Pascal with Objects version 7.0 manual from 1992 that I have in my bookshelf. When comparing P to the Borland Pascal with Objects, this 0.2.0 version of P still lacks a proper standard library. On the other hand I have added simple copying garbage collector and overloaded constructors that the Borland Pascal does not have. Otherwise P is pretty close to the original Borland Pascal with Objects.

Hello World

Here's a Hello World program written in P:

program Hello;
begin
  Writeln('Hello, world!');
end.

For compiling and running programs we have two commands: compiler pc and executor rp . To compile and run the Hello World, execute the following commands in Windows command prompt:

C:\>cd p-lang\prog

C:\p-lang\prog>pc -v Hello.p
> C:/p-lang/prog/Hello.p
==> C:/p-lang/prog/Hello.pcode

C:\p-lang\prog>rp -v Hello
Running C:/p-lang/prog/Hello.pcode...
Hello, world!
Heap size was 16 MB.
Collected 0 times.

The compiler translated the source code text Hello.p to a Hello.pcode binary file. The .pcode file contains both metadata and virtual machine instructions.

PCode

For inspecting the contents of a .pcode file, P has a third program: pd :

C:\p-lang\prog>pd -v Hello.pcode
> Hello.pcode
==> Hello.pcode.txt

The pd program dumps the contents of the Hello.pcode file to a text file Hello.pcode.txt . The dump contains virtual machine instructions in the code section:

program 'Hello'
global variable map:
uses: 'System'
source file path: C:/work/p-lang/prog/Hello.p
pcode file path: C:/work/p-lang/prog/Hello.pcode
block 'Hello'
procedure '@program'
block '@@program'
level: 0
flags: generated
id: bd5f304a-dcba-b9aa-2ead-bc73939fe2d3
level: 0
block '@@program'
level: 0
frame size: 0
code
0 : receive(0)
1 : push_value('Hello, world!')
2 : call_subroutine(Writeln, d17cbef6-653a-fecf-cce1-3b500ef8185e, 1)
3 : nop
level: 0

Implementation

P has been implemented in C++ using Microsoft Visual Studio 2022.

The syntax diagrams in this documentation have been generated using a P program SyntaxDiagrams.p included in the project. This program and the system library units acted also as tests for the P compiler.