p-lang 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +54 -0
- data/VERSION.yml +5 -0
- data/bin/p-lang +13 -0
- data/lib/p-lang.rb +24 -0
- data/lib/parser/ast.rb +168 -0
- data/lib/parser/nodes.rb +212 -0
- data/lib/parser/p-lang.treetop +197 -0
- data/lib/vm/environment.rb +51 -0
- data/lib/vm/pobject.rb +47 -0
- data/lib/vm/proc.rb +41 -0
- data/lib/vm/std/io.rb +17 -0
- data/lib/vm/vm.rb +211 -0
- data/test/helper.rb +10 -0
- data/test/test_parser.rb +26 -0
- data/test/test_parser_build.txt +72 -0
- data/test/test_parser_ok.txt +72 -0
- data/test/test_vm.rb +22 -0
- data/test/test_vm_programs.txt +37 -0
- data/test/test_vm_results.txt +37 -0
- metadata +119 -0
    
        data/test/helper.rb
    ADDED
    
    
    
        data/test/test_parser.rb
    ADDED
    
    | @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            require 'helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class TestParser < Test::Unit::TestCase
         | 
| 4 | 
            +
              
         | 
| 5 | 
            +
              EXPRESSIONS = File.readlines(File.join(File.dirname(__FILE__), "test_parser_ok.txt"))
         | 
| 6 | 
            +
              BUILT_EXPRESSIONS = File.readlines(File.join(File.dirname(__FILE__), "test_parser_build.txt"))
         | 
| 7 | 
            +
              
         | 
| 8 | 
            +
              context "The PLangParser" do
         | 
| 9 | 
            +
                setup do
         | 
| 10 | 
            +
                  @parser = PLangParser.new
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
                
         | 
| 13 | 
            +
                EXPRESSIONS.each_with_index do |expr, i|
         | 
| 14 | 
            +
                  should "parse the expression ##{i}" do
         | 
| 15 | 
            +
                    assert @parser.parse expr
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                EXPRESSIONS.each_with_index do |expr, i|
         | 
| 20 | 
            +
                  should "build the expression ##{i}" do
         | 
| 21 | 
            +
                    assert_equal eval(BUILT_EXPRESSIONS[i]), @parser.parse(expr).build.collect(&:to_sexp)
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
              
         | 
| 26 | 
            +
            end
         | 
| @@ -0,0 +1,72 @@ | |
| 1 | 
            +
            [[:+, [:literal, :integer, 1], [:literal, :integer, 2]]]
         | 
| 2 | 
            +
            [[:+,[:literal, :integer, 1],[:+, [:literal, :integer, 2], [:literal, :integer, 3]]]]
         | 
| 3 | 
            +
            [[:*, [:literal, :integer, 4], [:literal, :integer, 5]]]
         | 
| 4 | 
            +
            [[:/, [:literal, :integer, 4], [:literal, :integer, 2]]]
         | 
| 5 | 
            +
            [[:%, [:literal, :integer, 5], [:literal, :integer, 3]]]
         | 
| 6 | 
            +
            [[:+,[:literal, :integer, 1],[:*,[:literal, :integer, 2],[:/, [:literal, :integer, 3], [:literal, :integer, 5]]]]]
         | 
| 7 | 
            +
            [[:*,[:+,[:literal, :integer, 1],[:literal, :integer, 6]],[:literal, :integer, 5]]]
         | 
| 8 | 
            +
            [[:+,[:literal, :integer, 1],[:/,[:*, [:literal, :integer, 2], [:literal, :integer, 3]],[:-, [:literal, :integer, 5], [:literal, :integer, 1]]]]]
         | 
| 9 | 
            +
            [[:+,  [:literal, :decimal, 1.3],[:*,[:literal, :integer, 5],[:+, [:literal, :integer, 1], [:literal, :decimal, 1.568]]]]]
         | 
| 10 | 
            +
            [[:id, :xyz]]
         | 
| 11 | 
            +
            [[:>, [:literal, :integer, 1], [:literal, :integer, 2]]]
         | 
| 12 | 
            +
            [[:>=, [:id, :x], [:literal, :integer, 1]]]
         | 
| 13 | 
            +
            [[:<=, [:literal, :integer, 2], [:id, :b]]]
         | 
| 14 | 
            +
            [[:==, [:literal, :integer, 4], [:literal, :integer, 1]]]
         | 
| 15 | 
            +
            [[:<, [:literal, :integer, 2], [:id, :x]]]
         | 
| 16 | 
            +
            [[:object, :obj, []]]
         | 
| 17 | 
            +
            [[:object, :obj, [[:literal, :integer, 1], [:literal, :integer, 2], [:literal, :integer, 3]]]]
         | 
| 18 | 
            +
            [[:object,:obj,[[:+, [:literal, :integer, 1], [:literal, :integer, 2]], [:id, :x]]]]
         | 
| 19 | 
            +
            [[:object, :obj, [[:literal, :integer, 1], [:literal, :integer, 2]]]]
         | 
| 20 | 
            +
            [[:object, :obj, [[:id, :x], [:literal, :integer, 2], [:object, :other, []]]]]
         | 
| 21 | 
            +
            [[:object, :obj, [[:literal, :integer, 1]]]]
         | 
| 22 | 
            +
            [[:literal, :string, "teste"]]
         | 
| 23 | 
            +
            [[:literal, :char, "a"]]
         | 
| 24 | 
            +
            [[:if,[:>, [:id, :x], [:literal, :integer, 1]],[:literal, :string, "verdadeiro"],[:literal, :string, "falso"]]]
         | 
| 25 | 
            +
            [[:begin,[[:+,[:literal, :integer, 1],[:+, [:literal, :integer, 2], [:literal, :integer, 3]]],[:literal, :string, "oi"],[:<, [:literal, :integer, 2], [:literal, :integer, 3]],[:literal, :char, "a"]]]]
         | 
| 26 | 
            +
            [[:-,[:call, [:id, :sin], [[:*, [:literal, :integer, 2], [:id, :pi]]]],[:call, [:id, :cos], [[:*, [:literal, :integer, 2], [:id, :pi]]]]]]
         | 
| 27 | 
            +
            [[:call, [:id, :f], []]]
         | 
| 28 | 
            +
            [[:let, [:id, :x], [:literal, :integer, 1]]]
         | 
| 29 | 
            +
            [[:let,[:id, :x],[:+,[:literal, :integer, 1],[:+,[:literal, :integer, 2],[:+, [:literal, :integer, 3], [:literal, :integer, 4]]]]]]
         | 
| 30 | 
            +
            [[:let,[:id, :y],[:+,[:literal, :integer, 1],[:*, [:literal, :integer, 2], [:/, [:id, :x], [:literal, :integer, 2]]]]]]
         | 
| 31 | 
            +
            [[:let, [:id, :str], [:literal, :string, "string"]]]
         | 
| 32 | 
            +
            [[:let,[:id, :p1],[:call, [:id, :point], [[:literal, :integer, 1], [:literal, :integer, 2]]]]]
         | 
| 33 | 
            +
            [[:let,[:object, :obj, [[:id, :x]]],[:object, :obj, [[:literal, :integer, 1]]]]]
         | 
| 34 | 
            +
            [[:let, [:object, :obj, [[:id, :x], [:id, :t]]], [:id, :obj]]]
         | 
| 35 | 
            +
            [[:lambda, [[:id, :x]], [:id, :x], [],nil]]
         | 
| 36 | 
            +
            [[:lambda, [[:id, :x],[:id, :y]], [:+, [:id, :x], [:id, :y]], [],nil]]
         | 
| 37 | 
            +
            [[:lambda,[[:literal, :integer, 1],[:literal, :integer, 2],[:id, :x],[:object, :obj, [[:id, :x], [:id, :y]]]],[:literal, :integer, 1],[],nil]]
         | 
| 38 | 
            +
            [[:lambda,[[:id, :x]],[:id, :y],[[:let,[:id, :y],[:lambda, [[:id, :x]], [:+, [:id, :x], [:literal, :integer, 6]], [],nil]]],nil]]
         | 
