asmrb 0.0.2.6.1.2 → 0.0.2.6.1.3
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 +86 -86
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43288f18e0561f0edf394d9522578c582ea0956e
|
4
|
+
data.tar.gz: 3007f21ca287b145f4a04222c653433c74065cfc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 922176943cbb5921580c25157f6845f2453976a68d8fa93807f7656065c2ad4d236d0d13a28f3d353e035a127e27ca46103184343f25c7bffcd9811bb2db29c2
|
7
|
+
data.tar.gz: c27e8a276ae85073b5422e4b61c50bba94e6a27d85de9345ecb369277bee13a175b6eb7de6690d232014e0f6593e6b6efc213c8cdd46b78ff336dfc8d87a67a9
|
data/lib/asmrb.rb
CHANGED
@@ -70,6 +70,9 @@ class Asmrb
|
|
70
70
|
end
|
71
71
|
|
72
72
|
OPS = {
|
73
|
+
"lea" => lambda { | name |
|
74
|
+
@variables[name] = @stack.pop
|
75
|
+
},
|
73
76
|
|
74
77
|
"len" => lambda { | lst |
|
75
78
|
@stack.push @variables[lst].length
|
@@ -89,7 +92,7 @@ class Asmrb
|
|
89
92
|
@stack.push e
|
90
93
|
},
|
91
94
|
|
92
|
-
"
|
95
|
+
"dup" => lambda {
|
93
96
|
@stack.push @stack.last
|
94
97
|
},
|
95
98
|
|
@@ -109,11 +112,11 @@ class Asmrb
|
|
109
112
|
@stack.push @stack.pop / @stack.pop
|
110
113
|
},
|
111
114
|
|
112
|
-
"
|
115
|
+
"icr" => lambda { |dest, incval = 1|
|
113
116
|
@variables[dest] += incval
|
114
117
|
},
|
115
118
|
|
116
|
-
"
|
119
|
+
"dcr" => lambda { |dest, decrval = 1|
|
117
120
|
@variables[dest] -= decrval
|
118
121
|
},
|
119
122
|
|
@@ -123,6 +126,11 @@ class Asmrb
|
|
123
126
|
@variables[src] : src
|
124
127
|
},
|
125
128
|
|
129
|
+
"jnl" => lambda { | name |
|
130
|
+
req_args "jnl", 1
|
131
|
+
@pc = @labels[name] if @stack.pop.nil?
|
132
|
+
},
|
133
|
+
|
126
134
|
"jz" => lambda { | name |
|
127
135
|
req_args "jz", 1
|
128
136
|
@pc = @labels[name] if @stack.pop == 0
|
@@ -166,7 +174,7 @@ class Asmrb
|
|
166
174
|
@variables[val] = @stack.pop
|
167
175
|
},
|
168
176
|
|
169
|
-
"
|
177
|
+
"psh" => lambda {|src|
|
170
178
|
@stack.push(
|
171
179
|
src.is_a?(Symbol) ? @variables[src] : src )
|
172
180
|
},
|
@@ -190,7 +198,7 @@ class Asmrb
|
|
190
198
|
#binding.pry if @is_debug
|
191
199
|
},
|
192
200
|
|
193
|
-
"
|
201
|
+
"fn" => lambda {|name|
|
194
202
|
args = []
|
195
203
|
params = eval "$#{name}.params"
|
196
204
|
params.times do
|
@@ -202,15 +210,15 @@ class Asmrb
|
|
202
210
|
#binding.pry
|
203
211
|
},
|
204
212
|
|
205
|
-
"
|
206
|
-
req_args "
|
213
|
+
"inv" => lambda { |obj, f , n|
|
214
|
+
req_args "inv",n # obj.send(:func, args)
|
207
215
|
args = []
|
208
216
|
n.times { args << @stack.pop } if n > 0
|
209
217
|
result = @variables[obj].send(f, eval("args.join(', ')"))
|
210
218
|
@stack.push result
|
211
219
|
},
|
212
220
|
|
213
|
-
"
|
221
|
+
"cal" => lambda {|fname|
|
214
222
|
_method = method(fname)
|
215
223
|
if _method.parameters.length > 0
|
216
224
|
args = []
|
@@ -223,7 +231,7 @@ class Asmrb
|
|
223
231
|
end
|
224
232
|
@stack.push invoke if !invoke.nil?
|
225
233
|
},
|
226
|
-
"
|
234
|
+
"rec" => lambda {
|
227
235
|
@pc = -1
|
228
236
|
},
|
229
237
|
|
@@ -231,14 +239,14 @@ class Asmrb
|
|
231
239
|
@pc = @program.length-1
|
232
240
|
},
|
233
241
|
|
234
|
-
"
|
242
|
+
"end" => lambda {
|
235
243
|
exit
|
236
244
|
}
|
237
245
|
}
|
238
246
|
|
239
|
-
def create_label
|
240
|
-
@labels[
|
241
|
-
puts "#{@label[
|
247
|
+
def create_label blo
|
248
|
+
@labels[blo] = @program.length-1
|
249
|
+
puts "#{@label[blo]}: #{blo}".purple if @is_debug
|
242
250
|
end
|
243
251
|
|
244
252
|
def method_missing(name, *args)
|
@@ -246,7 +254,7 @@ class Asmrb
|
|
246
254
|
@source << [name, args]
|
247
255
|
|
248
256
|
# :name => "name"
|
249
|
-
sname = name.to_s
|
257
|
+
sname = name.to_s.gsub "_", ""
|
250
258
|
|
251
259
|
if OPS.keys.include?(sname)
|
252
260
|
@program << [sname, args]
|
@@ -255,10 +263,10 @@ class Asmrb
|
|
255
263
|
else
|
256
264
|
case sname
|
257
265
|
|
258
|
-
when "
|
266
|
+
when "blo"
|
259
267
|
create_label args.first
|
260
268
|
|
261
|
-
when "
|
269
|
+
when "def"
|
262
270
|
@name = args.first
|
263
271
|
#create_label args.first
|
264
272
|
|
@@ -280,7 +288,7 @@ class Asmrb
|
|
280
288
|
until @pc == @program.length
|
281
289
|
# get instruction:
|
282
290
|
instr = @program[@pc]
|
283
|
-
puts "#{@pc}: #{instr[0]} #{instr[1]}".light_green if debug
|
291
|
+
puts "#{@pc}: #{instr[0]} #{instr[1].join " "}".light_green if debug
|
284
292
|
# execute proc: arg , proc
|
285
293
|
self.instance_exec *instr[1], &OPS[instr[0]]
|
286
294
|
#binding.pry if debug
|
@@ -378,89 +386,81 @@ class Asmrb
|
|
378
386
|
eval "$#{@name}"
|
379
387
|
end
|
380
388
|
|
381
|
-
|
382
|
-
def self.fac(acc, n)
|
383
|
-
if(n > 0)
|
384
|
-
fac(
|
385
|
-
(acc * n),
|
386
|
-
(n - 1))
|
387
|
-
else
|
388
|
-
acc
|
389
|
-
end
|
390
|
-
end
|
391
|
-
|
392
|
-
def llvm_init
|
393
|
-
LLVM.init_jit
|
394
|
-
@mod = LLVM::Module.new @name.to_s
|
395
|
-
puts "[LLVM]: initialized".light_green
|
396
|
-
end
|
397
|
-
|
398
|
-
def llvm_finalize
|
399
|
-
@mod.verify
|
400
|
-
@mod.dump
|
401
|
-
@engine = LLVM::JITCompiler.new(@mod)
|
402
|
-
end
|
403
|
-
|
404
|
-
def llvm_partition
|
389
|
+
def partition
|
405
390
|
puts "partitioning...".light_green if@is_debug
|
406
391
|
if @labels.empty?
|
407
|
-
@partitions = { @name => @
|
392
|
+
@partitions = { @name => @program }
|
408
393
|
else
|
409
|
-
@partitions =
|
410
|
-
index = 0
|
394
|
+
@partitions = Hash.new
|
411
395
|
@labels.each do |label|
|
412
|
-
puts "
|
413
|
-
partition =
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
index
|
419
|
-
|
420
|
-
|
421
|
-
break
|
396
|
+
puts "#{label[1]+1}:#{label[0]}".magenta
|
397
|
+
partition = Array.new
|
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
|
422
405
|
end
|
406
|
+
partition << instruction
|
423
407
|
end
|
424
408
|
@partitions[label[0]] = partition.dup
|
425
409
|
end
|
426
410
|
end
|
427
|
-
puts "
|
411
|
+
puts "partitioning completed.".light_green
|
428
412
|
@partitions if@is_debug
|
429
413
|
end
|
430
|
-
|
431
|
-
def llvm_emit
|
432
|
-
# Checkout kaleidescope sample of ruby-llvm
|
433
|
-
end
|
434
|
-
|
435
|
-
def compile
|
436
|
-
llvm_init
|
437
|
-
llvm_partition
|
438
|
-
llvm_emit
|
439
|
-
#llvm_finalize
|
440
|
-
end
|
441
|
-
|
442
414
|
end
|
443
415
|
|
444
416
|
#testing :
|
445
|
-
Asmrb.new do
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
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
464
|
|
465
465
|
#$factorial.is_debug = true
|
466
466
|
#puts $factorial.invoke 1,3
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.3
|
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-
|
11
|
+
date: 2015-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: create a toy assembly-like DSL in ruby, checkout the homepage for usage
|
14
14
|
& syntax.
|