diff options
| author | elioat <elioat@tilde.institute> | 2025-07-20 21:59:12 -0400 |
|---|---|---|
| committer | elioat <elioat@tilde.institute> | 2025-07-20 21:59:12 -0400 |
| commit | 0607dc10b0d0b773272793947b83367ae168a7cf (patch) | |
| tree | c9cb9c041d5b52cf15859388319ea8a32cdd01df /awk | |
| parent | 8a403316fab3027f20988a146774586d40229a42 (diff) | |
| download | tour-0607dc10b0d0b773272793947b83367ae168a7cf.tar.gz | |
*
Diffstat (limited to 'awk')
| -rwxr-xr-x | awk/scheme/scheme/bin/compiler.awk | 30 | ||||
| -rw-r--r-- | awk/scheme/scheme/test/unit/control_flow.scm | 3 |
2 files changed, 24 insertions, 9 deletions
diff --git a/awk/scheme/scheme/bin/compiler.awk b/awk/scheme/scheme/bin/compiler.awk index 4b1735b..a8b8dce 100755 --- a/awk/scheme/scheme/bin/compiler.awk +++ b/awk/scheme/scheme/bin/compiler.awk @@ -1046,11 +1046,20 @@ function compile_cond(args, test, expr, test_label, end_label) { } # Compile and expression: (and expr1 expr2 ...) -function compile_and(args, expressions, nexprs, i, expr, short_circuit_label, end_label) { +function compile_and(args, expressions, nexprs, i, expr, short_circuit_label, end_label, split_result, remaining_args) { debug("Compiling and expression: " args) - # Split into expressions - nexprs = split(args, expressions, " ") + # Parse expressions properly using split_expr + expressions[1] = "" + nexprs = 0 + remaining_args = args + + while (remaining_args != "") { + nexprs++ + split_result = split_expr(remaining_args) + expressions[nexprs] = substr(split_result, 1, index(split_result, SUBSEP) - 1) + remaining_args = substr(split_result, index(split_result, SUBSEP) + 1) + } if (nexprs == 0) { # Empty and returns true @@ -1093,11 +1102,20 @@ function compile_and(args, expressions, nexprs, i, expr, short_circuit_label, } # Compile or expression: (or expr1 expr2 ...) -function compile_or(args, expressions, nexprs, i, expr, short_circuit_label, end_label) { +function compile_or(args, expressions, nexprs, i, expr, short_circuit_label, end_label, split_result, remaining_args) { debug("Compiling or expression: " args) - # Split into expressions - nexprs = split(args, expressions, " ") + # Parse expressions properly using split_expr + expressions[1] = "" + nexprs = 0 + remaining_args = args + + while (remaining_args != "") { + nexprs++ + split_result = split_expr(remaining_args) + expressions[nexprs] = substr(split_result, 1, index(split_result, SUBSEP) - 1) + remaining_args = substr(split_result, index(split_result, SUBSEP) + 1) + } if (nexprs == 0) { # Empty or returns false diff --git a/awk/scheme/scheme/test/unit/control_flow.scm b/awk/scheme/scheme/test/unit/control_flow.scm index 0e20518..0a99b9a 100644 --- a/awk/scheme/scheme/test/unit/control_flow.scm +++ b/awk/scheme/scheme/test/unit/control_flow.scm @@ -44,16 +44,13 @@ (not nil) (not (cons 1 2)) -;; Nested control flow (if (and #t #f) "and-true" "and-false") (if (or #f #t) "or-true" "or-false") (if (not #t) "not-true" "not-false") -;; Complexish conditions (cond ((and #t #t) "and-true") ((or #f #f) "or-false") (else "else")) -;; Short-circuit evaluation (and #f (error "should not evaluate")) (or #t (error "should not evaluate"))
\ No newline at end of file |