DMeroon, A Distributed Class-based Causally-Coherent Data Model — General documentation - Revision 1.64 Christian Queinnec

To cite this version:

Christian Queinnec. DMeroon, A Distributed Class-based Causally-Coherent Data Model — General documentation - Revision 1.64. [Research Report] lip6.1998.039, LIP6. 1998. ￿hal-02547797￿

HAL Id: hal-02547797 https://hal.archives-ouvertes.fr/hal-02547797 Submitted on 20 Apr 2020

HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non, lished or not. The documents may come from émanant des établissements d’enseignement et de teaching and research institutions in France or recherche français ou étrangers, des laboratoires abroad, or from public or private research centers. publics ou privés.

DMeroon

A Distributed Classbased CausallyCoherent Data Mo del

General do cumentation Revision

Christian Queinnec

Universite Paris Pierre et Marie Curie

LIP place Jussieu Paris Cedex

France Ml ChristianQueinneclip fr

DMeroon provides a data mo del ab ove a coherently distributed shared memory DMeroon allows multiple

users to statically or dynamically create new classes hierarchically organized to dynamically instantiate

these classes and to dynamically and coherently share the resulting instances over a network DMeroon

automatically takes care of representation and alignment marshaling and unmarshaling ob jects migrating

and sharing ob jects lo cal and global garbage collections

This do cument describ es DMeroon its philosophy of design its architecture and principles of implemen

tation and its bindings with various languages It also presents some internal details within DMeroon or

some applications ab ove DMeroon

This document tries to present the overlines of DMeroon in places it describes features which are not

implemented in some other places there are implemented features that are not documented I packed it up

in order for interested people to get an idea and perhaps induce them to pursue my eort or denitively

convince me of its little value I have a lot of lectures to prepare for the fol lowing months and wil l not be

able to devote much time to DMeroon

Contents

Introduction to DMeroon

Ab out this do cument

Ab out DMeroon

Frequently Asked Questions

Acknowledgments

Fundamental data mo del

Types of elds

Access to elds

Distributed asp ects

Clo cks

Sites

Classbased mo del

Main predened classes

Abstract API

Initialization

Class

Fields

Allo cation

Site

Clo ck

Communication

Equality

Ubiquity

DMeroon as a server

Miscellaneous

binding

Functions

Global variables

Contexts

Error co des

Static generation of classes

Tutorial examples

Dynamic creation

Static denition

Recursive class

CONTENTS

Scheme binding

Functions

Variables

Libraries

Tools

DMeroonet

Scheme p eculiarities

Biglo o

DMeroonScript binding

Programs

Constants

Access to eld

Commands

Basic commands

Vocabulary commands

Stack commands

Bo olean commands

Arithmetic commands

Meta commands

Miscellaneous commands

DMeroon API

Debugging command

Use

DMeroonScript API

Explicit evaluation

Development environment

Examples

Icslas binding

App endices

A DMeroon source les

A Structures of les

A The TOP DMeroonc directory

A Rebuilding DMeroon

A Other les

A C

A Biglo o

A Binding DMeroon

A The dmxxxh header

A The dmxxxc le

A The xxxmkf le

A Writing co de for DMeroon

B Ob ject internal representations

B Lo cal ob ject

B Uninitialized

B Lo cal sharable

B Lo cal copyable

B Semiexternalized

B Externalized

CONTENTS

B Remote

B Reexp orted

B Site

B Class

B Miscellaneous

B Prop erties

B Ob ject

B Entry item

B Exit item

C Proto cols

C Existing proto cols

C Adding proto cols

C Some classes

C The DMeroon inner proto col

C Ubiquitous ob jects

C Stackrelated commands

C Useful commands

C Sp ecic commands

C Technical commands

C Ob jectbased proto col

C DMeroon and http

C The http proto col

C Publishing informations

D Driving DMeroon servers

D Measuring the progress of a remote pro cess

D Distributed X cut buer

CONTENTS

List of Figures

DMeroon overview

DMeroon instance example

A remote p ointer

Lo cally cached remote ob ject

Ob ject monitored by a clo ck with an up to date replica

Ob ject monitored by a clo ck with an obsolete replica

A Site displayed in html

A mutable ob ject displayed in html

A Layers and relationship b etween les

A Ob jects in C Biglo o and Icslas

B States of lo cal ob jects

B Lo cal uninitialized ob ject

B Semiexternalized ob ject

B Externalized ob ject

B Exit item with absent class and absent clo ck

B Reexp orted Exit item

LIST OF FIGURES

Chapter

Introduction to DMeroon

DMeroon was conceived with many dierent goals in mind p ortability with resp ect to hardware and

languages expressiveness dynamicity coherency reusability selfdescription etc DMeroon is the data

layer of a distributed language named Icslas which is still under progress Nevertheless DMeroon has

b een carefully designed so it can also b e used indep endently of Icslas for various purp oses

as a classbased system

as a marshaling engine

as a message passing layer

as a distributed shared memory

DMeroon is based on a number of research results and oers unique features

language design Que

DMeroon oers a classbased system with regular or indexed elds without inheritance restriction

Ob jects can b e shared if remotely referenced but still retain their identity

ob jectoriented selfdescription QC Que

Ob jects are describ ed by their classes and classes are ob jects as well Most of the implementation

of DMeroon can b e freely insp ected programmatically The ob ject system is distributed and sup

p orts multiusers working together ie dynamically creating new classes and dynamically exchanging

instances of them

shared data coherency Quea Queb

Mutation of remotely shared mutable ob jects is coherently ie causally propagated to sites caching

copies of these ob jects through a lazy invalidation proto col DMeroon supp orts the notion of remote

p ointer ie a eld of type reference may refer to any kind of DMeroon ob ject indep endently of its

lo cation

marshaling engine Queb

Marshaling ob jects is considered as a compilation pro cess the resulting stream of bytes is then con

sidered as a program which is interpreted by a deserialization interpreter The exchange proto col is

therefore sp ecied as a language and most often many dierent strategies of compilation exist for all

of them the unmarshaling interpreter remains constant

garbage collection design LQP

Remotely shared data are managed with a reference counter Useless ob jects or classes automatically

disapp ear cycles of garbage are also recycled via another GC technique

CHAPTER INTRODUCTION TO DMEROON

DMeroon may b e used for very dierent purp oses see gure as well with various languages for which

a binding exists Scheme Biglo o SchemeC OScheme SCM C Emacs Tcl all under progress

First you may use DMeroon stand alone in a single pro cess ie as a single site just to take b ene

of its library of classes and ob jects You may dene your own classes instantiate them read or mo dify

elds within these ob jects You may also describ e or access C structured values with DMeroon classes

Garbage collection is active if p ossible You may insp ect or mo dify DMeroon ob jects via the HTTP

1

proto col and thus control the parameters of your application in the spirit of Paws You may also

extend the DMeroon server to supp ort additional proto cols

Second you can start multiple sites ie pro cesses on p ossibly dierent machines and let DMeroon

b e the marshalingunmarshaling engine You then copy structured values from site to site Regular

unstructured values such as messages ie sequences of bytes may also b e exchanged if represented by

instances of String

Third your application may b e supp orted by the shared distributed memory provided by DMeroon

you may then use shared ob jects Examples of such applications are the distributed management

of DMeroon sources distributing computations farming up on a synchronizing memory archiving

structured and complex data for a variety of pro cesses

Fourth DMeroon may b e the unifying framework that hosts on a variety of sites a variety of

applications allowing you and your colleagues to co op erate ab ove a coherent memory

other interactive

programc

programc interpreter

lib dmero ona lib dmero ona lib dmero ona

http client

for C for C for Scheme

DMeroon DMeroon DMeroon

private shared shared

memory memory memory

Figure DMeroon overview

Ab out this do cument

This do cument is a potpourri around DMeroon It rst describ es the generic asp ects of DMeroon then

details its current bindings with C and Scheme Additional app endices describ e some ner p oints of the

implementation as students keep asking me

Implementation note Warning This document is under construction as recalled in some

sections I also sometimes comment ner points inside implementation notes such as this one

Ab out DMeroon

DMeroon is freely accessible under Gnu Library General Public License version All remarks bugs

patches extensions stories etc are to b e mailed to

ChristianQueinneclipfr

Online fresh information is available from

1 httpzenoninriafrkoalaphkkwebintrohtml

FREQUENTLY ASKED QUESTIONS

httpwwwspilipfr queinnecWWWDMeroonhtml

Additional questions may b e addressed to

DMeroonspilipfr

To subscrib e to this unmo derated mailing list send a mail to

DMeroonrequestspilipfr

Insults are left to the following mailing list if one cares to create it

DMeroonhaterstoappearsomewhere

Finally an everchanging DMeroon server is sometimes reachable at

httpyoupoulipfr

Frequently Asked Questions

Section under construction

what means DMeroon

The name DMeroon stands for Distributed Meroon where Meroon is the name of an ob ject system

for Scheme Informations on Meroon is available on

httpwwwspilipfr queinnecWWWMeroonhtml

Meroons own FAQ tells us that the name Meroon was the name of my sons teddy b ear

How about PVM

DMeroon is dierent from PVM for at least two reasons DMeroon provides you a distributed shared

memory and structured ob jects with p ointers Conversely PVM oers task control host management whereas

DMeroon only deals with data Due to its youth it is not p orted as PVM is

How about Corba or ILU

DMeroon is dierent from Corba and ILU it do es not provide multiple inheritance of interfaces nor

remote metho d invocation It oers you automatic coherency for shared mutable ob jects source co de and

extensibility due to the selfdescription of the implementation However it might b e interesting to let DMe

roon understands the I IOP proto col Corba oers p ointers to remote interfaces whereas DMeroon oers

real mobile ob jects

How about Java

DMeroon is dierent from Java it oers you indexed elds allowing multiple values to b e packed

together so they are not split apart when marshaled it oers a distributed shared memory and automatic

coherency With Java RMI a remote ob ject is represented by a stub implementing some interface the class

of the lo cal stub and the class of the remote ob ject are not comparable whereas in DMeroon they are

the same Moreover in Java the stub and the server ob ject are comp elled to inherit from sp ecial classes

this is needless in DMeroon DMeroon also oers handling C values unsigned int for instance with C

semantics

Acknowledgments

Jing Wang wrote the rst version of the http proto col part that allows to mo dify mutable elds of ob jects

JeanMichel Ingleb ert contributed with dmClient a to ol to write and debug DMeroonScript programs

CHAPTER INTRODUCTION TO DMEROON

Chapter

Fundamental data mo del

A DMeroon ob ject is an ordered contiguous sequence of elds see gure Fields may b e regular mono

eld or indexed p olyeld A regular eld holds a single value while an indexed eld holds an ordered

sequence of values whose number of elements is determined at instance creation time currently this number

is stored right b efore these values This uniform mo del allows to represent all mundane data structures

1

such as records vectors strings with full inheritance ability

The ob ject shown on gure starts with two regular elds followed by an indexed eld itself followed

by a regular eld As in C a DMeroon reference refers the rst byte of its content DMeroon also stores

a reference to the class of the ob ject as well as a reference to its proxy a DMeroon ob ject containing all

the information needed to manage distribution in a prexed header which itself may b e prexed by the

standard header required by the binding language if any see gure A page

malloc header

andor

type header

class

proxy

DMeroon reference

rst monoeld

second monoeld

size of third polyeld

rst value of third p olyeld

second value of third p olyeld

last value of third p olyeld

fourth monoeld

other mono or poly elds

Figure DMeroon instance example

1

Never dreamt of a colored string That is from an implementation p oint of view a rep etition of characters followed by a

color

CHAPTER FUNDAMENTAL DATA MODEL

Types of elds

All elds have a precise type as shown in table These types have sizes and alignment constraints that

dep end on the site the hardware running DMeroon and on the C used to compile the DMeroon

library The sizes mentioned in the table are the usual ones Every implementation of DMeroon must

implement all these basic types with their asso ciated range but on a particular site some elds may b e

bigger than indicated to implement the correct range of values

Implementation note For any machine I know these sizes are the real sizes

Every DMeroon type has an asso ciated class with a single eld the value eld of that type Hence

nat is asso ciated to class Nat etc These classes are used in the implementation of DMeroon and may

b e used or rened by interested users see table

For every C structure that has an equivalent DMeroon class the layout of the structure and the layout

of the class are the same same order of elds same sizes same alignment constraints The DMeroon

mo del is richer since it allows indexed elds it is also p o orer since C oers b ounded arrays that are currently

not part of the DMeroon mo del

Implementation note C structures are subsumed by DMeroon classes at the exception of

arrays For instance char s is currently not supported in DMeroon you must use instead

an indexed eld or ve contiguous regular elds

Some basic types deserve sp ecial explanation

Signed integer types have a symmetric range to b e free of onecomplement or twocomplement enco d

ings

Implementation note XDR then Corba adhere to twocomplement I may change on

that point

The reference type is used to hold a p ointer to another DMeroon instance The referenced instance

can b e lo cal to the current site or remote without any semantical dierences

Implementation note A reference to a DMeroon instance is the address of the rst

byte of its rst eld This makes easy to al locate C structures with DMeroon al location

functions and to hand le them as C or DMeroon objects For languages in which objects are

described by the address of the rst word of their header for instance pointers have

to be translated back and forth between DMeroon and the binding language See gure A

for some implementation schemes

The can b e used to record any nonDMeroon information that ts in the size of a p ointer

to a lo cal C datum ie a void value Such lo cal information can b e a le descriptor a Scheme

value an EBCDIC character etc You may transmit such a eld without DMeroon blessing that is

DMeroon do es not ensure you anything on the size or on the representation of the transmitted eld

However if you use homogeneous machines you may try

The code type is similar but may hold the address of a C function The same lack of DMeroon

blessing holds of course You may try it if you are sure that your functions are linked with similar

addresses on dierent machines

The netnat types are similar to their nat counterpart except that these natural numbers are

in stored in network order Some data structures generally related to network structures sockaddr

for instance imp ose this enco ding it is therefore useful and less painful to let DMeroon manages

this enco ding for you That is you never have to use netnat numbers only their equivalent nat numbers

TYPES OF FIELDS

index name size meaning

bytes

nought not instantiable

1

nat natural unsigned number from to

2

nat natural unsigned number from to

4

nat natural unsigned number from to

8

nat natural unsigned number from to

reference or p ointer to a DMeroon instance

data or nonDMeroon information the size of a void C variable

code or address of a C function

1 1

int signed small integer from to

2 2

int signed small integer from to

4 4

int signed small integer from to

8 8

int signed small integer from to

char ISO Latin character

2

netnat natural unsigned number from to in network order

4

netnat natural unsigned number from to in network order

unicode not yet implemented

float IEEE oating p oint number with bits

float IEEE oating p oint number with bits

float IEEE oating p oint number with bits

offset internal ly needed by DMeroon

date date following Unix convention

key internal ly needed by DMeroon

classoptions internal ly needed by DMeroon

fieldoptions internal ly needed by DMeroon

portoptions internal ly needed by DMeroon

siteoptions internal ly needed by DMeroon

externaloptions internal ly needed by DMeroon

contextoptions internal ly needed by DMeroon

reserved by DMeroononeone

Table DMeroon primitive types

CHAPTER FUNDAMENTAL DATA MODEL

The types are not necessarily usable everywhere since they often o ccupy eight bytes and not all

hardware are able to add or divide bytes entities It is nevertheless p ossible to migrate ob jects with

such elds from site to site but you may not have in some language binding the p ossibility to manage

ie read or write these bytes entities Nevertheless these types exist and are predened

The float type is not implemented everywhere due to the lack of a common representation It was

initially intended for long double of C but unfortunately their size may b e sparcbsd ieee

bits or sparcsolaris bytes

Implementation note Types are encoded with a single byte This leaves around types

free for future extension If you plan to introduce new statically predened types remember

that you wil l not be able to communicate with servers lacking them However if your addi

tional types are valuable make others share them Future releases of DMeroon wil l probably

use more predened types for internal usage that is why some bytes are reserved

The key is an internal DMeroon type used to name ob jects that are to b e known via the network A

key qualies a single ob ject and is never reused It is dicult to forge meaningful keys ex nihilo this

allows to protect hidden remote ob jects from b eing discovered

Implementation note Currently a key is composed of the IP number of the DMeroon

server where it was al located of the portnumber used by this server of the date of creation

of the value of a bits cyclic counter and nal ly of bits randomly computed I may adopt

the DCE naming scheme some day

Access to elds

Any DMeroon instance can deliver the content of its regular elds Given an additional index i it can also

return the content of the ith value of an indexed eld Of course it is not p ossible to access a eld that

do es not exist in an instance and for indexed elds indexes are checked to b e within the range dened by

the instance Mutable elds can b e altered with the same limitations Indexed elds can return the number

of values they hold on a p erinstance basis

The precise way to access inquire or mo dify a eld in a DMeroon instance dep ends on which binding

language is used with DMeroon see for instance the C binding chapter or the Scheme binding chapter

However access should always b e p erformed via the appropriate functions to ensure the consistency and

the safety of DMeroon space and to give time to DMeroon to serve http requests or to manage ie

garbage collect the memory

A eld is qualied by some options that conditionalize the access see table These options may b e

freely combined By default elds are not mutable not volatile not lo cal and not secret

kind meaning

mutable The eld can b e mo died through the API

volatile The content of the eld may evolve sp ontaneously

lo cal Never marshal the content of this eld its meaning is only lo cal

secret The eld cannot b e read

Table DMeroon eld options

DMeroon prevents the mutation of immutable elds Only mutable elds may b e written By default

elds are immutable

A volatile eld cannot b e cached it must b e read every time it is accessed Even if the user cannot

mo dify it ie the eld is immutable its content may evolve Volatile elds are often used by the DMeroon

implementation to allow the insp ection of immutable but evolving values

DISTRIBUTED ASPECTS

A lo cal eld cannot b e read outside of the current site it only has a lo cal meaning By default elds

are not lo cal Lo cal elds are handy for elds of the data or code type and may also b e used to keep elds

secret

A secret eld cannot b e read at all It is probably not very interesting to b e volatile at the same time

This option is handy for some internal elds reserved to the implementation

A eld of type reference is always restricted to only refer to instances whether direct or indirect of a

given class The ro ot of all classes that is Object allows for all DMeroon ob jects

Distributed asp ects

DMeroon manages the DMeroon space which is the union of all DMeroon ob jects Within a pro cess

the user space is the complement of the DMeroon space values of data and code elds usually refer to the

user space It is p ossible to p erform computations in the user space then to copy results in the DMeroon

space to share them or exchange them with the marshalingunmarshaling capacity of DMeroon

A reference to a DMeroon ob ject from the user space always refers to an instance such as the one

shown on gure This is an invariant maintained by DMeroon the user of the API never sees internal

DMeroon ob jects such as Entry or Exit items

an Entry

Site

another ob ject an ob ject

an Exit

Site

Figure A remote p ointer

The content of a eld of type reference may b e null or not If nonnull then it refers to a DMeroon

ob ject It is p ossible to merge its own DMeroon space with other DMeroon spaces if they are available

via the network When merged referenced ob jects may b elong to one or another site without semantical

dierences users do not need to b e aware of distribution but for sp eed If the referenced ob ject is lo cal the

reference is represented by a regular p ointer if the referenced ob ject is not lo cal then a remote p ointer is

used instead as shown on gure

When a eld of type reference is read the DMeroon ob ject which is referred to is brought lo cally ie

is cached and a reference onto it is returned to the user see gure The cached ob ject is also known

as a replica A coherency proto col is run by DMeroon to ensure the consistency of the cached replica with

resp ect to communications b etween sites Access to DMeroon ob jects should only b e done through the

DMeroon API in order to maintain the consistency This is costly with resp ect to direct access with osets

as in C but allows DMeroon to garbage collect its space maintain consistency serve requests and the like

DMeroon allows you to send references onto ob jects towards remote sites Then all information exchanges

b etween sites if represented by ob jects are noticed by DMeroon so it may ensure coherency

Reading a eld of a cached ob ject may b e ecient under certain circumstances not volatile validly

cached Writing a eld always implies sending a message to the site that owns the original ob ject asking

CHAPTER FUNDAMENTAL DATA MODEL

an Entry

Site

an original ob ject an ob ject

cached ob ject

an Exit

Site

Figure Lo cally cached remote ob ject

that site to p erform the mutation These details are fortunately hidden for the users

Clo cks

A shared mutable ob ject is monitored by a clo ck an instance of the predened class Clock When such an

ob ject is mutated its clo ck is incremented Whenever sites exchange messages they lazily propagate the

clo cks they are aware of ie their clo cks and others

When an ob ject is cached on a site its asso ciated clo ck is also cached Moreover the exit item asso ciated

