yabfi 0.1.1 → 0.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/Rakefile +5 -3
- data/ext/yabfi/vm.c +41 -33
- data/lib/yabfi/version.rb +1 -1
- 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: f9633d4e62ce949c21115b65a315f836a40620ac
|
4
|
+
data.tar.gz: 6a66c94a80e5dfcc1d65590948b637782f96da63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15ca15fccdffd34bf6a1c1b560213952b6c58c3fd292b62fa0b6bd7fbfc899774333f194912147733e72b3221f79f56b34a555ea2c54886312d6f5dd403ce7e0
|
7
|
+
data.tar.gz: cc3808bc3061ba529f71496127e3247130a26bbe130d1a8fb2a8661b494712c3a2eab73e05c58b4f94c6ee8076ca9fb29eb45cc5d765dcebbc0f8bd3be1e0147
|
data/Rakefile
CHANGED
@@ -23,7 +23,9 @@ desc 'Run the specs'
|
|
23
23
|
RSpec::Core::RakeTask.new(spec: :compile)
|
24
24
|
|
25
25
|
desc 'Run the code quality metrics'
|
26
|
-
RuboCop::RakeTask.new(:quality)
|
26
|
+
RuboCop::RakeTask.new(:quality) do |task|
|
27
|
+
task.patterns = GEMSPEC.files.grep(/((\.rb)|(Rakefile))\z/)
|
28
|
+
end
|
27
29
|
|
28
30
|
desc 'Generate gem documentation'
|
29
31
|
YARD::Rake::YardocTask.new(:doc)
|
@@ -41,7 +43,7 @@ task shell: :environment do
|
|
41
43
|
end
|
42
44
|
|
43
45
|
desc 'Clean the files generated by other tasks'
|
44
|
-
task :
|
46
|
+
task blank: :clobber do
|
45
47
|
%w(coverage doc pkg tmp).each do |partial|
|
46
48
|
path = File.expand_path(partial, File.dirname(__FILE__))
|
47
49
|
next unless File.exist?(path)
|
@@ -50,4 +52,4 @@ task :clean do
|
|
50
52
|
end
|
51
53
|
|
52
54
|
desc 'Run the specs, quality metrics, and documentation tasks'
|
53
|
-
task default: [:
|
55
|
+
task default: [:blank, :spec, :quality, :doc]
|
data/ext/yabfi/vm.c
CHANGED
@@ -40,12 +40,15 @@ typedef struct {
|
|
40
40
|
int eof;
|
41
41
|
|
42
42
|
instruction *instructions;
|
43
|
-
size_t
|
43
|
+
size_t instructions_size;
|
44
44
|
size_t program_counter;
|
45
45
|
|
46
46
|
int *memory;
|
47
|
-
size_t
|
47
|
+
size_t memory_size;
|
48
48
|
size_t memory_cursor;
|
49
|
+
|
50
|
+
char *buffer;
|
51
|
+
size_t buffer_size;
|
49
52
|
} vm;
|
50
53
|
|
51
54
|
/**
|
@@ -83,13 +86,17 @@ static void
|
|
83
86
|
vm_free(void *p) {
|
84
87
|
vm *ptr = p;
|
85
88
|
|
86
|
-
if (ptr->
|
89
|
+
if (ptr->instructions_size > 0) {
|
87
90
|
free(ptr->instructions);
|
88
91
|
}
|
89
92
|
|
90
|
-
if (ptr->
|
93
|
+
if (ptr->memory_size > 0) {
|
91
94
|
free(ptr->memory);
|
92
95
|
}
|
96
|
+
|
97
|
+
if (ptr->buffer_size > 0) {
|
98
|
+
free(ptr->buffer);
|
99
|
+
}
|
93
100
|
}
|
94
101
|
|
95
102
|
/**
|
@@ -107,13 +114,16 @@ vm_alloc(VALUE klass) {
|
|
107
114
|
ptr->eof = 0;
|
108
115
|
|
109
116
|
ptr->instructions = NULL;
|
110
|
-
ptr->
|
117
|
+
ptr->instructions_size = 0;
|
111
118
|
ptr->program_counter = 0;
|
112
119
|
|
113
120
|
ptr->memory = NULL;
|
114
|
-
ptr->
|
121
|
+
ptr->memory_size = 0;
|
115
122
|
ptr->memory_cursor = 0;
|
116
123
|
|
124
|
+
ptr->buffer = NULL;
|
125
|
+
ptr->buffer_size = 0;
|
126
|
+
|
117
127
|
return instance;
|
118
128
|
}
|
119
129
|
|
@@ -166,15 +176,20 @@ vm_load(VALUE self, VALUE ary) {
|
|
166
176
|
|
167
177
|
Check_Type(ary, T_ARRAY);
|
168
178
|
|
179
|
+
vm_free(ptr);
|
180
|
+
|
169
181
|
ptr->memory_cursor = 0;
|
170
|
-
ptr->
|
182
|
+
ptr->memory_size = INITIAL_MEMORY_SIZE;
|
171
183
|
ptr->memory = calloc(INITIAL_MEMORY_SIZE, sizeof(int));
|
172
184
|
|
173
185
|
ptr->program_counter = 0;
|
174
|
-
ptr->
|
175
|
-
ptr->instructions = malloc(sizeof(instruction) * ptr->
|
186
|
+
ptr->instructions_size = RARRAY_LEN(ary);
|
187
|
+
ptr->instructions = malloc(sizeof(instruction) * ptr->instructions_size);
|
188
|
+
|
189
|
+
ptr->buffer_size = INITIAL_BUFFER_SIZE;
|
190
|
+
ptr->buffer = malloc(INITIAL_BUFFER_SIZE * sizeof(char));
|
176
191
|
|
177
|
-
for (iter = 0; iter < (int) ptr->
|
192
|
+
for (iter = 0; iter < (int) ptr->instructions_size; iter++) {
|
178
193
|
entry = rb_ary_entry(ary, iter);
|
179
194
|
Check_Type(entry, T_ARRAY);
|
180
195
|
if (RARRAY_LEN(entry) != 2) {
|
@@ -206,18 +221,14 @@ vm_load(VALUE self, VALUE ary) {
|
|
206
221
|
static VALUE
|
207
222
|
vm_execute(VALUE self) {
|
208
223
|
vm *ptr;
|
209
|
-
char *buffer;
|
210
224
|
int *tmp_memory;
|
211
|
-
int buffer_size;
|
212
225
|
int delta;
|
213
226
|
int iter;
|
214
227
|
instruction curr;
|
215
228
|
|
216
229
|
Data_Get_Struct(self, vm, ptr);
|
217
|
-
buffer_size = INITIAL_BUFFER_SIZE;
|
218
|
-
buffer = malloc(buffer_size * sizeof(char));
|
219
230
|
|
220
|
-
while (ptr->program_counter < ptr->
|
231
|
+
while (ptr->program_counter < ptr->instructions_size) {
|
221
232
|
curr = ptr->instructions[ptr->program_counter];
|
222
233
|
switch (curr.code) {
|
223
234
|
case INSTRUCTION_CHANGE_VALUE:
|
@@ -229,16 +240,16 @@ vm_execute(VALUE self) {
|
|
229
240
|
rb_raise(rb_cMemoryOutOfBounds, "The memory cursor went below zero");
|
230
241
|
}
|
231
242
|
ptr->memory_cursor += curr.argument;
|
232
|
-
while (ptr->memory_cursor >= ptr->
|
233
|
-
delta = ptr->
|
243
|
+
while (ptr->memory_cursor >= ptr->memory_size) {
|
244
|
+
delta = ptr->memory_size;
|
234
245
|
if (delta > MAX_REALLOCATION) {
|
235
246
|
delta = MAX_REALLOCATION;
|
236
247
|
}
|
237
248
|
tmp_memory = ptr->memory;
|
238
|
-
ptr->memory = malloc((ptr->
|
239
|
-
memcpy(ptr->memory, tmp_memory, ptr->
|
240
|
-
memset(ptr->memory + ptr->
|
241
|
-
ptr->
|
249
|
+
ptr->memory = malloc((ptr->memory_size + delta) * sizeof(int));
|
250
|
+
memcpy(ptr->memory, tmp_memory, ptr->memory_size * sizeof(int));
|
251
|
+
memset(ptr->memory + ptr->memory_size, 0, delta * sizeof(int));
|
252
|
+
ptr->memory_size += delta;
|
242
253
|
free(tmp_memory);
|
243
254
|
}
|
244
255
|
ptr->program_counter++;
|
@@ -269,25 +280,22 @@ vm_execute(VALUE self) {
|
|
269
280
|
ptr->program_counter++;
|
270
281
|
break;
|
271
282
|
case INSTRUCTION_PUT:
|
272
|
-
if (buffer_size < curr.argument) {
|
273
|
-
free(buffer);
|
274
|
-
buffer_size = curr.argument;
|
275
|
-
buffer = malloc(buffer_size * sizeof(char));
|
283
|
+
if (ptr->buffer_size < curr.argument) {
|
284
|
+
free(ptr->buffer);
|
285
|
+
ptr->buffer_size = curr.argument;
|
286
|
+
ptr->buffer = malloc(ptr->buffer_size * sizeof(char));
|
276
287
|
}
|
277
|
-
memset(buffer, ptr->memory[ptr->memory_cursor],
|
288
|
+
memset(ptr->buffer, ptr->memory[ptr->memory_cursor],
|
278
289
|
curr.argument * sizeof(char));
|
279
290
|
rb_funcall(ptr->output, rb_intern("write"), 1,
|
280
|
-
rb_str_new(buffer, curr.argument));
|
291
|
+
rb_str_new(ptr->buffer, curr.argument));
|
281
292
|
ptr->program_counter++;
|
282
293
|
break;
|
283
294
|
default:
|
284
|
-
free(buffer);
|
285
295
|
rb_raise(rb_cInvalidCommand, "Invalid command code: %i", curr.code);
|
286
296
|
}
|
287
297
|
}
|
288
298
|
|
289
|
-
free(buffer);
|
290
|
-
|
291
299
|
return Qnil;
|
292
300
|
}
|
293
301
|
|
@@ -304,11 +312,11 @@ vm_state(VALUE self) {
|
|
304
312
|
|
305
313
|
rb_hash_aset(hash, ID2SYM(rb_intern("memory_cursor")),
|
306
314
|
INT2FIX(ptr->memory_cursor));
|
307
|
-
rb_hash_aset(hash, ID2SYM(rb_intern("
|
308
|
-
INT2FIX(ptr->
|
315
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("memory_size")),
|
316
|
+
INT2FIX(ptr->memory_size));
|
309
317
|
rb_hash_aset(hash, ID2SYM(rb_intern("program_counter")),
|
310
318
|
INT2FIX(ptr->program_counter));
|
311
|
-
if (ptr->memory_cursor < ptr->
|
319
|
+
if (ptr->memory_cursor < ptr->memory_size) {
|
312
320
|
rb_hash_aset(hash, ID2SYM(rb_intern("current_value")),
|
313
321
|
INT2FIX(ptr->memory[ptr->memory_cursor]));
|
314
322
|
} else {
|
data/lib/yabfi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yabfi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Hulihan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|