Commit Graph

2307 Commits

Author SHA1 Message Date
David Wendt 7adabc8166 Use `unwrap_or_default` 2020-07-18 17:28:07 -04:00
David Wendt 44b924d7b4 `Script` should not hold write locks when probing it's internal caches. 2020-07-18 17:26:11 -04:00
David Wendt 575a9b091a Use FnvHashMap for the translation unit pools. 2020-07-18 17:02:52 -04:00
David Wendt 262bb148f1 Rename `a2me` to `entry` (or `method` in one case where it lets me simplify a struct declaration) 2020-07-18 17:02:32 -04:00
David Wendt c415190376 Zero-index multinames should generate a validation error in `QName::from_abc_multiname`. 2020-07-18 16:48:10 -04:00
David Wendt dc962f2abd Add AVM2 equivalent of `PropertyMap` for further expansion. 2020-07-18 16:41:35 -04:00
David Wendt 37b6b89d26 Add a stub AVM2 string representation to allow for both VMs' strings to diverge. 2020-07-18 16:20:58 -04:00
David Wendt ccacc540bf Remove dead code on all now-in-use structs and methods. 2020-07-18 16:12:24 -04:00
David Wendt e354c53075 Remove any remaining uses of `abc_ref`.
Holding a `Ref` on a garbage-collected object inherently extends any borrow locks on that object. Since ABC files are references already, taking a `Ref` to them only helps to skip the refcount update. This is less useful than expected: in most situations, using `abc_ref` causes double-borrow panics. The few methods that can use it are going to be fragile in the face of future refactors, so I'm nipping the problem in the bud now.
2020-07-14 20:14:23 -04:00
David Wendt f4c5075086 Run all string constant retrieval through the `TranslationUnit`, preventing us from making multiple copies of the same string.
For good measure, most of the other methods in `value` for retrieving pool primitives now also use `TranslationUnit` instead of `AbcFile`. This is the result of a handful of cascading changes throughout the project, and itself caused a few more.
2020-07-14 20:05:25 -04:00
David Wendt 70e9e7e9e9 Add support for cached/interned pool strings in the `TranslationUnit`. 2020-07-13 23:42:07 -04:00
David Wendt e1b9b823fc Remove `abc_string` and replace it with `abc_string_copy`. All code that pulls strings from the ABC file now uses `AvmString`s. 2020-07-13 23:41:46 -04:00
David Wendt 61a3ff8ae6 Replace `String` or `&str` references with `AvmString` everywhere in the AVM2 runtime. 2020-07-13 22:21:18 -04:00
David Wendt 2021cec9d3 Impl `Copy`, `Eq`, `PartialOrd`, `Ord`, and `Hash` for `AvmString`. 2020-07-13 22:09:34 -04:00
David Wendt 508fcd6e9e `pool_string` should return a `Ref<str>` just like `value::abc_string`. 2020-07-13 17:45:12 -04:00
David Wendt a406bdada2 Don't attempt to log debugging information if we're not in a debug build. 2020-07-13 17:45:12 -04:00
David Wendt ae26615bb4 `coerce_string` may return a static string, which we shouldn't clone. 2020-07-13 17:45:12 -04:00
David Wendt f0c633fe81 Allow borrowing string values from an ABC file instead of cloning everything. 2020-07-13 17:45:11 -04:00
David Wendt 64e5b46259 Add tests for `instanceof` and `is` operators. 2020-07-13 17:45:10 -04:00
David Wendt 39a4566f20 Instances should be listed as their prototypes (empty as they are) 2020-07-13 17:45:10 -04:00
David Wendt c917b3d411 Implement `istype`, `istypelate`, and `instanceof`. 2020-07-13 17:45:10 -04:00
David Wendt a0cb052795 Add `is_instance_of` trait method to `TObject` 2020-07-13 17:45:09 -04:00
David Wendt 3fae8b3832 Read the interface list when instantiating classes, resolve them, and stick them in the prototype for later use. 2020-07-13 17:45:09 -04:00
David Wendt cce68dbc21 Add trait methods for getting and setting the interfaces list. 2020-07-13 17:45:08 -04:00
David Wendt 563a515189 Add a test for loading interfaces into the AVM2.
This test will fail if the AVM2 implementation does not support bodyless methods or bare classes properly.
2020-07-13 17:45:07 -04:00
David Wendt 8f2d3315f3 Allow the construction of classes with no base class.
This is primarily used for interfaces, in case you can't guess by the previous commit.
2020-07-13 17:45:07 -04:00
David Wendt 5d89d4ed85 Allow methods to not hold a body.
Interface methods are specifically not allowed to be called: as a result, they don't get a method body. Existing code assumed a 1:1 relationship between methods and bodies, which causes spurious errors.
2020-07-13 17:45:07 -04:00
David Wendt 090fe56bd3 Wrap `BytecodeMethod` (and the bytecode half of `Executable`) in a `Gc`.
This is inspired by Dinnerbone's similar PR on the AVM1 side, where the Action half of that VM's `Executable` was reduced from 128 bytes to 16 by shoving it in a `Gc`. This won't be as dramatic but should still save some memory.

