asmrb 0.0.2.3 → 0.0.2.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 +41 -13
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8b8ea4a6ef9586d90b45b4fbea0d27c3fe25d2c
4
- data.tar.gz: 457793531698daf895a1f3b878a437570fce2b51
3
+ metadata.gz: 65959eb6a15a1ae6dfc55cf8d3b66e6d1a1135fc
4
+ data.tar.gz: c6cba8bc4473c3673d3f3d07fb6e9cf3e3a6470d
5
5
  SHA512:
6
- metadata.gz: 57207355602fa8b5440d45d64de9e62644e2b3e30ec3f97458b98858ea7698a31ec814289e4fa88a2b8ddf05c7ef2d565c34f9d618c4563f90898d9382a1844f
7
- data.tar.gz: 3b82fb7f49b70dc03be8adbd223d7dd253522d1ab1f2a90a55eae70063244a7e947677c6d48ed04a52ef9e31cea8285fd69a7ab1484e2e2af594d61b6c4ce333
6
+ metadata.gz: d20a11f724628741c96756ae0ff8239bec0a4d5102a7ba9cc28d4016cee113bb09c6ff169bbeee707a3f3d81ae16980b5a287179d70655f1e2c1ee46288375ab
7
+ data.tar.gz: 5eb31088ebe69adf432e4293276932a24fa98d5239bc89f2ea1e13392f74e1cc354cf6cc813e2210f94a5c7bddfe69796404813fa40f70414d355e6e47ccb696
data/lib/asmrb.rb CHANGED
@@ -83,20 +83,20 @@ class Asm
83
83
  @stack.push e
84
84
  },
85
85
 
86
- "add" => lambda { | a , b |
87
- @stack.push(refvar(a) + refvar(b))
86
+ "add" => lambda { | a |
87
+ @stack.push(@stack.pop + refvar(a))
88
88
  },
89
89
 
90
- "sub" => lambda { | a , b |
91
- @stack.push(refvar(a) - refvar(b))
90
+ "sub" => lambda { | a |
91
+ @stack.push(@stack.pop - refvar(a))
92
92
  },
93
93
 
94
- "mul" => lambda { | a , b |
95
- @stack.push(refvar(a) * refvar(b))
94
+ "mul" => lambda { | a |
95
+ @stack.push(@stack.pop * refvar(a))
96
96
  },
97
97
 
98
- "div" => lambda { | a , b |
99
- @stack.push(refvar(a) / refvar(b))
98
+ "div" => lambda { | a |
99
+ @stack.push(@stack.pop / refvar(a))
100
100
  },
101
101
 
102
102
  "incr" => lambda { |dest, incval = 1|
@@ -167,7 +167,7 @@ class Asm
167
167
 
168
168
  "dbg" => lambda {
169
169
  puts "#{@stack} > #{@program[@pc][0]}".light_green
170
- binding.pry if @is_debug
170
+ #binding.pry if @is_debug
171
171
  },
172
172
 
173
173
  "func" => lambda {|name|
@@ -182,7 +182,7 @@ class Asm
182
182
  # after invoking the outside function.
183
183
  # @@pc is belong to class, sync with all objects
184
184
  # made with this class.
185
- # while @pc is stick to instance that created
185
+ # while @pc is stick to instance that created
186
186
  # by this class.
187
187
  # which is why invoking other Asm, cause @@pc
188
188
  # to increase, while @pc don't.
@@ -217,8 +217,6 @@ class Asm
217
217
  "exit" => lambda {
218
218
  exit
219
219
  }
220
-
221
- #and so on
222
220
  }
223
221
 
224
222
  def create_label(lbl)
@@ -362,4 +360,34 @@ class Asm
362
360
  end
363
361
  end
364
362
 
365
- end
363
+ def self.fac2(n)
364
+ if(n > 1)
365
+ n * fac2(n - 1)
366
+ else
367
+ 1
368
+ end
369
+ end
370
+
371
+ end
372
+
373
+
374
+ Asm.new do
375
+ defn :factorial
376
+ arg acc, n
377
+ cmp n, 1
378
+ jge :recursion
379
+ jmp :exit
380
+
381
+ label :recursion
382
+ push acc
383
+ mul n
384
+ push n
385
+ sub 1
386
+ jmp :factorial
387
+ label :exit
388
+ push acc
389
+ end
390
+
391
+ $factorial.is_debug = true
392
+
393
+ puts $factorial.invoke 1,3
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asmrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2.3
4
+ version: 0.0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Trung
@@ -10,7 +10,7 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2015-02-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Inteprete your assembly style code inside ruby.
13
+ description: create assembly-like DSL in ruby, use LLVM to speed up.
14
14
  email: deulamco@gmail.com
15
15
  executables: []
16
16
  extensions: []