A Pliant pointer is not like a C pointer but rather like a C++ reference which you can modify using :> operator.
The following listing:
module "/pliant/language/unsafe.pli" gvar Int i gvar Pointer:Int j gvar Pointer:Int k j :> i j := 2 k :> j k := j
int i ; int *j ; j = &i ; *j = 2 ; k = j ; *k = *j ;
As you see, in Pliant, pointers are automatically dereferenced. When you want to set the pointer, you use the :> operator.So, j :> i should be read: 'j' now points 'i'
Last example:
module "/pliant/language/unsafe.pli" gvar Int i gvar Pointer:Int j gvar (Pointer Pointer:Int) k k :>> j k :> i k := 2
int i ; int *j ; int **k ; k=&j ; *k=&i ; **k=2 ;
module "/pliant/language/unsafe.pli" gvar Int i gvar Address a a := addressof i gvar Pointer:Int j j :> a map Address
function addressof data -> adr arg Universal data ; arg Address adr
returns the address of the data.
method adr map type -> data arg Address adr ; arg_RW type data
The type must be constant (known at compile time).
method base_address translate type count -> translated_address arg address base_address ; arg Type type ; arg Int count ; arg Address translated_address
Computes 'translated_address' by adding 'count' times 'type' size to 'base_address'
Links are just like pointers, but they automatically update the reference count of the pointed object and free the object when its reference count falls to 0.As result, the pointed data must be either a global variable or an object created by new function.Let's take an example:
module "/pliant/language/unsafe.pli" gvar Link:Int i gvar Int g # a global variable i :> new Int i := 2 i :> g
Extra rules about links:
method new type -> data arg Type type ; arg_RW type data
creates a new data (with an header that contains a pointer to the type of the data and a reference count) and returns a pointer to it.
method new type value -> data arg Type type ; arg type value ; arg_RW type data
creates a new data, sets it's value and returns a pointer to it.