Author Topic: On Muttering  (Read 9547 times)

0 Members and 2 Guests are viewing this topic.

Mike Lobanovsky

  • Guest
On Muttering
« on: October 05, 2014, 05:25:53 PM »
Hello native English speakers,

Welcome to a completely off-topic thread.

It is a well-known fact that people often mutter to themselves when totally immersed in some work. It is generally believed that muttering helps people concentrate deeper.

So my question is, how would you mutter to yourselves hWnd when typing a function call?

(Be forewarned I'm never going to believe it if you would insist you're calling it eitch-dubl-you-en-dee)

Charles Pegge

  • Guest
Re: On Muttering
« Reply #1 on: October 05, 2014, 10:47:29 PM »
Hi Mike,

It is easy using Welsh pronunciation, though I am not a speaker myself. Welsh phonetics are highly consistent, so one can deliver an entire speech without understanding a single word of it. :)

hWnd: pronounced Hoond



Mike Lobanovsky

  • Guest
Re: On Muttering
« Reply #2 on: October 05, 2014, 10:58:27 PM »
Morning Charles,

Is that your personal, unique way of muttering it?


(Charles, I've spent the whole night trying to find out why Oxygen's console wouldn't display printf(), fprintf(), etc. output, even though I can easily get correct pointers to msvcrt.dll's _iob[] (that's its internal FILE array) and all the necessary function pointers. MS VC, GCC, DynC and FBSL's BASIC do it easily without any problems with the exact same pointers but not Oxygen. That's very irritating because nanoscheme must use the same function set to print to the console and to disk files. That's what the fprintf family does. Do you know by any chance what might be causing this, er, unusual behavior? :( )
« Last Edit: October 05, 2014, 11:42:51 PM by Mike Lobanovsky »

Charles Pegge

  • Guest
Re: On Muttering
« Reply #3 on: October 05, 2014, 11:33:29 PM »
Nothing obvious, for sure. Would it be worth creating an emulation of printf, (returning a string). I have some partial models already. Avoiding dependency on MSVCRT.

PS: I seldom listen to my own mutterings :)

Mike Lobanovsky

  • Guest
Re: On Muttering
« Reply #4 on: October 05, 2014, 11:47:39 PM »
But why should we be trying to avoid this dependency? CRT is available on all known platforms, and its f... functions have been standard C stream methodology since K&R! printf() is just a castrated fprintf() oriented towards stdout only...

Charles Pegge

  • Guest
Re: On Muttering
« Reply #5 on: October 05, 2014, 11:55:48 PM »
I thought MSVCRT was only included with a C compier.

Does it require an initialisation procedure, invisibly implemented by the C compiler ?

http://msdn.microsoft.com/en-us/library/bb918180.aspx

Mike Lobanovsky

  • Guest
Re: On Muttering
« Reply #6 on: October 06, 2014, 12:03:54 AM »
CRT is a system library everywhere, Charles. And no, there's no initialization required. You can even get the _iob and function pointers via LoadLibrary/GetProcAddress in any of the languages and call fprintf or printf by pointer, and they would work -- but not in Oxygen. Neither is it a matter of variadic-ity (?) because sscanf() or sprintf() work faultlessly while being similarly variadic.

I think something must be wrong with the console proper. But exactly what it is is slipping me at the moment...

Charles Pegge

  • Guest
Re: On Muttering
« Reply #7 on: October 06, 2014, 12:39:17 AM »
I must explore!

sprint_s works:

Code: [Select]
includepath "$/inc/"
include "console.inc"

extern lib "MSVCRT.dll"

sys _aligned_malloc(sys size, alignment)
sys _aligned_free(sys memblock)
sys sprintf_s(char *buf, sys size, char* format, ...)

end extern

'a=_aligned_malloc 100,8

string s=nuls 1000

sprintf_s s,1000,"%s","Hello World",0

print s
waitkey

But printf does not engage with the console.
« Last Edit: October 06, 2014, 12:59:11 AM by Charles Pegge »

Charles Pegge

  • Guest
Re: On Muttering
« Reply #8 on: October 06, 2014, 01:07:13 AM »
Got it!

printf will not work in JIT code, but in a binary, you can declare it to be a console application. This changes the SUBSYSTEM flag in the PE fileheader from 2 to 3:

#console

Code: [Select]
#console
% filename "t.exe"
includepath "$/inc/"
include "RTL32.inc"
include "console.inc"

extern lib "MSVCRT.dll"

sys _aligned_malloc(sys size, alignment)
sys _aligned_free(sys memblock)
sys printf   (char *format, ...)
sys sprintf_s(char *buf, sys size, char *format, ...)

end extern

'a=_aligned_malloc 100,8

string s=nuls 1000, t=""

sprintf_s s,1000,"%s%i","Hello World" cr,42
print rtrim s
printf "%s%i\n", "Hello Moon" cr, 24

'waitkey
t=input

Mike Lobanovsky

  • Guest
Re: On Muttering
« Reply #9 on: October 06, 2014, 08:15:20 AM »
Yes Charles,

Your investigations are correct. My test script with fprintf() & Co. also works when compiled to a #console app, and that's great.

But this leaves us with the JIT problem in our hands. Fbsl.exe is a GUI program like gxo2.exe yet it allows its BASIC, DynC and DynAsm components to fprintf, printf and PRINT to the console easily. It just responds to the #apptype console directive in the script by opening up its process console that all these functions can print to no matter what components of the language are actually using them.

Can gxo2.exe do the same in response to #console, do you think?

Charles Pegge

  • Guest
Re: On Muttering
« Reply #10 on: October 06, 2014, 08:27:41 AM »
How do you make this happen in your JIT environment, Mike? Is it sufficient for the compiler to open a console?

Using sprintf is a good workaround:

sys sprintf_s(char *buf, sys size, char *format, ...)

static char s[1000]
...
sprintf_s s,1000,"%s%i","Hello World" cr,42 : print s
sprintf_s s,1000,"%s%i", cr "Hello Moon" cr, 24 : print s
« Last Edit: October 06, 2014, 10:19:50 AM by Charles Pegge »

JRS

  • Guest
Re: On Muttering
« Reply #11 on: October 06, 2014, 10:40:24 AM »
Quote
Using sprintf is a good workaround:

From the C world, I wouldn't call sprintf() a workaround. FORMAT in C clothing.

Charles Pegge

  • Guest
Re: On Muttering
« Reply #12 on: October 06, 2014, 10:48:31 AM »
It is certainly more versatile.

Mike Lobanovsky

  • Guest
Re: On Muttering
« Reply #13 on: October 06, 2014, 11:05:35 AM »
WE DON'T NEED ANY WORKAROUNDS! A WORKAROUND IS IN FACT A CRUTCH AND DOWNRIGHT SURRENDER! I BELIEVE WE CAN KILL THE BEAST IN ITS DEN!



There's absolutely no magic in the creation of FBSL console. Everything goes through AllocConsole(), same as in your Console.inc file.

From the system perspective, FBSL is always a monolithic GUI process. Its dynamically compiled DynC and DynAsm blocks are simply its subroutines that serve the needs of an FBSL script alonside the GCC subroutines of FBSL's virtual machine that execute the mixture of tokenized/bytecoded BASIC code proper. (Not all FBSL's BASIC constructs can be easily bytecoded so FBSL sometimes falls back to incremental interpretation, e.g. in the evaluation frames of For/Next loops.)

