mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
...
This commit is contained in:
parent
178bfa4c32
commit
620db020ed
@ -12,9 +12,9 @@
|
||||
#define PK_HEX_TABLE "0123456789abcdef"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define c11__unreachedable() __assume(0)
|
||||
#define c11__unreachable() __assume(0)
|
||||
#else
|
||||
#define c11__unreachedable() __builtin_unreachable()
|
||||
#define c11__unreachable() __builtin_unreachable()
|
||||
#endif
|
||||
|
||||
#define c11__abort(...) \
|
||||
|
@ -15,7 +15,7 @@ def sieve_of_eratosthenes(n: int) -> List[int]:
|
||||
primes = [num for num, prime in enumerate(is_prime) if prime]
|
||||
return primes
|
||||
|
||||
all_primes = sieve_of_eratosthenes(2**31)
|
||||
all_primes = sieve_of_eratosthenes(2**30)
|
||||
print(len(all_primes), all_primes[:10], all_primes[-10:])
|
||||
|
||||
index = 3
|
||||
@ -24,7 +24,10 @@ caps = [all_primes[index]]
|
||||
while True:
|
||||
for i in range(index+1, len(all_primes)):
|
||||
last_cap = caps[-1]
|
||||
min_cap = last_cap * 2
|
||||
if last_cap < 1000:
|
||||
min_cap = last_cap * 2
|
||||
else:
|
||||
min_cap = last_cap * 1.5
|
||||
if all_primes[i] >= min_cap:
|
||||
caps.append(all_primes[i])
|
||||
index = i
|
||||
@ -34,3 +37,9 @@ while True:
|
||||
|
||||
print('-'*20)
|
||||
print(caps)
|
||||
|
||||
print('switch(cap) {')
|
||||
for i in range(len(caps)-1):
|
||||
print(f' case {caps[i]}:', f'return {caps[i+1]};')
|
||||
print(' default: c11__unreachable();')
|
||||
print('}')
|
@ -128,7 +128,7 @@ bool NameExpr__emit_del(Expr* self_, Ctx* ctx) {
|
||||
break;
|
||||
case NAME_GLOBAL: Ctx__emit_(ctx, OP_DELETE_GLOBAL, self->name, self->line); break;
|
||||
case NAME_GLOBAL_UNKNOWN: Ctx__emit_(ctx, OP_DELETE_NAME, self->name, self->line); break;
|
||||
default: c11__unreachedable();
|
||||
default: c11__unreachable();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -327,7 +327,7 @@ void LiteralExpr__emit_(Expr* self_, Ctx* ctx) {
|
||||
Ctx__emit_(ctx, OP_LOAD_CONST, index, self->line);
|
||||
break;
|
||||
}
|
||||
default: c11__unreachedable();
|
||||
default: c11__unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
@ -355,7 +355,7 @@ void Literal0Expr__emit_(Expr* self_, Ctx* ctx) {
|
||||
case TK_TRUE: opcode = OP_LOAD_TRUE; break;
|
||||
case TK_FALSE: opcode = OP_LOAD_FALSE; break;
|
||||
case TK_DOTDOTDOT: opcode = OP_LOAD_ELLIPSIS; break;
|
||||
default: c11__unreachedable();
|
||||
default: c11__unreachable();
|
||||
}
|
||||
Ctx__emit_(ctx, opcode, BC_NOARG, self->line);
|
||||
}
|
||||
@ -1245,7 +1245,7 @@ static void Ctx__emit_store_name(Ctx* self, NameScope scope, py_Name name, int l
|
||||
case NAME_LOCAL: Ctx__emit_(self, OP_STORE_FAST, Ctx__add_varname(self, name), line); break;
|
||||
case NAME_GLOBAL: Ctx__emit_(self, OP_STORE_GLOBAL, name, line); break;
|
||||
case NAME_GLOBAL_UNKNOWN: Ctx__emit_(self, OP_STORE_NAME, name, line); break;
|
||||
default: c11__unreachedable();
|
||||
default: c11__unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
@ -2182,7 +2182,7 @@ static Error* read_literal(Compiler* self, py_Ref out) {
|
||||
} else if(value->index == TokenValue_F64) {
|
||||
py_newfloat(out, negated ? -value->_f64 : value->_f64);
|
||||
} else {
|
||||
c11__unreachedable();
|
||||
c11__unreachable();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ static bool stack_format_object(VM* self, c11_sv spec);
|
||||
case RES_RETURN: PUSH(&self->last_retval); break; \
|
||||
case RES_CALL: frame = self->top_frame; goto __NEXT_FRAME; \
|
||||
case RES_ERROR: goto __ERROR; \
|
||||
default: c11__unreachedable(); \
|
||||
default: c11__unreachable(); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
@ -1101,10 +1101,10 @@ FrameResult VM__run_top_frame(VM* self) {
|
||||
if(!ok) goto __ERROR;
|
||||
DISPATCH();
|
||||
}
|
||||
default: c11__unreachedable();
|
||||
default: c11__unreachable();
|
||||
}
|
||||
|
||||
c11__unreachedable();
|
||||
c11__unreachable();
|
||||
|
||||
__ERROR:
|
||||
py_BaseException__stpush(&self->curr_exception,
|
||||
@ -1340,7 +1340,7 @@ static bool stack_format_object(VM* self, c11_sv spec) {
|
||||
c11_sbuf__write_pad(&buf, pad_right, pad_c);
|
||||
break;
|
||||
}
|
||||
default: c11__unreachedable();
|
||||
default: c11__unreachable();
|
||||
}
|
||||
} else {
|
||||
c11_sbuf__write_sv(&buf, c11_string__sv(body));
|
||||
|
@ -502,10 +502,10 @@ FrameResult VM__vectorcall(VM* self, uint16_t argc, uint16_t kwargc, bool opcall
|
||||
self->stack.sp = p0; // reset the stack
|
||||
return RES_RETURN;
|
||||
}
|
||||
default: c11__unreachedable();
|
||||
default: c11__unreachable();
|
||||
};
|
||||
|
||||
c11__unreachedable();
|
||||
c11__unreachable();
|
||||
/*****************_py_call*****************/
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ bool pk_exec(CodeObject* co, py_Ref module) {
|
||||
FrameResult res = VM__run_top_frame(vm);
|
||||
if(res == RES_ERROR) return false;
|
||||
if(res == RES_RETURN) return true;
|
||||
c11__unreachedable();
|
||||
c11__unreachable();
|
||||
}
|
||||
|
||||
bool py_exec(const char* source, const char* filename, enum py_CompileMode mode, py_Ref module) {
|
||||
|
@ -210,7 +210,7 @@ bool pk_loadmethod(py_StackRef self, py_Name name) {
|
||||
self[0] = *py_getslot(cls_var, 0);
|
||||
self[1] = pk__type_info(type)->self;
|
||||
break;
|
||||
default: c11__unreachedable();
|
||||
default: c11__unreachable();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -16,27 +16,40 @@ static uint32_t Dict__next_cap(uint32_t cap) {
|
||||
case 163: return 331;
|
||||
case 331: return 673;
|
||||
case 673: return 1361;
|
||||
case 1361: return 2729;
|
||||
case 2729: return 5471;
|
||||
case 5471: return 10949;
|
||||
case 10949: return 21911;
|
||||
case 21911: return 43853;
|
||||
case 43853: return 87719;
|
||||
case 87719: return 175447;
|
||||
case 175447: return 350899;
|
||||
case 350899: return 701819;
|
||||
case 701819: return 1403641;
|
||||
case 1403641: return 2807303;
|
||||
case 2807303: return 5614657;
|
||||
case 5614657: return 11229331;
|
||||
case 11229331: return 22458671;
|
||||
case 22458671: return 44917381;
|
||||
case 44917381: return 89834777;
|
||||
case 89834777: return 179669557;
|
||||
case 179669557: return 359339171;
|
||||
case 359339171: return 718678369;
|
||||
case 718678369: return 1437356741;
|
||||
default: c11__unreachedable();
|
||||
case 1361: return 2053;
|
||||
case 2053: return 3083;
|
||||
case 3083: return 4637;
|
||||
case 4637: return 6959;
|
||||
case 6959: return 10453;
|
||||
case 10453: return 15683;
|
||||
case 15683: return 23531;
|
||||
case 23531: return 35311;
|
||||
case 35311: return 52967;
|
||||
case 52967: return 79451;
|
||||
case 79451: return 119179;
|
||||
case 119179: return 178781;
|
||||
case 178781: return 268189;
|
||||
case 268189: return 402299;
|
||||
case 402299: return 603457;
|
||||
case 603457: return 905189;
|
||||
case 905189: return 1357787;
|
||||
case 1357787: return 2036687;
|
||||
case 2036687: return 3055043;
|
||||
case 3055043: return 4582577;
|
||||
case 4582577: return 6873871;
|
||||
case 6873871: return 10310819;
|
||||
case 10310819: return 15466229;
|
||||
case 15466229: return 23199347;
|
||||
case 23199347: return 34799021;
|
||||
case 34799021: return 52198537;
|
||||
case 52198537: return 78297827;
|
||||
case 78297827: return 117446801;
|
||||
case 117446801: return 176170229;
|
||||
case 176170229: return 264255353;
|
||||
case 264255353: return 396383041;
|
||||
case 396383041: return 594574583;
|
||||
case 594574583: return 891861923;
|
||||
default: c11__unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user