This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

static modules and local vars


I have doubts concerning static modules and thread safety:

are local (inner-scope) variables in a static module
transformed (after compilation) to static class variables ?

The following code tries to show an example:

kawa code:
--------------------------------------------------------------------

(module-name   "m")
(module-static #t)
(module-export f)

(define (f x)
  (let ((y x))
    (+ 1 y)))

is compiled to:
---------------------------------------------------------------

Compiled from "m.scm"
public class m extends gnu.expr.ModuleBody{
public static final gnu.expr.ModuleMethod f;

static final m $instance;

static final gnu.math.IntNum Lit0; // * NOTICE THIS *
NOTICE THIS * NOTICE THIS *

public int numArgs();
  Code:
   0:   iconst_0
   1:   ireturn

public final void apply(gnu.mapping.CallContext);
  Code:
   0:   aload_1
   1:   getfield        #12; //Field
gnu/mapping/CallContext.consumer:Lgnu/lists/Consumer;
   4:   astore_2
   5:   return

public static java.lang.Object f(java.lang.Object);
  Code:
   0:   aload_0
   1:   astore_1
   2:   getstatic       #18; //Field
gnu/kawa/functions/AddOp.$Pl:Lgnu/kawa/functions/AddOp;
   5:   getstatic       #24; //Field Lit0:Lgnu/math/IntNum;
   8:   aload_1
   9:   invokevirtual   #30; //Method
gnu/mapping/Procedure.apply2:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
   12:  areturn

public m();
  Code:
   0:   aload_0
   1:   invokespecial   #6; //Method
gnu/expr/ModuleBody."<init>":()V
   4:   return

public static {};
  Code:
   0:   new     #20; //class m
   3:   dup
   4:   invokespecial   #31; //Method "<init>":()V
   7:   putstatic       #35; //Field $instance:Lm;
   10:  invokestatic    #38; //Method $literals$:()V
   13:  new     #40; //class ModuleMethod
   16:  dup
   17:  getstatic       #35; //Field $instance:Lm;
   20:  iconst_1
   21:  ldc     #42; //String f
   23:  sipush  4097
   26:  invokespecial   #45; //Method
gnu/expr/ModuleMethod."<init>":(Lgnu/expr/ModuleBody;ILjava/lang/Object;I)V
   29:  putstatic       #48; //Field
f:Lgnu/expr/ModuleMethod;
   32:  getstatic       #35; //Field $instance:Lm;
   35:  invokestatic    #52; //Method
gnu/mapping/CallContext.getInstance:()Lgnu/mapping/CallContext;
   38:  invokevirtual   #56; //Method
apply:(Lgnu/mapping/CallContext;)V
   41:  return

public java.lang.Object
apply1(gnu.expr.ModuleMethod,java.lang.Object);
  Code:
   0:   aload_1
   1:   getfield        #60; //Field
gnu/expr/ModuleMethod.selector:I
   4:   goto    19
   7:   aload_2
   8:   invokestatic    #63; //Method
f:(Ljava/lang/Object;)Ljava/lang/Object;
   11:  areturn
   12:  aload_0
   13:  aload_1
   14:  aload_2
   15:  invokespecial   #67; //Method
gnu/expr/ModuleBody.apply1:(Lgnu/expr/ModuleMethod;Ljava/lang/Object;)Ljava/lang/Object;
   18:  areturn
   19:  iconst_1
   20:  if_icmpeq       7
   23:  goto    12

}

-------------------------------------------------------------------------------

So is the "y" in the "let" transformed to static class
var "Lit0" ? If not I imagine it would be much better if
"y" was trasformed to a local var in method "f". In case
"y" is "Lit0" f is not thread-safe is it ?



 
__________________________________________________________________________
Acabe com aquelas janelinhas que pulam na sua tela.
AntiPop-up UOL - É grátis!
http://antipopup.uol.com.br/



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]