Quote from: Quin on Today at 03:19:23 PMCool stuff, MrBcx! this is a super cool looking project.
Quote from: jos on Today at 01:52:22 PMHi,
Interesting! Would it be possible to do something similar with a Basic interpreter? (Written entirely in C. Very fast and competent.)
https://github.com/paladin-t/my_basic?tab=readme-ov-file
#include "my_basic.c"
DIM bas AS struct mb_interpreter_t PTR
mb_init()
mb_open(&bas)
mb_load_string(bas, "print 22 / 7;", TRUE)
mb_run(bas, TRUE)
mb_close(&bas)
mb_dispose()
PAUSE
#include "my_basic.c"
DIM script AS STRING
script = " class my_list" + CRLF$
script += " var l = list()" + CRLF$
script += " var tail = " + WRAP$("__TAIL__") + CRLF$
script += " def push_back(i)" + CRLF$
script += " push(l, i)" + CRLF$
script += " enddef" + CRLF$
script += " def pop_back()" + CRLF$
script += " return pop(l)" + CRLF$
script += " enddef" + CRLF$
script += " def get_iterator()" + CRLF$
script += " it = iterator(l)" + CRLF$
script += " return lambda ()" + CRLF$
script += " (" + CRLF$
script += " if not move_next(it) then" + CRLF$
script += " return tail" + CRLF$
script += " endif" + CRLF$
script += " return get(it)" + CRLF$
script += " )" + CRLF$
script += " enddef" + CRLF$
script += "endclass" + CRLF$
script += "lst = new(my_list)" + CRLF$
script += "lst.push_back(1)" + CRLF$
script += "lst.push_back(2)" + CRLF$
script += "lst.push_back(3)" + CRLF$
script += "lst.push_back(4)" + CRLF$
script += "iter = lst.get_iterator()" + CRLF$
script += "do" + CRLF$
script += " item = iter()" + CRLF$
script += " if item <> lst.tail then" + CRLF$
script += " print item;" + CRLF$
script += " endif" + CRLF$
script += "until item = lst.tail" + CRLF$
DIM bas AS struct mb_interpreter_t PTR
mb_init()
mb_open(&bas)
mb_load_string(bas, script, TRUE)
mb_run(bas, TRUE)
mb_close(&bas)
mb_dispose()
PAUSE
print 'Hello, world!'
And it compiles to a standalone executable, around 280 KB with MSVC using the UCRT. Pretty impressive!$Header
#define LUA_IMPL
#include "minilua.h"
$Header
Dim L As lua_State Ptr
L = luaL_newstate()
If L = NULL Then End
luaL_openlibs(L)
luaL_loadstring(L, "print 'Hello, world!'")
lua_call(L, 0, 0)
lua_close(L)
Quote from: Quin on April 26, 2025, 04:13:14 PMQuote from: MrBcx on April 26, 2025, 02:17:39 PMEverything that you sandwich between $HEADER directives must be legal c/c++ or c/c++ pre-processors commands. You cannot use BCX's BASIC directives, like $PRAGMA.Gotcha, thanks!
Robert, could we consider noting this in the help?
QuoteA $HEADER directive is placed before and after the C code.
$HEADER
/* C statements go here */
$HEADER
Quote from: MrBcx on April 26, 2025, 02:17:39 PMEverything that you sandwich between $HEADER directives must be legal c/c++ or c/c++ pre-processors commands. You cannot use BCX's BASIC directives, like $PRAGMA.Gotcha, thanks!