Dear Joachim, dear all,

when I had a similar problem, it turned
out to be caused by very long strings
in the source code.  If your generated
code contains strings, you could try
to use the result of
  import XCompiler(new) at ...
  define MyVirtualStringToValue = {XCompiler.new}
as a replacement for
  Compiler.virtualStringToValue
.  The XCompiler functor is attached.
I'm not exactly sure how bug-free it is,
but it should be useful and quite reliable.

If that doesn't help, I'd suggest
you try to find some specific cause
for the slowness and then implement
a similar workaround.  Or maybe writing
the source to a file (wrapped as a functor)
and running
  {OS.system "ozc ..."}
on it is faster?

Anyway, good luck,
Andreas


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
%%
%% speed improvement for Compiler.virtualStringToValue 
%%

functor
   
import
   Compiler
   
export
   new:        MakeCompiler
   newWithEnv: MakeCompilerWithEnv

   object:     CompilerObj
   
define

   fun {ReportError MsgA}
      raise
         error(compiler(evalExpression "<unknown>"
                        [error(items:nil kind:'lexical error' msg:MsgA)]))
      end
   end
   
   local   
      Hex = hex(&0: 0x0 &1: 0x1 &2: 0x2 &3: 0x3 &4: 0x4
                &5: 0x5 &6: 0x6 &7: 0x7 &8: 0x8 &9: 0x9
                &A: 0xA &B: 0xB &C: 0xC &D: 0xD &E: 0xE &F: 0xF
                &a: 0xA &b: 0xB &c: 0xC &d: 0xD &e: 0xE &f: 0xF)
   in
      fun {ReadString S ?Sr}
         case S of &"|Cr then Sr=Cr ""
         [] &\\|C1|Cr then
            case C1 of &a then &\a|{ReadString Cr ?Sr}
            [] &b then &\b|{ReadString Cr ?Sr}
            [] &f then &\f|{ReadString Cr ?Sr}
            [] &n then &\n|{ReadString Cr ?Sr}
            [] &r then &\r|{ReadString Cr ?Sr}
            [] &t then &\t|{ReadString Cr ?Sr}
            [] &v then &\v|{ReadString Cr ?Sr}
            [] &x then C2|C3|Crr = Cr C in
               C = Hex.C2 * 16 + Hex.C3
               if C == 0 then
                  {ReportError 'character in hexadecimal notation == 0'}
               else
                  C|{ReadString Crr ?Sr}
               end
            [] &\\ then &\\|{ReadString Cr ?Sr}
            [] &` then &`|{ReadString Cr ?Sr}
            [] &" then &"|{ReadString Cr ?Sr}
            [] &' then &'|{ReadString Cr ?Sr}
            else C2|C3|Crr = Cr C in   % must be an octal constant
               C = Hex.C1 * 64 + Hex.C2 * 8 + Hex.C3
               if C == 0 then
                  {ReportError 'character in octal notation == 0'}
               elseif C >= 256 then
                  {ReportError 'character in octal notation >= 256'}
               else
                  C|{ReadString Crr ?Sr}
               end
            end
         [] C|Cr then
            C|{ReadString Cr ?Sr}
         else Sr=nil ""
         end
      end
   end
   local
      fun {SkipAtom SIn Tl ?Begin} % and call FindString again at end-of-atom 
         case SIn of &'|Cr then &'|{FindString Cr Tl ?Begin}
         [] &\\|C|Cr then &\\|C|{SkipAtom Cr Tl ?Begin}
         [] C|Cr then C|{SkipAtom Cr Tl ?Begin}
         else {ReportError 'unterminated atom (?)'}
         end
      end
   in
      fun {FindString SIn Tl ?Begin}
         case SIn of &"|_ then Begin=SIn Tl
         [] &'|Cr then &'|{SkipAtom Cr Tl Begin}
         [] &&|C|Cr then &&|C|{FindString Cr Tl ?Begin}
         [] &\\|C|Cr then &\\|C|{FindString Cr Tl ?Begin}
         [] C|Cr then C|{FindString Cr Tl ?Begin}
         else Begin=nil Tl
         end
      end
   end
   
   DefaultPrefix='Q_yXz'
   DefaultSuffix=''
   
   class StringProcessor
      attr
         prefix
         suffix
         count
         strings
      meth init(prefix:Prefix<=DefaultPrefix
                suffix:Suffix<=DefaultSuffix)
         prefix  <- {VirtualString.toAtom Prefix}
         suffix  <- {VirtualString.toAtom Suffix}
         count   <- 0
         strings <- {NewDictionary}
      end
      meth Reset
         count <- 0
         {Dictionary.removeAll @strings}
      end
      meth NewVar($)
         [EMAIL PROTECTED] in
         count <- I
         {VirtualString.toAtom @[EMAIL PROTECTED]
      end
      meth SubstStrings(SIn ?SOut)
         Tl in
         case {FindString SIn Tl $ ?SOut} of nil then Tl=nil
         [] &"|S1 then
            Rest
            Str = {ReadString S1 ?Rest}
            Var = StringProcessor, NewVar($)
            {Dictionary.put @strings Var Str}
            NewTl
         in
            Tl = {Append {VirtualString.toString " "#Var#" "} NewTl}
            StringProcessor, SubstStrings(Rest ?NewTl)
         end
      end
      meth substStrings(SIn ?SOut env:?Env)
         StringProcessor, Reset
         StringProcessor, SubstStrings(SIn ?SOut)
         Env = {Dictionary.toRecord strings @strings}
      end
   end
   
   class CompilerObj from StringProcessor
      
      prop
         locking
         
      attr
         env:      env
         engine  
         interface
         
      meth init(env:Env<[EMAIL PROTECTED])
         lock
            Engine    = {New Compiler.engine init}
            Interface = {New Compiler.interface init(Engine)}
            RealEnv
         in
            {Engine enqueue(mergeEnv(Env))}
            {Engine enqueue(getEnv(?RealEnv))}
            {Engine enqueue(setSwitch(expression true))}
            {Engine enqueue(setSwitch(threadedqueries false))}
            {Wait RealEnv}
            env       <- RealEnv
            engine    <- Engine
            interface <- Interface
            StringProcessor, init
         end
      end
      
      meth compile(VS ?Result)
         lock
            S Env
            local
               SIn = {VirtualString.toString VS} in
               StringProcessor, substStrings(SIn ?S env:?Env)
            end
            Engine    = @engine
            Interface = @interface
         in
            {Engine enqueue(putEnv({Adjoin Env @env}))}
            {Engine enqueue(feedVirtualString(S return(result:?Result)))}
            {Interface sync}
            if {Interface hasErrors($)} then
               Messages = {Interface getMessages($)} in
               {Interface reset}
               {Exception.raiseError compiler(evalExpression VS Messages)}
            end
         end
      end
      
   end

   proc {MakeCompiler ?VS2V}
      C = {New CompilerObj init} in
      fun {VS2V VS} {C compile(VS $)} end
   end
   
   proc {MakeCompilerWithEnv Env ?VS2V}
      C = {New CompilerObj init(env:Env)} in
      fun {VS2V VS} {C compile(VS $)} end
   end
end

   




_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to