Author Topic: Classes in child macros  (Read 449 times)

0 Members and 1 Guest are viewing this topic.

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 513
    • PluriBASIC
Classes in child macros
« on: December 06, 2018, 10:03:36 PM »

 I noticed that, while this compiles and works fine:

Code: [Select]
'Generated with PluriBASIC 6.0.74371.0

$ filename "classes_on_macros.exe"

uses rtl32

class _newclass
    public sys h
    method constructor(int s)
        h = getmemory(s)
        print h       
    end method
    method destructor()
        freememory(h)
    end method
    function hPtr() as sys
        print h
        return h
    end function       
end class

MACRO ELEMENT_INIT(src, trg)
   
    int i = sizeof(trg)
    new _newclass buf(i)
    src = buf.hPtr()       

END MACRO

FUNCTION PBMAIN() AS INT
   INT myvar
   INT target
    ELEMENT_INIT(myvar, target)
END FUNCTION

PBMAIN() ' invoke entry point

This does not compile:

Code: [Select]
'Generated with PluriBASIC 6.0.74371.0

$ filename "classes_on_macros.exe"

uses rtl32

class _newclass
    public sys h
    method constructor(int s)
        h = getmemory(s)
        print h       
    end method
    method destructor()
        freememory(h)
    end method
    function hPtr() as sys
        print h
        return h
    end function       
end class

MACRO ELEMENT_INIT(src, trg)
    MACRO .readyup(src, trg  buf, i, h)
        int i = sizeof(trg)
        new _newclass buf(i)
        src = buf.hPtr()
    END MACRO
END MACRO

FUNCTION PBMAIN() AS INT
   INT myvar
   INT target
   ELEMENT_INIT.readyup(myvar, target)
END FUNCTION

PBMAIN() ' invoke entry point

It seems like when it is inside a child macro, the code does not recognize the class function hPtr().

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 513
    • PluriBASIC
Re: Classes in child macros
« Reply #1 on: December 06, 2018, 10:07:21 PM »
  By the way, i went away and implemented the child macros in PluriBASIC, and they work fine with Oxygen now.

 However, i need to compile some child macros in raw Oxygen code, because i am changing the way the engine
clears variants when out of scope, to make use of the internal garbage collector instead of making my own.

 No rush though. I know you are busy Charles. :)

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4205
    • Oxygen Basic
Re: Classes in child macros
« Reply #2 on: December 08, 2018, 01:24:07 PM »
Brian,

With the new o2, destructors are automatically invoked when objects go out of scope. (This does not apply to virtual objects created with 'new'). All you have to do is provide a destructor for the class.

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 513
    • PluriBASIC
Re: Classes in child macros
« Reply #3 on: December 08, 2018, 07:31:14 PM »
 Thanks charles.

 In this update can i create and use class objects in a child macro?

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4205
    • Oxygen Basic
Re: Classes in child macros
« Reply #4 on: December 09, 2018, 07:01:20 PM »
Brian,

I found one problem with macro members. If you put a space between the macro name and the left bracket, this should make it locatable. but I will sort out this problem in the next few hours.