| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2021, Andreas Kling <kling@serenityos.org> | 
					
						
							| 
									
										
										
										
											2021-06-07 21:13:37 +01:00
										 |  |  |  * Copyright (c) 2021, Linus Groh <linusg@serenityos.org> | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-05 15:14:09 +02:00
										 |  |  | #include <LibJS/AST.h>
 | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | #include <LibJS/Bytecode/Interpreter.h>
 | 
					
						
							|  |  |  | #include <LibJS/Bytecode/Op.h>
 | 
					
						
							| 
									
										
										
										
											2021-06-08 07:59:25 +02:00
										 |  |  | #include <LibJS/Runtime/BigInt.h>
 | 
					
						
							| 
									
										
										
										
											2021-06-03 18:26:32 +02:00
										 |  |  | #include <LibJS/Runtime/GlobalObject.h>
 | 
					
						
							| 
									
										
										
										
											2021-06-05 15:14:09 +02:00
										 |  |  | #include <LibJS/Runtime/ScriptFunction.h>
 | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | #include <LibJS/Runtime/Value.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-07 15:12:43 +02:00
										 |  |  | namespace JS::Bytecode { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Instruction::execute(Bytecode::Interpreter& interpreter) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | #define __BYTECODE_OP(op)       \
 | 
					
						
							|  |  |  |     case Instruction::Type::op: \ | 
					
						
							|  |  |  |         return static_cast<Bytecode::Op::op const&>(*this).execute(interpreter); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (type()) { | 
					
						
							|  |  |  |         ENUMERATE_BYTECODE_OPS(__BYTECODE_OP) | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |         VERIFY_NOT_REACHED(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #undef __BYTECODE_OP
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | String Instruction::to_string() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | #define __BYTECODE_OP(op)       \
 | 
					
						
							|  |  |  |     case Instruction::Type::op: \ | 
					
						
							|  |  |  |         return static_cast<Bytecode::Op::op const&>(*this).to_string(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (type()) { | 
					
						
							|  |  |  |         ENUMERATE_BYTECODE_OPS(__BYTECODE_OP) | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |         VERIFY_NOT_REACHED(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #undef __BYTECODE_OP
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | namespace JS::Bytecode::Op { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Load::execute(Bytecode::Interpreter& interpreter) const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     interpreter.accumulator() = interpreter.reg(m_src); | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  | void LoadImmediate::execute(Bytecode::Interpreter& interpreter) const | 
					
						
							| 
									
										
										
										
											2021-06-07 22:05:09 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     interpreter.accumulator() = m_value; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Store::execute(Bytecode::Interpreter& interpreter) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     interpreter.reg(m_dst) = interpreter.accumulator(); | 
					
						
							| 
									
										
										
										
											2021-06-07 22:05:09 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-07 23:08:35 +02:00
										 |  |  | static Value abstract_inequals(GlobalObject& global_object, Value src1, Value src2) | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-07 23:08:35 +02:00
										 |  |  |     return Value(!abstract_eq(global_object, src1, src2)); | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-07 23:08:35 +02:00
										 |  |  | static Value abstract_equals(GlobalObject& global_object, Value src1, Value src2) | 
					
						
							| 
									
										
										
										
											2021-06-03 18:32:33 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-07 23:08:35 +02:00
										 |  |  |     return Value(abstract_eq(global_object, src1, src2)); | 
					
						
							| 
									
										
										
										
											2021-06-03 18:32:33 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-07 23:08:35 +02:00
										 |  |  | static Value typed_inequals(GlobalObject&, Value src1, Value src2) | 
					
						
							| 
									
										
										
										
											2021-06-07 19:17:20 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-07 23:08:35 +02:00
										 |  |  |     return Value(!strict_eq(src1, src2)); | 
					
						
							| 
									
										
										
										
											2021-06-07 19:17:20 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-07 23:08:35 +02:00
										 |  |  | static Value typed_equals(GlobalObject&, Value src1, Value src2) | 
					
						
							| 
									
										
										
										
											2021-06-07 19:17:20 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-07 23:08:35 +02:00
										 |  |  |     return Value(strict_eq(src1, src2)); | 
					
						
							| 
									
										
										
										
											2021-06-07 19:17:20 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  | #define JS_DEFINE_COMMON_BINARY_OP(OpTitleCase, op_snake_case)                            \
 | 
					
						
							|  |  |  |     void OpTitleCase::execute(Bytecode::Interpreter& interpreter) const                   \ | 
					
						
							|  |  |  |     {                                                                                     \ | 
					
						
							|  |  |  |         auto lhs = interpreter.reg(m_lhs_reg);                                            \ | 
					
						
							|  |  |  |         auto rhs = interpreter.accumulator();                                             \ | 
					
						
							|  |  |  |         interpreter.accumulator() = op_snake_case(interpreter.global_object(), lhs, rhs); \ | 
					
						
							|  |  |  |     }                                                                                     \ | 
					
						
							|  |  |  |     String OpTitleCase::to_string() const                                                 \ | 
					
						
							|  |  |  |     {                                                                                     \ | 
					
						
							|  |  |  |         return String::formatted(#OpTitleCase " lhs:{}", m_lhs_reg);                      \ | 
					
						
							| 
									
										
										
										
											2021-06-07 23:08:35 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-06-07 21:13:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-07 23:08:35 +02:00
										 |  |  | JS_ENUMERATE_COMMON_BINARY_OPS(JS_DEFINE_COMMON_BINARY_OP) | 
					
						
							| 
									
										
										
										
											2021-06-07 21:18:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-07 23:08:35 +02:00
										 |  |  | static Value not_(GlobalObject&, Value value) | 
					
						
							| 
									
										
										
										
											2021-06-07 21:13:37 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-07 23:08:35 +02:00
										 |  |  |     return Value(!value.to_boolean()); | 
					
						
							| 
									
										
										
										
											2021-06-07 21:13:37 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-07 23:08:35 +02:00
										 |  |  | static Value typeof_(GlobalObject& global_object, Value value) | 
					
						
							| 
									
										
										
										
											2021-06-07 19:53:47 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-07 23:08:35 +02:00
										 |  |  |     return js_string(global_object.vm(), value.typeof()); | 
					
						
							| 
									
										
										
										
											2021-06-07 19:53:47 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  | #define JS_DEFINE_COMMON_UNARY_OP(OpTitleCase, op_snake_case)                                              \
 | 
					
						
							|  |  |  |     void OpTitleCase::execute(Bytecode::Interpreter& interpreter) const                                    \ | 
					
						
							|  |  |  |     {                                                                                                      \ | 
					
						
							|  |  |  |         interpreter.accumulator() = op_snake_case(interpreter.global_object(), interpreter.accumulator()); \ | 
					
						
							|  |  |  |     }                                                                                                      \ | 
					
						
							|  |  |  |     String OpTitleCase::to_string() const                                                                  \ | 
					
						
							|  |  |  |     {                                                                                                      \ | 
					
						
							|  |  |  |         return #OpTitleCase;                                                                               \ | 
					
						
							| 
									
										
										
										
											2021-06-07 23:08:35 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-06-07 19:53:47 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-07 23:08:35 +02:00
										 |  |  | JS_ENUMERATE_COMMON_UNARY_OPS(JS_DEFINE_COMMON_UNARY_OP) | 
					
						
							| 
									
										
										
										
											2021-06-07 19:53:47 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-08 07:59:25 +02:00
										 |  |  | void NewBigInt::execute(Bytecode::Interpreter& interpreter) const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     interpreter.accumulator() = js_bigint(interpreter.vm().heap(), m_bigint); | 
					
						
							| 
									
										
										
										
											2021-06-08 07:59:25 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-03 18:26:32 +02:00
										 |  |  | void NewString::execute(Bytecode::Interpreter& interpreter) const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     interpreter.accumulator() = js_string(interpreter.vm(), m_string); | 
					
						
							| 
									
										
										
										
											2021-06-03 18:26:32 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-04 20:30:23 +02:00
										 |  |  | void NewObject::execute(Bytecode::Interpreter& interpreter) const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     interpreter.accumulator() = Object::create_empty(interpreter.global_object()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ConcatString::execute(Bytecode::Interpreter& interpreter) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     interpreter.reg(m_lhs) = add(interpreter.global_object(), interpreter.reg(m_lhs), interpreter.accumulator()); | 
					
						
							| 
									
										
										
										
											2021-06-04 20:30:23 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-03 18:26:32 +02:00
										 |  |  | void GetVariable::execute(Bytecode::Interpreter& interpreter) const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     interpreter.accumulator() = interpreter.vm().get_variable(m_identifier, interpreter.global_object()); | 
					
						
							| 
									
										
										
										
											2021-06-03 18:26:32 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SetVariable::execute(Bytecode::Interpreter& interpreter) const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     interpreter.vm().set_variable(m_identifier, interpreter.accumulator(), interpreter.global_object()); | 
					
						
							| 
									
										
										
										
											2021-06-03 18:26:32 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-04 21:03:53 +02:00
										 |  |  | void GetById::execute(Bytecode::Interpreter& interpreter) const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     if (auto* object = interpreter.accumulator().to_object(interpreter.global_object())) | 
					
						
							|  |  |  |         interpreter.accumulator() = object->get(m_property); | 
					
						
							| 
									
										
										
										
											2021-06-04 21:03:53 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-04 20:47:07 +02:00
										 |  |  | void PutById::execute(Bytecode::Interpreter& interpreter) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (auto* object = interpreter.reg(m_base).to_object(interpreter.global_object())) | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |         object->put(m_property, interpreter.accumulator()); | 
					
						
							| 
									
										
										
										
											2021-06-04 20:47:07 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-04 12:07:38 +02:00
										 |  |  | void Jump::execute(Bytecode::Interpreter& interpreter) const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-06 13:26:50 +02:00
										 |  |  |     interpreter.jump(*m_target); | 
					
						
							| 
									
										
										
										
											2021-06-04 12:07:38 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void JumpIfFalse::execute(Bytecode::Interpreter& interpreter) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VERIFY(m_target.has_value()); | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     auto result = interpreter.accumulator(); | 
					
						
							| 
									
										
										
										
											2021-06-07 22:53:33 +02:00
										 |  |  |     if (!result.to_boolean()) | 
					
						
							| 
									
										
										
										
											2021-06-04 12:07:38 +02:00
										 |  |  |         interpreter.jump(m_target.value()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-04 12:20:44 +02:00
										 |  |  | void JumpIfTrue::execute(Bytecode::Interpreter& interpreter) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VERIFY(m_target.has_value()); | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     auto result = interpreter.accumulator(); | 
					
						
							| 
									
										
										
										
											2021-06-07 22:53:33 +02:00
										 |  |  |     if (result.to_boolean()) | 
					
						
							| 
									
										
										
										
											2021-06-04 12:20:44 +02:00
										 |  |  |         interpreter.jump(m_target.value()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  | void JumpIfNotNullish::execute(Bytecode::Interpreter& interpreter) const | 
					
						
							| 
									
										
										
										
											2021-06-08 02:18:47 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     VERIFY(m_target.has_value()); | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     auto result = interpreter.accumulator(); | 
					
						
							|  |  |  |     if (!result.is_nullish()) | 
					
						
							| 
									
										
										
										
											2021-06-08 02:18:47 +02:00
										 |  |  |         interpreter.jump(m_target.value()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-05 15:15:30 +02:00
										 |  |  | void Call::execute(Bytecode::Interpreter& interpreter) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto callee = interpreter.reg(m_callee); | 
					
						
							|  |  |  |     if (!callee.is_function()) { | 
					
						
							|  |  |  |         TODO(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     auto& function = callee.as_function(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto this_value = interpreter.reg(m_this_value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Value return_value; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-07 15:12:43 +02:00
										 |  |  |     if (m_argument_count == 0) { | 
					
						
							| 
									
										
										
										
											2021-06-05 15:15:30 +02:00
										 |  |  |         return_value = interpreter.vm().call(function, this_value); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         MarkedValueList argument_values { interpreter.vm().heap() }; | 
					
						
							| 
									
										
										
										
											2021-06-07 15:12:43 +02:00
										 |  |  |         for (size_t i = 0; i < m_argument_count; ++i) { | 
					
						
							|  |  |  |             argument_values.append(interpreter.reg(m_arguments[i])); | 
					
						
							| 
									
										
										
										
											2021-06-05 15:15:30 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         return_value = interpreter.vm().call(function, this_value, move(argument_values)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     interpreter.accumulator() = return_value; | 
					
						
							| 
									
										
										
										
											2021-06-05 15:15:30 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-05 15:14:09 +02:00
										 |  |  | void EnterScope::execute(Bytecode::Interpreter& interpreter) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto& vm = interpreter.vm(); | 
					
						
							|  |  |  |     auto& global_object = interpreter.global_object(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (auto& declaration : m_scope_node.functions()) | 
					
						
							|  |  |  |         vm.current_scope()->put_to_scope(declaration.name(), { js_undefined(), DeclarationKind::Var }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (auto& declaration : m_scope_node.functions()) { | 
					
						
							|  |  |  |         auto* function = ScriptFunction::create(global_object, declaration.name(), declaration.body(), declaration.parameters(), declaration.function_length(), vm.current_scope(), declaration.is_strict_mode()); | 
					
						
							|  |  |  |         vm.set_variable(declaration.name(), function, global_object); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // FIXME: Process variable declarations.
 | 
					
						
							|  |  |  |     // FIXME: Whatever else JS::Interpreter::enter_scope() does.
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-05 15:53:36 +02:00
										 |  |  | void Return::execute(Bytecode::Interpreter& interpreter) const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     interpreter.do_return(interpreter.accumulator().value_or(js_undefined())); | 
					
						
							| 
									
										
										
										
											2021-06-05 15:53:36 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | String Load::to_string() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     return String::formatted("Load src:{}", m_src); | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  | String LoadImmediate::to_string() const | 
					
						
							| 
									
										
										
										
											2021-06-07 22:05:09 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     return String::formatted("LoadImmediate value:{}", m_value); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | String Store::to_string() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return String::formatted("Store dst:{}", m_dst); | 
					
						
							| 
									
										
										
										
											2021-06-07 22:05:09 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-08 07:59:25 +02:00
										 |  |  | String NewBigInt::to_string() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     return String::formatted("NewBigInt bigint:\"{}\"", m_bigint.to_base10()); | 
					
						
							| 
									
										
										
										
											2021-06-08 07:59:25 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-03 18:26:32 +02:00
										 |  |  | String NewString::to_string() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     return String::formatted("NewString string:\"{}\"", m_string); | 
					
						
							| 
									
										
										
										
											2021-06-03 18:26:32 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-04 20:30:23 +02:00
										 |  |  | String NewObject::to_string() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     return "NewObject"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | String ConcatString::to_string() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return String::formatted("ConcatString lhs:{}", m_lhs); | 
					
						
							| 
									
										
										
										
											2021-06-04 20:30:23 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-03 18:26:32 +02:00
										 |  |  | String GetVariable::to_string() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     return String::formatted("GetVariable identifier:{}", m_identifier); | 
					
						
							| 
									
										
										
										
											2021-06-03 18:26:32 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | String SetVariable::to_string() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     return String::formatted("SetVariable identifier:{}", m_identifier); | 
					
						
							| 
									
										
										
										
											2021-06-03 18:26:32 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-04 20:47:07 +02:00
										 |  |  | String PutById::to_string() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     return String::formatted("PutById base:{}, property:{}", m_base, m_property); | 
					
						
							| 
									
										
										
										
											2021-06-04 20:47:07 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-04 21:03:53 +02:00
										 |  |  | String GetById::to_string() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     return String::formatted("GetById property:{}", m_property); | 
					
						
							| 
									
										
										
										
											2021-06-04 21:03:53 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-04 12:07:38 +02:00
										 |  |  | String Jump::to_string() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-06 13:26:50 +02:00
										 |  |  |     return String::formatted("Jump {}", *m_target); | 
					
						
							| 
									
										
										
										
											2021-06-04 12:07:38 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | String JumpIfFalse::to_string() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_target.has_value()) | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |         return String::formatted("JumpIfFalse target:{}", m_target.value()); | 
					
						
							|  |  |  |     return "JumpIfFalse target:<empty>"; | 
					
						
							| 
									
										
										
										
											2021-06-04 12:07:38 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-04 12:20:44 +02:00
										 |  |  | String JumpIfTrue::to_string() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_target.has_value()) | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |         return String::formatted("JumpIfTrue target:{}", m_target.value()); | 
					
						
							|  |  |  |     return "JumpIfTrue result:{}, target:<empty>"; | 
					
						
							| 
									
										
										
										
											2021-06-04 12:20:44 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  | String JumpIfNotNullish::to_string() const | 
					
						
							| 
									
										
										
										
											2021-06-08 02:18:47 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (m_target.has_value()) | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |         return String::formatted("JumpIfNotNullish target:{}", m_target.value()); | 
					
						
							|  |  |  |     return "JumpIfNotNullish target:<empty>"; | 
					
						
							| 
									
										
										
										
											2021-06-08 02:18:47 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-05 15:15:30 +02:00
										 |  |  | String Call::to_string() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     StringBuilder builder; | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     builder.appendff("Call callee:{}, this:{}", m_callee, m_this_value); | 
					
						
							| 
									
										
										
										
											2021-06-07 15:12:43 +02:00
										 |  |  |     if (m_argument_count != 0) { | 
					
						
							| 
									
										
										
										
											2021-06-05 15:15:30 +02:00
										 |  |  |         builder.append(", arguments:["); | 
					
						
							| 
									
										
										
										
											2021-06-07 15:12:43 +02:00
										 |  |  |         for (size_t i = 0; i < m_argument_count; ++i) { | 
					
						
							| 
									
										
										
										
											2021-06-05 15:15:30 +02:00
										 |  |  |             builder.appendff("{}", m_arguments[i]); | 
					
						
							| 
									
										
										
										
											2021-06-07 15:12:43 +02:00
										 |  |  |             if (i != m_argument_count - 1) | 
					
						
							| 
									
										
										
										
											2021-06-05 15:15:30 +02:00
										 |  |  |                 builder.append(','); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         builder.append(']'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return builder.to_string(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-05 15:14:09 +02:00
										 |  |  | String EnterScope::to_string() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return "EnterScope"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-05 15:53:36 +02:00
										 |  |  | String Return::to_string() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return "Return"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | } |