[Laszlo-checkins] r3893 - openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc
ptw@openlaszlo.org
ptw at openlaszlo.org
Thu Feb 22 15:33:15 PST 2007
Author: ptw
Date: 2007-02-22 15:33:12 -0800 (Thu, 22 Feb 2007)
New Revision: 3893
Modified:
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/Actions.java
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/Assembler.java
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/CodeGenerator.java
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/Instructions.java
Log:
Change 20070210-ptw-k by ptw at dueling-banjos.local on 2007-02-10 17:19:44 EST
in /Users/ptw/OpenLaszlo/3.4
Summary: svn merge -r 3748:3749 http://svn.openlaszlo.org/openlaszlo/branches/legals
Bugs Fixed:
LPP-2366: 'Fix SWF compiler forward branch bug that keeps appearing'
LPP-NaN: 'Unknown getURL2 flag: 0x11'
LPP-NaN: 'FSCommand2. This is a new opcode in FL2 (Flash Lite 2) that is used for all mobile-specific functionality.'
Technical Reviewer: jgrandy (verbal)
QA Reviewer: mamye (pending)
Doc Reviewer: n/a
Tests:
smokecheck
LFC's flasm without error
Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/Actions.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/Actions.java 2007-02-22 23:21:46 UTC (rev 3892)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/Actions.java 2007-02-22 23:33:12 UTC (rev 3893)
@@ -3,7 +3,7 @@
*/
/* J_LZ_COPYRIGHT_BEGIN *******************************************************
-* Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
+* Copyright 2001-2007 Laszlo Systems, Inc. All Rights Reserved. *
* Use is subject to license terms. *
* J_LZ_COPYRIGHT_END *********************************************************/
@@ -174,7 +174,7 @@
public static Action WaitForFrameExpression = new Action("WaitForFrameExpression", (byte)0x8D);
public static Action PUSH = new Action("PUSH", (byte)0x96, 0, 1);
public static Action BRANCH = new Action("BRANCH", (byte)0x99);
- public static Action GetURL2 = new Action("GetURL2", (byte)0x9A, 2, 0, false);
+ public static Action GetURL2 = new Action("GetURL2", (byte)0x9A, 2, 0);
public static Action BranchIfTrue = new Action("BranchIfTrue", (byte)0x9D);
public static Action CallFrame = new Action("CallFrame", (byte)0x9E);
public static Action GotoExpression = new Action("GotoExpression", (byte)0x9F);
@@ -237,4 +237,9 @@
public static Action DefineFunction2 = new Action("DefineFunction2", (byte)0x8e);
public static Action TRY = new Action("TRY", (byte)0x8f);
public static Action THROW = new Action("THROW", (byte)0x2a);
+
+ /*
+ * Flash Lite 2
+ */
+ public static Action FSCommand2 = new Action("FsCommand2", (byte)0x2d);
}
Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/Assembler.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/Assembler.java 2007-02-22 23:21:46 UTC (rev 3892)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/Assembler.java 2007-02-22 23:33:12 UTC (rev 3893)
@@ -60,14 +60,15 @@
}
public boolean isResolved() {
- return this.location != -1;
+ return location != -1;
}
public void setLocation(ByteBuffer bytes) {
- assert (! this.isResolved()) : "Label.setLocation() called on resolved label";
- this.location = bytes.position();
+ assert (! isResolved()) : "Label.setLocation() called on resolved label";
+ assert bytes.order() == ByteOrder.LITTLE_ENDIAN;
+ location = bytes.position();
// Backpatch forward jumps
- for (Iterator i = this.references.iterator(); i.hasNext(); ) {
+ for (Iterator i = references.iterator(); i.hasNext(); ) {
int patchloc = ((Integer)i.next()).intValue();
int offset = location - patchloc - 2;
if (offset < MIN_OFFSET() || offset > MAX_OFFSET()) {
@@ -76,11 +77,12 @@
}
bytes.putShort(patchloc, (short)offset);
}
- this.references = null;
+ references = null;
}
public short computeOffset(ByteBuffer bytes) {
- assert (this.isResolved()) : "Label.computeOffset() called on unresolved label";
+ assert (isResolved()) : "Label.computeOffset() called on unresolved label";
+ assert bytes.order() == ByteOrder.LITTLE_ENDIAN;
int offset = location - bytes.position();
if (offset < MIN_OFFSET() || offset > MAX_OFFSET()) {
throw new CompilerException((this instanceof Block?"Block":"Label") + " " +
@@ -90,12 +92,12 @@
}
public void addReference(int patchloc) {
- assert (! this.isResolved()) : "adding reference to resolved label";
- this.references.add(new Integer(patchloc));
+ assert (! isResolved()) : "adding reference to resolved label";
+ references.add(new Integer(patchloc));
}
public String toString() {
- return this.name.toString();
+ return name.toString();
}
}
@@ -125,54 +127,55 @@
byte[] bs = getBacking();
if (bs != null) {
this.bytes = ByteBuffer.wrap(bs);
+ bytes.order(ByteOrder.LITTLE_ENDIAN);
} else {
// Room to not grow immediately. See emit.
this.bytes = ByteBuffer.allocate((1<<14) + (1<<16));
+ bytes.order(ByteOrder.LITTLE_ENDIAN);
}
this.constants = new Hashtable(); // {String -> int}
}
public byte[] assemble(List instrs) {
for (Iterator i = instrs.iterator(); i.hasNext(); ) {
- this.emit((Instruction)i.next());
+ emit((Instruction)i.next());
}
List unresolvedLabels = new ArrayList();
// One wonders why this couldn't be an Iterator
- for (Enumeration i = this.labels.elements(); i.hasMoreElements(); ) {
+ for (Enumeration i = labels.elements(); i.hasMoreElements(); ) {
Label label = (Label)i.nextElement();
if (! label.isResolved()) {
unresolvedLabels.add(label);
}
}
- //System.out.println("assembled: " + this.bytes.toString());
+ //System.out.println("assembled: " + bytes.toString());
assert (unresolvedLabels.size() == 0) : "unresolved labels: " + unresolvedLabels;
// TODO [2004-03-04 ptw] be more efficient than this!
- byte[] result = new byte[this.bytes.position()];
- this.bytes.flip();
- this.bytes.get(result);
+ byte[] result = new byte[bytes.position()];
+ bytes.flip();
+ bytes.get(result);
// Save the backing buffer
setBacking(bytes.array());
return result;
}
public Label getLabel(Object name, boolean signed) {
- if (! this.labels.containsKey(name)) {
+ if (! labels.containsKey(name)) {
if (signed) {
- this.labels.put(name, new Label(name));
+ labels.put(name, new Label(name));
} else {
- this.labels.put(name, new Block(name));
+ labels.put(name, new Block(name));
}
}
- return (Label)this.labels.get(name);
+ return (Label)labels.get(name);
}
public void emit(Instruction instr) {
// Verify there is room for a maximal instruction (1<<16)
- // TODO: [2004-08-02 ptw] 1<<16 does not work. Why?
- // As a temporary kludge, double that.
- if (! (bytes.remaining() > 1<<19)) {
+ if (! (bytes.remaining() > 1<<16)) {
// TODO [2004-03-11 ptw] Spool to file above a certain size
ByteBuffer newBytes = ByteBuffer.allocate(bytes.capacity() * 2);
+ newBytes.order(ByteOrder.LITTLE_ENDIAN);
ByteBuffer oldBytes = bytes;
bytes.flip();
newBytes.put(bytes);
@@ -184,36 +187,37 @@
this.constants = new Hashtable();
for (ListIterator i = ((ConcreteInstruction)instr).args.listIterator(); i.hasNext(); ) {
int index = i.nextIndex();
- this.constants.put(i.next(), new Integer(index));
+ constants.put(i.next(), new Integer(index));
}
// Fall through to the general case
}
if (instr instanceof LABELInstruction) {
Object name = ((LABELInstruction)instr).name;
- Label label = this.getLabel(name, true);
+ Label label = getLabel(name, true);
assert (! label.isResolved()) : "duplicate label" + label;
// Get the current location, and save it for backjumps
label.setLocation(bytes);
} else if (instr instanceof TargetInstruction) {
TargetInstruction target = (TargetInstruction)instr;
- Label label = this.getLabel(target.getTarget(), instr instanceof BranchInstruction);
+ Label label = getLabel(target.getTarget(), instr instanceof BranchInstruction);
int loc = label.location;
if (loc == -1) {
// Target location isn't yet available. Use a null
// offset, and add the address to be patched to this
// label's list of backpatch locations.
- target.writeBytes(this.bytes, this.constants);
+ target.writeBytes(bytes, constants);
int patchloc = bytes.position() - 2;
label.addReference(patchloc);
} else {
// Target computation requires that we write the instruction first!
target.targetOffset = 0;
- target.writeBytes(this.bytes, this.constants);
+ target.writeBytes(bytes, constants);
short offset = label.computeOffset(bytes);
+ assert bytes.order() == ByteOrder.LITTLE_ENDIAN;
bytes.putShort(bytes.position() - 2, offset);
}
} else {
- instr.writeBytes(this.bytes, this.constants);
+ instr.writeBytes(bytes, constants);
}
}
}
Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/CodeGenerator.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/CodeGenerator.java 2007-02-22 23:21:46 UTC (rev 3892)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/CodeGenerator.java 2007-02-22 23:33:12 UTC (rev 3893)
@@ -1836,9 +1836,14 @@
assert v instanceof String;
collector.push("FSCommand:" + v);
visitExpression(args[1]);
- collector.emit(Instructions.GetURL2);
+ collector.emit(Instructions.GetURL2.make(0));
return true;
}
+ if ("FSCommand2".equals(name)) {
+ visitCallParameters(node, isReferenced, args);
+ collector.emit(Instructions.FSCommand2);
+ return true;
+ }
if ("removeMovieClip".equals(name) && arglen == 1) {
visitExpression(args[0]);
collector.emit(Instructions.RemoveClip);
@@ -1859,7 +1864,7 @@
// it could visit them in reverse order if they don't
// have side effects, otherwise emit SWAP.
//- if "getURL".equals(name) && arglen == 2:
- //- collector.emit(Instructions.GetURL2); return
+ //- collector.emit(Instructions.GetURL2.make(0)); return
if ("getVersion".equals(name) && arglen == 0) {
collector.push("/:$version");
collector.emit(Instructions.GetVariable);
Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/Instructions.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/Instructions.java 2007-02-22 23:21:46 UTC (rev 3892)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/Instructions.java 2007-02-22 23:33:12 UTC (rev 3893)
@@ -1,4 +1,4 @@
-/* -*- mode: JDE; c-basic-offset: 2; -*- */
+/* -*- mode: java; c-basic-offset: 2; -*- */
/***
* Instructions.java
@@ -7,7 +7,7 @@
*/
/* J_LZ_COPYRIGHT_BEGIN *******************************************************
-* Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
+* Copyright 2001-2007 Laszlo Systems, Inc. All Rights Reserved. *
* Use is subject to license terms. *
* J_LZ_COPYRIGHT_END *********************************************************/
@@ -341,7 +341,6 @@
* against constants.
*/
public void writeBytes(ByteBuffer bytes, Map constants) {
- bytes.order(ByteOrder.LITTLE_ENDIAN);
assert bytes.order() == ByteOrder.LITTLE_ENDIAN;
bytes.put(this.op.opcode);
// Flash has two types of instructions: single-byte instructions,
@@ -406,6 +405,14 @@
);
}
bytes.put(regno.byteValue());
+ } else if (op == Actions.GetURL2) {
+ Integer flags = ((Integer)args.get(0));
+ if (flags.intValue() != flags.byteValue()) {
+ throw new CompilerException("Invalid FLAGS for GetURL2");
+ }
+ bytes.put(flags.byteValue());
+ // TODO: [2007-02-08 ptw] Are there more args? The variables
+ // to send?
} else {
throw new CompilerException(
/* (non-Javadoc)
@@ -432,7 +439,7 @@
assert false : "this can't happen";
}
return b;
- } else if (op == Actions.SetRegister) {
+ } else if (op == Actions.SetRegister || op == Actions.GetURL2) {
return 1;
} else {
return 0;
@@ -483,6 +490,7 @@
}
public void writeArgs(ByteBuffer bytes, Map pool) {
+ assert bytes.order() == ByteOrder.LITTLE_ENDIAN;
bytes.putShort(this.targetOffset);
}
@@ -564,6 +572,7 @@
}
public void writeArgs(ByteBuffer bytes, Map pool) {
+ assert bytes.order() == ByteOrder.LITTLE_ENDIAN;
try {
List args = this.args;
String fname = (String)args.get(1);
@@ -660,6 +669,7 @@
}
public void writeArgs(ByteBuffer bytes, Map pool) {
+ assert bytes.order() == ByteOrder.LITTLE_ENDIAN;
try {
List args = this.args;
String fname = (String)args.get(1);
@@ -893,6 +903,7 @@
}
public void writeArgs(ByteBuffer bytes, Map constants) {
+ assert bytes.order() == ByteOrder.LITTLE_ENDIAN;
try {
for (Iterator i = this.args.iterator(); i.hasNext(); ) {
Object o = i.next();
@@ -1008,6 +1019,7 @@
}
public void writeBytes(ByteBuffer bytes, Map constants) {
+ assert bytes.order() == ByteOrder.LITTLE_ENDIAN;
;
}
@@ -1116,6 +1128,7 @@
}
public void writeBytes(ByteBuffer bytes, Map constants) {
+ assert bytes.order() == ByteOrder.LITTLE_ENDIAN;
System.out.println(super.toString() + "\t" + bytes.position());
}
}
@@ -1134,6 +1147,7 @@
}
public void writeBytes(ByteBuffer bytes, Map constants) {
+ assert bytes.order() == ByteOrder.LITTLE_ENDIAN;
bytes.put(this.blob);
}
@@ -1252,6 +1266,9 @@
// Flash 7
public static Instruction DefineFunction2 = Instruction.curry(Actions.DefineFunction2);
+ // Flash Lite 2
+ public static Instruction FSCommand2 = Instruction.curry(Actions.FSCommand2);
+
// Psuedo-instructions
public static Instruction BranchIfFalse = new BranchIfFalseInstruction("");
public static Instruction LABEL = new LABELInstruction("");
More information about the Laszlo-checkins
mailing list