Author: hqm
Date: 2008-02-07 06:30:47 -0800 (Thu, 07 Feb 2008)
New Revision: 7976

Modified:
   openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LFCApplication.as
   openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/Library.lzs
   openlaszlo/branches/devildog/WEB-INF/lps/lfc/views/LaszloCanvas.js
   
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/compiler/CompilationEnvironment.java
   
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/compiler/Compiler.java
   
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/Compiler.java
   
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9Generator.java
   
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/servlets/responders/ResponderEVAL.java
   openlaszlo/branches/devildog/test/swf9/hello.lzx
Log:
Change 20080207-hqm-a by [EMAIL PROTECTED] on 2008-02-07 01:35:03 EST
    in /Users/hqm/openlaszlo/devildog
    for http://svn.openlaszlo.org/openlaszlo/branches/devildog

Summary:  a debugger eval implementation

New Features:

Bugs Fixed:

Technical Reviewer: dda
QA Reviewer: ptw
Doc Reviewer: (pending)

Documentation:

Release Notes:

Details:

To eval an expression, a new class is compiled,  whose constructor executes the 
expression, and 
prints the value to a crude text field console.

The new class is named DebugEvaluate, and it is a subclass of a stub base class 
named DebugExec, which
just defines a console print method for now. 

I modified SWF9Generator to emit the DebugEvaluate class instead of 
LzApplication, when the new
debugEval flag is passed in.
    

Tests:

hello.lzx, or any app. Type an expression in the pink input field, and see 
output in gray area



Modified: 
openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LFCApplication.as
===================================================================
--- openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LFCApplication.as  
2008-02-07 12:36:53 UTC (rev 7975)
+++ openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LFCApplication.as  
2008-02-07 14:30:47 UTC (rev 7976)
@@ -19,6 +19,9 @@
     import flash.events.*;
     import flash.utils.*;
     import flash.text.*;
+    import flash.system.*;
+    import flash.net.*;
+    import flash.ui.*;
     }#
 
 
@@ -53,17 +56,90 @@
         // cheapo debug console
         lzconsole = this;
         var tfield:TextField = new TextField();
+        tfield.background = true;
+        tfield.backgroundColor = 0xcccccc;
         tfield.x = 0;
-        tfield.y = 580;
-        tfield.width = 1000;
-        tfield.height = 20;
+        tfield.y = 400;
+        tfield.wordWrap = true;
+        tfield.multiline = true;
+        tfield.width = 800;
+        tfield.height = 100;
         tfield.border = true;
         consoletext = tfield;
+
+        var ci:TextField =  new TextField();
+        consoleinputtext = ci;
+        ci.background = true;
+        ci.backgroundColor = 0xffcccc;
+        ci.x = 0;
+        ci.y = 500;
+        ci.wordWrap = false;
+        ci.multiline = false;
+        ci.width = 800;
+        ci.height = 20;
+        ci.border = true;
+        ci.type = TextFieldType.INPUT;
+        ci.addEventListener(KeyboardEvent.KEY_DOWN, consoleInputHandler);
+
+        var newFormat:TextFormat = new TextFormat();
+        newFormat.size = 14;
+        newFormat.font = "sans-serif";
+        ci.setTextFormat(newFormat);
+        consoletext.setTextFormat(newFormat);
+
+        
+
         ////////////////////////////////////////////////////////////////
 
+
+        ////////////////////////////////////////////////////////////////
+        // Testing runtime code loading
+        ////////////////////////////////////////////////////////////////
+
     }
 
+    var debugloader:Loader;
 
