[qfcc] Support some unicode ops and GA ops

Only · (dot product) and × (cross product for vector, commutator product
for geometric algebra) have been tested so far, but that involved
fighting with cpp to get it to not convert the · to \U000000b7, which
was rather annoying.
This commit is contained in:
Bill Currie 2023-08-17 16:22:49 +09:00
parent a0ddc2b2bd
commit cb4b073e47
5 changed files with 50 additions and 7 deletions

View file

@ -311,6 +311,7 @@ DecodeArgs (int argc, char **argv)
add_cpp_undef ("-undef"); add_cpp_undef ("-undef");
add_cpp_undef ("-nostdinc"); add_cpp_undef ("-nostdinc");
add_cpp_undef ("-fno-extended-identifiers");
add_cpp_def ("-D__QFCC__=1"); add_cpp_def ("-D__QFCC__=1");
add_cpp_def ("-D__QUAKEC__=1"); add_cpp_def ("-D__QUAKEC__=1");

View file

@ -115,6 +115,7 @@ STRING \"(\\.|[^"\\])*\"
grab_frame = GRAB_FRAME; grab_frame = GRAB_FRAME;
grab_other = GRAB_OTHER; grab_other = GRAB_OTHER;
grab_write = GRAB_WRITE; grab_write = GRAB_WRITE;
qc_yylval.pointer = 0; // ensure pointer vals are null
"/*" { BEGIN (COMMENT); } "/*" { BEGIN (COMMENT); }
<COMMENT>"/*" { warning (0, "nested /* in comment"); } <COMMENT>"/*" { warning (0, "nested /* in comment"); }
@ -264,12 +265,18 @@ STRING \"(\\.|[^"\\])*\"
} }
[!(){}.*/&|^~+\-=\[\];,#%?:] { [!(){}.*/&|^~+\-=\[\];,#%?:] {
qc_yylval.pointer = 0; // ensure pointer vals are null
return yytext[0]; return yytext[0];
} }
"·" { return DOT; }
"∧" { return WEDGE; }
"" { return REGRESSIVE; }
"⋀" { return WEDGE; }
"†" { return DAGGER; }
"" { return STAR; }
"×" { return CROSS; }
"%%" { "%%" {
qc_yylval.pointer = 0; // ensure pointer vals are null
return MOD; return MOD;
} }
@ -427,9 +434,11 @@ static keyword_t qf_keywords[] = {
{"@param", TYPE_SPEC, .spec = { .type = &type_param } }, {"@param", TYPE_SPEC, .spec = { .type = &type_param } },
{"@return", AT_RETURN, }, {"@return", AT_RETURN, },
{"@hadamard", HADAMARD, },
{"@cross", CROSS, }, {"@cross", CROSS, },
{"@dot", DOT, }, {"@dot", DOT, },
{"@hadamard", HADAMARD, }, {"@wedge", WEDGE, },
{"@geometric", GEOMETRIC, },
}; };
// These keywors are always available. Other than the @ keywords, they // These keywors are always available. Other than the @ keywords, they

View file

@ -141,9 +141,9 @@ int yylex (void);
%left SHL SHR %left SHL SHR
%left '+' '-' %left '+' '-'
%left '*' '/' '%' MOD SCALE %left '*' '/' '%' MOD SCALE GEOMETRIC
%left CROSS DOT HADAMARD %left HADAMARD CROSS DOT WEDGE REGRESSIVE
%right <op> SIZEOF UNARY INCOP %right <op> SIZEOF UNARY INCOP DAGGER STAR
%left HYPERUNARY %left HYPERUNARY
%left '.' '(' '[' %left '.' '(' '['
@ -1708,9 +1708,11 @@ expr
| expr '^' expr { $$ = binary_expr ('^', $1, $3); } | expr '^' expr { $$ = binary_expr ('^', $1, $3); }
| expr '%' expr { $$ = binary_expr ('%', $1, $3); } | expr '%' expr { $$ = binary_expr ('%', $1, $3); }
| expr MOD expr { $$ = binary_expr (MOD, $1, $3); } | expr MOD expr { $$ = binary_expr (MOD, $1, $3); }
| expr GEOMETRIC expr { $$ = binary_expr (GEOMETRIC, $1, $3); }
| expr HADAMARD expr { $$ = binary_expr (HADAMARD, $1, $3); }
| expr CROSS expr { $$ = binary_expr (CROSS, $1, $3); } | expr CROSS expr { $$ = binary_expr (CROSS, $1, $3); }
| expr DOT expr { $$ = binary_expr (DOT, $1, $3); } | expr DOT expr { $$ = binary_expr (DOT, $1, $3); }
| expr HADAMARD expr { $$ = binary_expr (HADAMARD, $1, $3); } | expr WEDGE expr { $$ = binary_expr (WEDGE, $1, $3); }
; ;
texpr texpr

View file

@ -70,6 +70,7 @@ test_progs_dat=\
tools/qfcc/test/vecexpr.dat \ tools/qfcc/test/vecexpr.dat \
tools/qfcc/test/vecconst.dat \ tools/qfcc/test/vecconst.dat \
tools/qfcc/test/vecinit.dat \ tools/qfcc/test/vecinit.dat \
tools/qfcc/test/vecops.dat \
tools/qfcc/test/voidfor.dat \ tools/qfcc/test/voidfor.dat \
tools/qfcc/test/while.dat \ tools/qfcc/test/while.dat \
tools/qfcc/test/zerolinker.dat tools/qfcc/test/zerolinker.dat
@ -801,6 +802,16 @@ tools/qfcc/test/vecinit.run: $(qfcc_test_run_deps)
include $(vecinit_dep) # am--include-marker include $(vecinit_dep) # am--include-marker
r_depfiles_remade += $(vecinit_dep) r_depfiles_remade += $(vecinit_dep)
tools_qfcc_test_vecops_dat_SOURCES=tools/qfcc/test/vecops.r
vecops_obj=$(tools_qfcc_test_vecops_dat_SOURCES:.r=.o)
vecops_dep=$(call qcautodep,$(tools_qfcc_test_vecops_dat_SOURCES))
tools/qfcc/test/vecops.dat$(EXEEXT): $(vecops_obj) $(QFCC_DEP)
$(V_QFCCLD)$(QLINK) -o $@ $(vecops_obj)
tools/qfcc/test/vecops.run: $(qfcc_test_run_deps)
@$(top_srcdir)/tools/qfcc/test/build-run $@
include $(vecops_dep) # am--include-marker
r_depfiles_remade += $(vecops_dep)
tools_qfcc_test_voidfor_dat_SOURCES=tools/qfcc/test/voidfor.r tools_qfcc_test_voidfor_dat_SOURCES=tools/qfcc/test/voidfor.r
voidfor_obj=$(tools_qfcc_test_voidfor_dat_SOURCES:.r=.o) voidfor_obj=$(tools_qfcc_test_voidfor_dat_SOURCES:.r=.o)
voidfor_dep=$(call qcautodep,$(tools_qfcc_test_voidfor_dat_SOURCES)) voidfor_dep=$(call qcautodep,$(tools_qfcc_test_voidfor_dat_SOURCES))

20
tools/qfcc/test/vecops.r Normal file
View file

@ -0,0 +1,20 @@
#include "test-harness.h"
vector a = { 1, 0, 0 };
vector b = { 0, 1, 0 };
vector c = { 0, 0, 1 };
int
main ()
{
vector v = a × b;
if (v != c) {
printf ("cross product failed\n");
return 1;
};
if (v · c != [1, 1, 1]) {
printf ("dot product failed\n");
return 1;
}
return 0;
}