mirror of
https://github.com/pocketpy/pocketpy
synced 2025-11-06 11:40:16 +00:00
Compare commits
6 Commits
dbaf7a61ce
...
05e1de4101
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
05e1de4101 | ||
|
|
6266161118 | ||
|
|
cbae815d37 | ||
|
|
8e3c335449 | ||
|
|
068ec948ec | ||
|
|
5a47ae6f42 |
@ -48,7 +48,10 @@ class vec2(_vecF['vec2']):
|
||||
def with_y(self, y: float) -> vec2: ...
|
||||
def with_z(self, z: float) -> vec3: ...
|
||||
|
||||
@overload
|
||||
def __init__(self, x: float, y: float) -> None: ...
|
||||
@overload
|
||||
def __init__(self, xy: vec2i) -> None: ...
|
||||
|
||||
def rotate(self, radians: float) -> vec2: ...
|
||||
|
||||
@ -159,7 +162,10 @@ class vec3(_vecF['vec3']):
|
||||
def with_z(self, z: float) -> vec3: ...
|
||||
def with_xy(self, xy: vec2) -> vec3: ...
|
||||
|
||||
@overload
|
||||
def __init__(self, x: float, y: float, z: float) -> None: ...
|
||||
@overload
|
||||
def __init__(self, xyz: vec3i) -> None: ...
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1400,7 +1400,9 @@ static Error* parse_expression(Compiler* self, int precedence, bool allow_slice)
|
||||
TokenIndex op = curr()->type;
|
||||
advance();
|
||||
PrattCallback infix = rules[op].infix;
|
||||
assert(infix != NULL);
|
||||
if(infix == NULL) {
|
||||
return SyntaxError(self, "expected an infix operator, got %s", TokenSymbols[op]);
|
||||
}
|
||||
check(infix(self));
|
||||
}
|
||||
return NULL;
|
||||
@ -1650,7 +1652,12 @@ static Error* exprBinaryOp(Compiler* self) {
|
||||
Error* err;
|
||||
int line = prev()->line;
|
||||
TokenIndex op = prev()->type;
|
||||
check(parse_expression(self, rules[op].precedence + 1, false));
|
||||
int precedence = rules[op].precedence;
|
||||
if(op != TK_POW) {
|
||||
// if not right associative, increase precedence
|
||||
precedence += 1;
|
||||
}
|
||||
check(parse_expression(self, precedence, false));
|
||||
BinaryExpr* e = BinaryExpr__new(line, op, false);
|
||||
if(op == TK_IN || op == TK_NOT_IN) {
|
||||
e->lhs = Ctx__s_popx(ctx());
|
||||
|
||||
@ -110,10 +110,17 @@ static py_Ref _const(py_Type type, const char* name) {
|
||||
|
||||
#define DEF_VECTOR_OPS(D) \
|
||||
static bool vec##D##__new__(int argc, py_Ref argv) { \
|
||||
PY_CHECK_ARGC(D + 1); \
|
||||
c11_vec##D res; \
|
||||
for(int i = 0; i < D; i++) { \
|
||||
if(!py_castfloat32(&argv[i + 1], &res.data[i])) return false; \
|
||||
if(argc == 2) { \
|
||||
PY_CHECK_ARG_TYPE(1, tp_vec##D##i); \
|
||||
c11_vec##D##i v = py_tovec##D##i(&argv[1]); \
|
||||
for(int i = 0; i < D; i++) \
|
||||
res.data[i] = v.data[i]; \
|
||||
} else { \
|
||||
PY_CHECK_ARGC(D + 1); \
|
||||
for(int i = 0; i < D; i++) { \
|
||||
if(!py_castfloat32(&argv[i + 1], &res.data[i])) return false; \
|
||||
} \
|
||||
} \
|
||||
py_newvec##D(py_retval(), res); \
|
||||
return true; \
|
||||
|
||||
@ -400,3 +400,8 @@ a[vec2i(1, 2)] = 1
|
||||
assert a[vec2i(1, 2)] == 1
|
||||
a[vec3i(1, 2, 3)] = 2
|
||||
assert a[vec3i(1, 2, 3)] == 2
|
||||
|
||||
assert vec2(vec2i.LEFT) == vec2(-1, 0)
|
||||
assert vec2(vec2i.RIGHT) == vec2(1, 0)
|
||||
assert vec3(vec3i.ONE) == vec3(1, 1, 1)
|
||||
assert vec3(vec3i.ZERO) == vec3(0, 0, 0)
|
||||
|
||||
@ -47,3 +47,7 @@ assert A()[::, :] == (slice(None, None, None), slice(None, None, None))
|
||||
assert A()[::, :2] == (slice(None, None, None), slice(None, 2, None))
|
||||
assert A()['b':'c':1, :] == (slice('b', 'c', 1), slice(None, None, None))
|
||||
assert A()[1:2, :A()[3:4, ::-1]] == (slice(1, 2, None), slice(None, (slice(3, 4, None), slice(None, None, -1)), None))
|
||||
|
||||
# test right associative
|
||||
assert 2**2**3 == 256
|
||||
assert (2**2**3)**2 == 65536
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user