From ebf331532d28e43ee8a6fea8f09820162fd00ab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ma=C5=A1karinec?= Date: Sun, 25 Feb 2024 12:15:01 +0100 Subject: [PATCH] Fixes for recent umka versions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marek Maškarinec --- Makefile | 7 ++++++- main.c | 45 ++++++++++++++++++++++++++++++--------------- umka-lang | 2 +- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 81171a2..1103ea7 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,11 @@ .PHONY: build -build: umka-lang/build/libumka.a +build: umprof + +umka-lang/build/libumka.a: + make -C umka-lang + +umprof: main.c umka-lang/build/libumka.a $(CC) main.c umka-lang/build/libumka.a -lm -ldl -o umprof .PHONY: clean diff --git a/main.c b/main.c index e179b09..8dc42f6 100644 --- a/main.c +++ b/main.c @@ -1,16 +1,25 @@ -#include -#include #include "umka-lang/src/umka_api.h" +#include +#include #define UMPROF_IMPL #include "umprof.h" +static void +printHelp() +{ + printf("Umprof - a simple umka profiler.\numprof [ -j ] [ -o output-file ] source-file\n"); +} -void printHelp() { - printf("Umprof - a simple umka profiler.\numprof [ -o output-file ] source-file\n"); +static void +warningCallback(UmkaError *warn) +{ + fprintf(stderr, "Warning: %s:%d: %s\n", warn->fileName, warn->line, warn->msg); } -int main(int argc, char *argv[]) { +int +main(int argc, char *argv[]) +{ if (argc < 2) { printHelp(); return 1; @@ -19,8 +28,9 @@ int main(int argc, char *argv[]) { bool json = 0; int argoff = 1; - for (; argoff < argc-1; argoff++) { - if (argv[argoff][0] != '-') break; + for (; argoff < argc - 1; argoff++) { + if (argv[argoff][0] != '-') + break; if (strcmp(argv[argoff], "-j") == 0) json = 1; @@ -42,22 +52,26 @@ int main(int argc, char *argv[]) { } void *umka = umkaAlloc(); - if (!umkaInit(umka, argv[argoff], NULL, 0, 1024 * 1024, NULL, argc - argoff, argv + argoff)) + if (!umkaInit(umka, argv[argoff], NULL, 1024 * 1024, NULL, argc - argoff, argv + argoff, + true, true, warningCallback)) return 1; umprofInit(umka); if (!umkaCompile(umka)) { UmkaError error; umkaGetError(umka, &error); - fprintf(stderr, "Error %s (%d, %d): %s\n", error.fileName, error.line, error.pos, error.msg); + fprintf(stderr, "Error %s (%d, %d): %s\n", error.fileName, error.line, error.pos, + error.msg); return 1; } - if (!umkaRun(umka)) { - UmkaError error; - umkaGetError(umka, &error); - fprintf(stderr, "\nRuntime error %s (%d): %s\n", error.fileName, error.line, error.msg); - return 1; + int exitCode = umkaRun(umka); + if (exitCode != 0) { + UmkaError error; + umkaGetError(umka, &error); + fprintf( + stderr, "\nRuntime error %s (%d): %s\n", error.fileName, error.line, error.msg); + return exitCode; } if (json) { @@ -68,7 +82,8 @@ int main(int argc, char *argv[]) { umprofPrintInfo(of, info, len); } - if (of != stdout) fclose(of); + if (of != stdout) + fclose(of); return 0; } diff --git a/umka-lang b/umka-lang index 0c1fa23..783d2d2 160000 --- a/umka-lang +++ b/umka-lang @@ -1 +1 @@ -Subproject commit 0c1fa2304d1eeeed8749b03a93ef391fbcbe05cf +Subproject commit 783d2d2732c628d1315341190532b2d8acde646e -- 2.45.2