hyc

Hydrogen Compiler written in C
git clone git://git.kocotian.pl/hyc.git
Log | Files | Refs | README | LICENSE

commit 43e5406c8db82973d5c42108b838c3ef72da1b90
parent c0fb27b5a910c03b82ea07050acfca1b545d72fc
Author: kocotian <kocotian@kocotian.pl>
Date:   Mon, 26 Jul 2021 18:03:52 +0000

asmAppend() appends to String, not compiler

Diffstat:
Minclude/target/x86_64-linux.h | 1+
Mtarget/x86_64-linux.c | 17+++++++++--------
2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/include/target/x86_64-linux.h b/include/target/x86_64-linux.h @@ -22,6 +22,7 @@ #define _TARGET_H #include <ast.h> +#include <stdlib.h> typedef struct { String text, data; diff --git a/target/x86_64-linux.c b/target/x86_64-linux.c @@ -20,12 +20,13 @@ #include <target/x86_64-linux.h> #include <stdarg.h> +#include <stdio.h> #include <string.h> -static size_t asmAppend(int data, Compiler *compiler, char *fmt, ...); +static size_t asmAppend(String *s, char *fmt, ...); -#define asmTextAppend(...) asmAppend(0, __VA_ARGS__) -#define asmDataAppend(...) asmAppend(1, __VA_ARGS__) +#define asmTextAppend(COMPILER, ...) asmAppend(&((COMPILER)->text), __VA_ARGS__) +#define asmDataAppend(COMPILER, ...) asmAppend(&((COMPILER)->data), __VA_ARGS__) static void compileExpressionLiteralIdentifier(Compiler *compiler, ASTExpressionLiteral expr); static void compileExpressionLiteralInteger(Compiler *compiler, ASTExpressionLiteral expr); @@ -53,20 +54,20 @@ static Array(ASTExpressionLiteral) literalStrings; /////////////////////////////////////////////////////////////////////////////// static size_t -asmAppend(int data, Compiler *compiler, char *fmt, ...) +asmAppend(String *s, char *fmt, ...) { char buf[8192]; size_t wb; va_list ap; - String *a = (data ? &compiler->data : &compiler->text); va_start(ap, fmt); wb = (unsigned)vsnprintf(buf, sizeof buf - 1, fmt, ap); va_end(ap); buf[wb++] = '\n'; buf[wb] = '\0'; - a->data = realloc(a->data, a->len + wb + 1); - strcpy(a->data + a->len, buf); - a->len += wb; + s->data = realloc(s->data, s->len + wb + 1); + strcpy(s->data + s->len, buf); + s->len += wb; + return wb; } /* Expressions ***************************************************************/