mirror of
https://github.com/sigmasternchen/macrofuck
synced 2025-03-15 07:08:56 +00:00
feat: Add first input builtin
This commit is contained in:
parent
cd6d710d13
commit
764450a442
6 changed files with 25 additions and 4 deletions
|
@ -11,7 +11,7 @@ MAKE = make
|
|||
|
||||
PLUGINS =
|
||||
BUILTINS = obj/builtins/builtins.o obj/builtins/numbers.o \
|
||||
obj/builtins/print.o
|
||||
obj/builtins/io.o
|
||||
OBJS = obj/lex.yy.o obj/y.tab.o obj/codegen.o obj/codegen_expr.o \
|
||||
obj/codegen_stat.o obj/ast.o obj/band.o obj/plugins.o obj/scope.o \
|
||||
$(PLUGINS) $(BUILTINS) obj/main.o
|
||||
|
|
|
@ -4,15 +4,19 @@
|
|||
|
||||
#define decl(n) region_t* n(FILE*, scope_t*, size_t, region_t**)
|
||||
|
||||
decl(to_str);
|
||||
decl(print);
|
||||
decl(read_char);
|
||||
|
||||
decl(to_str);
|
||||
|
||||
static struct builtin_list_item {
|
||||
const char* name;
|
||||
builtin_t function;
|
||||
} builtins[] = {
|
||||
{"to_str", to_str},
|
||||
{"print", print},
|
||||
{"read_char", read_char},
|
||||
|
||||
{"to_str", to_str},
|
||||
};
|
||||
|
||||
builtin_t find_builtin(const char* name) {
|
||||
|
|
|
@ -36,3 +36,14 @@ extern region_t* print(FILE* out, scope_t* scope, size_t argc, region_t** argv)
|
|||
region_t* result = scope_add_tmp(scope, 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
extern region_t* read_char(FILE* out, scope_t* scope, size_t argc, region_t** argv) {
|
||||
if (argc != 0) {
|
||||
panic("read_char() doesn't accept arguments");
|
||||
}
|
||||
|
||||
region_t* result = scope_add_tmp(scope, 1);
|
||||
move_to(result); input();
|
||||
|
||||
return result;
|
||||
}
|
|
@ -164,7 +164,11 @@ builtincall: ID OPENING_BRACKETS argumentlist CLOSING_BRACKETS
|
|||
}
|
||||
;
|
||||
|
||||
argumentlist: expr
|
||||
argumentlist: /* empty */
|
||||
{
|
||||
$$ = builtin_call_expression_new();
|
||||
}
|
||||
| expr
|
||||
{
|
||||
$$ = builtin_call_expression_new();
|
||||
builtin_call_expression_add_argument($$, $1);
|
||||
|
|
1
compiler/test/cases/019-read-char.in
Normal file
1
compiler/test/cases/019-read-char.in
Normal file
|
@ -0,0 +1 @@
|
|||
print(read_char());
|
1
compiler/test/cases/019-read-char.out
Normal file
1
compiler/test/cases/019-read-char.out
Normal file
|
@ -0,0 +1 @@
|
|||
,.
|
Loading…
Reference in a new issue