C compiler done ? va_list/arg program working :)
This commit is contained in:
parent
239a1a3c27
commit
6acd24e315
2 changed files with 21 additions and 5 deletions
18
05/main.c
18
05/main.c
|
@ -1,3 +1,19 @@
|
||||||
|
typedef unsigned long va_list;
|
||||||
|
#define va_start(list, arg) ((list) = (unsigned long)&arg)
|
||||||
|
#define va_arg(list, type) (*((type *)(list += ((sizeof(type) + 7) & 0xfffffffffffffff8))))
|
||||||
|
#define va_end(list)
|
||||||
|
|
||||||
|
int sum(int n, ...) {
|
||||||
|
va_list args;
|
||||||
|
int i;
|
||||||
|
int total = 0;
|
||||||
|
va_start(args, n);
|
||||||
|
for (i = 0; i < n; ++i) {
|
||||||
|
total += va_arg(args, int);
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
long factorial(long x) {
|
long factorial(long x) {
|
||||||
if (x == 0) {
|
if (x == 0) {
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -28,6 +44,6 @@ int f() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
return fibonacci(20);
|
return sum(3, -100, 200, -300);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -376,10 +376,10 @@ function parse_toplevel_declaration
|
||||||
parse_type_declarators(prefix, prefix_end, suffix, suffix_end, 0)
|
parse_type_declarators(prefix, prefix_end, suffix, suffix_end, 0)
|
||||||
parse_base_type(base_type)
|
parse_base_type(base_type)
|
||||||
|
|
||||||
puts(.str_typedef)
|
;puts(.str_typedef)
|
||||||
putc(32)
|
;putc(32)
|
||||||
print_type(type)
|
;print_type(type)
|
||||||
putc(10)
|
;putc(10)
|
||||||
|
|
||||||
b = ident_list_lookup(typedefs, ident)
|
b = ident_list_lookup(typedefs, ident)
|
||||||
if b != 0 goto typedef_redefinition
|
if b != 0 goto typedef_redefinition
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue