Xoc, yaspl (yet another SPL)
bearophile
bearophileHUGS at lycos.com
Tue Aug 17 11:08:56 PDT 2010
Justin Johansson:
> Has anyone here come across Xoc before?
Never seen it before. It looks interesting.
The good thing of LLVM is that there is a bit higher probability that similar works become integrated with it, instead of just dying as hundreds of similar experiments have done in the last thirty years or so.
More info here:
http://pdos.csail.mit.edu/xoc/
A paper about it:
http://pdos.csail.mit.edu/xoc/asplos08.pdf
The xoc-unstable.tgz-1\xoc-unstable\zeta\xoc\x directory inside here shows most of the examples discussed in the paper:
http://pdos.csail.mit.edu/xoc/xoc-unstable.tgz
Even the examples look interesting, like the extension "Sparse" written by Linux to avoid bugs when writing the kernel...
As example, I think this is the code necessary to add >>> and <<< to C:
from xoc import *;
extend grammar C99
{
expr: expr "<<<" expr [Shift]
| expr ">>>" expr [Shift];
}
extend attribute
type(term: C.expr): C.type
{
switch(term){
case `{\a <<< \b} || `{\a >>> \b}:
if(a.type.isinteger && b.type.isinteger)
return a.type.integerpromotion;
errorast(term, "non-integer rotate");
return `C.type{int};
}
return default(term);
}
extend attribute
compiled(term: C.expr): COutput.expr
{
switch(term){
case `{\a <<< \b}:
n := a.type.sizeof * 8;
term = `C.expr{
({
\(a.type.unsigned) x = \a;
\(b.type) y = \b;
(x << y) | (x >> (\n-y));
})
};
return term.compiled;
case `{\a >>> \b}:
n := term.type.sizeof * 8;
term = `C.expr{ \a <<< (\n-\b) };
return term.compiled;
}
return default(term);
}
Bye,
bearophile
More information about the Digitalmars-d
mailing list