Using TCC again; add clang-format

This commit is contained in:
John Alanbrook 2023-04-21 21:57:30 +00:00
parent 1f3a0091bb
commit 653e80cae8
6 changed files with 266 additions and 41 deletions

217
.clang-format Normal file
View file

@ -0,0 +1,217 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveAssignments:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: true
AlignConsecutiveBitFields:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignConsecutiveDeclarations:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignConsecutiveMacros:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
AttributeMacros:
- __capability
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: Always
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 0
CommentPragmas: '^ IWYU pragma:'
QualifierAlignment: Leave
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
PackConstructorInitializers: BinPack
BasedOnStyle: ''
ConstructorInitializerAllOnOneLineOrOnePerLine: false
AllowAllConstructorInitializersOnNextLine: true
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseLabels: false
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentRequiresClause: true
IndentWidth: 2
IndentWrappedFunctionNames: false
InsertBraces: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
LambdaBodyIndentation: Signature
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PenaltyIndentedWhitespace: 0
PointerAlignment: Right
PPIndentWidth: -1
ReferenceAlignment: Pointer
ReflowComments: true
RemoveBracesLLVM: false
RequiresClausePosition: OwnLine
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterOverloadedOperator: false
AfterRequiresInClause: false
AfterRequiresInExpression: false
BeforeNonEmptyParentheses: false
SpaceAroundPointerQualifiers: Default
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Latest
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
IndentWidth: 2
...

View file

@ -19,7 +19,7 @@ ifeq ($(DBG), 1)
endif endif
else else
LVL = -O2 -DNDEBUG LVL = -O2 -DNDEBUG -flto
INFO = rel INFO = rel
endif endif
@ -72,7 +72,7 @@ SEM = 0.0.1
COM != git rev-parse --short HEAD COM != git rev-parse --short HEAD
VER = $(SEM)-$(COM) VER = $(SEM)-$(COM)
COMPILER_FLAGS = $(includeflag) $(QFLAGS) -MD $(WARNING_FLAGS) -DCP_USE_DOUBLES=0 -DTINYSPLINE_FLOAT_PRECISION -DDUK_USE_SYMBOL_BUILTIN -DVER=\"$(VER)\" -DINFO=\"$(INFO)\" -DCONFIG_BIGNUM=y -DCONFIG_VERSION="2020-11-08" -march=native -std=c99 -c $< -o $@ COMPILER_FLAGS = $(includeflag) $(QFLAGS) -MD $(WARNING_FLAGS) -DCP_USE_DOUBLES=0 -DTINYSPLINE_FLOAT_PRECISION -DVER=\"$(VER)\" -DINFO=\"$(INFO)\" -march=native -std=c99 -c $< -o $@
LIBPATH = -L$(BIN) LIBPATH = -L$(BIN)

View file

