From 7353fb1769cc136e4884b90ae2cdb1da32f09e41 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sun, 25 Aug 2024 12:34:08 -0400 Subject: [PATCH] added x11 commands --- .gitignore | 1 + Makefile | 2 +- source/main.c | 117 ++++++++++++++++++++++++++++++++++++++++++-- source/onward.ft | 9 ---- source/onward_sys.h | 2 +- x11.f | 23 +++++++++ 6 files changed, 140 insertions(+), 14 deletions(-) create mode 100644 x11.f diff --git a/.gitignore b/.gitignore index 5cabc30..a43a25c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ *.exe .rsconscache config.mk +onward diff --git a/Makefile b/Makefile index bf00ca3..01fc7cb 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ AR = ar # flags INCS = -Isource/ -Itests/ CPPFLAGS = -D_XOPEN_SOURCE=700 -CFLAGS += ${INCS} ${CPPFLAGS} --std=c99 -pedantic -Wall -Wextra +CFLAGS += ${INCS} ${CPPFLAGS} --std=c99 -Wall -Wextra LDFLAGS += ${LIBS} ARFLAGS = rcs diff --git a/source/main.c b/source/main.c index 17f27ee..6312824 100644 --- a/source/main.c +++ b/source/main.c @@ -34,15 +34,126 @@ defcode("load-sym", load_sym, &load_lib, 0u) { onward_aspush((value_t)val); } -defcode("ccall", ccall, &load_sym, 0u) { +defcode("ccall0", ccall0, &load_sym, 0u) { + void* func = (void*)onward_aspop(); + ((void (*)(void))func)(); +} + +defcode("ccall1", ccall1, &ccall0, 0u) { + void* func = (void*)onward_aspop(); + value_t arg1 = onward_aspop(); + ((void (*)(value_t))func)(arg1); +} + +defcode("ccall2", ccall2, &ccall1, 0u) { + void* func = (void*)onward_aspop(); + value_t arg2 = onward_aspop(); + value_t arg1 = onward_aspop(); + ((void (*)(value_t,value_t))func)(arg1, arg2); +} + +defcode("ccall3", ccall3, &ccall2, 0u) { + void* func = (void*)onward_aspop(); + value_t arg3 = onward_aspop(); + value_t arg2 = onward_aspop(); + value_t arg1 = onward_aspop(); + ((void (*)(value_t,value_t,value_t))func)( arg1, arg2, arg3 ); +} + +defcode("ccall4", ccall4, &ccall3, 0u) { + void* func = (void*)onward_aspop(); + value_t arg4 = onward_aspop(); + value_t arg3 = onward_aspop(); + value_t arg2 = onward_aspop(); + value_t arg1 = onward_aspop(); + ((void (*)(value_t,value_t,value_t,value_t))func)( arg1, arg2, arg3, arg4 ); +} + +defcode("ccall5", ccall5, &ccall4, 0u) { + void* func = (void*)onward_aspop(); + value_t arg5 = onward_aspop(); + value_t arg4 = onward_aspop(); + value_t arg3 = onward_aspop(); + value_t arg2 = onward_aspop(); + value_t arg1 = onward_aspop(); + ((void (*)(value_t,value_t,value_t,value_t,value_t))func)( arg1, arg2, arg3, arg4, arg5 ); +} +defcode("ccall6", ccall6, &ccall5, 0u) { + void* func = (void*)onward_aspop(); + value_t arg6 = onward_aspop(); + value_t arg5 = onward_aspop(); + value_t arg4 = onward_aspop(); + value_t arg3 = onward_aspop(); + value_t arg2 = onward_aspop(); + value_t arg1 = onward_aspop(); + ((void (*)(value_t,value_t,value_t,value_t,value_t,value_t))func)( arg1, arg2, arg3, arg4, arg5, arg6 ); } -defcode("ccall-ret", ccall_ret, &ccall, 0u) { +defcode("ccall0-ret", ccall0_ret, &ccall6, 0u) { + void* func = (void*)onward_aspop(); + value_t result = ((value_t (*)(void))func)(); + onward_aspush(result); +} + +defcode("ccall1-ret", ccall1_ret, &ccall0_ret, 0u) { + void* func = (void*)onward_aspop(); + value_t arg1 = onward_aspop(); + value_t result = ((value_t (*)(value_t))func)(arg1); + onward_aspush(result); +} + +defcode("ccall2-ret", ccall2_ret, &ccall1_ret, 0u) { + void* func = (void*)onward_aspop(); + value_t arg2 = onward_aspop(); + value_t arg1 = onward_aspop(); + value_t result = ((value_t (*)(value_t,value_t))func)(arg1, arg2); + onward_aspush(result); +} + +defcode("ccall3-ret", ccall3_ret, &ccall2_ret, 0u) { + void* func = (void*)onward_aspop(); + value_t arg3 = onward_aspop(); + value_t arg2 = onward_aspop(); + value_t arg1 = onward_aspop(); + value_t result = ((value_t (*)(value_t,value_t,value_t))func)( arg1, arg2, arg3 ); + onward_aspush(result); +} + +defcode("ccall4-ret", ccall4_ret, &ccall3_ret, 0u) { + void* func = (void*)onward_aspop(); + value_t arg4 = onward_aspop(); + value_t arg3 = onward_aspop(); + value_t arg2 = onward_aspop(); + value_t arg1 = onward_aspop(); + value_t result = ((value_t (*)(value_t,value_t,value_t,value_t))func)( arg1, arg2, arg3, arg4 ); + onward_aspush(result); +} + +defcode("ccall5-ret", ccall5_ret, &ccall4_ret, 0u) { + void* func = (void*)onward_aspop(); + value_t arg5 = onward_aspop(); + value_t arg4 = onward_aspop(); + value_t arg3 = onward_aspop(); + value_t arg2 = onward_aspop(); + value_t arg1 = onward_aspop(); + value_t result = ((value_t (*)(value_t,value_t,value_t,value_t,value_t))func)( arg1, arg2, arg3, arg4, arg5 ); + onward_aspush(result); +} +defcode("ccall6-ret", ccall6_ret, &ccall5_ret, 0u) { + void* func = (void*)onward_aspop(); + value_t arg6 = onward_aspop(); + value_t arg5 = onward_aspop(); + value_t arg4 = onward_aspop(); + value_t arg3 = onward_aspop(); + value_t arg2 = onward_aspop(); + value_t arg1 = onward_aspop(); + value_t result = ((value_t (*)(value_t,value_t,value_t,value_t,value_t,value_t))func)( arg1, arg2, arg3, arg4, arg5, arg6 ); + onward_aspush(result); } -defcode("dumpw", dumpw, &load_sym, 0u) { +defcode("dumpw", dumpw, &ccall6_ret, 0u) { word_t* word = (word_t*)onward_aspop(); printf("name:\t'%s'\n", word->name); printf("flags:\t%#zx\n", word->flags); diff --git a/source/onward.ft b/source/onward.ft index b21b43e..f01734f 100644 --- a/source/onward.ft +++ b/source/onward.ft @@ -44,15 +44,6 @@ : const word create [compile] literal 0 , ; -\ Stack Manipulation Words -\ ----------------------------------------------------------------------------- -: nip swap drop ; -: tuck swap over ; -: pick - 1 + CELLSZ * \ Calculate the offset of the desired element - asp @ swap - @ \ Fetch the element -; - \ Boolean Words \ ----------------------------------------------------------------------------- : negate 0 swap - ; diff --git a/source/onward_sys.h b/source/onward_sys.h index 8110c13..98af380 100644 --- a/source/onward_sys.h +++ b/source/onward_sys.h @@ -18,7 +18,7 @@ #endif #ifndef WORD_BUF_SZ -#define WORD_BUF_SZ (256 * sizeof(value_t)) +#define WORD_BUF_SZ (4096 * sizeof(value_t)) #endif extern value_t Argument_Stack[ARG_STACK_SZ]; diff --git a/x11.f b/x11.f new file mode 100644 index 0000000..9e286c6 --- /dev/null +++ b/x11.f @@ -0,0 +1,23 @@ +variable Xlib +variable Display + +: lib + word load-lib ; + +: -> + @ word load-sym ; + +# load xlib and store it's handle off +Xlib + lib libX11.so ! + +: sync + Display @ 0 [ Xlib -> XSync ] literal ccall2 ; + + +# Open the display and sync +Display + 0 [ Xlib -> XOpenDisplay ] ccall1-ret ! +sync + + -- 2.51.0