Author Topic: On Muttering  (Read 9540 times)

0 Members and 1 Guest are viewing this topic.

JRS

  • Guest
Re: On Muttering
« Reply #15 on: October 06, 2014, 11:30:44 AM »
Quote from: Mike
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.

You should have a peek at the DLLC code Charles did for console support in a threaded environment. Works great!

Mike Lobanovsky

  • Guest
Re: On Muttering
« Reply #16 on: October 06, 2014, 11:43:33 AM »
John,

You feelin' jealous or overlooked or what? Charles asked me how my console works in FBSL and I answered. We are talking about problems with his gxo2.exe, not FBSL or SB that don't have any such problems, thanks God in the former case, and Charles, in the latter.

Charles is a brilliant programmer and I'm absolutely sure gxo2.exe will get eventually improved on too (if only he wouldn't doze off over such workarounds as were suggested here... ;) )

JRS

  • Guest
Re: On Muttering
« Reply #17 on: October 06, 2014, 12:39:14 PM »
Quote from: Mike
You feelin' jealous or overlooked or what?

Nope. It's what people do when advocating for an open source project.

Before disregarding my post, the O2 DLLC debug console works well with GUI centric code.

 

Mike Lobanovsky

  • Guest
Re: On Muttering
« Reply #18 on: October 06, 2014, 01:45:53 PM »
PS: I seldom listen to my own mutterings :)

Hehe, now tell me how you don't talk to your robotic vacuum cleaner when it stumbles upon your feet or how you don't talk to your television in the middle of a soccer or baseball match! :P

Charles Pegge

  • Guest
Re: On Muttering
« Reply #19 on: October 06, 2014, 02:44:25 PM »

I remember giving up my black&white telly around 1987 - It babbled too much, and never listened to what I had to say. It was eventually used as a monitor for an EPROM programming device.

re: printf
I tried late binding msvcrt after the console was initialised. But that did not work, so I tried : _cprintf, and that worked (direct console output). So the problem appears to be a disconnection with STDOUT.

http://msdn.microsoft.com/en-us/library/7ax4dbdt.aspx
http://msdn.microsoft.com/en-us/library/7x2hy4cx.aspx

Thanks for your detailed description of FBSL operations, Mike.

Mike Lobanovsky

  • Guest
Re: On Muttering :: Victory!
« Reply #20 on: October 06, 2014, 04:17:48 PM »
Ta-da-a-a-a-a!!! :D

Charles,

I've found a way to bind any console to the msvcrt's internal file buffers (including stdin, stdout, and stderr). Such functions as fprintf() with an explicit reference to a file buffer can even utilize an external user-defined FILE structure for its file buffer.

printf() is however bound to the msvcrt's internal file array element preset as stdout so its initialization is just a couple of lines longer.

I'm currently running tests but in the meantime you can enjoy

fprintf @stdout, "%s and his %s%d%s", "Charles", "O", 2, cr

fprintf'ed via a user-defined stdout structure in Oxygen's standard Console.inc's console as it runs in gxo2:

.

Charles Pegge

  • Guest
Re: On Muttering
« Reply #21 on: October 06, 2014, 04:49:12 PM »

Very good Mike,

Can you pls show me your code, setting up for fprintf stdout.

Must sleep now. Happy hunting!

Mike Lobanovsky

  • Guest
Re: On Muttering
« Reply #22 on: October 06, 2014, 05:37:25 PM »
Sure Charles,

Have a good rest. The test script will be waiting for you below -- both runnable in gxo2 and compilable into a console exe:

Code: [Select]
#console

includepath "$\inc\"
'$filename "fprintf.exe"
'include "rtl32.inc"
include "Console.inc"

indexbase 0

' _iob[FOPEN_MAX] is msvcrt's internal file buffer array.
' _iob[] can be exported directly, or via cdecl __p__iob(), or via cdecl __iob_func().
' Reference:
' #define FOPEN_MAX     20
' #define STDIN_FILENO  0
' #define STDOUT_FILENO 1
' #define STDERR_FILENO 2
' #define stdin         &_iob[STDIN_FILENO]
' #define stdout        &_iob[STDOUT_FILENO]
' #define stderr        &_iob[STDERR_FILENO]

type FILE
char* _ptr
int _cnt
char* _base
int _flag
int _file
int _charbuf
int _bufsiz
char* _tmpfname
end type

