AmberVM 0.0.19 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
@@ -185,7 +185,7 @@ if not @options.dont_execute
185
185
 
186
186
  begin
187
187
  v "Compiling core library #{lib}."
188
- code = @compiler.compile(File.read(lib), true)
188
+ code = @compiler.compile(File.read(lib), true, lib)
189
189
  v "Optimizing library #{lib}" if @options.optimize
190
190
  code = code.optimize(@optvars) if @options.optimize
191
191
  begin
@@ -234,12 +234,13 @@ end
234
234
  if @options.code
235
235
  v "Executing: #{@options.code}."
236
236
  @source = @options.code
237
+ @file = "Commandline"
237
238
  else
238
- if file = ARGV.first
239
- if File.exist?(file)
240
- @source = File.read(file)
239
+ if @file = ARGV.first
240
+ if File.exist?(@file)
241
+ @source = File.read(@file)
241
242
  else
242
- puts "ERROR: Could not load source file: #{file}"
243
+ puts "ERROR: Could not load source file: #{@file}"
243
244
  exit 7
244
245
  end
245
246
  else
@@ -256,7 +257,7 @@ begin
256
257
  i = 0; puts @source.gsub(/^/) { "%3d: " % [i += 1] }
257
258
  end
258
259
  v "Compiling program code."
259
- code = @compiler.compile(@source, @options.run_as_core)
260
+ code = @compiler.compile(@source, @options.run_as_core, @file)
260
261
  v "Optimizing code" if @options.optimize
261
262
  code = code.optimize(@optvars) if @options.optimize
262
263
  if @options.compilation
@@ -268,7 +269,7 @@ begin
268
269
  v "Executing program code."
269
270
  p code.execute(@env)
270
271
  rescue Exception => e
271
- puts "ERROR: could not execute program code #=> #{}"
272
+ puts "ERROR: could not execute program code #=> #{e}"
272
273
  raise e
273
274
  end
274
275
  end
@@ -15,7 +15,7 @@ require 'timeout'
15
15
  #
16
16
  # It also contains some usefull functions that wil allow to make the usuage easyer.
17
17
  module AmberVM
18
- VERSION = "0.0.19" unless defined?(AmberVM::VERSION)
18
+ VERSION = "0.0.20" unless defined?(AmberVM::VERSION)
19
19
 
20
20
  # This class is designed to allow execting code more safely
21
21
  #
@@ -40,10 +40,11 @@ module AmberVM
40
40
 
41
41
 
42
42
  def obj_send(method, params, env)
43
- m = @variables[method] || @object_class.variables[method]
43
+ m = (@variables[method] || @object_class.variables[method]).val
44
44
  raise "Unknown method #{method} for object #{self}" if not m or not m.respond_to?(:call)
45
45
  AmberVM::debug "Calling object function method #{method}." if $DEBUG
46
- env = AmberVM::Interpreter::Environment.new({:params => params||[], :locals => @variables}, env)
46
+ params ||= []
47
+ env = AmberVM::Interpreter::Environment.new({:params => ([self] + params), :locals => @variables}, env)
47
48
  m.call(params, env)
48
49
  end
49
50
 
@@ -171,6 +171,12 @@ module AmberVM
171
171
  # written, which might be helpfull when trying to publish
172
172
  # some data to a script that is not supposed to be changed.
173
173
  def initialize val = nil
174
+ val = val.val if val.is_a? VariableStorage
175
+ @val = val
176
+ end
177
+
178
+ def val= val
179
+ val = val.val if val.is_a? VariableStorage
174
180
  @val = val
175
181
  end
176
182
 
@@ -183,20 +189,11 @@ module AmberVM
183
189
  end
184
190
  end
185
191
 
186
- class ROVariableStorage
192
+ class ROVariableStorage < VariableStorage
187
193
 
188
194
  # Lets the script read the value of the variable.
189
195
  attr_reader :val
190
-
191
- # The storage is initialized with two optional parameters:
192
- #
193
- # +val+:: which is the value to be stores.
194
- # +writable+:: which when set to false prevents the variable to be
195
- # written, which might be helpfull when trying to publish
196
- # some data to a script that is not supposed to be changed.
197
- def initialize val = nil
198
- @val = val
199
- end
196
+
200
197
 
201
198
  def pretty_print(q)
202
199
  q.text "Variable(#{object_id})"
@@ -229,15 +226,16 @@ module AmberVM
229
226
  #
230
227
  def initialize obj, var, writable = true
231
228
  super(nil)
229
+ @writable = writable
232
230
  @obj = obj
233
231
  @get = var.to_sym
234
- @set = "#{var}=".to_sym
232
+ @set = "#{var}=".to_sym if writable
235
233
  end
