AmberVM 0.0.19 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,8 +13,10 @@ describe AmberVM::Languages::ECMA do
13
13
 
14
14
  def run code, &tests
15
15
  env = @env.dup
16
- yield(@compiler.compile(code).execute(@env), @env)
17
- yield(@compiler.compile(code).optimize.execute(env), env)
16
+ c = @compiler.compile(code)
17
+ yield(c.execute(@env), @env)
18
+ c = @compiler.compile(code).optimize
19
+ yield(c.execute(env), env)
18
20
  end
19
21
 
20
22
  describe "objects" do
@@ -75,7 +77,7 @@ describe AmberVM::Languages::ECMA do
75
77
  return this.x;
76
78
  }
77
79
  };
78
- o.f();
80
+ o.f();
79
81
  CODE
80
82
  run code do |result, env|
81
83
  result.should == 23
@@ -111,14 +113,14 @@ describe AmberVM::Languages::ECMA do
111
113
  return this.x;
112
114
  }
113
115
  };
114
- o = {
115
- x: 23,
116
- f: function() {
117
- n.f();
118
- return this.x;
119
- }
120
- };
121
- o.f();
116
+ o = {
117
+ x: 23,
118
+ f: function() {
119
+ n.f();
120
+ return this.x;
121
+ }
122
+ };
123
+ o.f();
122
124
  CODE
123
125
  run code do |result, env|
124
126
  result.should == 23
@@ -457,7 +457,7 @@ describe AmberVM::Languages::ECMA do
457
457
  }
458
458
  EOC
459
459
  run code do |result, env|
460
- result.class.should.kind_of? AmberVM::Interpreter::Clousure::Binding
460
+ result.class.should.kind_of? AmberVM::Interpreter::Closures::Binding
461
461
  env['f'].should be
462
462
  end
463
463
  end
@@ -469,7 +469,7 @@ describe AmberVM::Languages::ECMA do
469
469
  }
470
470
  EOC
471
471
  run code do |result, env|
472
- result.class.should <= AmberVM::Interpreter::Clousure::Binding
472
+ result.class.should <= AmberVM::Interpreter::Closures::Binding
473
473
  env['g'].should be
474
474
  end
475
475
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: AmberVM
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 0.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Heinz N. Gies
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-13 00:00:00 +02:00
12
+ date: 2009-08-31 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -212,14 +212,6 @@ test_files:
212
212
  - spec/languages/ecma/ecma_objects_spec.rb
213
213
  - spec/languages/ecma/ecma_old_spec.rb
214
214
  - spec/languages/ecma/ecma_spec.rb
215
- - spec/languages/ecma_fuku/ecma_array_spec.rb
216
- - spec/languages/ecma_fuku/ecma_closure_spec.rb
217
- - spec/languages/ecma_fuku/ecma_function_spec.rb
218
- - spec/languages/ecma_fuku/ecma_literals_spec.rb
219
- - spec/languages/ecma_fuku/ecma_objects_spec.rb
220
- - spec/languages/ecma_fuku/ecma_old_spec.rb
221
- - spec/languages/ecma_fuku/ecma_operator_spec.rb
222
- - spec/languages/ecma_fuku/ecma_spec.rb
223
215
  - spec/languages/math/compiler_spec.rb
224
216
  - spec/languages/math/tokenizer_spec.rb
225
217
  - spec/languages/math/tree_spec.rb
@@ -1,61 +0,0 @@
1
- $: << 'lib'
2
- require 'amber'
3
- require 'amber/languages'
4
- require 'amber/languages/ecma_fuku'
5
-
6
- describe AmberVM::Languages::ECMA_Fuku do
7
- before(:each) do
8
- @env = {}
9
- @compiler = AmberVM::Languages::ECMA_Fuku.new
10
- end
11
-
12
- def run code
13
- @compiler.compile(code).execute(@env)
14
- end
15
-
16
- describe "arrays" do
17
- it "should allow accessing data on an array" do
18
- @env['test'] = [42]
19
- result = run <<-CODE
20
- test[0]
21
- CODE
22
- result.should == 42
23
- end
24
- it "should allow set data on an array" do
25
- @env['test'] = [42]
26
- result = run <<-CODE
27
- test[0] = 23
28
- CODE
29
- result.should == 23
30
- @env['test'].should == [23]
31
- @env['test'][0].should == 23
32
- end
33
- it "should allow to concat arrays" do
34
- a1 = [42]
35
- @env['test'] = [a1]
36
- result = run <<-CODE
37
- test[0][0]
38
- CODE
39
- result.should == 42
40
- end
41
-
42
- it "should allow to concat arrays when setting values" do
43
- a1 = [42]
44
- @env['test'] = [a1]
45
- result = run <<-CODE
46
- test[0][0] = 23
47
- CODE
48
- result.should == 23
49
- @env['test'].should == [[23]]
50
- end
51
-
52
- it "should wrap arrays" do
53
- a1 = [42]
54
- @env['test'] = a1
55
- result = run <<-CODE
56
- test[0] = 23
57
- CODE
58
- a1.should == [23]
59
- end
60
- end
61
- end
@@ -1,33 +0,0 @@
1
- $: << 'lib'
2
- require 'amber'
3
- require 'amber/languages'
4
- require 'amber/languages/ecma_fuku'
5
-
6
- describe AmberVM::Languages::ECMA_Fuku do
7
- before(:each) do
8
- @env = {} # AmberVM::Interpreter.env
9
- @compiler = AmberVM::Languages::ECMA_Fuku.new
10
- end
11
-
12
- def run code
13
- @compiler.compile(code).execute(@env)
14
- end
15
-
16
- describe "closure" do
17
- it "should be created" do
18
- pending 'No closures implemented yet.'
19
- result = run <<-CODE
20
- function createClosure(x) {
21
- return function() {
22
- return x;
23
- };
24
- }
25
- closure = createClosure(42);
26
- createClosure("wrong!");
27
- closure();
28
- CODE
29
- result.should == 42
30
- end
31
- end
32
-
33
- end
@@ -1,84 +0,0 @@
1
- $: << 'lib'
2
- require 'amber'
3
- require 'amber/languages'
4
- require 'amber/languages/ecma_fuku'
5
-
6
- describe AmberVM::Languages::ECMA_Fuku do
7
- before(:each) do
8
- @env = {}
9
- @compiler = AmberVM::Languages::ECMA_Fuku.new
10
- end
11
-
12
- def run code
13
- @compiler.compile(code).execute(@env)
14
- end
15
-
16
- describe "functions" do
17
- it "should handle function definitions without parameters" do
18
- res = run <<-EOC
19
- function f() {
20
- return 42;
21
- }
22
- EOC
23
- res.class.should == Proc
24
- @env['f'].should be
25
- end
26
-
27
- it "should handle function definitions with parameters" do
28
- res = run <<-EOC
29
- function g(x) {
30
- return 42 + x;
31
- }
32
- EOC
33
- res.class.should == Proc
34
- @env['g'].should be
35
- end
36
-
37
- it "should execute function definitions without parameters" do
38
- result = run <<-EOC
39
- function f() {
40
- return 42;
41
- }
42
- f();
43
- EOC
44
- result.should == 42
45
- end
46
-
47
- it "should execute function with parameters" do
48
- result = run <<-EOC
49
- function g(x) {
50
- return 42 + x;
51
- }
52
- g(2)
53
- EOC
54
- result.should == 44
55
- end
56
-
57
- it "should execute function that calls a function" do
58
- result = run <<-EOC
59
- function f() {
60
- return 'inner';
61
- }
62
- function g() {
63
- return f();
64
- }
65
- g();
66
- EOC
67
- result.should == 'inner'
68
- end
69
-
70
- it "should execute member functions (methods)" do
71
- result = run <<-CODE
72
- o = {
73
- b: function() {
74
- return 1;
75
- }
76
- };
77
- o.b();
78
- CODE
79
- result.should == 1
80
- end
81
-
82
- end
83
-
84
- end
@@ -1,55 +0,0 @@
1
- $: << 'lib'
2
- require 'amber'
3
- require 'amber/languages'
4
- require 'amber/languages/ecma_fuku'
5
-
6
- describe AmberVM::Languages::ECMA_Fuku do
7
- before(:each) do
8
- @compiler = AmberVM::Languages::ECMA_Fuku.new
9
- @env = {}
10
- end
11
- def run code
12
- @compiler.compile(code).execute(@env)
13
- end
14
-
15
- describe "literals" do
16
- it "should know String literals" do
17
- res = run <<-CODE
18
- "test"
19
- CODE
20
- res.should == "test"
21
- end
22
- it "should know Integer literals" do
23
- res = run <<-CODE
24
- 42
25
- CODE
26
- res.should == 42
27
- end
28
- it "should know Float literals" do
29
- res = run <<-CODE
30
- 4.2
31
- CODE
32
- res.should == 4.2
33
- end
34
-
35
- it "should know complex Float literals" do
36
- res = run <<-CODE
37
- .2e-10
38
- CODE
39
- res.should == 0.2e-10
40
- end
41
- it "should know the false literals" do
42
- res = run <<-CODE
43
- false
44
- CODE
45
- res.should_not be_true
46
- end
47
- it "should know the true literals" do
48
- res = run <<-CODE
49
- true
50
- CODE
51
- res.should be_true
52
- end
53
- end
54
-
55
- end
@@ -1,133 +0,0 @@
1
- $: << 'lib'
2
- require 'amber'
3
- require 'amber/languages'
4
- require 'amber/languages/ecma_fuku'
5
- require 'ostruct'
6
-
7
- describe AmberVM::Languages::ECMA_Fuku do
8
- before(:each) do
9
- @env = {}
10
- @compiler = AmberVM::Languages::ECMA_Fuku.new
11
- end
12
-
13
- def run code
14
- @compiler.compile(code).execute(@env)
15
- end
16
-
17
- describe "objects" do
18
-
19
- it "should see outer functions" do
20
- result = run <<-CODE
21
- function a() {
22
- return 1;
23
- }
24
- o = {
25
- b: function() {
26
- return a();
27
- }
28
- };
29
- o.b();
30
- CODE
31
- result.should == 1
32
- end
33
-
34
- it "should get variables" do
35
- result = run <<-CODE
36
- obj = { variable: 42 };
37
- obj.variable
38
- CODE
39
- result.should == 42
40
- end
41
-
42
- it "should set variables" do
43
- result = run <<-CODE
44
- obj = { variable: 42 };
45
- obj.variable = 23
46
- CODE
47
- @env['obj'].variable.should == 23
48
- end
49
-
50
- it "should allow to concat objects variables" do
51
- result = run <<-CODE
52
- obj = {};
53
- obj2 = { variable: 42 };
54
- obj.obj = obj2;
55
- obj.obj.variable
56
- CODE
57
- result.should == 42
58
- end
59
-
60
- it "should handle this.member" do
61
- result = run <<-CODE
62
- obj = {
63
- a: 42,
64
- b: function() {
65
- return this.a;
66
- }
67
- };
68
- obj.b();
69
- CODE
70
- result.should == 42
71
- end
72
-
73
- it "should handle this.method()" do
74
- result = run <<-CODE
75
- obj = {
76
- a: function() {
77
- return 42;
78
- },
79
- b: function() {
80
- return this.a();
81
- }
82
- };
83
- obj.b();
84
- CODE
85
- result.should == 42
86
- end
87
-
88
- end
89
-
90
- describe "external objects" do
91
- it "should get variables" do
92
- object = OpenStruct.new
93
- object.variable = 42
94
- @env['obj'] = object
95
- result = run <<-CODE
96
- obj.variable
97
- CODE
98
- result.should == 42
99
- end
100
-
101
- it "should set variables" do
102
- object = OpenStruct.new
103
- object.variable = 42
104
- @env['obj'] = object
105
- result = run <<-CODE
106
- obj.variable = 23
107
- CODE
108
- @env['obj'].variable.should == 23
109
- end
110
-
111
- it "should allow to concat objects variables" do
112
- object = OpenStruct.new
113
- object2 = OpenStruct.new
114
- object.obj = object2
115
- object2.variable = 42
116
- @env['obj'] = object
117
- result = run <<-CODE
118
- obj.obj.variable
119
- CODE
120
- result.should == 42
121
- end
122
-
123
- it "should allow to assign literals to variables" do
124
- result = run <<-CODE
125
- test = 23
126
- CODE
127
- result.should == 23
128
- @env['test'].should == 23
129
- end
130
-
131
- end
132
-
133
- end