! __p__iob cdecl lib "msvcrt.dll" () as sys
! _open_osfhandle cdecl lib "msvcrt.dll" (sys a, b) as sys
! _fdopen cdecl lib "msvcrt.dll" (sys a, char* b) as sys
! setvbuf cdecl lib "msvcrt.dll" (sys a, char* b, sys c, d)
! fprintf cdecl lib "msvcrt.dll" (sys a, char* b, ...)
! printf lib "msvcrt.dll" (char* a, ...)
! memcpy lib "msvcrt.dll" (sys a, b, c)

#define _O_TEXT 0x4000 // CRLF in file becomes LF in memory!
#define _IONBF  0x4

' same for ConsIn/"r", ConsErr/"w"
sys hCrt = _open_osfhandle(ConsOut, _O_TEXT)
sys hf   = _fdopen(hCrt, "w")

' user-defined buffer (for fprintf() only!)
FILE mystdout at hf
setvbuf @mystdout, NULL, _IONBF, 0

' _iob's internals:
' stdin at _iob as "r",
' stdout at iob+sizeof(FILE) as "w"
' stderr at _iob+2*sizeof(FILE) as "w"
sys _iob = __p__iob()
memcpy _iob + sizeof(FILE), hf, sizeof(FILE)
setvbuf _iob + sizeof(FILE), NULL, _IONBF, 0

fprintf @mystdout, "fprintf via mystdout: %s and his %s%d%s", "Charles", "O", 2, cr
fprintf _iob + sizeof(FILE), "fprintf via stdout  : %s and his %s%d%s", "Charles", "O", 2, cr
printf "printf  via stdout  : %s and his %s%d%s", "Charles", "O", 2, cr

waitkey

.

Charles Pegge

  • Guest
Re: On Muttering
« Reply #23 on: October 07, 2014, 12:49:04 AM »
Hi Mike,

Many thanks! That is seriously technical, and very useful to get some insight into MSVCRT. I have been playing with it :)



PS:

How to tell whether a function is cdecl or not:

espval=esp
memcpy _iob + sizeof(FILE), hf, sizeof(FILE)
print espval-esp cr
'This will be 12 if the function has not been declared cdecl

Lib declaration block

extern cdecl lib "msvcrt.dll"
! __p__iob        () as sys
! _open_osfhandle (sys a, b) as sys
! _fdopen         (sys a, char* b) as sys
! setvbuf         (sys a, char* b, sys c, d)
! fprintf         (sys a, char* b, ...)
! printf          (char* a, ...)
! memcpy          (sys a, b, c)
end extern



« Last Edit: October 07, 2014, 03:56:35 AM by Charles Pegge »

Mike Lobanovsky

  • Guest
Re: On Muttering
« Reply #24 on: October 07, 2014, 05:20:39 AM »
Hi Charles,

Thanks for fixing my declarations. Of course all the functions in msvcrt are cdecl by definition. The slip of my pen was due to FBSL always fixing the stack pointer transparently so that it makes no difference whatsoever to the user if the function to be called from an external library is in fact stdcall or cdecl. There are a couple dozens such C finctions that I don't need to look up the definitions for, and memcpy() and printf() happen to be among them.

I gather O2 must be doing the same trick or the script would have crashed at the first misdeclared cdecl call encountered? ;)


P.S. Console.inc included and functions declared as above, a somewhat prettified procedure of stdout initialization might look like this:

#define _IONBF  &H4
#define _O_TEXT &H4000
#define STDOUT_FILENO 1
#define stdout @_iob[STDOUT_FILENO]


sys hCrt = _open_osfhandle(ConsOut, _O_TEXT)
sys hf = _fdopen(hCrt, "w")

FILE* _iob = @(__p__iob())
memcpy stdout, hf, sizeof(FILE)
setvbuf stdout, NULL, _IONBF, 0

fprintf stdout, "fprintf via stdout  : %s and his %s%d%s", "Charles", "O", 2, cr


