mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 09:40:21 +00:00
add Limbo: language, samples
This commit is contained in:
@@ -1663,6 +1663,13 @@ LilyPond:
|
|||||||
- .ily
|
- .ily
|
||||||
ace_mode: text
|
ace_mode: text
|
||||||
|
|
||||||
|
Limbo:
|
||||||
|
type: programming
|
||||||
|
extensions:
|
||||||
|
- .b
|
||||||
|
- .m
|
||||||
|
ace_mode: text
|
||||||
|
|
||||||
Liquid:
|
Liquid:
|
||||||
type: markup
|
type: markup
|
||||||
extensions:
|
extensions:
|
||||||
|
|||||||
48
samples/Limbo/cat.b
Normal file
48
samples/Limbo/cat.b
Normal 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
26
samples/Limbo/lock.b
Normal 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
13
samples/Limbo/lock.m
Normal 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();
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user