to the ob ject memorizes the time when the cached ob ject was read For instance on gure the replica

was read at time

Before a replica is read its asso ciated clo ck is checked not to have changed since the replica was fetched

On gure Site is not aware of any change on this clo ck so the replica is not obsolete Had a message

b een sent from Site recently then Site would have advanced the clo ck to thus making obsolete the

replica see gure When the replica is out of date a request for a fresher copy will b e sent this

will authorize Site to advance its cached clo cks with resp ect to Site This is the essence of the lazy

invalidation proto col describ ed in Quea

There is a tradeo b etween the number of clo cks to propagate and the number of ob jects that are

simultaneously invalidated b ecause they are monitored by the same clo ck DMeroon allows you to choose

the right grain you may create clo cks or even sub class the Clock class and asso ciate them to ob jects on

a p erob ject basis

All entry items have a reference counter counting the number of remote p ointers referencing an ob ject

This allows for a simple garbage collector A more elab orated marking GC is run by DMeroon to take care

of useless distributed cycles

Sites

A site corresp onds to a single address space usually a pro cess in Unix parlance Sites may b e connected

to form a bigger DMeroon space

When a DMeroon ob ject is allo cated on a site it is owned by this very site If the ob ject is motile it

may migrate that is b e owned by another site The site that owns an ob ject serializes the mutations that

are applied on this ob ject It is p ossible to know which site owns an ob ject

An ob ject is local to a site if it owned by this site otherwise the ob ject is remote and asso ciated to an

Exit item ie remotely p ointed An ob ject is present if lo cal or cached An ob ject is absent if remote and

SITES

a cached clo ck

a cached mutable ob ject

read at

Site

Site

a Clo ck

a mutable ob ject

Figure Ob ject monitored by a clo ck with an up to date replica

a cached clo ck

a cached mutable ob ject

read at

Site

Site

a Clo ck

a mutable ob ject

Figure Ob ject monitored by a clo ck with an obsolete replica

CHAPTER FUNDAMENTAL DATA MODEL

not cached ie not asso ciated to a replica on the current site A replica is valid or a remote ob ject is valid ly

cached if its asso ciated clo ck is not known to b e out of date as p erceived by the current site see gure

Sites are reied into instances of the immutable Site class These ob jects may b e read to discover the

prop erties of the site A site has an information eld that holds values that are said to b e published ie

readable by any one in p ossession of a reference onto that site ob ject

Classbased mo del

Any DMeroon instance b elongs to a particular class the class of which it is a direct instance Classes are

related by inheritance As Mero onV or Java DMeroon is a single inheritance classbased mo del When

a class A inherits from a class B all the elds of B are also elds of A with the same prop erties Therefore

when a class is dened only the additional elds it introduces are mentioned

DMeroon predenes a hierarchy of classes most of them can b e sub classed at will without restriction

The actual core hierarchy is shown on gure where indentation means sub class of for instance Type is

a direct sub class of Object DMeroonType is a sub class of Type and therefore an indirect sub class of Object

The implementation of DMeroon ensures that the isasubclass check when comparing two classes or the is

aninstance check is always p erformed in constant time Furthermore in the current implementation of DMe

roon all predened classes are statically allo cated and not dynamically created ie they are ubiquitous

Classes may b e customized with some options These are

nonsub classable it is not p ossible to create a sub class of such a class but predened subclasses

may exist

immotile instances of that class cannot b e migrated ie change their owning site they may b e

shared ie remotely p ointed instead

noninstantiable characterizes a class that cannot b e instantiated this is reserved for some internal

classes of DMeroon

mutable instances of such a class have at least one mutable eld This option is deduced from the

options of the elds

volatile instances of such a class have at least one volatile eld This option is deduced from the

options of the elds

copyable instances of such a class are by default copied rather than shared when communicated

from one site to another one

sharable instances of such a class are by default shared rather than copied when communicated

from one site to another one

Main predened classes

Only the core classes are dened here Many more useful classes also exist and will b e describ ed elsewhere

in particular those of the Icslas language

Object Class

This class is the ro ot of the inheritance tree All classes inherit from Object therefore all ob jects are

direct or indirect instances of Object The Object class has no eld The Object class is itself an instance

of Class

CLASSBASED MODEL

Object the root of al l classes

Type

CType types of the C support language

DMeroonType DMeroon portable types

Class

Field

String repetition of char

MutableVector mutable vector of DMeroon references

ImmutableVector immutable vector of DMeroon references

Clock

Hashtable

BoundedStack

ImmutableLink

ImmutablePair immutable dotted pairs a la Lisp

QueueLink

Symbol immutable symbols a la Lisp

Boolean Booleans as in Smal ltalk

True t as in Scheme

False f as in Scheme

ImmutableByteVector

Null nil as in Lisp

Site the class of the current site

Dictionary dictionary node see appendix C

Value Classes for al l DMeroon types as in Java

Number

ExactNumber

SignedNumber

Int

Int

Int

Int

UnsignedNumber Classes for unsigned numbers not as in Java

Nat

Nat

Nat

Nat

InexactNumber

Float

Float

Float not always present

Char

NetNat Nat in networkorder

NetNat Nat in networkorder

Data reference to nonDMeroon values

Code reference to C functions

Reference reference to a DMeroon object

Date portable date

Context used for bindings

Facts asynchronous facts reported by DMeroon

Table Hierarchy of predened classes

CHAPTER FUNDAMENTAL DATA MODEL

Class Class

options a sequence of bits encoded as a classoption

super an indexed sequence of reference to the superclasses

field an indexed sequence of instances of Field

name a repetition of characters

This class describ es the structure of classes All classes are direct or indirect instances of Class partic

ularly Object and Class according to the Ob jVlisp mo del Coi Class inherits from Object Object is

an instance of Class and so is Class itself

The options eld describ es some prop erties of the class such as its immutability or motility etc This eld

is reserved for DMeroons usage An instance of an immotile class cannot migrate from a site to another

one it is nailed down to the site where it was created An immotile instance may b e copied or remotely

referenced hence shared A nonsub classable class cannot b e subclassed An immutable class imp oses its

immutability to all its elds

The indexed super eld refers in order to the sup erclasses Object is the sup erclass of index the last

sup erclass is the class itself

The indexed field eld refers to instances of Field describing the elds of the class

Field Class

options a sequence of bits encoded as a fieldoptions

introducing a reference to the class that introduced the eld

referring a reference to the class the values should be instance of

offset an indexed sequence of offset

name a repetition of characters

This class describ es how to access elds within instances A eld descriptor encapsulates all the infor

mation needed to access or introspect such a eld in an instance of such a class

The options eld describ es some prop erties of the eld such as its immutability etc This eld is reserved

for DMeroons usage

The introducing eld refers to the Class instance that introduced that eld ie the class from which

this eld is inherited

When the eld holds references the referring eld contains the class the referred values should b e

direct or indirect instances of This eld is useless for other DMeroon types

The indexed offset eld a kind of nat contains raw numbers enco ding the type of the value of the

eld the type of the rep etition factor if any and how to access thisthese values

Type Class

index a nat index characterizing this type

alignment a nat number constraining the al location

size a nat size in bytes

repsize a nat size in bytes

name a repetition of characters

This class describ es the implementation of a DMeroon type All DMeroon types are characterized

by an index a small natural number Conversely this index allows to retrieve the asso ciated type The

alignment eld expresses the constraints of the hardware as understo o d by the C compiler to record a

ABSTRACT API

value of that type Values of that type have a length of size bytes p er se and a length of repsize that is

size plus some padding when rep eated as in an array of that type

Two sorts of types exist C types and DMeroon p ortable types they are describ ed by sp ecial sub classes

of Type the CType and DMeroonType classes C types describ e the implementation and are initialized by

the C compiler used to compile DMeroon DMeroon p ortable types have a eld telling which C type is

used to implement them Recipro cally C types have a eld telling which DMeroon type might implement

them C types are only used by the implementation and are not to b e seen by normal users

String Class

character a natindexed repetition of characters

This class describ es immutable strings

Symbol Class

character a natindexed repetition of characters

This class describ es symbols la Lisp also known as unique strings in Java parlance Two dierent symbols

dier at least by a character or the number of characters they have Symbols are immutable

Abstract API

This section summarizes the abstract primitives oered by DMeroon Of course their exact interface

dep ends on the binding language All details are not included here the precise do cumentation should b e

referred to

Primitives are sorted by level on table Level corresp onds to primitives that may run on a single site

level are for simple distributed primitives while level corresp onds to more complex primitives Primitives

of level are generally immediate ie non blo cking while others may require communication with remote

sites and therefore are non immediate

Implementation note Currently level primitives are stil l in a ux

DMeroon functions or variables all have a name starting with the DM prex this prex may b e longer

Due to the binding language dash or underscore may b e additionally used When a call is erroneous the

error is rep orted in a way that dep ends on the binding language Function calls often return some useful

data in a way that also dep ends on the binding language

An immediate primitive is a primitive that answers in a b ounded time Primitives that require commu

nication with other sites may take a long time hence are not immediate It is p ossible with some bindings

to b ound the duration of a call to such a primitive and to return an error when this duration is exhausted

without answer

Initialization

initialize This function is sometimes implic Before using DMeroon you must initialize it with DM

itly called but it is harmless to call it again It returns an ob ject that describ es the current site By

default a DMeroon server is started that listens to a TCP p ort The p ort number is currently de

SERVING PORT environment variable or by default as the value of the ned as the value of the DMEROON

DMEROON FAVORITE PORT cpp variable which is currently DM

define DMDMEROONFAVORITEPORT

CHAPTER FUNDAMENTAL DATA MODEL

Level Functionality

initialize DMeroon library

check whether an instance is an instance of a class

return the direct class of an instance

get the content of a regular eld within an ob ject

get the content of a indexed eld within an ob ject

get the length of a indexed eld within an ob ject

set the content of a regular eld within an ob ject

set the content of a indexed eld within an ob ject

instantiate a class

declare the end of the initialization of an ob ject

create a sub class

get the site that owns the ob ject

set the site that owns the ob ject ie migrate the ob ject

set the clo ck asso ciated to a mutable ob ject

get the clo ck asso ciated to a mutable ob ject

connect the current site to a remote site

send to another site a reference onto an ob ject

receive a reference

check whether two p ointers refer to a same ob ject

Table DMeroon primitives

Class

A DMeroon instance has a single class of which it is a direct instance of This class may b e obtained with

class of Inversely it is p ossible to check with DM is a whether an ob ject is an instance of a given DM

class Once a class is obtained a direct or indirect instance of Class its elds may b e read for instance

to get its sup erclasses Additionally the DM is a subclass predicate allows to compare classes in sub class

relationship

Fields

Fields may b e read or written dep ending on their mutability characteristics DM field value takes an ob ject

a eld descriptor ie one of the elds of its class and returns the content of the given eld If the eld

is indexed then DM indexed field value takes an ob ject a eld descriptor and an index and returns the

content of the indexed eld at that index Indexes are checked to b e valid for the given ob ject It is p ossible

indexed field length given an ob ject and an indexed to discover the length of an indexed eld with DM

eld descriptor Indexes are zerobased

set field value that takes an ob ject a eld descriptor and a A mutable eld may b e written with DM

value A mutable indexed eld may b e written with DM set indexed field value that takes an additional

index For that last primitive pay attention to the order of the arguments an indexed eld is always

followed by an index number in a mutation the new value always app ears last

As shown on gure an indexed eld is represented by a rep etition prexed by its length a la Pascal

strings The enco ding of the length is explicitly chosen when the class is created it may b e any of the

nat types This type as well as the type of the value stored in a eld may b e obtained through the eld

field types function descriptor via the DM

Accessing a p ossibly indexed eld of a lo cal ob ject is simple reading is allowed if the eld is not secret

writing is allowed if the eld is mutable Accessing a p ossibly indexed eld of a remote ob ject is sub ject

to the same restrictions however to read a volatile eld involves sending a request to the owner of the

ob ject but to read a lo cal eld is always lo cal Writing a lo cal eld of a probably remote ob ject is always

a lo cal op eration in the other cases writing a eld of a remote ob ject involves sending a request to p erform

ABSTRACT API

that remote mutation Note that reading immutable non volatile elds of a present ob ject is always a lo cal

therefore fast op eration

Allo cation

allocate function that takes a class and some allo cation parameters An ob ject may b e allo cated with the DM

to sp ecify the length of the indexed elds For example a String is a class with a single indexed eld of type

char the rep etition factor is a nat to allow for large strings of characters The allo cation of a String

requires one nat value to b e able to compute the size of the instance to allo cate Once an instance is

allo cated the sizes of its indexed elds cannot b e mo died

The allo cation primitive is not part stricto sensu of DMeroon but must b e provided by the binding

2

language It is often implemented with help of Hans Bo ehms Garbage Collector A binding with CMM

AF is under study

After an ob ject is allo cated it must b e initialized All its elds are considered as readable or writable

without the constraints required by the elds but only until the ob ject is declared initialized Once declared

initialized ob jects elds acquire their denite characteristics in particular an immutable eld is immutable

set sharable and DM set copyable If an ob ject is declared sharable Two kinds of initializers exist DM

then it may b e shared ie remotely referred to from another site If an ob ject is declared copyable then

if sent to another site it will b e copied and not shared The remote copy will no longer b e linked with the

copied original ob ject no consistency b etween the two ob jects then exists This is a builtin remotecloning

op eration

set initialized which initializes ob jects according to the default b ehavior A third initializer exists DM

of their class copyable or sharable

Once an ob ject is initialized it cannot b e reinitialized dierently DM is initialized allows to check

whether an ob ject is initialized as well as how it was initialized ie sharable or copyable

Even if classes are normal ob jects of class Class they are not created with DM allocate but with

DM create subclass that takes a class and the description of a eld and creates a new sub class containing

that additional eld Once created the class is initialized and ready for use

Site

An ob ject is always managed by the site that owns it by default the site where the ob ject was allo cated

site of takes an ob ject and returns the site that owns it To migrate an ob ject means to change the The DM

site that manages it This may b e p erformed by the DM set site of function that takes an ob ject and a site

This also impacts the asso ciated clo ck since it must always b e a neighbor of the ob ject ie an ob ject owned

by the same site This function b elongs to level and is not useful for lower levels that ignore distribution

A site may merge its DMeroon space with the DMeroon space of another site by op ening a connection

b etween them The DM connect function takes the name of an host machine and a TCP p ort number and

returns a reference onto the remote site ob ject corresp onding to that DMeroon server

Clo ck

A mutable ob ject must b e asso ciated to an instance of Clock if remotely shared Such a clo ck is incremented

any time the ob ject is mutated A clo ck may monitor multiple ob jects When a site sends some information

to another site it also transmit the clo cks it is aware of A cached ob ject may only b e read if the clo ck that

clock of monitors it is not out of date The clo ck asso ciated to an ob ject may b e retrieved with DM

When a clo ck is incremented this invalidates all the cached ob jects asso ciated to that clo ck It is p ossible

to sp ecify which clo ck monitors which ob ject with DM set clock of

Communication

send takes an A site may send a reference onto one of the ob jects it knows of to another remote site DM

ob ject and a site and creates on that site a remote reference onto that ob ject There is no restriction on the

2

httprealitysgicomemployeesbo ehm mtigchtml

CHAPTER FUNDAMENTAL DATA MODEL

ob ject provided it is a DMeroon ob ject

receive The ob ject may then b e ignored accessed A site may receive a reference onto an ob ject with DM

mo died etc The ob ject may convey information representing a message a request etc

These functions b elong to level

If DMeroon is used as a library then you must leave it time to manage its space serve requests p erform

garbage collection ensure consistency etc This dep ends also on whether you use DMeroon in a sequential

or multithreaded framework If you use DMeroon in a sequential framework then the easiest way is to call

DM serve with some duration from time to time Another p ossibility is to call DM receive with a duration

of zero seconds this also allows to empty the queue of already received ob jects even if ignoring them In

a multithreaded framework a thread might b e devoted to DMeroon

Even if you do not plan to receive ob jects you must empty the queue of received ob jects that may contain

instances of the Fact class used to rep ort asynchronous anomalies or other interesting facts such as new sites

requesting a connection

DMeroon requires the presence of an event lo op to pro cess incoming requests The prop erties of this

event lo op dep ends on the precise way DMeroon is b ound to your application

If you have a sequential binding then any time you invoke a function of the DMeroon API then the

DMeroon event lo op will run while waiting for the requests needed to pro cess your call This means

that DMeroon must resp ect a stack discipline if while pro cessing your call DMeroon receives a

request from the network then your call will b e delayed until the network is satised

You may have a binding at that time your application is on top of the DMeroon event

lo op Any time you invoke a function of the DMeroon API the current thread of control technically

a continuation is susp ended control returns to the event lo op until it is appropriate to resume your

call with the answer In this mo de incoming requests are pro cessed within their own coroutine

This is a coroutine mo de where only one thread of control is active when DMeroon runs your

application dont The problem with is that passing control is explicit a malicious thread

may keep control for ever

You may have a multithread binding where DMeroon runs in its own thread as well as incoming

requests A thread that calls the DMeroon API and requires a remote request to b e satised is

susp ended and reied into a DMeroon request ob ject When free the DMeroon thread will handle

it and resume after completion the waiting thread In this binding only one DMeroon thread may

act up on the DMeroon data structures

This binding is still to b e written

The sequential binding is p ortable but less interesting than the coroutine binding which is the preferred

one Note that with these two bindings your application and the DMeroon event lo op have dierent

p ositions

serve or DM receive any time your application waits for some In the sequential binding you call DM

events from the network

In the coroutine binding your application is ab ove the DMeroon event lo op the DM install receiver

API function tells DMeroon which function of your application must b e run any time an ob ject is

received With this binding your application is triggered via a callback function applied on every

received ob ject

Equality

eq predicate compares When ob jects migrate it may b e dicult to know if they are the same or not The DM

two ob jects and return true if they are the same

ABSTRACT API

Ubiquity

Some ob jects are ubiquitous ie lo cal to all sites since they incarnate universal concepts Predened classes

DMeroon types as well as some constants true false are ubiquitous Even if DMeroon types are ubiqui

tous they may have dierent implementation a reference may have a size of or However it is never

p ossible to compare two dierent representations of a same ubiquitous ob ject

DMeroon as a server

A DMeroon server listens for incoming connections and analyzes the rst received bytes to determine the

used proto col

If the request starts with GET that is the letters G E and T then this is supp osed to start an http

request These requests represent a compact enco ding of an DMeroonScript program The DMe

roonScript allows to call nearly all functions of the DMeroon API These

requests may b e conveniently b e emitted from any HTTP client such as Netscap e or IExplorer

If the request starts with DMeroonScript then the next characters represent a multiline DMe

roonScript program to b e interpreted The DMeroonScript programming language is describ ed

in chapter

If the rst letters are DMeroon then the connection is understo o d as a DMeroon connection This is

the binary proto col used to marshal ob jects see C

It is p ossible to dynamically add new proto cols to the list of recognized proto cols see app endix C for

more details

Miscellaneous

Many other functions exist in the implementation read the source co de and win the b est DMeroon

undo cumented feature challenge

CHAPTER FUNDAMENTAL DATA MODEL

Chapter

C binding

This chapter describ es how DMeroon and C cohabits This binding has b een designed to b e systematic

and threadsafe

Functions

they may p erform a lot of checks to The functions of the DMeroon API are all prexed with DMeroon

ensure the validity of their arguments Unsafer functions also exist but are hidden in the implementation

All API functions return a status A status of zero known as DME SUCCESS means that everything went

correctly a nonzero status indicates the kind of problem that o ccurred Other statuses exist describ ed

in the dmerrh le and have a name prexed by DME Error statuses are used to represent synchronous

problems Asynchronous problems for instance receiving unmarshable bytes from a TCP connection

cannot b e rep orted this way to the user they are instead reied into a Fact instance and received as if a

receive these ob jects not to encumber memory Another remote ob ject It is the duty of the user to DM

install receiver a function to pro cess any incoming ob ject metho d is to install with DM

All API functions take as rst argument an instance of the Context class ie the DM Context structure

in C Such an instance contains a number of elds to control DMeroon b ehavior see Section

All DMeroon predened classes without indexed elds have a related C structure whose name is the

name of the class prexed by DM

When an API function has to return a result it must b e given an address where to store this result as a

sideeect this allows to b e allo cationsafe Addresses of results app ear as second and successive arguments

if more than one result is exp ected as in DM field types The content of these addresses is meaningful

only if the API function returns DME SUCCESS It is sometimes p ossible to give a null p ointer instead of a an

address to ignore a result This case is agged with a or NULL comment in the prototypes b elow

As a convention for the prototypes of the DMeroon API a variable whose name is immediately prexed

