Tiago Cogumbreiro

O Irrepupável

Back to top

Showing posts with label en. Show all posts
Showing posts with label en. Show all posts

Thursday, July 17, 2008

What I have been up to....

Classes are almost over! Wohoo! I am almost free to work on MIL and on Callas.

On both projects I have been focusing on their interpreters. The implementation is focused on representing the operational semantics in a clear and (hopefully) clean manner, so there is no virtual machine (VM) or bytecode representation of the language. We do intend to implement that, but it will be on the next step. I am gathering documentation about VM's and interpreters.

Another thing I have been doing in our compilers is to get rid of the Visitor pattern. It is one of those things that trying to generalize makes the code worse (at least in how we are using it)! To solve the same problem I have developed a dispatching engine that takes care of what Double Dispatch did. Which reminds me, Double Dispatching is evil! Don't do it. It adds circular dependencies and makes the entangles concerns. Forget about that hack.

Finally, my interest in LLVM has raised. Unfortunately, it has no support for concurrency. This would be very handy for MIL. I was also looking at Parrot. The paper On the Architecture of the Parrot virtual machine provides a good overview on the VM's internals. Unfortunately, the site is confusing and it is difficult to find what I was looking for (the PIR specification).

Sunday, June 15, 2008

Installing Ubuntu Hardy Heron (8.04) into a LG R405

I have previously blogged about Installing Ubuntu Gutsy Gibbon (7.10) into a LG R405. I have now updated the system up to Ubuntu Hardy Heron (8.04) and have some remaining issues.

WiFi support is available through NDISwrapper and with more reliability through madwifi. To setup NDISwrapper you can download the package ndisgtk and use the Windows' drivers from on of the laptop's CDs.

Regarding madwifi, if you follow ticker #1192, you will find out version 0.9.5 will bring support for the wireless chipset AR2425. Meanwhile, you can download the driver from a SVN branch at the madwifi's repositories. NetworkManager works best with madwifi's driver (this includes support for eduroam).