236
234
 
237
235
  # This methods sets the variable passed to the object by sending it to
238
236
  # the setter method.
239
237
  def val= v
240
- @obj.send(@set,v) if @writable
238
+ @obj.send(@set, v) if @writable
241
239
  @obj.send(@get)
242
240
  end
243
241
 
@@ -36,12 +36,12 @@ module AmberVM
36
36
  end
37
37
 
38
38
  class RuntimeError < Exception
39
- attr_accessor :total, :line, :char, :error_message
40
- def initialize message, total = nil, line = nil, char = nil
39
+ attr_accessor :total, :line, :char, :file, :error_message
40
+ def initialize message, pos = [], file = nil
41
41
  super()
42
- @line = line
43
- @char = char
44
- @total = total
42
+ @line = pos[1]
43
+ @char = pos[2]
44
+ @total = pos[0]
45
45
  @error_message = message
46
46
  end
47
47
 
@@ -57,7 +57,10 @@ module AmberVM
57
57
  res << " line #{@line}"
58
58
  end
59
59
  if @char
60
- res << ":#{@char}"
60
+ res << " position #{@char}"
61
+ end
62
+ if @file
63
+ res << " in file #{@file}"
61
64
  end
62
65
  res << ": #{@error_message}"
63
66
  res
@@ -90,8 +93,9 @@ module AmberVM
90
93
 
91
94
 
92
95
  class Program < Element
93
- def initialize code
96
+ def initialize code, filename = "direct input"
94
97
  @code = code
98
+ @filename = filename
95
99
  @variables = {}
96
100
  end
97
101
 
@@ -105,7 +109,13 @@ module AmberVM
105
109
  @variables.each do |name, var|
106
110
  var.val = env[name].val if env[name]
107
111
  end
108
- res = @code.execute(env)
112
+
113
+ begin
114
+ res = @code.execute(env)
115
+ rescue RuntimeError => e
116
+ e.file = @filename
117
+ raise e
118
+ end
109
119
  @variables.each do |name, var|
110
120
  env[name] = var.val
111
121
  end
@@ -828,6 +838,10 @@ module AmberVM
828
838
  q.text ".value"
829
839
  end
830
840
 
841
+ def to_s
842
+ @pos.join('-')
843
+ end
844
+
831
845
  def optimize variables = {}
832
846
  variable = @variable.optimize variables
833
847
  VariableValue.new(variable)
@@ -859,7 +873,9 @@ module AmberVM
859
873
  def execute env
860
874
  AmberVM::debug "Executing SimpleVariable at #{@pos}..." if $DEBUG
861
875
  begin
862
- obj = @object.execute(env) #.val
876
+ #DEBUG
877
+ obj = @object.execute(env)
878
+ obj = obj.val if obj.is_a? VariableStorage
863
879
  r = obj.variables[@name]
864
880
  if not r
865
881
  if @require_declaration
@@ -871,7 +887,7 @@ module AmberVM
871
887
  @type = r.val.data_type if r.val.respond_to?(:data_type)
872
888
  r
873
889
  rescue Exception => e
874
- raise RuntimeError.new("Failed to get object variable Variable #{$!}", @pos[0], @pos[1], @pos[2])
890
+ raise RuntimeError.new("Failed to get object variable Variable: #{$!}", @pos)
875
891
  end
876
892
  end
877
893
 
@@ -971,7 +987,7 @@ module AmberVM
971
987
  AmberVM::debug "Executing Sequence... #{inspect}" if $DEBUG
972
988
  for item in @data
973
989
  r = item.execute env
974
- end
990
+ end if @data
975
991
  r
976
992
  end
977
993
 
@@ -1164,19 +1180,19 @@ module AmberVM
1164
1180
  @function.call(args, env, @pos)
1165
1181
  # The function is a selfdefined function (or object function)
1166
1182
  elsif @function.is_a? AmberVM::Interpreter::Element
1167
- fun = @function.execute(env)
1168
- # The arguments are executed.
1169
- args = @arguments.map do |arg|
1170
- arg.execute env
1171
- end
1172
- # Call the function
1173
- begin
1174
- fun.call(args, env, @pos)
1175
- rescue Exception => e
1176
- exit
1177
- end
1178
- # The function is a selfdefined function (or object function)
1179
- elsif fun = env.function(@function)
1183
+ fun = @function.execute(env)
1184
+ # The arguments are executed.
1185
+ args = @arguments.map do |arg|
1186
+ arg.execute env
1187
+ end
1188
+ # Call the function
1189
+ begin
1190
+ fun.call(args, env, @pos)
1191
+ rescue Exception => e
1192
+ raise RuntimeError.new("Cound not call function: #{$!.to_s.gsub('<','&lt;')}<br/>#{e.to_s.gsub('<','&lt;')}", @pos)
1193
+ end
1194
+ # The function is a selfdefined function (or object function)
1195
+ elsif fun = env.function(@function)
1180
1196
  # The arguments are executed.