with a star indicates that it is an out variable that will b e lled during the invocation of the function

class of Without a leading star the variable is an in variable only See for instance the DMeroon

function b elow that takes an ob ject and returns its class

DMErrorCode Level

DMerooninitialize DMContext context

DMSite returnedsite or NULL

Initializes the DMeroon library This call must b e p erformed b efore any other call to the DMeroon

library otherwise undened b ehavior may arise The Site instance describing the current DMeroon space

ie the current site is returned It is useless but safe to call this function more than once it always returns

CHAPTER C BINDING

the current site This is an immediate primitive It is p ossible to give NULL for the returned site if not

interested in it

Implementation note The fol lowing signature might be better since it al lows to return a

fresh Contexts any time it is called This is far easier to get the rst Context this way

DMErrorCode Level

DMerooninitialize DMContext context or NULL

DMContext returnedcontext or NULL

DMSite returnedsite or NULL

DMErrorCode Level

DMeroonclassof DMContext context

DMClass returnedclass

DMObject object

Returns the most sp ecic class of an ob ject that is the class of which this ob ject is a direct instance of

This is an immediate primitive

DMErrorCode Level

DMeroonisa DMContext context

DMcboolean returnedboolean

DMObject object

DMClass class

Checks whether an ob ject is a direct or an indirect instance of a class This is an immediate primitive

The returned b o olean conforms to C practice means false other values mean true

DMErrorCode Level

DMeroonisasubclass DMContext context

DMcboolean returnedboolean

DMClass subclass

DMClass class

Checks whether a class is equal to or a sub class of another one This is an immediate primitive The

returned b o olean conforms to C practice means false other values mean true

FUNCTIONS

DMErrorCode Level

DMeroonfieldvalue DMContext context

t returnedvalue

DMDMeroonType returnedtype or NULL

DMObject object

DMField field

Returns the content of a regular eld of an ob ject This primitive may blo ck for instance when reading

a volatile or mutable eld of a remote ob ject returned value is the address of a cell of type t where t

must b e the type of the read eld This adequation may not b e statically checked in C so this is an unsafe

primitive To help deco ding the returned value this primitive also returns the type of the read eld that is

the DMeroon type corresp onding to t It is p ossible to give NULL for the returned type if not interested in

DMErrorCode Level

DMeroonindexedfieldvalue DMContext context

t returnedvalue

DMDMeroonType returnedtype or NULL

DMObject object

DMField field

DMnat index

Returns the content of the indexth value of an indexed eld from an ob ject This primitive may blo ck

for instance when reading a volatile or mutable eld of a remote ob ject The index is sp ecied as a nat

number even if it corresp onds to a nat nat or nat number Indexes are therefore restricted to b e inferior

32

to Indexes are checked to b e valid within the ob ject returned value is the address of a cell of type

t where t must b e the type of the read eld This adequation may not b e statically checked in C so this

is an unsafe primitive To help deco ding the returned value this primitive also return the type of the read

eld that is the DMeroon type corresp onding to t It is p ossible to give NULL for the returned type if not

interested in

DMErrorCode Level

DMeroonindexedfieldlength DMContext context

t returnedvalue

DMDMeroonType returnedtype or NULL

DMObject object

DMField field

Returns the length of an indexed eld This is an immediate primitive t must b e the type of the rep etition

factor of the indexed eld that is a nat nat nat or nat natural number To help deco ding the returned

value this primitive also return the type of the read eld that is the DMeroon type corresp onding to t It

is p ossible to give NULL for the returned type if not interested in

CHAPTER C BINDING

DMErrorCode Level

DMeroonsetfieldvalue DMContext context

t returnedpreviousvalue or NULL

DMObject object

DMField field

t newvalue

Atomically changes the content of a regular eld of an ob ject and returns the previous content of

that eld This primitive may blo ck for instance when writing a mutable eld of a remote ob ject

returned previous value and new value are the addresses of cells of type t where t must b e the type

of the written eld This adequation may not b e statically checked in C so this is an unsafe primitive When

a reference is written it is checked as far as p ossible to b e the address of a DMeroon ob ject It is p ossible

to give NULL for the returned previous value if not interested in If t is the DMeroon reference type then

the new value must b e an instance of the class sp ecied in the referring eld of field

value and returned previous value addresses must b e dierent The new

DMErrorCode Level

DMeroonsetindexedfieldvalue DMContext context

t returnedpreviousvalue or NULL

DMObject object

DMField field

DMnat index

t newvalue

Atomically changes the content of the indexth value of an indexed eld of an ob ject and returns its

previous value This primitive may blo ck for instance when writing a mutable eld of a remote ob ject

previous value and new value hold the addresses of cells of type t where t must The variables returned

b e the type of the written eld This adequation may not b e statically checked in C so this is an unsafe

primitive When a reference is written it is checked as far as p ossible to b e the address of a DMeroon

ob ject It is p ossible to give NULL for the returned previous value if not interested in If t is the DMeroon

reference type then the new value must b e an instance of the class sp ecied in the referring eld of

field

returned previous value and new value must b e dierent addresses

DMErrorCode Level

DMeroonfieldtypes DMContext context

DMDMeroonType returneditemtype or NULL

DMDMeroonType returnedrepetitiontype or NULL

DMField field

Returns the type of a eld as well as its rep etition type if indexed It is p ossible to give NULL for any of

the two returned types when not interested by the results If a eld is not indexed then DM nought type is

returned for the rep etition type the nought type is characterized by a zero index

FUNCTIONS

DMErrorCode Level

DMeroonallocate DMContext context

DMObject returnedobject

DMClass class

DMnat numberofsizes

DMnat size

Allo cates an instance of a class with the sp ecied sizes for the indexed elds This is an immediate

primitive There must b e as many sizes as there are indexed elds in the class Sizes are given as nat

numbers even if they corresp ond to nat or nat or nat numbers but in that case their value must b e in

the correct range compatible with nat or nat numbers Indexes are therefore restricted to b e inferior to

32

Due to the C limit of arguments in a function call the number of indexed elds is restricted to b e

less than although the exact limit is fuzzy it is probably greater than The content of the ob ject is

initially lled with zero es If the ob ject do es not have any indexed eld then the number of sizes argument

is equal to zero and no other size follow it

DMErrorCode Level

DMeroonsetsharable DMContext context

DMObject object

Declares to DMeroon that an ob ject is completely initialized and may now b e shared over the network

This is an immediate primitive Once an ob ject is initialized it cannot b e reinitialized dierently When

an ob ject is sharable a reference onto it may b e sent to another site see gure When an ob ject is

initialized accessing a eld is constrained by the options of its eld descriptor

DMErrorCode Level

DMeroonsetcopyable DMContext context

DMObject object

Declares to DMeroon that an ob ject is completely initialized and may now b e copied over the network

A copyable ob ject is never remotely shared it is copied instead there is no longer any link b etween the

original and the copy This is an immediate primitive Once an ob ject is initialized it cannot b e reinitialized

dierently When an ob ject is initialized accessing a eld is constrained by the options of its eld descriptor

DMErrorCode Level

DMeroonsetinitialized DMContext context

DMObject object

Declares to DMeroon that an ob ject is completely initialized The ob ject will b e sharable or copyable

dep ending on its class By default classes are created with the sharable option This is an immediate

primitive Once an ob ject is initialized it cannot b e reinitialized dierently When an ob ject is initialized

accessing a eld is constrained by the options of its eld descriptor

CHAPTER C BINDING

DMErrorCode Level

DMeroonisinitialized DMContext context

DMnat returnedresult

DMObject object

Checks whether an ob ject is initialized sharable or copyable or not The returned result conforms

to C practice means false other values mean true However the result is more informative as it tells

whether the ob ject is sharable or copyable Results are then resp ectively DM OBJECT IS SHARABLE or

DM OBJECT IS COPYABLE This is an immediate primitive

DMErrorCode Level

DMerooncreatesubclass DMContext context

DMClass returnedclass

DMClass superclass

char classname

DMclassoptions classoptions

char fieldname

DMfieldoptions fieldoptions

DMDMeroonType repetitiontype

DMDMeroonType itemtype

DMClass referringclass or NULL

This primitive creates a new class with a name and some class options that adds one additional eld to

the sup er class The eld is sp ecied with a name and some eld options One must also sp ecify its type

and whether it is indexed or not If the type is the reference type then the class the values should b e

instance of must b e given This primitive may blo ck

class options type They are summarized in table Some Possible class options b elong to the DM

CLASS IS VOLATILE or DM CLASS IS MUTABLE of these options apply to the class this is the case of DM

other options apply on instances this is the case of DM CLASS IS IMMOTILE and DM CLASS IS COPYABLE

Still other options are only used within DMeroon implementation

name meaning

DM CLASS DEFAULT OPTIONS Instances are motile immutable sharable nonvolatile

DM CLASS IS IMMOTILE The class is immotile Its instances cannot b e migrated

DM CLASS IS COPYABLE The class is copyable Its instances cannot b e shared unless they

are initialized with DM set sharable

DM CLASS IS NOT SUBCLASSABLE The class cannot b e sub classed

DM CLASS IS VOLATILE The class is volatile at least one elds is volatile

DM CLASS IS MUTABLE The class is mutable at least one eld is mutable

DM CLASS IS NOT INSTANTIABLE The class cannot b e instantiated

Table Class options

Possible eld options b elong to the DM field options type They are summarized in table

Implementation note Should oer a new type of eld guarded eld A guarded eld

somewhat extends secret elds To be read a correct password must appear in the current context

The comparison is of course done only on the owning site Such elds are like portals Should

FUNCTIONS

name meaning

DM FIELD DEFAULT OPTIONS The eld is immutable non volatile non lo cal and non secret

DM FIELD IS MUTABLE The eld is mutable the user may mo dify it

DM FIELD IS VOLATILE The eld is volatile its value may evolve sp ontaneously

DM FIELD IS LOCAL The eld is lo cal its content is never marshaled

DM FIELD IS SECRET The eld is secret its content cannot b e read

Table Field options

think to how to have more than one password in the context The context must also be passed

from site to site when emitting requests

FIELD IS RESIZABLE option This complicates the coherency pro I also consider adding the DM

tocol but makes users life far easier Of course a resizable eld should be mutable

The previous primitive may only dene additional elds one by one this is needed to keep the prototype

of the C function static but this increases considerably the depth of the tree of classes Thats why there is

another primitive to create classes

DMErrorCode Level

DMeroonsmashclass DMContext context

DMClass returnedclass

DMClass class

char classname

DMclassoptions classoptions

DMnat level

This primitive returns a new class with a name and some class options This new class has exactly the

same elds the given class has but only a shortened sequence of sup erclasses ie level sup erclasses less This

primitive may blo ck This primitive is used with the previous one to create a direct sub class with multiple

elds

For instance to create a direct sub class of A with two additional elds say x and y you rst create B as

A x then C as B y C has the required elds but has as sup erclasses A B whereas only A is wanted

To remove the B sup erclass we smash one level of sup erclasses from C and obtain D as A x y The x

and y elds are assumed to have b een introduced by D

DMErrorCode Level

DMeroonsiteof DMContext context

DMSite returnedsite

DMObject object

Returns the site that owns the ob ject This primitive may blo ck The current site may b e obtained with

DM initialize Ubiquitous ob jects always have the current site as site

CHAPTER C BINDING

DMErrorCode Level NOT YET IMPLEMENTED

DMeroonsetsiteof DMContext context

DMSite returnedprevioussite

DMObject object

DMSite newsite

Changes the site that owns an ob ject and returns the previous owner this is also called migration

The ob ject must b e motile otherwise its owner cannot b e altered and the ob ject cannot move out of the

site where it had b een created this do es not prevent the ob ject to b e copied or shared that is remotely

referenced This primitive may blo ck This primitive has an impact on the monitoring clo ck if any

DMErrorCode Level

DMeroonclockof DMContext context

DMClock returnedclock

DMObject object

Returns the instance of Clock that monitors a mutable ob ject This is an immediate primitive If the

ob ject is immutable or not initialized or not monitored then DM NULL is returned instead When creating

a remote reference onto a mutable ob ject which is not monitored the general clo ck of the current site is

assumed to monitor it by default

DMErrorCode Level NOT FULLY IMPLEMENTED

DMeroonsetclockof DMContext context

DMClock returnedpreviousclock

DMObject object

DMClock clock

Sets or changes the clo ck monitoring a mutable ob ject and returns the previous clo ck if there was one or

NULL The ob ject may b e not initialized The new clo ck must b e a neighbor of the ob ject that is owned DM

by the same site This primitive may blo ck

DMErrorCode Level

DMeroonconnect DMContext context

DMSite returnedsite

char hostname

DMnat portnumber

char passwd

Connects the current site to the given remote site This primitive may blo ck It returns a reference onto

the remote site ob ject The hostname may b e the humanreadable name of a machine or an IP number in

dot notation The p ort number must b e a regular natural number do not sp ecify it in network order dont

care if you do not know what is network order just give a number

Implementation note Should probably think again to this password stu Would be better to

use SSL to protect communications

FUNCTIONS

DMErrorCode Level

DMeroonsend DMContext context

DMObject object

DMSite site

Sends the reference onto an ob ject to a site This primitive may blo ck

Implementation note The reference is immediately marshaled in an OutBuffer that wil l be

ushed when the Connection wil l al low it The reference wil l be unmarshaled in a queue of arrived

send there is no guarantee that the reference is objects Therefore when returning from DMeroon

obtained by the intended site

DMErrorCode Level

DMeroonreceive DMContext context

DMObject returnedobject

DMnat duration

Receives an ob ject This primitive blo cks at most duration seconds If no ob ject is received during

TIMEOUT error co de DMeroon signals asynchronous errors by reify this time then it returns the DME

ing them into instances of Fact These Facts may b e normally received This primitive is exclusive of

install receiver DMeroon

DMErrorCode Level

DMerooninstallreceiver DMContext context

void handlerDMContext DMObject

This primitive is exclusive of DMeroon receive The DMeroon install receiver function tells DMe

roon to invoke a given function on every incoming ob ject The context received by the handler function

is the one given to DMeroon install receiver By default the receiver function accumulates incoming

receive ob jects in a eld of the current site from which they may b e extracted using DMeroon

DMErrorCode Level

DMeroonserve DMContext context

DMnat duration

This primitive yields control to DMeroon for at least duration seconds Zero seconds is a p ossible

duration in which case p ending requests are handled if already present This allows DMeroon to handle

incoming requests and manage its lo cal space If a receiver function is installed then any incoming ob ject will

receive these ob jects b e automatically submitted to that receiver function otherwise you must DMeroon

serve explicitly after returning from DMeroon

Implementation note As a kind of answer to the need for interfaces I consider adding

virtual elds

CHAPTER C BINDING

VirtualField Class

name a rep etition of characters

A virtual eld al lows to gather instances of Field or VirtualField in order to provide an unied access

to many unrelated instances of unrelated classes For instance I imagine the name virtual eld that al lows

access the name eld of Class Field Site Type etc To get the name of instances of any of these classes

field value function with the virtual eld instead of the appropriate you may just use the regular DMeroon

instance of Field The appropriate eld wil l be automatically chosen in the set of elds contained in the

virtual eld Virtual elds are similar to generic functions la CLOS note I wil l probably introduce the

discrimination mechanism directly so it can be used in other places for instance to implement generic

functions

VirtualField instances are immutable They have a name for introspection They may be extended to

extend virtual field function incorporate new elds with the DMeroon

Global variables

In order to instrosp ect DMeroon ob jects you need at hand the predened classes their asso ciated elds

as well as the DMeroon p ortable types They are all accessible via sp ecialized macros available from

the dmeroonh header le The case is signicant Classes have a capitalized name Fields are written in

lowercase and comp onents are separated with underscores

The les that are mentioned b elow are relative to the TOP directory where the source les are More on

these les in app endix A

DMReferenceToClassname Level

This macro takes the name of a class and returns a DMeroon reference onto a predened Class the

Class type for C Most predened class names app ear in table however they all returned value has DM

app ear in the TOP DMerooncdmstructdm le

DMReferenceToFieldOfClasseldname classname Level

This macro takes the name of a eld and the name of a class and returns a DMeroon reference onto a

predened instance of Field the returned value has DM Field type for C Some elds were mentioned in

section otherwise they all app ear in the TOP DMerooncdmstructdm le

DMReferenceToDMeroonTypename Level

This macro takes the name of a DMeroon p ortable type and returns a DMeroon reference onto a

DMeroonType type for C DMeroon types predened instance of DMeroonType the returned value has DM

are listed in table

CONTEXTS

Contexts

Section under construction

Contexts control many asp ects of DMeroon b ehavior Where alternate b ehaviors are p ossible they may

b e sp ecied by the user by toggling some options of the context When calling the DMeroon API a context

should b e given if the user has p eculiar needs If no context is given a default one is cloned after the default

context held in a eld of the current site Binding languages may customize this default context

Contexts are threaded throughout DMeroon innards there is nearly always a current context every

where The context contains options that may b e trigger to toggle various b ehaviors Whenever an exception

o ccurs reied by an error co de the context provides a handler that will b e invoked to manage this exception

The handler may b e customized to take b enet of the supp ort language

A context is an instance of class Context which contains the following elds

Context Class

handler a C function to hand le exceptions

options a sequence of bits encoded as a contextoptions

errcode the last DMeroon error code

file the name of the le of the last error a C string

line the line number within that le

errnumber the last errno code not portable

previous previous context for debug purpose

continuation where to go in case of error

errstream where to report errors

These elds are lo cal and volatile They are mainly used by the implementation to rep ort errors These

elds are not reset when a DMeroon API function is called The errstream eld contains the p ort where

warnings or errors are rep orted the exact meaning of the p ort dep ends on the binding language For C and

Unx stdout and stderr are legal values Scheme p orts are also legal for Biglo o

The rst eld designates the function to handle the exception This function must have the following

prototype

void handlerDMContext context

DMErrorCode errcode

char FILE

unsigned long LINE

The third and fourth arguments show the birth place of the exception The second argument is the error

co de see section later The rst argument is the current context where additional information may b e

found such as the value of errno set by various system calls By default this function is the DM abort

function that noties the problem then escap e to a safer place as indicated in the continuation eld a

jmpbuf for C a real continuation for Scheme

The following options are legal

CONTEXT CHECK DMEROON Forces DMeroon to check every ob ject received as argu DM

ment to b e a DMeroon ob ject

CONTEXT CHECK CLASS Forces DMeroon to check every ob ject received as argu DM

ment to b e an instance of the appropriate class

DM DONT INITIALIZE When DMeroon allo cates an ob ject this ob ject is by de

fault initialized When set DMeroon leaves them unini

tialized so it is up to the user to make them sharable or copyable

CHAPTER C BINDING

There are other hidden options that make it is p ossible in case of anomalies to force DMeroon to

longjmp to a given p osition or to call an internal debugger

Error co des

Section under construction

Hundreds of error co des exist They are detailed in the TOP DMerooncdmerrh le

Static generation of classes

If you consider dening classes and writing C co de around these classes for instance to contribute new

co de to DMeroon you may want to use static classes and their asso ciated C structs to avoid creating

these classes dynamically This is contrary to the spirit of DMeroon but you may require these classes to

b e immutable volatile lo cal and immotile so you can safely hack them on the current site There exists a

compiler that takes the denition of these classes and pro duces the appropriate C les

The current compiler is written in Scheme its name is dmch which is the name of a shell script from

TOP DMeroonCommands that must b e run in the TARGET directory the directory were all les are com

piled see again app endix A This compiler is used by DMeroon itself for its own b o otstrap

dmch le otherles Command

The rst le contains the classes to b e compiled These classes may inherit from other classes which

are not to b e compiled but which must b e known at compilationtime the DMeroon classes for instance

which are dened in the TOP DMerooncdmstructdm le see app endix A These classes should app ear

in the other les mentioned in the command line

The compiler pro duces two les a lec and a leh dening the DMeroon representation of the desired

classes The leh le contains the equivalent C structs and can b e included in your C co de The C le

must b e compiled and linked to your co de it only contains static data and no co de at all You may refer to

these classes and their elds with the macros of section

Classes are dened as in MeroonV that is as Sexpressions

defineclass classname superclassname Scheme macro

eldname eldoptions

classoptions

Classes are named shortly ie as Object QueueLink etc DMeroon types are also named shortly ie

as nat char etc All elds must have a name and b e qualied by some options as describ ed in table

The class itself may b e qualied by some options as describ ed in table

The compiler will warn you if it cannot generate a C struct that emulates a DMeroon class This may

b e the case if you have a class with elds following an indexed eld

Tutorial examples

Section under construction

TUTORIAL EXAMPLES

option meaning

type DMeroonType This option is mandatory The type of the eld must

b e one of the DMeroon types of gure

indexingtype DMeroonType By default a eld is not indexed Mentioning

indexingtype requires to sp ecify a type among

nat nat nat and nat

refer classname This option is only meaningful for the reference

type It sp ecies the class of referred ob jects De

fault is refer Object

mutable The eld is mutable No option means that the eld

is immutable

local The eld is lo cal

volatile The eld is volatile

secret The eld cannot b e read

Table Field options

option meaning

immotile By default classes are motile This option prevents

instances of that class to migrate

mutable At least one eld is mutable This option is auto

matically set

volatile at least one eld is volatile This option is automat

ically set

copyable instances of this class are by default copied rather

than shared

uninstantiable this class cannot b e instantiated

unsubclassable this class cannot b e sub classed

Table Class options

CHAPTER C BINDING

Dynamic creation

Here is how you may dene the class Point We extend Object with the two elds x and y then we smash

the resulting class o a level To lessen the size of the example and although this is highly incorrect error

co des are not checked

DMClass pointclass px py

voidDMerooncreatesubclassctx px DMReferenceToClassObject

no name DMCLASSDEFAULTOPTIONS

x DMFIELDISMUTABLE

DMReferenceToDMeroonTypenought

DMReferenceToDMeroonTypeint

DMNULL

voidDMerooncreatesubclassctx py px

no name DMCLASSDEFAULTOPTIONS

y DMFIELDISMUTABLE

DMReferenceToDMeroonTypenought

DMReferenceToDMeroonTypeint

DMNULL

voidDMeroonsmashclassctx pointclass py Point

DMCLASSDEFAULTOPTIONS

class variable Its rst eld may b e obtained as follows Now the Point class is the value of the point

and similarly for the second eld

DMField pointxfield

voidDMeroonindexedfieldvaluectx pointxfield DMNULL

pointclass

DMReferenceToFieldOfClassfield Class

Once the class is created an instance may b e created lled and initialized like that

DMObject pt

DMint ix

void DMeroonallocatectx pt pointclass

void DMeroonsetfieldvaluectx NULL pt pointxfield ix

void DMeroonsetinitializedctx pt

Static denition

This is far more simple and may even b e made inline with DMeroon b ound with Scheme First create a

le containing the denition of the Point class

This is le Pointdm

defineclass Point Object

x type int mutable

y type int mutable

Second compile this le with the dmch compiler The command is it is not necessary to mention

TOP DMerooncdmstructdm since Point only inherits from the empty Object class

dmch Pointdm

This compilation pro duces the Pointh and Pointc les You then have to compile them with your

favorite C compiler and to link the resulting Pointo le to your application You may take advantage of

this class in your other les and refer to the class or its elds writing the C type of these constructions is

given in a prexed comment

include Pointh Dont forget this inclusion

DMClass DMReferenceToClassPoint

TUTORIAL EXAMPLES

DMField DMReferenceToFieldOfClassx Point

DMField DMReferenceToFieldOfClassy Point

Recursive class

We now want to create a sub class of Point say LinkedPoint with an additional eld which is a reference

onto an instance of LinkedPoint

Section under construction

CHAPTER C BINDING

Chapter

Scheme binding

This chapter describ es how DMeroon and Scheme cohabit This binding has b een designed to b e Scheme

friendly errors are rep orted via exceptions when the particular Scheme dialect allows it results are returned

by function calls This is a far more natural and userfriendly interface compared to the C binding

Implementation note This binding worked with Bigloo It looks like working with a

prealpha release of Bigloo d It does not work with the current distribution of Bigloo

When accessing ob jects DMeroon oers an interface not to o dissimilar to Meroon Que

All API names to b e used from Scheme are prexed with DM They are implemented by global variables

or C functions prexed with DMscm and dened in the TOP DMerooncdmscmc le They use a set of

macros to convert C values to Scheme values back and forth This set of macros resp ect the usual conventions

of Scheme implementations for value representation Technically this layer uses the C binding layer It has

b een used to bind DMeroon with Biglo o OScheme and PicoLisp Scheme values are automatically co erced

into DMeroon values back and forth according to table Range checks are also p erformed

Scheme type DMeroon type

integer nat nat nat nat int int int int netnat netnat

oat float float float

DMeroon ob ject reference

value data

character char

Table SchemeDMeroon co ercions

Here are the conventions that are used b elow A capitalized name such as Object or Class means a value

that is an instance of the given class The word value means any Scheme value whereas boolean means only

t or f Natural numbers ie p ositive integers are represented by words such as length or index These

words are sometimes prexed by new or old to disambiguate some of their o ccurrences Scheme strings are

enclosed within double quotes with a description of their content

Functions

DMinitialize Site Level

CHAPTER SCHEME BINDING

This primitive returns the current site this ob ject is also the value of the DMsite variable The

DMeroon library is already initialized by the implementation This primitive is immediate

DMisobject value boolean Level

Checks whether a Scheme value is a DMeroon ob ject or not This is an immediate primitive

DMclassof Object Class Level

Returns the most sp ecic class of an ob ject that is the class of which this ob ject is a direct instance of

This is an immediate primitive

DMisa Object Class boolean Level

Checks whether an ob ject is an instance of a class This is an immediate primitive

DMisasubclass Class Class boolean Level

Checks whether the rst argument is equal to or a sub class of the second argument This is an immediate

primitive

DMfieldvalue Object Field value Level

Returns the content of a regular eld of an ob ject This primitive may blo ck for instance when reading

a volatile or mutable eld of a remote ob ject The value is automatically co erced into a Scheme value

according to table

DMindexedfieldvalue Object Field index value Level

Returns the content of the indexth value of an indexed eld of an ob ject This primitive may blo ck for

instance when reading a volatile or mutable eld of a remote ob ject The value is automatically co erced

into a Scheme value if p ossible

DMindexedfieldlength Object Field length Level

FUNCTIONS

Returns the length of an indexed eld This is an immediate primitive

DMsetfieldvalue Object Field newvalue oldvalue Level

Atomically changes the content of a regular eld of an ob ject and returns the previous content of that

eld Values are co erced back and forth b etween DMeroon and Scheme according to table This

primitive may blo ck for instance when writing a mutable eld of a remote ob ject When a reference is

written it is checked as far as it is p ossible to b e the address of a DMeroon ob ject of an appropriate

class

DMsetindexedfieldvalue Object Field index newvalue oldvalue Level

Atomically changes the content of the indexth value of an indexed eld of an ob ject and returns its

previous value Values are co erced back and forth b etween DMeroon and Scheme according to table

This primitive may blo ck for instance when writing a mutable eld of a remote ob ject When a reference

is written it is checked as far as it is p ossible to b e the address of a DMeroon ob ject of an appropriate

class

Pay attention to the order of the arguments The index always follow the eld since it is an indexed

eld and the value is always given last

DMfielditemtype Field DMeroonType Level

Returns the type of a value stored in a Field whether indexed or not This is an immediate primitive

DMfieldrepetitiontype Field DMeroonType Level

Returns the type of the rep etition factor of a Field If the Field is not indexed then DMnoughttype is

returned instead This is an immediate primitive

DMallocate Class sizes Object Level

Allo cates an instance of a class with the sp ecied sizes for the indexed elds This is an immediate

primitive There must b e as many sizes as there are indexed elds in the class The content of the ob ject is

initialized with zero es

DMsetsharable Object the Object itself Level

CHAPTER SCHEME BINDING

Declares to DMeroon that an ob ject is completely initialized and may b e shared over the network This

is an immediate primitive

DMsetcopyable Object the Object itself Level

Declares to DMeroon that an ob ject is completely initialized and may b e copied over the network This

is an immediate primitive

DMsetinitialized Object the Object itself Level

Declares to DMeroon that an ob ject is completely initialized It will b e shared or copied dep ending on

its class This is an immediate primitive

DMisinitialized Object boolean Level

Returns true or false whether the ob ject is initialized sharable or copyable or not In fact the result

when true is more informative is returned when the ob ject is sharable while is returned if the ob ject is

copyable Once initialized an ob ject cannot b e reinitialized dierently

DMcreatesubclass Class class name classoptions Level

eld name eldoptions

DMeroonType DMeroonType Class Class

This primitive creates a new class with a name and some class options The newly dened class adds one

additional eld to its sup er class The eld is sp ecied with a name and some eld options One should also

sp ecify its type and whether it is indexed or not If the type of the eld is the DMeroon reference type

then the nal argument a class sp ecies the class the values must b e instance of This primitive may blo ck

Classoptions are represented by integers with the C enco ding They are summarized on table Add

these values to sp ecify more than one

co de C name meaning

DM CLASS DEFAULT OPTIONS Instances are motile immutable sharable non

volatile

DM CLASS IS MUTABLE The class is mutable all elds are mutable

DM CLASS IS IMMOTILE The class is immotile Its instances cannot b e mi

grated

DM CLASS IS VOLATILE The class is volatile all elds are volatile

DM CLASS IS NOT SUBCLASSABLE The class cannot b e sub classed

DM CLASS IS COPYABLE The class is copyable Its instances cannot b e shared

set sharable unless initialized with DM

DM CLASS IS NOT INSTANTIABLE The class cannot b e instantiated

Table Class options

FUNCTIONS

Fieldoptions are similarly represented as shown on table Add these values to sp ecify more than one

co de C name meaning

DM FIELD DEFAULT OPTIONS The eld is immutable non volatile and non lo cal

DM FIELD IS MUTABLE The eld is mutable

DM FIELD IS VOLATILE The eld is volatile

DM FIELD IS LOCAL The eld is lo cal

DM FIELD IS SECRET The eld is secret

Table Field options

DMsmashclass Class class name classoptions level Class Level

This primitive returns a new class with a name and some class options This new class has elds similar

to the given class but it has level sup erclasses less This primitive may blo ck This primitive is used with the

previous one to allow to create a direct sub class with multiple elds However classes may b e more easily

created with the DMdefineclass macro see Section

DMsiteof Object Site Level

Returns the site that owns the ob ject This is an immediate primitive

DMsetsiteof Object newSite oldSite Level NOT YET IMPLEMENTED

Changes the site that owns an ob ject and returns the previous owner this is also called migration The

ob ject must b e motile otherwise its owner cannot b e altered and the ob ject cannot move from the site where

it had b een created this do es not prevent the ob ject to b e copied or shared that is remotely referenced

This primitive may blo ck This primitive impacts the monitoring clo ck if any

DMclockof Object f or Clock Level

Returns the clo ck monitoring a mutable ob ject This is an immediate primitive If the ob ject is immutable

or not monitored by a clo ck then f is returned instead

DMsetclockof Object newClock oldClock Level NOT YET IMPLEMENTED

Changes the clo ck asso ciated to a mutable ob ject and returns the previous clo ck The new clo ck must

b e a neighbor of the ob ject that is owned by the same site This primitive may blo ck

CHAPTER SCHEME BINDING

DMconnect host name or IP number portnumber password Site Level

Connects the current DMeroon space with a remote one The remote DMeroon space is sp ecied by

an hostname and a p ort number The hostname may also b e an IP number written in dot notation

DMsend Object Site the Object itself Level

Sends a reference onto an ob ject to a site This primitive may blo ck

DMreceive duration f or an Object Level

Receives an ob ject This primitive blo cks at most duration seconds If no ob ject is received then it

returns false This function may only b e used while the DMhandlerobject variable is false

DMhandlerobject Object f Level

If this variable is false ie f then incoming ob jects are accumulated then received using DMreceive

If this variable is not false then its value must b e a unary function that will b e applied on every incoming

ob ject In this case one must not call DMreceive

DMserve duration bolean Level

This primitive yields control to DMeroon for at least duration seconds Zero seconds is a p ossible

duration in which case p ending requests are handled if already present This allows DMeroon to handle

incoming requests and manage its lo cal space

Variables

The current site is the value of the DMsite variable

A number of global variables allow to access predened classes Their name start with DM and end with

class These are for instance DMObjectclass DMClassclass DMFieldclass DMTypeclass

DMStringclass etc

To allow an easy access to instances of predened classes elds of predened classes are also predened

Their name b egin with DM the name of the introducing class a dash the name of the eld and is followed by

field These are for instance DMClassnamefield DMClasssuperfield DMClassfieldfield

etc

DMero on types are also dened under a name ending with type These are for instance DMnou

ghttype DMnattype DMnattype DMnattype etc

LIBRARIES

Libraries

The Scheme binding denes additional useful functions These les may b e dynamically loaded or compiled

and linked

Tools

Some useful functions are dened in the TOP DMeroondmlibscm le Among them is an iterator on ob jects

DM iterate a co ercer into Scheme strings a function to display details of DMeroon ob jects functions to

convert Scheme values into DMeroon ob jects back and forth etc

DMiterate Object byitem bylength byindexeditem unspecied Scheme function

byitem Object Field DMeroonType unspecied

bylength Object Field DMeroonType DMeroonType unspecied

byindexeditem Object Field DMeroonType index unspecied

Iterate sequentially on all the nonsecret values contained in an ob ject but the secret ones and apply

appropriate functions on these values The byitem function is applied on every regular nonsecret eld the

bylength function is applied on every nonsecret indexed eld the byindexeditem function is applied on

every value of every nonsecret indexed eld

DMstring Object Field String Scheme function

This function takes an instance of the String class and co erces it into a Scheme string Used with two

arguments an ob ject and an additional instance of the Field class corresp onding to a rep etition of char

it co erces the eld into a Scheme string For example obtaining the name of the current site may b e written

as

DMstring DMsite DMSitenamefield

Implementation note A common error is to confuse Scheme and DMeroon values espe

cial ly strings and instances of String Use the DMstring or DMsexpr functions

DMdescribe Object outputport unspecied Scheme function

This function prints a detailed description of an ob ject onto a Scheme output p ort by default onto the

current output p ort Only the rst level of the ob ject is printed use the next function to recursively display

an ob ject This function is implemented with DMiterate

DMdescribeall Object outputport unspecied Scheme function

CHAPTER SCHEME BINDING

This function prints a detailed description of an ob ject onto a Scheme output p ort by default onto

the current output p ort it also recursively prints the detailed description of referenced ob jects Cycles of

ob jects are handled This function is implemented with DMiterate

DMsexpr value hand ler Scheme function

This function converts a Scheme value into a DMeroon ob ject The empty list b o oleans symbols

characters vectors pairs strings integers and oats are converted Other types of values pro cedures for

instance are given to the hand ler their translation is left to the denition of the handler The default

handler raises an error Sharing is not resp ected by this simpleminded converter but DMeroon ob jects are

left as they are

DMsexpr value hand ler Scheme function

This function converts a DMeroon ob ject into a Scheme value The empty list b o oleans symbols

characters vectors pairs numbers and strings are converted If a DMeroon ob ject is not converted then

it is given to the hand ler which by default raises an error Sharing is not resp ected by this simpleminded

converter

DMpublish Object name unspecied Scheme function

This function publishes a DMeroon ob ject ie incorp orates it in an instance of the Dictionary class in

the ospring of the site ob ject more precisely via the information eld of the current site The pathname

leading to this ob ject is indicated in the following arguments of the DMpublish function By default every

value published by the user is in the user dictionary

Published ob jects can b e insp ected with an URL formed after their pathname

DMretrieve name Object or t Scheme function

This function retrieves the DMeroon ob ject that is published under the given pathname If that ob ject

do es not exist then f is returned instead

To store my rst name I can say

DMpublish DMstring Queinnec name first

It can now b e retrieved with

DMretrieve name first

DMeroonet

The TOP DMeroondmeroonetscm le denes a light ob ject system ab ove DMeroon in the spirit of Mer

oonV

The DMeroonet ob ject system is very simple to use only three macros are dened one to dene classes

this macro is almost similar to the defineclass macro describ ed in Section DMeroonet provides

distributed generic functions ie generic functions whose metho ds may b e lo cated on dierent sites Quea

LIBRARIES

DMdefineclass classname superclass Scheme macro

eldname eldoptions

classoptions

This macro denes a class with a name a symbol a sup erclass an evaluated expression that must

yield a class some elds and p ossibly some class options Class options are describ ed in table A eld

starts with a name a symbol followed by eld options as describ ed in table

For example here is the denition of the Point class note the dierence with the denition of Section

This is le Pointdm

DMdefineclass Point DMObjectclass

x type int mutable

y type int mutable

DMgeneric name variablesspecication Scheme macro

default body

This macro denes an anonymous generic function The variablesspecication sp ecies the variables

of the function as well as which variables are discriminating A discriminating variable app ears b etween

parentheses The values of the discriminating variables allow to choose the appropriate metho d By default

the default b ehavior of a generic function is sp ecied by the default body In particular if applied on Scheme

values rather than DMeroon values the default b o dy is applied The generic function itself is a DMeroon

ob ject value of the name the default b o dy may b e recursive and use this anonymous generic function with

the name variable

DMmethod name variablesspecication Scheme macro

body

This macro denes a metho d for a generic function The generic function may b e referred to with the

name variable The variablesspecication sp ecies the variables of the function as well as which variables

are discriminating Of course this must b e congruent with the generic functions to which this metho d

will b e added A discriminating variable app ears b etween parentheses accompanied by an expression whose

value is the class on which the metho d will b e triggered

DMaddmethods genericfunction method Scheme function

This function allows to add multiple metho ds to a generic function It returns a new generic function

similar to the previous one except that it understands new b ehaviors

CHAPTER SCHEME BINDING

DMinvoke genericfunction value Scheme function

This function invokes a generic function on some arguments The arguments that corresp ond to discrim

inating variables allow to choose the appropriate metho d which is then applied on these arguments

callnextmethod Method macro

This macro can only app ear in a method denition It allows to call the sup er metho d on the same

arguments

callformermethod value Method macro

This macro can only app ear in a method denition It allows to refer to the metho d that would have

b een triggered in the generic function that was enriched by DMaddmethods

Scheme p eculiarities

The ab ove do cumentation describ es the general binding of DMeroon with a generic Scheme implementation

Often it is p ossible to bind it b etter This section describ es these additions

Biglo o

The binding of DMeroon with Biglo o brings some additional features

the display function is extended to recognize DMeroon ob jects They are printed as

DMeroonreference

where reference is a DMeroon reference and not a Biglo o address

if Biglo o waits when reading a le or the input terminal then the interpreter will take advantage of

that situation to serve incoming DMeroon requests DMeroon uses Biglo os continuations to create

or susp end or resume coroutines With DMhandleobject any incoming ob ject is pro cessed in its

own coroutine

a new proto col is recognized the SchemeScript proto col which allows to receive Sexpressions to

evaluate via the DMeroon server These Sexpressions are evaluated in the global environment of the

interpreter The displayed result is sent back to the client and the connection is closed A SchemeScript

message ends with a sequence of four characters which are the NUL NUL CR and LF characters in

that order

To use that proto col you may use the schemescript command dened in the TOP DMeroonCom

mandsschemescriptprl le

schemescriptprl hostport le Command

SCHEME PECULIARITIES

This command sends the content of the given le or the standard input if absent to the DMeroon

server sp ecied by hostport It prints the returned result but do es not rep ort errors they are rep orted via

the standard error output of Biglo o

CHAPTER SCHEME BINDING

Chapter

DMeroonScript binding

This chapter describ es the DMeroonScript language and its binding with DMeroon This language had

b een dened to test the DMeroon API and to write simple URLs to access DMeroon ob jects it then

evolved into a sp ecic language DMeroonScript is a tiny language that can easily b e extended by the

user with DMeroonScript denitions or by the implementor in C This language may b e used to write

simple singleline URLs to access DMeroon ob jects or quite complex multiline programs to p erform some

actions on them All the functionalities of DMeroon API may b e put to work with the DMeroonScript

language

DMeroonScript is a stackbased Forthlike language with a p ostx syntax Constants are pushed

onto the stack when pro cessed Other words corresp ond to commands whose denition is recorded in a

of vocabularies instances of UrlEnv Commands p op their arguments out of the stack and push

their results The stack only contains DMeroon ob jects

DMeroonScript uses HTML to display its results so it is b etter to use it from an http client The

interpret API function also allows to submit DMeroonScript programs DMeroon

When an DMeroonScript is erroneous its execution stops and an error message is returned in html

and the content of the stack is displayed as well When an DMeroonScript program stops normally the

stack should b e empty if the stack contains a single value it is displayed If the stack contains more than a

single value an error message is returned

The empty DMeroonScript program triggers the display of an help message

An DMeroonScript program is evaluated with a stack holding DMeroon ob jects and an environment

mapping variables to DMeroon ob jects An DMeroonScript is formed of a succession of constants or

commands separated by spaces or tabulations or newlines or by slashes this eases writing URLs

Programs

A program is a p ossibly empty sequence of lines Comments start with the hash sign and end up with the

