aboutsummaryrefslogtreecommitdiffstats
path: root/qv4codegen.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Fix break without identifier in labelled loopSimon Hausmann2013-01-041-0/+1
| | | | | | | | | | Make sure to do leaveLoop() after enterLoop() when processing labelled statements. Fixes hang in ch12/12.8/S12.8_A3 Change-Id: Iee96ea515524e9ea879f7528dc43e552b1343020 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Produce a syntax error when a break appears outside of an iterationSimon Hausmann2013-01-041-1/+3
| | | | | | | Fixes expected failure of ch12/12.8/S12.8_A1_T2 and others Change-Id: I261d649f6a29bbd6debfca35e7ccaf1a0a7006b9 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Fix hang in do-while loops with continue statement in the bodySimon Hausmann2013-01-041-1/+7
| | | | | | | | | | | | | | | | | | | | The construct do { ... continue; } while (condition) Would result in the body basic block ending with a jump to the loop body, causing an infinite loop. Instead we have to place the condition into an extra block and set that one as the target for continue. This is also covered by ch12/12.14/S12.14_A9_T2, which uses such a loop. Change-Id: If06de112b338b74b9a49e3d6b51078463645196d Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Set data properties using __defineOwnProperties__Lars Knoll2013-01-041-11/+22
| | | | | | | | | | | | Properties in object literals are defined using defineOwnProperty, so that they get set even if the object prototype contains a non writable property with the same name. This fixes all remaining test cases for 11.1.5 Change-Id: I3928a144d09c51c5bf20a25bcb1c6c3c243975ee Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Throw syntax errors with duplicated values in Object literalsLars Knoll2013-01-041-25/+41
| | | | | | | | | Object literals can only contain duplicated values for data properties in non strict mode. In all other cases throw a syntax error. Change-Id: Icb06ba1c343daffdb6a0532a08f7b9ae027e4e45 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Correctly size arrays with trailing elisionsLars Knoll2013-01-041-2/+5
| | | | | Change-Id: Iae09ec815e3307615299bf97741716b3671c9560 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Implement { get/set ... }Lars Knoll2013-01-031-1/+40
| | | | | | | | Implement support for defining accessor properties through { ... }. Implementation for moth is pending. Change-Id: I558b6811bc5656dc0fae78c49e23155043ce9cb1 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Fix liveness analyses for hidden exception handling TEMPs.Erik Verbruggen2012-12-181-5/+15
| | | | | | | | | By passing the inCatch/hasException temps to builtin_delete_exception_handler, the TEMPs are marked as alive all through the exception handling block. Change-Id: Ib0f17059e04c03ca98d264759bb2a7e4786ed9be Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Added check for formal parameter names in strict mode.Erik Verbruggen2012-12-181-31/+57
| | | | | | | Also fixed up other error messages. Change-Id: I26bfab761ab6a8ced3755a8e3dfbc42d428194e3 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Fix compilation after changes in the QML parser.Erik Verbruggen2012-12-181-1/+13
| | | | | Change-Id: I5c6903446a252139fde4ce180f6c01a5eff85406 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* ensure correct initialization order for local variablesLars Knoll2012-12-181-32/+36
| | | | | | | | | | | | | | | section 10.5 requires that function definitions get initialized at the beginning of the method. variable declarations do not override the function definitions. assignments to variables happen when they appear in the source code. Also remove a duplicated intializations of variables to undefined. This is already being done by initCallContext or builtin_declare_vars, so no need to do it in the generated code again. Change-Id: I63805b97017f8676d57e0662073689e852b6ac23 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Fix a bug in catch{}finally{} and simplify codeLars Knoll2012-12-171-40/+16
| | | | | | | | | | | There was a bug in the implementation of unwindException(), that caused failures when called twice from one catch statement. Also refactor and simplify the TryStatement code further by introducing a rethrow builtin. Change-Id: I77bf37f1707042f402488ef2dfaf4e59bf8dc82a Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Resolve argument names from right to leftLars Knoll2012-12-171-1/+1
| | | | | | | | | Duplicated names for arguments are allowed in JS, later ones shadow previous ones. So we need to iterate from back to front to resolve the names correctly. Change-Id: If427ce9d11ac561457c24e41f79c11263fa0a8dc Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Fix delete operator on local variable and argumentsLars Knoll2012-12-141-0/+10
| | | | | | | | throw in strict mode, and ignore delete operations on arguments otherwise. Change-Id: Icd55f1c99dc5e5c35b3fea1ce5fdf46d5295dbaf Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Fixes for the arguments objectLars Knoll2012-12-141-0/+19
| | | | | | | We now pass most of the test cases for it. Change-Id: Idc43a9baa75c3c1e8fe760d78cf5e6092f051c6e Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Fix invalid reads in valgrind during unused basic block collectionsSimon Hausmann2012-12-131-7/+10
| | | | | | | | | | | | | When clearing cross-references to unused basic blocks blocks, don't delete the block right afterwards because another block might also still reference it. Instead keep track of the ones to be deleted and delete them afterwards in one shot. Also replaces the existance check for the blocks from a linear vector search to a hash set lookup which we already have around. Change-Id: I3bd72359259065ba26bf2116bf849575e4601f32 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Correctly set up nested functionsLars Knoll2012-12-131-2/+2
| | | | | | | | | Make sure we have the correct set of nested functions in both IR::Function and VM::Function. This is required so that closures can work correctly. Change-Id: I42493d5ee503090653b71650c8d19e06c4bcfdda Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Fix the bit shift and complement operatorsLars Knoll2012-12-131-3/+3
| | | | | | | | Take care of some corner cases and make them pass the test suite. Change-Id: Ic83508859800c62681ee873968b475ef81fffb82 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Fix increment and decrement operatorsLars Knoll2012-12-121-7/+41
| | | | | | | | These operators have semantics that are different from (foo + 1), as they always convert the LHS to a number first. Change-Id: I3fb4a1a328e3dfcb334875435c3cec90d01b67dd Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
* Fix assertionLars Knoll2012-12-121-2/+2
| | | | | Change-Id: I2c79d7c8c5f8624a5cfd5cb1c5af1488ccd5aada Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Fix indentationLars Knoll2012-12-121-1/+1
| | | | | Change-Id: I8ccb47cae3214ab2ac8ed51657856f51fc6c4e95 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Use a new and empty cleanup list for try statements when entering a functionLars Knoll2012-12-121-0/+4
| | | | | | | | | The cleanup list is local to a function definition. Otherwise inner functions would create cleanup code for try statements in outer functions leading to crashes. Change-Id: I5d35893b0ea6b0692cda44d5b34b0bb3dfc93fdd Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Remove references to deleted basic blocksLars Knoll2012-12-121-1/+7
| | | | | | | | | | | | When linearizing, we can sometimes remove some basic blocks that are never being jumped to. In this case we also need to clean up the back references to these blocks from other blocks. This fixes a valgrind error with SHOW_CODE=1 Change-Id: I07d74cef24d6cf2c8bcc1e748e314a3a5b5ed60a Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Properly set up the 'this' pointerLars Knoll2012-12-101-1/+2
| | | | | | | | | Make sure the this pointer is setup correctly for function calls. Also make sure we set the strict mode flag correctly in all functions. Change-Id: Idaacc92bf6469145b7addfac2bbddea588e85c2d Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
* Create a temp when a new expression is called with e.g. a closureLars Knoll2012-12-081-1/+7
| | | | | | | | Don't crash on e.g. var x = new (function() { return this; }) Change-Id: I120410b40ecda7fdc41e1dcc2c17251397143bc1 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Keep references while moving other expressions into a tempLars Knoll2012-12-081-2/+13
| | | | | | | | | delete and typeof need to get correct references as arguments. But we still need to evaluate other expressions correctly. The best way to do that is to store them in a temp. Change-Id: I7bcd152742bf752df47fd63a837952c57ea70bf5 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Fix typeof to work with undefined referencesLars Knoll2012-12-081-1/+1
| | | | | Change-Id: I90cd2b34a25476dfee1ec01315275b6c179d11dc Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Add a MemoryManager, which does GC for the interpreter.Erik Verbruggen2012-12-081-1/+4
| | | | | | | | | Todo: - stack walking for MASM - fix all TODOs/FIXMEs and hidden treasures (bugs). Change-Id: I36f8cdc3a545df7287ce1df17b3570a9c017865e Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Allow only the ExecutionEngine's StringPool to create Strings.Erik Verbruggen2012-12-041-3/+6
| | | | | | | | Strings are the only non-Object Values living on the heap. So by tracking creation, we can help the future GC a lot. Change-Id: I5d5044f9ff10da42aeb75dd4a556d6ab3d839b1a Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Pass the ExecutionContext into the code generatorLars Knoll2012-12-031-8/+20
| | | | | | | | | | Use the contexts strict mode flag to correctly parse eval code inside strict mode sections. Add code to allow the code generator to throw syntax errors. Change-Id: I4e4258b0d0b88952f4d609ec51bbe8db9a1c66a9 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Fix code generation for try statementsLars Knoll2012-12-021-65/+39
| | | | | | | | | | | | | | | The old code was not correctly handling statements as try { return; } finally {...} and others. In addition it was hard to read an maintain. We now keep a stack of try statements inside the code generator. Loops know about their surrounding try statement. Whenever a break, continue or return statement is encountered we now generate code for the finally statements and exception handlers we need to cleanup. Change-Id: I53bcc0587f1e923be00fea9b562453ef1e96b2de Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Add some debugging infrastructure to the interpreter.Erik Verbruggen2012-11-291-1/+17
| | | | | | | | | This currently mainly intended to be useful in a C++ debugger. The infrastructure makes it a lot easier to access (parent) contexts, find function names, etc. Change-Id: I0493d3a3bd4bf5c3a03379c1a2b545ed76862cd5 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Check for strict mode, and store it.Erik Verbruggen2012-11-271-0/+62
| | | | | Change-Id: I88e48a982eb6d4041aed085de0420d98cf96d406 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Correctly instantiate variables in the local scopeLars Knoll2012-11-271-5/+20
| | | | | | | | This fixes cases where eval() would create variables in the wrong scope. Change-Id: Ie93ec2d1fb125e588c1b6ffa2ca8ca4b6e3112c9 Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
* Fix: do not rune codegen when there is no program.Erik Verbruggen2012-11-261-0/+2
| | | | | | | | Happens in valid cases like an empty JS file (or one only containing comments). Change-Id: I553f57503b46da29276b06532a14e2a74395d84c Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Support for the with statementLars Knoll2012-11-251-4/+21
| | | | | | | | | | | | Add the with object (list) to the environment, and check properties there if it's available. Generate IR statements implementing with() support. Add two new builtin methods to enter and leave a with scope. Implement support for the builtin's in masm. Make sure exception handling works across with scopes. Change-Id: I8257a16cfccc91a1acedfd740ade711b016b33fd Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Correctly bind varibles in the global contextLars Knoll2012-11-241-9/+9
| | | | | | | | | | | | | | | Variables need to be bound to the execution context before entering the method. For the global scope this implies that declared variables are available, but may be undefined. The lines: print(x) var x = 1; has to print 'undefined' and not throw a type error. Change-Id: I9d7062823da83cd4c4e74588693bb0ce8dc85c6b Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Fix for local count in the global context.Erik Verbruggen2012-11-221-2/+5
| | | | | Change-Id: If0f07c995a51df45603c5581c721da15c1050158 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Compress temp usage in the interpreter.Erik Verbruggen2012-11-201-9/+12
| | | | | | | | | | Uses a variation on linear scan register allocation as the algorithm. As it depends on liveness analysis, keep that data around after codegen is finished (in IR::Stmt::Data). Added clean-up code for it in the IR::Function destructor. Change-Id: If3636648efbafcc1df469a24aaa885e21e6a2f16 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Remove the unused handlersBlock in the IR::FunctionLars Knoll2012-11-201-6/+0
| | | | | | | | This block was used for the old exception handling mechanism that is not in use anymore. Change-Id: If5adf89e43a22ab167378827c0e97f9907d8a366 Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
* Fix possible null-pointer deref.Erik Verbruggen2012-11-151-9/+10
| | | | | Change-Id: I8c4e2c34b2a3803d1346a1f716a0e40bde6bfdff Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Tune break/continue exception trampoline block generation.Erik Verbruggen2012-11-151-3/+8
| | | | | | | | If the break/continue trampoline blocks get reached, there cannot be a pending exception, so don't bother with saving it. Change-Id: Id079d48d961f21dd236dbc33fad1712edbd2df97 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Rethrow the right exception after finally if catch is missing.Erik Verbruggen2012-11-151-16/+36
| | | | | | | | | | | | Save the (unhandled) exception, because there might be another try block with a catch in the finally block. Restore it at the end of the finally block. The codegen for the finally, which is also needed for the break/continue trampoline blocks, has moved into a helper method. Change-Id: Iff28506b92a3749c6a5585fb6d94f3120696e89a Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Optimise move instructions involving constantsLars Knoll2012-11-141-1/+1
| | | | | Change-Id: Ic12a54ab1c5789cc5684d38961c58f6b34f9597a Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
* Fix codegen for try-statements in loops.Erik Verbruggen2012-11-141-1/+51
| | | | | | | | The tricky part is that a break/continue in a try or catch block must still execute the finally block. Change-Id: I5215c1b5688d87f3c9d1dd168eed7f3555bae22a Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Allow Const's as operands to BinopLars Knoll2012-11-121-4/+6
| | | | | | | | | | | This allows us to use expressions such as %x = %y + const in the IR. This still requires an implementation for moth. Change-Id: I134e96ddad08bcbe4f3ea5fa27c5338a96acac80 Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
* Fix codegen for void expressions.Erik Verbruggen2012-11-071-1/+2
| | | | | Change-Id: If89306aa91995e84106437a802e1d6d1940f17e7 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Implement Function(...) and new Function(...)Lars Knoll2012-11-011-2/+25
| | | | | Change-Id: I3ff229740820883a99dee6e32370fc528bf9169c Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Implement initial support for the delete operatorLars Knoll2012-10-311-2/+5
| | | | | | | And don't dump the assemply unless SHOW_CODE is set. Change-Id: I17ad36f002404b57c65f910048e5c82d42307976 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Implement the other variant of the 'for in' statementLars Knoll2012-10-311-2/+32
| | | | | Change-Id: I90823a97331fd15a8289bab93d7e9c1f34aaa10d Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>