1181
1197
  args = @arguments.map do |arg|
1182
1198
  arg.execute env
@@ -47,7 +47,7 @@ module AmberVM
47
47
  @core_libs = additional_core_libs
48
48
  Dir[File.join(File.dirname(__FILE__), 'languages', self.class.plugin_id.to_s, 'core-*')].each do |f|
49
49
  begin
50
- @core_libs << compile(File.read(f),true)
50
+ @core_libs << compile(File.read(f), true, f)
51
51
  rescue Exception => e
52
52
  puts "Failed to compile core library: #{f}."
53
53
  raise e
@@ -24,12 +24,12 @@ module AmberVM
24
24
  class ECMA
25
25
  class Compiler < Racc::Parser
26
26
 
27
- module_eval(<<'...end ecma.y/module_eval...', 'ecma.y', 351)
27
+ module_eval(<<'...end ecma.y/module_eval...', 'ecma.y', 353)
28
28
 
29
29
  include AmberVM::Interpreter
30
30
 
31
31
 
32
- def compile(str, include_core = false)
32
+ def compile(str, include_core = false, file = nil)
33
33
  @variables = Environment.new
34
34
  @q = []
35
35
  str = str.chomp(';') + ';'
@@ -120,7 +120,7 @@ module_eval(<<'...end ecma.y/module_eval...', 'ecma.y', 351)
120
120
  end
121
121
  @q.push([false, '$end'])
122
122
 
123
- Program.new(do_parse)
123
+ Program.new(do_parse, file)
124
124
  end
125
125
 
126
126
  def version
@@ -138,6 +138,17 @@ module_eval(<<'...end ecma.y/module_eval...', 'ecma.y', 351)
138
138
  def core_fun(fun)
139
139
  VariableValue.new(ObjectVariable.new(VariableValue.new(SimpleVariable.new('Core')), fun))
140
140
  end
141
+
142
+ def core_fun_call fun, args, pos
143
+ last_self = StaticVariable.new(nil, pos)
144
+ result = StaticVariable.new(nil, pos)
145
+ Sequence.new([
146
+ Assignment.new(last_self, VariableValue.new(Variable.new(:self, pos), pos)),
147
+ Assignment.new(result, FunctionCall.new(core_fun(fun), [VariableValue.new(SimpleVariable.new('Core'))] + args ,pos), pos),
148
+ Assignment.new(Variable.new(:self, pos), VariableValue.new(last_self, pos)),
149
+ VariableValue.new(result, pos)
150
+ ], pos)
151
+ end
141
152
  ...end ecma.y/module_eval...
142
153
  ##### State transition tables begin ###
143
154
 
@@ -1007,7 +1018,7 @@ module_eval(<<'.,.,', 'ecma.y', 94)
1007
1018
  if rhs.is_a?(Constant) and rhs.value.is_a?(AmberVM::Classes::Number)
1008
1019
  result = CoreCall.new(:add, [lhs, rhs], val[1][1])
1009
1020
  else
1010
- result = result = FunctionCall.new(core_fun('plus'), [lhs, rhs] ,val[1][1])
1021
+ result = result = core_fun_call('plus', [lhs, rhs] ,val[1][1])
1011
1022
  end
1012
1023
 
1013
1024
  result
@@ -1188,7 +1199,7 @@ module_eval(<<'.,.,', 'ecma.y', 129)
1188
1199
 
1189
1200
  module_eval(<<'.,.,', 'ecma.y', 130)
1190
1201
  def _reduce_57(val, _values, result)
1191
- result = VariableValue.new(result)
1202
+ result = VariableValue.new(result, ['g','g','g'])
1192
1203
  result
1193
1204
  end
1194
1205
  .,.,
@@ -1199,7 +1210,7 @@ module_eval(<<'.,.,', 'ecma.y', 130)
1199
1210
 
1200
1211
  module_eval(<<'.,.,', 'ecma.y', 133)
1201
1212
  def _reduce_60(val, _values, result)
1202
- result = FunctionCall.new(core_fun('type'), [val[1]] ,val[0][1])
1213
+ result = core_fun_call('type', [val[1]] ,val[0][1])
1203
1214
  result
1204
1215
  end
1205
1216
  .,.,
@@ -1231,7 +1242,7 @@ module_eval(<<'.,.,', 'ecma.y', 141)
1231
1242
 
1232
1243
  module_eval(<<'.,.,', 'ecma.y', 148)
1233
1244
  def _reduce_71(val, _values, result)
1234
- result = ObjectVariable.new(VariableValue.new(val[0]), val[2][0], val[1][1])
1245
+ result = ObjectVariable.new(VariableValue.new(val[0], val[1][1]), val[2][0], val[1][1])
1235
1246
 
1236
1247
  result
1237
1248
  end
@@ -1240,19 +1251,18 @@ module_eval(<<'.,.,', 'ecma.y', 148)
1240
1251
  module_eval(<<'.,.,', 'ecma.y', 152)
1241
1252
  def _reduce_72(val, _values, result)
1242
1253
  if val[0].is_a? ObjectVariable
1243
- last_self = StaticVariable.new(nil)
1244
- result = StaticVariable.new(nil)
1254
+ last_self = StaticVariable.new(nil, val[1][1])
1255
+ result = StaticVariable.new(nil, val[1][1])
1245
1256
  obj = val[0].object
1246
1257
  var = val[0].name
1247
1258
  result = Sequence.new([
1248
- Assignment.new(last_self, VariableValue.new(Variable.new(:self))),
1249
- Assignment.new(Variable.new(:self), obj),
1250
- Assignment.new(result,FunctionCall.new(VariableValue.new(ObjectVariable.new(VariableValue.new(Variable.new(:self)), var, val[0].pos)),val[2])),
1251
- Assignment.new(Variable.new(:self), VariableValue.new(last_self)),
1252
- VariableValue.new(result)
1253
- ])
1259
+ Assignment.new(last_self, VariableValue.new(Variable.new(:self, val[1][1]), val[1][1])),
1260
+ Assignment.new(result, FunctionCall.new(VariableValue.new(val[0], val[1][1]), [obj] + val[2], val[1][1]), val[1][1]),
1261
+ Assignment.new(Variable.new(:self, val[1][1]), VariableValue.new(last_self, val[1][1])),
1262
+ VariableValue.new(result, val[1][1])
1263
+ ], val[1][1])
1254
1264
  else
1255
- result = FunctionCall.new(VariableValue.new(val[0]), val[2], val[1][1])
1265
+ result = FunctionCall.new(VariableValue.new(val[0], val[1][1]), [VariableValue.new(Variable.new(:self,val[1][1]),val[1][1])] + val[2], val[1][1])
1256
1266
  end
1257
1267
 
1258
1268
  result
@@ -1263,28 +1273,28 @@ module_eval(<<'.,.,', 'ecma.y', 152)
1263
1273
 
1264
1274
  # reduce 74 omitted
1265
1275
 
1266
- module_eval(<<'.,.,', 'ecma.y', 173)
1276
+ module_eval(<<'.,.,', 'ecma.y', 172)
1267
1277
  def _reduce_75(val, _values, result)
1268
1278
  result = [val[0][0]]
1269
1279
  result
1270
1280
  end
1271
1281
  .,.,
1272
1282
 
1273
- module_eval(<<'.,.,', 'ecma.y', 174)
1283
+ module_eval(<<'.,.,', 'ecma.y', 173)
1274
1284
  def _reduce_76(val, _values, result)
1275
1285
  result << val[2][0]
1276
1286
  result
1277
1287
  end
1278
1288
  .,.,
1279
1289
 
1280
- module_eval(<<'.,.,', 'ecma.y', 175)
1290
+ module_eval(<<'.,.,', 'ecma.y', 174)
1281
1291
  def _reduce_77(val, _values, result)
1282
1292
  result = []
1283
1293
  result
1284
1294
  end
1285
1295
  .,.,
1286
1296
 
1287
- module_eval(<<'.,.,', 'ecma.y', 178)
1297
+ module_eval(<<'.,.,', 'ecma.y', 177)
1288
1298
  def _reduce_78(val, _values, result)
1289
1299
  result = CoreCall.new(val[2][0], val[4], val[1][1])
1290
1300
 
@@ -1292,7 +1302,7 @@ module_eval(<<'.,.,', 'ecma.y', 178)
1292
1302
  end
1293
1303
  .,.,
1294
1304
 
1295
- module_eval(<<'.,.,', 'ecma.y', 181)
1305
+ module_eval(<<'.,.,', 'ecma.y', 180)
1296
1306
  def _reduce_79(val, _values, result)
1297
1307
  result = CoreCall.new(:at, [VariableValue.new(val[0]), val[2]], val[1][1])
1298
1308
  result
@@ -1301,7 +1311,7 @@ module_eval(<<'.,.,', 'ecma.y', 181)
1301
1311
 
1302
1312
  # reduce 80 omitted