@ -83,7 +83,7 @@ void querylist(cpShape *shape, cpContactPointSet *points, void *data)
void querylistbodies(cpBody *body, void *data) void querylistbodies(cpBody *body, void *data)
{ {
cpBB *bbox = data; cpBB *bbox = data;
if (cpBBContainsVect(*bbox, cpBodyGetPosition(body))) { if (cpBBContainsVect(*bbox, cpBodyGetPosition(body))) {
int go = body2id(body); int go = body2id(body);
if (go < 0) return; if (go < 0) return;
@ -137,7 +137,6 @@ int *phys2d_query_box(cpVect pos, cpVect wh)
if (qhits) arrfree(qhits); if (qhits) arrfree(qhits);
cpSpaceShapeQuery(space, box, querylist, NULL); cpSpaceShapeQuery(space, box, querylist, NULL);
cpSpaceEachBody(space, querylistbodies, &bbox); cpSpaceEachBody(space, querylistbodies, &bbox);
cpShapeFree(box); cpShapeFree(box);
@ -207,6 +206,7 @@ void phys2d_init()
} }
void phys2d_set_gravity(cpVect v) { void phys2d_set_gravity(cpVect v) {
YughInfo("Set gravity to %g %g", v.x, v.y);
cpSpaceSetGravity(space, v); cpSpaceSetGravity(space, v);
} }
@ -668,7 +668,7 @@ void duk_call_phys_cb(cpVect norm, struct callee c, int hit, cpArbiter *arb)
JS_SetPropertyStr(js, obj, "hit", JS_NewInt32(js, hit)); JS_SetPropertyStr(js, obj, "hit", JS_NewInt32(js, hit));
JS_SetPropertyStr(js, obj, "sensor", JS_NewBool(js, cpShapeGetSensor(shape2))); JS_SetPropertyStr(js, obj, "sensor", JS_NewBool(js, cpShapeGetSensor(shape2)));
JS_SetPropertyStr(js, obj, "velocity", vec2js(cpArbiterGetSurfaceVelocity(arb))); JS_SetPropertyStr(js, obj, "velocity", vec2js(cpArbiterGetSurfaceVelocity(arb)));
JS_Call(js, c.fn, c.obj, 1, &obj); script_callee(c, 1, &obj);
} }
#define CTYPE_BEGIN 0 #define CTYPE_BEGIN 0
@ -692,26 +692,26 @@ static cpBool handle_collision(cpArbiter *arb, int type)
cpVect norm1 = cpArbiterGetNormal(arb); cpVect norm1 = cpArbiterGetNormal(arb);
cpVect vel1 = cpArbiterGetSurfaceVelocity(arb); cpVect vel1 = cpArbiterGetSurfaceVelocity(arb);
/*
switch (type) { switch (type) {
case CTYPE_BEGIN: case CTYPE_BEGIN:
for (int i = 0; i < arrlen(go->shape_cbs); i++) for (int i = 0; i < arrlen(go->shape_cbs); i++)
if (go->shape_cbs[i].shape == pshape1) if (go->shape_cbs[i].shape == pshape1)
duk_call_phys_cb(norm1, go->shape_cbs[i].cbs.begin, g2, arb); duk_call_phys_cb(norm1, go->shape_cbs[i].cbs.begin, g2, arb);
if (go->cbs.begin.obj) if (!JS_IsNull(go->cbs.begin.obj))
duk_call_phys_cb(norm1, go->cbs.begin, g2, arb); duk_call_phys_cb(norm1, go->cbs.begin, g2, arb);
break; break;
case CTYPE_SEP: case CTYPE_SEP:
if (go->cbs.separate.obj) if (!JS_IsNull(go->cbs.separate.obj))
duk_call_phys_cb(norm1, go->cbs.separate, g2, arb); duk_call_phys_cb(norm1, go->cbs.separate, g2, arb);
break; break;
} }
*/
return 1; return 1;
} }

View file

@ -10,17 +10,5 @@
#define PI 3.14159265358979323846264338327950288f #define PI 3.14159265358979323846264338327950288f
#define DEG2RADS 0.0174532925199432957692369076848861271344287188854172545609719144f #define DEG2RADS 0.0174532925199432957692369076848861271344287188854172545609719144f
#define RAD2DEGS 57.2958f #define RAD2DEGS 57.2958f
#define MSAA_SAMPLES 2
/* S7 Scheme defines */
#define INITIAL_HEAP_SIZE 4096
#define INITIAL_STACK_SIZE 4096
#define DEFAULT_BIGNUM_PRECISION 128
#define WITH_PURE_S7 0
#define WITH_SYSTEM_EXTRAS 0
#define WITH_C_LOADER 0
#define WITH_NUMBER_SEPARATOR 1
#endif #endif

View file

