asmrb 0.0.2.6.1 → 0.0.2.6.1.2
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 +38 -31
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57d706ea40276b6485207d9090aa93329ef6090c
|
4
|
+
data.tar.gz: a7b388a89846c4a280419790c4139578afdb0722
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ac464f3459c2ac32f4454b25a3597b39392791124a05dc7a76fdbe7b30240de7051d8394979f06e27bedf7d094f0f86c32066a331d750ba0715601591213de6
|
7
|
+
data.tar.gz: 7eaa37903c8dd999209ab4fd78512fd29ba5ba2e8ab15fd2ff63d88eed461bee1bf7819674ade9430c4c31ba4645022d0d51bc8ff18415959e648c21489516b3
|
data/lib/asmrb.rb
CHANGED
@@ -21,7 +21,7 @@ class Asmrb
|
|
21
21
|
# car arr # get out first element of arr
|
22
22
|
# call :puts # call ruby's puts
|
23
23
|
# cdr arr # get rest of arr Array
|
24
|
-
#
|
24
|
+
# recur # jump back to :rec_print ( or start of this function )
|
25
25
|
# label :exit # ending label.
|
26
26
|
# end
|
27
27
|
# => $rec_print
|
@@ -37,9 +37,9 @@ class Asmrb
|
|
37
37
|
attr_reader :variables, :stack, :source, :name, :result, :params,:is_debug, :is_compiled
|
38
38
|
attr_writer :is_debug
|
39
39
|
|
40
|
-
def initialize
|
40
|
+
def initialize &block
|
41
41
|
new_scope
|
42
|
-
assemble &block
|
42
|
+
assemble &block unless block.nil?
|
43
43
|
end
|
44
44
|
|
45
45
|
def new_scope
|
@@ -56,7 +56,7 @@ class Asmrb
|
|
56
56
|
@is_compiled = false
|
57
57
|
end
|
58
58
|
|
59
|
-
def refvar
|
59
|
+
def refvar val
|
60
60
|
val.is_a?(Symbol) ? @variables[val] : val
|
61
61
|
end
|
62
62
|
|
@@ -123,7 +123,6 @@ class Asmrb
|
|
123
123
|
@variables[src] : src
|
124
124
|
},
|
125
125
|
|
126
|
-
|
127
126
|
"jz" => lambda { | name |
|
128
127
|
req_args "jz", 1
|
129
128
|
@pc = @labels[name] if @stack.pop == 0
|
@@ -224,7 +223,7 @@ class Asmrb
|
|
224
223
|
end
|
225
224
|
@stack.push invoke if !invoke.nil?
|
226
225
|
},
|
227
|
-
"
|
226
|
+
"recur" => lambda {
|
228
227
|
@pc = -1
|
229
228
|
},
|
230
229
|
|
@@ -237,9 +236,9 @@ class Asmrb
|
|
237
236
|
}
|
238
237
|
}
|
239
238
|
|
240
|
-
def create_label
|
239
|
+
def create_label lbl
|
241
240
|
@labels[lbl] = @program.length-1
|
242
|
-
#
|
241
|
+
puts "#{@label[lbl]}: #{lbl}".purple if @is_debug
|
243
242
|
end
|
244
243
|
|
245
244
|
def method_missing(name, *args)
|
@@ -253,9 +252,7 @@ class Asmrb
|
|
253
252
|
@program << [sname, args]
|
254
253
|
# get parameter amount:
|
255
254
|
@params = args.length if sname == "arg"
|
256
|
-
|
257
255
|
else
|
258
|
-
|
259
256
|
case sname
|
260
257
|
|
261
258
|
when "label"
|
@@ -267,7 +264,6 @@ class Asmrb
|
|
267
264
|
|
268
265
|
else
|
269
266
|
return name
|
270
|
-
|
271
267
|
end
|
272
268
|
end
|
273
269
|
end
|
@@ -281,12 +277,12 @@ class Asmrb
|
|
281
277
|
puts "#{@stack} > #{@name}".yellow if debug
|
282
278
|
begin
|
283
279
|
@pc = 0
|
284
|
-
until
|
280
|
+
until @pc == @program.length
|
285
281
|
# get instruction:
|
286
282
|
instr = @program[@pc]
|
287
283
|
puts "#{@pc}: #{instr[0]} #{instr[1]}".light_green if debug
|
288
284
|
# execute proc: arg , proc
|
289
|
-
self.instance_exec
|
285
|
+
self.instance_exec *instr[1], &OPS[instr[0]]
|
290
286
|
#binding.pry if debug
|
291
287
|
@pc += 1
|
292
288
|
end
|
@@ -322,36 +318,47 @@ class Asmrb
|
|
322
318
|
puts "\n----------------------"
|
323
319
|
end
|
324
320
|
|
325
|
-
def debug
|
321
|
+
def debug e, instr
|
322
|
+
if @pc.nil? || instr.nil?
|
323
|
+
puts "possible null jump:".red
|
324
|
+
binding.pry
|
325
|
+
end
|
326
326
|
puts "\n--------[BUG]---------"
|
327
|
-
|
328
327
|
# error scope:
|
329
|
-
|
330
|
-
|
331
|
-
debug_end = @pc <= (@program.length - 2) ?
|
332
|
-
@pc + 1 : @pc
|
333
|
-
|
328
|
+
scope_begin = @pc >= 1 ? @pc - 1 : 0
|
329
|
+
scope_end = @pc <= (@program.length - 2) ? @pc + 1 : @pc
|
334
330
|
# ranging...
|
335
|
-
(
|
331
|
+
(scope_begin..scope_end).each do | i |
|
336
332
|
instr = @program[i]
|
337
333
|
color = i != @pc ? :light_green : :magenta
|
338
|
-
puts "#{i}: #{instr[0]} #{instr[1]}".colorize color
|
334
|
+
puts "#{i}: #{instr[0]} #{instr[1]}".colorize color
|
335
|
+
end
|
336
|
+
unless instr.nil?
|
337
|
+
puts "\nat line #{@pc}:" +
|
338
|
+
"#{ops_info(@program[@pc][0])}" +
|
339
|
+
"has #{e.message}".colorize(:magenta)
|
339
340
|
end
|
340
|
-
puts "\nat line #{@pc}: #{ops_info(@program[@pc][0])} has #{e.message}".colorize(:magenta) if !instr.nil?
|
341
|
-
# test via pry:
|
342
341
|
binding.pry if is_debug
|
343
342
|
end
|
344
343
|
|
345
|
-
def
|
346
|
-
|
347
|
-
|
344
|
+
def all_ops
|
345
|
+
OPS.map do |k,v|
|
346
|
+
ops_info k
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
def ops_info name
|
351
|
+
parameters = Array.new
|
352
|
+
OPS[name].parameters.each do |pair|
|
353
|
+
parameters << pair.last
|
354
|
+
end
|
348
355
|
"#{name} [#{parameters.join(', ')}]"
|
349
356
|
end
|
350
357
|
|
351
358
|
def arguments(args=[])
|
352
359
|
args.each do | arg |
|
353
|
-
|
354
|
-
|
360
|
+
@stack << arg
|
361
|
+
end
|
355
362
|
end
|
356
363
|
|
357
364
|
def invoke(*args)
|
@@ -365,7 +372,7 @@ class Asmrb
|
|
365
372
|
@stack = []
|
366
373
|
end
|
367
374
|
|
368
|
-
def assemble
|
375
|
+
def assemble &block
|
369
376
|
load_program(&block)
|
370
377
|
eval "$#{@name} = self.clone"
|
371
378
|
eval "$#{@name}"
|
@@ -452,7 +459,7 @@ Asmrb.new do
|
|
452
459
|
push 1
|
453
460
|
push :n
|
454
461
|
sub
|
455
|
-
|
462
|
+
recur
|
456
463
|
end
|
457
464
|
|
458
465
|
#$factorial.is_debug = true
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
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.2
|
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-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: create a toy assembly-like DSL in ruby
|
13
|
+
description: create a toy assembly-like DSL in ruby, checkout the homepage for usage
|
14
|
+
& syntax.
|
14
15
|
email: deulamco@gmail.com
|
15
16
|
executables: []
|
16
17
|
extensions: []
|
@@ -40,6 +41,6 @@ rubyforge_project:
|
|
40
41
|
rubygems_version: 2.4.5
|
41
42
|
signing_key:
|
42
43
|
specification_version: 4
|
43
|
-
summary: assembly-like DSL in ruby
|
44
|
+
summary: assembly-like DSL toy in ruby
|
44
45
|
test_files: []
|
45
46
|
has_rdoc:
|