Bluetooth got broken in the update (for some Nokia's mobiles). If you follow launchpad's bug #211252, you will notice that you may install Debian's SID bluez-utils to fix the issue (I have left a comment in the ticket stating just that). Fortunately, the regression has been fixed upstream. The fix, however, has not been applied in the Ubuntu package.

Sleep and hibernate work. Well... mostly. After waking up the sound dies (see Ubuntu's bug #200210). I have not bothered with scavenging the net to a fix/bug report.

The (graphical) intel driver has been improved (it is no longer blacklisted in compiz). Power management is better, since the brightness is not crazy anymore.

Concluding, support is still sub-optimal. Sadly, the alternatives are scarse.

Friday, May 30, 2008

Simple Django handlers

Or, an example about introspection targeting Python's functions.

I really like the way CherryPy maps GET parameters to the parameters of the handling function (usually, methods). I miss this mapping in Django, therefore I implemented it. I am "lazy" and I did not search Django's API for something related to this — I did this for pleasure.

Anyway, I have implemented a decorator, params_from_GET that adds this functionality to Django-handlers. You have to read the docstring to read the usage.

Code dump (licensed under public domain):

import inspect
def get_func_args(func):
    """
    Returns a generators of pairs (parameter name, default value)
    of the target function.
    """
    (args, varargs, varkw, defaults) = inspect.getargspec(func)
    if defaults is None:
        defaults = ()
    offset = len(args) - len(defaults)
    return args[:offset], dict(zip(args[offset:], defaults))

def params_from(func, method, default_value=''):
    """
    Returns a decorator, see params_from_GET.
    """
    # get the default params
    args, params = get_func_args(func)
    if args[0] != "request":
        raise TypeError("First parameters needs to be 'request'")
    for param in args[1:]:
        params[param] = default_value=''
    
    def wrapper(request, **orig_kwargs):
        # copy the parameters
        kwargs = params.copy()
        # get the map for the defined method, e.g GET
        method_dict = getattr(request, method)
        # set the request object
        kwargs['request'] = request
        for key in params:
            # fill with values that were sent by the user
            if key in method_dict:
                kwargs[key] = method_dict[key]
        kwargs.update(orig_kwargs)
        return func(**kwargs)
    return wrapper

def params_from_GET(func):
    """
    The decorator pics up a handler function and fetches the
    values from the GET map.

    For example:

    @params_from_GET
    handler(request, foo, bar):
       pass

    Is the same as:

    handler(request):
       foo = request.GET('foo', '')
       bar = request.GET('bar', '')
    """
    return params_from(func, 'GET')

Update: added support for the keyword arguments that may be passed to the dispatcher by urls.py.

Monday, May 26, 2008

Compiling the π-calculus into a Multithreaded Typed Assembly Language

I have just uploaded: Compiling the π-calculus into a Multithreaded Typed Assembly Language. Tiago Cogumbreiro, Francisco Martins, and Vasco T. Vasconcelos. In Proceedings of Places08 - Programming Language Approaches to Concurrency and Communication-cEntric Software. 2008.

This is the paper I will be presenting in Oslo!

Friday, May 09, 2008

Accepted in PLACES '08

I am really happy to announce that my first publication was accepted in the workshop PLACES '08! Thanks to GLOSS (a research team from LaSIGE) I will be presenting the paper in Oslo, Norway. The subject is about the formalization of the compiler from the π-calculus into MIL.

Accepted in the TiC '08 Summer School

I am going to attend the Second International School on Trends in Concurrency! Thanks to a generous grant from Intel my registration fee was lowered. The program looks promissing. The focus is leaning towards technical aspects of concurrency.

This will be my first summer school. My hopes are really high ;) I am really curious and excited about the people I am going to meet! It will also be a good oportunity to know a new city, Prague.

Saturday, March 29, 2008

Django and Unicode

I have made this patch against Django SVN r7379, please have a look at it:

--- /usr/lib/python2.5/site-packages/django/http/__init__.py    2008-03-29 22:24:02.000000000 +0000
+++ __init__.py 2008-03-29 22:23:03.000000000 +0000
@@ -360,10 +360,8 @@
         return self
 
     def next(self):
-        chunk = self._iterator.next()
-        if isinstance(chunk, unicode):
-            chunk = chunk.encode(self._charset)
-        return str(chunk)
+        chunk = unicode(self._iterator.next())
+        return chunk.encode(self._charset)
 
     def close(self):
         if hasattr(self._container, 'close'):

Before the patch, a chunk (the reply that will be sent by the HTTP server to the client) is encoded with the charset defined in our project (self._charset) only if it is an unicode object, otherwise, it will happily convert to a string using the system's encoding (by using the function str), which was resulting in a UnicodeEncodeError exception that would break Django.

If you want to make sure that the reply you are sending, through your HTTPResponse, is encoded into a string using the project's encoding, then convert it first into a unicode object. If my patch is accepted, though, this will be done automatically for you.

Oh, by the way, I am enjoying Django. I am using it to create REST web-services. It is being an enjoying and out-of-your-face experience.

Thursday, February 21, 2008

Serpentine is not default on Ubuntu anymore

I am sure they have their reasons. But here is an article about the switch at Linux.com. The conclusion of the article, however, does not seem very coherent.

Monday, January 14, 2008

What is Continuation Passing Style (CPS)

Introduction

I remember trying to learn Continuation Passing Style and having difficulty trying to grasp this concept. I think the problem I had was not understanding the motivation. I did not understand why this was important, what problem was it trying to solve. This article tries to shed some light on the subject.

Motivation

Stack based machines have the concept of call-and-return: at any time, a program can call a number of instructions (e.g. a function), and then return to the point of call. This enables a hierarchical composition of abstractions that are represented by blocks of code (e.g. functions). On these machines, blocks of code may communicate using the stack, for example the parameters of a function are, usually, passed through a stack. Higher level languages abstract the communication between blocks of code that uses stacks, expressing them as parameters or as the return value.

Register machines, however, have no stack. In these machines continuation passing style is a more natural way to program. Because there is no stack to control where to go after a code block ends, if you want to simulate a call-and-return, then, when you call a code block, you have to pass where to return to as well. The code block being called must cooperate with the caller, it must explicitly call the code block to execute when it itself is finished. Continuation passing style, is therefore a convention.

An example

Consider a simple assembly language (defined in BNF) that targets a register based machine, where you can group instructions into code bocks, delimited by curly braces, and identify them with a certain name:

<program> ::= <program> <code-block>
            | <code-block>

<code-block> ::= <identifier> "{" <intructions> "}"
               | <identifier> "{" "}"

<instructions> ::= <instructions> <instruction> | <instruction>

<instruction> ::= <register> ":=" <value>
                | <register> ":=" <register> <binop> <value>
                | print <value>
                | if <register> = <value> jump <value>
                | if <register> != <value> jump <value>
                | jump <value>

<value> ::= <number> | <register> | <identifier>

Comments start with ";"

This is an example of a simple program that places the value 5 in register r1, increments it to 6 and prints it on the screen:

main {
 r1 := 5
 r1 := r1 + r1
 print r1
}

Now we split this program into three blocks of code, placing each step into a block of code:

main {
 r1 := 5
 jump inc
}
inc {
 r1 := r1 + r1
 print r1
 jump finish
}
finish {
 print r1
}

Because of this restructuration, after a step is finished we jump to the next block of code (i.e. step). Now, if we want to reuse the block of code inc, we must abstract the label of the next block of code. Let us abstract it in the register r2:

main {
 r1 := 5
 r2 := finish
 jump r1
}
inc {
 r1 := r1 + r1
 jump r2
}
finish {
 print r1 -- will output '6'
}

The block of code inc now expects that a label is provided in the second register, which will be used to jump to after its computation finishes.

Another example: the factorial

Consider an implementation of the factorial function:

fact {
 r3 := 1
 jump fact_aux
}
fact_aux {
 if r1 = 0 jump fact_finish
 if r1 = 1 jump fact_finish

 r3 := r3 * r1
 r1 := r1 - 1
 jump fact_aux
}
fact_finish {
 r3 := r1
 jump r2
}

The block of code fact_aux expects three registers, the first must hold the actual parameter of the factorial function, the second must hold the continuation label, and the third must hold the result of the last call. In the first two instructions we verify if we are in the base of the recursion; if so, then we jump to fact_finish, where we move the result into register r1 and then jump to the continuation held in register r2. If we are in an intermediate step, then we update the value of the result, decrement the value of the factorial, and, finally, jump to fact_aux.

Conclusion

Continuation passing style is ackward to reason about. Our brain is more used to divide and conquer. There are, however, examples of successful projects that use this notion as the foundation of its framework (like Python's Twisted). Continuation passing style and tail recursion enable the definition of stackless machines, making functional languages very efficient. Once the cornerstone is grasped (i.e. there is no return), continuation passing style is easy to master.

Saturday, January 12, 2008

Dynamic Interfaces

This week Vasco T. Vasconcelos gave a very interesting talk in GLOSS (a research tram of LaSIGE) about Dynamic Interfaces. IMO, this paper tackles some problems also tackled by the State pattern, although in different levels.

Introduction to MIL (part 1)

The final work of my graduation was the creation of a compiler for the π-calculus that generated MIL. This is a small example on what is MIL.

MIL is an assembly language that looks better (syntactically) than x86 assembly. The usual assembly operations are supported:

-- this is a comment
{-
 A multi-line
 comment
-}
r1 := 1       -- copying values to a register
r1 := r1 + r2 -- arithmetics
r1 := r2[0]   -- loading a value from a tuple
r2[0] := r1   -- storing a value into a tuple
if r1 = 0
  jump label1 -- conditional jump
jump label2   -- usual jump

Processor registers have the format rn, where n is a non-negative integer (a natural number). Notice that, currently, the language only supports literals in offsets (load and store operations); bounds are checked at compile time.

This language is typed. There is support for simple strings and integers. Instructions are grouped in code blocks that are delimited by curly braces. Code blocks are identified by a label and a type, specifying the type of each value stored in the registers when the processor is executing it. For example, in order execute code block cb1 (to jump into it) register r1 must hold a value of type integer:

cb1 (r1: int) {
 r1 := r1 + 1 -- we can safely add one to this register
 --- some more code
}

The code block main is, as usual, the first code block to be executed. This code is valid:

main() {
  r1 := 1
  jump cb1
}
cb1 (r1: int) {
  -- ...
}

Yet, this code block will not compile,

main() {
  r1 := "foo"
  jump cb1
}
cb1 (r1: int) {
  -- ...
}

because r1 holds a string, when it should hold an integer.

But typed assembly languages are not new. MIL also tackles the problem of concurrency. The machine executing this language contains various processors and a single shared main memory. Now I show you how to fork (i.e., to create) a thread:

main() {
  fork t1
  fork t2
  yield 
}
t1 () {
  r1 := 10
  -- ...
}
t2 () {
  r2 := 20
  -- ...
}

The first thread executes the code block main that forks a new thread that will execute the code block t1, then it forks a new thread that will execute the code block t2, and, finally, yield the control of the processor, terminating this execution thread. As we can observe, MIL uses a cooperative threading model — there is no context switching.

Next post about MIL will feature memory allocation and locking.

Friday, November 16, 2007

Ungeeking or getting unhypenotized?

As I get older I am reacting less and less to technology. What makes me tick has stopped being the desktop, or new open source applications. Now what makes me tick is compilers, languages, concurrency, global computing, and, lately, networks of sensors. Things like Codebits, or the new Mac release just make me yawn. I remember when I scanned Freshmeat every day, read Planet GNOME every day. Now all these time consuming things are slowly being left behind.

Maybe it's one of those times in life. On the one hand my awareness of the world is decreasing. On the other hand I'm much more focused in university. Maybe what I am learning has become more interesting than everything else, contrary to what used to be.

NestedVM: from unsafe native code to safe bytecode

NestedVM is one of those projects that makes me go "Snap!"

Existing techniques for using code written in an unsafe language within a safe virtual machine generally involve transformations from one source code language (such as C, Pascal, or Fortran) to another (such as Java) which is then compiled into virtual machine bytecodes. We present an alternative approach which translate MIPS binaries produced by any compiler into safe virtual machine bytecodes. This approach offers four key advantages over existing techniques: it is language agnostic, it offers bug-for-bug compiler compatibility, requires no post-translation human intervention, and introduces no build process modifications.

This is an excerpt of the paper Complete Translation of Unsafe Native Code to Safe Bytecode, from Brian Alliet and from Adam Megacz. The paper offers a rapid overview of the motivation for the technique and its application (NestedVM). I would love to see a more in-depth document describing a formal definition of the translation, but alas.

Thursday, November 15, 2007

Applications I can't live without

texlive-*
I can't be bother with missing space when I'm working with LaTex, I can handle the 1GB of storage.
cvs
some projects that I work on use CVS (*sigh*)
svn
some projects that I work on use SVN
bzr{,-gtk}
my favorite VCS
meld
makes working with VCS bareable
emacs-snapshot-gtk
pretty emacs
eclipse
can't program in Java without it
sun-java6-{jre,doc,plugin}
Sun's Java 6 (some features I need are missing in IcedTea)
subclipse
Integration of SVN in Eclipse
maven
great tool for Java projects
gstm
SSH Tunnel handling made easy

Friday, November 09, 2007

Installing prooftree in Ubuntu

Download the bundled zip from the package proofs to your desktop. Now open the terminal and type:

cd /usr/share/texmf-texlive/tex/latex
sudo unzip ~/Desktop/taylor.zip
sudo mktexlsr

This procedure should work on all Ubuntu versions that are using TeX Live.

Related posts:

Monday, November 05, 2007

Hiding the welcome screen of Emacs

To hide the welcome screen of Emacs you need to paste this into your ~/.emacs:

(setq inhibit-splash-screen t)

Via a deeply burried comment in Pretty Emacs Reloaded.

Sunday, November 04, 2007

Installing Ubuntu Gutsy Gibbon (7.10) into a LG R405

I have bought — actually, it was kind of a present — my first laptop: a LG R405. Because I am not that geeky, I didn't even bother to checkout what the famous Windows Vista looks like and promptly installed Ubuntu on my machine, removing the other OS.

Installation went smoothly. What didn't work out of the box?

  • wireless not supported by the default drivers: I followed a tutorial from the forums called HOWTO: Atheros AR5007EG on Feisty Fawn (with ndiswrapper) and it turned out OK. The problem was: how do I know my laptop has a chipset named AR5007EG (lspci reports an AR5006EG!)?
  • bluetooth support is poor and falky: although a bluetooth icon appeared in my desktop I could not send files to my laptop (I had to google for an answer and understand I had to install bluetooth-gnome). I wanted bluetooth to synchronize the contacts on my Nokia 6680 with my laptop, I still have no idea how to configure the criptic kitchensink :(

About the Bluetooth Preferences. I do not understand what are the Services; shouldn't all the services be turned on? There is a section called Input Devices which I could crash just by connecting to a device. What is this section for? On the General pane, what is a class of device, what the hell is that option for? On the first pane, how do I bond from the laptop to a device? Why is it only from the device to my laptop? Why do I need to specify the class of device, does anyone care about this?

Monday, October 29, 2007

Homepage back up

This past month of October school has started. Since I am also starting a whole new life, in alot of aspects, this takes a toll in my free time (read: very little time to blahg).

One thing that was annoying me was the outage of my homepage. I was not annoyed with the hosting, since it was kindly donated to me. I was annoyed with me, because I didn't find a better solution while the hosting was offline (this month of October). I've fixed that problem already, but with it comes the ads.

I am using FWHA. For a free service (with ads) it's alright. I can only afford to pay about €15 per year, but my needs are very little: low bandwith requirements, static HTML, and about 10MB of free space. Can anyone point me out to a good hosting solution? One thing I dislike about FWHA is that it obligates the usage of the sub domain 'www'.

Update: oh, another big requirement for the hosting service is the possibility to add CX records (whatever that is) in order for me to continue using the domain blog.irrepupavel.com. That is to say that the address blog.irrepupavel.com does not work. Please use irrepupavel.blogspot.com to access my blog.

Friday, August 24, 2007

Migration [mostly] complete!

Thanks to André Medeiros, who kindly offers me the web space to do it, I have a new web presence. The front page that used to be generated from my blog's feed is now replaced by the about page. The blog is now a sub domain of my home page and integrated with the rest of the site.

You can stop using the domain s1x.homelinux.net (which will be offline in a few days) and the domain irrepupavel.blogspot.com, since they were moved to irrepupavel.com and blog.irrepupavel.com respectively.

New domain

My homepage has a new domain: irrepupavel.com!