DynC and DynAsm blocks are compiled on program load and their entry points are fitted into the framework of an ordinary internal variant-based tree of a user defined function. There is no "external" difference between the tree (i.e. a doubly linked list of arguments, entry and return addresses, and a variant that would store persistently the most recent return value of this function) of an ordinary user defined BASIC function and a function precompiled by any of the two JITs. And the only "internal" difference between them would be that an interpretative BASIC function would make sideways calls to the virtual machine's helper routines to perform its duties while a JIT function would be completely self-sufficient -- sort of "encapsulated".

That said, FBSL would always create an invisible GUI window on launching regardless of the script's #apptype. If the #apptype is GUI (the default) or MDI, the user is supposed to optionally resize and center or otherwise reshape the window to the program's needs, show it and fall through to the Begin Events/End Events block which is a prettified callback for processing the window's messages.

The console is not automatically created in a GUI application. It is created on the fly only if the script hits an unsuppressed warning or untrapped error condition, in which case the console is immediately spawned through the same AllocConsole() and associated text coloration helpers to serve as an stderr device.

In an #apptype console or cgi mode, the console is created automatically via AllocConsole() at app start while the GUI window stays hidden at all times. This is the device where BASIC, C, and Asm code prints to, if needed, utilizing any of the BASIC or C or asm facilities that the programmer wishes, including BASIC PRINTF() and its derivatives, C fprintf() or printf(), or asm calls to any libraries preloaded for that purpose.

Printing occurs automagically: once the process has its console window opened, all printing goes there all by itself regardless of what printing functions are invoked.

If gxo2.exe acts in the same manner, i.e. if JIT compiled code runs within the bounds of gxo2's process as a subroutine, then gxo2.exe should spawn its own console in response to the #console directive in the script. But if it emits precompiled O2 code as a separate process, it should then inject transparently the AllocConsole() lines into the script just before compilation in response to the #console directive.


I hope my explanations are helpful. :)
« Last Edit: October 06, 2014, 11:19:44 AM by Mike Lobanovsky »

Mike Lobanovsky

  • Guest
Re: On Muttering
« Reply #14 on: October 06, 2014, 11:06:46 AM »
Hi John,

In the meantime, what about you variant of hWnd, please?