- Add -O0 (no opts) and -O2 (no opts + no checks) CLI flags - Add -v 1..4 verbosity: timing, per-function stats, debug dump, optimization diffs - Whole-word JIT: compile Definition bodies to native x86-64 for CT VM - Lazy CTMemory/JIT/ctype init (defer ctypes until first CT execution) - Stack-effect comment parsing for stack-checks - Peephole rules refactored to module-level dicts with O(1) lookup - _emitted_start short-circuit (O(1) vs O(n) scan) - Add --no-auto-inline to disable auto-inlining of small asm bodies - Fix --ct-run-main to execute after linking (prevent SIGSEGV) - Stdlib: small optimizations like swap + drop -> nip
68 lines
1.0 KiB
Plaintext
68 lines
1.0 KiB
Plaintext
import stdlib.sl
|
|
|
|
#alloc [* | size] -> [* | addr]
|
|
word alloc
|
|
0 # addr hint (NULL)
|
|
swap # size
|
|
3 # prot (PROT_READ | PROT_WRITE)
|
|
34 # flags (MAP_PRIVATE | MAP_ANON)
|
|
-1 # fd
|
|
0 # offset
|
|
mmap
|
|
nip
|
|
end
|
|
|
|
#free [*, addr | size] -> [*]
|
|
word free
|
|
munmap drop
|
|
end
|
|
|
|
#memcpy [*, dst_addr, src_addr | len] -> [*, dst_addr | len]
|
|
word memcpy
|
|
dup
|
|
>r
|
|
swap
|
|
dup c@
|
|
3 pick swap
|
|
c!
|
|
swap
|
|
for
|
|
1 + dup
|
|
c@
|
|
swap
|
|
-rot
|
|
swap
|
|
1 +
|
|
dup
|
|
rot
|
|
c!
|
|
swap
|
|
end
|
|
drop
|
|
r> dup -rot - swap
|
|
end
|
|
|
|
#memset [*, value, len | addr] -> [*]
|
|
word memset
|
|
swap
|
|
0 swap for
|
|
-rot swap 2 pick + 2dup swap ! 1 + -rot swap
|
|
end
|
|
2drop drop
|
|
end
|
|
|
|
#memdump [*, len | addr] -> [* | addr]
|
|
word memdump
|
|
for
|
|
dup @ puti cr 8 +
|
|
end
|
|
end
|
|
|
|
#realloc [*, addr, old_len | new_len] -> [* | new_addr]
|
|
word realloc
|
|
2 pick swap alloc
|
|
rot rot swap
|
|
memcpy
|
|
swap -rot free
|
|
end
|