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.
- checksums.yaml +4 -4
- data/lib/asmrb.rb +27 -79
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 327f8a64c7dd648f81b9047b9d13dbbd067be247
|
4
|
+
data.tar.gz: 21f417fb164ba9c7fdf188015b14f885687d891a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
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
|
-
"
|
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?
|
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
|
280
|
-
self.instance_exec
|
279
|
+
def load_program &block
|
280
|
+
self.instance_exec &block
|
281
281
|
end
|
282
282
|
|
283
|
-
def execute
|
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
|
307
|
+
def fast_execute *args
|
308
308
|
arguments args
|
309
309
|
@pc = 0
|
310
|
-
until
|
310
|
+
until @pc == @program.length
|
311
311
|
# execute proc:
|
312
|
-
self.instance_exec
|
313
|
-
&OPS[@program[@pc]
|
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
|
-
|
318
|
+
@result
|
319
319
|
end
|
320
320
|
|
321
|
-
def new_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
|
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
|
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]
|
400
|
-
|
401
|
-
if
|
402
|
-
|
403
|
-
|
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
|
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
|
-
|
417
|
-
#
|
418
|
-
#
|
419
|
-
|
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.
|
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-
|
11
|
+
date: 2015-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: create a
|
14
|
-
& syntax.
|
13
|
+
description: create a assembly-like function in ruby.
|
15
14
|
email: deulamco@gmail.com
|
16
15
|
executables: []
|
17
16
|
extensions: []
|