mirror of
https://github.com/nineties/planckforth
synced 2024-12-26 21:58:42 +01:00
Merge pull request #22 from nineties/make-python-faster
Make python faster
This commit is contained in:
commit
32baf5e2d1
1 changed files with 4 additions and 2 deletions
|
@ -19,6 +19,7 @@ MEMORY_SIZE = 0x10000
|
||||||
|
|
||||||
memory = array.array('i', [0]*MEMORY_SIZE)
|
memory = array.array('i', [0]*MEMORY_SIZE)
|
||||||
CELL = memory.itemsize
|
CELL = memory.itemsize
|
||||||
|
CELLm1 = CELL - 1
|
||||||
CELL_SHIFT = CELL.bit_length() - 1
|
CELL_SHIFT = CELL.bit_length() - 1
|
||||||
|
|
||||||
STACK_SIZE = 0x100
|
STACK_SIZE = 0x100
|
||||||
|
@ -32,8 +33,9 @@ rp = (MEMORY_SIZE - STACK_SIZE) * CELL
|
||||||
ip = 0
|
ip = 0
|
||||||
np = 0
|
np = 0
|
||||||
|
|
||||||
|
ALIGN_MASK = ~(CELL - 1)
|
||||||
def aligned(n):
|
def aligned(n):
|
||||||
return (n + CELL - 1) & ~(CELL - 1)
|
return (n + CELLm1) & ALIGN_MASK
|
||||||
|
|
||||||
def align():
|
def align():
|
||||||
write(HERE_CELL, aligned(read(HERE_CELL)))
|
write(HERE_CELL, aligned(read(HERE_CELL)))
|
||||||
|
@ -57,7 +59,7 @@ def read_byte(addr):
|
||||||
|
|
||||||
def write_byte(addr, c):
|
def write_byte(addr, c):
|
||||||
i = addr >> CELL_SHIFT
|
i = addr >> CELL_SHIFT
|
||||||
m = (addr % CELL)*8
|
m = (addr % CELL) * 8
|
||||||
v = memory[i]
|
v = memory[i]
|
||||||
memory[i] = (v & ~(0xff << m)) | (c&0xff) << m
|
memory[i] = (v & ~(0xff << m)) | (c&0xff) << m
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue