From 35f2699eb34aabc5069bb93e1e3ebe74cc5f51fa Mon Sep 17 00:00:00 2001 From: Alex Efros Date: Sun, 5 Apr 2015 02:34:02 +0300 Subject: [PATCH 1/5] add Limbo: language, samples --- lib/linguist/languages.yml | 7 ++++++ samples/Limbo/cat.b | 48 ++++++++++++++++++++++++++++++++++++++ samples/Limbo/lock.b | 26 +++++++++++++++++++++ samples/Limbo/lock.m | 13 +++++++++++ 4 files changed, 94 insertions(+) create mode 100644 samples/Limbo/cat.b create mode 100644 samples/Limbo/lock.b create mode 100644 samples/Limbo/lock.m diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 2833bbd2..398bb834 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1663,6 +1663,13 @@ LilyPond: - .ily ace_mode: text +Limbo: + type: programming + extensions: + - .b + - .m + ace_mode: text + Liquid: type: markup extensions: diff --git a/samples/Limbo/cat.b b/samples/Limbo/cat.b new file mode 100644 index 00000000..5b9e3b5b --- /dev/null +++ b/samples/Limbo/cat.b @@ -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), ""); + } +} + +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"; + } +} diff --git a/samples/Limbo/lock.b b/samples/Limbo/lock.b new file mode 100644 index 00000000..8b51e4f9 --- /dev/null +++ b/samples/Limbo/lock.b @@ -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() +{ +} diff --git a/samples/Limbo/lock.m b/samples/Limbo/lock.m new file mode 100644 index 00000000..ffd818c5 --- /dev/null +++ b/samples/Limbo/lock.m @@ -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(); +}; From f016867e1ae75e2d21cb7e8f2a75d32bda72bc71 Mon Sep 17 00:00:00 2001 From: Alex Efros Date: Sun, 5 Apr 2015 02:56:36 +0300 Subject: [PATCH 2/5] Limbo: fix tm_scope --- lib/linguist/languages.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 398bb834..eb698aa6 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1668,6 +1668,7 @@ Limbo: extensions: - .b - .m + tm_scope: none ace_mode: text Liquid: From bbea29be558f121f297e420b8557afe7ba88691f Mon Sep 17 00:00:00 2001 From: Alex Efros Date: Sun, 5 Apr 2015 03:03:45 +0300 Subject: [PATCH 3/5] add Limbo to test_languages --- test/test_language.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_language.rb b/test/test_language.rb index f3847a77..32eb4341 100644 --- a/test/test_language.rb +++ b/test/test_language.rb @@ -188,7 +188,7 @@ class TestLanguage < Minitest::Test assert_equal [], Language.find_by_extension('foo.rb') assert_equal [Language['Ruby']], Language.find_by_extension('rb') assert_equal [Language['Ruby']], Language.find_by_extension('.rb') - assert_equal [Language['M'], Language['MUF'], Language['Mathematica'], Language['Matlab'], Language['Mercury'], Language['Objective-C']], Language.find_by_extension('.m') + assert_equal [Language['Limbo'], Language['M'], Language['MUF'], Language['Mathematica'], Language['Matlab'], Language['Mercury'], Language['Objective-C']], Language.find_by_extension('.m') end def test_find_all_by_extension From c97c10623bd0947d7725c074a909c23aaab676ec Mon Sep 17 00:00:00 2001 From: Alex Efros Date: Sun, 5 Apr 2015 18:08:20 +0300 Subject: [PATCH 4/5] add .b Brainfuck sample --- samples/Brainfuck/factor.b | 195 +++++++++++++++++++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 samples/Brainfuck/factor.b diff --git a/samples/Brainfuck/factor.b b/samples/Brainfuck/factor.b new file mode 100644 index 00000000..43f06ba2 --- /dev/null +++ b/samples/Brainfuck/factor.b @@ -0,0 +1,195 @@ +* factor an arbitrarily large positive integer +* +* Copyright (C) 1999 by Brian Raiter +* under the GNU General Public License + +>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>- + +* +* read in the number +* + +<<<<<<<<<+ +[-[>>>>>>>>>>][-]<<<<<<<<<<[[->>>>>>>>>>+<<<<<<<<<<]<<<<<<<<<<] + >>>>>>>>>>,----------] +>>>>>>>>>>[------------------------------------->>>>>>>>>->] +<[+>[>>>>>>>>>+>]<-<<<<<<<<<<]- + +* +* display the number and initialize the loop variable to two +* + +[>++++++++++++++++++++++++++++++++++++++++++++++++. + ------------------------------------------------<<<<<<<<<<<] +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++. +--------------------------.[-] +>>>>>>>>>>>>++<<<<+ + +* +* the main loop +* + +[ [-]>> + + * + * make copies of the number and the loop variable + * + + [>>>>[-]>[-]>[-]>[-] + >[-]>[-] + <<<<<<<[->>>+>+<<<<]>>>>>>>>] + <<<<<<<<<<[>>>>>>[-<<<<+>>>>]<<<<<<<<<<<<<<<<]>>>>>>>>>> + [>[->>>+>>+<<<<<]>>>>>>>>>] + <<<<<<<<<<[>>>>>>[-<<<<<+>>>>>]<<<<<<<<<<<<<<<<]>>>>>>>>>> + + * + * divide the number by the loop variable + * + + [>>>[-]>>>[-]>[-]>>>] initialize + <<<<<<<<<<[<<<<<<<<<<] + >>>>>>>>>[-]>>>>>>>+<<<<<<<<[+]+ + [ ->> double divisor until above dividend + [>>>>>>[->++<]>>>>]<<<<<<<<<< + [>>>>>>>>[-]>[-] + <<<<[->>>++<<<]<<<<<<<<<<<<<<<]>>>>>>>>>> + [>>>>>>>>[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->+< + [->--------->>>>>>>>>+<<<<<<<<<<[->+<]]]]]]]]]]]>>] + <<<<<<<<<<[>>>>>>>>>[-<+<<<+>>>>]<<<<<<<<<<<<<<<<<<<]>>>>>>>>>> + [>>>>>>>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+> + [-<--------->>>>>>>>>>>+<<<<<<<<<<[-<+>]]]]]]]]]]]>>>] + <<<<<<<<<< + [>>>>[->>>+>>+<<<<<]<<<<<<<<<<<<<<] + >>>>>>>>>>[>>>>>>>[-<<<+>>>]>>>]<<<<<<<<<< + [>>>>>>>>[->-<]> + [<<<<<<<<<[<[-]>>>>>>>>>>[-<<<<<<<<<<+>>>>>>>>>>]<<<<<<<<<<<<<<<<<<<] + >>>>>>>>>>>>>>>>>>>] + <<<<<<<<<<<<<<<<<<<] + >>>>>>>>>[+[+[+[+[+[+[+[+[+[+[[-]<+>]]]]]]]]]]]< + ] + >>>>>>>> + [ subtract divisor from dividend + <<<<<< + [>>>>>>>>[-]>[-]<<<<<[->>>+>+<<<<]>>>>>>]<<<<<<<<<< + [>>>>>>>>[-<<<<+>>>>]<<<[->>>+>+<<<<]<<<<<<<<<<<<<<<]>>>>>>>>>> + [>>>>>>>>>[-<<<<+>>>>]>]<<<<<<<<<< + [>>>>>>>>[-<->]<<<<<<<<<<<<<<<<<<]>>>>>>>>>> + [>>>>>>>[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->+< + [++++++++++[+>-<]>>>>>>>>>>-<<<<<<<<<<]]]]]]]]]]]>>>] + >>>>>>>+ + [ if difference is nonnegative then + [-]<<<<<<<<<<<<<<<<< replace dividend and increment quotient + [>>>>[-]>>>>[-<<<<+>>>>]<<[->>+<<]<<<<<<<<<<<<<<<<]>>>>>>>>>> + [>>>>>>>>[->+<<<+>>]>>]<<<<<<<<<< + [>>>[->>>>>>+<<<<<<]<<<<<<<<<<<<<]>>>>>>>>>> + [>>>>>>>>>[-<<<<<<+>>>>>>[-<<<<<<+>>>>>> + [-<<<<<<+>>>>>>[-<<<<<<+>>>>>> + [-<<<<<<+>>>>>>[-<<<<<<+>>>>>> + [-<<<<<<+>>>>>>[-<<<<<<+>>>>>> + [-<<<<<<+>>>>>>[-<<<<<<--------->>>>>>>>>>>>>>>>+<<<<<<<<<< + [-<<<<<<+>>>>>>]]]]]]]]]]]>] + >>>>>>> + ] halve divisor and loop until zero + <<<<<<<<<<<<<<<<<[<<<<<<<<<<]>>>>>>>>>> + [>>>>>>>>[-]<<[->+<]<[->>>+<<<]>>>>>]<<<<<<<<<< + [+>>>>>>>[-<<<<<<<+>>>>>>>[-<<<<<<<->>>>>>+> + [-<<<<<<<+>>>>>>>[-<<<<<<<->>>>>>+> + [-<<<<<<<+>>>>>>>[-<<<<<<<->>>>>>+> + [-<<<<<<<+>>>>>>>[-<<<<<<<->>>>>>+> + [-<<<<<<<+>>>>>>>]]]]]]]]]<<<<<<< + [->>>>>>>+<<<<<<<]-<<<<<<<<<<] + >>>>>>> + [-<<<<<<<<<<<+>>>>>>>>>>>] + >>>[>>>>>>>[-<<<<<<<<<<<+++++>>>>>>>>>>>]>>>]<<<<<<<<<< + [+>>>>>>>>[-<<<<<<<<+>>>>>>>>[-<<<<<<<<->>>>>+>>> + [-<<<<<<<<+>>>>>>>>[-<<<<<<<<->>>>>+>>> + [-<<<<<<<<+>>>>>>>>[-<<<<<<<<->>>>>+>>> + [-<<<<<<<<+>>>>>>>>[-<<<<<<<<->>>>>+>>> + [-<<<<<<<<+>>>>>>>>]]]]]]]]]<<<<<<<< + [->>>>>>>>+<<<<<<<<]-<<<<<<<<<<] + >>>>>>>>[-<<<<<<<<<<<<<+>>>>>>>>>>>>>]>> + [>>>>>>>>[-<<<<<<<<<<<<<+++++>>>>>>>>>>>>>]>>]<<<<<<<<<< + [<<<<<<<<<<]>>>>>>>>>> + >>>>>> + ] + <<<<<< + + * + * make copies of the loop variable and the quotient + * + + [>>>[->>>>+>+<<<<<]>>>>>>>] + <<<<<<<<<< + [>>>>>>>[-<<<<+>>>>]<<<<<[->>>>>+>>+<<<<<<<]<<<<<<<<<<<<] + >>>>>>>>>>[>>>>>>>[-<<<<<+>>>>>]>>>]<<<<<<<<<< + + * + * break out of the loop if the quotient is larger than the loop variable + * + + [>>>>>>>>>[-<->]< + [<<<<<<<< + [<<[-]>>>>>>>>>>[-<<<<<<<<<<+>>>>>>>>>>]<<<<<<<<<<<<<<<<<<] + >>>>>>>>>>>>>>>>>>]<<<<<<<<<<<<<<<<<<] + >>>>>>>>[>-<[+[+[+[+[+[+[+[+[+[[-]>+<]]]]]]]]]]]>+ + + [ [-] + + * + * partially increment the loop variable + * + + <[-]+>>>>+>>>>>>>>[>>>>>>>>>>]<<<<<<<<<< + + * + * examine the remainder for nonzero digits + * + + [<<<<<<[<<<<[<<<<<<<<<<]>>>>+<<<<<<<<<<]<<<<] + >>>>>>>>>>>>>>>>>>>>[>>>>>>>>>>]<<<<<<<<<<[<<<<<<<<<<] + >>>>- + + [ [+] + + * + * decrement the loop variable and replace the number with the quotient + * + + >>>>>>>>-<<[>[-]>>[-<<+>>]>>>>>>>]<<<<<<<<<< + + * + * display the loop variable + * + + [+>>[>>>>>>>>+>>]<<-<<<<<<<<<<]- + [>>++++++++++++++++++++++++++++++++++++++++++++++++. + ------------------------------------------------<<<<<<<<<<<<] + ++++++++++++++++++++++++++++++++.[-]>>>> + + ] + + * + * normalize the loop variable + * + + >>>>>> + [>>[->>>>>+<<<<<[->>>>>+<<<<< + [->>>>>+<<<<<[->>>>>+<<<<< + [->>>>>+<<<<<[->>>>>+<<<<< + [->>>>>+<<<<<[->>>>>+<<<<< + [->>>>>+<<<<<[->>>>>--------->>>>>+<<<<<<<<<< + [->>>>>+<<<<<]]]]]]]]]]]>>>>>>>>] + <<<<<<<<<<[>>>>>>>[-<<<<<+>>>>>]<<<<<<<<<<<<<<<<<] + >>>>>>>>> + + ]< + +]>> + +* +* display the number and end +* + +[>>>>>>>>>>]<<<<<<<<<<[+>[>>>>>>>>>+>]<-<<<<<<<<<<]- +[>++++++++++++++++++++++++++++++++++++++++++++++++.<<<<<<<<<<<] +++++++++++. From c3288543afdbb69147468338f0a78a1a24f9f6a9 Mon Sep 17 00:00:00 2001 From: Alex Efros Date: Mon, 6 Apr 2015 20:17:52 +0300 Subject: [PATCH 5/5] add heuristic for Limbo --- lib/linguist/heuristics.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index 205ef11c..f8a6320e 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -184,7 +184,7 @@ module Linguist end end - disambiguate "M", "MUF", "Mathematica", "Matlab", "Mercury", "Objective-C" do |data| + disambiguate "Limbo", "M", "MUF", "Mathematica", "Matlab", "Mercury", "Objective-C" do |data| if ObjectiveCRegex.match(data) Language["Objective-C"] elsif data.include?(":- module") @@ -197,6 +197,8 @@ module Linguist Language["Mathematica"] elsif /^\s*%/.match(data) Language["Matlab"] + elsif /^\w+\s*:\s*module\s*{/.match(data) + Language["Limbo"] end end