+    // Debugger loader completion handler 
+    function debugEvalListener (e:Event):void {
+        trace("init dbg loader loaded, executing doit()");
+        debugloader.unload();
+        //DebugExec(e.target.content).doit();
+    }
+
+    function consoleInputHandler (event:KeyboardEvent ){
+        if (event.charCode == Keyboard.ENTER) {
+            var expr = consoleinputtext.text;
+            write(expr);
+            consoleinputtext.text = "";
+
+            debugloader = new Loader();
+            debugloader.contentLoaderInfo.addEventListener(Event.INIT, 
debugEvalListener);
+
+            // Send EVAL request to LPS server
+            var url = "hello.lzx?lzr=swf9&lz_load=false&lzt=eval&lz_script=" + 
encodeURIComponent(expr)+"&lzbc=" +(new Date()).getTime();
+            trace('requesting from '+url);
+            debugloader.load(new URLRequest(url),
+                             new LoaderContext(false,
+                                               new 
ApplicationDomain(ApplicationDomain.currentDomain)));
+        }
+    }
+
+
+    ////////////////////////////////////////////////////////////////
+    // A crude debugger output window for now
+    public var consoletext:TextField;
+    public var consoleinputtext:TextField;
+    
+    public function write (...args) {
+        consoletext.appendText( "\n" + args.join(","));
+        consoletext.scrollV = consoletext.maxScrollV;
+    }
+    ////////////////////////////////////////////////////////////////
+
+
+
+
       function reportWheel(event:MouseEvent):void
     {
         trace(event.currentTarget.toString() + 
@@ -100,17 +176,6 @@
         LzKeyboardKernel.__keyboardEvent(event.charCode, 'onkeydown');
     }
 
-    ////////////////////////////////////////////////////////////////
-    // A crude debugger output window for now
-    public var consoletext:TextField;
-    
-    public function write (msg:*) {
-        consoletext.text = msg;
-    }
-    ////////////////////////////////////////////////////////////////
-
-
-
         /**
          * __idleupdate is a callback function from LzIdleKernel.
          * Treat it as a static function (ie. Don't reference 'this')
@@ -135,3 +200,4 @@
 
 
 
+

Modified: openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/Library.lzs
===================================================================
--- openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/Library.lzs        
2008-02-07 12:36:53 UTC (rev 7975)
+++ openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/Library.lzs        
2008-02-07 14:30:47 UTC (rev 7976)
@@ -8,6 +8,9 @@
   * @subtopic AS2
   */
 
+// A class for loading and executing debug code at runtime
+#include "kernel/swf9/DebugExec.as"
+
 #include "kernel/swf9/LFCApplication.as"
 #include "kernel/swf9/LzIdleKernel.as"
 #include "kernel/swf9/LzSprite.as"

Modified: openlaszlo/branches/devildog/WEB-INF/lps/lfc/views/LaszloCanvas.js
===================================================================
--- openlaszlo/branches/devildog/WEB-INF/lps/lfc/views/LaszloCanvas.js  
2008-02-07 12:36:53 UTC (rev 7975)
+++ openlaszlo/branches/devildog/WEB-INF/lps/lfc/views/LaszloCanvas.js  
2008-02-07 14:30:47 UTC (rev 7976)
@@ -291,9 +291,9 @@
     trace("LzCanvas.init called");
 
     // cheapo debugger printing
-    var tf = lzconsole.consoletext;
-    sprite.addChild(tf);
-    lzconsole.write("elapsed time "+getTimer()+" msec");
+    sprite.addChild(lzconsole.consoletext);
+    sprite.addChild(lzconsole.consoleinputtext);
+    //lzconsole.write("elapsed time "+getTimer()+" msec");
 }
 
 /**

Modified: 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/compiler/CompilationEnvironment.java
===================================================================
--- 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/compiler/CompilationEnvironment.java
     2008-02-07 12:36:53 UTC (rev 7975)
+++ 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/compiler/CompilationEnvironment.java
     2008-02-07 14:30:47 UTC (rev 7976)
@@ -3,7 +3,7 @@
 * ****************************************************************************/
 
 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
-* Copyright 2001-2007 Laszlo Systems, Inc.  All Rights Reserved.              *
+* Copyright 2001-2008 Laszlo Systems, Inc.  All Rights Reserved.              *
 * Use is subject to license terms.                                            *
 * J_LZ_COPYRIGHT_END *********************************************************/
 
@@ -30,6 +30,7 @@
     public static final String RUNTIME_PROPERTY = "runtime";
     public static final String PROXIED_PROPERTY           = "lzproxied";
     public static final String DEBUG_PROPERTY             = "debug";
+    public static final String DEBUG_EVAL_PROPERTY        = "debugEval";
 
     // matches the value of sc.Compiler.DEBUG_BACKTRACE
     public static final String BACKTRACE_PROPERTY         = "debugBacktrace";

Modified: 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/compiler/Compiler.java
===================================================================
--- 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/compiler/Compiler.java
   2008-02-07 12:36:53 UTC (rev 7975)
+++ 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/compiler/Compiler.java
   2008-02-07 14:30:47 UTC (rev 7976)
@@ -544,7 +544,60 @@
     }
 
 