end of the line Lines are made of tokens that is constants ie literals or commands Commands are named

as C identiers they start with a letter or an underscore and may contain a number of letters underscores

or digits Succeeding commands that may b e confused should b e separated with whitespace tabulations

newlines LF or CR or slashes

Within DMeroon programs are represented by an instance of class String A NUL character of co de

zero ends the representation of a program even if it is not the last character

Constants

Constants may b e numbers strings or characters They are pushed onto the stack as so on as recognized

Numbers are only p ositive They may b e written in decimal form or in o ctal form if prexed with or

in hexadecimal form if prexed with x or X Numbers are converted into instances of the Nat class

CHAPTER DMEROONSCRIPT BINDING

Strings are enclosed with Characters within a string and mainly and may b e protected by

Strings may also b e sp ecied if surrounded by matching f and g Quite often this is used to denote an

executable piece of co de to submit to the eval command Strings are converted into instances of the String

class

Characters are enclosed within They are converted into instances of the Char class

When created a constant is initialized as copyable unless the DM CONTEXT DONT INITIALIZE Context

option is set

Examples

The following program pushes onto the stack an instance of Char two instances of Strings and three

instances of Nat

Q

This is a string

This is another string

xCafeBabe

Access to eld

The content of the eld of a DMeroon ob ject may b e extracted via the dot notation followed by the name

of the eld sp ecied directly and not as a string The content of an indexed eld may b e extracted via the

dot notation followed by the name of the eld sp ecied directly and not as a string suxed by an index

b etween square brackets The result must always b e a DMeroon ob ject this implies that the eld must

have type reference

An error is signaled if an index app ears and the eld is not indexed An error is signaled if the eld is

indexed and no index app ears An error is signaled if the eld is secret

Implementation note Indexes are no longer implemented In the past a eld such as a

nat when read was automatically reied into a Nat instance The reciprocal conversion was

automatically done at writingtime Should I reintroduce these features

Examples

For instance if the current site is on top of the stack then its information eld is read by the information

command this value replaces the site on top of the stack

thesite get the current site onto the stack

information the DMeroon dictionary

rest get the user dictionary

After removing all the previous comments this little program may b e equivalently written as

thesiteinformationrest

After the evaluation of either one of these two programs the stack contains a single ob ject an instance

of Dictionary

Commands

A word that cannot b e parsed as a constant or an access command ie the name of a eld prexed with

a dot is a command whose denition has to b e found in the current vocabulary If the command is not

dened the DMeroonScript program is erroneous and stopp ed

Commands are explained in this Section with the following notations The stack is displayed with its

top to the right then the command is shown followed by the resulting stack with still its top to the right

Uninteresting parts of the stack are elided with The class of the arguments is represented by the name

of their class

COMMANDS

Basic commands

The basic vocabulary of the DMeroonScript language provides the commands that are used by the html

display mechanism of DMeroon ob jects These are thesite byteprint fancyprint entry and modify

thesite Site DMeroonScript commands

Object byteprint

Object fancyprint

The thesite command pushes the current site on top of the stack The fancyprint command p ops an

ob ject out of the stack and displays its content in html in a fancy form while byteprint displays its content

in bytes again in html form These commands do not push anything in result The byteprint command

displays a result that is implementationdependent There is an additional print directive

Nat Nat Nat Nat entry Entry DMeroonScript command

The entry command p ops four numbers out of the stack and pushes the Entry instance that has a key

formed with these four numbers Keys include a random part making the forgery of keys at least dicult

String Object modify Object DMeroonScript command

The modify command allows to p erform on an ob ject a series of mo dications enco ded in a string

When an ob ject has some mutable elds these elds are displayed within an html form that when sent back

to the DMeroon server with the Modify button triggers a POST request A POST request is handled

similarly to a GET request except that the content of the POST request a string of namevalue pairs

is turned into an instance of the String class and is prepushed in the stack b efore the evaluation of the

DMeroonScript program This command allows to mo dify many elds at once

Implementation note This command knows how to modify al l types of nonindexed elds

but reference eld

Vocabulary commands

The set of p ossible commands is held in a linked list of instances of UrlEnv ie vocabularies When dened

a command is recorded into the topmost vocabulary It is not p ossible to redened a command but it is

p ossible to push a new empty vocabulary to use another vocabulary or to p op the current vocabulary

The evaluation starts with an empty vocabulary followed by the predened vocabulary containing all the

commands describ ed in this chapter

begin DMeroonScript commands

end

UrlEnv use UrlEnv

CHAPTER DMEROONSCRIPT BINDING

The begin command creates a new empty vocabulary and insert it in topmost p osition in the list of

vocabularies The end command reverses this eect and p ops the current vocabulary The use command

allows to change entirely the linked list of vocabularies it returns the previous vocabulary

The current vocabulary may b e obtained via the reifying state command

Object String define DMeroonScript command

The define command binds a name and an ob ject in the current environment This implicitly creates a

new command with that name that when invoked returns the asso ciated ob ject

String String defcommand DMeroonScript command

The defcommand command binds a name and a string When the command is invoked the asso ciated

string is evaluated instead

Examples

To b e in an empty vocabulary with nothing at all dened is simple but problematic since there is no means

to return to a regular situation this is a deadend

UrlEnv allocate use pop

The print command consumes the top of the stack It is a simple matter to dene a new command

named idprint that avoids this b ehavior that is that prints the top of the stack and leaves the stack

unchanged For instance

dup print

idprint define

idprint eval Test idprint

Rather than using eval explicitly we may dene an equivalent command and write

dup print

idprint defcommand

idprint Another test

Here is a small DMeroonScript program that rolls the three ob jects on top of the stack This is an

extended swap command whose name is inspired from Forth similar command

begin

top define pop top and name it top

subtop define pop subtop and name it subtop

subsubtop define pop subsubtop and name it subsubtop

subtop top subsubtop push all three of them in a different order

end

roll defcommand

roll Stack contains from top

This example is safer than the two previous ones since the arguments of the roll command are created

in a lo cal vocabulary which is only used during the computation of the roll command The name top may

b e used again safely

Stack commands

These are Forthlike commands

COMMANDS

Object dup Object Object DMeroonScript commands

Object Object swap Object Object

1 2 2 1

Object pop

These commands manage the stack dup duplicates the top of the stack swap swaps the two ob jects at

the top of the stack while pop removes the top of the stack

Bo olean commands

These are the commands dealing with b o olean and chiey the alternative construction

false Boolean DMeroonScript commands

true Boolean

Object Object Boolean

1 2

Object not Boolean

Object Object Object if

else then

These are the commands dealing with logical values The true resp false command pushes true

resp false onto the stack True and false are predened instance of classes True and False sub classes of

Boolean The command compares two ob jects and return the true or false b o olean DMeroon ob jects

True is pro duced if the two compared ob jects are just the same physical ob ject however comparing two

Nat numbers or two Strings yields true if they have same content The not command returns true if given

the b o olean false and returns false for all other DMeroon ob jects The if command p ops out an ob ject

and two other ob jects known as then and else If the ob ject is false else is pushed otherwise then is pushed

instead Note that in DMeroonScript all values are equivalent to true but the false ob ject which is the

only one of its kind

null Object DMeroonScript commands

The null command pushes DM NULL ie the empty reference which b elongs to any class

Examples

This command allows to p op a stack until nding a null value This null value is consumed This function

is erroneous if the stack do es not contain a null value

begin Open a new vocabulary

x define Name the argument

popuntilnull x null if eval

end Close the local vocabulary

popuntilnull defcommand

null true popuntilnull Just leaves on the stack

Arithmetic commands

The arithmetic op erations exist as well They are sp elled in full letters and the only problem is to remember

how not commutative op erations take their arguments

CHAPTER DMEROONSCRIPT BINDING

Nat Nat plus Nat DMeroonScript commands

Nat Nat minus Nat

Nat Nat times Nat

Nat Nat quotient Nat

Nat Nat modulo Nat

There are also the other arithmetic comparators Remember they are not commutative so pay attention

to the order of the arguments A quick rule is that you have to write as in a mirror

Nat Nat le Boolean DMeroonScript commands

Nat Nat lt Boolean

Nat Nat ge Boolean

Nat Nat gt Boolean

Nat Nat ne Boolean

Examples

Here is the b estseller factorial example

begin

n define Name the argument

DEBUG n print n print print Print argument

n n minus factorial times n le if eval

end

factorial defcommand

factorial print

Meta commands

There are two metacommands The eval command allows to evaluate a string while state reies the

current state of the DMeroonScript machine

String eval DMeroonScript command

The eval command p ops out a string and evaluates it The evaluation of the string do es not yield results

p er se rather it may alter the stack and the current environment

state UrlState DMeroonScript command

The state command reies the full state of the evaluation into an instance of UrlState Such an ob ject

app ears in the message emitted in case of errors

COMMANDS

dumpstack DMeroonScript command

Nat exit

To view the stack one may print it with dumpstack but you may alternately interactively insp ect it with

the state command If you want to ab ort immediately the evaluation of a DMeroonScript program use

the exit command and tell it the error co de you want to raise or zero if this is an abrupt but normal end

Site go Site DMeroonScript command

The go command allows to migrate computations from one site to another The site where the compu

tation should go is p opp ed out of the stack the current site is pushed instead and the whole state of the

machine is copied and resumed on the intended site The new site may return to the original site if using

the top of its stack

Miscellaneous commands

These are the leftover commands

Object print DMeroonScript command

The print command p ops an ob ject out of the stack and tries to display its content into a short

comprehensible humanreadable form Instances of the abstract classes Value mainly for numbers and

String are recognized and printed sp ecially

String String extract String DMeroonScript command

The POST request pushes its b o dy a string of namevalue pairs The extract command allows to

extract a value asso ciated to a name from that string The value is turned into an instance of String This

command may b e used to extract the value of a given eld from a string

Entry fetch Object DMeroonScript command

The fetch command caches or up dates lo cally the ob ject asso ciated to an Entry

Clock tick DMeroonScript command

CHAPTER DMEROONSCRIPT BINDING

The tick command p ops and increments a lo cal Clo ck

DMeroon API

There exist commands to invoke the functions of the DMeroon API The arguments p opp ed from the stack

are in the order of the variables of the corresp onding function of the API

Object classof Class DMeroonScript commands

Object siteof Site

Object clockof Clock

The classof command p ops an ob ject out of the stack and pushes its class instead Similarly the siteof

command pushes the site that owns the ob ject and clockof pushes the asso ciated clo ck that is NULL if no

clo ck is asso ciated

String class Class DMeroonScript command

String type DMeroonType

Class String field Field

String Nat site Site

The class command p ops a name and pushes back the predened class with that name An error is

signalled if no predened class with that name exists The type command p ops a name and pushes back

the predened DMeroon type with that name An error is signalled if no predened type with that name

exists The field command p ops a name and a class and pushes the Field descriptor with that name from

that class An error is signalled if no eld with that name exists The site command p ops an hostname

and a p ort number and returns the appropriate DMeroon instance of Site if it exists

Class Nat allocate Object DMeroonScript command

Object clone Object

The allocate command p ops sizes ie numbers out of the stack until nding a class It then allo cates

and pushes an instance of that class with the given sizes

The clone command p ops an ob ject out of the stack clones it and pushes the result back onto the stack

Object setsharable DMeroonScript commands

Object setcopyable

These commands p ops an ob ject and makes it sharable or copyable

DMEROON API

Object Site setsiteof DMeroonScript commands

Object Clock setclockof

These commands allow to change the site owning an ob ject or the clo ck monitoring an ob ject

String Nat String connect Site DMeroonScript command

hostname passw or d

The connect command connects the current site with another site sp ecied by the name of its host its

p ortnumber and the password to use

Site Object send DMeroonScript commands

receive Object Boolean

The send command sends the reference of an ob ject towards a given site The receive command returns

a b o olean telling if an ob ject has b een received accompanied by the ob ject if the b o olean is true When the

b o olean is false the following ob ject is meaningless

Object Field xlenth Nat DMeroonScript commands

Object Field get Object

Object Field Nat xget Object

Object Field Object set Object

Object Field Nat Object xset Object

These commands allow to read the length of an indexed eld or the content of a regular or indexed eld

or to mo dify a regular or indexed eld They are restricted to elds of type reference You may mo dify

elds with other type with the modify command

Class String Nat Nat smashclass Class DMeroonScript commands

Class String Nat String Nat Type Type Class createsubclass Class

The createsubclass command p ops all the arguments needed to create a class The smashclass

command p ops all the arguments needed to smash a class a number of levels

Debugging command

The DMeroonScript language allows to debug applications through HTTP and unsafe additional com mands

CHAPTER DMEROONSCRIPT BINDING

Nat address Object DMeroonScript command

The address command p ops out a number and pushes the DMeroon ob ject whose DMeroon reference

is equal to this address The word address is misleading since the number is the DMeroon reference not

the address of the ob ject viewed from the binding language

Object proxyof External DMeroonScript command

This command returns the proxy of a DMeroon ob ject It must only b e used for debugging since these

ob jects are normally hidden from the user

Nat setdebuglevel Nat DMeroonScript command

This command allows to change the debug level of the DMeroon server Zero means terse higher

numbers increase verbosity This command returns the previous debug level This command is meaningless

DEBUG dened if the server is compiled without the cpp variable DM

Use

DMeroonScript is used to insp ect DMeroon values with an http client If your DMeroon server runs

on your lo cal machine then the initial URL is

httplocalhost

This URL gives access to some general information and provides a link to allow the insp ection of the site

ob ject This URL is

httplocalhostthesitefancyprint

From this one can follow references that corresp ond to URLs lo oking like

httplocalhostxadcxexaxfcdentryobject

This kind of URL sp ecies an ob ject externalized with a given key

When an ob ject is displayed see gure a banner tells which DMeroon server was the source of

the answer The ob ject is preceded by a sentence sp ecifying its main characteristics such as immutable

or mutable lo cal or remote sharable or copyable or uninitialized obsolete or uptodate its class is also

1

mentioned and it is p ossible to see the bytes representing the ob ject if you are an hex fan The elds of

the ob ject are then displayed in order starting with the name of the eld its type its length if indexed and

followed by its content If a eld is mutable then it is p ossible to mo dify it directly in your http client and

press the Modify button see gure

DMeroonScript API

It is p ossible to run DMeroonScript programs from the binding language The DMeroonScript lan

guage may easily b e extended in C with new commands Here follows the API to extend in C the DMe

roonScript language

The DMeroonScript machine has a state an instance of the UrlState class

1

des sixties comme disait Serge Gainsbourg

DMEROONSCRIPT API

Figure A Site displayed in html

Figure A mutable ob ject displayed in html

CHAPTER DMEROONSCRIPT BINDING

UrlState Class

previous another UrlState

script the DMeroonScript program a String

pc the program counter a nat number

stack the stack a BoundedStack

environment the vocabulary of commands an UrlEnv

errcode the last error code

This class denes the various comp onents of the state of the DMeroonScript machine Ob jects are

pushed onto the stack and the stack is extended when needed The program counter is an index into the script

a String To invoke the eval command in the DMeroonScript creates a new state for this evaluation

When the evaluation is over the old state is restaured Commands are lo oked for in the environment a

linked list of hashtables containing instances of UrlActions

UrlAction Class

behavior a pointer to a C function

internal a DMeroon object or NULL

name a natsequence of char

argument a natsequence of Classes

An UrlAction records an DMeroonScript command It has a name is implemented by a C function

with a precise signature The arguments of that command must b e DMeroon ob jects only and must have

the class sp ecied in the indexed argument eld The internal eld holds any DMeroon value that may b e

needed by the command This eld is used for instance by the define and defcommand DMeroonScript

command and may also b e used to mimic closures

The UrlAction class may of course b e sub classed

The C function that implements an UrlAction command must have the following prototype

DMUrlState behavior UrlAction behavior

DMContext context

DMUrlAction self

DMUrlState state

void outputport

DMObject arg references only

This behavior function receives the current context the UrlAction describing it so it may fetch the

internal value for instance the state of the DMeroonScript machine with its stack for instance the

output p ort where to print or NULL if no printing is needed and as many variables as there are arguments

The DMeroonScript machine takes care of invoking b ehaviors with the correct number and classes of

arguments A command may take from to arguments A command return the new state of the machine

The only diculty is to remember how are mapp ed arguments from the stack to variables of the b ehavior

they are mapp ed as represented in the previous denitions If a command has three arguments the last one

is at the top of the stack this is to simulate how stacks are displayed in this chapter

DMEROONSCRIPT API

Example

Here is the co de of the setdebuglevel command

static DMUrlState

DMsetdebuglevelcommand DMContext context

DMUrlAction self

DMUrlState state

void outputport

DMNat arg

DMNat result DMAllocatecontext Nat

resultvalue DMTheCurrentSitedebuglevel

if context DMHasNotOptioncontext DMCONTEXTDONTINITIALIZE

DMSetCopyablecontext result

DMTheCurrentSitedebuglevel argvalue

DMpushobjectinboundedstackcontext

DMObjectresult

statestack

stateerrcode DMESUCCESS

return state

Explicit evaluation

To run an DMeroonScript program is simple Just give a C string containing the DMeroonScript

program and a number of ob jects that will form the initial stack rst ob ject is the rst pushed onto the

stack These ob jects must b e DMeroon ob jects they are prexed by their number The nal state

of the DMeroonScript machine is returned so the results may b e p opp ed out of the nal stack The

DMeroonScript machine is run in mute mo de nothing is printed

DMErrorCode Level

DMerooninterpret DMContext context

DMUrlState urlstate

char urlprogram

DMnat nobjects

DMObject object

The previous function is implemented on top of the following one which is less usable as it stands but

more accurate since it represents the current DMeroonScript interpreter

DMUrlState Level

DMinterpreturlscript DMContext context

DMUrlState urlstate

void outputport or NULL

CHAPTER DMEROONSCRIPT BINDING

This function runs an DMeroonScript machine with an initial state When the DMeroonScript

machine terminates its nal state may b e accessed to discover the ob jects that are pushed in its stack

The interpretation stops as so on as an error o ccurs Printing may o ccur via the p ort mentioned as third

argument NULL prevents printing

Examples

It is sometimes interesting to combine two accesses but not to force the intermediate ob ject to b e fetched

on the current site Here is a way to achieve that

errcode DMsiteofcontext othersite o

Check error code

errcode DMinterpretcontext urlstate

go swap field field swap go

o othersite

Check error code

urlstatestackitem is the result

The computation is migrated onto the owning site of the o ob ject ofield is made present on that site

and ofieldfield is returned onto the original site

Development environment

You may use the TOP DMeroonCommandsurlscript command to submit clearer longer multilined DMe

roonScript programs from any shell command interpreter

urlscript hostnameport le Command

This command establishes a connection to the sp ecied DMeroon server and sends it the sp ecied le

using the DMeroonScript proto col If no le is mentioned the standard input is accumulated until an

endofle b efore b eing sent Shell variables are substituted with their values b efore b eing sent to the server

The server answers with html which is delivered onto the standard output of the urlscript command The

nal errorco de returned by the DMeroonScript program b ecomes the return co de of the command Files

containing DMeroonScript programs have dms as extension

An excellent to ol named dmClient allows you to really easily edit and submit DMeroonScript requests

to a DMeroon server JeanMichel Ingleb ert is the author of dmClient dmClient may b e op erated from

any JavaScriptenabled http client Point your favorite browser to TOP ContribdmClientdmClienthtm

page to play with

There also exists an Emacs mo de to edit DMeroonScript programs Two variables may b e set to

sp ecify the DMeroon server you want to send the content of the current buer The result is viewed

2

with Emacs thanks to the marvellous w package from William Perry This Emacs mo de app ears in the

TOP EmacsDMeroonScriptel le Do cumentation app ears in its header

Examples

This is a oneliner to increment the general clo ck of a site It displays the string Attention followed by the

current clo ck increments the clo ck and redisplays it in a fancy way ie with a tick button The script

ends by printing Done Here it is

AttentionprintthesiteclockduptickfancyprintDoneprint

2 ftpftpcsindianaedupubelispw

EXAMPLES

This is a bigger example of an DMeroonScript program that records the string DMeroon is great

in a dictionary named queinnec which is grafted in the user dictionary

Get the user dictionary

thesiteinformationrest userdictionary define

Create a new dictionary with the right size

Dictionary class allocate newdictionary define

Initialize the name field

namequeinnec newdictionary modify pop

Initialize the value and rest fields

newdictionary dup classof value field DMeroon is great set pop

newdictionary dup classof rest field userdictionaryrest set pop

Finish the initialization and makes the dictionary sharable

newdictionary setsharable

Hook the new dictionary after the user dictionary

