Author Topic: scope  (Read 7267 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
Re: scope
« Reply #15 on: July 08, 2014, 02:52:01 PM »
One potentially useful construct is a class that can be used without creating objects:

Such a class may contain methods and static variables, and these will be accessible, invoking the class by name:

Code: [Select]
class act
  method greet(string n) as string
  return "helo "+n
  end method
  method depart(string n) as string
  return "bye "+n
  end method
end class

class util
  method compile(string src) as sys
  sys a=compile src
  er=error
  if er then
    print er+src
    return 0
  else
    return a
  end if
  end method
end class

a=util.compile quote """ print act.greet "World" """
if a then call a

freememory a

PS:
The problem with the binary file (even when oxygen.dll is available) is that it does not carry any static symbolic data. So the dynamic compiler has no information about the classes.

Whereas under JIT compiling conditions, with gxo2/exo2, the static symbol data from primary compilation is retained, and made accessible to the dynamic compiler.

pber

  • Guest
Re: scope
« Reply #16 on: July 08, 2014, 03:21:36 PM »
Thanks again Charles.
Sorry for my annoying ignorance of your architecture.

Now I see if I want to make use of Oxygen's JIT compiler from a binary
I have to bind application's objects to newly compiled code.
For functions and variables using native datatypes no problem.

But types and classes?
Do their structure get forget, as well as of all other static symbols, or retained?

Charles Pegge

  • Guest
Re: scope
« Reply #17 on: July 08, 2014, 03:47:18 PM »
Yes, structures are also forgotten.

But it may be possible to modify Oxygen to retain selected symbols on-demand, for dynamic compiling purposes. I will need to think it through.

Charles Pegge

  • Guest
Re: scope
« Reply #18 on: July 09, 2014, 04:44:53 AM »
Paolo,

I have updated Oxygen to pass static symbol records to the binary:

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

This will now work:
Code: [Select]
#file       "t.exe"

class act
  method greet(string n) as string
  return "helo "+n
  end method
  method depart(string n) as string
  return "bye "+n
  end method
end class

class util
  method compile(string src) as sys
  sys a=compile src
  er=error
  if er then
    print er+src
    return 0
  else
    return a
  end if
  end method
end class

a=util.compile quote """ print act.greet "World" """
if a then call a

freememory a

Also with an instantiation of Act

Act AA

Code: [Select]
#file       "t.exe"

class act
  method greet(string n) as string
  return "helo "+n
  end method
  method depart(string n) as string
  return "bye "+n
  end method
end class

act AA

class util
  method compile(string src) as sys
  sys a=compile src
  er=error
  if er then
    print er+src
    return 0
  else
    return a
  end if
  end method
end class

a=util.compile quote """ print AA.greet "World" """
if a then call a

freememory a


pber

  • Guest
Re: scope
« Reply #19 on: July 09, 2014, 11:13:44 AM »
GREAT! Many thanks Charles.

...well: I didn't post immediately,
I wanted to try to see my program run as I expected...
I'm very frustrating on telling that no, it didn't.

Can I store the result of compile in an instance var,
for lately execute call on it?

I tryied to transform class util from your 2nd example.
Executing run causes a crash.

Code: [Select]
class util2
    sys a
    method compile(string src)
      a=compile src
      er=error
      if er then
        print er+src
      end if
  end method
  method run()
    call a
  end method
end class

Charles Pegge

  • Guest
Re: scope
« Reply #20 on: July 09, 2014, 12:55:34 PM »
The solution is rather obscure, but simple. When the dynamically compiled code uses strings, it requires string management from the parent function. To trigger string management.the parent function (run) must include a string, even if the string is never used.

This is new territory!

  method run()
  string v
  call a
  end method


Code: [Select]
class util2
    sys a
    method compile(string src) as sys
      a=compile src
      er=error
      if er then
        print er+src
      end if
      return a
  end method
  method run()
  string v
  call a
  end method
end class

util2 u
u.compile quote """ print "ok" 123 """
u.run

pber

  • Guest
Re: scope
« Reply #21 on: July 09, 2014, 01:23:02 PM »
It makes me simply happy.
Thanks Charles.