Author Topic: Explicit Type Conversion  (Read 2510 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
Explicit Type Conversion
« on: May 23, 2011, 08:06:49 AM »
This works with low level procedures. (which have no defined prototype)

Oxygen in-progress 23/May/2011

Code: [Select]

  '========================
  'EXPLICIT TYPE CONVERSION
  '========================

  'this can be used for procedure calls without prototypes


  function fs(single a, single b) external
  '---------------------------------------
  print b
  end function

  function fd(double a,double b) external
  '--------------------------------------
  print b
  end function



  'SETUP ANONYMOUS PROCEDURES BY USING A SYS VARIABLE AS A POINTER
  '===============================================================
  

  sys g

  g=@fd 'anonymIse
  call g double 1,double 5+2.5
  

  'implicit single with decimal point
  '==================================

  g=@fs 'anonymise
  call g 1.2, 15.25



  'explicit single
  '===============

  call g  single 1, single 10



Charles

« Last Edit: May 23, 2011, 08:09:57 AM by Charles Pegge »

JRS

  • Guest
Re: Explicit Type Conversion
« Reply #1 on: May 23, 2011, 09:33:16 PM »
Nice feature Charles!

Can the function contain optional arguments?

This feature reminds me of ICALL/ADDRESS in SB.

Charles Pegge

  • Guest
Re: Explicit Type Conversion
« Reply #2 on: May 23, 2011, 11:58:14 PM »
John,

The low level calls need an exact match of parameters with the callee function.

But it is easy to take the g value and create a function declaration from it. Then you have all the facilities of a high level function including optional parameters.

  sys g=@fun
  declare function f (v as sys, optional a as sys, b as sys) at g



Code: [Select]



'========================================
'OPTIONAL PARAMETERS + FUNCTION ADDRESSES
'========================================


  '-----------------------------------------------------------
  function fun(v as sys, optional a as sys, b as sys) external
  '===========================================================
  string opts
  '
  '
  'check to see if the address of b is null
  '
  if @a then
    opts+=" A = "+str(a)
  else
    opts+="  A is not specified  "
  end if

 if @b then
    opts+="  B = "+str(b)
  else
    opts+="  B is not specified  "
  end if

  '
  print "V = " str(v) chr(13) chr(10) opts
  '
  end function


  'SOME DATA
  '=========

  sys vv=42


  'GET FUNCTION ADDRESS
  '====================


  sys g=@fun

  'USE G TO CREATE A FUNCTION DECLARATION WITH A FULL PROTOTYPE
  '============================================================

  declare function f (v as sys, optional a as sys, b as sys) at g


  '======
  'TESTS:
  '======

  f vv          'A AND B NOT SPECIFIED
  f vv,123      'A SPECIFIED
  f vv,,456     'B SPECIFIED (A SET TO 0)
  f vv,123,456  'BOTH SPECIFIED


Charles