From d0e2c0a9d97636a2b5cd5a1944f2cb5b932593f6 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 29 May 2023 15:14:59 +0900 Subject: [PATCH] [gatest] Allow specifying the algebra on the command line Saves having to recompile for a different algebra. Right now, just `-a p,m,z` is supported. --- ruamoko/gatest/algebra.h | 1 + ruamoko/gatest/algebra.r | 9 +++++++++ ruamoko/gatest/main.r | 41 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/ruamoko/gatest/algebra.h b/ruamoko/gatest/algebra.h index 687a497f6..d6a773454 100644 --- a/ruamoko/gatest/algebra.h +++ b/ruamoko/gatest/algebra.h @@ -15,6 +15,7 @@ BasisLayout *layout; int num_components; int dimension; + int plus, minus, zero; } +(Algebra *) R:(int)p, int m, int z; +(Algebra *) PGA:(int)n; diff --git a/ruamoko/gatest/algebra.r b/ruamoko/gatest/algebra.r index 74cfcc68b..6db1b4ad6 100644 --- a/ruamoko/gatest/algebra.r +++ b/ruamoko/gatest/algebra.r @@ -1,4 +1,5 @@ #include +#include #include "algebra.h" #include "metric.h" @@ -14,6 +15,9 @@ Algebra *a = [[[Algebra alloc] init] autorelease]; a.metric = [[Metric R:p, m, z] retain]; + a.plus = p; + a.minus = m; + a.zero = z; int d = p + m + z; a.dimension = d; a.num_components = 1 << d; @@ -153,4 +157,9 @@ } } +-(string) describe +{ + return sprintf ("R(%d,%d,%d)", plus, minus, zero); +} + @end diff --git a/ruamoko/gatest/main.r b/ruamoko/gatest/main.r index a25457d4f..667b3c66d 100644 --- a/ruamoko/gatest/main.r +++ b/ruamoko/gatest/main.r @@ -396,6 +396,35 @@ get_symtab_key (void *var, void *unused) return ((var_t *) var).name; } +static Algebra * +parse_algebra (string spec) +{ + ivec3 R = {}; + string s = spec; + if (is_digit (str_mid (spec, 0, 1))) { + for (int i = 0; i < 3; i++) { + int end = 0; + R[i] = strtol (s, &end, 0); + string e = str_mid (s, end, end + 1); + if (!e) { + break; + } + if (e != ",") { + goto bad_spec; + } + s = str_mid (s, end + 1); + } + if (!R[0] && !R[1] && !R[2]) { + goto bad_spec; + } + return [Algebra R:R[0], R[1], R[2]]; + } else { + } +bad_spec: + printf ("bad algebra spec: %s\n", spec); + return nil; +} + int main (int argc, string *argv) { @@ -412,10 +441,22 @@ main (int argc, string *argv) arp_end (); arp_start (); for (int i = 1; i < argc; i++) { + if (argv[i] == "-a") { + Algebra *a = [parse_algebra (argv[++i]) retain]; + if (!a) { + return 1; + } + [algebra release]; + algebra = a; + [minus_one release]; + minus_one = [[algebra ofGrade:0 values:&m1] retain]; + continue; + } QFile file = Qopen (argv[i], "rt"); if (file) { arp_end (); arp_start (); + printf ("Using algebra %@\n", algebra); int res = parse_script (argv[i], file); Qclose (file); if (!res) {