| 39 | 
            +
            [[:lambda,[[:id, :x]],[:id, :y],[[:let,[:id, :y],[:lambda, [[:id, :x]], [:+, [:id, :x], [:literal, :integer, 6]], [], nil]],[:let,[:id, :z],[:lambda,[[:id, :x]],[:-, [:id, :x], [:literal, :integer, 6]],[],nil]],[:let, [:id, :k], [:literal, :integer, 1]]],nil]]
         | 
| 40 | 
            +
            [[:let, [:id, :x], [:lambda, [], [:literal, :integer, 1], [],nil]]]
         | 
| 41 | 
            +
            [[:let,[:id, :fibonacci],[:lambda,[[:literal, :integer, 1]],[:literal, :integer, 1],[],[:lambda,[[:literal, :integer, 2]],[:literal, :integer, 1],[],[:lambda,[[:id, :n]],[:+,[:call, [:id, :fibonacci], [[:-, [:id, :n], [:literal, :integer, 1]]]],[:call, [:id, :fibonacci], [[:-, [:id, :n], [:literal, :integer, 2]]]]],[],nil]]]]]
         | 
| 42 | 
            +
            [[:let,[:id, :str_list],[:object,:list,[[:literal, :char, "s"],[:object,:list,[[:literal, :char, "t"],[:object,:list,[[:literal, :char, "r"],[:object,:list,[[:literal, :char, "i"],[:object,:list,[[:literal, :char, "n"],[:object,:list,[[:literal, :char, "g"], [:object, :list, []]]]]]]]]]]]]]]]
         | 
| 43 | 
            +
            [[:let,[:id, :point],[:lambda,[[:id, :x], [:id, :y]],[:object, :point, [[:id, :x], [:id, :y]]],[],nil]]]
         | 
| 44 | 
            +
            [[:let,[:id, :point_x],[:lambda, [[:object, :point, [[:id, :x], [:id, :y]]]], [:id, :x], [],nil]]]
         | 
| 45 | 
            +
            [[:let,[:id, :point_y],[:lambda, [[:object, :point, [[:id, :x], [:id, :y]]]], [:id, :y], [],nil]]]
         | 
| 46 | 
            +
            [[:let,[:id, :point_sum],[:lambda,[[:object, :point, [[:id, :x1], [:id, :y1]]],[:object, :point, [[:id, :x2], [:id, :y2]]]],[:object,:point,[[:+, [:id, :x1], [:id, :x2]], [:+, [:id, :y1], [:id, :y2]]]],[],nil]]]
         | 
| 47 | 
            +
            [[:let,[:id, :sum],[:lambda, [[:id, :a], [:id, :b]], [:+, [:id, :a], [:id, :b]], [], nil]]]
         | 
| 48 | 
            +
            [[:let,[:id, :f],[:lambda,[[:id, :x]],[:begin,[[:let, [:id, :algo], [:id, :x]],[:*, [:id, :algo], [:id, :algo]],[:id, :algo]]],[], nil]]]
         | 
| 49 | 
            +
            [[:let,[:id, :f],[:lambda,[[:id, :x]],[:+, [:call, [:id, :f], [[:id, :x]]], [:call, [:id, :g], [[:id, :x]]]],[[:let,[:id, :f],[:lambda, [[:id, :x]], [:*, [:id, :x], [:id, :x]], [], nil]],[:let,[:id, :g],[:lambda,[[:id, :x]],[:/, [:id, :x], [:literal, :integer, 2]],[],nil]]],nil]]]
         | 
| 50 | 
            +
            [[:let,[:id, :f],[:lambda,[[:id, :x]],[:id, :y],[[:let, [:id, :y], [:*, [:literal, :integer, 2], [:id, :x]]]], nil]]]
         | 
| 51 | 
            +
            [[:object_call, [:id, :p], [:id, :x]]]
         | 
| 52 | 
            +
            [[:call,[:object_call, [:id, :p], [:id, :x]],[[:id, :p], [:literal, :integer, 1]]]]
         | 
| 53 | 
            +
            [[:call, [:object_call, [:id, :p], [:id, :x]], [[:id, :p]]]]
         | 
| 54 | 
            +
            [[:call,[:object_call, [:call, [:id, :f], [[:literal, :integer, 1]]], [:id, :algo]],[[:call, [:id, :f], [[:literal, :integer, 1]]], [:literal, :integer, 1]]]]
         | 
| 55 | 
            +
            [[:call, [:object_call, [:id, :x], [:id, :algo]], [[:id, :x]]]]
         | 
| 56 | 
            +
            [[:call,[:object_call, [:literal, :integer, 10], [:id, :algo]],[[:literal, :integer, 10],[:literal, :integer, 1],[:literal, :integer, 2],[:literal, :integer, 3]]]]
         | 
| 57 | 
            +
            [[:call,[:object_call,[:object, :algo, [[:literal, :integer, 1], [:literal, :integer, 2]]],[:id, :algo]],[[:object, :algo, [[:literal, :integer, 1], [:literal, :integer, 2]]]]]]
         | 
| 58 | 
            +
            [[:call,[:object_call, [:object, :algo, [[:id, :x], [:id, :y]]], [:id, :x]],[[:object, :algo, [[:id, :x], [:id, :y]]]]]]
         | 
| 59 | 
            +
            [[:object_let,[:object, :point, [[:id, :x], [:id, :y]]],[:id, :x],[:lambda, [[:id, :x]], [:id, :x], [], nil]]]
         | 
| 60 | 
            +
            [[:object_let,[:object, :aaaa, [[:id, :x], [:id, :y]]],[:id, :a],[:lambda, [], [:id, :x], [[:let, [:id, :x], [:literal, :integer, 1]]], nil]]]
         | 
| 61 | 
            +
            [[:object_let,[:object, :aaaa, [[:id, :x], [:id, :y]]],[:id, :algo],[:lambda,[[:id, :x]],[:id, :y],[[:let,[:id, :y],[:lambda, [[:id, :x]], [:+, [:id, :x], [:literal, :integer, 6]], [], nil]]], nil]]]
         | 
| 62 | 
            +
            [[:object_let,[:object, :algo, [[:id, :x], [:id, :y]]],[:id, :algo],[:lambda, [[:id, :x]], [:id, :x], [], nil]]]
         | 
| 63 | 
            +
            [[:object_let, [:object, :algo, []], [:id, :algo], [:literal, :integer, 1]]]
         | 
| 64 | 
            +
            [[:literal, :boolean, :true]]
         | 
| 65 | 
            +
            [[:literal, :boolean, :false]]
         | 
| 66 | 
            +
            [[:let, [:id, :x], [:literal, :boolean, :true]]]
         | 
| 67 | 
            +
            [[:if,[:literal, :boolean, :true],[:literal, :string, "sim"],[:literal, :string, "nao"]]]
         | 
| 68 | 
            +
            [[:and, [:id, :x], [:id, :y]]]
         | 
| 69 | 
            +
            [[:if,[:and, [:literal, :boolean, :true], [:literal, :boolean, :false]],[:literal, :integer, 1],[:literal, :integer, 2]]]
         | 
| 70 | 
            +
            [[:if,[:or, [:and, [:id, :x], [:id, :y]], [:id, :z]],[:literal, :integer, 1],[:literal, :integer, 2]]]
         | 
| 71 | 
            +
            [[:not, [:literal, :boolean, :true]]]
         | 
| 72 | 
            +
            [[:let, [:id, :x], [:or, [:and, [:id, :x], [:id, :y]], [:not, [:id, :k]]]]]
         | 
| @@ -0,0 +1,72 @@ | |
| 1 | 
            +
            1+2
         | 
| 2 | 
            +
            1+2+3
         | 
| 3 | 
            +
            4*5
         | 
| 4 | 
            +
            4/2
         | 
| 5 | 
            +
            5%3
         | 
| 6 | 
            +
            1+2*3/5
         | 
| 7 | 
            +
            (1+6)*5
         | 
| 8 | 
            +
            1+(2*3)/(5-1)
         | 
| 9 | 
            +
            1.3+5*(1+1.568)
         | 
| 10 | 
            +
            xyz
         | 
| 11 | 
            +
            1>2
         | 
| 12 | 
            +
            x>=1
         | 
| 13 | 
            +
            2<=b
         | 
| 14 | 
            +
            4==1
         | 
| 15 | 
            +
            2<x
         | 
| 16 | 
            +
            {obj}
         | 
