Skip to content

Commit 62fd0bf

Browse files
committed
operator dispatch system done
1 parent ee1348f commit 62fd0bf

3 files changed

Lines changed: 32 additions & 10 deletions

File tree

scripts/build_lib

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
#!/bin/bash
2+
set -e
23

3-
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
4-
cd "$SCRIPT_DIR/.."
5-
cmake -S . -B build && cmake --build build
6-
cmake --install build
4+
ROOT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
5+
6+
BUILD_DIR="$ROOT_DIR/build"
7+
INSTALL_DIR="$ROOT_DIR/install"
8+
9+
# Safety check before rm -rf
10+
if [[ -z "$BUILD_DIR" || "$BUILD_DIR" == "/" ]]; then
11+
echo "Refusing to delete unsafe BUILD_DIR: '$BUILD_DIR'"
12+
exit 1
13+
fi
14+
15+
rm -rf "$BUILD_DIR"
16+
mkdir -p "$BUILD_DIR"
17+
cd "$BUILD_DIR"
18+
19+
cmake "$ROOT_DIR" \
20+
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
21+
-DPYTHONIC_ENABLE_GRAPH_VIEWER=ON
22+
23+
cmake --build . -j$(nproc)
24+
cmake --install .
25+
26+
echo
27+
echo "✔ Clean build + install complete"
28+
echo " Install prefix: $INSTALL_DIR"

scripts/gen_dispatch_stubs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,11 @@ def print_cast(operand, varname, t, ctype):
291291
elif opname in ("band", "bor", "bxor"):
292292
if left == 'bool' and right == 'bool':
293293
if opname == "band":
294-
print(f" return var(a.var_get<bool>() & b.var_get<bool>());")
294+
print(f" return var(static_cast<bool>(a.var_get<bool>() & b.var_get<bool>()));")
295295
elif opname == "bor":
296-
print(f" return var(a.var_get<bool>() | b.var_get<bool>());")
296+
print(f" return var(static_cast<bool>(a.var_get<bool>() | b.var_get<bool>()));")
297297
elif opname == "bxor":
298-
print(f" return var(a.var_get<bool>() ^ b.var_get<bool>());")
298+
print(f" return var(static_cast<bool>(a.var_get<bool>() ^ b.var_get<bool>()));")
299299
elif is_integral(left) and is_integral(right):
300300
ctype = get_common_integral_bitwise(left, right)
301301
print_cast('a', 'la', left, ctype)

src/pythonicDispatchStubs.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20315,7 +20315,7 @@ var band__bool__string(const var& a, const var& b, pythonic::overflow::Overflow
2031520315
throw pythonic::PythonicTypeError("TypeError: unsupported operand type(s) for &: 'bool' and 'string'");
2031620316
}
2031720317
var band__bool__bool(const var& a, const var& b, pythonic::overflow::Overflow policy, bool smallest_fit) {
20318-
return var(a.var_get<bool>() & b.var_get<bool>());
20318+
return var(static_cast<bool>(a.var_get<bool>() & b.var_get<bool>()));
2031920319
}
2032020320
var band__bool__double(const var& a, const var& b, pythonic::overflow::Overflow policy, bool smallest_fit) {
2032120321
throw pythonic::PythonicTypeError("TypeError: unsupported operand type(s) for &: 'bool' and 'double'");
@@ -21434,7 +21434,7 @@ var bor__bool__string(const var& a, const var& b, pythonic::overflow::Overflow p
2143421434
throw pythonic::PythonicTypeError("TypeError: unsupported operand type(s) for |: 'bool' and 'string'");
2143521435
}
2143621436
var bor__bool__bool(const var& a, const var& b, pythonic::overflow::Overflow policy, bool smallest_fit) {
21437-
return var(a.var_get<bool>() | b.var_get<bool>());
21437+
return var(static_cast<bool>(a.var_get<bool>() | b.var_get<bool>()));
2143821438
}
2143921439
var bor__bool__double(const var& a, const var& b, pythonic::overflow::Overflow policy, bool smallest_fit) {
2144021440
throw pythonic::PythonicTypeError("TypeError: unsupported operand type(s) for |: 'bool' and 'double'");
@@ -22552,7 +22552,7 @@ var bxor__bool__string(const var& a, const var& b, pythonic::overflow::Overflow
2255222552
throw pythonic::PythonicTypeError("TypeError: unsupported operand type(s) for ^: 'bool' and 'string'");
2255322553
}
2255422554
var bxor__bool__bool(const var& a, const var& b, pythonic::overflow::Overflow policy, bool smallest_fit) {
22555-
return var(a.var_get<bool>() ^ b.var_get<bool>());
22555+
return var(static_cast<bool>(a.var_get<bool>() ^ b.var_get<bool>()));
2255622556
}
2255722557
var bxor__bool__double(const var& a, const var& b, pythonic::overflow::Overflow policy, bool smallest_fit) {
2255822558
throw pythonic::PythonicTypeError("TypeError: unsupported operand type(s) for ^: 'bool' and 'double'");

0 commit comments

Comments
 (0)