1303
1313
 
1304
- module_eval(<<'.,.,', 'ecma.y', 186)
1314
+ module_eval(<<'.,.,', 'ecma.y', 185)
1305
1315
  def _reduce_81(val, _values, result)
1306
1316
  result = SimpleDeclaration.new(val[0][0], val[2], val[1][1])
1307
1317
 
@@ -1309,7 +1319,7 @@ module_eval(<<'.,.,', 'ecma.y', 186)
1309
1319
  end
1310
1320
  .,.,
1311
1321
 
1312
- module_eval(<<'.,.,', 'ecma.y', 189)
1322
+ module_eval(<<'.,.,', 'ecma.y', 188)
1313
1323
  def _reduce_82(val, _values, result)
1314
1324
  result = SimpleDeclaration.new(val[0][0], const(:null,nil), val[0][1])
1315
1325
 
@@ -1317,68 +1327,68 @@ module_eval(<<'.,.,', 'ecma.y', 189)
1317
1327
  end
1318
1328
  .,.,
1319
1329
 
1320
- module_eval(<<'.,.,', 'ecma.y', 192)
1330
+ module_eval(<<'.,.,', 'ecma.y', 191)
1321
1331
  def _reduce_83(val, _values, result)
1322
1332
  result = val[1]
1323
1333
  result
1324
1334
  end
1325
1335
  .,.,
1326
1336
 
1327
- module_eval(<<'.,.,', 'ecma.y', 194)
1337
+ module_eval(<<'.,.,', 'ecma.y', 193)
1328
1338
  def _reduce_84(val, _values, result)
1329
1339
  result = Sequence.new([result])
1330
1340
  result
1331
1341
  end
1332
1342
  .,.,
1333
1343
 
1334
- module_eval(<<'.,.,', 'ecma.y', 195)
1344
+ module_eval(<<'.,.,', 'ecma.y', 194)
1335
1345
  def _reduce_85(val, _values, result)
1336
1346
  result << val[2]
1337
1347
  result
1338
1348
  end
1339
1349
  .,.,
1340
1350
 
1341
- module_eval(<<'.,.,', 'ecma.y', 197)
1351
+ module_eval(<<'.,.,', 'ecma.y', 196)
1342
1352
  def _reduce_86(val, _values, result)
1343
1353
  result = Assignment.new(val[0], val[2], val[1][1])
1344
1354
  result
1345
1355
  end
1346
1356
  .,.,
1347
1357
 
1348
- module_eval(<<'.,.,', 'ecma.y', 198)
1358
+ module_eval(<<'.,.,', 'ecma.y', 197)
1349
1359
  def _reduce_87(val, _values, result)
1350
1360
  result = Assignment.new(val[0], val[2], val[1][1])
1351
1361
  result
1352
1362
  end
1353
1363
  .,.,
1354
1364
 
1355
- module_eval(<<'.,.,', 'ecma.y', 199)
1365
+ module_eval(<<'.,.,', 'ecma.y', 198)
1356
1366
  def _reduce_88(val, _values, result)
1357
1367
  result = Assignment.new(val[0], val[2], val[1][1])
1358
1368
  result
1359
1369
  end
1360
1370
  .,.,
1361
1371
 
1362
- module_eval(<<'.,.,', 'ecma.y', 200)
1372
+ module_eval(<<'.,.,', 'ecma.y', 199)
1363
1373
  def _reduce_89(val, _values, result)
1364
- result = Assignment.new(val[1], FunctionCall.new(core_fun('inc'), [val[1]] ,val[0][1]), val[0][1])
1374
+ result = Assignment.new(val[1], core_fun_call('inc', [val[1]] ,val[0][1]), val[0][1])
1365
1375
  result
1366
1376
  end
1367
1377
  .,.,
1368
1378
 
1369
- module_eval(<<'.,.,', 'ecma.y', 201)
1379
+ module_eval(<<'.,.,', 'ecma.y', 200)
1370
1380
  def _reduce_90(val, _values, result)
1371
- result = Assignment.new(val[1], FunctionCall.new(core_fun('dec'), [val[1]] ,val[0][1]), val[0][1])
1381
+ result = Assignment.new(val[1], core_fun_call('dec', [val[1]] ,val[0][1]), val[0][1])
1372
1382
  result
1373
1383
  end
1374
1384
  .,.,
1375
1385
 
1376
- module_eval(<<'.,.,', 'ecma.y', 203)
1386
+ module_eval(<<'.,.,', 'ecma.y', 202)
1377
1387
  def _reduce_91(val, _values, result)
1378
1388
  seq = Sequence.new()
1379
1389
  var = StaticVariable.new(nil)