userdictionary dup classof rest field newdictionary set pop

Report correct execution

Done print

CHAPTER DMEROONSCRIPT BINDING

Chapter

Icslas binding

This chapter describ es a binding initiated some years ago with a concurrent distributed extension to the

Scheme language the Icslas language The Icslas language is p owered by a bytecode interpreter a

compiler exists written in Scheme for the Scheme subset of Icslas The bytecode machine and the

compiler are enhanced versions from the ones describ ed in Que

All Icslas values are represented as DMeroon ob jects Entities necessary for the bytecode machine

such as lexical environments global environments and continuations are as well represented by DMeroon

ob jects thus allowing their migration

Implementation note Unfortunately I had no time to pursue that eort since

CHAPTER ICSLAS BINDING

Bibliography

AF G Attardi and T Flagella A customizable memory management framework In Proceedings of the USENIX

C Conference Cambridge Massachussetts

Coi Pierre Cointe The Ob jVlisp kernel a reexive architecture to dene a uniform ob ject oriented system

In P Maes and D Nardi editors Workshop on MetaLevel Architectures and Reection Alghiero Sardinia

Italy Octob er North Holland

LQP Bernard Lang Christian Queinnec and Jose Piquer Garbage collecting the world In POPL

Nineteenth Annual ACM symposium on Principles of Programming Languages pages Albuquerque

New Mexico USA January

Piq Jose Miguel Piquer Indirect reference counting A distributed garbage collection algorithm In PARLE

Parallel Architectures and Languages Europe pages Lecture Notes in Computer Science

SpringerVerlag June

QC Christian Queinnec and Pierre Cointe An op enended Data Representation Mo del for EuLisp In LFP

ACM Symposium and pages Snowbird Utah USA

Que Christian Queinnec A Framework for Data Aggregates In Pierre Cointe Philipp e Gautron and Christian

Queinnec editors Actes des JFLA Journees Francophones des Langages Applicatifs pages La

Ro chelle France January Revue BigreGlobule

Que Christian Queinnec Meroon A small ecient and enhanced ob ject system Technical Rep ort

LIXRR Ecole Polytechnique Palaiseau Cedex France November

Que Christian Queinnec Designing meroon v In Christian Rathke J urgen Kopp Hub ertus Hohl and Harry

Bretthauer editors ObjectOriented Programming in Lisp Languages and Applications A Report on the

ECOOP Workshop number Sankt Augustin Germany September

Quea Christian Queinnec Lo cality causality and continuations In LFP ACM Symposium on Lisp and

Functional Programming pages Orlando Florida USA June ACM Press

Queb Christian Queinnec Sharing mutable ob jects and controlling groups of tasks in a concurrent and distributed

language In Takayasu Ito and Akinori Yonezawa editors Proceedings of the Workshop on Theory and

Practice of Parallel Programming TPPP Lecture Notes in Computer Science pages Sendai

Japan November SpringerVerlag

Que Christian Queinnec Lisp in Smal l Pieces Cambridge University Press

Quea Christian Queinnec Distributed generic functions In JeanPaul Bahsoun Takanobu Baba and Jean

Pierre Briot editors Second FranceJapan workshop on ObjectBased Parallel and Distributed Computing

OBPDC Toulouse France Octob er

Queb Christian Queinnec Serialisationdeserialisation en DMeroon In Omar Raq editor NOTERE

Col loque international sur les NOuvel les TEchnologies de la REpartition pages Pau France

November Editions TASC

WS Larry Wall and Randal L Schwartz Programming perl OReilly Asso ciates Inc

BIBLIOGRAPHY

App endix A

DMeroon source les

This chapter gives some insight on the sources of DMeroon this might b e useful i when adapting DMe

roon to another language ii when p orting to another Op erating System or language iii for curious

p eople

There are many p ossible dimensions for customization or mo dularization of DMeroon Figure A try

to place the various les with resp ect to layers mo dules and relationship b etween them

DMeroonScript user Scheme user

C user

dmact dmscm

dmnewapi

dmgifdmhtml

dmstructdmtypesdmsite

dmkern

dmreq

dmreqst

dmrdobjdmwrobj

dmprtcl dmzlib

dmsched

dmnet

net support language

Figure A Layers and relationship b etween les

A Structures of les

The top directory of the distribution is named icslas p erhaps suxed with a version number Let TOP

b e this directory Under TOP may b e found various README les and other administrative les

When you rebuild the DMeroon library for a given language the compilation takes place in another

directory the TARGET directory Once DMeroon is rebuilt for a given language the obtained library

should not b e used with another language It is nevertheless p ossible to rebuild DMeroon concurrently for

all languages for which a binding exists

The TOP directory contains a number of subdirectories

The DMeroon directory contains the les that are indep endent of any binding languages This directory

also contains a number of subdirectories

APPENDIX A DMEROON SOURCE FILES

The c directory contains the C les

The Commands contains shell or Perl scripts

The Doc directory contains the current do cumentation and some other related research pap ers

The Test directory contains DMeroonScript test programs as well as other tests written in

Scheme

The C directory denes C as a binding language and so is the Bigloo directory Former bindings were

studied but are no longer maintained these are OScheme Pico XXX contains template for bindings

The Bootstrap isdirectory used by the maintainers of DMeroon to regenerate some les b elonging

to DMeroon distribution ie tarballs

The Commands directory contains shell or Perl scripts and so is DMeroonCommands

The Others directory contains Scheme co de from other authors while Library contains Scheme co de

b elonging to the Icslas runtime library

The config directory p opulated with various Imakeles These parts are combined using imake to

form the complete Makele in the TARGET directory This pro cess is pretty complex and plenty of

b ells and whistles may parameterize it

The Contrib directory contains DMeroonfans contributed co de

The TOP directory also contains some interesting les such as the top Imakefile which was carefully

written to b e usable as a regular Makele the ChangeLog le of the Icslas pro ject various README

les

A The TOP DMeroonc directory

The DMeroon library is made of a number of C les p opulating the TOP DMeroonc directory Each C le

has an asso ciated h le dening the prototypes of the exp orted variables or functions but to allow an easy

use of the DMeroon system you only have to include the dmeroonh header le which in turn includes all

the sp ecialized header les such as dmstructh dmkernh etc The dmh header le is also automatically

included This le is a little p eculiar since it denes macros that are used in all these other header les

The dmeroonh header le also recursively includes two sp ecialized header les The rst header dmosh

contains all the dep endencies with resp ect to the Op erating System it tries to automatically discover the

op erating system

The second header le also automatically included describ es the p eculiarities of the binding language

this is TOP Bigloodmbglh for Biglo o TOP Cdmch for C TOP OSchemedmoschemeh for OScheme etc

When DMeroon is b ound with some language it requires access to sp ecic routines of the runtime of this

language to help DMeroon manage its space or comply with the conventions of data representations so that

DMeroon ob jects lo ok like normal ob jects This header le is often complemented by some co de adding to

the runtime of DMeroon For instance for C DMeroon uses Bo ehms Garbage Collector

prex they all have Names are rather systematic and I hop e easily decipherable Except for the DM

variables and functions have lowercase names made of underscore separated words Functional macros

names are made of JointTogetherCapitalizedWords while data macro names are written as usual in

UPPER CASE

Most of the data structures required by DMeroon are statically allo cated so loading DMeroon is a

snap All these les end with an initializing routine for the initializations that cannot b e static When

compiled with the appropriate debug level many checks are p erformed in these initialization routines

Nearly all functions have a Context instance as rst argument even internal functions This allows to

conne errors or to parameterize certain b ehaviors

Do cumentation may b e automatically extracted from these les to form html pages that may b e browsed

by your favorite html client To get them run make regeneratedocumentation in the TARGET directory

The html pages will app ear in TARGET WWW and the

A STRUCTURES OF FILES

Basic les

TOP DMerooncdmstructdm This imp ortant le denes all the C structures that are used by DMe

roon All these structures are also DMeroon classes and so may b e insp ected as regular DMeroon ob jects

thus satisfying introspective reexivity This le has a Scheme syntax in fact a Meroon syntax and is

automatically turned into a dmstructc and a dmstructh les with help of the dmch compiler

TOP DMerooncdmeroonh This is the header le that recursively includes what is necessary to

compile C les using DMeroon resources Not very big by itself but rather complex

TOP DMerooncdmh An enormous header le far less readable than dmeroonh and far more complex

only for diehards It denes many of the internal macros that are used throughout the co de of DMeroon

TOP DMerooncdmosh This le contains the dep endencies with resp ect to Op erating Systems Cur

rently these are all UNXbased and appropriate for SUN bsd SUN solaris DEC Alpha DEC Ultrix

Sony News PC Linux The selection of the right OS is automatic but I plan to use autoconf some time

TOP DMerooncdmerrh This header le denes the zillions error co des detected by DMeroon

accompanied with some explanations

TOP DMerooncdmidh The current version of DMeroon

TOP DMerooncdmsizesh This le denes how DMeroon types are mapp ed onto C types ie

nat is often an unsigned int The current mapping is universal with resp ect to the previously men

tioned Op erating Systems but you may have to change it if DMeroon detects a mist DMeroon checks

compatibility when initialized see dmtypesc initialization and in case of disagreement displays the ap

propriate size and alignment constraints to help you Some examples of sizes and alignments are kept in the

TOP DMerooncHINTS le

Core les

From now on the remaining parts are comp osed of a h and c les They are classed in alphab etical order

TOP DMerooncdmactc This le denes the DMeroonScript language

TOP DMerooncdmcachec This le denes the utilitary functions to manage caches when marshal

ingunmarshaling ob jects

TOP DMerooncdmcommc This le denes the management of Entry and Exit items that supp ort

the remote p ointer mechanism

TOP DMerooncdmdbgc This le denes some debug utilities for DMeroon They are rather useful

when p orting DMeroon but not after

TOP DMerooncdmextrc This le denes extra libraries for users comfort in C

TOP DMerooncdmgifc This le denes some icons

TOP DMerooncdmhashc This le denes the basic machinery for hashtables Pay attention search

ing is done via a macro not by a function for typing reason

TOP DMerooncdmhtmlc This le denes the HTML server which allow to insp ect DMeroon in

stances from any http clients

TOP DMerooncdmkernc This contains the functions that constitutes the basic DMeroon memory

mo del ie how to access elds within an ob ject whether an ob ject is lo cal or not initialized or not how to

increment a clo ck to clone an ob ject to create new classes This le also contains some predened DMe

roon constant ob jects that are used throughout the implementation such as nil true false uninitialized

These constants and functions are not part of the API

TOP DMerooncdmlibc This le is there to hold functions lacking from some Op erating Systems

you know the kind of things such as strstr bad memcpy etc It is also used to mask some dierences such

as putenv versus setenv that cannot b e resolved in dmosh

TOP DMerooncdmnetc This le denes the TCPIP related parts of DMeroon It allows to listen

for connections to llush buers to sendreceive messages

TOP DMerooncdmnewapic This le denes the API for the C language

TOP DMerooncdmprintc This le denes a series of C functions to print every predened DMe

roon type This is mainly used for debug and html generation

TOP DMerooncdmprtclc This le denes how proto cols used on TCP connections are recognized

and handled

APPENDIX A DMEROON SOURCE FILES

TOP DMerooncdmrdobjc This le denes how to deco de sequences of bytes into DMeroon ob jects

over TCP connections This is viewed as a kind of bytecode interpreter implementing a stackoriented

machine

TOP DMerooncdmreqc This le manages requests queues and their answers

TOP DMerooncdmreqstc This le denes functions that manage distribution at low level It checks

for lo cality handle communication requests

TOP DMerooncdmschedc This le denes the DMeroon event lo op It actually implements various

variations DMeroon may b e run in a unique pro cess in a thread or from Scheme where threads are

enco ded as continuations

TOP DMerooncdmscmc This is the generic interface for Scheme It translates the C API into a set

of functions more amenable to b e used from a Scheme implementation

TOP DMerooncdmsitec This le denes the original Site ob ject which is the ro ot of DMeroon

selfdescription

TOP DMerooncdmtypesc This le checks whether DMeroon types are well mapp ed onto C types

it also dynamically asso ciates DMeroon types to the appropriate C readwrite functions

TOP DMerooncdmwrobjc This le denes how to enco de DMeroon ob jects over TCP connections

This enco ding is viewed as a compilation for the deco ding machine As for many dierent

enco dings are p ossible thats why this le has b een more heavily changed than the dmrdobjc le

A Rebuilding DMeroon

Rebuilding DMeroon is p erformed in the TARGET directory First this TARGET directory is created

then it is p opulated with a lot of les a generated Makefile some config les memorizing pathnames in

various formats shell makele or Scheme Appropriate les from TOP are copied Whenever p ossible les

are linked rather than copied Eventually make world is p erformed in the TARGET directory and should

yield a fully op erational DMeroon server for a given language

Running make from the TOP directory will ask interactively some questions The rst question is what

to build answer d for DMeroon The second question concerns the binding language answer c for C or b

for Biglo o The script will try to identify the sort of machine it is running on will create and p opulate the

TARGET directory then will prop ose to rebuild DMeroon Answer y then and wait

A Other les

Other les are required to adapt DMeroon to a particular language The binding is detailed in Chapter

A

A C

The binding with C requires some additional les that are lo cated in the TOP C directory These are

TOP Cdmch TOP Cdmcc These are the binding les They explain how to map DMeroon

values in C values DMeroon needs a GC two are p ossible Bo ehms GC or no GC at all with the latter

the server will crash after saturating the swap space

TOP Cserverh TOP Cserverc This le implements a very simple DMeroon server It has

several options describ ed in table A that may b e sp ecied as arguments to the command

There is also a TOP configcmkf le that describ es how to regenerate DMeroon for C This le also

contains some standalone tests

A Biglo o

The binding with Biglo o requires some additional les that are lo cated in the TOP Bigloo directory These

are

TOP Bigloodmbglh TOP Bigloodmbglc These are the binding les They explain how to map

DMeroon values in Biglo o values

A BINDING DMEROON

Option Meaning

banner Prints a banner

verbose displays some information

linger duration The server will nish after duration seconds of in

activity Used as last option the duration may b e

elided to mean innity

Table A Options of the rudimentary C server

TOP Bigloodmbgl This le written in Scheme is a Biglo o mo dule dening the DMeroon server

ab ove Biglo o

TOP Bigloomainbgl These are the main Biglo o mo dules that start the server

TOP Bigloodmwriterh TOP Bigloodmportsh These are les helping to patch les of the

distribution of Biglo o

There is also the TOP configbigloomkf le that describ es how to regenerate and how to test DMe

roon for Biglo o

A Binding DMeroon

DMeroon is currently b ound to C and to Biglo o a Scheme dialect It was b ound to OScheme another

dialect of Scheme and Pico still another dialect of Scheme These last bindings are to b e up dated It is

envisioned to bind DMeroon with Caml C Emacs Java Linux kernel Tcl etc

The sources of DMeroon are parameterized with resp ect to the supp ort language ie the language

with which it is b ound In eect DMeroon statically allo cates all its predened classes elds types as

well as the site ob ject and therefore needs to statically know the format of the ob jects as imp osed by the

binding language DMeroon ob jects lo ok like ob jects of the binding language that is DMeroon ob jects

are embedded into native ob jects of the supp ort language

DMeroon also has to manage its memory space ie allo cate and free ob jects it uses the GC of the

supp ort language otherwise DMeroon brings its own GC All these parameters are sp ecied by macros and

functions that are required to compile DMeroon sources This means that a DMeroon library compiled

for one supp ort language can probably not b e used by other supp ort languages

To bind DMeroon with some xxx language is supp orted by at least three les

TOP Xxxdmxxxh containing macros and prototypes

TOP Xxxdmxxxc containing runtime functions or ob jects

TOP configxxxmkf is the Makele to compile the p ort

These three les are often built altogether since they are highly interrelated You may take a lo ok at

these les for Biglo o C or Icslas

A The dmxxxh header

First prevent double inclusion to save cpp time Then include any header le that are required for the xxx

supp ort language

Dene DM SUPPORT LANGUAGE to b e a string with the name of the supp ort language something like xxx

This string will app ear in the support eld of the site ob ject as a String instance

MALLOC should b e the name of the routine that allo cates ob jects for the binding language As Cs DM

malloc this routine takes the number of bytes to allo cate and returns a p ointer onto the allo cated ob ject

See the DM allocate function in the dmxxxc le b elow

The dicult part is how to embed DMeroon ob jects within xxx ob jects Often ob jects in xxx have

a particular header prexing the content with resp ect to xxx of the ob ject This content consists of the

APPENDIX A DMEROON SOURCE FILES

DMeroon header followed by the content with resp ect to DMeroon of the asso ciated elds see gure

It is imp ortant not to confuse the three views of the same ob ject an ob ject may b e referenced by a

p ointer in xxx another one in DMeroon and a third one if considered by DM malloc

Figure A shows that in C p ointers designate the rst byte of the content of the ob ject Class and

proxy are accessed backwards from this p ointer To b e able to recognize DMeroon ob jects we use a tag

MALLOC returns a p ointer on and to resp ect alignment constraint some padding is added The lowlevel DM

the rst byte of the ob ject ie its tag

MALLOC Biglo o ob jects are handled via the address of the Biglo o tag that is the address returned by DM

Some padding is then added for alignment constraint DMeroon can b e recognized with a sp ecic Biglo o

tag

Icslas just uses DMeroon representation and adds nothing to it

malloc p ointer malloc p ointer

tag Biglo o tag

Biglo o p ointer

malloc p ointer

padding padding class

class class proxy

DMeroon p ointer

proxy proxy content

Icslas p ointer

C p ointer DMeroon p ointer

content content

DMeroon p ointer

Figure A Ob jects in C Biglo o and Icslas

Viewed from DM MALLOC the prex of a DMeroon ob ject is describ ed by the following universal structure

taken from the TOP DMerooncdmh le

typedef struct DMeroonobject

DMSupportPrefix

DMDMeroonPrefix

DMeroonobject

MALLOC p oint of view the DM SupportPrefix macro describing You must therefore dene from the DM

the structure of the ob ject and the DM SupportPrefixInitialization macro that initializes this structure

This latter macro receives the name and the exact type of the ob ject to b e initialized so the initialization

may use this information to record the size of the ob ject for instance

You must then dene how to recognize a DMeroon instance among the values handled by the xxx

supp ort language You may also dene this macro to b e always true if you like to live dangerously This is

the DM IsDMeroonInstance macro which takes a p ointer viewed from xxx onto an xxx value and which

returns a C b o olean

IsObject but this one takes a DMeroon reference instead Another macro p erforms the same task DM

of a p ointer onto an xxx value and returns a C b o olean Since a NULL value is a legal DMeroon p ointer

this macro should take care of this fact

To b e able to switch from the DMeroon world to the xxx world and back two fundamental macros are

DM ToSupport that takes a DMeroon reference and returns an xxx p ointer and DM FromSupport that takes

an xxx p ointer and returns a DMeroon reference In the source les of DMeroon a variable prexed by

holds a value of the supp ort language wrapped

SupportPointer macro denes the type of a p ointer onto an xxx value A p ointer onto a DMe The DM

roon ob ject has the DM Object type A p ointer onto an ob ject viewed from DM MALLOC has type void

Dont confuse them

The glue to bind DMeroon may require some initialization co de the function to call is mentioned by

the DM INITIALIZE macro

RaiseException macro must b e dened it receives an errorco de and has to take care of Finally the DM

handling that situation It may signal a recoverable exception if the binding language supp orts it it may

longjmp in C to a safer context it may print the error co de and ab orts the pro cess

This is the end of the minimal binding

A BINDING DMEROON

The dmscm layer

If you bind DMeroon to a language with runtime types such as Scheme or maybe Java then you may use

the dmscm layer that insulates you more from gory details This layer is a new API ab ove the one describ ed in

chapter oering facilities more like the ones of chapter Values of the supp ort language are automatically

converted into their appropriate representation in DMeroon back and forth Youll have to dene additional

macros describing this situation

A The dmxxxc le

This le contains the runtime functions that are necessary to glue DMeroon with the xxx supp ort language

Some functions must b e dened since they are required by DMeroon this is the case of the DM alloca

bare instance the DM print char star and the DM INITIALIZE functions te

All allo cations p erformed by DMeroon are done via a single function named DM allocate bare ins

tance This function has the following prototype

DMObject

DMallocatebareinstance DMContext context

DMClass class

DMnat size

Given a class and a size in bytes it should allo cate an xxx value able to contain a DMeroon ob ject of a

given size in bytes The function should return a DMeroon reference onto the freshly allo cated ob ject or

ab ort if the allo cation cannot b e p erformed The ob ject must b e correctly initialized with resp ect to the

xxx supp ort language It will b e initialized with resp ect to DMeroon p oint of view by other DMeroon

routines shortly after Pay attention to alignment the rst byte referenced by the DMeroon p ointer should

1

resp ect the most stringent alignment constraint imp osed by the hardware or compiler DMeroon p erforms

some sanity checks to detect such things

print char star function Its prototype is All values are printed by DMeroon using the DM

void

DMprintcharstar DMContext context

char string

DMnat len

DMSupportPointer wrappedport

The second argument is a C string to print the third if not zero is the number of characters to print out

of the string If the third argument is zero then the whole C string is printed up to its end ie up to a NUL

character The fourth argument is an xxx value representing the output stream where to print Dep ending

on the xxx language this argument may b e very dierent things a C stream a C le descriptor a Scheme

p ort etc

INITIALIZE macro This The last function that must b e present is the function mentioned by the DM

function often named DM xxx initialize p erforms some checks and initializes the binding

A The xxxmkf le

This le is the Imakele describing how to regenerate DMeroon with the xxx supp ort language Most

often the xxxmkf le complements the allmkf le which denes how to regenerate a generic DMeroon

executable

1

On my home machine gcc aligns long doubles on bytes b oundaries while the hardware only requires bytes alignment

APPENDIX A DMEROON SOURCE FILES

A Writing co de for DMeroon

If you ever want to add co de to DMeroon you must follow some rules This set is far from complete but

will b e enriched as I remember them

Indent your co de I p ersonally use the default indent style of Emacs Dont use long lines ie bigger

than characters

Try to b e p ortable Check p ortability on at least another computer system

Mark temp orary lines with a TEMP comment mark future co de to b e written with a FUTURE

comment accompanied by a short description

Every bug if corrected must lead to a comment and to a test in some test suite

Try to use the facilities of the auto do c utility that builds html pages from source les

Wrap test or sanity co de within DM DebugAtLevel directives

Compile with all the p ossible warning options and never leave a warning app ear The Wall option

for gcc is recommended

Declare external functions in fileh and dene them in filec Add these les to the global Makefile

architecture

Be very cautious ab out allo cations

dont use mutable global data structures try to b e threadsafe

dont call malloc use DMeroon ob jects instead

b etter try to stack allo cate these DMeroon ob jects

dont let b ounded data structures limit your algorithms

Resp ect naming conventions for identiers Names are rather systematic and I hop e easily decipher

prex they all have variables and functions have lowercase names made of able Except for the DM

underscore separated words Functional macros names are made of JointTogetherCapitalizedWords

CASE while data macro names are written as usual in UPPER

DMeroon puts a high emphasis on selfdescription and parameterization Use DMeroon ob jects for

that goal

App endix B

Ob ject internal representations

This app endix describ es the various implementation states DMeroon ob jects may have This is a rather

technical chapter but is of great help for me

Viewed from a site a DMeroon ob ject may b e local or remote Lo cal means that the current site owns

it A remote ob ject is always asso ciated with an Exit item Again viewed from a site an ob ject is either

present ie lo cal or remote but cached or absent that is remote and not cached Moreover when a remote

ob ject is present it may b e valid ly cached or obsolete ie its cache is up to date or out of date

Viewed from users the ob jects they have p ointers on are always present They never can access proxies

ie entry or exit items

Some constants are used to enco de these states Constants in DMeroon are instances of the Constant

class a direct sub class of Object

B Lo cal ob ject

allocate returns it in the uninitialized state The class of an allo cated When an ob ject is allo cated DMeroon

ob ject is always present and so is its owning site since this is the current site An ob ject stays in this state until

b eing initialized semiexternalized or externalized see the state diagram in Figure B some uninteresting

states are omitted from this Figure

lo cal

initialized

uninitialized externalized

semiexternalized

Figure B States of lo cal ob jects

Implementation note The constants that are used to mark these states have historical names

and wil l probably be changed These representations were choosen to lessen memory consumption

a local object costs two additional references and maybe some padding compared to C which

does not require any overhead This cost increases when objects are externalized

APPENDIX B OBJECT INTERNAL REPRESENTATIONS

The class eld of the DMeroon header always contains a reference to a present class which the ob ject

is a direct instance of

B Uninitialized

A lo cal uninitialized ob ject has as proxy the uninitialized constant see gure B Allo cation returns

DMeroon ob jects in this state

proxy uninitialized

class

Figure B Lo cal uninitialized ob ject

B Lo cal sharable

When an unitialized ob ject is declared sharable then its proxy b ecomes the nil constant

B Lo cal copyable

When an uninitialized ob ject is declared copyable then its proxy b ecomes the true constant

B Semiexternalized

set clock of then it must b e semiexternalized since If a lo cal ob ject is to b e monitored by a clo ck via DM

the clo ck can only b e held in a eld of an Entry item see gure B in this gure the dotted squares shows

the details of the elds of the Entry item To b e semiexternalized means that the ob ject has an Entry item

as proxy In this state the ob ject is still unknown from remote sites To b e semiexternalized has no relation

with its initialized state the ob ject may still b e declared initialized sharable or copyable the dierence is

that these prop erties are now recorded as options in the asso ciated entry item

key

refcount

options

Entry item

clo ck clo ck

proxy

class

Figure B Semiexternalized ob ject

Entry items are for the implementation regular DMeroon ob jects instances of the Entry class dened

as follows An externalized or semiexternalized ob ject has an instance of Entry as proxy this proxy p oints

back to the semiexternalized ob ject via the object eld That is

B LOCAL OBJECT

The class of a semiexternalized ob ject is always semiexternalized or externalized The owning site of a

semiexternalized ob ject is always semiexternalized or externalized

Entry Class

number a unique key identifying the object

counter a reference counter for GC

options some options describing the Entry item

object the object the entry item stands for

clock its associated Clock if any

When an ob ject is semiexternalized an Entry item is allo cated and b ecomes the proxy of the ob ject

The key ie the number under which the ob ject will b e known from the network of the Entry item is null

but the clock eld is set to hold the monitoring clo ck The Entry item is itself an immotile DMeroon

ob ject which is in the uninitialized state and will b e left in that state all its lifetime Recall that Entry items

are never seen by the user

If the ob ject was copyable b efore b ecoming semiexternalized then the options eld of the Entry item has

the DM ENTRY IS COPYABLE option set If the ob ject was sharable instead b efore b ecoming semiexternalized

then the same option is unset If the ob ject was uninitialized then the previous option has no meaning but

the DM ENTRY IS UNINITIALIZED option is set instead

If a semiexternalized ob ject is made copyable then the DM ENTRY IS UNINITIALIZED option is unset

and the DM ENTRY IS COPYABLE option is set If a semiexternalized ob ject is made sharable then the

DM ENTRY IS UNINITIALIZED option is unset and the DM ENTRY IS COPYABLE option is unset A semi

ENTRY IS UNINITIALIZED option of its Entry item is set externalized ob ject is uninitialized when the DM

A direct instance of Entry with a null key corresp onds to a semiexternalized ob ject

B Externalized

An ob ject is externalized when it needs to b e known from other sites either b ecause it is reachable from

another ob ject displayed in html for an http client that may want to follow the link ie the reference or

b ecause a reference onto the ob ject was sent to another site When externalized an ob ject has as proxy an

Entry item with the same set of options as in the semiexternalized state Additionally the Entry item i

gets a non null key ii is registered in the hashtable holding all Entry items iii its reference counter is

initialized with zero

When externalized a mutable ob ject must b e monitored by a Clo ck By default and if not explicitly

sp ecied this Clo ck is the general Clo ck of the current site held in the clock eld of the site If the

NULL An ob ject may b e externalized without b eing ob ject is immutable then the clock eld is set to DM

semiexternalized rst and without even b eing initialized

When an ob ject is externalized its class is also externalized as well as its owning site

Any time a reference onto a DMeroon ob ject is sent its reference counter is incremented however the

reference counter is not incremented when a html link is sent When a site detects that it do es not need

any longer a reference it discards it and sends a decrement message to the asso ciated reference counter

When the reference counter reaches zero the Entry item may b e reclaimed since no DMeroon site needs

its asso ciated ob ject After the Entry item is reclaimed the ob ject itself may b e reclaimed if lo cally useless

When an ob ject is externalized a key is generated for it The key is unique and will never b e reused

anywhere anytime the key is based on the IP and p ort numbers of the server the current date a regularly

incremented counter and two random bytes to make the forgery of keys at least dicult When an ob ject

is migrated ie is owned by a dierent site than its birth site it keeps its key

A direct instance of Entry with a non null key corresp onds to an externalized ob ject The reference

counter may b e zero or strictly p ositive Zero means that no site knows it however the ob ject had b een

externalized for the sake of some http client

APPENDIX B OBJECT INTERNAL REPRESENTATIONS

key

refcount

options

or DM NULL

Entry item

clo ck clo ck

key Entries

Hashtable

proxy

class

Figure B Externalized ob ject

B Remote

Only the unmarshaling routines can create remote references An Exit item is a big data structure containing

enough information to fetch the content of the remote ob ject to know its asso ciated class clo ck or site to

p erform nonlo cal GC When a remote ob ject is present ie lo cally cached it lo oks like a lo cal ob ject except

that its proxy is an Exit item Intermediate states exist to cop e with dynamically created classes whose

instances are sent b efore their class

When an ob ject is remote it is only remotely referenced as in gure by an Exit item Remember

that outside of the API users never see Exit items When a reference onto an ob ject is sent the ob ject is

externalized on its owning site and an Exit item is created on the receiving site see Figure B for the most

complex case

The Exit class inherits from the Entry class thus an Exit item may b e externalized as an Entry item

and b e known from other sites The Exit class is dened as follows

Exit Class

number a unique key identifying the original object

counter a reference counter for GC

options some options describing the Exit item

NULL or a replica object DM

clock the associated Clock if any or DM NULL if immutable or an Exit if absent

class the class of the remote object or an Exit if absent

time the time when the replica was fetched

from the site from which we got the Exit item maybe unusable

owner the site owning the remote object maybe unusable

next used internal ly

When a site unmarshals an Exit item it tries to prefetch asynchronously the class and the clo ck of the

remote ob ject if they were unmarshaled as remote p ointers Therefore the class eld is either a p ointer to

a present instance of Class or a p ointer to an Exit item leading to a remote class Once the class is present

NULL if the current site tries to prefetch asynchronously its clo ck Therefore the clock eld is either DM

the ob ject is immutable a present instance of Clock or a p ointer to an Exit item leading to a remote clo ck

The content of the site eld is always an instance of Site this site is always registered in the hashtable of

known sites but the site may b e in the unusable state

Only when the content of the class and clock elds are present the remote ob ject can b e fetched to

B SITE

Sites IPport

Hashtable

site Site

key Exits

Hashtable

clo ck

class

Site

Exit Exit Exit

key

refcount

options

Entry Entry

clo ck

original ob ject

Site

proxy

class a Class

clo ck

Figure B Exit item with absent class and absent clo ck

form a lo cal replica of the remote ob ject This replica is reachable via the object eld of the Exit item and

has as proxy the Exit item DMeroon tries to shortcut p ointers to the Exit item into direct p ointers to the

replica see gure

DMeroon may for GC reasons reverts a p ointer to a replica into a p ointer to the asso ciated Exit item

and then reclaims the replica To fetch again the replica will b e automatically redone if needed If an Exit

item has a lo cally cached replica then this replica has this Exit item as proxy

When a replica is present its class and clo ck are always present The converse may not b e true

B Reexp orted

An Exit item may b e marshaled towards a site in which case the part of the Exit item which is inherited

from the Entry class is lled except the key which is already set the reference counter is initialized to zero

it counts the number of times the Exit item is reexp orted Piq but the object eld of the Exit item

may b e null since a replica do es not need to b e present nor its class or clo ck See gure B

B Site

Sites are handled particularly All sites ob jects are reachable from a hashtable of lo cally known sites Sites

are lazily propagated b etween DMeroon servers A site instance may b e usable or not but its fundamental

elds ie IP number p ort and date of creation are always up to date A usable site is a site whose content

may b e read for that a usable site must b e validly cached and has as proxy an Exit item whose owner

eld is that very site A site without Exit item as proxy is not usable However normal users outside the

SITE IS USABLE identies that state API never see that internal state A sp ecial option DM

SITE COMMAND can create instances of Site an uninstantiable class Only the unmarshaling command DM

Such a site is not initialized and only its fundamental elds are correct ie its address port date elds

and additionally p erhaps the route eld It is p ossible to send ob jects to sites for which no Connection is

APPENDIX B OBJECT INTERNAL REPRESENTATIONS

Entry

site a present Site maybe not usable

class a present Class maybe not usable or an Exit

clo ck a present Clo ck an Exit or DM NULL

ob ject DM NULL or a replica

Site

Exit

Figure B Reexp orted Exit item

op en The route eld refers to a third site from which the current site heard of the site and which acts as a

communication relay It is also p ossible to op en a more direct Connection When a site is usable or it has

a op ened Connection in its connection eld or it has a relay site in its route eld

B Class

For a class to b e usable it must b e present its sup erclasses must b e usable and all its elds must b e present

Users outside the API cannot p erceive that state This state is identied by the DM CLASS IS USABLE

option this option is reset when a class is transmitted A site that receives a class tries to prefetch missing

comp onents to ensure its usability

B Miscellaneous

Out of the API users only have p ointers onto present and usable for classes and sites ob jects They never

see Entry or Exit items These ob jects may b e out of date but to read them will force DMeroon to refresh

them

Inside the API a reference may b e to a present ob ject or to an Exit item The Exit item may b e

asso ciated to a replica or not this replica may b e valid or not Before a replica may b e brought lo cally the

class of the ob ject must b e present as well as its clo ck if mutable The elds of Entry or Exit item should

b e considered with great care since classes or sites may b e unusable

B Prop erties

These data structures are complex and resp ect some invariants This Section is intended to b e useful for

implementors it describ es the same representational invariants b ottomup ie starting from the implemen

tation

We will use the following terminology A proxy is an entry or exit item An ob ject is a regular DMeroon

value that is not a proxy Pay attention that exit items are from the implementational standp oint indirect

instances of Entry however when we say that something is an entry item we exclude the exit item case

The user of the DMeroon API can only see present ob jects An implementor may see ob jects or proxies

Ob jects and proxies are always handled via p ointers so when we say an ob ject we imply a reference to an

ob ject

B Ob ject

An ob ject is always present its class is always present Its proxy may b e

B PROPERTIES

the uninitialized constant meaning that the ob ject is uninitialized

the nil constant meaning that the ob ject is uninitialized but declared sharable

the true constant meaning that the ob ject is uninitialized but declared copyable

an exit item meaning that the ob ject is remote but lo cally cached The ob ject then app ears in the

object eld of the exit item The exit item is registered in the exits hashtable of the current site the

class eld of the exit item refers to a present class The site eld of the exit item contains a

present site

an entry item meaning that the ob ject is either

semiexternalized if the key of its entry item is zero then the entry item is not registered in the

entries hashtable of the current site If a clo ck had b een explicitly asso ciated to the ob ject then

it is held in the clock eld of the entry item

externalized if the key of its entry item is non zero The entry item is registered in the entries

hashtable its reference counter tells how many times the ob ject was marshaled to other sites

In b oth cases the class is also at least semiexternalized and so is the current site The ob ject may

still b e uninitialized or sharable or copyable this is sp ecied by bits in the option eld of the entry

item

Two sp ecial cases exist for classes and sites

Class

A remote but present class may have non present elds The DMeroon library tries to fetch as so on as

p ossible remote elds of present classes When the class has the USABLE option set then its elds are all

present The user may only see usable classes and therefore can only allo cate ob jects with usable classes

Site

The current site is a regular ob ject remote sites are sp ecial When a site heard of a remote site an instance

of Site is allo cated and lled with the basic information IP p ort number and stored in the sites table of

the current site If it needs to the DMeroon library fetches the content of the site and sets its USABLE

option on The user may only see usable sites

B Entry item

An entry item a direct instance of the Entry class always has an ob ject in its object eld which in turn

has the entry item in its proxy eld The class of the ob ject and its owning site the current site are present

and externalized The key of the entry item may b e zero if the ob ject is only semiexternalized or nonzero if

the ob ject is externalized In this latter case the entry item app ears in the entries hashtable of the current

site

The ob ject the entry item stands for may b e uninitialized or sharable or copyable If the ob ject is sharable

then it is monitored by a clo ck held in the clock eld of the entry item The ob ject may b e uninitialized

and already asso ciated to a clo ck

The ob ject may b e known from other sites if externalized A reference counter of zero is a sure sign

that the ob ject was displayed in html for some http client An entry item with a null reference counter and

asso ciated to no clo ck or to the general clo ck of the site may b e recycled by the GC

APPENDIX B OBJECT INTERNAL REPRESENTATIONS

B Exit item

An exit item stands for a remote ob ject An exit item app ears in the exits hashtable of the current site The

site eld of the exit item refers to a site which is present but not necessarily usable

The ob ject may b e cached or not If the remote ob ject is cached then its object eld holds a present

ob ject ie a replica of the remote ob ject The replica has the same structural information the remote ob ject

has same class same length for indexed elds In this case the class eld of the exit item refers to a

present class

The exit item may b e reexp orted in which case it is registered as well in the entries hashtable of the

current site The exit item may b e lo cally cached or not

If the remote ob ject is not cached the object eld of the exit item is NULL the class eld may b e a

present class or an exit item leading to a remote class

App endix C

Proto cols

When started DMeroon acts as a server listening to a p ort and waiting for incoming connections When

a connection is op ened the rst characters are scanned to determine which proto col they ob ey Currently

a DMeroon server recognizes i the GET and POST requests of the HTTP proto col ii the DMe

roonScript proto col extending the two rst proto cols iii the DMeroon proto col which is used to

exchange binaryenco ded DMeroon requests b etween DMeroon sites

This chapter describ es proto cols and shows how DMeroon servers may b e extended to handle new

proto cols It requires some understanding of DMeroon implementation and predened classes as they

app ear in the TOP DMerooncdmstructdm le Warning not all details are present here read the sources

and chiey the TOP DMerooncdmprtclc le

The DMeroon implementation uses only DMeroon ob jects this allows to debug parts of DMeroon

with DMeroon itself When DMeroon is initialized it normally listens to a TCP p ort whose p ort num

SERVING PORT If this variable is not set then the b er is sp ecied by the environment variable DMEROON

DMEROON FAVORITE PORT cpp variable is used that is the very wellknown p ort If value of the DM

DMEROON SERVING PORT is the zero number then no Server is created and DMeroon will not serve any re

quests In the numerous cases where a server is created an instance of the Server class reies this situation

When a connection is detected an instance of the Connection class is created This instance contains

two buers to hold bytes to emit or bytes received via the connection The buer for incoming bytes is an

instance of the InBuffer class the other is an instance of the OutBuffer class

When enough characters are received to form a line ie a sequence of bytes terminated by a newline

character then the rst characters are scanned to determine which proto col may b e used to handle the

connection To this end a connection instance has a eld the protocol eld initially lled with the

equivalent eld of the current site ob ject This eld is a linked list of instances of the Protocol class The

Protocol class is dened hereafter

Protocol Class

next next protocol to try

handler a C function

name a natindexed eld of char

A proto col is dened with a name the sequence of characters that triggers this proto col and a handler a

p ointer to a lo cal C function to handle the connection Each proto col name is tried in turn and compared

against the rst incoming characters If no proto col is recognized the connection is immediately closed

When a proto col is recognized the asso ciated handler is invoked with the current context on the incoming

buer

When a proto col is recognized it is its duty to consume the incoming characters The asso ciated handler

is stored in the handler eld of the connection This is used for instance by the DMeroon proto col to handle

APPENDIX C PROTOCOLS

new incoming requests The handler returns a C b o olean telling whether the request has b een handled or not

FALSE means that while the rst line with the letters determining the proto col is Therefore to return DM

present the rest of the request is still not present In this case the whole pro cess will b e retried later when

the connection receives additional characters this allows a proto col to wait until the entire request is present

in an InBuffer It is up to the proto col to decide when the request is complete For instance DMeroon

prexes messages with their lengths while the SchemeScript proto col for Biglo o waits for a sequence of

NUL NUL CR LF While buers are b ounded DMeroon ensures that the whole request is held in a single

instance of the InBuffer class

When the handler returns DM TRUE it must have consumed the characters of the request it thus has to

mo dify the index eld of the incoming buer

The order of proto cols is signicant since they are tried in turn Of course a proto col triggered by a null

string catches everything

C Existing proto cols

Besides the three main proto cols that is HTTP DMeroonScript and DMeroon there also exist other

small sp ecialized proto cols They are currently useless but serve as examples

The proto col swallows empty lines or lines starting with a sharp sign or a white space This proto col

