Compare commits
7 Commits
e8271895fb
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
052f9191c3 | ||
|
|
a74c4b8c41 | ||
|
|
d639c63fd3 | ||
|
|
ab613e644a | ||
|
|
75b01b9635 | ||
|
|
b263e7d0de | ||
|
|
bc3a894737 |
8
main.py
8
main.py
@@ -11542,7 +11542,7 @@ def _run_docs_tui(
|
|||||||
"\n"
|
"\n"
|
||||||
" 5. NASM + LINKER\n"
|
" 5. NASM + LINKER\n"
|
||||||
" The assembly is assembled by NASM into an object\n"
|
" The assembly is assembled by NASM into an object\n"
|
||||||
" file, then linked (via ld or gcc) into the final\n"
|
" file, then linked (via ld or ld.ldd) into the final\n"
|
||||||
" binary.\n"
|
" binary.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"───────────────────────────────────────────────────────────────\n"
|
"───────────────────────────────────────────────────────────────\n"
|
||||||
@@ -11567,7 +11567,7 @@ def _run_docs_tui(
|
|||||||
" The CT VM is a stack-based interpreter that runs during\n"
|
" The CT VM is a stack-based interpreter that runs during\n"
|
||||||
" parsing. It maintains:\n"
|
" parsing. It maintains:\n"
|
||||||
"\n"
|
"\n"
|
||||||
" - A value stack (Python list of ints/strings/lists)\n"
|
" - A value stack\n"
|
||||||
" - A dictionary of CT-callable words\n"
|
" - A dictionary of CT-callable words\n"
|
||||||
" - A return stack for nested calls\n"
|
" - A return stack for nested calls\n"
|
||||||
"\n"
|
"\n"
|
||||||
@@ -11579,7 +11579,7 @@ def _run_docs_tui(
|
|||||||
"\n"
|
"\n"
|
||||||
" When --ct-run-main is used, the CT VM can also JIT-compile\n"
|
" When --ct-run-main is used, the CT VM can also JIT-compile\n"
|
||||||
" and execute native x86-64 code via the Keystone assembler\n"
|
" and execute native x86-64 code via the Keystone assembler\n"
|
||||||
" engine (for words that need native performance).\n"
|
" engine (for words that need near native performance).\n"
|
||||||
"\n"
|
"\n"
|
||||||
"───────────────────────────────────────────────────────────────\n"
|
"───────────────────────────────────────────────────────────────\n"
|
||||||
"\n"
|
"\n"
|
||||||
@@ -11641,7 +11641,7 @@ def _run_docs_tui(
|
|||||||
" just numbers. Type safety is your responsibility.\n"
|
" just numbers. Type safety is your responsibility.\n"
|
||||||
"\n"
|
"\n"
|
||||||
" - Macro expansion depth: macros can expand macros,\n"
|
" - Macro expansion depth: macros can expand macros,\n"
|
||||||
" but there's a limit (default 64, configurable via\n"
|
" but there's a limit (default 256, configurable via\n"
|
||||||
" --macro-expansion-limit).\n"
|
" --macro-expansion-limit).\n"
|
||||||
"\n"
|
"\n"
|
||||||
" - :py blocks: Python code embedded in :py { ... }\n"
|
" - :py blocks: Python code embedded in :py { ... }\n"
|
||||||
|
|||||||
@@ -326,3 +326,22 @@ word dyn_arr_sorted
|
|||||||
dyn_arr_clone
|
dyn_arr_clone
|
||||||
dyn_arr_sort
|
dyn_arr_sort
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# arr_contains [*, addr | x] -> [* | bool]
|
||||||
|
word arr_contains
|
||||||
|
over @ >r >r 8 + r> r>
|
||||||
|
for
|
||||||
|
2dup swap @ == if 1 nip nip rdrop ret end
|
||||||
|
swap 8 + swap
|
||||||
|
end 0 nip nip
|
||||||
|
end
|
||||||
|
|
||||||
|
# arr_find [*, addr | x] -> [* | bool]
|
||||||
|
word arr_find
|
||||||
|
over @ >r >r 8 + r> r>
|
||||||
|
0 >r
|
||||||
|
for
|
||||||
|
2dup swap @ == if rswap r> nip nip rdrop ret end
|
||||||
|
swap 8 + swap rswap r> 1 + >r rswap
|
||||||
|
end rdrop -1 nip nip
|
||||||
|
end
|
||||||
|
|||||||
@@ -167,6 +167,37 @@
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
#3dup [*, x1, x2 | x3] -> [*, x1, x2, x3, x1, x2 | x3]
|
||||||
|
:asm 3dup {
|
||||||
|
mov rax, [r12] ; c (top)
|
||||||
|
mov rbx, [r12 + 8] ; b
|
||||||
|
mov rcx, [r12 + 16] ; a
|
||||||
|
sub r12, 8 ; make room
|
||||||
|
mov [r12], rcx ; push a
|
||||||
|
sub r12, 8 ; make room
|
||||||
|
mov [r12], rbx ; push b
|
||||||
|
sub r12, 8 ; make room
|
||||||
|
mov [r12], rax ; push c
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
#4dup [*, x1, x2, x3 | x4] -> [*, x1, x2, x3, x4, x1, x2, x3 | x4]
|
||||||
|
:asm 4dup {
|
||||||
|
mov rax, [r12] ; d
|
||||||
|
mov rbx, [r12 + 8] ; c
|
||||||
|
mov rcx, [r12 + 16] ; b
|
||||||
|
mov rdx, [r12 + 24] ; a
|
||||||
|
sub r12, 8 ; make room
|
||||||
|
mov [r12], rdx ; push a
|
||||||
|
sub r12, 8 ; make room
|
||||||
|
mov [r12], rcx ; push b
|
||||||
|
sub r12, 8 ; make room
|
||||||
|
mov [r12], rbx ; push c
|
||||||
|
sub r12, 8 ; make room
|
||||||
|
mov [r12], rax ; push d
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
#2drop [*, x1 | x2] -> [*]
|
#2drop [*, x1 | x2] -> [*]
|
||||||
:asm 2drop {
|
:asm 2drop {
|
||||||
add r12, 16 ; remove two items
|
add r12, 16 ; remove two items
|
||||||
|
|||||||
@@ -491,3 +491,66 @@ word splitby_char
|
|||||||
r>
|
r>
|
||||||
rm_zero_len_str
|
rm_zero_len_str
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# ltrim [*, addr | len] -> [*, addr, | len]
|
||||||
|
word ltrim
|
||||||
|
dup for
|
||||||
|
over c@ 32 == if
|
||||||
|
swap 1 + swap 1 -
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# rtrim [*, addr | len] -> [*, addr, | len]
|
||||||
|
word rtrim
|
||||||
|
swap tuck swap
|
||||||
|
swap over + 1 - swap
|
||||||
|
dup for
|
||||||
|
over c@ 32 == if
|
||||||
|
swap 1 - swap 1 -
|
||||||
|
end
|
||||||
|
end nip
|
||||||
|
end
|
||||||
|
|
||||||
|
# trim [*, addr | len] -> [*, addr | len]
|
||||||
|
word trim
|
||||||
|
ltrim rtrim
|
||||||
|
end
|
||||||
|
|
||||||
|
# startswith [*, addr, len, addr | len] -> [*, bool]
|
||||||
|
inline word startswith
|
||||||
|
strcmp
|
||||||
|
end
|
||||||
|
|
||||||
|
# endswith [*, addr, len, addr | len] -> [*, bool]
|
||||||
|
word endswith
|
||||||
|
dup 3 pick swap - 4 pick + over 2 pick 4 pick swap strcmp
|
||||||
|
nip nip nip nip
|
||||||
|
end
|
||||||
|
|
||||||
|
# contains [*, addr, len, addr | len] -> [* | bool]
|
||||||
|
word contains
|
||||||
|
2 pick for
|
||||||
|
4dup strcmp 1 == if 1 nip nip nip nip rdrop ret end
|
||||||
|
>r >r >r 1 + r> r> r>
|
||||||
|
end 0 nip nip nip nip
|
||||||
|
end
|
||||||
|
|
||||||
|
# find the first occurence of a string inside another string, returns the index
|
||||||
|
# find [*, addr, len, addr | len] -> [* | index]
|
||||||
|
word find
|
||||||
|
0 >r 2 pick for
|
||||||
|
4dup strcmp 1 == if rswap r> nip nip nip nip rdrop ret end
|
||||||
|
>r >r >r 1 + r> r> r> rswap r> 1 + >r rswap
|
||||||
|
end -1 nip nip nip nip
|
||||||
|
end
|
||||||
|
|
||||||
|
# find the last occurence of a string inside another string, returns the index
|
||||||
|
# rfind [*, addr, len, addr | len] -> [* | index]
|
||||||
|
word rfind
|
||||||
|
>r >r dup >r + 1 - r> r> r>
|
||||||
|
2 pick 1 - >r 2 pick for
|
||||||
|
4dup strcmp 1 == if rswap r> nip nip nip nip rdrop ret end
|
||||||
|
>r >r >r 1 - r> r> r> rswap r> 1 - >r rswap
|
||||||
|
end -1 nip nip nip nip
|
||||||
|
end
|
||||||
|
|||||||
@@ -11,3 +11,6 @@ o wor
|
|||||||
d he
|
d he
|
||||||
o wor
|
o wor
|
||||||
he
|
he
|
||||||
|
|f |
|
||||||
|
| f|
|
||||||
|
|f|
|
||||||
|
|||||||
@@ -21,4 +21,9 @@ word main
|
|||||||
for puts end
|
for puts end
|
||||||
"hello world hello world hello" "l" splitby
|
"hello world hello world hello" "l" splitby
|
||||||
for puts end
|
for puts end
|
||||||
|
|
||||||
|
" f " 2dup 2dup
|
||||||
|
124 putc ltrim write_buf 124 putc cr
|
||||||
|
124 putc rtrim write_buf 124 putc cr
|
||||||
|
124 putc trim write_buf 124 putc cr
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user