Data update

This commit is contained in:
Ingy döt Net 2024-10-16 18:07:41 -07:00
parent 81fd053722
commit 52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions

View file

@ -0,0 +1,16 @@
#include "crt.bi"
Extern "C"
Function Query (Byval dato As zstring Ptr, Byval longitud As size_t Ptr) As Integer Export
Dim As String message = "Here am I"
Dim As size_t message_length = Len(message)
If *longitud < message_length Then
Return 0
Else
memcpy(dato, Strptr(message), message_length)
*longitud = message_length
Return 1
End If
End Function
End Extern

View file

@ -0,0 +1,53 @@
#include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
#include <windows.h>
#else
#include <dlfcn.h>
#endif
typedef int (*QueryFunc)(char *, size_t *);
int main(int argc, char *argv[])
{
char Buffer[1024];
size_t Size = sizeof(Buffer);
#ifdef _WIN32
HMODULE hLib = LoadLibrary("libquery.dll");
if (!hLib) {
printf("failed to load library\n");
return 1;
}
QueryFunc Query = (QueryFunc)GetProcAddress(hLib, "Query");
#else
void *hLib = dlopen("./libquery.so", RTLD_LAZY);
if (!hLib) {
printf("failed to load library\n");
return 1;
}
QueryFunc Query = (QueryFunc)dlsym(hLib, "Query");
#endif
if (!Query) {
printf("failed to find Query function\n");
return 1;
}
if (0 == Query(Buffer, &Size)) {
printf("failed to call Query\n");
} else {
char *Ptr = Buffer;
while (Size-- > 0) putchar(*Ptr++);
putchar('\n');
}
#ifdef _WIN32
FreeLibrary(hLib);
#else
dlclose(hLib);
#endif
return 0;
}

View file

@ -1,13 +1,11 @@
(notonline)-->
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (peek/poke, call_back)</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">Here_am_I</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"Here am I"</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">Query</span><span style="color: #0000FF;">(</span><span style="color: #004080;">atom</span> <span style="color: #000000;">pData</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">pLength</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">len</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">peekNS</span><span style="color: #0000FF;">(</span><span style="color: #000000;">pLength</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">machine_word</span><span style="color: #0000FF;">(),</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">poke_string</span><span style="color: #0000FF;">(</span><span style="color: #000000;">pData</span><span style="color: #0000FF;">,</span><span style="color: #000000;">len</span><span style="color: #0000FF;">,</span><span style="color: #000000;">Here_am_I</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">0</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #7060A8;">pokeN</span><span style="color: #0000FF;">(</span><span style="color: #000000;">pLength</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">Here_am_I</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">machine_word</span><span style="color: #0000FF;">())</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">Query_cb</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">call_back</span><span style="color: #0000FF;">(</span><span style="color: #000000;">Query</span><span style="color: #0000FF;">)</span>
<!--
without js -- (peek/poke, call_back)
constant Here_am_I = "Here am I"
function Query(atom pData, pLength)
integer len = peekNS(pLength,machine_word(),0)
if poke_string(pData,len,Here_am_I) then
return 0
end if
pokeN(pLength,length(Here_am_I)+1,machine_word())
return 1
end function
constant Query_cb = call_back(Query)

View file

@ -0,0 +1,27 @@
format ELF64
public Query
section ".text" executable
Query:
push rdx ;preserve the registers
push rcx ;we change. Just in case.
xor rax, rax ;zero RAX. we use as an index
mov rdx, end_message - message ;length of message
cmp rdx, [rsi] ;is message bigger than buffer
jg .exit ;if yes goto .exit with zero in RAX
.xstring:
mov cl, byte[message + rax] ;move character to CL
mov byte[rdi + rax], cl ;move character in CL to buffer
inc rax ;increment index
cmp rax, rdx ;is index less than length of
jl .xstring ;message? if so loop again.
.finish:
mov qword[rsi], rax ;mov number of bytes copied to Length
mov rax, 1 ;mov return value of 1 into RAX
.exit:
pop rcx ;restore the registers to calling function
pop rdx ;Ben Eater says it's the polite thing to do.
ret ;return to calling function.
section ".data" writable
message: db "Here am I"
end_message: