summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-02-13 14:35:34 -0500
committerpommicket <pommicket@gmail.com>2022-02-13 14:35:34 -0500
commit6acd24e315c4351294c7f2e9b88fdd5faf48b966 (patch)
treefc044b6ab6efde3f926db06092527c6c335d1d37
parent239a1a3c271d03e9202b9dc62d87e6ee631d0d40 (diff)
C compiler done ? va_list/arg program working :)
-rw-r--r--05/main.c18
-rw-r--r--05/parse.b8
2 files changed, 21 insertions, 5 deletions
diff --git a/05/main.c b/05/main.c
index 68140cf..6c19317 100644
--- a/05/main.c
+++ b/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) {
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);
}
diff --git a/05/parse.b b/05/parse.b
index a4ba853..52c8d4a 100644
--- a/05/parse.b
+++ b/05/parse.b
@@ -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