| 17 | 
            +
            {obj: 1, 2, 3}
         | 
| 18 | 
            +
            {obj: 1+2, x}
         | 
| 19 | 
            +
            {obj: 1, 2}
         | 
| 20 | 
            +
            {obj: x, 2, {other}}
         | 
| 21 | 
            +
            {obj: 1} 
         | 
| 22 | 
            +
            "teste"
         | 
| 23 | 
            +
            'a'
         | 
| 24 | 
            +
            if(x>1, "verdadeiro", "falso")
         | 
| 25 | 
            +
            begin(1+2+3, "oi", 2<3, 'a')
         | 
| 26 | 
            +
            sin(2*pi)-cos(2*pi)
         | 
| 27 | 
            +
            f()
         | 
| 28 | 
            +
            x = 1
         | 
| 29 | 
            +
            x = 1+2+3+4
         | 
| 30 | 
            +
            y = 1+2*x/2
         | 
| 31 | 
            +
            str = "string"
         | 
| 32 | 
            +
            p1 = point(1,2)
         | 
| 33 | 
            +
            {obj: x} = {obj: 1}
         | 
| 34 | 
            +
            {obj: x, t} = obj
         | 
| 35 | 
            +
            [x|x]
         | 
| 36 | 
            +
            [x,y| x+y]
         | 
| 37 | 
            +
            [1, 2, x, {obj: x, y}| 1]
         | 
| 38 | 
            +
            [x| y] : (y = [x| x+6])
         | 
| 39 | 
            +
            [x| y] : (y = [x| x+6], z = [x| x-6], k=1)
         | 
| 40 | 
            +
            x = [1]
         | 
| 41 | 
            +
            fibonacci = [1| 1], [2| 1] , [n| fibonacci(n-1)+fibonacci(n-2)]
         | 
| 42 | 
            +
            str_list = {list: 's', {list: 't', {list: 'r', {list: 'i', {list: 'n', {list: 'g', {list}}}}}}}
         | 
| 43 | 
            +
            point = [x, y| {point: x, y}]
         | 
| 44 | 
            +
            point_x = [{point: x, y}| x]
         | 
| 45 | 
            +
            point_y = [{point: x, y}| y]
         | 
| 46 | 
            +
            point_sum = [{point: x1, y1}, {point: x2, y2}| {point: x1+x2, y1+y2}]
         | 
| 47 | 
            +
            sum = [ a, b| a + b]
         | 
| 48 | 
            +
            f = [x| begin(algo=x, algo*algo, algo)]
         | 
| 49 | 
            +
            f = [x| f(x) + g(x)] : (f = [x| x*x], g = [x| x/2])
         | 
| 50 | 
            +
            f = [x| y] : (y = 2*x)
         | 
| 51 | 
            +
            p->x
         | 
| 52 | 
            +
            p->x(1)
         | 
| 53 | 
            +
            p->x()
         | 
| 54 | 
            +
            f(1)->algo(1)
         | 
| 55 | 
            +
            x->algo()
         | 
| 56 | 
            +
            10->algo(1,2,3)
         | 
| 57 | 
            +
            {algo: 1, 2} -> algo()
         | 
| 58 | 
            +
            {algo: x, y} -> x()
         | 
| 59 | 
            +
            {point: x, y} -> x = [x|x]
         | 
| 60 | 
            +
            {aaaa: x, y}->a = [x] : (x = 1)
         | 
| 61 | 
            +
            {aaaa: x, y} -> algo = [x| y] : (y = [x| x+6])
         | 
| 62 | 
            +
            {algo: x, y}->algo = [x| x]
         | 
| 63 | 
            +
            {algo} -> algo = 1
         | 
| 64 | 
            +
            true
         | 
| 65 | 
            +
            false
         | 
| 66 | 
            +
            x = true
         | 
| 67 | 
            +
            if(true, "sim", "nao")
         | 
| 68 | 
            +
            x and y
         | 
| 69 | 
            +
            if(true and false, 1, 2)
         | 
| 70 | 
            +
            if((x and y) or z, 1, 2)
         | 
| 71 | 
            +
            not true
         | 
| 72 | 
            +
            x = (x and y) or (not k)
         | 
    
        data/test/test_vm.rb
    ADDED
    
    | @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            require 'helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class TestVM < Test::Unit::TestCase
         | 
| 4 | 
            +
              
         | 
| 5 | 
            +
              PROGRAMS = File.readlines(File.join(File.dirname(__FILE__), "test_vm_programs.txt"))
         | 
| 6 | 
            +
              RESULTS = File.readlines(File.join(File.dirname(__FILE__), "test_vm_results.txt"))
         | 
| 7 | 
            +
              
         | 
| 8 | 
            +
              context "The VM" do
         | 
| 9 | 
            +
                setup do
         | 
| 10 | 
            +
                  @parser = PLangParser.new
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                PROGRAMS.each_with_index do |program, i|
         | 
| 14 | 
            +
                  should "interp the program ##{i}" do
         | 
| 15 | 
            +
                    ast = @parser.parse(program)
         | 
| 16 | 
            +
                    vm = PLang::VM.new(ast.build.collect(&:to_sexp))
         | 
| 17 | 
            +
                    assert_equal eval(RESULTS[i]), vm.execute!.params[0]
         | 
| 18 | 
            +
                  end
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
              
         | 
| 22 | 
            +
            end
         | 
| @@ -0,0 +1,37 @@ | |
| 1 | 
            +
            1
         | 
| 2 | 
            +
            1+2
         | 
| 3 | 
            +
            4-7
         | 
| 4 | 
            +
            3*2
         | 
| 5 | 
            +
            6/2
         | 
| 6 | 
            +
            6.0-0.5
         | 
| 7 | 
            +
            5%2
         | 
| 8 | 
            +
            1>2
         | 
| 9 | 
            +
            1>=1
         | 
| 10 | 
            +
            3<1
         | 
| 11 | 
            +
            7<=0
         | 
| 12 | 
            +
            (2>0) and (3<1)
         | 
| 13 | 
            +
            true or false
         | 
| 14 | 
            +
            x=1 x+2
         | 
| 15 | 
            +
            x=1 y=2 x+y
         | 
| 16 | 
            +
            soma = [a,b| a+b] soma(3,4)
         | 
| 17 | 
            +
            soma = [a,b| a+b] soma(3,4)+10
         | 
| 18 | 
            +
            soma = [a,b| sum] : (sum = a+b) soma(10,5)
         | 
| 19 | 
            +
            fib = [1|1], [2|1], [n| fib(n-1)+fib(n-2)] fib(8)
         | 
| 20 | 
            +
            x=1 y=2 f=[x| x+y] f(10)
         | 
| 21 | 
            +
            if (true, 1, 2)
         | 
| 22 | 
            +
            if (false, 1, 2)
         | 
| 23 | 
            +
            begin(1,2,3,4)
         | 
| 24 | 
            +
            {obj: x, y} = {obj: 1, 2} x+y
         | 
| 25 | 
            +
            {obj: 5, 10, z} = {obj: 5, 10, 15} z
         | 
| 26 | 
            +
            [{obj: 10, x}| x]({obj: 10, -5})
         | 
| 27 | 
            +
            [{obj: {algo}, x}| x]({obj: {algo}, 13})
         | 
| 28 | 
            +
            [{obj: {algo: 10}, x}| x]({obj: {algo: 10}, 1})
         | 
| 29 | 
            +
            [{obj: {algo: x}, y}| x+y]({obj: {algo: 1}, 2})
         | 
| 30 | 
            +
            [{obj: {algo: x}, y}, 1, z, {ok}| x+y+z]({obj: {algo: 1}, 2}, 1, 10, {ok})
         | 
| 31 | 
            +
            [{ok}| 10]({ok})
         | 
| 32 | 
            +
            {obj: 1, x} -> f = [x] {obj: 2, x} -> f = [x+1] a = {obj: 2, 20} a -> f()
         | 
| 33 | 
            +
            {obj: 1, x} -> f = [x] {obj: 2, x} -> f = [x+1] a = {obj: 1, 20} a -> f()
         | 
| 34 | 
            +
            {obj: x} -> f = [x-1] {obj: 1} -> f()
         | 
| 35 | 
            +
            {obj: 1, 2, 3, x} -> f = [1+2+3+x] {obj: 1, 2, 3, 10}->f()
         | 
| 36 | 
            +
            f = [_,x,_| x*2] f(1,2,3)
         | 
| 37 | 
            +
            f = [{obj: {xxx: _}, x}, y| x+y] f({obj: {xxx: 1}, 2}, 3)
         | 
| @@ -0,0 +1,37 @@ | |
| 1 | 
            +
            1
         | 
| 2 | 
            +
            3
         | 
| 3 | 
            +
            -3
         | 
| 4 | 
            +
            6
         | 
| 5 | 
            +
            3
         | 
| 6 | 
            +
            5.5
         | 
| 7 | 
            +
            1
         | 
| 8 | 
            +
            false
         | 
| 9 | 
            +
            true
         | 
| 10 | 
            +
            false
         | 
| 11 | 
            +
            false
         | 
| 12 | 
            +
            false
         | 
| 13 | 
            +
            true
         | 
| 14 | 
            +
            3
         | 
| 15 | 
            +
            3
         | 
| 16 | 
            +
            7
         | 
| 17 | 
            +
            17
         | 
| 18 | 
            +
            15
         | 
| 19 | 
            +
            21
         | 
| 20 | 
            +
            12
         | 
| 21 | 
            +
            1
         | 
| 22 | 
            +
            2
         | 
| 23 | 
            +
            4
         | 
| 24 | 
            +
            3
         | 
| 25 | 
            +
            15
         | 
| 26 | 
            +
            -5
         | 
| 27 | 
            +
            13
         | 
| 28 | 
            +
            1
         | 
| 29 | 
            +
            3
         | 
| 30 | 
            +
            13
         | 
| 31 | 
            +
            10
         | 
| 32 | 
            +
            21
         | 
| 33 | 
            +
            20
         | 
| 34 | 
            +
            0
         | 
| 35 | 
            +
            16
         | 
| 36 | 
            +
            4
         | 
| 37 | 
            +
            5
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,119 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification 
         | 
| 2 | 
            +
            name: p-lang
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            +
              hash: 29
         | 
| 5 | 
            +
              prerelease: false
         | 
| 6 | 
            +
              segments: 
         | 
| 7 | 
            +
              - 0
         | 
| 8 | 
            +
              - 0
         | 
| 9 | 
            +
              - 1
         | 
| 10 | 
            +
              version: 0.0.1
         | 
| 11 | 
            +
            platform: ruby
         | 
| 12 | 
            +
            authors: 
         | 
| 13 | 
            +
            - Igor Bonadio
         | 
| 14 | 
            +
            autorequire: 
         | 
| 15 | 
            +
            bindir: bin
         | 
| 16 | 
            +
            cert_chain: []
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            date: 2010-07-06 00:00:00 -03:00
         | 
| 19 | 
            +
            default_executable: p-lang
         | 
| 20 | 
            +
            dependencies: 
         | 
| 21 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 22 | 
            +
              name: treetop
         | 
| 23 | 
            +
              prerelease: false
         | 
| 24 | 
            +
              requirement: &id001 !ruby/object:Gem::Requirement 
         | 
| 25 | 
            +
                none: false
         | 
| 26 | 
            +
                requirements: 
         | 
| 27 | 
            +
                - - ">="
         | 
| 28 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 29 | 
            +
                    hash: 3
         | 
| 30 | 
            +
                    segments: 
         | 
| 31 | 
            +
                    - 0
         | 
| 32 | 
            +
                    version: "0"
         | 
| 33 | 
            +
              type: :development
         | 
| 34 | 
            +
              version_requirements: *id001
         | 
| 35 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 36 | 
            +
              name: shoulda
         | 
| 37 | 
            +
              prerelease: false
         | 
| 38 | 
            +
              requirement: &id002 !ruby/object:Gem::Requirement 
         | 
| 39 | 
            +
                none: false
         | 
| 40 | 
            +
                requirements: 
         | 
| 41 | 
            +
                - - ">="
         | 
| 42 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 43 | 
            +
                    hash: 3
         | 
| 44 | 
            +
                    segments: 
         | 
| 45 | 
            +
                    - 0
         | 
