mirror of
https://github.com/sigmasternchen/macrofuck
synced 2025-03-15 07:08:56 +00:00
feat: Add read() builtin to read to array/string
This commit is contained in:
parent
b346c25033
commit
aa28a78102
4 changed files with 25 additions and 0 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
decl(print);
|
||||
decl(read_char);
|
||||
decl(read);
|
||||
|
||||
decl(to_str);
|
||||
|
||||
|
@ -15,6 +16,7 @@ static struct builtin_list_item {
|
|||
} builtins[] = {
|
||||
{"print", print},
|
||||
{"read_char", read_char},
|
||||
{"read", read},
|
||||
|
||||
{"to_str", to_str},
|
||||
};
|
||||
|
|
|
@ -47,3 +47,22 @@ extern region_t* read_char(FILE* out, scope_t* scope, size_t argc, region_t** ar
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
extern region_t* read(FILE* out, scope_t* scope, size_t argc, region_t** argv) {
|
||||
if (argc == 0) {
|
||||
// default to read_char
|
||||
return read_char(out, scope, argc, argv);
|
||||
}
|
||||
if (argc != 1) {
|
||||
panic("read() has at most one argument");
|
||||
}
|
||||
|
||||
region_t* region = argv[0];
|
||||
|
||||
for (size_t i = 0; i < region->size; i++) {
|
||||
move_offset(region, i); input();
|
||||
}
|
||||
|
||||
return region;
|
||||
}
|
||||
|
||||
|
|
2
compiler/test/cases/020b-print-read-empty-array.in
Normal file
2
compiler/test/cases/020b-print-read-empty-array.in
Normal file
|
@ -0,0 +1,2 @@
|
|||
print(read([3]));
|
||||
print("\n");
|
2
compiler/test/cases/020b-print-read-empty-array.out
Normal file
2
compiler/test/cases/020b-print-read-empty-array.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
>>>[-]>[-]<[-<<<+>>>>+<]>[-<+>]<[-]>[-]<[-<<+>>>+<]>[-<+>]<[-]>[-]<[-<+>>+<]>[-<+>]<<<<,>,>,<<.>.>.
|
||||
<<[-]++++++++++.
|
Loading…
Reference in a new issue