Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 26 |
Nodes: | 6 (1 / 5) |
Uptime: | 18:42:40 |
Calls: | 629 |
Files: | 1,186 |
D/L today: |
19 files (29,897K bytes) |
Messages: | 167,605 |
Humm... Actually, is this use of my macro(s), CT_ASB_*, okay for this
little code example I wrote to "help" me write AppleSoft BASIC? Can you
run it, is the code Kosher, so to speak, well, does it work for you or not...? Any undefined behavior in my macro? The macros seem a bit
hackish, but they seem to work okay for now: ______________________________________
#include <iostream>
#include <sstream>
// Macro kosher? Seems to be...
namespace ct_basic {
-a-a-a-a struct program_counter {
-a-a-a-a-a-a-a-a unsigned long m_origin;
-a-a-a-a-a-a-a-a unsigned long m_cur;
-a-a-a-a-a-a-a-a unsigned long m_inc;
-a-a-a-a-a-a-a-a std::stringstream m_prog;
-a-a-a-a-a-a-a-a program_counter(
-a-a-a-a-a-a-a-a-a-a-a-a unsigned long cur = 0,
-a-a-a-a-a-a-a-a-a-a-a-a unsigned long inc = 10
-a-a-a-a-a-a-a-a ) : m_origin(cur), m_cur(cur), m_inc(inc) {
-a-a-a-a-a-a-a-a }
-a-a-a-a-a-a-a-a void line(std::stringstream const& line0) { -a-a-a-a-a-a-a-a-a-a-a-a m_prog << m_cur << " " << line0.str() << std::endl; -a-a-a-a-a-a-a-a-a-a-a-a m_cur += m_inc;
-a-a-a-a-a-a-a-a }
-a-a-a-a };
-a-a-a-a #define CT_ASB_LINE(mp_pc, mp_x) \
-a-a-a-a-a-a-a-a { \
-a-a-a-a-a-a-a-a-a-a-a-a std::stringstream line0; \
-a-a-a-a-a-a-a-a-a-a-a-a line0 << mp_x; \
-a-a-a-a-a-a-a-a-a-a-a-a (mp_pc).line(line0); \
-a-a-a-a-a-a-a-a }
-a-a-a-a #define CT_ASB_GOSUB(mp_pc0, mp_pc1, mp_indent) \
-a-a-a-a-a-a-a-a CT_ASB_LINE(mp_pc0, mp_indent "GOSUB " << mp_pc1.m_origin)
}
int
main()
{
-a-a-a-a {
-a-a-a-a-a-a-a-a std::cout << "ctBasic testing 123... :^)\n"; -a-a-a-a-a-a-a-a std::cout << "__________________________\n";
-a-a-a-a-a-a-a-a {
-a-a-a-a-a-a-a-a-a-a-a-a ct_basic::program_counter pc0(100); -a-a-a-a-a-a-a-a-a-a-a-a ct_basic::program_counter pc1(1000);
-a-a-a-a-a-a-a-a-a-a-a-a // ct_main
-a-a-a-a-a-a-a-a-a-a-a-a {
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a ct_basic::program_counter& PC = pc0;
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a CT_ASB_LINE(PC, "REM ct_main"); -a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a CT_ASB_LINE(PC, "-a-a-a PRINT \"ct_main\""); -a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a CT_ASB_GOSUB(PC, pc1, "-a-a-a "); -a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a CT_ASB_LINE(PC, "END"); -a-a-a-a-a-a-a-a-a-a-a-a }
-a-a-a-a-a-a-a-a-a-a-a-a // ct_init
-a-a-a-a-a-a-a-a-a-a-a-a {
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a ct_basic::program_counter& PC = pc1;
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a CT_ASB_LINE(PC, "REM ct_init"); -a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a CT_ASB_LINE(PC, "-a-a-a PRINT \"ct_init\""); -a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a CT_ASB_LINE(PC, "RETURN"); -a-a-a-a-a-a-a-a-a-a-a-a }
-a-a-a-a-a-a-a-a-a-a-a-a std::cout << pc0.m_prog.str() << "\n\n"; -a-a-a-a-a-a-a-a-a-a-a-a std::cout << pc1.m_prog.str() << "\n\n"; -a-a-a-a-a-a-a-a }
-a-a-a-a-a-a-a-a std::cout << "__________________________\n";
-a-a-a-a }
-a-a-a-a std::cout << "Complete! Well, time to test the\n";
-a-a-a-a std::cout << "generated AppleSoft BASIC";
-a-a-a-a return 0;
}
______________________________________
Fwiw, I get an output of:
ctBasic testing 123... :^)
__________________________
100 REM ct_main
110-a-a-a-a PRINT "ct_main"
120-a-a-a-a GOSUB 1000
130 END
1000 REM ct_init
1010-a-a-a-a PRINT "ct_init"
1020 RETURN
__________________________---- snippet of class Spu manpage https://sourceforge.net/projects/cscall/ SYNOPSIS
Complete! Well, time to test the
generated AppleSoft BASIC
Humm... Actually, is this use of my macro(s), CT_ASB_*, okay for this
little code example I wrote to "help" me write AppleSoft BASIC? Can you
run it, is the code Kosher, so to speak, well, does it work for you or not...? Any undefined behavior in my macro? The macros seem a bit
hackish, but they seem to work okay for now: ______________________________________
#include <iostream>
#include <sstream>
// Macro kosher? Seems to be...
namespace ct_basic {
-a-a-a struct program_counter {
-a-a-a-a-a-a-a unsigned long m_origin;
-a-a-a-a-a-a-a unsigned long m_cur;
-a-a-a-a-a-a-a unsigned long m_inc;
-a-a-a-a-a-a-a std::stringstream m_prog;
-a-a-a-a-a-a-a program_counter(
-a-a-a-a-a-a-a-a-a-a-a unsigned long cur = 0,
-a-a-a-a-a-a-a-a-a-a-a unsigned long inc = 10
-a-a-a-a-a-a-a ) : m_origin(cur), m_cur(cur), m_inc(inc) {
-a-a-a-a-a-a-a }
-a-a-a-a-a-a-a void line(std::stringstream const& line0) {
-a-a-a-a-a-a-a-a-a-a-a m_prog << m_cur << " " << line0.str() << std::endl;
-a-a-a-a-a-a-a-a-a-a-a m_cur += m_inc;
-a-a-a-a-a-a-a }
-a-a-a };
-a-a-a #define CT_ASB_LINE(mp_pc, mp_x) \
-a-a-a-a-a-a-a { \
-a-a-a-a-a-a-a-a-a-a-a std::stringstream line0; \
-a-a-a-a-a-a-a-a-a-a-a line0 << mp_x; \
-a-a-a-a-a-a-a-a-a-a-a (mp_pc).line(line0); \
-a-a-a-a-a-a-a }
-a-a-a #define CT_ASB_GOSUB(mp_pc0, mp_pc1, mp_indent) \
-a-a-a-a-a-a-a CT_ASB_LINE(mp_pc0, mp_indent "GOSUB " << mp_pc1.m_origin)
}
int
main()
{
-a-a-a {
-a-a-a-a-a-a-a std::cout << "ctBasic testing 123... :^)\n";
-a-a-a-a-a-a-a std::cout << "__________________________\n";
-a-a-a-a-a-a-a {
-a-a-a-a-a-a-a-a-a-a-a ct_basic::program_counter pc0(100);
-a-a-a-a-a-a-a-a-a-a-a ct_basic::program_counter pc1(1000);
-a-a-a-a-a-a-a-a-a-a-a // ct_main
-a-a-a-a-a-a-a-a-a-a-a {
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a ct_basic::program_counter& PC = pc0;
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a CT_ASB_LINE(PC, "REM ct_main");
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a CT_ASB_LINE(PC, "-a-a-a PRINT \"ct_main\"");
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a CT_ASB_GOSUB(PC, pc1, "-a-a-a ");
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a CT_ASB_LINE(PC, "END");
-a-a-a-a-a-a-a-a-a-a-a }
-a-a-a-a-a-a-a-a-a-a-a // ct_init
-a-a-a-a-a-a-a-a-a-a-a {
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a ct_basic::program_counter& PC = pc1;
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a CT_ASB_LINE(PC, "REM ct_init");
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a CT_ASB_LINE(PC, "-a-a-a PRINT \"ct_init\"");
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a CT_ASB_LINE(PC, "RETURN");
-a-a-a-a-a-a-a-a-a-a-a }
-a-a-a-a-a-a-a-a-a-a-a std::cout << pc0.m_prog.str() << "\n\n";
-a-a-a-a-a-a-a-a-a-a-a std::cout << pc1.m_prog.str() << "\n\n";
-a-a-a-a-a-a-a }
-a-a-a-a-a-a-a std::cout << "__________________________\n";
-a-a-a }
-a-a-a std::cout << "Complete! Well, time to test the\n";
-a-a-a std::cout << "generated AppleSoft BASIC";
-a-a-a return 0;
}
______________________________________
Fwiw, I get an output of:
ctBasic testing 123... :^)
__________________________
100 REM ct_main
110-a-a-a-a PRINT "ct_main"
120-a-a-a-a GOSUB 1000
130 END
1000 REM ct_init
1010-a-a-a-a PRINT "ct_init"
1020 RETURN
__________________________
Complete! Well, time to test the
generated AppleSoft BASIC
On 9/17/2025 2:45 AM, Chris M. Thomasson wrote:
Humm... Actually, is this use of my macro(s), CT_ASB_*, okay for this
little code example I wrote to "help" me write AppleSoft BASIC? Can
you run it, is the code Kosher, so to speak, well, does it work for
you or not...? Any undefined behavior in my macro? The macros seem a
bit hackish, but they seem to work okay for now:
______________________________________
#include <iostream>
#include <sstream>
// Macro kosher? Seems to be...
namespace ct_basic {
-a-a-a-a struct program_counter {
-a-a-a-a-a-a-a-a unsigned long m_origin;
-a-a-a-a-a-a-a-a unsigned long m_cur;
-a-a-a-a-a-a-a-a unsigned long m_inc;
-a-a-a-a-a-a-a-a std::stringstream m_prog;
-a-a-a-a-a-a-a-a program_counter(
-a-a-a-a-a-a-a-a-a-a-a-a unsigned long cur = 0,
-a-a-a-a-a-a-a-a-a-a-a-a unsigned long inc = 10
-a-a-a-a-a-a-a-a ) : m_origin(cur), m_cur(cur), m_inc(inc) {
-a-a-a-a-a-a-a-a }
-a-a-a-a-a-a-a-a void line(std::stringstream const& line0) {
-a-a-a-a-a-a-a-a-a-a-a-a m_prog << m_cur << " " << line0.str() << std::endl; >> -a-a-a-a-a-a-a-a-a-a-a-a m_cur += m_inc;
-a-a-a-a-a-a-a-a }
-a-a-a-a };
-a-a-a-a #define CT_ASB_LINE(mp_pc, mp_x) \
-a-a-a-a-a-a-a-a { \
-a-a-a-a-a-a-a-a-a-a-a-a std::stringstream line0; \
-a-a-a-a-a-a-a-a-a-a-a-a line0 << mp_x; \
-a-a-a-a-a-a-a-a-a-a-a-a (mp_pc).line(line0); \
-a-a-a-a-a-a-a-a }
-a-a-a-a #define CT_ASB_GOSUB(mp_pc0, mp_pc1, mp_indent) \
-a-a-a-a-a-a-a-a CT_ASB_LINE(mp_pc0, mp_indent "GOSUB " << mp_pc1.m_origin) >> }
Why macros? My Copilot rewrote them as functions, apparently with no
loss of functionality:
-a-a void CT_ASB_LINE(program_counter& mp_pc, const std::string& mp_x)
-a-a {
-a-a-a-a-a-a std::stringstream line0;
-a-a-a-a-a-a line0 << mp_x;
-a-a-a-a-a-a (mp_pc).line(line0);
-a-a }
-a-a void CT_ASB_GOSUB(program_counter& mp_pc0, program_counter& mp_pc1, const std::string& mp_indent)
-a-a {
-a-a-a-a-a-a CT_ASB_LINE(mp_pc0, mp_indent + "GOSUB " + std::to_string(mp_pc1.m_origin));
-a-a }
Coming to think about that, why stringstreams at all? In my experience
just growing a std::string by appending to it is both simpler and faster.
On 9/17/2025 4:43 AM, Paavo Helde wrote:
On 9/17/2025 2:45 AM, Chris M. Thomasson wrote:
Humm... Actually, is this use of my macro(s), CT_ASB_*, okay for this
little code example I wrote to "help" me write AppleSoft BASIC? Can
you run it, is the code Kosher, so to speak, well, does it work for
you or not...? Any undefined behavior in my macro? The macros seem a
bit hackish, but they seem to work okay for now:
______________________________________
#include <iostream>
#include <sstream>
// Macro kosher? Seems to be...
namespace ct_basic {
-a-a-a-a struct program_counter {
-a-a-a-a-a-a-a-a unsigned long m_origin;
-a-a-a-a-a-a-a-a unsigned long m_cur;
-a-a-a-a-a-a-a-a unsigned long m_inc;
-a-a-a-a-a-a-a-a std::stringstream m_prog;
-a-a-a-a-a-a-a-a program_counter(
-a-a-a-a-a-a-a-a-a-a-a-a unsigned long cur = 0,
-a-a-a-a-a-a-a-a-a-a-a-a unsigned long inc = 10
-a-a-a-a-a-a-a-a ) : m_origin(cur), m_cur(cur), m_inc(inc) {
-a-a-a-a-a-a-a-a }
-a-a-a-a-a-a-a-a void line(std::stringstream const& line0) {
-a-a-a-a-a-a-a-a-a-a-a-a m_prog << m_cur << " " << line0.str() << std::endl;
-a-a-a-a-a-a-a-a-a-a-a-a m_cur += m_inc;
-a-a-a-a-a-a-a-a }
-a-a-a-a };
-a-a-a-a #define CT_ASB_LINE(mp_pc, mp_x) \
-a-a-a-a-a-a-a-a { \
-a-a-a-a-a-a-a-a-a-a-a-a std::stringstream line0; \
-a-a-a-a-a-a-a-a-a-a-a-a line0 << mp_x; \
-a-a-a-a-a-a-a-a-a-a-a-a (mp_pc).line(line0); \
-a-a-a-a-a-a-a-a }
-a-a-a-a #define CT_ASB_GOSUB(mp_pc0, mp_pc1, mp_indent) \
-a-a-a-a-a-a-a-a CT_ASB_LINE(mp_pc0, mp_indent "GOSUB " << mp_pc1.m_origin) >>> }
Why macros? My Copilot rewrote them as functions, apparently with no
loss of functionality:
-a-a-a void CT_ASB_LINE(program_counter& mp_pc, const std::string& mp_x)
-a-a-a {
-a-a-a-a-a-a-a std::stringstream line0;
-a-a-a-a-a-a-a line0 << mp_x;
-a-a-a-a-a-a-a (mp_pc).line(line0);
-a-a-a }
-a-a-a void CT_ASB_GOSUB(program_counter& mp_pc0, program_counter&
mp_pc1, const std::string& mp_indent)
-a-a-a {
-a-a-a-a-a-a-a CT_ASB_LINE(mp_pc0, mp_indent + "GOSUB " +
std::to_string(mp_pc1.m_origin));
-a-a-a }
Coming to think about that, why stringstreams at all? In my experience
just growing a std::string by appending to it is both simpler and faster.
Hummm. I need to try them, thanks. Wrt stringstreams, I want to be able
to do shit like this, say:
______________________
// ct_init
{
-a-a-a ct_basic::program_counter& PC = pc1;
-a-a-a unsigned long xxx = 42;
-a-a-a CT_ASB_LINE(PC, "REM ct_init");
-a-a-a CT_ASB_LINE(PC, "-a-a-a PRINT \"ct_init\"");
-a-a-a CT_ASB_LINE(PC, "-a-a-a X = " << xxx);
-a-a-a CT_ASB_LINE(PC, "-a-a-a PRINT \"from C++: X = \"; X");
-a-a-a CT_ASB_LINE(PC, "RETURN");
}
______________________
See the difference? I have to try to compile it using the copilot code.
Let me try... Nope, does not work, errors for sure. The macros sure seem
to work. Unless I am missing something?
On 9/17/2025 10:58 PM, Chris M. Thomasson wrote:[...]
On 9/17/2025 4:43 AM, Paavo Helde wrote:
On 9/17/2025 2:45 AM, Chris M. Thomasson wrote:
[...]-a-a-a-a CT_ASB_LINE(PC, "REM ct_init");
-a-a-a-a CT_ASB_LINE(PC, "-a-a-a PRINT \"ct_init\"");
-a-a-a-a CT_ASB_LINE(PC, "-a-a-a X = " << xxx);
-a-a-a-a CT_ASB_LINE(PC, "-a-a-a PRINT \"from C++: X = \"; X");
-a-a-a-a CT_ASB_LINE(PC, "RETURN");
}
______________________
See the difference? I have to try to compile it using the copilot
code. Let me try... Nope, does not work, errors for sure. The macros
sure seem to work. Unless I am missing something?
I believe you want something like this:
Now you can call it with comma, instead of obscure << which would only
make sense if you know the macro details:
CT_ASB_LINE(PC, "-a-a-a X = ", xxx);
instead of former
CT_ASB_LINE(PC, "-a-a-a X = " << xxx);
One less character to type, yay!
On 9/17/2025 10:58 PM, Chris M. Thomasson wrote:[...]
On 9/17/2025 4:43 AM, Paavo Helde wrote:
On 9/17/2025 2:45 AM, Chris M. Thomasson wrote:
Humm... Actually, is this use of my macro(s), CT_ASB_*, okay for
this little code example I wrote to "help" me write AppleSoft BASIC?
Can you run it, is the code Kosher, so to speak, well, does it work
for you or not...? Any undefined behavior in my macro? The macros
seem a bit hackish, but they seem to work okay for now:
______________________________________
One less character to type, yay!
On 9/18/2025 3:28 AM, Paavo Helde wrote:
On 9/17/2025 10:58 PM, Chris M. Thomasson wrote:[...]
On 9/17/2025 4:43 AM, Paavo Helde wrote:
On 9/17/2025 2:45 AM, Chris M. Thomasson wrote:
Humm... Actually, is this use of my macro(s), CT_ASB_*, okay for
this little code example I wrote to "help" me write AppleSoft
BASIC? Can you run it, is the code Kosher, so to speak, well, does
it work for you or not...? Any undefined behavior in my macro? The
macros seem a bit hackish, but they seem to work okay for now:
______________________________________
One less character to type, yay!
:^D It works like a charm. Thanks Paavo! :^)
On 9/19/2025 9:41 AM, Chris M. Thomasson wrote:
On 9/18/2025 3:28 AM, Paavo Helde wrote:
On 9/17/2025 10:58 PM, Chris M. Thomasson wrote:[...]
On 9/17/2025 4:43 AM, Paavo Helde wrote:
On 9/17/2025 2:45 AM, Chris M. Thomasson wrote:
Humm... Actually, is this use of my macro(s), CT_ASB_*, okay for
this little code example I wrote to "help" me write AppleSoft
BASIC? Can you run it, is the code Kosher, so to speak, well, does >>>>>> it work for you or not...? Any undefined behavior in my macro? The >>>>>> macros seem a bit hackish, but they seem to work okay for now:
______________________________________
One less character to type, yay!
:^D It works like a charm. Thanks Paavo! :^)
Good to hear! C++ variadic templates from 2011 generating AppleSoft
BASIC from 1977, why not!
On 9/20/2025 12:03 AM, Paavo Helde wrote:
On 9/19/2025 9:41 AM, Chris M. Thomasson wrote:
On 9/18/2025 3:28 AM, Paavo Helde wrote:
On 9/17/2025 10:58 PM, Chris M. Thomasson wrote:[...]
On 9/17/2025 4:43 AM, Paavo Helde wrote:
On 9/17/2025 2:45 AM, Chris M. Thomasson wrote:
Humm... Actually, is this use of my macro(s), CT_ASB_*, okay for >>>>>>> this little code example I wrote to "help" me write AppleSoft
BASIC? Can you run it, is the code Kosher, so to speak, well,
does it work for you or not...? Any undefined behavior in my
macro? The macros seem a bit hackish, but they seem to work okay >>>>>>> for now:
______________________________________
One less character to type, yay!
:^D It works like a charm. Thanks Paavo! :^)
Good to hear! C++ variadic templates from 2011 generating AppleSoft
BASIC from 1977, why not!
In C++17, you can use Folds to reduce that to a single template.
template<typename... Args>
void printer(Args&&... args)
{
-a-a-a (std::cout << ... << args) << '\n';
}
On 9/20/2025 12:03 AM, Paavo Helde wrote:
On 9/19/2025 9:41 AM, Chris M. Thomasson wrote:
On 9/18/2025 3:28 AM, Paavo Helde wrote:
On 9/17/2025 10:58 PM, Chris M. Thomasson wrote:[...]
On 9/17/2025 4:43 AM, Paavo Helde wrote:
On 9/17/2025 2:45 AM, Chris M. Thomasson wrote:
Humm... Actually, is this use of my macro(s), CT_ASB_*, okay for >>>>>>> this little code example I wrote to "help" me write AppleSoft
BASIC? Can you run it, is the code Kosher, so to speak, well,
does it work for you or not...? Any undefined behavior in my
macro? The macros seem a bit hackish, but they seem to work okay >>>>>>> for now:
______________________________________
One less character to type, yay!
:^D It works like a charm. Thanks Paavo! :^)
Good to hear! C++ variadic templates from 2011 generating AppleSoft
BASIC from 1977, why not!
In C++17, you can use Folds to reduce that to a single template.
template<typename... Args>
void printer(Args&&... args)
{
-a-a-a (std::cout << ... << args) << '\n';
}
On 9/19/2025 9:41 AM, Chris M. Thomasson wrote:
On 9/18/2025 3:28 AM, Paavo Helde wrote:
On 9/17/2025 10:58 PM, Chris M. Thomasson wrote:[...]
On 9/17/2025 4:43 AM, Paavo Helde wrote:
On 9/17/2025 2:45 AM, Chris M. Thomasson wrote:
Humm... Actually, is this use of my macro(s), CT_ASB_*, okay for
this little code example I wrote to "help" me write AppleSoft
BASIC? Can you run it, is the code Kosher, so to speak, well, does >>>>>> it work for you or not...? Any undefined behavior in my macro? The >>>>>> macros seem a bit hackish, but they seem to work okay for now:
______________________________________
One less character to type, yay!
:^D It works like a charm. Thanks Paavo! :^)
Good to hear! C++ variadic templates from 2011 generating AppleSoft
BASIC from 1977, why not!
:^D Fwiw, I found an inefficacy in my BASIC code.
I should be rendering
one line, not all of the damn segments! One call vs four... Sigh.
Finding interesting shit in the generate code is fun. ;^)
Retro?