| 46 | 
            +
                    version: "0"
         | 
| 47 | 
            +
              type: :development
         | 
| 48 | 
            +
              version_requirements: *id002
         | 
| 49 | 
            +
            description: P programming language
         | 
| 50 | 
            +
            email: igorbonadio@gmail.com
         | 
| 51 | 
            +
            executables: 
         | 
| 52 | 
            +
            - p-lang
         | 
| 53 | 
            +
            extensions: []
         | 
| 54 | 
            +
             | 
| 55 | 
            +
            extra_rdoc_files: 
         | 
| 56 | 
            +
            - LICENSE
         | 
| 57 | 
            +
            - README.rdoc
         | 
| 58 | 
            +
            files: 
         | 
| 59 | 
            +
            - .document
         | 
| 60 | 
            +
            - .gitignore
         | 
| 61 | 
            +
            - LICENSE
         | 
| 62 | 
            +
            - README.rdoc
         | 
| 63 | 
            +
            - Rakefile
         | 
| 64 | 
            +
            - VERSION.yml
         | 
| 65 | 
            +
            - bin/p-lang
         | 
| 66 | 
            +
            - lib/p-lang.rb
         | 
| 67 | 
            +
            - lib/parser/ast.rb
         | 
| 68 | 
            +
            - lib/parser/nodes.rb
         | 
| 69 | 
            +
            - lib/parser/p-lang.treetop
         | 
| 70 | 
            +
            - lib/vm/environment.rb
         | 
| 71 | 
            +
            - lib/vm/pobject.rb
         | 
| 72 | 
            +
            - lib/vm/proc.rb
         | 
| 73 | 
            +
            - lib/vm/std/io.rb
         | 
| 74 | 
            +
            - lib/vm/vm.rb
         | 
| 75 | 
            +
            - test/helper.rb
         | 
| 76 | 
            +
            - test/test_parser.rb
         | 
| 77 | 
            +
            - test/test_parser_build.txt
         | 
| 78 | 
            +
            - test/test_parser_ok.txt
         | 
| 79 | 
            +
            - test/test_vm.rb
         | 
| 80 | 
            +
            - test/test_vm_programs.txt
         | 
| 81 | 
            +
            - test/test_vm_results.txt
         | 
| 82 | 
            +
            has_rdoc: true
         | 
| 83 | 
            +
            homepage: http://github.com/igorbonadio/p-lang
         | 
| 84 | 
            +
            licenses: []
         | 
| 85 | 
            +
             | 
| 86 | 
            +
            post_install_message: 
         | 
| 87 | 
            +
            rdoc_options: 
         | 
| 88 | 
            +
            - --charset=UTF-8
         | 
| 89 | 
            +
            require_paths: 
         | 
| 90 | 
            +
            - lib
         | 
| 91 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         | 
| 92 | 
            +
              none: false
         | 
| 93 | 
            +
              requirements: 
         | 
| 94 | 
            +
              - - ">="
         | 
| 95 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 96 | 
            +
                  hash: 3
         | 
| 97 | 
            +
                  segments: 
         | 
| 98 | 
            +
                  - 0
         | 
| 99 | 
            +
                  version: "0"
         | 
| 100 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         | 
| 101 | 
            +
              none: false
         | 
| 102 | 
            +
              requirements: 
         | 
| 103 | 
            +
              - - ">="
         | 
| 104 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 105 | 
            +
                  hash: 3
         | 
| 106 | 
            +
                  segments: 
         | 
| 107 | 
            +
                  - 0
         | 
| 108 | 
            +
                  version: "0"
         | 
| 109 | 
            +
            requirements: []
         | 
| 110 | 
            +
             | 
| 111 | 
            +
            rubyforge_project: 
         | 
| 112 | 
            +
            rubygems_version: 1.3.7
         | 
| 113 | 
            +
            signing_key: 
         | 
| 114 | 
            +
            specification_version: 3
         | 
| 115 | 
            +
            summary: P programming language
         | 
| 116 | 
            +
            test_files: 
         | 
| 117 | 
            +
            - test/helper.rb
         | 
| 118 | 
            +
            - test/test_parser.rb
         | 
| 119 | 
            +
            - test/test_vm.rb
         |