+    public void compileAndWriteToSWF9 (String script, String seqnum, 
OutputStream out) {
+        try {
+            Properties props = new Properties();
+            props.setProperty(CompilationEnvironment.RUNTIME_PROPERTY, "swf9");
+            props.setProperty("canvasWidth", "1000");
+            props.setProperty("canvasHeight", "600");
+            Map compileTimeConstants = new HashMap();
+            compileTimeConstants.put("$debug", new Boolean(false));
+            compileTimeConstants.put("$profile", new Boolean(false));
+            compileTimeConstants.put("$backtrace", new Boolean(false));
+            compileTimeConstants.put("$runtime", "swf9");
+            compileTimeConstants.put("$swf7", Boolean.valueOf(false));
+            compileTimeConstants.put("$swf8", Boolean.valueOf(false));
+            compileTimeConstants.put("$as2", Boolean.valueOf(false));
+            compileTimeConstants.put("$swf9", Boolean.valueOf(true));
+            compileTimeConstants.put("$as3", Boolean.valueOf(true));
+            compileTimeConstants.put("$dhtml", Boolean.valueOf(false));
+            compileTimeConstants.put("$j2me", Boolean.valueOf(false));
+            compileTimeConstants.put("$svg", Boolean.valueOf(false));
+            compileTimeConstants.put("$js1", Boolean.valueOf(false));
+            props.put("compileTimeConstants", compileTimeConstants);
+            props.setProperty(CompilationEnvironment.DEBUG_EVAL_PROPERTY, 
"true");
+            byte[] objcode;
+            String prog;
 
+
+            // Try compiling as an expression first.  If that fails,
+            // compile as sequence of statements.  If that fails too,
+            // report the parse error.
+            try {
+                prog = "(function () {lzconsole.write("+script +")})();";
+                objcode = ScriptCompiler.compileToByteArray(prog, props);
+            } catch (org.openlaszlo.sc.parser.ParseException e) {
+                try {
+                    prog = "var mycode = (function () {\n"+script 
+"\n});\n"+"mycode();\n";
+                    objcode = ScriptCompiler.compileToByteArray(prog, props);
+                } catch (org.openlaszlo.sc.parser.ParseException e2) {
+                    mLogger.info("error compiling/writing script: " + 
e2.getMessage());
+                    objcode = ScriptCompiler.compileToByteArray(
+                        "lzconsole.write(" + ScriptCompiler.quote("Parse 
error: "+ e2.getMessage()) + ")",
+                        props);
+                }
+            }
+
+            int total = FileUtils.sendToStream(new 
ByteArrayInputStream(objcode), out);
+            out.flush();
+            out.close();
+        } catch (IOException e) {
+            mLogger.info("error compiling/writing script: " + script);
+        }
+    }
+
+
+
     static ElementCompiler getElementCompiler(Element element,
                                               CompilationEnvironment env) {
         if (CanvasCompiler.isElement(element)) {

Modified: 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/Compiler.java
===================================================================
--- 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/Compiler.java
 2008-02-07 12:36:53 UTC (rev 7975)
+++ 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/Compiler.java
 2008-02-07 14:30:47 UTC (rev 7976)
@@ -410,6 +410,7 @@
   public static String DEBUG = "debug";
   public static String DEBUG_BACKTRACE = "debugBacktrace";
   public static String DEBUG_SIMPLE = "debugSimple";
+  public static String DEBUG_EVAL = "debugEval";
   public static String DISABLE_CONSTANT_POOL = "disableConstantPool";
   public static String ELIMINATE_DEAD_EXPRESSIONS = "eliminateDeadExpressions";
   public static String FLASH_COMPILER_COMPATABILITY = 
"flashCompilerCompatability";

Modified: 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9Generator.java
===================================================================
--- 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9Generator.java
    2008-02-07 12:36:53 UTC (rev 7975)
+++ 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9Generator.java
    2008-02-07 14:30:47 UTC (rev 7976)
@@ -46,6 +46,10 @@
   /** The LFC 'main' class, which extends nothing */
   public final static String MAIN_LIB_CLASSNAME = "LFCApplication";
 
+  /** The class to use when compiling a debug eval statement */
+  public final static String DEBUG_EVAL_SUPERCLASS = "DebugExec";
+  public final static String DEBUG_EVAL_CLASSNAME  = "DebugEvaluate";
+
   /** The first part of a every emitted javascript file */
   public static final String DEFAULT_FILE_PREAMBLE = "package {\n";
 
@@ -238,8 +242,13 @@
     // initialization, and currently there is no default one.
     // We'll add one here, doing it later adds too many special cases.
     if (!options.getBoolean(Compiler.BUILD_SHARED_LIBRARY)) {
-      source += "public class " + SWF9Generator.MAIN_APP_CLASSNAME +
-        " extends " +  SWF9Generator.MAIN_LIB_CLASSNAME + " {}\n";
+      if (options.getBoolean(Compiler.DEBUG_EVAL)) {
+        source += "public class " + SWF9Generator.DEBUG_EVAL_CLASSNAME +
+          " extends " +  SWF9Generator.DEBUG_EVAL_SUPERCLASS + " {}\n";
+      } else {
+        source += "public class " + SWF9Generator.MAIN_APP_CLASSNAME +
+          " extends " +  SWF9Generator.MAIN_LIB_CLASSNAME + " {}\n";
+      }
     }
     return source;
   }
@@ -321,9 +330,15 @@
   public List makeTranslationUnits(SimpleNode translatedNode, boolean 
compress, boolean obfuscate)
   {
     boolean buildSharedLibrary = 
options.getBoolean(Compiler.BUILD_SHARED_LIBRARY);
-    String mainClass = buildSharedLibrary ?
-      SWF9Generator.MAIN_LIB_CLASSNAME : SWF9Generator.MAIN_APP_CLASSNAME;
+    boolean debugEval = options.getBoolean(Compiler.DEBUG_EVAL);
 
+    String mainClass;
+    if (buildSharedLibrary) {
+      mainClass = SWF9Generator.MAIN_LIB_CLASSNAME;
+    } else {
+      mainClass = debugEval ? SWF9Generator.DEBUG_EVAL_CLASSNAME : 
SWF9Generator.MAIN_APP_CLASSNAME;
+    }
+
     return (new SWF9ParseTreePrinter(compress, obfuscate, mainClass, 
buildSharedLibrary)).makeTranslationUnits(translatedNode);
   }
 

Modified: 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/servlets/responders/ResponderEVAL.java
===================================================================
--- 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/servlets/responders/ResponderEVAL.java
   2008-02-07 12:36:53 UTC (rev 7975)
+++ 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/servlets/responders/ResponderEVAL.java
   2008-02-07 14:30:47 UTC (rev 7976)
@@ -3,7 +3,7 @@
  * 
****************************************************************************/
 
 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
-* Copyright 2001-2004 Laszlo Systems, Inc.  All Rights Reserved.              *
+* Copyright 2001-2004, 2008 Laszlo Systems, Inc.  All Rights Reserved.         
     *
 * Use is subject to license terms.                                            *
 * J_LZ_COPYRIGHT_END *********************************************************/
 
@@ -68,12 +68,11 @@
                 res.setContentType(MimeType.SWF);
                 Compiler compiler = new Compiler();
                 String swfversion = req.getParameter("lzr");
-                // For back compatibility, should an older app that doesn't 
pass "lzr" arg
-                // be running somehow.
-                if (swfversion == null) {
-                    swfversion = "swf6";
+                if ("swf9".equals(swfversion)) {
+                    compiler.compileAndWriteToSWF9(script, seqnum, out);
+                } else {
+                    compiler.compileAndWriteToSWF(script, seqnum, out, 
swfversion);
                 }
-                compiler.compileAndWriteToSWF(script, seqnum, out, swfversion);
             } catch (Exception e) {
                 mLogger.info(
 /* (non-Javadoc)

Modified: openlaszlo/branches/devildog/test/swf9/hello.lzx
===================================================================
--- openlaszlo/branches/devildog/test/swf9/hello.lzx    2008-02-07 12:36:53 UTC 
(rev 7975)
+++ openlaszlo/branches/devildog/test/swf9/hello.lzx    2008-02-07 14:30:47 UTC 
(rev 7976)
@@ -1,4 +1,4 @@
-<canvas width="1000" height="600"> 
+<canvas width="1000" height="800"> 
   <!--    <text bgcolor="#ccffcc">Hello OpenLaszlo!</text> -->
   <text oninit="this.setText('runtime='+canvas.runtime)"/>
 
@@ -38,7 +38,7 @@
 
 
 
-  <view id="bar" x="100" y="200" >
+  <view name="bar" x="100" y="200" >
     <view id="foo" bgcolor="0xcccccc" x="-100" y="-100"  height="200" 
width="200"
           onclick="this.parent.animate('rotation', 90, 1000, true)" >
 


_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins

Reply via email to