asmrb 0.0.2.6.1.3 → 0.0.2.6.1.4

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/asmrb.rb +27 -79
  3. metadata +3 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43288f18e0561f0edf394d9522578c582ea0956e
4
- data.tar.gz: 3007f21ca287b145f4a04222c653433c74065cfc
3
+ metadata.gz: 327f8a64c7dd648f81b9047b9d13dbbd067be247
4
+ data.tar.gz: 21f417fb164ba9c7fdf188015b14f885687d891a
5
5
  SHA512:
6
- metadata.gz: 922176943cbb5921580c25157f6845f2453976a68d8fa93807f7656065c2ad4d236d0d13a28f3d353e035a127e27ca46103184343f25c7bffcd9811bb2db29c2
7
- data.tar.gz: c27e8a276ae85073b5422e4b61c50bba94e6a27d85de9345ecb369277bee13a175b6eb7de6690d232014e0f6593e6b6efc213c8cdd46b78ff336dfc8d87a67a9
6
+ metadata.gz: c794268632d536b2afb3ba20e07207279d12a9cc6404b7fcd7cb7167016dd839f0785b25235a0ced6eeac2c1d0808f1bd7a0c8c826b508691a6d42117f1ae826
7
+ data.tar.gz: a88548213c8d9ffc6e9f3ee7a4086352f1c9a745842eb72b11eee615bef55d11342462779423ad40902fd0c862538bebf83936404b6ddf75a4dc17c535f6125f
data/lib/asmrb.rb CHANGED
@@ -219,13 +219,13 @@ class Asmrb
219
219
  },
220
220
 
221
221
  "cal" => lambda {|fname|
222
- _method = method(fname)
223
- if _method.parameters.length > 0
224
- args = []
222
+ _method = method fname
223
+ if _method && _method.parameters.length > 0
224
+ args = Array.new
225
225
  _method.parameters.length.times do
226
226
  args.push @stack.pop
227
227
  end
228
- invoke = _method.call(args)
228
+ invoke = _method.call args
229
229
  else
230
230
  invoke = _method.call
231
231
  end
@@ -239,7 +239,7 @@ class Asmrb
239
239
  @pc = @program.length-1
240
240
  },
241
241
 
242
- "end" => lambda {
242
+ "exi" => lambda {
243
243
  exit
244
244
  }
245
245
  }
@@ -256,7 +256,7 @@ class Asmrb
256
256
  # :name => "name"
257
257
  sname = name.to_s.gsub "_", ""
258
258
 
259
- if OPS.keys.include?(sname)
259
+ if OPS.keys.include? sname
260
260
  @program << [sname, args]
261
261
  # get parameter amount:
262
262
  @params = args.length if sname == "arg"
@@ -276,11 +276,11 @@ class Asmrb
276
276
  end
277
277
  end
278
278
 
279
- def load_program(&block)
280
- self.instance_exec(&block)
279
+ def load_program &block
280
+ self.instance_exec &block
281
281
  end
282
282
 
283
- def execute(debug=false)
283
+ def execute debug=false
284
284
  new_line if debug
285
285
  puts "#{@stack} > #{@name}".yellow if debug
286
286
  begin
@@ -304,21 +304,21 @@ class Asmrb
304
304
  @result
305
305
  end
306
306
 
307
- def fast_execute(*args)
307
+ def fast_execute *args
308
308
  arguments args
309
309
  @pc = 0
310
- until(@pc == @program.length)
310
+ until @pc == @program.length
311
311
  # execute proc:
312
- self.instance_exec(*@program[@pc][1],
313
- &OPS[@program[@pc][0]])
312
+ self.instance_exec *@program[@pc].last,
313
+ &OPS[@program[@pc].first]
314
314
  @pc += 1
315
315
  end
316
316
  @result = @stack.last
317
317
  clear
318
- return @result
318
+ @result
319
319
  end
320
320
 
321
- def new_title(title)
321
+ def new_title title
322
322
  puts "\n::#{title}"
323
323
  end
324
324
 
@@ -363,7 +363,7 @@ class Asmrb
363
363
  "#{name} [#{parameters.join(', ')}]"
364
364
  end
365
365
 
366
- def arguments(args=[])
366
+ def arguments args=[]
367
367
  args.each do | arg |
368
368
  @stack << arg
369
369
  end
@@ -381,7 +381,7 @@ class Asmrb
381
381
  end
382
382
 
383
383
  def assemble &block
384
- load_program(&block)
384
+ load_program &block
385
385
  eval "$#{@name} = self.clone"
386
386
  eval "$#{@name}"
387
387
  end
@@ -396,16 +396,13 @@ class Asmrb
396
396
  puts "#{label[1]+1}:#{label[0]}".magenta
397
397
  partition = Array.new
398
398
  # navigate down to the block:
399
- @program[label.last+1..@program.length-1].each.with_index do |instruction, index|
400
- break if instruction.first == :label
401
- if@is_debug
402
- message = " #{index}: #{instruction.first}" +
403
- " #{instruction.last.join(" ") unless instruction.last.empty?}"
404
- puts message.light_yellow
405
- end
406
- partition << instruction
399
+ code_segment = @program[label.last+1..@program.length-1]
400
+ code_segment.each.with_index do |statement, index|
401
+ break if statement.first == :label
402
+ partition << statement
403
+ puts (read_internal statement, index).light_yellow if @is_debug
407
404
  end
408
- @partitions[label[0]] = partition.dup
405
+ @partitions[label.first] = partition.dup
409
406
  end
410
407
  end
411
408
  puts "partitioning completed.".light_green
@@ -413,56 +410,7 @@ class Asmrb
413
410
  end
414
411
  end
415
412
 
416
- #testing :
417
- # @a = Asmrb.new do
418
- # _def :factorial
419
- # _arg :acc, :n
420
- # _psh 1
421
- # _psh :n
422
- # _cmp
423
- # _jge :recursion
424
- # _psh :acc
425
- # _ret
426
-
427
- # _blo :recursion
428
-
429
- # _psh :times
430
- # _jnl :init_counter
431
-
432
- # _psh 1
433
- # _psh :times
434
- # _add
435
- # _lea :times
436
- # _jmp :for_fun
437
- # _blo :comeback
438
-
439
- # _psh :acc
440
- # _psh :n
441
- # _mul
442
- # _psh 1
443
- # _psh :n
444
- # _sub
445
- # _rec
446
-
447
- # _blo :for_fun
448
- # _psh "recursions counts:"
449
- # _cal :puts
450
- # _psh :times
451
- # _cal :puts
452
- # _jmp :comeback
453
-
454
- # _blo :init_counter
455
- # _psh 0
456
- # _lea :times
457
- # _jmp :recursion
458
-
459
- # end
460
-
461
- #@a.is_debug = true
462
- #@a.partition
463
- #puts "partitioning test completed."
464
-
465
- #$factorial.is_debug = true
466
- #puts $factorial.invoke 1,3
467
-
468
- #$factorial.compile
413
+ def read_internal instruction, index
414
+ " #{index}: #{instruction.first}" +
415
+ " #{instruction.last.join(" ") unless instruction.last.empty?}"
416
+ end
metadata CHANGED
@@ -1,17 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asmrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2.6.1.3
4
+ version: 0.0.2.6.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Trung
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-29 00:00:00.000000000 Z
11
+ date: 2015-05-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: create a toy assembly-like DSL in ruby, checkout the homepage for usage
14
- & syntax.
13
+ description: create a assembly-like function in ruby.
15
14
  email: deulamco@gmail.com
16
15
  executables: []
17
16
  extensions: []