Tiago Cogumbreiro

O Irrepupável

Back to top

Thursday, July 02, 2009

An applet for MIL and the simply typed π-calculus compiler

In an effort to showcase my MSc work, I have developed an applet that contains the π-calculus compiler along with the MIL interpreter. You can try out either MIL our the simply-typed π-calculus and run it online. Our article about compiling the π-calculus into a multithreaded typed assembly language is an useful reference.

Try MIL and the pi-calculus compiler on-line!

The π-calculus consists of processes that run concurrently—you may read processes as tasks or threads, although they sit at a much higher level. The simplest process is the inactive one that finishes, we represent it by a zero 0. The basis of the π-calculus is communication; it is so important that the fundamental step of computation is the communication of sequences of values (integers, strings, and channels). Processes synchronize (and communicate) by message-passing, using channels. To send a message 10 through a channel x we write the output process x<10>. To receive a message through a channel x and store it in a name y that is visible in process P we write the input process x(y).P, notice that process P is not a variable, it must be replaced with an actual process, like the inactive process 0. If we want to receive a message repeatedly, like a server does, we just write a bang (!) in front of an input process, for example !x(y).P. To execute process P in parallel with process Q we write the parallel process P | Q, or to remove ambiguity we may use parenthesis (P | Q). To use a channel x in a process P, we must first declare it along with its type T by writing new x:T P. A type T is not a variable, it can be either an integer type int, a string type str, or a channel ^[T1,...,Tn] (the parameters ranging from T1,...,Tn are a possibly empty sequence of types, like the empty channel type ^[] or the channel that communicate two integers ^[int,int]. Channels may themselves send channels, for example channel type ^[int,^[int]] types channels that communicates two values, one of the integer type, another a channel that communicates integers.

A quick example of an echo server:

new echo:^[int,^[int]] (
  !echo(x,y).y<x>
  |
  new print:^[int] (
    !print(m).printInt<m>
    |
    echo<10,print>
  )
)

Tuesday, June 23, 2009

“Compiling the π-calculus into a multithreaded typed assembly language” is published

After one year the article I presented in PLACES '08 was published.

We extend a previous work on a multithreaded typed assembly language (MIL) targeted at shared memory multiprocessors, and describe the design of a type-preserving compiler from the π-calculus into MIL. The language enforces a policy on lock usage through a typing system that also ensures race-freedom for typable programs, while allowing for typing various important concurrency patterns. Our translation to MIL generates code that is then linked to a library supporting a generic unbounded buffer monitor, variant of Hoare's bounded buffer monitor, entirely written in MIL. Such a monitor shields client code (the π-calculus compiler in particular) from the hazardous task of direct lock manipulation, while allowing for the representation of π-calculus channels. The compiler produces type correct MIL programs from type correct source code, generating low-contention cooperative multithreaded programs.

Tiago Cogumbreiro, Francisco Martins, and Vasco T. Vasconcelos. Compiling the π-calculus into a multithreaded typed assembly language. ENTCS, 241:57–84, 2009.

Monday, April 06, 2009

Problemas com acentos usando Latex, Flyspell, ISpell e Emacs

Estive muito tempo com problemas na forma como o Emacs e o ISpell reconheciam as palavras portuguesas. Depois de muito escavar lá encontrei o .emacs do sítio oficial do dicionário português para ISpell. Para corrigir, coloquem este código no vosso .emacs:

(custom-set-variables
   '(ispell-local-dictionary-alist
     (quote (("portugues" "[A-Za-zàèìòùÀÈÌÒÙáéíóúÁÉÍÓÚãõÃÕâêîôûÂÊÎÔÛçÇ]"
                          "[^A-Za-zàèìòùÀÈÌÒÙáéíóúÁÉÍÓÚãõÃÕâêîôûÂÊÎÔÛçÇ]"
                          "[-]" nil nil "~latin1" iso-8859-1)
             ("portutex"  "[A-Za-z\\\\\\\\]"
                          "[^A-Za-z\\\\\\\\]"
                          "[---~`'^{}]" nil nil "~tex" iso-8859-1)))))

Isto é quase arte ASCII.

Wednesday, April 01, 2009

Redirecting to an external link/URL in Zope (and Plone)

Go to the Zope Management Interface. In Plone click on Site Setup (on the upper left corner) and then under Plone Configuration click on Zope Management Interface.

Next, create a content Script (Python) (select it in the drop-down widget in the upper left corner of the page). Select the name of the link of the origin of the redirection and click on Add and Edit.

Add the following content:

# Import a standard function, and get the HTML request and response objects.
from Products.PythonScripts.standard import html_quote
request = container.REQUEST
RESPONSE = request.RESPONSE

#return context.REQUEST.RESPONSE.redirect("http://www.google.com/")
return RESPONSE.redirect("http://www.google.com/")

This will redirect http://YOURHOSTNAME/foo (if you create the python script at the root of your Zope Management Interface named foo) and redirect it to http://www.google.com/. Could be easier (and fully accessible trough Plone's UI).

Sunday, March 08, 2009

MiNEMA Winter School 2009

I am going to attend MiNEMA Winter School. Great oportunity to learn about wireless sensor networks and to discover Göteborg.

Wednesday, February 18, 2009

World of Goo

I was amazed by the demo and had to buy the full game of World of Goo (for Linux). I do not play a game in years, so this was really a urge I could not control ;-) The game cost me 16 euros.

Wednesday, February 04, 2009

Hindley/Milner Type Inference Algorithm implementated in Haskell (untested and naïve)

I do not program in Haskell in a couple of years. Today I needed to learn the Hendley/Milner algorithm for type inference and decided to implement it in Haskell. A far more interesting related blog post is one about “Writing A Lisp Interpreter In Haskell”, by Slava Akhmechet.

You can grab the (hardly tested) code, released under public domain, in Pastebin at http://pastebin.com/f7dede189. The Source Code Is The Documentation™.

I can't stress enough the usefulness of algebraic data types and declarative languages for creating compilers. But alas, I am still working with Java in my research projects.

Update: Because I have somehow broken the indentation, I have taken the chance to re-upload the source code, while cleaning up some code. Added a nice link about interpreter implementation using Haskell.

Thursday, December 11, 2008

The π-calculus library chapter and literate programming

I finished the π-calculus library implemented in MIL. I started working in the translation chapter. Meanwhile, An explanation I received cleared up some details I was having with programming recursive types in MIL. With the misconception corrected I can now proceed working on the paper.

For my work on the paper I intend to clean up my pseudo-framework for doing literate programming, which enables the library described in the aforementioned chapter to be generated and then type-checked for errors. Make the code free from embarrassing errors.

Wednesday, December 10, 2008

pi2mil, mil, and the thesis

I reimplemented the compiler from the π-calculus into MIL (in Java). The only part that was not touched was the parsing. It took me two days to rewrite the type-checking and the compiler. My work was basically translating mathematical notation into Java. It is interesting to note how much code was simplified because the translation was formalized. Looking back, I had an over-engineered compiler. Now I have a much simpler implementation and a proof that it is compiling safely, preserving types.

After the compiler, I worked on synchronizing the implementation of MIL with the latest paper we have been working on. This amounted to rewriting the pretty-printer and to adding support for some instructions and a few types. The test battery we have implemented helped making sure I wasn't breaking any type-checking rule. There are, however, some problems that need to be solved in implementing some of the new sub-typing rules, notably with recursive types.

In this last week I have mostly programmed and haven't made significant progress in my thesis. We are working on a paper with a deadline due next week. But since I am waiting for some feedback to continue working on the paper, I have an opening to finish up the chapter on the π-calculus library. I only have half of a section to review to finish the chapter, so I hope I finish it in this week.

Thursday, November 27, 2008

Summary of the last week

I have been studying monitors for a section included in the chapter of the π-calculus library. The obvious references are “Monitors: An Operating System Structuring Concept” for Hoare-style monitors and “Experience with Processes and Monitors in Mesa” for Mesa-style monitors. I also found the chapter “Thread Synchronization” of the book “Inside the Java Virtual Machine” inspiring. My friend Neva made me realize that I was misusing terminology in my introduction to monitors.

After concluding the section I moved along to the section on the implementation of queues in MIL. There is a typing rule in MIL that is confusing me. Spent yesterday's afternoon reading “Types and Programming Languages”, just to understand that I need way more time to understand the chapter about the meta-theory of recursive types. The good part is that I found out that my chapter explaining MIL is very superficial. The bad part is that I have to invest more time to make it deeper. Today I plan on rewriting most of the text included in the queues section.

Yesterday I have also worked on a new project (another compiler). We are using SableCC for the parser and for the AST creation. The good part of this tool is that it allows for a separation of the AST from the CST, this is specially enticing for people developing languages for calculus, like our group. The shortcoming of this tool is that there is no way to tag the AST with metadata. We need to know the source code location related to an element of the AST. A proposed solution is to “pollute” the AST with terminal tokens delimiting the location. Tokens, however, do not have a single interface to retrieve the line and column and lack an associated filename.