@ -26,6 +26,7 @@
#include "debugdraw.h" #include "debugdraw.h"
#include "stb_ds.h" #include "stb_ds.h"
#include <ftw.h> #include <ftw.h>
#include <assert.h>
#include "miniaudio.h" #include "miniaudio.h"
@ -276,6 +277,11 @@ JSValue duk_nuke(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
if (JS_IsString(argv[1])) if (JS_IsString(argv[1]))
str = JS_ToCString(js,argv[1]); str = JS_ToCString(js,argv[1]);
else {
JSValue tostr = JS_ToString(js,argv[1]);
str = JS_ToCString(js,argv[1]);
JS_FreeValue(js,tostr);
}
struct nk_rect rect = nk_rect(0,0,0,0); struct nk_rect rect = nk_rect(0,0,0,0);
JSValue ret = JS_NULL; JSValue ret = JS_NULL;
@ -375,34 +381,46 @@ JSValue duk_win_make(JSContext *js, JSValueConst this, int argc, JSValueConst *a
JSValue duk_spline_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) JSValue duk_spline_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
{ {
static_assert(sizeof(tsReal)*2 == sizeof(cpVect));
tsBSpline spline; tsBSpline spline;
int n = js_arrlen(argv[4]); int d = js2int(argv[2]); /* dimensions */
int d = js2int(argv[2]); int degrees = js2int(argv[1]);
cpVect points[n*d]; int type = js2int(argv[3]);
JSValue ctrl_pts = argv[4];
int n = js_arrlen(ctrl_pts);
size_t nsamples = js2int(argv[5]);
cpVect points[n];
tsStatus status; tsStatus status;
ts_bspline_new(n, d, js2int(argv[1]), js2int(argv[3]), &spline, &status); ts_bspline_new(n, d, degrees, type, &spline, &status);
if (status.code) if (status.code)
YughCritical("Spline creation error %d: %s", status.code, status.message); YughCritical("Spline creation error %d: %s", status.code, status.message);
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
points[i] = js2vec2(JS_GetPropertyUint32(js, argv[4], i)); points[i] = js2vec2(JS_GetPropertyUint32(js, ctrl_pts, i));
ts_bspline_set_control_points(&spline, points, NULL); ts_bspline_set_control_points(&spline, (tsReal*)points, &status);
if (status.code)
size_t nsamples = js2int(argv[5]); YughCritical("Spline creation error %d: %s", status.code, status.message);
cpVect samples[nsamples]; cpVect samples[nsamples];
static_assert(sizeof(tsReal)*2 == sizeof(cpVect));
size_t rsamples; size_t rsamples;
ts_bspline_sample(&spline, nsamples, &samples, &rsamples, NULL); /* TODO: This does not work with Clang/GCC due to UB */
ts_bspline_sample(&spline, nsamples, (tsReal**)&samples, &rsamples, &status);
if (status.code)
YughCritical("Spline creation error %d: %s", status.code, status.message);
JSValue arr = JS_NewArray(js); JSValue arr = JS_NewArray(js);
for (int i = 0; i < nsamples; i++) { for (int i = 0; i < nsamples; i++) {
JSValue psample; JSValue psample = JS_NewArray(js);
JS_SetPropertyUint32(js, psample, 0, float2js(samples[i].x)); JS_SetPropertyUint32(js, psample, 0, float2js(samples[i].x));
JS_SetPropertyUint32(js, psample, 1, float2js(samples[i].y)); JS_SetPropertyUint32(js, psample, 1, float2js(samples[i].y));
JS_SetPropertyUint32(js, arr, i, psample); JS_SetPropertyUint32(js, arr, i, psample);
@ -943,7 +961,9 @@ JSValue duk_register_collide(JSContext *js, JSValueConst this, int argc, JSValue
{ {
int cmd = js2int(argv[0]); int cmd = js2int(argv[0]);
int go = js2int(argv[3]); int go = js2int(argv[3]);
struct callee c = {argv[1], argv[2]}; struct callee c;
c.fn = argv[1];
c.obj = argv[2];
switch(cmd) { switch(cmd) {
case 0: case 0:
@ -1237,14 +1257,14 @@ JSValue duk_cmd_box2d(JSContext *js, JSValueConst this, int argc, JSValueConst *
JSValue duk_make_circle2d(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) JSValue duk_make_circle2d(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
{ {
int go = js2int(argv[0]); int go = js2int(argv[0]);
double radius = js2number(argv[1]); double radius = js2number(argv[1]);
struct phys2d_circle *circle = Make2DCircle(go); struct phys2d_circle *circle = Make2DCircle(go);
circle->radius = radius; circle->radius = radius;
circle->offset = js2vec2(argv[2]); circle->offset = js2vec2(argv[2]);
phys2d_applycircle(circle); phys2d_applycircle(circle);
JSValue circleval = JS_NewObject(js); JSValue circleval = JS_NewObject(js);
JS_SetPropertyStr(js, circleval, "id", ptr2js(circle)); JS_SetPropertyStr(js, circleval, "id", ptr2js(circle));
@ -1306,8 +1326,6 @@ JSValue duk_make_edge2d(JSContext *js, JSValueConst this, int argc, JSValueConst
int go = js2int(argv[0]); int go = js2int(argv[0]);
struct phys2d_edge *edge = Make2DEdge(go); struct phys2d_edge *edge = Make2DEdge(go);
int arridx = 1;
int n = js_arrlen(argv[1]); int n = js_arrlen(argv[1]);
cpVect points[n]; cpVect points[n];

View file

@ -96,12 +96,14 @@ void go_shape_apply(cpBody *body, cpShape *shape, struct gameobject *go)
cpShapeSetFriction(shape, go->f); cpShapeSetFriction(shape, go->f);
cpShapeSetElasticity(shape, go->e); cpShapeSetElasticity(shape, go->e);
cpShapeSetCollisionType(shape, go2id(go)); cpShapeSetCollisionType(shape, go2id(go));
cpShapeFilter filter; /* cpShapeFilter filter;
filter.group = go2id(go); filter.group = go2id(go);
filter.categories = 1<<go->layer; filter.categories = 1<<go->layer;
filter.mask = category_masks[go->layer]; filter.mask = category_masks[go->layer];
cpShapeSetFilter(shape, filter); cpShapeSetFilter(shape, filter);
*/
} }
void go_shape_moi(cpBody *body, cpShape *shape, struct gameobject *go) void go_shape_moi(cpBody *body, cpShape *shape, struct gameobject *go)