(Coloration is like in Oxygen's SciTE -- not very much to my liking BTW)
« Last Edit: October 07, 2014, 08:16:36 PM by Mike Lobanovsky »

Kuron

  • Guest
Re: On Muttering
« Reply #25 on: October 08, 2014, 06:45:34 AM »
So my question is, how would you mutter to yourselves hWnd when typing a function call?

H Wind

wind as in a breeze, not wind as in winding a watch
« Last Edit: October 08, 2014, 07:09:41 AM by Kuron »

Charles Pegge

  • Guest
Re: On Muttering
« Reply #26 on: October 08, 2014, 12:18:51 PM »
Hi Mike,

Re: Scite Ide Colors

Not my favorite either. You are welcome to improve them if you have a favorite colour scheme. You will find ThemeStandard, ThemeDark, and ThemeLight.PROPERTIES in ide/. The themes are selected at the end of Oxygen.PROPERTIES.

Here is ThemeStandard.PROPERTIES
Code: [Select]
# Light Theme by kryton9
# OxygenBasic Styles
style.vb.32=fore:000000,back:EEEEEE,font:Courier New,size:12

# Symbols
 style.vb.0=fore:000000,back:EEEEEE,font:Courier New,size:12

# Comment
style.vb.1=fore:224400,back:EEEEEE,font:Courier New,size:12

# Number
style.vb.2=fore:880000,back:EEEEEE,font:Courier New,size:12,bold

# Keyword
style.vb.3=fore:1100AA,back:EEEEEE,font:Courier New,size:12,bold

# String
style.vb.4=fore:2200AA,back:EEEEEE,font:Courier New,size:12,bold

# keywords 2 Directives Preprocessor
style.vb.5=fore:440000,back:EEEEEE,font:Courier New,size:12

# Operator
style.vb.6=fore:000000,back:EEEEEE,font:Courier New,size:12

# Identifier
style.vb.7=fore:000000,back:EEEEEE,font:Courier New,size:12

# Date
# style.vb.8=

# End of line where string is not closed
# style.vb.9=

# keywords3
#style.vb.11=fore:222222,back:EEEEEE,font:Courier New,size:12

# keywords4
#style.vb.12=fore:222222,back:EEEEEE,font:Courier New,size:12

# Constant
style.vb.13=fore:222222,back:EEEEEE,font:Courier New,size:12

# Asm
# style.vb.14=

# Label
style.vb.15=

# Error
style.vb.16=

# HexNumber
style.vb.17=

# BinNumber
style.vb.18=


# Line number
style.vb.33=fore:333333,back:#DDDDDD,font:Courier New,size:12

# Indentation guides
style.vb.37=fore:#CCCCCC,back:#CCCCCC

if style.vb
caret.fore=#000000
selection.alpha=128
selection.back=#CCCCCC

if style.vb
fold.margin.colour=#555555
fold.margin.highlight.colour=#555555
fold.symbols=0
#the below only work for fold.symbols >= 2
#fold.highlight=1
#fold.highlight.colour=#007700

JRS

  • Guest
Re: On Muttering
« Reply #27 on: October 08, 2014, 12:24:01 PM »
Charles,

I think Mike was referring to the O2 forum. I have syntax highlighting working on the SB forum and sent you a message some time ago offering to install it here. Your call.

John

Charles Pegge

  • Guest
Re: On Muttering
« Reply #28 on: October 08, 2014, 12:47:14 PM »
Thanks John.

I could not decide whether to use it. I am a minimalist at heart.



Mike,

I have fixed the pointered typedef problem. So you should be able to create variables with pointer, as well as cell*

Pointered Typedefs example
Code: [Select]

typedef struct _tt
==================
{
 sys a,b,c
} tt,*pt

function f(pt b)
================
pt a at getmemory 120
a.b=42
print a.b '42
print b.b '2
freememory @a
end function

Test
====

tt a={1,2,3}
f a

http://www.oxygenbasic.org/o2zips/Oxygen.zip



PS: One can often get away with undetected cdecl calls within  an O2 function because the epilog restores the stack pointer from the ebp register. Such calls inside a loop, risk a stack overflow, however.

« Last Edit: October 09, 2014, 03:27:48 AM by Charles Pegge »

Mike Lobanovsky

  • Guest
Re: On Muttering
« Reply #29 on: October 08, 2014, 05:57:34 PM »
Hi guys,


@Kuron:

That's it! :D

Following the lofty "hwat", "hwen", "hwere" as an intuitive template, I've been always muttering it as "hwind". But I was also always too shy to ask whether I'd make a laughing stock of myself if ever caught at doing that by somebody who really knows how it should sound. One item off the long list of questions that must be resolved before I go. :)


@John:

Yes, I think it would add elegance to the overall look of the site. Of course if Charles' Spartan style and Stoic philosophy permit. :) (Regretfully, I can't do the same at FBSL because the phpbb3 board simply doesn't support this feature.)


@Charles:

1. Thanks much for syntax highlighting directions and Kryton's theme as a template. I'll try to readjust my SciTE environment to my liking so that it wouldn't distract my attention any more.

2. char*/pointer usablity is good news. It does add to Oxygen's consistency regardless of someone's paranoia about the code it's going to be used in. ;)

3. Thanks also for making me aware of stack issues with misdeclared cdecl functions in a loop.