Oxygen Basic
Programming => Problems & Solutions => Topic started by: on October 05, 2018, 02:56:28 PM
-
Browsing the examples, I often find keywords that aren't documented anywhere, and I have to guess what they do. It must be the first time that a new user has to write the documentation of a language that he intends to learn.
Not sure if all my guess work is correct, so please correct me if needed.
... (ellipsis)
Used in procedure declarations and definitions to indicate a variable argument list. The first parameter in the variadic procedure must be the number of arguments pushed on the stack. The passed arguments must be of the same type.
param
Returns the Nth argument from a variable argument list. Together with ... (ellipsis), it allows the use of a variable number or arguments within a procedure. The passed arguments must be of the same type.
function cubes(int n, ...)
indexbase 0
int i
float v
for i = 1 to n
v = (int) param[i]
print v*v*v
next
end function
cubes 3, 2,3,4
-
call
Invokes a procedure by its address.
' Load the user32.dll
dim hLib as sys = LoadLibrary("user32.dll")
' Get the address of the MessageBoxA procedure
dim proc as sys = GetProcAddress(hLib, "MessageBoxA")
' Call the procedure by its address
call proc(0,"Hello World", "MessageBoxA", 0)
' Free the library
freelibrary hLib
From what I have learned with bind, I can also use this instead of call.
' Load the user32.dll
dim hLib as sys = LoadLibrary("user32.dll")
' Get the address of the MessageBoxA procedure
dim proc as sys = GetProcAddress(hLib, "MessageBoxA")
' Attach a function prototype to the address of MessageBox.
declare MessageBox(sys hWnd, char* lpText, char* lpCaption, dword uType) as int at proc
' Invoke the procedure
MessageBox 0,"Hello World", "MessageBoxA", 0
' Free the library
freelibrary hLib
There is also an example (ExplicitType.02bas) that uses call:
'========================
'EXPLICIT TYPE CONVERSION
'========================
'this can be used for procedure calls without prototypes
function fs(single a, b) external
'--------------------------------
print a+b
end function
function fd(double a, b) external
'--------------------------------
print a+b
end function
'SETUP ANONYMOUS PROCEDURES BY USING A SYS VARIABLE AS A POINTER
'===============================================================
sys g
'implicit double with decimal point
'==================================
g=@fs 'anonymise
call g 1.2, 15.25+1.0 'default single
'implicit single
'===============
g=@fs 'anonymise
single a=4.5, b=8.25
call g a, a+b
'explicit double
'===============
g=@fd 'anonymise
call g convert double 1, convert double 10
-
If CALL and BIND are duplicate functions, I would like CALL to provide its traditional BASIC function which #lookahead does now.
-
I would like CALL to provide its traditional BASIC function which #lookahead does now.
It is a misinterpretation of CALL tradition in BASIC. The genuine tradition is in CALL being used to execute the procedures that reside in external modules rather than in the main module where subs and functions may be called directly by their names.
The "lookahead" function of CALL command is exclusive to SB and is thus in no way "traditional".
-
Looks like call can be used as a function to get the returned value:
' Load the user32.dll
dim hLib as sys = LoadLibrary("user32.dll")
' Get the address of the MessageBoxA procedure
dim proc as sys = GetProcAddress(hLib, "MessageBoxA")
' Call the procedure by its address
dim hr as long = call proc(0,"Hello World", "MessageBoxA", 0)
print hr
' Free the library
freelibrary hLib
-
I was traditionally wrong. I still like the idea if CALL is available for repurposing.
-
o2 has two call forms:
1 Assembler call
A call with no parameters is treated as an asm instruction
call abc
2 procedure call
A call with parameters or empty brackets is treated as a normal procedural call, obeying the prevailing calling convention. 'call' is usually omitted when calling procedures :)
call abc()
v=call abc(...)
v=call abc x,y,z ...
-
... (ellipsis)
Used in procedure declarations and definitions to indicate a variable argument list. The first parameter in the variadic procedure must be the number of arguments pushed on the stack. The passed arguments must be of the same type.
The first parameter could also be a format string, enabling subsequent params to be dynamically typed:
A simplified format example:
function fmt(string sf,...) as string
'====================================
sys p=@param+sizeof sys
int nv at p 'integers
bstring sv at p 'string
single fv at p 'single
double dv at p 'double
sys i
int le=len sf
string sp=" "
do
i++ : if i>le then exit do
select asc sf,i
case "s" : function+= sv sp : p+=sizeof sys
case "n" : function+= nv sp : p+=sizeof sys
case "f" : function+= fv sp : p+=sizeof sys
case "d" : function+= dv sp : p+=sizeof double
end select
end do
end function
'TEST
'====
'literal floating points are Double
string s
s=fmt ("sndd","Result:", 42, 1.25, pi)
print s
-
param
Returns the Nth argument from a variable argument list. Together with ... (ellipsis), it allows the use of a variable number or arguments within a procedure. The passed arguments must be of the same type.
Param can be used to access parameters on the stack, as an array of sys values.
These can be cast to the expected type. But beware direct doubles on a 32bit system. They occupy 2 param slots.
@Param can be used as a base pointer to the list of parameters on the stack.
-
And we have to know all this without detailed documentation?
I will remove the "Basic" part from the name of the compiler.
-
It is a language in the making. We don't have a fixed specification, and these are quite technical features intended for the development of further infrastructure.
-
It is a language in the making. We don't have a fixed specification, and these are quite technical features intended for the development of further infrastructure.
I think DLLC is a good example as is the extensions to thinBasic.
And we have to know all this without detailed documentation?
If curiosity persists, the source to O2 is always available.
-
Great advice for beginners.
-
If you think O2 is confusing, try learning JavaScript.
-
I don't like scripting languages.
-
I got that with your comments about Script BASIC.
I think the era of language development has peaked. They are now recycling scripting languages instead.
-
Great advice for beginners.
DLLC high level FFI makes rolling your own includes a breeze.