In fact, it should save a *lot* of memory in bytecode execution, where thanks to the previous commit's rebase, we now need to clone the current method once *for each instruction executed*. That is terrible, but should stop now.
2020-07-13 17:45:06 -04:00
David Wendt 97e005622b Invert the role of `Avm2` and it's `Activation`, similar to what was done with `Avm1` and it's `Activation`.
This also results in a far reduced role for `ReturnValue`, since I also took the liberty of removing most of it's use. Furthermore, I also made it apply equally to native and AVM2 code, which ensures all native implementations of methods don't double-borrow.

In AVM1, `ReturnValue` was actually removed entirely, because it's not needed. I attempted to do the same, but the fact that we're currently embedding `ScriptObjectData` in native objects means that we need it for virtual properties. Otherwise, virtual property implementations will see locked objects, which is bad.
2020-07-13 17:45:06 -04:00
David Wendt 5b5bf0719e Remove `Avm2Function` as it is no longer used. 2020-07-13 17:45:05 -04:00
David Wendt 098b034de0 Refactor method-related structs into a separate method module.
This also renames `NativeFunction` and `Avm2MethodEntry` to `NativeMethod` and `BytecodeMethod`, respectively.
2020-07-13 17:45:05 -04:00
David Wendt b6e05519cd Remove `Avm2ClassEntry`. It is no longer used. 2020-07-13 17:45:05 -04:00
David Wendt 12fc13da7f Clippy compliance for the last batch of commits. 2020-07-13 17:45:05 -04:00
David Wendt 041cb0b5c3 Resolve multiname constant zero as an error rather than a panic.
While some code that references pool multinames has zero as a valid index, we cannot validate exactly what the zero index is for a given index. Hence, callers instantiating multinames must check for zero and substitute the correct zero-value interpretation for their given type. If zero is an invalid value, it should ideally throw a different error than what's provided here.
2020-07-13 17:45:04 -04:00
David Wendt 0d2235d2e0 Resolve all remaining compilation issues with this refactor. 2020-07-13 17:45:04 -04:00
David Wendt 7684736bf7 `table_class` should resolve `Class`es straight from the current translation unit. 2020-07-13 17:45:04 -04:00
David Wendt 232c29dc5e Fix remaining problems with method loading using `callstatic` 2020-07-13 17:45:03 -04:00
David Wendt eaebd3c63c Make `Avm2MethodEntry` hold it's `TranslationUnit` rather than an `AbcFile`. 2020-07-13 17:45:03 -04:00
David Wendt 4467bc3193 Make `TranslationUnit` a GC-mandatory type (only referred to by `GcCell`). 2020-07-13 17:45:03 -04:00
David Wendt 60f3ae3ba7 Remove `Avm2ScriptEntry`. It is now obsolete and unused. 2020-07-13 17:45:02 -04:00
David Wendt f549d0146e Fix compilation bugs involved with automatic script initializer execution. 2020-07-13 17:45:02 -04:00
David Wendt b4f944b37b Wrap ABC loading inside of a `TranslationUnit`. 2020-07-13 17:45:01 -04:00
David Wendt 70e9030072 Decouple the entire trait machinery from ABC-provided traits.
This commit breaks the build: we still need to tell `Avm2` how to turn ABC traits into our own internal `Trait<'gc>`, `Class<'gc>`, and `Method<'gc>` types. We also need something to track which traits have already been instantiated, because `callstatic` would otherwise reinstantiate the trait in a different scope. (In fact, I think it *does* do exactly that right now...)
2020-07-13 17:45:01 -04:00
David Wendt 15a62d31cb Add an internal representation of `Trait`, separate from `swf::avm2::types::Trait`, which is specific to the ABC file format.
The intention is to completely replace all usage of `Avm2XYZEntry` with `Class`, `Trait`, and `Method`. This will allow runtime-provided global class traits to coexist with those provided by user code.
2020-07-13 17:45:01 -04:00
David Wendt 4cd30455de Excise `ReturnValue<'gc>` from all `TObject` methods.
Inspired by Dinnerbone's PR doing the exact same thing to AVM1.

On AVM2 we have a bit of a subtle issue: the base implementation of `set_property_local` and `init_property_local` *must* return `ReturnValue`s to avoid double-borrows. Each implementation of `TObject` must resolve them before returning.
2020-07-13 17:45:00 -04:00
David Wendt 3362ec09e8 chore: Clippy conformance 2020-07-13 17:45:00 -04:00
David Wendt fe283e6770 Silence this warning about occupied slots being an unused variant.
I don't know if I'm missing something, but I'm pretty sure this variant is reachable via `TObject::install_slot`.
2020-07-13 17:45:00 -04:00
David Wendt 6117288fe2 Add tests for `ifstricteq`, `ifstrictne`, and `strictequals`. 2020-07-13 17:44:59 -04:00
David Wendt 34ab8c8ce6 `NaN` is not special-cased in AS3. 2020-07-13 17:44:59 -04:00
David Wendt 34b3bbae63 *Correctly* implement `ifstricteq` and `ifstrictne`.
The previous implementation suffered from copypasta and was attempting to assert that both of it's values were `bool`.
2020-07-13 17:44:59 -04:00