diff options
author | pommicket <pommicket@gmail.com> | 2022-02-13 14:35:34 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-02-13 14:35:34 -0500 |
commit | 6acd24e315c4351294c7f2e9b88fdd5faf48b966 (patch) | |
tree | fc044b6ab6efde3f926db06092527c6c335d1d37 | |
parent | 239a1a3c271d03e9202b9dc62d87e6ee631d0d40 (diff) |
C compiler done ? va_list/arg program working :)
-rw-r--r-- | 05/main.c | 18 | ||||
-rw-r--r-- | 05/parse.b | 8 |
2 files changed, 21 insertions, 5 deletions
@@ -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) { if (x == 0) { return 1; @@ -28,6 +44,6 @@ int f() { } 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_base_type(base_type) - puts(.str_typedef) - putc(32) - print_type(type) - putc(10) + ;puts(.str_typedef) + ;putc(32) + ;print_type(type) + ;putc(10) b = ident_list_lookup(typedefs, ident) if b != 0 goto typedef_redefinition |