asmrb 0.0.2.5 → 0.0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/asmrb.rb +32 -27
- 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: 771ddde246ce924141e25cc6c4f8d6a95342f74c
|
4
|
+
data.tar.gz: 8dd350e2b9e6d536a019c553c4d229d1e9325e2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06a741a3c1589f1b6ffc4afc70f5596e462e0a5c3abaa84ef46ef56f814a9a3f2dd690092a38ac66ebbb4a482e426840d4e4885b5ae2b4dc4d79c81f8a4bc766
|
7
|
+
data.tar.gz: c0729a4f76c4ab2835e019f59493dabce3e4080eaad0749d4ae1b802b41ca648173e81857df8a55deeff770b6db2145926df467aaf7a7cd9d2712cbd17bf2997
|
data/lib/asmrb.rb
CHANGED
@@ -84,20 +84,24 @@ class Asm
|
|
84
84
|
@stack.push e
|
85
85
|
},
|
86
86
|
|
87
|
-
"
|
88
|
-
@
|
87
|
+
"dupl" => lambda {
|
88
|
+
@stack.push @stack.last
|
89
89
|
},
|
90
90
|
|
91
|
-
"
|
92
|
-
@
|
91
|
+
"add" => lambda {
|
92
|
+
@stack.push @stack.pop + @stack.pop
|
93
93
|
},
|
94
94
|
|
95
|
-
"
|
96
|
-
@
|
95
|
+
"sub" => lambda {
|
96
|
+
@stack.push @stack.pop - @stack.pop
|
97
97
|
},
|
98
98
|
|
99
|
-
"
|
100
|
-
@
|
99
|
+
"mul" => lambda {
|
100
|
+
@stack.push @stack.pop * @stack.pop
|
101
|
+
},
|
102
|
+
|
103
|
+
"div" => lambda {
|
104
|
+
@stack.push @stack.pop / @stack.pop
|
101
105
|
},
|
102
106
|
|
103
107
|
"incr" => lambda { |dest, incval = 1|
|
@@ -114,6 +118,12 @@ class Asm
|
|
114
118
|
@variables[src] : src
|
115
119
|
},
|
116
120
|
|
121
|
+
|
122
|
+
"jz" => lambda { | name |
|
123
|
+
req_args "jz", 1
|
124
|
+
@pc = @labels[name] if @stack.pop == 0
|
125
|
+
},
|
126
|
+
|
117
127
|
"jnz" => lambda { | name |
|
118
128
|
req_args "jnz", 1
|
119
129
|
@pc = @labels[name] if @stack.pop != 0
|
@@ -134,11 +144,12 @@ class Asm
|
|
134
144
|
@pc = @labels[name] if @stack.pop == :eq
|
135
145
|
},
|
136
146
|
|
137
|
-
"cmp" => lambda {
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
147
|
+
"cmp" => lambda {
|
148
|
+
a = @stack.pop
|
149
|
+
b = @stack.pop
|
150
|
+
@stack.push(
|
151
|
+
a > b ? :gt
|
152
|
+
: a == b ? :eq : :lt )
|
142
153
|
},
|
143
154
|
|
144
155
|
|
@@ -167,7 +178,7 @@ class Asm
|
|
167
178
|
},
|
168
179
|
|
169
180
|
"req" => lambda {|amount|
|
170
|
-
raise Exception.new "require #{amount}
|
181
|
+
raise Exception.new "require #{amount} arg." if @stack.length < amount
|
171
182
|
},
|
172
183
|
|
173
184
|
"dbg" => lambda {
|
@@ -183,16 +194,6 @@ class Asm
|
|
183
194
|
end
|
184
195
|
eval "$#{name}.is_debug = true" if @is_debug
|
185
196
|
o = eval "$#{name}.invoke #{args.join(',')}"
|
186
|
-
# for some reasons, this pointer is increased,
|
187
|
-
# after invoking the outside function.
|
188
|
-
# @@pc is belong to class, sync with all objects
|
189
|
-
# made with this class.
|
190
|
-
# while @pc is stick to instance that created
|
191
|
-
# by this class.
|
192
|
-
# which is why invoking other Asm, cause @@pc
|
193
|
-
# to increase, while @pc don't.
|
194
|
-
# to test this problem, uncomment below and rake test:
|
195
|
-
#@pc += 1
|
196
197
|
@stack.push o if !o.nil?
|
197
198
|
#binding.pry
|
198
199
|
},
|
@@ -379,15 +380,19 @@ end
|
|
379
380
|
Asm.new do
|
380
381
|
defn :factorial
|
381
382
|
arg acc, n
|
382
|
-
|
383
|
+
push 1
|
384
|
+
push n
|
385
|
+
cmp
|
383
386
|
jge :recursion
|
384
387
|
jmp :exit
|
385
388
|
|
386
389
|
label :recursion
|
387
|
-
mul n, acc
|
388
|
-
sub 1, n
|
389
390
|
push acc
|
390
391
|
push n
|
392
|
+
mul
|
393
|
+
push 1
|
394
|
+
push n
|
395
|
+
sub
|
391
396
|
jmp :factorial
|
392
397
|
label :exit
|
393
398
|
push acc
|
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.
|
4
|
+
version: 0.0.2.6
|
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-02-
|
11
|
+
date: 2015-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: create a toy assembly-like DSL in ruby
|
14
14
|
email: deulamco@gmail.com
|