Skip to content

Commit 5c3d4ce

Browse files
fixed issue #22
1 parent 13663e4 commit 5c3d4ce

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

src/io.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,16 @@ namespace fastcode {
185185

186186
return gc->new_apartment(new value(VALUE_TYPE_NUMERICAL, new long double(1)));
187187
}
188+
189+
runtime::reference_apartment* system_call(std::list<value*> args, runtime::garbage_collector* gc) {
190+
match_arg_len(args, 1);
191+
match_arg_type(args.front(), VALUE_TYPE_COLLECTION);
192+
193+
char* command = to_c_str(args.front());
194+
system(command);
195+
delete[] command;
196+
197+
return gc->new_apartment(new value(VALUE_TYPE_NULL, nullptr));
198+
}
188199
}
189200
}

src/io.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ namespace fastcode {
1616

1717
runtime::reference_apartment* file_read_text(std::list<value*> args, runtime::garbage_collector* gc);
1818
runtime::reference_apartment* file_write_text(std::list<value*> args, runtime::garbage_collector* gc);
19+
20+
runtime::reference_apartment* system_call(std::list<value*> args, runtime::garbage_collector* gc);
1921
}
2022
void handle_syntax_err(int syntax_error, unsigned int pos, const char* source);
2123
void handle_runtime_err(int runtime_error, parsing::token* err_tok);

src/references.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace fastcode {
5353
}
5454

5555
void reference_apartment::remove_reference(reference_apartment* parent) {
56-
if (this->references == 0)
56+
if (this->references - parent->references < 0)
5757
throw ERROR_CANNOT_DEREFERENCE;
5858
this->references -= parent->references;
5959
unsigned int children_count = 0;

src/runtime.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ namespace fastcode {
4444
import_func("len", builtins::get_length);
4545
import_func("range", builtins::get_range);
4646
import_func("handle", builtins::get_handle);
47+
import_func("system", builtins::system_call);
4748
import_func("read@file", builtins::file_read_text);
4849
import_func("write@file", builtins::file_write_text);
4950
import_func("count@linq", builtins::count_instances);
@@ -332,7 +333,7 @@ namespace fastcode {
332333
call_stack.top()->manager->declare_var(set_tok->destination->get_identifier(), eval->get_value());
333334
}
334335
}
335-
}
336+
}
336337
}
337338
else {
338339
if (eval->type == VALUE_EVAL_TYPE_REF) {

src/variables.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ namespace fastcode {
4848
if (parent == nullptr)
4949
hash_buckets[id_hash % VARIABLE_HASH_BUCKET_SIZE] = new variable_bucket(id_hash, reference);
5050
else
51-
parent = new variable_bucket(id_hash, reference);
51+
parent->next_bucket = new variable_bucket(id_hash, reference);
52+
size++;
5253
return reference;
5354
}
5455

@@ -71,6 +72,7 @@ namespace fastcode {
7172
parent->next_bucket = bucket->next_bucket;
7273
bucket->apartment->remove_reference();
7374
delete bucket;
75+
size--;
7476
}
7577

7678
bool variable_manager::has_var(unsigned long id_hash)

0 commit comments

Comments
 (0)