do es not answer anything but after the line is swallowed it starts again to determine which proto col to use

to handle the remaining characters This is the comment proto col

The help proto col just answers the identication of the DMeroon site then closes the connection One

may write instead of help

A third proto col is the error which prints the rest of the line on the standard error output of DMeroon

It do es not close the connection

The GET proto col answers http requests in html form The pro duced html pages may trigger a POST

proto col to mutate ob jects The dd convention may b e used for these two proto cols It allows to hide

characters under their ASCI I co de

The GET proto col is also used to serve the robotstxt le to prevent compliant rob ots to explore a

DMeroon server and the iconsdmeroongif icon les to illuminate the html pages generated by the

DMeroon server

The DMeroon proto col is a byteoriented communication proto col that allows DMeroon servers to ex

change values See the pap er in French called serialisationdeserialisation en DMeroon for details

After entering the DMeroon proto col the connection is used in inner DMeroon proto col see chapter C

The Scheme binding with Biglo o oers another proto col the SchemeScript proto col which waits for a

string containing an Sexpression to evaluate The result is sent back to the client that sent the expression

then the connection is closed The expression is evaluated with Biglo os eval function in the global shared

environment This is a dangerous but p owerful proto col dened in the TOP Bigloodmbglc le that can

b e used with the TOP DMeroonCommandsschemescriptprl command

The use of the last proto cols may b e restricted with a password This password may b e sp ecied

PASSWORD environment variable or at compilation time by the DMEROON ADD at runtime by the DMEROON

PASSWORD cpp variable The principle is very simple the name of the proto col is suxed with this ITIONAL

string of characters Passwords are currently limited to characters by the DMEROON ADDITIONAL PASS

WORD LENGTH cpp variable The password is immediately concatenated to the name of the proto col pay

attention to leading spaces

Implementation note Reading the pgp man page I realized how unsafe is the DMEROON PASS

WORD environment variable This wil l be improved in some future Uses of passwords make at

least dicult connections to DMeroon servers protected by dierent passwords

C Adding proto cols

New proto cols may b e added dynamically You clearly are an exp ert if you use this function

C SOME CLASSES

DMProtocol Internal

DMaddprotocol DMContext context

char string

DMcboolean handlerDMContext DMInBuffer

This primitive denes a new proto col to b e recognized by the current site All new connections will know

this new proto col but already op ened ones will not This proto col will b e tried rst so it can mask existing

proto cols with longer names but same prex you may alternatively directly hack the protocol eld of

TRUE if it consumes the request or DM FALSE the current site The handler must return the C b o olean DM

if the request is not entirely present At that time when the connection receives additional characters then

DMeroon will call again the handler function It is p ossible for the handler to extract from the InBuffer

instance the asso ciated Port OutBuffer and other related values

When the handler is called the index eld of the InBuffer designates the rst character to b e handled

Since the handler is called the rst line is present in the buer ie there is a LF character somewhere after

this index The buer may b e used up to the maximum eld which designates the rst character which is

not part of the buer

If you want to register a proto col that must b e protected by the password of the DMeroon server then

you have to use this function instead

DMProtocol Internal

DMaddrestrictedprotocol

DMContext context

char string

DMcboolean handlerDMContext DMInBuffer

C Some classes

There are many classes used in the message layer Two sites may exchange message through a Connection

Except for a short time while a Connection is b eing initialized the site eld may b e not usable

APPENDIX C PROTOCOLS

Connection Class

number the p ortnumber or le descriptor

options options

TCP stu

lastread last date an InBuffer was read

lastwrite last date an OutBuffer was ushed

reception the asso ciated InBuffer

emission the current asso ciated OutBuffer

emitqueue the rst OutBuffer to ush

clocker the last time the buer was ushed

site the site at the other end of the connection

protocol the list of proto cols that may b e used

handler the function to handle the proto col

password the password to use

The most imp ortant parts of a Connection are the buers to consume and pro duce When a message

arrives it is always recorded in a single InBuffer

InBuffer Class

port the asso ciated Connection

cache a BoundedStack acting as a stackcache

index the next character to read

maximum the rst character not to read

amount the total number of characters acquired by the Connection

byte the characters

When marshaling an ob ject the OutBuffer may b e full a new OutBuffer is then allo cated and linked

in the next eld Since there is the p ossibility to ab ort a message while comp osing it multiple OutBuffers

may stand in memory

OutBuffer Class

port the asso ciated Connection

cache a BoundedStack acting as a stackcache

mark mark the b eginning of a message

index the next character to write

maximum the rst character not to write

amount the total number of characters ushed by the Connection

next the next outBuffer

byte the characters

C The DMeroon inner proto col

This section describ es the DMeroon proto col ie the language used by DMeroon servers to serialize or

deserialize ob jects The serialization is viewed as a compilation into bytecodes towards the deserializer wich

acts as a bytecode interpreter There is usually more than one way to serialize some data the serializer may

C THE DMEROON INNER PROTOCOL

choose to b e eager and presend ie push values or to b e lazy and let the receiver pull the missing values

The deserializer is the interpreter of a valueoriented stackbased prex language The stack may as well b e

managed as a cache Each Connection has separate asso ciated caches for reading and writing

The DMeroon proto col is triggered by the DMeroon word then the connection is turned into the inner

DMeroon proto col In this inner proto col messages are exchanged A message corresp onds to a sequence

of bytes that will b e deserialized into a single ob ject The content of reference elds may also b e present

Commands are enco ded by a single byte and may b e followed by arguments In addition to the commands

describ ed b elow the commands corresp onding to the characters CR LF and SP are ignored Comments are

also skipp ed they start with a sharp character and end with the rst following CR or LF These conventions

allows to comment a bytestream for instance to use the convention of Unix

There are a number of invariants to resp ect when marshaling ob jects the most imp ortant one is that

it is not p ossible to unmarshal an ob ject if its class is not usable withing the receiver This is why when

sending ob jects only a remote p ointer is created Before asking for the content of an ob ject the receiver

ask for its class and also its clo ck Ob jects are then pulled rather than pushed However you may presend

these ob jects if you are sure that the receiver knows their class or if you use the LIMIT command

The following notations are used b elow object clock class etc means that an instance of that class is

exp ected DMeroon types such as nat or classoptions may also app ear

C Ubiquitous ob jects

These commands return ubiquitous ob jects ie ob jects that are lo cal to every site even if dierently

implemented

NIL unmarshaling commands

TRUE

FALSE

UNINITIALIZED

NULL

The rst niladic commands that is NIL TRUE FALSE UNINITIALIZED and NULL just transmits a simple

ubiquitous ob ject Ubiquitous ob jects are mainly used by the implementation or by the Scheme binding

although they exist on every site they are considered equal The site of an ubiquitous ob ject as obtained

with DMsiteof is always the current site NULL allows to transmit the null reference ie a reference that

do es not lead to any DMeroon ob ject

PREDEFINEDCLASS nat unmarshaling commands

PREDEFINEDTYPE nat

PREDEFINEDFIELD nat nat

The PREDEFINEDCLASS command takes a nat as argument and returns the predened class with that

index among the set of predened classes Such a class is an ubiquitous ob ject even if its representation

varies from site to site The TYPE command takes a nat and returns the DMeroon type with that index

see table Such a type is an ubiquitous ob ject even if its representation varies from site to site The

PREDEFINEDFIELD i j command returns the ith eld of the j th predened class

C Stackrelated commands

These commands deal with the stack they may take an additional argument The stack is a regular stack

if managed from the top it is considered as a cache if managed from the b ottom Technically a Tcp

APPENDIX C PROTOCOLS

Connection b etween two sites is asso ciated to four stackcaches two p er communication way When the

emitter changes its stackcache it enco des the command that will mo dify accordingly the stackcache of the

receiver

Implementation note I may separate some time stacks from caches

POP unmarshaling commands

SWAP object

DUP object

RESET object

PUSH object

The commands POP SWAP DUP and RESET manage the stackcache of the deserializer First there is a

stack which is accessed with the usual functions It is p ossible to extract or replace values from this stack

with an index counted from the top of the stack or from the b ottom of the cache RESET totally clears the

cache SWAP swaps the top of the stack with the element right under it the subtop of the stack of course

the stack must have at least two elements DUP duplicates the top of the stack ie it pushes the ob ject on

the top of the stack in the stack of course the stack must contain at least one ob ject The three previous

commands do not return a DMeroon ob ject per se they just p erform the required action then read the

ob ject that follows and return it

POP returns the ob ject standing on the top of the stack as well as it removes it from the stack PUSH

reads its argument pushes it onto the stack then it returns that ob ject as value Stacks are automatically

extended whenever needed

REFERWITHNAT nat unmarshaling commands

REFERWITHNAT nat

REFERWITHNAT nat

The commmand REFERWITHNAT resp REFERWITHNAT or REFERWITHNAT takes a nat resp

a nat or nat argument and returns the ob ject cached at that p osition counted from the b ottom of the

cache The cache must b e large enough for this index to b e legal in particular less than the stack p ointer

INSERTWITHNAT nat object unmarshaling commands

INSERTWITHNAT nat object

INSERTWITHNAT nat object

These commands take an index and an ob ject insert the ob ject in the cache at the given p osition counted

from the b ottom of the cache and return this ob ject The cache must b e large enough for this index to b e

legal in particular less than the stack p ointer

C Useful commands

C THE DMEROON INNER PROTOCOL

EMITTINGSITE unmarshaling commands

RECEIVINGSITE

Commands EMITTINGSITE and RECEIVINGSITE are shortcuts that enco de the two sites standing at

b oth ends of a TCP connection These sites are known after a brief handshake that takes place immediately

after the Connection is op ened This handshake or b o otstrap of the Connection has to b e sp ecially done

since it must warm up the inner DMeroon proto col and pro ceed to the exchange of site ob jects

SETCOPYABLE object unmarshaling commands

SETSHARABLE object

SETCOPYABLE resp SETSHARABLE takes a DMeroon ob ject as argument and initializes it to b e

copyable resp sharable it returns that initialized ob ject These commands are often needed after the

ALLOCATE command

CLASS classoptions class unmarshaling commands

FIELD eld

SYMBOL symbol

CLASS takes some classoptions and a class as arguments it returns this very class Nonpredened classes

must b e prexed by this command to b e usable on a remote site A class must b e usable b efore you may use

it to allo cate instances A class is usable when all its sup erclasses and all its elds are present and usable

FIELD takes a eld as argument and returns it Nonpredened elds must b e prexed by this command

to b e usable on a remote site

SYMBOL takes a symbol as argument interns it in the lo cal hashtable of symbols so two symbols with

the same name are the same and returns it as value

RECEIVEREQUEST request unmarshaling commands

RECEIVEANSWER answer

The two commands RECEIVEREQUEST and RECEIVEANSWER take a DMeroon ob ject as argument and

return it as value RECEIVEREQUEST resp RECEIVEANSWER enqueues the ob ject which must b e an instance

of Request resp Answer in the list of p ending requests resp answers These requests or answers will b e

handled after the deserialization of the current message

Implementation note This is to avoid simple deadlocks when a site has to unmarshal a

message and requires for it another message from the same site

PROG object object unmarshaling commands

PROG object object

APPENDIX C PROTOCOLS

The PROG resp PROG command takes two ob jects as arguments and returns the rst resp the

second of them

LIMIT nat object unmarshaling command

This command returns its second argument but ensures that its enco ding is exactly nat bytes this size

includes the representation of the nat number itself up to the last byte of the ob ject Moreover if an error

o ccurs while unmarshaling the ob ject the error is caught and NULL is returned instead This command is

often used to presend values whose classes may b e unknown from the receiver

C Sp ecic commands

These are commands that create ob jects remote p ointers etc

ALLOCATE class sizes unmarshaling command

This command takes as rst argument a class followed by nat sizes It allo cates and returns an instance

of the class whose indexed elds are determined by the given sizes For instance to allo cate a String of

characters you may write is supp osed to b e the index of the String predened class

ALLOCATE PREDEFINEDCLASS

The parentheses that app ear ab ove are cosmetic only they group commands to ease reading

The class that app ears as rst argument must b e usable Note that it is not required to sp ecify the

number of sizes since this may b e deduced from the class

FILL object content unmarshaling command

This command takes an ob ject as argument lls it with the serialized content and nally returns it The

content is made of the concatenation of the serialized elds For instance to ll the previously mentioned

String of three characters one may write

FILL ALLOCATE PREDEFINEDCLASS F o o

The parentheses that app ear ab ove are cosmetic only they group commands to ease reading

EMITTERREFERENCE key externaloptions class clock unmarshaling command

The EMITTERREFERENCE command creates a remote p ointer onto an ob ject owned by the emitting site

The key is the number that names the asso ciated Entry item or a reexp orted Exit item The class may

b e enco ded as a remote p ointer itself the receiving site will fetch it in order to b e able to lo cally cache

such a remote ob ject If the ob ject is mutable then the clo ck is enco ded or remotely p ointed If the ob ject

NULL is sent instead The entire command returns an Exit item or the asso ciated is immutable then DM

replica if already present The externaloptions allows to sp ecify whether the ob ject is copyable sharable

or uninitialized

C THE DMEROON INNER PROTOCOL

RECEIVERREFERENCE key unmarshaling command

The RECEIVERREFERENCE command returns the ob ject held by the receiving site externalized with that

key

REMOTEREFERENCE key externaloptions class clock site unmarshaling command

The REMOTEREFERENCE command creates a remote p ointer onto an ob ject owned by a remote site The

key is the unique number that names the original ob ject on its birth site The class may b e enco ded as

a remote p ointer itself the receiving site will fetch it in order to make it lo cally usable If the ob ject is

NULL is sent mutable then the clo ck is enco ded or remotely p ointed If the ob ject is immutable then DM

instead The site argument is the site that owns the ob ject The entire command returns an Exit item or

the asso ciated ob ject if already present

CACHE object exit unmarshaling command

This command reads an ob ject and an Exit item it asso ciates the ob ject to the Exit item and returns the

ob ject This allows for instance to presend an ob ject in hop e it will b e useful to the receiver Something

like cache limit exit

Of course the ob ject must not b e already asso ciated to an Exit item and the Exit item must not b e

already asso ciated to an ob ject

SITE IPnumber portnumber date sitenamelength unmarshaling command

The SITE command returns a Site instance describing the site watching a given p ort on a given host

sp ecied by its IP number The SITE command is the only command that can create instances of Site

this class is uninstantiable by the user Most often the site is in the not usable state The site is not

connect for that The server is also identied contacted and no Connection is op ened to it use DMeroon

by its birth date to cop e with servers restart Since the Site class contains an indexed eld to hold its

hostname its length is also given

C Technical commands

These commands are internally used by DMeroon

DECREMENT key object unmarshaling command

This command reads a key and decrements the reference counter of the asso ciated Entry item The Entry

item will b e reclaimed if the reference counter reaches zero Eventually the command then reads and returns

the ob ject that follows

APPENDIX C PROTOCOLS

UPDATECLOCK clock nat object unmarshaling command

This command is used to mention that the clo ck app earing as rst argument has at least the next nat

value Eventually the command reads and returns the ob ject that follows

DEFINEEMITTER site key unmarshaling commands

This command is used while b o otstrapping a Connection When a Connection is op ened the requesting

Site signals itself with the DEFINEEMITTER command followed by an enco ding of the site and followed again

with its key This allows to build on the receiver site the Site instance and its asso ciated proxy

Instances of Site pass through various p eculiar states see app endix B

C Ob jectbased proto col

The DMeroon inner proto col sp ecies the exchange language When it is p ossible to exchange ob jects it

is p ossible to make DMeroon servers co op erate exchanging structured requests A request is an instance

of the Request class Often requests are answered by instances of Answer a subclass of Request

There are several types of requests

SCR for SiteConnectionRequest This request is only used to b o otstrap a connection The connecting

site sends such a request which is answered by a SiteConnectionAnswer aka SCA

OSR for ObjectSendRequest When sending a remote reference towards a site this request is used

There is no asso ciated answer

OFR for ObjectFetchRequest This request is sent when a site wants to refresh a replica It is

answered by an instance of ObjectFetchAnswer aka OFA

OMR for ObjectMutationRequest This request is send to the owner site of an ob ject so it can mutate

a regular eld of this ob ject It is answered by an ObjectMutationAnswer aka OFA that returns the

former value of the mutated eld

OIMR for ObjectIndexedMutationRequest This request is send to the owner site of an ob ject so it

can mutate an indexed eld of this ob ject It is answered by an ObjectIndexedMutationAnswer aka

OIMA that returns the former value of the mutated eld

Section under construction

C DMeroon and http

Normally DMeroon starts an http server You may invoke it to insp ect the site ob ject of DMeroon if

of course sucient time is given to the server to watch for the incoming requests The default URL is

httplocalhost The rest is selfexplanatory and clickable as so on as your favorite http client

xmosaic Netscape IExplorer etc can op en this URL

The site ob ject is the most prominent ob ject of DMeroon It allows to inquire the exact denitions

of DMeroon types the predened classes and the published information The site ob ject contains a

information eld containing instances of Dictionary a sort of multiAssociationlist containing whatever

values exp orted from this site Currently there are more than a hundred published values The published

information is publicly available since any user that connects to this site may read the site ob ject and inquire

its published information

C DMEROON AND HTTP

Section under construction

C The http proto col

This proto col is triggered by the GET keyword followed by an DMeroonScript request This request is

made of words separated by slashes It may use the dd convention to enco de some characters with their

ASCI I co de The default URL is

httplocalhosthelp

In fact a whole language exists to write these URLs This is a small stackoriented language the DMe

roonScript language see chapter that allows to call all the API functions

C Publishing informations

The site ob ject whose class is Site exp orts all its content and in particular an immutable eld named

information whose content is a multiAlist to which you may add your own values The ob jects that are

reachable from this information eld is said to b e published

As seen from table C there are initially two dictionaries The user dictionary is empty and reserved

for users the DMeroon dictionary is reserved for DMeroon and holds values describing the implementation

DMeroon The own DMeroon dictionary

site the site object itself

classes the Vector of predened classes

constants a subdictionary listing some constants

nil

true

types the Vector of predened types

user a dictionary free for users

Table C Predened published informations

The Dictionary class is dened as

Dictionary Class

rest a mutable reference to another dictionary or NULL

value a mutable reference to a DMeroon instance

name a repetition of characters

Published informations are gathered in no des from class Dictionary A Dictionary is somewhat similar

to an Alist no de The rest and value elds are mutable The value eld can of course refer to a Dictionary

instance justifying the multiAlist term

Published ob jects are known by pathname describing the path to follow through dictionaries to reach

these ob jects It is not recommended to use names with spaces dots and slashes since pathnames are

often written as sequences of names separated by slashes dots or spaces The easiest way to p opulate these

dictionaries ie to publish information is to use the Scheme binding see

Implementation note An http client is not really part of DMeroon space since it is con

nectionless An html page may have some links towards DMeroon objects These links may be

broken if the DMeroon server disappears meanwhile

APPENDIX C PROTOCOLS

App endix D

Driving DMeroon servers

This chapter describ es some applications using the DMeroonScript language to drive DMeroon servers

D Measuring the progress of a remote pro cess

Section under construction

Supp ose you started a pro cess on a remote machine that pro duces lines of results that are further

pro cessed Supp ose this pro cess to b e very long and to require days and days for its completion you

probably have to stop the rlogin connection you used to start it and then you can no longer observe its

output A simple solution to measure whether the pro cess makes some progress is to lter the output with a

dmtee command This command records the last ltered lines in a DMeroon ob ject You can then insp ect

that ob ject with any http client from your oce your home or even from Mars

Implementation note The dislocate utility from Don Libes command seems to be similar

The dmtee has the following syntax

dmteeprl n hostport pathname Command

This command creates a connection to the DMeroon server mentioned in the argument hostport or

localhost by default This DMeroon should of course b e running Then it creates a mutable

vector of size n by default keeping the last n lines This ob ject is published with pathname as name or

userUSER by default

This ob ject can b e inquired with the following URL

httphostportpathname

To return to our introductory example supp ose your command was originally solve verify file

then you just have to transform it into solve dmtee verify file to b enet of this new facility

dmtee is a simple Perl script WS using the DMeroonScript language to drive a DMeroon server

It app ears in TOP DMeroonCommandsdmteeprl le

D Distributed X cut buer

One day working on a workstation near Luc Moreau he asked me for a bibliographical reference I highlight

the text in my favorite Emacs and started to move the selection b efore realizing that there was no way to

paste it on Lucs screen I then use Email This application allows dierent users to share X selections It

is written in Tcl and uses the DMeroonScript language

APPENDIX D DRIVING DMEROON SERVERS

Section under construction