Author Topic: Undocumented features  (Read 3381 times)

0 Members and 1 Guest are viewing this topic.

  • Guest
Undocumented features
« 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.

Code: [Select]
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
« Last Edit: October 05, 2018, 03:43:08 PM by José Roca »

  • Guest
Re: Undocumented features
« Reply #1 on: October 05, 2018, 02:58:55 PM »
call

Invokes a procedure by its address.

Code: [Select]
' 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.

Code: [Select]
' 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:

Code: [Select]


  '========================
  '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
« Last Edit: October 05, 2018, 03:43:57 PM by José Roca »

JRS

  • Guest
Re: Undocumented features
« Reply #2 on: October 05, 2018, 03:07:48 PM »
If CALL and BIND are duplicate functions, I would like CALL to provide its traditional BASIC function which #lookahead does now.

Mike Lobanovsky

  • Guest
Re: Undocumented features
« Reply #3 on: October 05, 2018, 03:42:23 PM »
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".

José Roca

  • Guest
Re: Undocumented features
« Reply #4 on: October 05, 2018, 04:00:48 PM »
Looks like call can be used as a function to get the returned value:

Code: [Select]
' 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

JRS

  • Guest
Re: Undocumented features
« Reply #5 on: October 05, 2018, 04:06:00 PM »
I was traditionally wrong. I still like the idea if CALL is available for repurposing.

Charles Pegge

  • Guest
Re: Undocumented features
« Reply #6 on: October 06, 2018, 01:00:12 AM »
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 ...
 

Charles Pegge

  • Guest
Re: Undocumented features
« Reply #7 on: October 06, 2018, 01:14:02 AM »
Quote
... (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:
Code: [Select]
  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

Charles Pegge

  • Guest
Re: Undocumented features
« Reply #8 on: October 06, 2018, 01:31:55 AM »
Quote
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.

José Roca

  • Guest
Re: Undocumented features
« Reply #9 on: October 06, 2018, 07:09:21 AM »
And we have to know all this without detailed documentation?

I will remove the "Basic" part from the name of the compiler.

Charles Pegge

  • Guest
Re: Undocumented features
« Reply #10 on: October 06, 2018, 07:31:17 AM »
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.

JRS

  • Guest
Re: Undocumented features
« Reply #11 on: October 06, 2018, 08:16:04 AM »
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.

Quote
And we have to know all this without detailed documentation?

If curiosity persists, the source to O2 is always available.
« Last Edit: October 06, 2018, 09:06:03 AM by John »

José Roca

  • Guest
Re: Undocumented features
« Reply #12 on: October 06, 2018, 08:43:12 AM »
Great advice for beginners.

JRS

  • Guest
Re: Undocumented features
« Reply #13 on: October 06, 2018, 09:09:06 AM »
If you think O2 is confusing, try learning JavaScript.

José Roca

  • Guest
Re: Undocumented features
« Reply #14 on: October 06, 2018, 09:17:20 AM »
I don't like scripting languages.