add Limbo: language, samples

This commit is contained in:
Alex Efros
2015-04-05 02:34:02 +03:00
parent 3e06b95f98
commit 35f2699eb3
4 changed files with 94 additions and 0 deletions

View File

@@ -1663,6 +1663,13 @@ LilyPond:
- .ily
ace_mode: text
Limbo:
type: programming
extensions:
- .b
- .m
ace_mode: text
Liquid:
type: markup
extensions:

48
samples/Limbo/cat.b Normal file
View File

@@ -0,0 +1,48 @@
implement Cat;
include "sys.m";
sys: Sys;
include "draw.m";
Cat: module
{
init: fn(ctxt: ref Draw->Context, argv: list of string);
};
stdout: ref Sys->FD;
init(nil: ref Draw->Context, args: list of string)
{
sys = load Sys Sys->PATH;
stdout = sys->fildes(1);
args = tl args;
if(args == nil)
args = "-" :: nil;
for(; args != nil; args = tl args){
file := hd args;
if(file != "-"){
fd := sys->open(file, Sys->OREAD);
if(fd == nil){
sys->fprint(sys->fildes(2), "cat: cannot open %s: %r\n", file);
raise "fail:bad open";
}
cat(fd, file);
}else
cat(sys->fildes(0), "<stdin>");
}
}
cat(fd: ref Sys->FD, file: string)
{
buf := array[Sys->ATOMICIO] of byte;
while((n := sys->read(fd, buf, len buf)) > 0)
if(sys->write(stdout, buf, n) < n) {
sys->fprint(sys->fildes(2), "cat: write error: %r\n");
raise "fail:write error";
}
if(n < 0) {
sys->fprint(sys->fildes(2), "cat: error reading %s: %r\n", file);
raise "fail:read error";
}
}

26
samples/Limbo/lock.b Normal file
View File

@@ -0,0 +1,26 @@
implement Lock;
include "sys.m";
sys: Sys;
include "lock.m";
Semaphore.obtain(l: self ref Semaphore)
{
l.c <-= 0;
}
Semaphore.release(l: self ref Semaphore)
{
<-l.c;
}
Semaphore.new(): ref Semaphore
{
l := ref Semaphore;
l.c = chan[1] of int;
return l;
}
init()
{
}

13
samples/Limbo/lock.m Normal file
View File

@@ -0,0 +1,13 @@
Lock: module
{
PATH: con "/dis/lib/lock.dis";
Semaphore: adt {
c: chan of int;
obtain: fn(nil: self ref Semaphore);
release: fn(nil: self ref Semaphore);
new: fn(): ref Semaphore;
};
init: fn();
};