Skip to content

Commit 4962d3c

Browse files
authored
Merge pull request #26 from sfall-team/feature/pragma-sce
Pragma for short-circuit evaluation
2 parents bd7a9ce + c319984 commit 4962d3c

4 files changed

Lines changed: 43 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
uses: actions/cache@v4
1919
with:
2020
path: test/gamescripts
21-
key: rpu-and-modderpack-gamescripts-v1004
21+
key: rpu-and-modderpack-gamescripts-v1005
2222

2323
- name: Download RPU scripts & modderspack
2424
if: github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'skip-rpu-check')
@@ -97,7 +97,7 @@ jobs:
9797
uses: actions/cache@v4
9898
with:
9999
path: test/gamescripts
100-
key: rpu-and-modderpack-gamescripts-v1004
100+
key: rpu-and-modderpack-gamescripts-v1005
101101
- name: Download RPU scripts & modderspack
102102
if: github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'skip-rpu-check')
103103
shell: bash
@@ -234,7 +234,7 @@ jobs:
234234
if: github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'skip-rpu-check')
235235
with:
236236
path: test/gamescripts
237-
key: rpu-and-modderpack-gamescripts-v1004
237+
key: rpu-and-modderpack-gamescripts-v1005
238238
fail-on-cache-miss: true
239239
- name: Test on Fallout RPU
240240
if: github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'skip-rpu-check')
@@ -283,7 +283,7 @@ jobs:
283283
if: github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'skip-rpu-check')
284284
with:
285285
path: test/gamescripts
286-
key: rpu-and-modderpack-gamescripts-v1004
286+
key: rpu-and-modderpack-gamescripts-v1005
287287
fail-on-cache-miss: true
288288
- name: Test on Fallout RPU
289289
if: github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'skip-rpu-check')

docs/sslc_readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ Syntax which requires sfall for compiled scripts to be interpreted is marked by
322322
If you want to add additional condition for continuing the loop, use syntax: `foreach (<symbol> in <expression> while <expression>)`. In this case loop will iterate over elements of an array until last element or until "while" expression is true (whatever comes first).
323323
324324
__NOTE:__ Just like `for` loop, `continue` statement will respect increments of a hidden counter variable, so you can safely use it inside `foreach`.
325+
326+
- `#pragma sce` directive. If present anywhere in the compiled script, will enable short-circuit evaluation of logical `and` and `or` operators, even if `-s` command line argument is not used.
325327
326328
---
327329
@@ -348,6 +350,9 @@ There are several changes in this version of sslc which may result in problems f
348350
349351
### Changelog
350352
353+
**sfall 4.4.10:**
354+
- added #pragma sce
355+
351356
**sfall 4.4.7:**
352357
- fixed leftover stack data caused by the `break` statement
353358
- added Linux & WebAssembly builds

lex.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ static void AppendToAssignCache() {
3737
}
3838

3939
extern int backwardcompat;
40+
extern int shortCircuit;
4041

4142
static int ungotToken = -1;
4243
static int lastToken = -1;
@@ -637,6 +638,38 @@ int lex_internal(void) {
637638
ungetChar();
638639
}
639640
}
641+
else if (_stricmp(buf[which], "pragma") == 0) { // pragma directives
642+
do {
643+
c = getChar();
644+
} while(c != EOF && c != '\n' && !validSymbolChar(c));
645+
646+
if (c == EOF) {
647+
ungetChar();
648+
}
649+
else if (validSymbolChar(c)) {
650+
651+
buf[which][0] = c;
652+
653+
i = 0;
654+
while(1) {
655+
c = getChar();
656+
657+
if (!validSymbolChar(c) && c != '-')
658+
break;
659+
660+
buf[which][i+1] = c;
661+
i++;
662+
}
663+
664+
buf[which][i+1] = 0;
665+
666+
if (_stricmp(buf[which], "sce") == 0 && !shortCircuit) {
667+
shortCircuit = 1;
668+
}
669+
if (c == EOF)
670+
ungetChar();
671+
}
672+
}
640673
else if (c == EOF) {
641674
ungetChar();
642675
}

parse.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extern int warnings;
2828
extern int optimize;
2929
extern int debug;
3030
extern int dumpTree;
31-
extern int shortCircuit;
31+
3232
void optimizeTree(Program *program);
3333

3434
/*

0 commit comments

Comments
 (0)