1380
1390
  seq << Assignment.new(var, VariableValue.new(result, val[1][1]), val[1][1]);
1381
- seq << Assignment.new(result, FunctionCall.new(core_fun('inc'), [result] ,val[1][1]), val[1][1])
1391
+ seq << Assignment.new(result, core_fun_call('inc', [result] ,val[1][1]), val[1][1])
1382
1392
  seq << VariableValue.new(var, val[1][1])
1383
1393
  result = seq
1384
1394
 
@@ -1386,12 +1396,12 @@ module_eval(<<'.,.,', 'ecma.y', 203)
1386
1396
  end
1387
1397
  .,.,
1388
1398
 
1389
- module_eval(<<'.,.,', 'ecma.y', 211)
1399
+ module_eval(<<'.,.,', 'ecma.y', 210)
1390
1400
  def _reduce_92(val, _values, result)
1391
1401
  seq = Sequence.new()
1392
1402
  var = StaticVariable.new(nil)
1393
1403
  seq << Assignment.new(var, VariableValue.new(result, val[1][1]), val[1][1]);
1394
- seq << Assignment.new(result, FunctionCall.new(core_fun('dec'), [result] ,val[1][1]), val[1][1])
1404
+ seq << Assignment.new(result, core_fun_call('dec', [result] ,val[1][1]), val[1][1])
1395
1405
  seq << VariableValue.new(var, val[1][1])
1396
1406
  result = seq
1397
1407
 
@@ -1399,101 +1409,102 @@ module_eval(<<'.,.,', 'ecma.y', 211)
1399
1409
  end
1400
1410
  .,.,
1401
1411
 
1402
- module_eval(<<'.,.,', 'ecma.y', 219)
1412
+ module_eval(<<'.,.,', 'ecma.y', 218)
1403
1413
  def _reduce_93(val, _values, result)
1404
1414
  lhs = val[0]
1405
1415
  rhs = val[2]
1406
1416
  if rhs.is_a?(Constant) and rhs.value.is_a?(AmberVM::Classes::Number)
1407
1417
  result = Assignment.new(val[0], CoreCall.new(:add, [VariableValue.new(lhs, val[1][1]), rhs], val[1][1]), val[1][1])
1408
1418
  else
1409
- result = Assignment.new(val[0], FunctionCall.new(core_fun('plus'), [VariableValue.new(lhs, val[1][1]), rhs] ,val[1][1]), val[1][1])
1419
+ result = Assignment.new(val[0], core_fun_call('plus', [VariableValue.new(lhs, val[1][1]), rhs] ,val[1][1]), val[1][1])
1410
1420
  end
1411
1421
 
1412
1422
  result
1413
1423
  end
1414
1424
  .,.,
1415
1425
 
1416
- module_eval(<<'.,.,', 'ecma.y', 227)
1426
+ module_eval(<<'.,.,', 'ecma.y', 226)
1417
1427
  def _reduce_94(val, _values, result)
1418
1428
  result = Assignment.new(val[0], CoreCall.new(:sub, [VariableValue.new(val[0], val[1][1]), val[2]], val[1][1]), val[1][1])
1419
1429
  result
1420
1430
  end
1421
1431
  .,.,
1422
1432
 
1423
- module_eval(<<'.,.,', 'ecma.y', 228)
1433
+ module_eval(<<'.,.,', 'ecma.y', 227)
1424
1434
  def _reduce_95(val, _values, result)
1425
1435
  result = Assignment.new(val[0], CoreCall.new(:mul, [VariableValue.new(val[0], val[1][1]), val[2]], val[1][1]), val[1][1])
1426
1436
  result
1427
1437
  end
1428
1438
  .,.,
1429
1439
 
1430
- module_eval(<<'.,.,', 'ecma.y', 229)
1440
+ module_eval(<<'.,.,', 'ecma.y', 228)
1431
1441
  def _reduce_96(val, _values, result)
1432
1442
  result = Assignment.new(val[0], CoreCall.new(:div, [VariableValue.new(val[0], val[1][1]), val[2]], val[1][1]), val[1][1])
1433
1443
  result
1434
1444
  end
1435
1445
  .,.,
1436
1446
 
1437
- module_eval(<<'.,.,', 'ecma.y', 230)
1447
+ module_eval(<<'.,.,', 'ecma.y', 229)
1438
1448
  def _reduce_97(val, _values, result)
1439
1449
  result = Assignment.new(val[0], CoreCall.new(:mod, [VariableValue.new(val[0], val[1][1]), val[2]], val[1][1]), val[1][1])
1440
1450
  result
1441
1451
  end
1442
1452
  .,.,
1443
1453
 
1444
- module_eval(<<'.,.,', 'ecma.y', 231)
1454
+ module_eval(<<'.,.,', 'ecma.y', 230)
1445
1455
  def _reduce_98(val, _values, result)
1446
1456
  result = Assignment.new(val[0], CoreCall.new(:bitwise_or, [VariableValue.new(val[0], val[1][1]), val[2]], val[1][1]), val[1][1])
1447
1457
  result
1448
1458
  end
1449
1459
  .,.,
1450
1460
 
1451
- module_eval(<<'.,.,', 'ecma.y', 232)
1461
+ module_eval(<<'.,.,', 'ecma.y', 231)
1452
1462
  def _reduce_99(val, _values, result)
1453
1463
  result = Assignment.new(val[0], CoreCall.new(:bitwise_and, [VariableValue.new(val[0], val[1][1]), val[2]], val[1][1]), val[1][1])
1454
1464
  result
1455
1465
  end
1456
1466
  .,.,
1457
1467
 
1458
- module_eval(<<'.,.,', 'ecma.y', 233)
1468
+ module_eval(<<'.,.,', 'ecma.y', 232)
1459
1469
  def _reduce_100(val, _values, result)
1460
1470
  result = Assignment.new(val[0], CoreCall.new(:bitwise_xor, [VariableValue.new(val[0], val[1][1]), val[2]], val[1][1]), val[1][1])
1461
1471
  result
1462
1472
  end
1463
1473
  .,.,
1464
1474
 
1465
- module_eval(<<'.,.,', 'ecma.y', 234)
1475
+ module_eval(<<'.,.,', 'ecma.y', 233)
1466
1476
  def _reduce_101(val, _values, result)
1467
1477
  result = Assignment.new(val[0], CoreCall.new(:shl, [VariableValue.new(val[0], val[1][1]), val[2]], val[1][1]), val[1][1])
1468
1478
  result
1469
1479
  end
1470
1480
  .,.,
1471
1481
 
1472
- module_eval(<<'.,.,', 'ecma.y', 235)
1482
+ module_eval(<<'.,.,', 'ecma.y', 234)
1473
1483
  def _reduce_102(val, _values, result)
1474
1484
  result = Assignment.new(val[0], CoreCall.new(:shr, [VariableValue.new(val[0], val[1][1]), val[2]], val[1][1]), val[1][1])
1475
1485
  result
1476
1486
  end
1477
1487
  .,.,
1478
1488
 
1479
- module_eval(<<'.,.,', 'ecma.y', 236)
1489
+ module_eval(<<'.,.,', 'ecma.y', 235)
1480
1490
  def _reduce_103(val, _values, result)
1481
1491
  result = Assignment.new(val[0], CoreCall.new(:shr, [VariableValue.new(val[0], val[1][1]), val[2]], val[1][1]), val[1][1])
1482
1492
  result
1483
1493
  end
1484
1494
  .,.,
1485
1495
 
1486
- module_eval(<<'.,.,', 'ecma.y', 240)
1496
+ module_eval(<<'.,.,', 'ecma.y', 239)
1487
1497
  def _reduce_104(val, _values, result)
1488
1498
  name = nil
1489
1499
  arg_def = val[2]
1490
1500
  block = val[4]
1491
- i=0
1492
1501
  if not block.is_a?(Sequence)
1493
1502
  temp_block = block
1494
1503
  block = Sequence.new()
1495
1504
  block << temp_block
1496
1505
  end
1506
+ i = 1
1507
+ block.unshift Assignment.new(Variable.new(:self), Parameter.new(const(:number, 0)))
1497
1508
  val[2].each do |a|
1498
1509
  block.unshift SimpleDeclaration.new(a, Parameter.new(const(:number, i)))
1499
1510
  i +=1
@@ -1511,12 +1522,14 @@ module_eval(<<'.,.,', 'ecma.y', 258)
1511
1522
  name = val[1][0]
1512
1523
  arg_def = val[3]
1513
1524
  block = val[5]
1514
- i = 0
1525
+
1515
1526
  if not block.is_a?(Sequence)
1516
1527
  temp_block = block
1517
1528
  block = Sequence.new()
1518
1529
  block << temp_block
1519
1530
  end
1531
+ i = 1
1532
+ block.unshift Assignment.new(Variable.new(:self), Parameter.new(const(:number, 0)))
1520
1533
  val[3].each do |a|
1521
1534
  block.unshift SimpleDeclaration.new(a, Parameter.new(const(:number, i)))
1522
1535
  i +=1
@@ -1533,7 +1546,7 @@ module_eval(<<'.,.,', 'ecma.y', 258)
1533
1546
 
1534
1547
  # reduce 107 omitted
1535
1548
 
1536
- module_eval(<<'.,.,', 'ecma.y', 280)
1549
+ module_eval(<<'.,.,', 'ecma.y', 282)
1537
1550
  def _reduce_108(val, _values, result)
1538
1551
  cond = val[2]
1539
1552
  body = val[4]
@@ -1543,7 +1556,7 @@ module_eval(<<'.,.,', 'ecma.y', 280)
1543
1556
  end
1544
1557
  .,.,
1545
1558
 
1546
- module_eval(<<'.,.,', 'ecma.y', 285)
1559
+ module_eval(<<'.,.,', 'ecma.y', 287)
1547
1560
  def _reduce_109(val, _values, result)
1548
1561
  cond = val[4]
1549
1562
  block = val[1]
@@ -1555,7 +1568,7 @@ module_eval(<<'.,.,', 'ecma.y', 285)
1555
1568
  end
1556
1569
  .,.,
1557
1570
 
1558
- module_eval(<<'.,.,', 'ecma.y', 293)
1571
+ module_eval(<<'.,.,', 'ecma.y', 295)
1559
1572
  def _reduce_110(val, _values, result)
1560
1573
  init = val[2]
1561
1574
  cond = val[4]
@@ -1576,42 +1589,42 @@ module_eval(<<'.,.,', 'ecma.y', 293)
1576
1589
  end
1577
1590
  .,.,
1578
1591
 
1579
- module_eval(<<'.,.,', 'ecma.y', 309)
1592
+ module_eval(<<'.,.,', 'ecma.y', 311)
1580
1593
  def _reduce_111(val, _values, result)
1581
1594
  result = Condition.new(val[2], val[4], val[6], val[0][1])
1582
1595
  result
1583
1596
  end
1584
1597
  .,.,
1585
1598
 
1586
- module_eval(<<'.,.,', 'ecma.y', 310)
1599
+ module_eval(<<'.,.,', 'ecma.y', 312)
1587
1600
  def _reduce_112(val, _values, result)
1588
1601
  result = Condition.new(val[2], val[4], nil, val[0][1])
1589
1602
  result
1590
1603
  end
1591
1604
  .,.,
1592
1605
 
1593
- module_eval(<<'.,.,', 'ecma.y', 312)
1606
+ module_eval(<<'.,.,', 'ecma.y', 314)
1594
1607
  def _reduce_113(val, _values, result)
1595
1608
  result = Return.new(val[1])
1596
1609
  result
1597
1610
  end
1598
1611
  .,.,
1599
1612
 
1600
- module_eval(<<'.,.,', 'ecma.y', 313)
1613
+ module_eval(<<'.,.,', 'ecma.y', 315)
1601
1614
  def _reduce_114(val, _values, result)
1602
1615
  result = Return.new(val[1])
1603
1616
  result
1604
1617
  end
1605
1618
  .,.,
1606
1619
 
1607
- module_eval(<<'.,.,', 'ecma.y', 315)
1620
+ module_eval(<<'.,.,', 'ecma.y', 317)
1608
1621
  def _reduce_115(val, _values, result)
1609
1622
  result = const(:object, nil)
1610
1623
  result
1611
1624
  end
1612
1625
  .,.,
1613
1626
 
1614
- module_eval(<<'.,.,', 'ecma.y', 318)
1627
+ module_eval(<<'.,.,', 'ecma.y', 320)
1615
1628
  def _reduce_116(val, _values, result)
1616
1629
  object = const(:object, nil)
1617
1630
  result = Sequence.new([])
@@ -1630,21 +1643,21 @@ module_eval(<<'.,.,', 'ecma.y', 318)
1630
1643
 
1631
1644
  # reduce 118 omitted
1632
1645
 
1633
- module_eval(<<'.,.,', 'ecma.y', 329)
1646
+ module_eval(<<'.,.,', 'ecma.y', 331)
1634
1647
  def _reduce_119(val, _values, result)
1635
1648
  result = [val[0][0], val[2]]
1636
1649
  result
1637
1650
  end
1638
1651
  .,.,
1639
1652
 
1640
- module_eval(<<'.,.,', 'ecma.y', 330)
1653
+ module_eval(<<'.,.,', 'ecma.y', 332)
1641
1654
  def _reduce_120(val, _values, result)
1642
1655
  result = [result]
1643
1656
  result
1644
1657
  end
1645
1658
  .,.,
1646
1659
 
1647
- module_eval(<<'.,.,', 'ecma.y', 331)
1660
+ module_eval(<<'.,.,', 'ecma.y', 333)
1648
1661
  def _reduce_121(val, _values, result)
1649
1662
  result << val[2]
1650
1663
  result