diff --git a/buildSrc/src/main/kotlin/cc-tweaked.java-convention.gradle.kts b/buildSrc/src/main/kotlin/cc-tweaked.java-convention.gradle.kts index e61b43776..ab12aff33 100644 --- a/buildSrc/src/main/kotlin/cc-tweaked.java-convention.gradle.kts +++ b/buildSrc/src/main/kotlin/cc-tweaked.java-convention.gradle.kts @@ -57,7 +57,6 @@ repositories { filter { includeGroup("cc.tweaked") - includeModule("org.squiddev", "Cobalt") // Things we mirror includeGroup("commoble.morered") includeGroup("dev.architectury") diff --git a/doc/events/file_transfer.md b/doc/events/file_transfer.md index dc73238da..db631b4ac 100644 --- a/doc/events/file_transfer.md +++ b/doc/events/file_transfer.md @@ -12,7 +12,7 @@ SPDX-License-Identifier: MPL-2.0 The [`file_transfer`] event is queued when a user drags-and-drops a file on an open computer. This event contains a single argument of type [`TransferredFiles`], which can be used to [get the files to be -transferred][`TransferredFiles.getFiles`]. Each file returned is a [binary file handle][`fs.BinaryReadHandle`] with an +transferred][`TransferredFiles.getFiles`]. Each file returned is a [binary file handle][`fs.ReadHandle`] with an additional [getName][`TransferredFile.getName`] method. ## Return values diff --git a/doc/guides/speaker_audio.md b/doc/guides/speaker_audio.md index 9ff4779b8..2a09c06e7 100644 --- a/doc/guides/speaker_audio.md +++ b/doc/guides/speaker_audio.md @@ -134,7 +134,7 @@ accepts blocks of DFPWM data and converts it to a list of 8-bit amplitudes, whic As mentioned above, [`speaker.playAudio`] accepts at most 128Γ—1024 samples in one go. DFPMW uses a single bit for each sample, which means we want to process our audio in chunks of 16Γ—1024 bytes (16KiB). In order to do this, we use [`io.lines`], which provides a nice way to loop over chunks of a file. You can of course just use [`fs.open`] and -[`fs.BinaryReadHandle.read`] if you prefer. +[`fs.ReadHandle.read`] if you prefer. ## Processing audio As mentioned near the beginning of this guide, PCM audio is pretty easy to work with as it's just a list of amplitudes. diff --git a/doc/reference/breaking_changes.md b/doc/reference/breaking_changes.md index ce9283d3f..18f1eefcc 100644 --- a/doc/reference/breaking_changes.md +++ b/doc/reference/breaking_changes.md @@ -21,6 +21,19 @@ of the mod should run fine on later versions. However, some changes to the underlying game, or CC: Tweaked's own internals may break some programs. This page serves as documentation for breaking changes and "gotchas" one should look out for between versions. +## CC: Tweaked 1.109.0 {#cct-1.109} + + - Update to Lua 5.2: + - Support for Lua 5.0's pseudo-argument `arg` has been removed. You should always use `...` for varargs. + - Environments are no longer baked into the runtime, and instead use the `_ENV` local or upvalue. `getfenv`/`setfenv` + now only work on Lua functions with an `_ENV` upvalue. `getfenv` will return the global environment when called + with other functions, and `setfenv` will have no effect. + - `load`/`loadstring` defaults to using the global environment (`_G`) rather than the current coroutine's + environment. + - Support for dumping functions (`string.dump`) and loading binary chunks has been removed. + + - File handles, HTTP requests and websockets now always use the original bytes rather than encoding/decoding to UTF-8. + ## Minecraft 1.13 {#mc-1.13} - The "key code" for [`key`] and [`key_up`] events has changed, due to Minecraft updating to LWJGL 3. Make sure you're using the constants provided by the [`keys`] API, rather than hard-coding numerical values. diff --git a/doc/reference/feature_compat.md b/doc/reference/feature_compat.md index d3afcdb7b..72f9b18d8 100644 --- a/doc/reference/feature_compat.md +++ b/doc/reference/feature_compat.md @@ -9,17 +9,19 @@ SPDX-License-Identifier: MPL-2.0 --> # Lua 5.2/5.3 features in CC: Tweaked -CC: Tweaked is based off of the Cobalt Lua runtime, which uses Lua 5.1. However, Cobalt and CC:T implement additional features from Lua 5.2 and 5.3 (as well as some deprecated 5.0 features) that are not available in base 5.1. This page lists all of the compatibility for these newer versions. +CC: Tweaked is based off of the Cobalt Lua runtime, which uses Lua 5.2. However, Cobalt and CC:T implement additional +features from Lua 5.2 and 5.3 (as well as some deprecated 5.0 and 5.1 features). This page lists all of the +compatibility for these newer versions. ## Lua 5.2 | Feature | Supported? | Notes | |---------------------------------------------------------------|------------|-------------------------------------------------------------------| -| `goto`/labels | ❌ | | -| `_ENV` | πŸ”Ά | The `_ENV` global points to `getfenv()`, but it cannot be set. | +| `goto`/labels | βœ” | | +| `_ENV` | βœ” | | | `\z` escape | βœ” | | | `\xNN` escape | βœ” | | | Hex literal fractional/exponent parts | βœ” | | -| Empty statements | ❌ | | +| Empty statements | βœ” | | | `__len` metamethod | βœ” | | | `__ipairs` metamethod | ❌ | Deprecated in Lua 5.3. `ipairs` uses `__len`/`__index` instead. | | `__pairs` metamethod | βœ” | | @@ -27,12 +29,12 @@ CC: Tweaked is based off of the Cobalt Lua runtime, which uses Lua 5.1. However, | `collectgarbage` isrunning, generational, incremental options | ❌ | `collectgarbage` does not exist in CC:T. | | New `load` syntax | βœ” | | | `loadfile` mode parameter | βœ” | Supports both 5.1 and 5.2+ syntax. | -| Removed `loadstring` | πŸ”Ά | Only if `disable_lua51_features` is enabled in the configuration. | -| Removed `getfenv`, `setfenv` | πŸ”Ά | Only if `disable_lua51_features` is enabled in the configuration. | +| Removed `loadstring` | ❌ | | +| Removed `getfenv`, `setfenv` | πŸ”Ά | Only supports closures with an `_ENV` upvalue. | | `rawlen` function | βœ” | | | Negative index to `select` | βœ” | | -| Removed `unpack` | πŸ”Ά | Only if `disable_lua51_features` is enabled in the configuration. | -| Arguments to `xpcall` | βœ” | | +| Removed `unpack` | ❌ | | +| Arguments to `xpcall` | βœ” | | | Second return value from `coroutine.running` | βœ” | | | Removed `module` | βœ” | | | `package.loaders` -> `package.searchers` | ❌ | | @@ -40,14 +42,14 @@ CC: Tweaked is based off of the Cobalt Lua runtime, which uses Lua 5.1. However, | `package.config` | βœ” | | | `package.searchpath` | βœ” | | | Removed `package.seeall` | βœ” | | -| `string.dump` on functions with upvalues (blanks them out) | βœ” | | -| `string.rep` separator | βœ” | | +| `string.dump` on functions with upvalues (blanks them out) | ❌ | `string.dump` is not supported | +| `string.rep` separator | βœ” | | | `%g` match group | ❌ | | | Removal of `%z` match group | ❌ | | -| Removed `table.maxn` | πŸ”Ά | Only if `disable_lua51_features` is enabled in the configuration. | +| Removed `table.maxn` | ❌ | | | `table.pack`/`table.unpack` | βœ” | | | `math.log` base argument | βœ” | | -| Removed `math.log10` | πŸ”Ά | Only if `disable_lua51_features` is enabled in the configuration. | +| Removed `math.log10` | ❌ | | | `*L` mode to `file:read` | βœ” | | | `os.execute` exit type + return value | ❌ | `os.execute` does not exist in CC:T. | | `os.exit` close argument | ❌ | `os.exit` does not exist in CC:T. | @@ -61,7 +63,7 @@ CC: Tweaked is based off of the Cobalt Lua runtime, which uses Lua 5.1. However, | Tail call hooks | ❌ | | | `=` prefix for chunks | βœ” | | | Yield across C boundary | βœ” | | -| Removal of ambiguity error | ❌ | | +| Removal of ambiguity error | βœ” | | | Identifiers may no longer use locale-dependent letters | βœ” | | | Ephemeron tables | ❌ | | | Identical functions may be reused | ❌ | Removed in Lua 5.4 | diff --git a/doc/stub/os.lua b/doc/stub/os.lua index a2b5f5e08..ff7d88f58 100644 --- a/doc/stub/os.lua +++ b/doc/stub/os.lua @@ -95,10 +95,10 @@ function pullEventRaw(filter) end -- nearest multiple of 0.05. function sleep(time) end ---- Get the current CraftOS version (for example, `CraftOS 1.8`). +--- Get the current CraftOS version (for example, `CraftOS 1.9`). -- -- This is defined by `bios.lua`. For the current version of CC:Tweaked, this --- should return `CraftOS 1.8`. +-- should return `CraftOS 1.9`. -- -- @treturn string The current CraftOS version. -- @usage os.version() diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 03acb635f..20f3c511a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -19,8 +19,8 @@ parchmentMc = "1.20.1" asm = "9.5" autoService = "1.1.1" checkerFramework = "3.32.0" -cobalt = "0.7.3" -cobalt-next = "0.7.4" # Not a real version, used to constrain the version we accept. +cobalt = "0.8.0" +cobalt-next = "0.8.1" # Not a real version, used to constrain the version we accept. commonsCli = "1.3.1" fastutil = "8.5.9" guava = "31.1-jre" @@ -51,7 +51,7 @@ jqwik = "1.7.4" junit = "5.10.0" # Build tools -cctJavadoc = "1.8.0" +cctJavadoc = "1.8.1" checkstyle = "10.12.3" curseForgeGradle = "1.0.14" errorProne-core = "2.21.1" @@ -68,7 +68,7 @@ mixinGradle = "0.7.+" nullAway = "0.9.9" spotless = "6.21.0" taskTree = "2.1.1" -teavm = "0.9.0-SQUID.1" +teavm = "0.10.0-SQUID.1" vanillaGradle = "0.2.1-SNAPSHOT" vineflower = "1.11.0" @@ -78,7 +78,7 @@ asm = { module = "org.ow2.asm:asm", version.ref = "asm" } asm-commons = { module = "org.ow2.asm:asm-commons", version.ref = "asm" } autoService = { module = "com.google.auto.service:auto-service", version.ref = "autoService" } checkerFramework = { module = "org.checkerframework:checker-qual", version.ref = "checkerFramework" } -cobalt = { module = "org.squiddev:Cobalt", version.ref = "cobalt" } +cobalt = { module = "cc.tweaked:cobalt", version.ref = "cobalt" } commonsCli = { module = "commons-cli:commons-cli", version.ref = "commonsCli" } fastutil = { module = "it.unimi.dsi:fastutil", version.ref = "fastutil" } forgeSpi = { module = "net.minecraftforge:forgespi", version.ref = "forgeSpi" } diff --git a/projects/common/src/client/java/dan200/computercraft/client/gui/widgets/TerminalWidget.java b/projects/common/src/client/java/dan200/computercraft/client/gui/widgets/TerminalWidget.java index fe55ede70..cc914e339 100644 --- a/projects/common/src/client/java/dan200/computercraft/client/gui/widgets/TerminalWidget.java +++ b/projects/common/src/client/java/dan200/computercraft/client/gui/widgets/TerminalWidget.java @@ -8,8 +8,8 @@ import com.mojang.blaze3d.vertex.Tesselator; import dan200.computercraft.client.render.RenderTypes; import dan200.computercraft.client.render.text.FixedWidthFontRenderer; import dan200.computercraft.core.terminal.Terminal; +import dan200.computercraft.core.util.StringUtil; import dan200.computercraft.shared.computer.core.InputHandler; -import net.minecraft.SharedConstants; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.AbstractWidget; @@ -112,26 +112,8 @@ public class TerminalWidget extends AbstractWidget { } private void paste() { - var clipboard = Minecraft.getInstance().keyboardHandler.getClipboard(); - - // Clip to the first occurrence of \r or \n - var newLineIndex1 = clipboard.indexOf('\r'); - var newLineIndex2 = clipboard.indexOf('\n'); - if (newLineIndex1 >= 0 && newLineIndex2 >= 0) { - clipboard = clipboard.substring(0, Math.min(newLineIndex1, newLineIndex2)); - } else if (newLineIndex1 >= 0) { - clipboard = clipboard.substring(0, newLineIndex1); - } else if (newLineIndex2 >= 0) { - clipboard = clipboard.substring(0, newLineIndex2); - } - - // Filter the string - clipboard = SharedConstants.filterText(clipboard); - if (!clipboard.isEmpty()) { - // Clip to 512 characters and queue the event - if (clipboard.length() > 512) clipboard = clipboard.substring(0, 512); - computer.queueEvent("paste", new Object[]{ clipboard }); - } + var clipboard = StringUtil.normaliseClipboardString(Minecraft.getInstance().keyboardHandler.getClipboard()); + if (!clipboard.isEmpty()) computer.queueEvent("paste", new Object[]{ clipboard }); } @Override diff --git a/projects/common/src/main/java/dan200/computercraft/shared/computer/core/ResourceMount.java b/projects/common/src/main/java/dan200/computercraft/shared/computer/core/ResourceMount.java index 0a69cdc7e..2171ac6d4 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/computer/core/ResourceMount.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/computer/core/ResourceMount.java @@ -21,7 +21,7 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; -import static dan200.computercraft.core.filesystem.MountHelpers.NO_SUCH_FILE; +import static dan200.computercraft.api.filesystem.MountConstants.NO_SUCH_FILE; /** * A mount backed by Minecraft's {@link ResourceManager}. diff --git a/projects/core-api/src/main/java/dan200/computercraft/api/filesystem/FileAttributes.java b/projects/core-api/src/main/java/dan200/computercraft/api/filesystem/FileAttributes.java index cf478ca4b..256ac8529 100644 --- a/projects/core-api/src/main/java/dan200/computercraft/api/filesystem/FileAttributes.java +++ b/projects/core-api/src/main/java/dan200/computercraft/api/filesystem/FileAttributes.java @@ -7,7 +7,8 @@ package dan200.computercraft.api.filesystem; import javax.annotation.Nullable; import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.FileTime; -import java.time.Instant; + +import static dan200.computercraft.api.filesystem.MountConstants.EPOCH; /** * A simple version of {@link BasicFileAttributes}, which provides what information a {@link Mount} already exposes. @@ -20,8 +21,6 @@ import java.time.Instant; public record FileAttributes( boolean isDirectory, long size, FileTime creationTime, FileTime lastModifiedTime ) implements BasicFileAttributes { - private static final FileTime EPOCH = FileTime.from(Instant.EPOCH); - /** * Create a new {@link FileAttributes} instance with the {@linkplain #creationTime() creation time} and * {@linkplain #lastModifiedTime() last modified time} set to the Unix epoch. diff --git a/projects/core-api/src/main/java/dan200/computercraft/api/filesystem/MountConstants.java b/projects/core-api/src/main/java/dan200/computercraft/api/filesystem/MountConstants.java new file mode 100644 index 000000000..6992fe761 --- /dev/null +++ b/projects/core-api/src/main/java/dan200/computercraft/api/filesystem/MountConstants.java @@ -0,0 +1,85 @@ +// SPDX-FileCopyrightText: 2023 The CC: Tweaked Developers +// +// SPDX-License-Identifier: MPL-2.0 + +package dan200.computercraft.api.filesystem; + +import java.nio.file.OpenOption; +import java.nio.file.StandardOpenOption; +import java.nio.file.attribute.BasicFileAttributes; +import java.nio.file.attribute.FileTime; +import java.time.Instant; +import java.util.List; +import java.util.Set; + +/** + * Useful constants functions for working with mounts. + * + * @see Mount + * @see WritableMount + */ +public final class MountConstants { + /** + * A {@link FileTime} set to the Unix EPOCH, intended for {@link BasicFileAttributes}'s file times. + */ + public static final FileTime EPOCH = FileTime.from(Instant.EPOCH); + + /** + * The minimum size of a file for file {@linkplain WritableMount#getCapacity() capacity calculations}. + */ + public static final long MINIMUM_FILE_SIZE = 500; + + /** + * The error message used when the file does not exist. + */ + public static final String NO_SUCH_FILE = "No such file"; + + /** + * The error message used when trying to use a file as a directory (for instance when + * {@linkplain Mount#list(String, List) listing its contents}). + */ + public static final String NOT_A_DIRECTORY = "Not a directory"; + + /** + * The error message used when trying to use a directory as a file (for instance when + * {@linkplain Mount#openForRead(String) opening for reading}). + */ + public static final String NOT_A_FILE = "Not a file"; + + /** + * The error message used when attempting to modify a read-only file or mount. + */ + public static final String ACCESS_DENIED = "Access denied"; + + /** + * The error message used when trying to overwrite a file (for instance when + * {@linkplain WritableMount#rename(String, String) renaming files} or {@linkplain WritableMount#makeDirectory(String) + * creating directories}). + */ + public static final String FILE_EXISTS = "File exists"; + + /** + * The error message used when trying to {@linkplain WritableMount#openForWrite(String) opening a directory to read}. + */ + public static final String CANNOT_WRITE_TO_DIRECTORY = "Cannot write to directory"; + + /** + * The error message used when the mount runs out of space. + */ + public static final String OUT_OF_SPACE = "Out of space"; + + /** + * The error message to throw when an unsupported set of options were passed to + * {@link WritableMount#openFile(String, Set)}. + */ + public static final String UNSUPPORTED_MODE = "Unsupported mode"; + + public static final Set READ_OPTIONS = Set.of(StandardOpenOption.READ); + + public static final Set WRITE_OPTIONS = Set.of(StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); + + public static final Set APPEND_OPTIONS = Set.of(StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.APPEND); + + private MountConstants() { + } +} diff --git a/projects/core-api/src/main/java/dan200/computercraft/api/filesystem/WritableMount.java b/projects/core-api/src/main/java/dan200/computercraft/api/filesystem/WritableMount.java index 9cdd2ea3d..918ae3402 100644 --- a/projects/core-api/src/main/java/dan200/computercraft/api/filesystem/WritableMount.java +++ b/projects/core-api/src/main/java/dan200/computercraft/api/filesystem/WritableMount.java @@ -7,8 +7,13 @@ package dan200.computercraft.api.filesystem; import dan200.computercraft.api.peripheral.IComputerAccess; import java.io.IOException; -import java.io.OutputStream; +import java.nio.channels.FileChannel; import java.nio.channels.SeekableByteChannel; +import java.nio.file.OpenOption; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; +import java.nio.file.attribute.FileAttribute; +import java.util.Set; /** * Represents a part of a virtual filesystem that can be mounted onto a computer using {@link IComputerAccess#mount(String, Mount)} @@ -51,22 +56,51 @@ public interface WritableMount extends Mount { void rename(String source, String dest) throws IOException; /** - * Opens a file with a given path, and returns an {@link OutputStream} for writing to it. + * Opens a file with a given path, and returns an {@link SeekableByteChannel} for writing to it. * * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram". - * @return A stream for writing to. + * @return A channel for writing to. * @throws IOException If the file could not be opened for writing. + * @deprecated Replaced with more the generic {@link #openFile(String, Set)}. */ + @Deprecated(forRemoval = true) SeekableByteChannel openForWrite(String path) throws IOException; /** - * Opens a file with a given path, and returns an {@link OutputStream} for appending to it. + * Opens a file with a given path, and returns an {@link SeekableByteChannel} for appending to it. * * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram". - * @return A stream for writing to. + * @return A channel for writing to. + * @throws IOException If the file could not be opened for writing. + * @deprecated Replaced with more the generic {@link #openFile(String, Set)}. + */ + @Deprecated(forRemoval = true) + SeekableByteChannel openForAppend(String path) throws IOException; + + /** + * Opens a file with a given path, and returns an {@link SeekableByteChannel}. + *

+ * This allows opening a file in a variety of options, much like {@link FileChannel#open(Path, Set, FileAttribute[])}. + *

+ * At minimum, the option sets {@link MountConstants#READ_OPTIONS}, {@link MountConstants#WRITE_OPTIONS} and + * {@link MountConstants#APPEND_OPTIONS} should be supported. It is recommended any valid combination of + * {@link StandardOpenOption#READ}, {@link StandardOpenOption#WRITE}, {@link StandardOpenOption#CREATE}, + * {@link StandardOpenOption#TRUNCATE_EXISTING} and {@link StandardOpenOption#APPEND} are supported. + *

+ * Unsupported modes (or combinations of modes) should throw an exception with the message + * {@link MountConstants#UNSUPPORTED_MODE "Unsupported mode"}. + * + * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram". + * @param options For options used for opening a file. + * @return A channel for writing to. * @throws IOException If the file could not be opened for writing. */ - SeekableByteChannel openForAppend(String path) throws IOException; + default SeekableByteChannel openFile(String path, Set options) throws IOException { + if (options.equals(MountConstants.READ_OPTIONS)) return openForRead(path); + if (options.equals(MountConstants.WRITE_OPTIONS)) return openForWrite(path); + if (options.equals(MountConstants.APPEND_OPTIONS)) return openForAppend(path); + throw new IOException(MountConstants.UNSUPPORTED_MODE); + } /** * Get the amount of free space on the mount, in bytes. You should decrease this value as the user writes to the diff --git a/projects/core-api/src/main/java/dan200/computercraft/api/lua/IArguments.java b/projects/core-api/src/main/java/dan200/computercraft/api/lua/IArguments.java index 336f0b926..fa0018ef7 100644 --- a/projects/core-api/src/main/java/dan200/computercraft/api/lua/IArguments.java +++ b/projects/core-api/src/main/java/dan200/computercraft/api/lua/IArguments.java @@ -195,6 +195,19 @@ public interface IArguments { return LuaValues.encode(getString(index)); } + /** + * Get the argument, converting it to the raw-byte representation of its string by following Lua conventions. + *

+ * This is equivalent to {@link #getStringCoerced(int)}, but then + * + * @param index The argument number. + * @return The argument's value. This is a read only buffer. + * @throws LuaException If the argument cannot be converted to Java. + */ + default ByteBuffer getBytesCoerced(int index) throws LuaException { + return LuaValues.encode(getStringCoerced(index)); + } + /** * Get a string argument as an enum value. * diff --git a/projects/core/src/main/java/dan200/computercraft/core/apis/FSAPI.java b/projects/core/src/main/java/dan200/computercraft/core/apis/FSAPI.java index 4e2f9b2ca..a359320dd 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/apis/FSAPI.java +++ b/projects/core/src/main/java/dan200/computercraft/core/apis/FSAPI.java @@ -4,22 +4,22 @@ package dan200.computercraft.core.apis; +import dan200.computercraft.api.filesystem.MountConstants; import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.ILuaAPI; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaFunction; -import dan200.computercraft.core.apis.handles.BinaryReadableHandle; -import dan200.computercraft.core.apis.handles.BinaryWritableHandle; -import dan200.computercraft.core.apis.handles.EncodedReadableHandle; -import dan200.computercraft.core.apis.handles.EncodedWritableHandle; +import dan200.computercraft.core.apis.handles.ReadHandle; +import dan200.computercraft.core.apis.handles.ReadWriteHandle; +import dan200.computercraft.core.apis.handles.WriteHandle; import dan200.computercraft.core.filesystem.FileSystem; import dan200.computercraft.core.filesystem.FileSystemException; import dan200.computercraft.core.metrics.Metrics; import javax.annotation.Nullable; -import java.util.HashMap; -import java.util.Map; -import java.util.function.Function; +import java.nio.file.OpenOption; +import java.nio.file.StandardOpenOption; +import java.util.*; /** * Interact with the computer's files and filesystem, allowing you to manipulate files, directories and paths. This @@ -55,6 +55,9 @@ import java.util.function.Function; * @cc.module fs */ public class FSAPI implements ILuaAPI { + private static final Set READ_EXTENDED = Set.of(StandardOpenOption.READ, StandardOpenOption.WRITE); + private static final Set WRITE_EXTENDED = union(Set.of(StandardOpenOption.READ), MountConstants.WRITE_OPTIONS); + private final IAPIEnvironment environment; private @Nullable FileSystem fileSystem = null; @@ -301,8 +304,6 @@ public class FSAPI implements ILuaAPI { } } - // FIXME: Add individual handle type documentation - /** * Opens a file for reading or writing at a path. *

@@ -311,10 +312,13 @@ public class FSAPI implements ILuaAPI { *

  • "r": Read mode
  • *
  • "w": Write mode
  • *
  • "a": Append mode
  • + *
  • "r+": Update mode (allows reading and writing), all data is preserved
  • + *
  • "w+": Update mode, all data is erased.
  • * *

    * The mode may also have a "b" at the end, which opens the file in "binary - * mode". This allows you to read binary files, as well as seek within a file. + * mode". This changes {@link ReadHandle#read(Optional)} and {@link WriteHandle#write(IArguments)} + * to read/write single bytes as numbers rather than strings. * * @param path The path to the file to open. * @param mode The mode to open the file with. @@ -354,42 +358,38 @@ public class FSAPI implements ILuaAPI { * file.write("Just testing some code") * file.close() -- Remember to call close, otherwise changes may not be written! * } + * @cc.changed 1.109.0 Add support for update modes ({@code r+} and {@code w+}). + * @cc.changed 1.109.0 Opening a file in non-binary mode now uses the raw bytes of the file rather than encoding to + * UTF-8. */ @LuaFunction public final Object[] open(String path, String mode) throws LuaException { + if (mode.isEmpty()) throw new LuaException(MountConstants.UNSUPPORTED_MODE); + + var binary = mode.indexOf('b') >= 0; try (var ignored = environment.time(Metrics.FS_OPS)) { switch (mode) { - case "r" -> { - // Open the file for reading, then create a wrapper around the reader - var reader = getFileSystem().openForRead(path, EncodedReadableHandle::openUtf8); - return new Object[]{ new EncodedReadableHandle(reader.get(), reader) }; + case "r", "rb" -> { + var reader = getFileSystem().openForRead(path); + return new Object[]{ new ReadHandle(reader.get(), reader, binary) }; } - case "w" -> { - // Open the file for writing, then create a wrapper around the writer - var writer = getFileSystem().openForWrite(path, false, EncodedWritableHandle::openUtf8); - return new Object[]{ new EncodedWritableHandle(writer.get(), writer) }; + case "w", "wb" -> { + var writer = getFileSystem().openForWrite(path, MountConstants.WRITE_OPTIONS); + return new Object[]{ WriteHandle.of(writer.get(), writer, binary, true) }; } - case "a" -> { - // Open the file for appending, then create a wrapper around the writer - var writer = getFileSystem().openForWrite(path, true, EncodedWritableHandle::openUtf8); - return new Object[]{ new EncodedWritableHandle(writer.get(), writer) }; + case "a", "ab" -> { + var writer = getFileSystem().openForWrite(path, MountConstants.APPEND_OPTIONS); + return new Object[]{ WriteHandle.of(writer.get(), writer, binary, false) }; } - case "rb" -> { - // Open the file for binary reading, then create a wrapper around the reader - var reader = getFileSystem().openForRead(path, Function.identity()); - return new Object[]{ BinaryReadableHandle.of(reader.get(), reader) }; + case "r+", "r+b" -> { + var reader = getFileSystem().openForWrite(path, READ_EXTENDED); + return new Object[]{ new ReadWriteHandle(reader.get(), reader, binary) }; } - case "wb" -> { - // Open the file for binary writing, then create a wrapper around the writer - var writer = getFileSystem().openForWrite(path, false, Function.identity()); - return new Object[]{ BinaryWritableHandle.of(writer.get(), writer, true) }; + case "w+", "w+b" -> { + var writer = getFileSystem().openForWrite(path, WRITE_EXTENDED); + return new Object[]{ new ReadWriteHandle(writer.get(), writer, binary) }; } - case "ab" -> { - // Open the file for binary appending, then create a wrapper around the reader - var writer = getFileSystem().openForWrite(path, true, Function.identity()); - return new Object[]{ BinaryWritableHandle.of(writer.get(), writer, false) }; - } - default -> throw new LuaException("Unsupported mode"); + default -> throw new LuaException(MountConstants.UNSUPPORTED_MODE); } } catch (FileSystemException e) { return new Object[]{ null, e.getMessage() }; @@ -498,4 +498,11 @@ public class FSAPI implements ILuaAPI { throw new LuaException(e.getMessage()); } } + + private static Set union(Set a, Set b) { + Set union = new HashSet<>(); + union.addAll(a); + union.addAll(b); + return Set.copyOf(union); + } } diff --git a/projects/core/src/main/java/dan200/computercraft/core/apis/HTTPAPI.java b/projects/core/src/main/java/dan200/computercraft/core/apis/HTTPAPI.java index 65ef1f966..4e198b4cc 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/apis/HTTPAPI.java +++ b/projects/core/src/main/java/dan200/computercraft/core/apis/HTTPAPI.java @@ -4,10 +4,7 @@ package dan200.computercraft.core.apis; -import dan200.computercraft.api.lua.IArguments; -import dan200.computercraft.api.lua.ILuaAPI; -import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.lua.LuaFunction; +import dan200.computercraft.api.lua.*; import dan200.computercraft.core.CoreConfig; import dan200.computercraft.core.apis.http.*; import dan200.computercraft.core.apis.http.request.HttpRequest; @@ -18,6 +15,7 @@ import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpMethod; +import java.nio.ByteBuffer; import java.util.Locale; import java.util.Map; import java.util.Optional; @@ -73,7 +71,8 @@ public class HTTPAPI implements ILuaAPI { @LuaFunction public final Object[] request(IArguments args) throws LuaException { - String address, postString, requestMethod; + String address, requestMethod; + ByteBuffer postBody; Map headerTable; boolean binary, redirect; Optional timeoutArg; @@ -81,7 +80,8 @@ public class HTTPAPI implements ILuaAPI { if (args.get(0) instanceof Map) { var options = args.getTable(0); address = getStringField(options, "url"); - postString = optStringField(options, "body", null); + var postString = optStringField(options, "body", null); + postBody = postString == null ? null : LuaValues.encode(postString); headerTable = optTableField(options, "headers", Map.of()); binary = optBooleanField(options, "binary", false); requestMethod = optStringField(options, "method", null); @@ -90,7 +90,7 @@ public class HTTPAPI implements ILuaAPI { } else { // Get URL and post information address = args.getString(0); - postString = args.optString(1, null); + postBody = args.optBytes(1).orElse(null); headerTable = args.optTable(2, Map.of()); binary = args.optBoolean(3, false); requestMethod = null; @@ -103,7 +103,7 @@ public class HTTPAPI implements ILuaAPI { HttpMethod httpMethod; if (requestMethod == null) { - httpMethod = postString == null ? HttpMethod.GET : HttpMethod.POST; + httpMethod = postBody == null ? HttpMethod.GET : HttpMethod.POST; } else { httpMethod = HttpMethod.valueOf(requestMethod.toUpperCase(Locale.ROOT)); if (httpMethod == null || requestMethod.equalsIgnoreCase("CONNECT")) { @@ -113,7 +113,7 @@ public class HTTPAPI implements ILuaAPI { try { var uri = HttpRequest.checkUri(address); - var request = new HttpRequest(requests, apiEnvironment, address, postString, headers, binary, redirect, timeout); + var request = new HttpRequest(requests, apiEnvironment, address, postBody, headers, binary, redirect, timeout); // Make the request if (!request.queue(r -> r.request(uri, httpMethod))) { diff --git a/projects/core/src/main/java/dan200/computercraft/core/apis/handles/BinaryReadableHandle.java b/projects/core/src/main/java/dan200/computercraft/core/apis/handles/AbstractHandle.java similarity index 64% rename from projects/core/src/main/java/dan200/computercraft/core/apis/handles/BinaryReadableHandle.java rename to projects/core/src/main/java/dan200/computercraft/core/apis/handles/AbstractHandle.java index a1b1acb29..51a4864db 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/apis/handles/BinaryReadableHandle.java +++ b/projects/core/src/main/java/dan200/computercraft/core/apis/handles/AbstractHandle.java @@ -1,45 +1,100 @@ -// SPDX-FileCopyrightText: 2018 The CC: Tweaked Developers +// SPDX-FileCopyrightText: 2017 The CC: Tweaked Developers // // SPDX-License-Identifier: MPL-2.0 package dan200.computercraft.core.apis.handles; +import dan200.computercraft.api.lua.Coerced; +import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.core.filesystem.TrackingCloseable; +import dan200.computercraft.core.util.IoUtil; import javax.annotation.Nullable; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; import java.nio.channels.SeekableByteChannel; import java.util.ArrayList; import java.util.List; import java.util.Optional; /** - * A file handle opened with {@link dan200.computercraft.core.apis.FSAPI#open(String, String)} with the {@code "rb"} - * mode. - * - * @cc.module fs.BinaryReadHandle + * The base class for all file handle types. */ -public class BinaryReadableHandle extends HandleGeneric { +public abstract class AbstractHandle { private static final int BUFFER_SIZE = 8192; private final SeekableByteChannel channel; + private @Nullable TrackingCloseable closeable; + protected final boolean binary; + private final ByteBuffer single = ByteBuffer.allocate(1); - BinaryReadableHandle(SeekableByteChannel channel, TrackingCloseable closeable) { - super(closeable); + protected AbstractHandle(SeekableByteChannel channel, TrackingCloseable closeable, boolean binary) { this.channel = channel; + this.closeable = closeable; + this.binary = binary; } - public static BinaryReadableHandle of(SeekableByteChannel channel, TrackingCloseable closeable) { - return new BinaryReadableHandle(channel, closeable); + protected void checkOpen() throws LuaException { + var closeable = this.closeable; + if (closeable == null || !closeable.isOpen()) throw new LuaException("attempt to use a closed file"); } - public static BinaryReadableHandle of(SeekableByteChannel channel) { - return of(channel, new TrackingCloseable.Impl(channel)); + /** + * Close this file, freeing any resources it uses. + *

    + * Once a file is closed it may no longer be read or written to. + * + * @throws LuaException If the file has already been closed. + */ + @LuaFunction + public final void close() throws LuaException { + checkOpen(); + IoUtil.closeQuietly(closeable); + closeable = null; + } + + /** + * Seek to a new position within the file, changing where bytes are written to. The new position is an offset + * given by {@code offset}, relative to a start position determined by {@code whence}: + *

    + * - {@code "set"}: {@code offset} is relative to the beginning of the file. + * - {@code "cur"}: Relative to the current position. This is the default. + * - {@code "end"}: Relative to the end of the file. + *

    + * In case of success, {@code seek} returns the new file position from the beginning of the file. + * + * @param whence Where the offset is relative to. + * @param offset The offset to seek to. + * @return The new position. + * @throws LuaException If the file has been closed. + * @cc.treturn [1] number The new position. + * @cc.treturn [2] nil If seeking failed. + * @cc.treturn string The reason seeking failed. + * @cc.since 1.80pr1.9 + */ + @Nullable + public Object[] seek(Optional whence, Optional offset) throws LuaException { + checkOpen(); + long actualOffset = offset.orElse(0L); + try { + switch (whence.orElse("cur")) { + case "set" -> channel.position(actualOffset); + case "cur" -> channel.position(channel.position() + actualOffset); + case "end" -> channel.position(channel.size() + actualOffset); + default -> throw new LuaException("bad argument #1 to 'seek' (invalid option '" + whence + "'"); + } + + return new Object[]{ channel.position() }; + } catch (IllegalArgumentException e) { + return new Object[]{ null, "Position is negative" }; + } catch (IOException e) { + return null; + } } /** @@ -51,17 +106,21 @@ public class BinaryReadableHandle extends HandleGeneric { * @throws LuaException When trying to read a negative number of bytes. * @throws LuaException If the file has been closed. * @cc.treturn [1] nil If we are at the end of the file. - * @cc.treturn [2] number The value of the byte read. This is returned when the {@code count} is absent. + * @cc.treturn [2] number The value of the byte read. This is returned if the file is opened in binary mode and + * {@code count} is absent * @cc.treturn [3] string The bytes read as a string. This is returned when the {@code count} is given. * @cc.changed 1.80pr1 Now accepts an integer argument to read multiple bytes, returning a string instead of a number. */ @Nullable - @LuaFunction - public final Object[] read(Optional countArg) throws LuaException { + public Object[] read(Optional countArg) throws LuaException { checkOpen(); try { - if (countArg.isPresent()) { - int count = countArg.get(); + if (binary && countArg.isEmpty()) { + single.clear(); + var b = channel.read(single); + return b == -1 ? null : new Object[]{ single.get(0) & 0xFF }; + } else { + int count = countArg.orElse(1); if (count < 0) throw new LuaException("Cannot read a negative number of bytes"); if (count == 0) return channel.position() >= channel.size() ? null : new Object[]{ "" }; @@ -109,10 +168,6 @@ public class BinaryReadableHandle extends HandleGeneric { assert pos == totalRead; return new Object[]{ bytes }; } - } else { - single.clear(); - var b = channel.read(single); - return b == -1 ? null : new Object[]{ single.get(0) & 0xFF }; } } catch (IOException e) { return null; @@ -128,8 +183,7 @@ public class BinaryReadableHandle extends HandleGeneric { * @cc.since 1.80pr1 */ @Nullable - @LuaFunction - public final Object[] readAll() throws LuaException { + public Object[] readAll() throws LuaException { checkOpen(); try { var expected = 32; @@ -137,16 +191,14 @@ public class BinaryReadableHandle extends HandleGeneric { var stream = new ByteArrayOutputStream(expected); var buf = ByteBuffer.allocate(8192); - var readAnything = false; while (true) { buf.clear(); var r = channel.read(buf); if (r == -1) break; - readAnything = true; stream.write(buf.array(), 0, r); } - return readAnything ? new Object[]{ stream.toByteArray() } : null; + return new Object[]{ stream.toByteArray() }; } catch (IOException e) { return null; } @@ -163,8 +215,7 @@ public class BinaryReadableHandle extends HandleGeneric { * @cc.changed 1.81.0 `\r` is now stripped. */ @Nullable - @LuaFunction - public final Object[] readLine(Optional withTrailingArg) throws LuaException { + public Object[] readLine(Optional withTrailingArg) throws LuaException { checkOpen(); boolean withTrailing = withTrailingArg.orElse(false); try { @@ -206,28 +257,64 @@ public class BinaryReadableHandle extends HandleGeneric { } /** - * Seek to a new position within the file, changing where bytes are written to. The new position is an offset - * given by {@code offset}, relative to a start position determined by {@code whence}: - *

    - * - {@code "set"}: {@code offset} is relative to the beginning of the file. - * - {@code "cur"}: Relative to the current position. This is the default. - * - {@code "end"}: Relative to the end of the file. - *

    - * In case of success, {@code seek} returns the new file position from the beginning of the file. + * Write a string or byte to the file. * - * @param whence Where the offset is relative to. - * @param offset The offset to seek to. - * @return The new position. + * @param arguments The value to write. * @throws LuaException If the file has been closed. - * @cc.treturn [1] number The new position. - * @cc.treturn [2] nil If seeking failed. - * @cc.treturn string The reason seeking failed. - * @cc.since 1.80pr1.9 + * @cc.tparam [1] string contents The string to write. + * @cc.tparam [2] number charcode The byte to write, if the file was opened in binary mode. + * @cc.changed 1.80pr1 Now accepts a string to write multiple bytes. */ - @Nullable - @LuaFunction - public final Object[] seek(Optional whence, Optional offset) throws LuaException { + public void write(IArguments arguments) throws LuaException { checkOpen(); - return handleSeek(channel, whence, offset); + try { + var arg = arguments.get(0); + if (binary && arg instanceof Number) { + var number = ((Number) arg).intValue(); + writeSingle((byte) number); + } else { + channel.write(arguments.getBytesCoerced(0)); + } + } catch (IOException e) { + throw new LuaException(e.getMessage()); + } + } + + /** + * Write a string of characters to the file, following them with a new line character. + * + * @param text The text to write to the file. + * @throws LuaException If the file has been closed. + */ + public void writeLine(Coerced text) throws LuaException { + checkOpen(); + try { + channel.write(text.value()); + writeSingle((byte) '\n'); + } catch (IOException e) { + throw new LuaException(e.getMessage()); + } + } + + private void writeSingle(byte value) throws IOException { + single.clear(); + single.put(value); + single.flip(); + channel.write(single); + } + + /** + * Save the current file without closing it. + * + * @throws LuaException If the file has been closed. + */ + public void flush() throws LuaException { + checkOpen(); + try { + // Technically this is not needed + if (channel instanceof FileChannel channel) channel.force(false); + } catch (IOException e) { + throw new LuaException(e.getMessage()); + } } } diff --git a/projects/core/src/main/java/dan200/computercraft/core/apis/handles/BinaryWritableHandle.java b/projects/core/src/main/java/dan200/computercraft/core/apis/handles/BinaryWritableHandle.java deleted file mode 100644 index dfcf8bb45..000000000 --- a/projects/core/src/main/java/dan200/computercraft/core/apis/handles/BinaryWritableHandle.java +++ /dev/null @@ -1,117 +0,0 @@ -// SPDX-FileCopyrightText: 2017 The CC: Tweaked Developers -// -// SPDX-License-Identifier: MPL-2.0 - -package dan200.computercraft.core.apis.handles; - -import dan200.computercraft.api.lua.IArguments; -import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.lua.LuaFunction; -import dan200.computercraft.api.lua.LuaValues; -import dan200.computercraft.core.filesystem.TrackingCloseable; - -import javax.annotation.Nullable; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; -import java.nio.channels.SeekableByteChannel; -import java.util.Optional; - -/** - * A file handle opened by {@link dan200.computercraft.core.apis.FSAPI#open} using the {@code "wb"} or {@code "ab"} - * modes. - * - * @cc.module fs.BinaryWriteHandle - */ -public class BinaryWritableHandle extends HandleGeneric { - final SeekableByteChannel channel; - private final ByteBuffer single = ByteBuffer.allocate(1); - - protected BinaryWritableHandle(SeekableByteChannel channel, TrackingCloseable closeable) { - super(closeable); - this.channel = channel; - } - - public static BinaryWritableHandle of(SeekableByteChannel channel, TrackingCloseable closeable, boolean canSeek) { - return canSeek ? new Seekable(channel, closeable) : new BinaryWritableHandle(channel, closeable); - } - - /** - * Write a string or byte to the file. - * - * @param arguments The value to write. - * @throws LuaException If the file has been closed. - * @cc.tparam [1] number charcode The byte to write. - * @cc.tparam [2] string contents The string to write. - * @cc.changed 1.80pr1 Now accepts a string to write multiple bytes. - */ - @LuaFunction - public final void write(IArguments arguments) throws LuaException { - checkOpen(); - try { - var arg = arguments.get(0); - if (arg instanceof Number) { - var number = ((Number) arg).intValue(); - single.clear(); - single.put((byte) number); - single.flip(); - - channel.write(single); - } else if (arg instanceof String) { - channel.write(arguments.getBytes(0)); - } else { - throw LuaValues.badArgumentOf(arguments, 0, "string or number"); - } - } catch (IOException e) { - throw new LuaException(e.getMessage()); - } - } - - /** - * Save the current file without closing it. - * - * @throws LuaException If the file has been closed. - */ - @LuaFunction - public final void flush() throws LuaException { - checkOpen(); - try { - // Technically this is not needed - if (channel instanceof FileChannel channel) channel.force(false); - } catch (IOException e) { - throw new LuaException(e.getMessage()); - } - } - - public static class Seekable extends BinaryWritableHandle { - public Seekable(SeekableByteChannel channel, TrackingCloseable closeable) { - super(channel, closeable); - } - - /** - * Seek to a new position within the file, changing where bytes are written to. The new position is an offset - * given by {@code offset}, relative to a start position determined by {@code whence}: - *

    - * - {@code "set"}: {@code offset} is relative to the beginning of the file. - * - {@code "cur"}: Relative to the current position. This is the default. - * - {@code "end"}: Relative to the end of the file. - *

    - * In case of success, {@code seek} returns the new file position from the beginning of the file. - * - * @param whence Where the offset is relative to. - * @param offset The offset to seek to. - * @return The new position. - * @throws LuaException If the file has been closed. - * @cc.treturn [1] number The new position. - * @cc.treturn [2] nil If seeking failed. - * @cc.treturn string The reason seeking failed. - * @cc.since 1.80pr1.9 - */ - @Nullable - @LuaFunction - public final Object[] seek(Optional whence, Optional offset) throws LuaException { - checkOpen(); - return handleSeek(channel, whence, offset); - } - } -} diff --git a/projects/core/src/main/java/dan200/computercraft/core/apis/handles/EncodedReadableHandle.java b/projects/core/src/main/java/dan200/computercraft/core/apis/handles/EncodedReadableHandle.java deleted file mode 100644 index 2a113b74b..000000000 --- a/projects/core/src/main/java/dan200/computercraft/core/apis/handles/EncodedReadableHandle.java +++ /dev/null @@ -1,163 +0,0 @@ -// SPDX-FileCopyrightText: 2018 The CC: Tweaked Developers -// -// SPDX-License-Identifier: MPL-2.0 - -package dan200.computercraft.core.apis.handles; - -import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.lua.LuaFunction; -import dan200.computercraft.core.filesystem.TrackingCloseable; - -import javax.annotation.Nullable; -import java.io.BufferedReader; -import java.io.IOException; -import java.nio.channels.Channels; -import java.nio.channels.ReadableByteChannel; -import java.nio.charset.Charset; -import java.nio.charset.CodingErrorAction; -import java.nio.charset.StandardCharsets; -import java.util.Optional; - -/** - * A file handle opened with {@link dan200.computercraft.core.apis.FSAPI#open(String, String)} with the {@code "r"} - * mode. - * - * @cc.module fs.ReadHandle - */ -public class EncodedReadableHandle extends HandleGeneric { - private static final int BUFFER_SIZE = 8192; - - private final BufferedReader reader; - - public EncodedReadableHandle(BufferedReader reader, TrackingCloseable closable) { - super(closable); - this.reader = reader; - } - - public EncodedReadableHandle(BufferedReader reader) { - this(reader, new TrackingCloseable.Impl(reader)); - } - - /** - * Read a line from the file. - * - * @param withTrailingArg Whether to include the newline characters with the returned string. Defaults to {@code false}. - * @return The read string. - * @throws LuaException If the file has been closed. - * @cc.treturn string|nil The read line or {@code nil} if at the end of the file. - * @cc.changed 1.81.0 Added option to return trailing newline. - */ - @Nullable - @LuaFunction - public final Object[] readLine(Optional withTrailingArg) throws LuaException { - checkOpen(); - boolean withTrailing = withTrailingArg.orElse(false); - try { - var line = reader.readLine(); - if (line != null) { - // While this is technically inaccurate, it's better than nothing - if (withTrailing) line += "\n"; - return new Object[]{ line }; - } else { - return null; - } - } catch (IOException e) { - return null; - } - } - - /** - * Read the remainder of the file. - * - * @return The file, or {@code null} if at the end of it. - * @throws LuaException If the file has been closed. - * @cc.treturn nil|string The remaining contents of the file, or {@code nil} if we are at the end. - */ - @Nullable - @LuaFunction - public final Object[] readAll() throws LuaException { - checkOpen(); - try { - var result = new StringBuilder(); - var line = reader.readLine(); - while (line != null) { - result.append(line); - line = reader.readLine(); - if (line != null) { - result.append("\n"); - } - } - return new Object[]{ result.toString() }; - } catch (IOException e) { - return null; - } - } - - /** - * Read a number of characters from this file. - * - * @param countA The number of characters to read, defaulting to 1. - * @return The read characters. - * @throws LuaException When trying to read a negative number of characters. - * @throws LuaException If the file has been closed. - * @cc.treturn string|nil The read characters, or {@code nil} if at the of the file. - * @cc.since 1.80pr1.4 - */ - @Nullable - @LuaFunction - public final Object[] read(Optional countA) throws LuaException { - checkOpen(); - try { - int count = countA.orElse(1); - if (count < 0) { - // Whilst this may seem absurd to allow reading 0 characters, PUC Lua it so - // it seems best to remain somewhat consistent. - throw new LuaException("Cannot read a negative number of characters"); - } else if (count <= BUFFER_SIZE) { - // If we've got a small count, then allocate that and read it. - var chars = new char[count]; - var read = reader.read(chars); - - return read < 0 ? null : new Object[]{ new String(chars, 0, read) }; - } else { - // If we've got a large count, read in bunches of 8192. - var buffer = new char[BUFFER_SIZE]; - - // Read the initial set of characters, failing if none are read. - var read = reader.read(buffer, 0, Math.min(buffer.length, count)); - if (read < 0) return null; - - var out = new StringBuilder(read); - var totalRead = read; - out.append(buffer, 0, read); - - // Otherwise read until we either reach the limit or we no longer consume - // the full buffer. - while (read >= BUFFER_SIZE && totalRead < count) { - read = reader.read(buffer, 0, Math.min(BUFFER_SIZE, count - totalRead)); - if (read < 0) break; - - totalRead += read; - out.append(buffer, 0, read); - } - - return new Object[]{ out.toString() }; - } - } catch (IOException e) { - return null; - } - } - - public static BufferedReader openUtf8(ReadableByteChannel channel) { - return open(channel, StandardCharsets.UTF_8); - } - - public static BufferedReader open(ReadableByteChannel channel, Charset charset) { - // Create a charset decoder with the same properties as StreamDecoder does for - // InputStreams: namely, replace everything instead of erroring. - var decoder = charset.newDecoder() - .onMalformedInput(CodingErrorAction.REPLACE) - .onUnmappableCharacter(CodingErrorAction.REPLACE); - return new BufferedReader(Channels.newReader(channel, decoder, -1)); - } -} diff --git a/projects/core/src/main/java/dan200/computercraft/core/apis/handles/EncodedWritableHandle.java b/projects/core/src/main/java/dan200/computercraft/core/apis/handles/EncodedWritableHandle.java deleted file mode 100644 index fda4ccde3..000000000 --- a/projects/core/src/main/java/dan200/computercraft/core/apis/handles/EncodedWritableHandle.java +++ /dev/null @@ -1,95 +0,0 @@ -// SPDX-FileCopyrightText: 2017 The CC: Tweaked Developers -// -// SPDX-License-Identifier: MPL-2.0 - -package dan200.computercraft.core.apis.handles; - -import dan200.computercraft.api.lua.Coerced; -import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.lua.LuaFunction; -import dan200.computercraft.core.filesystem.TrackingCloseable; - -import java.io.BufferedWriter; -import java.io.IOException; -import java.nio.channels.Channels; -import java.nio.channels.WritableByteChannel; -import java.nio.charset.Charset; -import java.nio.charset.CodingErrorAction; -import java.nio.charset.StandardCharsets; - -/** - * A file handle opened by {@link dan200.computercraft.core.apis.FSAPI#open} using the {@code "w"} or {@code "a"} modes. - * - * @cc.module fs.WriteHandle - */ -public class EncodedWritableHandle extends HandleGeneric { - private final BufferedWriter writer; - - public EncodedWritableHandle(BufferedWriter writer, TrackingCloseable closable) { - super(closable); - this.writer = writer; - } - - /** - * Write a string of characters to the file. - * - * @param textA The text to write to the file. - * @throws LuaException If the file has been closed. - */ - @LuaFunction - public final void write(Coerced textA) throws LuaException { - checkOpen(); - var text = textA.value(); - try { - writer.write(text, 0, text.length()); - } catch (IOException e) { - throw new LuaException(e.getMessage()); - } - } - - /** - * Write a string of characters to the file, following them with a new line character. - * - * @param textA The text to write to the file. - * @throws LuaException If the file has been closed. - */ - @LuaFunction - public final void writeLine(Coerced textA) throws LuaException { - checkOpen(); - var text = textA.value(); - try { - writer.write(text, 0, text.length()); - writer.newLine(); - } catch (IOException e) { - throw new LuaException(e.getMessage()); - } - } - - /** - * Save the current file without closing it. - * - * @throws LuaException If the file has been closed. - */ - @LuaFunction - public final void flush() throws LuaException { - checkOpen(); - try { - writer.flush(); - } catch (IOException e) { - throw new LuaException(e.getMessage()); - } - } - - public static BufferedWriter openUtf8(WritableByteChannel channel) { - return open(channel, StandardCharsets.UTF_8); - } - - public static BufferedWriter open(WritableByteChannel channel, Charset charset) { - // Create a charset encoder with the same properties as StreamEncoder does for - // OutputStreams: namely, replace everything instead of erroring. - var encoder = charset.newEncoder() - .onMalformedInput(CodingErrorAction.REPLACE) - .onUnmappableCharacter(CodingErrorAction.REPLACE); - return new BufferedWriter(Channels.newWriter(channel, encoder, -1)); - } -} diff --git a/projects/core/src/main/java/dan200/computercraft/core/apis/handles/HandleGeneric.java b/projects/core/src/main/java/dan200/computercraft/core/apis/handles/HandleGeneric.java deleted file mode 100644 index 617e5bddd..000000000 --- a/projects/core/src/main/java/dan200/computercraft/core/apis/handles/HandleGeneric.java +++ /dev/null @@ -1,76 +0,0 @@ -// SPDX-FileCopyrightText: 2017 The CC: Tweaked Developers -// -// SPDX-License-Identifier: MPL-2.0 - -package dan200.computercraft.core.apis.handles; - -import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.lua.LuaFunction; -import dan200.computercraft.core.filesystem.TrackingCloseable; -import dan200.computercraft.core.util.IoUtil; - -import javax.annotation.Nullable; -import java.io.IOException; -import java.nio.channels.SeekableByteChannel; -import java.util.Optional; - -public abstract class HandleGeneric { - private @Nullable TrackingCloseable closeable; - - protected HandleGeneric(TrackingCloseable closeable) { - this.closeable = closeable; - } - - protected void checkOpen() throws LuaException { - var closeable = this.closeable; - if (closeable == null || !closeable.isOpen()) throw new LuaException("attempt to use a closed file"); - } - - protected final void close() { - IoUtil.closeQuietly(closeable); - closeable = null; - } - - /** - * Close this file, freeing any resources it uses. - *

    - * Once a file is closed it may no longer be read or written to. - * - * @throws LuaException If the file has already been closed. - */ - @LuaFunction("close") - public final void doClose() throws LuaException { - checkOpen(); - close(); - } - - - /** - * Shared implementation for various file handle types. - * - * @param channel The channel to seek in - * @param whence The seeking mode. - * @param offset The offset to seek to. - * @return The new position of the file, or null if some error occurred. - * @throws LuaException If the arguments were invalid - * @see {@code file:seek} in the Lua manual. - */ - @Nullable - protected static Object[] handleSeek(SeekableByteChannel channel, Optional whence, Optional offset) throws LuaException { - long actualOffset = offset.orElse(0L); - try { - switch (whence.orElse("cur")) { - case "set" -> channel.position(actualOffset); - case "cur" -> channel.position(channel.position() + actualOffset); - case "end" -> channel.position(channel.size() + actualOffset); - default -> throw new LuaException("bad argument #1 to 'seek' (invalid option '" + whence + "'"); - } - - return new Object[]{ channel.position() }; - } catch (IllegalArgumentException e) { - return new Object[]{ null, "Position is negative" }; - } catch (IOException e) { - return null; - } - } -} diff --git a/projects/core/src/main/java/dan200/computercraft/core/apis/handles/ReadHandle.java b/projects/core/src/main/java/dan200/computercraft/core/apis/handles/ReadHandle.java new file mode 100644 index 000000000..8a7b1b3b7 --- /dev/null +++ b/projects/core/src/main/java/dan200/computercraft/core/apis/handles/ReadHandle.java @@ -0,0 +1,68 @@ +// SPDX-FileCopyrightText: 2018 The CC: Tweaked Developers +// +// SPDX-License-Identifier: MPL-2.0 + +package dan200.computercraft.core.apis.handles; + +import dan200.computercraft.api.lua.LuaException; +import dan200.computercraft.api.lua.LuaFunction; +import dan200.computercraft.core.filesystem.TrackingCloseable; + +import javax.annotation.Nullable; +import java.nio.channels.SeekableByteChannel; +import java.util.Optional; + +/** + * A file handle opened for reading with {@link dan200.computercraft.core.apis.FSAPI#open(String, String)}. + * + * @cc.module fs.ReadHandle + */ +public class ReadHandle extends AbstractHandle { + public ReadHandle(SeekableByteChannel channel, TrackingCloseable closeable, boolean binary) { + super(channel, closeable, binary); + } + + public ReadHandle(SeekableByteChannel channel, boolean binary) { + this(channel, new TrackingCloseable.Impl(channel), binary); + } + + /** + * {@inheritDoc} + */ + @Nullable + @Override + @LuaFunction + public final Object[] read(Optional countArg) throws LuaException { + return super.read(countArg); + } + + /** + * {@inheritDoc} + */ + @Nullable + @Override + @LuaFunction + public final Object[] readAll() throws LuaException { + return super.readAll(); + } + + /** + * {@inheritDoc} + */ + @Nullable + @Override + @LuaFunction + public final Object[] readLine(Optional withTrailingArg) throws LuaException { + return super.readLine(withTrailingArg); + } + + /** + * {@inheritDoc} + */ + @Nullable + @Override + @LuaFunction + public final Object[] seek(Optional whence, Optional offset) throws LuaException { + return super.seek(whence, offset); + } +} diff --git a/projects/core/src/main/java/dan200/computercraft/core/apis/handles/ReadWriteHandle.java b/projects/core/src/main/java/dan200/computercraft/core/apis/handles/ReadWriteHandle.java new file mode 100644 index 000000000..d295a3763 --- /dev/null +++ b/projects/core/src/main/java/dan200/computercraft/core/apis/handles/ReadWriteHandle.java @@ -0,0 +1,96 @@ +// SPDX-FileCopyrightText: 2018 The CC: Tweaked Developers +// +// SPDX-License-Identifier: MPL-2.0 + +package dan200.computercraft.core.apis.handles; + +import dan200.computercraft.api.lua.Coerced; +import dan200.computercraft.api.lua.IArguments; +import dan200.computercraft.api.lua.LuaException; +import dan200.computercraft.api.lua.LuaFunction; +import dan200.computercraft.core.filesystem.TrackingCloseable; + +import javax.annotation.Nullable; +import java.nio.ByteBuffer; +import java.nio.channels.SeekableByteChannel; +import java.util.Optional; + +/** + * A file handle opened for reading and writing with {@link dan200.computercraft.core.apis.FSAPI#open(String, String)}. + * + * @cc.module fs.ReadWriteHandle + */ +public class ReadWriteHandle extends AbstractHandle { + public ReadWriteHandle(SeekableByteChannel channel, TrackingCloseable closeable, boolean binary) { + super(channel, closeable, binary); + } + + /** + * {@inheritDoc} + */ + @Nullable + @Override + @LuaFunction + public final Object[] read(Optional countArg) throws LuaException { + return super.read(countArg); + } + + /** + * {@inheritDoc} + */ + @Nullable + @Override + @LuaFunction + public final Object[] readAll() throws LuaException { + return super.readAll(); + } + + /** + * {@inheritDoc} + */ + @Nullable + @Override + @LuaFunction + public final Object[] readLine(Optional withTrailingArg) throws LuaException { + return super.readLine(withTrailingArg); + } + + /** + * {@inheritDoc} + */ + @Nullable + @Override + @LuaFunction + public final Object[] seek(Optional whence, Optional offset) throws LuaException { + return super.seek(whence, offset); + } + + /** + * {@inheritDoc} + */ + @Override + @LuaFunction + public final void write(IArguments arguments) throws LuaException { + super.write(arguments); + } + + /** + * {@inheritDoc} + */ + @Override + @LuaFunction + public final void writeLine(Coerced text) throws LuaException { + super.writeLine(text); + } + + /** + * {@inheritDoc} + */ + @Override + @LuaFunction + public final void flush() throws LuaException { + super.flush(); + } + + +} diff --git a/projects/core/src/main/java/dan200/computercraft/core/apis/handles/WriteHandle.java b/projects/core/src/main/java/dan200/computercraft/core/apis/handles/WriteHandle.java new file mode 100644 index 000000000..c91bf37ac --- /dev/null +++ b/projects/core/src/main/java/dan200/computercraft/core/apis/handles/WriteHandle.java @@ -0,0 +1,74 @@ +// SPDX-FileCopyrightText: 2017 The CC: Tweaked Developers +// +// SPDX-License-Identifier: MPL-2.0 + +package dan200.computercraft.core.apis.handles; + +import dan200.computercraft.api.lua.Coerced; +import dan200.computercraft.api.lua.IArguments; +import dan200.computercraft.api.lua.LuaException; +import dan200.computercraft.api.lua.LuaFunction; +import dan200.computercraft.core.filesystem.TrackingCloseable; + +import javax.annotation.Nullable; +import java.nio.ByteBuffer; +import java.nio.channels.SeekableByteChannel; +import java.util.Optional; + +/** + * A file handle opened for writing by {@link dan200.computercraft.core.apis.FSAPI#open}. + * + * @cc.module fs.WriteHandle + */ +public class WriteHandle extends AbstractHandle { + protected WriteHandle(SeekableByteChannel channel, TrackingCloseable closeable, boolean binary) { + super(channel, closeable, binary); + } + + public static WriteHandle of(SeekableByteChannel channel, TrackingCloseable closeable, boolean binary, boolean canSeek) { + return canSeek ? new Seekable(channel, closeable, binary) : new WriteHandle(channel, closeable, binary); + } + + /** + * {@inheritDoc} + */ + @Override + @LuaFunction + public final void write(IArguments arguments) throws LuaException { + super.write(arguments); + } + + /** + * {@inheritDoc} + */ + @Override + @LuaFunction + public final void writeLine(Coerced text) throws LuaException { + super.writeLine(text); + } + + /** + * {@inheritDoc} + */ + @Override + @LuaFunction + public final void flush() throws LuaException { + super.flush(); + } + + public static class Seekable extends WriteHandle { + Seekable(SeekableByteChannel channel, TrackingCloseable closeable, boolean binary) { + super(channel, closeable, binary); + } + + /** + * {@inheritDoc} + */ + @Nullable + @Override + @LuaFunction + public final Object[] seek(Optional whence, Optional offset) throws LuaException { + return super.seek(whence, offset); + } + } +} diff --git a/projects/core/src/main/java/dan200/computercraft/core/apis/http/request/HttpRequest.java b/projects/core/src/main/java/dan200/computercraft/core/apis/http/request/HttpRequest.java index 24e83c013..fb28284e2 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/apis/http/request/HttpRequest.java +++ b/projects/core/src/main/java/dan200/computercraft/core/apis/http/request/HttpRequest.java @@ -26,7 +26,7 @@ import org.slf4j.LoggerFactory; import javax.annotation.Nullable; import java.net.URI; import java.net.URISyntaxException; -import java.nio.charset.StandardCharsets; +import java.nio.ByteBuffer; import java.util.Locale; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -57,21 +57,21 @@ public class HttpRequest extends Resource { final AtomicInteger redirects; public HttpRequest( - ResourceGroup limiter, IAPIEnvironment environment, String address, @Nullable String postText, + ResourceGroup limiter, IAPIEnvironment environment, String address, @Nullable ByteBuffer postBody, HttpHeaders headers, boolean binary, boolean followRedirects, int timeout ) { super(limiter); this.environment = environment; this.address = address; - postBuffer = postText != null - ? Unpooled.wrappedBuffer(postText.getBytes(StandardCharsets.UTF_8)) + postBuffer = postBody != null + ? Unpooled.wrappedBuffer(postBody) : Unpooled.buffer(0); this.headers = headers; this.binary = binary; redirects = new AtomicInteger(followRedirects ? MAX_REDIRECTS : 0); this.timeout = timeout; - if (postText != null) { + if (postBody != null) { if (!headers.contains(HttpHeaderNames.CONTENT_TYPE)) { headers.set(HttpHeaderNames.CONTENT_TYPE, "application/x-www-form-urlencoded; charset=utf-8"); } diff --git a/projects/core/src/main/java/dan200/computercraft/core/apis/http/request/HttpRequestHandler.java b/projects/core/src/main/java/dan200/computercraft/core/apis/http/request/HttpRequestHandler.java index cd708cc5b..7cba7a803 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/apis/http/request/HttpRequestHandler.java +++ b/projects/core/src/main/java/dan200/computercraft/core/apis/http/request/HttpRequestHandler.java @@ -6,8 +6,7 @@ package dan200.computercraft.core.apis.http.request; import dan200.computercraft.core.Logging; import dan200.computercraft.core.apis.handles.ArrayByteChannel; -import dan200.computercraft.core.apis.handles.BinaryReadableHandle; -import dan200.computercraft.core.apis.handles.EncodedReadableHandle; +import dan200.computercraft.core.apis.handles.ReadHandle; import dan200.computercraft.core.apis.http.HTTPRequestException; import dan200.computercraft.core.apis.http.NetworkUtils; import dan200.computercraft.core.apis.http.options.Options; @@ -188,9 +187,7 @@ public final class HttpRequestHandler extends SimpleChannelInboundHandler= 200 && status.code() < 400) { diff --git a/projects/core/src/main/java/dan200/computercraft/core/apis/http/request/HttpResponseHandle.java b/projects/core/src/main/java/dan200/computercraft/core/apis/http/request/HttpResponseHandle.java index 126ddc133..cb2a6fd79 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/apis/http/request/HttpResponseHandle.java +++ b/projects/core/src/main/java/dan200/computercraft/core/apis/http/request/HttpResponseHandle.java @@ -7,18 +7,16 @@ package dan200.computercraft.core.apis.http.request; import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.core.apis.HTTPAPI; -import dan200.computercraft.core.apis.handles.BinaryReadableHandle; -import dan200.computercraft.core.apis.handles.EncodedReadableHandle; -import dan200.computercraft.core.apis.handles.HandleGeneric; +import dan200.computercraft.core.apis.handles.AbstractHandle; +import dan200.computercraft.core.apis.handles.ReadHandle; import dan200.computercraft.core.methods.ObjectSource; import java.util.List; import java.util.Map; /** - * A http response. This provides the same methods as a {@link EncodedReadableHandle file} (or - * {@link BinaryReadableHandle binary file} if the request used binary mode), though provides several request specific - * methods. + * A http response. This provides the same methods as a {@link ReadHandle file}, though provides several request + * specific methods. * * @cc.module http.Response * @see HTTPAPI#request(IArguments) On how to make a http request. @@ -29,7 +27,7 @@ public class HttpResponseHandle implements ObjectSource { private final String responseStatus; private final Map responseHeaders; - public HttpResponseHandle(HandleGeneric reader, int responseCode, String responseStatus, Map responseHeaders) { + public HttpResponseHandle(AbstractHandle reader, int responseCode, String responseStatus, Map responseHeaders) { this.reader = reader; this.responseCode = responseCode; this.responseStatus = responseStatus; diff --git a/projects/core/src/main/java/dan200/computercraft/core/apis/http/websocket/WebsocketHandle.java b/projects/core/src/main/java/dan200/computercraft/core/apis/http/websocket/WebsocketHandle.java index 7e4f18d85..407dc4f0c 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/apis/http/websocket/WebsocketHandle.java +++ b/projects/core/src/main/java/dan200/computercraft/core/apis/http/websocket/WebsocketHandle.java @@ -8,6 +8,11 @@ import dan200.computercraft.api.lua.*; import dan200.computercraft.core.apis.IAPIEnvironment; import dan200.computercraft.core.apis.http.options.Options; +import java.nio.ByteBuffer; +import java.nio.charset.CharacterCodingException; +import java.nio.charset.CharsetDecoder; +import java.nio.charset.CodingErrorAction; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Objects; import java.util.Optional; @@ -24,6 +29,8 @@ import static dan200.computercraft.core.apis.http.websocket.WebsocketClient.MESS * @see dan200.computercraft.core.apis.HTTPAPI#websocket On how to open a websocket. */ public class WebsocketHandle { + private static final CharsetDecoder DECODER = StandardCharsets.UTF_8.newDecoder().onMalformedInput(CodingErrorAction.REPLACE); + private final IAPIEnvironment environment; private final String address; private final WebsocketClient websocket; @@ -68,18 +75,23 @@ public class WebsocketHandle { * @cc.changed 1.81.0 Added argument for binary mode. */ @LuaFunction - public final void send(Coerced message, Optional binary) throws LuaException { + public final void send(Coerced message, Optional binary) throws LuaException { checkOpen(); var text = message.value(); - if (options.websocketMessage() != 0 && text.length() > options.websocketMessage()) { + if (options.websocketMessage() != 0 && text.remaining() > options.websocketMessage()) { throw new LuaException("Message is too large"); } if (binary.orElse(false)) { - websocket.sendBinary(LuaValues.encode(text)); + websocket.sendBinary(text); } else { - websocket.sendText(text); + try { + websocket.sendText(DECODER.decode(text).toString()); + } catch (CharacterCodingException e) { + // This shouldn't happen, but worth mentioning. + throw new LuaException("Message is not valid UTF8"); + } } } diff --git a/projects/core/src/main/java/dan200/computercraft/core/apis/http/websocket/WebsocketHandler.java b/projects/core/src/main/java/dan200/computercraft/core/apis/http/websocket/WebsocketHandler.java index 8fe6fa244..8d5e2e5ae 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/apis/http/websocket/WebsocketHandler.java +++ b/projects/core/src/main/java/dan200/computercraft/core/apis/http/websocket/WebsocketHandler.java @@ -51,15 +51,15 @@ class WebsocketHandler extends SimpleChannelInboundHandler { var frame = (WebSocketFrame) msg; if (frame instanceof TextWebSocketFrame textFrame) { - var data = textFrame.text(); + var data = NetworkUtils.toBytes(textFrame.content()); - websocket.environment().observe(Metrics.WEBSOCKET_INCOMING, data.length()); + websocket.environment().observe(Metrics.WEBSOCKET_INCOMING, data.length); websocket.environment().queueEvent(MESSAGE_EVENT, websocket.address(), data, false); } else if (frame instanceof BinaryWebSocketFrame) { - var converted = NetworkUtils.toBytes(frame.content()); + var data = NetworkUtils.toBytes(frame.content()); - websocket.environment().observe(Metrics.WEBSOCKET_INCOMING, converted.length); - websocket.environment().queueEvent(MESSAGE_EVENT, websocket.address(), converted, true); + websocket.environment().observe(Metrics.WEBSOCKET_INCOMING, data.length); + websocket.environment().queueEvent(MESSAGE_EVENT, websocket.address(), data, true); } else if (frame instanceof CloseWebSocketFrame closeFrame) { websocket.close(closeFrame.statusCode(), closeFrame.reasonText()); } diff --git a/projects/core/src/main/java/dan200/computercraft/core/apis/transfer/TransferredFile.java b/projects/core/src/main/java/dan200/computercraft/core/apis/transfer/TransferredFile.java index 177dc6666..76342dc26 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/apis/transfer/TransferredFile.java +++ b/projects/core/src/main/java/dan200/computercraft/core/apis/transfer/TransferredFile.java @@ -5,7 +5,7 @@ package dan200.computercraft.core.apis.transfer; import dan200.computercraft.api.lua.LuaFunction; -import dan200.computercraft.core.apis.handles.BinaryReadableHandle; +import dan200.computercraft.core.apis.handles.ReadHandle; import dan200.computercraft.core.methods.ObjectSource; import java.nio.channels.SeekableByteChannel; @@ -15,19 +15,19 @@ import java.util.Optional; /** * A binary file handle that has been transferred to this computer. *

    - * This inherits all methods of {@link BinaryReadableHandle binary file handles}, meaning you can use the standard - * {@link BinaryReadableHandle#read(Optional) read functions} to access the contents of the file. + * This inherits all methods of {@link ReadHandle binary file handles}, meaning you can use the standard + * {@link ReadHandle#read(Optional) read functions} to access the contents of the file. * * @cc.module [kind=event] file_transfer.TransferredFile - * @see BinaryReadableHandle + * @see ReadHandle */ public class TransferredFile implements ObjectSource { private final String name; - private final BinaryReadableHandle handle; + private final ReadHandle handle; public TransferredFile(String name, SeekableByteChannel contents) { this.name = name; - handle = BinaryReadableHandle.of(contents); + handle = new ReadHandle(contents, true); } /** diff --git a/projects/core/src/main/java/dan200/computercraft/core/asm/Generator.java b/projects/core/src/main/java/dan200/computercraft/core/asm/Generator.java index 6d7c76ea5..0a7ff34c1 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/asm/Generator.java +++ b/projects/core/src/main/java/dan200/computercraft/core/asm/Generator.java @@ -47,7 +47,7 @@ final class Generator { private static final Map, ArgMethods> argMethods; private static final ArgMethods ARG_TABLE_UNSAFE; - private static final MethodHandle ARG_GET_OBJECT, ARG_GET_ENUM, ARG_OPT_ENUM, ARG_GET_STRING_COERCED; + private static final MethodHandle ARG_GET_OBJECT, ARG_GET_ENUM, ARG_OPT_ENUM, ARG_GET_STRING_COERCED, ARG_GET_BYTES_COERCED; private record ArgMethods(MethodHandle get, MethodHandle opt) { public static ArgMethods of(Class type, String name) throws ReflectiveOperationException { @@ -84,9 +84,14 @@ final class Generator { ARG_OPT_ENUM = LOOKUP.findVirtual(IArguments.class, "optEnum", MethodType.methodType(Optional.class, int.class, Class.class)); // Create a new Coerced<>(args.getStringCoerced(_)) function. + var mkCoerced = LOOKUP.findConstructor(Coerced.class, MethodType.methodType(void.class, Object.class)); ARG_GET_STRING_COERCED = MethodHandles.filterReturnValue( setReturn(LOOKUP.findVirtual(IArguments.class, "getStringCoerced", MethodType.methodType(String.class, int.class)), Object.class), - LOOKUP.findConstructor(Coerced.class, MethodType.methodType(void.class, Object.class)) + mkCoerced + ); + ARG_GET_BYTES_COERCED = MethodHandles.filterReturnValue( + setReturn(LOOKUP.findVirtual(IArguments.class, "getBytesCoerced", MethodType.methodType(ByteBuffer.class, int.class)), Object.class), + mkCoerced ); } catch (ReflectiveOperationException e) { throw new RuntimeException(e); @@ -265,6 +270,7 @@ final class Generator { if (klass == null) return null; if (klass == String.class) return MethodHandles.insertArguments(ARG_GET_STRING_COERCED, 1, argIndex); + if (klass == ByteBuffer.class) return MethodHandles.insertArguments(ARG_GET_BYTES_COERCED, 1, argIndex); } if (argType == Optional.class) { diff --git a/projects/core/src/main/java/dan200/computercraft/core/filesystem/AbstractInMemoryMount.java b/projects/core/src/main/java/dan200/computercraft/core/filesystem/AbstractInMemoryMount.java index fdf619d8d..188628a3b 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/filesystem/AbstractInMemoryMount.java +++ b/projects/core/src/main/java/dan200/computercraft/core/filesystem/AbstractInMemoryMount.java @@ -17,7 +17,7 @@ import java.util.List; import java.util.Map; import java.util.function.Function; -import static dan200.computercraft.core.filesystem.MountHelpers.*; +import static dan200.computercraft.api.filesystem.MountConstants.*; /** * An abstract mount which stores its file tree in memory. diff --git a/projects/core/src/main/java/dan200/computercraft/core/filesystem/ChannelWrapper.java b/projects/core/src/main/java/dan200/computercraft/core/filesystem/ChannelWrapper.java deleted file mode 100644 index 4bc8a5503..000000000 --- a/projects/core/src/main/java/dan200/computercraft/core/filesystem/ChannelWrapper.java +++ /dev/null @@ -1,41 +0,0 @@ -// SPDX-FileCopyrightText: 2019 The CC: Tweaked Developers -// -// SPDX-License-Identifier: MPL-2.0 - -package dan200.computercraft.core.filesystem; - -import java.io.Closeable; -import java.io.IOException; -import java.nio.channels.Channel; - -/** - * Wraps some closeable object such as a buffered writer, and the underlying stream. - *

    - * When flushing a buffer before closing, some implementations will not close the buffer if an exception is thrown - * this causes us to release the channel, but not actually close it. This wrapper will attempt to close the wrapper (and - * so hopefully flush the channel), and then close the underlying channel. - * - * @param The type of the closeable object to write. - */ -class ChannelWrapper implements Closeable { - private final T wrapper; - private final Channel channel; - - ChannelWrapper(T wrapper, Channel channel) { - this.wrapper = wrapper; - this.channel = channel; - } - - @Override - public void close() throws IOException { - try { - wrapper.close(); - } finally { - channel.close(); - } - } - - T get() { - return wrapper; - } -} diff --git a/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileFlags.java b/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileFlags.java new file mode 100644 index 000000000..a6594ee9b --- /dev/null +++ b/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileFlags.java @@ -0,0 +1,47 @@ +// SPDX-FileCopyrightText: 2023 The CC: Tweaked Developers +// +// SPDX-License-Identifier: MPL-2.0 + +package dan200.computercraft.core.filesystem; + +import dan200.computercraft.api.filesystem.WritableMount; + +import java.io.IOException; +import java.nio.file.OpenOption; +import java.nio.file.StandardOpenOption; +import java.util.Set; + +import static dan200.computercraft.api.filesystem.MountConstants.UNSUPPORTED_MODE; + +/** + * Tracks the {@link OpenOption}s passed to {@link WritableMount#openFile(String, Set)}. + * + * @param read Whether this file was opened for reading. ({@link StandardOpenOption#READ}) + * @param write Whether this file was opened for writing. ({@link StandardOpenOption#WRITE}) + * @param truncate Whether to truncate this file when opening. ({@link StandardOpenOption#TRUNCATE_EXISTING}) + * @param create Whether to create the file if it does not exist. ({@link StandardOpenOption#CREATE}) + * @param append Whether this file was opened for appending. ({@link StandardOpenOption#APPEND}) + */ +record FileFlags(boolean read, boolean write, boolean truncate, boolean create, boolean append) { + public static FileFlags of(Set options) throws IOException { + boolean read = false, write = false, truncate = false, create = false, append = false; + for (var option : options) { + if (!(option instanceof StandardOpenOption stdOption)) throw new IOException(UNSUPPORTED_MODE); + switch (stdOption) { + case READ -> read = true; + case WRITE -> write = true; + case APPEND -> write = append = true; + case TRUNCATE_EXISTING -> truncate = true; + case CREATE -> create = true; + case CREATE_NEW, DELETE_ON_CLOSE, SPARSE, SYNC, DSYNC -> throw new IOException(UNSUPPORTED_MODE); + } + } + + // Quick safety check that we've been given something reasonable. + if (!read && !write) read = true; + if (read && append) throw new IllegalArgumentException("Cannot use READ and APPEND"); + if (append && truncate) throw new IllegalArgumentException("Cannot use APPEND and TRUNCATE_EXISTING"); + + return new FileFlags(read, write, truncate, create, append); + } +} diff --git a/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileMount.java b/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileMount.java index d75065a50..38568d1e2 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileMount.java +++ b/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileMount.java @@ -12,20 +12,17 @@ import dan200.computercraft.api.filesystem.Mount; import java.io.IOException; import java.nio.channels.SeekableByteChannel; import java.nio.file.FileSystemException; -import java.nio.file.*; +import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.attribute.BasicFileAttributes; import java.util.List; -import java.util.Set; -import static dan200.computercraft.core.filesystem.MountHelpers.NOT_A_FILE; -import static dan200.computercraft.core.filesystem.MountHelpers.NO_SUCH_FILE; +import static dan200.computercraft.api.filesystem.MountConstants.*; /** * A {@link Mount} implementation which provides read-only access to a directory. */ public class FileMount implements Mount { - private static final Set READ_OPTIONS = Set.of(StandardOpenOption.READ); - protected final Path root; public FileMount(Path root) { @@ -108,7 +105,7 @@ public class FileMount implements Mount { protected FileOperationException remapException(String fallbackPath, IOException exn) { return exn instanceof FileSystemException fsExn ? remapException(fallbackPath, fsExn) - : new FileOperationException(fallbackPath, exn.getMessage() == null ? MountHelpers.ACCESS_DENIED : exn.getMessage()); + : new FileOperationException(fallbackPath, exn.getMessage() == null ? ACCESS_DENIED : exn.getMessage()); } /** diff --git a/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java b/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java index 0d1876923..fb27eebd7 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java +++ b/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java @@ -16,15 +16,14 @@ import java.io.IOException; import java.lang.ref.Reference; import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; -import java.nio.channels.Channel; import java.nio.channels.SeekableByteChannel; import java.nio.file.AccessDeniedException; +import java.nio.file.OpenOption; import java.nio.file.attribute.BasicFileAttributes; import java.util.*; -import java.util.function.Function; import java.util.regex.Pattern; -import static dan200.computercraft.core.filesystem.MountHelpers.*; +import static dan200.computercraft.api.filesystem.MountConstants.*; public class FileSystem { /** @@ -37,7 +36,7 @@ public class FileSystem { private final Map mounts = new HashMap<>(); - private final HashMap>, ChannelWrapper> openFiles = new HashMap<>(); + private final HashMap>, SeekableByteChannel> openFiles = new HashMap<>(); private final ReferenceQueue> openFileQueue = new ReferenceQueue<>(); public FileSystem(String rootLabel, Mount rootMount) throws FileSystemException { @@ -256,7 +255,7 @@ public class FileSystem { } else { // Copy a file: try (var source = sourceMount.openForRead(sourcePath); - var destination = destinationMount.openForWrite(destinationPath)) { + var destination = destinationMount.openForWrite(destinationPath, WRITE_OPTIONS)) { // Copy bytes as fast as we can ByteStreams.copy(source, destination); } catch (AccessDeniedException e) { @@ -276,18 +275,16 @@ public class FileSystem { } } - private synchronized FileSystemWrapper openFile(MountWrapper mount, Channel channel, T file) throws FileSystemException { + private synchronized FileSystemWrapper openFile(MountWrapper mount, SeekableByteChannel channel) throws FileSystemException { synchronized (openFiles) { if (CoreConfig.maximumFilesOpen > 0 && openFiles.size() >= CoreConfig.maximumFilesOpen) { - IoUtil.closeQuietly(file); IoUtil.closeQuietly(channel); throw new FileSystemException("Too many files already open"); } - var channelWrapper = new ChannelWrapper(file, channel); - var fsWrapper = new FileSystemWrapper(this, mount, channelWrapper, openFileQueue); - openFiles.put(fsWrapper.self, channelWrapper); + var fsWrapper = new FileSystemWrapper<>(this, mount, channel, openFileQueue); + openFiles.put(fsWrapper.self, channel); return fsWrapper; } } @@ -298,22 +295,22 @@ public class FileSystem { } } - public synchronized FileSystemWrapper openForRead(String path, Function open) throws FileSystemException { + public synchronized FileSystemWrapper openForRead(String path) throws FileSystemException { cleanup(); path = sanitizePath(path); var mount = getMount(path); var channel = mount.openForRead(path); - return openFile(mount, channel, open.apply(channel)); + return openFile(mount, channel); } - public synchronized FileSystemWrapper openForWrite(String path, boolean append, Function open) throws FileSystemException { + public synchronized FileSystemWrapper openForWrite(String path, Set options) throws FileSystemException { cleanup(); path = sanitizePath(path); var mount = getMount(path); - var channel = append ? mount.openForAppend(path) : mount.openForWrite(path); - return openFile(mount, channel, open.apply(channel)); + var channel = mount.openForWrite(path, options); + return openFile(mount, channel); } public synchronized long getFreeSpace(String path) throws FileSystemException { diff --git a/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileSystemException.java b/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileSystemException.java index 8828218c7..a1dd0c416 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileSystemException.java +++ b/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileSystemException.java @@ -7,7 +7,7 @@ package dan200.computercraft.core.filesystem; import java.io.IOException; import java.io.Serial; -import static dan200.computercraft.core.filesystem.MountHelpers.ACCESS_DENIED; +import static dan200.computercraft.api.filesystem.MountConstants.ACCESS_DENIED; public class FileSystemException extends Exception { @Serial diff --git a/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileSystemWrapper.java b/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileSystemWrapper.java index 3a5d0ea69..171434ca2 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileSystemWrapper.java +++ b/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileSystemWrapper.java @@ -27,11 +27,11 @@ import java.lang.ref.WeakReference; public class FileSystemWrapper implements TrackingCloseable { private final FileSystem fileSystem; final MountWrapper mount; - private final ChannelWrapper closeable; + private final T closeable; final WeakReference> self; private boolean isOpen = true; - FileSystemWrapper(FileSystem fileSystem, MountWrapper mount, ChannelWrapper closeable, ReferenceQueue> queue) { + FileSystemWrapper(FileSystem fileSystem, MountWrapper mount, T closeable, ReferenceQueue> queue) { this.fileSystem = fileSystem; this.mount = mount; this.closeable = closeable; @@ -56,6 +56,6 @@ public class FileSystemWrapper implements TrackingCloseable } public T get() { - return closeable.get(); + return closeable; } } diff --git a/projects/core/src/main/java/dan200/computercraft/core/filesystem/JarMount.java b/projects/core/src/main/java/dan200/computercraft/core/filesystem/JarMount.java index 4711333b3..ebd975612 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/filesystem/JarMount.java +++ b/projects/core/src/main/java/dan200/computercraft/core/filesystem/JarMount.java @@ -18,7 +18,8 @@ import java.util.HashMap; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; -import static dan200.computercraft.core.filesystem.MountHelpers.NO_SUCH_FILE; +import static dan200.computercraft.api.filesystem.MountConstants.EPOCH; +import static dan200.computercraft.api.filesystem.MountConstants.NO_SUCH_FILE; /** * A mount which reads zip/jar files. @@ -97,6 +98,6 @@ public final class JarMount extends ArchiveMount implements } private static FileTime orEpoch(@Nullable FileTime time) { - return time == null ? MountHelpers.EPOCH : time; + return time == null ? EPOCH : time; } } diff --git a/projects/core/src/main/java/dan200/computercraft/core/filesystem/MemoryMount.java b/projects/core/src/main/java/dan200/computercraft/core/filesystem/MemoryMount.java index 5310c3812..c8e09a586 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/filesystem/MemoryMount.java +++ b/projects/core/src/main/java/dan200/computercraft/core/filesystem/MemoryMount.java @@ -17,12 +17,13 @@ import java.nio.channels.ClosedChannelException; import java.nio.channels.SeekableByteChannel; import java.nio.charset.StandardCharsets; import java.nio.file.AccessDeniedException; +import java.nio.file.OpenOption; import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.FileTime; import java.time.Instant; import java.util.*; -import static dan200.computercraft.core.filesystem.MountHelpers.*; +import static dan200.computercraft.api.filesystem.MountConstants.*; /** * A basic {@link Mount} which stores files and directories in-memory. @@ -147,33 +148,44 @@ public final class MemoryMount extends AbstractInMemoryMount options) throws IOException { + var flags = FileFlags.of(options); + + if (path.isEmpty()) { + throw new FileOperationException(path, flags.create() ? CANNOT_WRITE_TO_DIRECTORY : NOT_A_FILE); + } var parent = getParentAndName(path); - if (parent == null) throw new FileOperationException(path, "Parent directory does not exist"); + if (parent == null) throw new FileOperationException(path, NO_SUCH_FILE); var file = parent.get(); - if (file != null && file.isDirectory()) throw new FileOperationException(path, CANNOT_WRITE_TO_DIRECTORY); - if (file == null) parent.put(file = FileEntry.newFile()); + if (file != null && file.isDirectory()) { + throw new FileOperationException(path, flags.create() ? CANNOT_WRITE_TO_DIRECTORY : NOT_A_FILE); + } - return file; - } + if (file == null) { + if (!flags.create()) throw new FileOperationException(path, NO_SUCH_FILE); + parent.put(file = FileEntry.newFile()); + } else if (flags.truncate()) { + file.contents = EMPTY; + file.length = 0; + } - @Override - public SeekableByteChannel openForWrite(String path) throws IOException { - var file = getForWrite(path); - - // Truncate the file. - file.contents = EMPTY; - file.length = 0; - return new EntryChannel(file, 0); - } - - @Override - public SeekableByteChannel openForAppend(String path) throws IOException { - var file = getForWrite(path); - return new EntryChannel(file, file.length); + // Files are always read AND write, so don't need to do anything fancy here! + return new EntryChannel(file, flags.append() ? file.length : 0); } @Override diff --git a/projects/core/src/main/java/dan200/computercraft/core/filesystem/MountHelpers.java b/projects/core/src/main/java/dan200/computercraft/core/filesystem/MountHelpers.java index 3e3b701af..e4e653b66 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/filesystem/MountHelpers.java +++ b/projects/core/src/main/java/dan200/computercraft/core/filesystem/MountHelpers.java @@ -4,69 +4,15 @@ package dan200.computercraft.core.filesystem; -import dan200.computercraft.api.filesystem.Mount; -import dan200.computercraft.api.filesystem.WritableMount; +import dan200.computercraft.api.filesystem.MountConstants; import java.nio.file.FileSystemException; import java.nio.file.*; -import java.nio.file.attribute.BasicFileAttributes; -import java.nio.file.attribute.FileTime; -import java.time.Instant; -import java.util.List; /** * Useful constants and helper functions for working with mounts. */ public final class MountHelpers { - /** - * A {@link FileTime} set to the Unix EPOCH, intended for {@link BasicFileAttributes}'s file times. - */ - public static final FileTime EPOCH = FileTime.from(Instant.EPOCH); - - /** - * The minimum size of a file for file {@linkplain WritableMount#getCapacity() capacity calculations}. - */ - public static final long MINIMUM_FILE_SIZE = 500; - - /** - * The error message used when the file does not exist. - */ - public static final String NO_SUCH_FILE = "No such file"; - - /** - * The error message used when trying to use a file as a directory (for instance when - * {@linkplain Mount#list(String, List) listing its contents}). - */ - public static final String NOT_A_DIRECTORY = "Not a directory"; - - /** - * The error message used when trying to use a directory as a file (for instance when - * {@linkplain Mount#openForRead(String) opening for reading}). - */ - public static final String NOT_A_FILE = "Not a file"; - - /** - * The error message used when attempting to modify a read-only file or mount. - */ - public static final String ACCESS_DENIED = "Access denied"; - - /** - * The error message used when trying to overwrite a file (for instance when - * {@linkplain WritableMount#rename(String, String) renaming files} or {@linkplain WritableMount#makeDirectory(String) - * creating directories}). - */ - public static final String FILE_EXISTS = "File exists"; - - /** - * The error message used when trying to {@linkplain WritableMount#openForWrite(String) opening a directory to read}. - */ - public static final String CANNOT_WRITE_TO_DIRECTORY = "Cannot write to directory"; - - /** - * The error message used when the mount runs out of space. - */ - public static final String OUT_OF_SPACE = "Out of space"; - private MountHelpers() { } @@ -77,10 +23,10 @@ public final class MountHelpers { * @return The friendly reason for this exception. */ public static String getReason(FileSystemException exn) { - if (exn instanceof FileAlreadyExistsException) return FILE_EXISTS; - if (exn instanceof NoSuchFileException) return NO_SUCH_FILE; - if (exn instanceof NotDirectoryException) return NOT_A_DIRECTORY; - if (exn instanceof AccessDeniedException) return ACCESS_DENIED; + if (exn instanceof FileAlreadyExistsException) return MountConstants.FILE_EXISTS; + if (exn instanceof NoSuchFileException) return MountConstants.NO_SUCH_FILE; + if (exn instanceof NotDirectoryException) return MountConstants.NOT_A_DIRECTORY; + if (exn instanceof AccessDeniedException) return MountConstants.ACCESS_DENIED; var reason = exn.getReason(); return reason != null ? reason.trim() : "Operation failed"; diff --git a/projects/core/src/main/java/dan200/computercraft/core/filesystem/MountWrapper.java b/projects/core/src/main/java/dan200/computercraft/core/filesystem/MountWrapper.java index 2f72a0c21..3a98d62b6 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/filesystem/MountWrapper.java +++ b/projects/core/src/main/java/dan200/computercraft/core/filesystem/MountWrapper.java @@ -11,11 +11,14 @@ import dan200.computercraft.api.filesystem.WritableMount; import javax.annotation.Nullable; import java.io.IOException; import java.nio.channels.SeekableByteChannel; +import java.nio.file.OpenOption; +import java.nio.file.StandardOpenOption; import java.nio.file.attribute.BasicFileAttributes; import java.util.List; import java.util.OptionalLong; +import java.util.Set; -import static dan200.computercraft.core.filesystem.MountHelpers.*; +import static dan200.computercraft.api.filesystem.MountConstants.*; class MountWrapper { private final String label; @@ -164,45 +167,20 @@ class MountWrapper { } } - public SeekableByteChannel openForWrite(String path) throws FileSystemException { + public SeekableByteChannel openForWrite(String path, Set options) throws FileSystemException { if (writableMount == null) throw exceptionOf(path, ACCESS_DENIED); path = toLocal(path); try { - if (mount.exists(path) && mount.isDirectory(path)) { - throw localExceptionOf(path, CANNOT_WRITE_TO_DIRECTORY); - } else { - if (!path.isEmpty()) { - var dir = FileSystem.getDirectory(path); - if (!dir.isEmpty() && !mount.exists(path)) { - writableMount.makeDirectory(dir); - } - } - return writableMount.openForWrite(path); + if (mount.isDirectory(path)) { + throw localExceptionOf(path, options.contains(StandardOpenOption.CREATE) ? CANNOT_WRITE_TO_DIRECTORY : NOT_A_FILE); } - } catch (IOException e) { - throw localExceptionOf(path, e); - } - } - - public SeekableByteChannel openForAppend(String path) throws FileSystemException { - if (writableMount == null) throw exceptionOf(path, ACCESS_DENIED); - - path = toLocal(path); - try { - if (!mount.exists(path)) { - if (!path.isEmpty()) { - var dir = FileSystem.getDirectory(path); - if (!dir.isEmpty() && !mount.exists(path)) { - writableMount.makeDirectory(dir); - } - } - return writableMount.openForWrite(path); - } else if (mount.isDirectory(path)) { - throw localExceptionOf(path, CANNOT_WRITE_TO_DIRECTORY); - } else { - return writableMount.openForAppend(path); + if (options.contains(StandardOpenOption.CREATE)) { + var dir = FileSystem.getDirectory(path); + if (!dir.isEmpty() && !mount.exists(path)) writableMount.makeDirectory(dir); } + + return writableMount.openFile(path, options); } catch (IOException e) { throw localExceptionOf(path, e); } @@ -220,9 +198,7 @@ class MountWrapper { if (e instanceof java.nio.file.FileSystemException ex) { // This error will contain the absolute path, leaking information about where MC is installed. We drop that, // just taking the reason. We assume that the error refers to the input path. - var message = ex.getReason(); - if (message == null) message = ACCESS_DENIED; - return localExceptionOf(localPath, message); + return localExceptionOf(localPath, MountHelpers.getReason(ex)); } return FileSystemException.of(e); diff --git a/projects/core/src/main/java/dan200/computercraft/core/filesystem/WritableFileMount.java b/projects/core/src/main/java/dan200/computercraft/core/filesystem/WritableFileMount.java index 7ebfe5c69..390e7899e 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/filesystem/WritableFileMount.java +++ b/projects/core/src/main/java/dan200/computercraft/core/filesystem/WritableFileMount.java @@ -14,13 +14,13 @@ import java.io.File; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.ClosedChannelException; -import java.nio.channels.NonReadableChannelException; import java.nio.channels.SeekableByteChannel; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.Set; -import static dan200.computercraft.core.filesystem.MountHelpers.*; +import static dan200.computercraft.api.filesystem.MountConstants.*; + /** * A {@link WritableFileMount} implementation which provides read-write access to a directory. @@ -28,9 +28,6 @@ import static dan200.computercraft.core.filesystem.MountHelpers.*; public class WritableFileMount extends FileMount implements WritableMount { private static final Logger LOG = LoggerFactory.getLogger(WritableFileMount.class); - private static final Set WRITE_OPTIONS = Set.of(StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); - private static final Set APPEND_OPTIONS = Set.of(StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.APPEND); - protected final File rootFile; private final long capacity; private long usedSpace; @@ -159,43 +156,46 @@ public class WritableFileMount extends FileMount implements WritableMount { } @Override - public SeekableByteChannel openForWrite(String path) throws FileOperationException { - create(); - - var file = resolvePath(path); - var attributes = tryGetAttributes(path, file); - if (attributes == null) { - if (getRemainingSpace() < MINIMUM_FILE_SIZE) throw new FileOperationException(path, OUT_OF_SPACE); - } else if (attributes.isDirectory()) { - throw new FileOperationException(path, CANNOT_WRITE_TO_DIRECTORY); - } else { - usedSpace -= Math.max(attributes.size(), MINIMUM_FILE_SIZE); - } - - usedSpace += MINIMUM_FILE_SIZE; - - try { - return new CountingChannel(Files.newByteChannel(file, WRITE_OPTIONS), true); - } catch (IOException e) { - throw remapException(path, e); - } + @Deprecated(forRemoval = true) + public SeekableByteChannel openForWrite(String path) throws IOException { + return openFile(path, WRITE_OPTIONS); } @Override - public SeekableByteChannel openForAppend(String path) throws FileOperationException { + @Deprecated(forRemoval = true) + public SeekableByteChannel openForAppend(String path) throws IOException { + return openFile(path, APPEND_OPTIONS); + } + + @Override + public SeekableByteChannel openFile(String path, Set options) throws IOException { + var flags = FileFlags.of(options); + + if (path.isEmpty()) { + throw new FileOperationException(path, flags.create() ? CANNOT_WRITE_TO_DIRECTORY : NOT_A_FILE); + } + create(); var file = resolvePath(path); var attributes = tryGetAttributes(path, file); + if (attributes != null && attributes.isDirectory()) { + throw new FileOperationException(path, flags.create() ? CANNOT_WRITE_TO_DIRECTORY : NOT_A_FILE); + } + if (attributes == null) { + if (!flags.create()) throw new FileOperationException(path, NO_SUCH_FILE); + if (getRemainingSpace() < MINIMUM_FILE_SIZE) throw new FileOperationException(path, OUT_OF_SPACE); - } else if (attributes.isDirectory()) { - throw new FileOperationException(path, CANNOT_WRITE_TO_DIRECTORY); + usedSpace += MINIMUM_FILE_SIZE; + } else if (flags.truncate()) { + usedSpace -= Math.max(attributes.size(), MINIMUM_FILE_SIZE); + usedSpace += MINIMUM_FILE_SIZE; } // Allowing seeking when appending is not recommended, so we use a separate channel. try { - return new CountingChannel(Files.newByteChannel(file, APPEND_OPTIONS), false); + return new CountingChannel(Files.newByteChannel(file, options)); } catch (IOException e) { throw remapException(path, e); } @@ -203,11 +203,9 @@ public class WritableFileMount extends FileMount implements WritableMount { private class CountingChannel implements SeekableByteChannel { private final SeekableByteChannel channel; - private final boolean canSeek; - CountingChannel(SeekableByteChannel channel, boolean canSeek) { + CountingChannel(SeekableByteChannel channel) { this.channel = channel; - this.canSeek = canSeek; } @Override @@ -245,7 +243,6 @@ public class WritableFileMount extends FileMount implements WritableMount { @Override public SeekableByteChannel position(long newPosition) throws IOException { if (!isOpen()) throw new ClosedChannelException(); - if (!canSeek) throw new UnsupportedOperationException("File does not support seeking"); if (newPosition < 0) throw new IllegalArgumentException("Cannot seek before the beginning of the stream"); return channel.position(newPosition); @@ -257,9 +254,8 @@ public class WritableFileMount extends FileMount implements WritableMount { } @Override - public int read(ByteBuffer dst) throws ClosedChannelException { - if (!channel.isOpen()) throw new ClosedChannelException(); - throw new NonReadableChannelException(); + public int read(ByteBuffer dst) throws IOException { + return channel.read(dst); } @Override diff --git a/projects/core/src/main/java/dan200/computercraft/core/lua/CobaltLuaMachine.java b/projects/core/src/main/java/dan200/computercraft/core/lua/CobaltLuaMachine.java index 3510c8956..ade0cf4d6 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/lua/CobaltLuaMachine.java +++ b/projects/core/src/main/java/dan200/computercraft/core/lua/CobaltLuaMachine.java @@ -73,20 +73,20 @@ public class CobaltLuaMachine implements ILuaMachine { .build(); // Set up our global table. - var globals = state.getMainThread().getfenv(); - CoreLibraries.debugGlobals(state); - Bit32Lib.add(state, globals); - globals.rawset("_HOST", ValueFactory.valueOf(environment.hostString())); - globals.rawset("_CC_DEFAULT_SETTINGS", ValueFactory.valueOf(CoreConfig.defaultComputerSettings)); - - // Add default APIs - for (var api : environment.apis()) addAPI(globals, api); - - // And load the BIOS try { + var globals = state.globals(); + CoreLibraries.debugGlobals(state); + Bit32Lib.add(state, globals); + globals.rawset("_HOST", ValueFactory.valueOf(environment.hostString())); + globals.rawset("_CC_DEFAULT_SETTINGS", ValueFactory.valueOf(CoreConfig.defaultComputerSettings)); + + // Add default APIs + for (var api : environment.apis()) addAPI(globals, api); + + // And load the BIOS var value = LoadState.load(state, bios, "@bios.lua", globals); - mainRoutine = new LuaThread(state, value, globals); - } catch (CompileException e) { + mainRoutine = new LuaThread(state, value); + } catch (LuaError | CompileException e) { throw new MachineException(Nullability.assertNonNull(e.getMessage())); } @@ -171,7 +171,7 @@ public class CobaltLuaMachine implements ILuaMachine { return found ? table : null; } - private LuaValue toValue(@Nullable Object object, @Nullable IdentityHashMap values) { + private LuaValue toValue(@Nullable Object object, @Nullable IdentityHashMap values) throws LuaError { if (object == null) return Constants.NIL; if (object instanceof Number num) return ValueFactory.valueOf(num.doubleValue()); if (object instanceof Boolean bool) return ValueFactory.valueOf(bool); @@ -235,7 +235,7 @@ public class CobaltLuaMachine implements ILuaMachine { return Constants.NIL; } - Varargs toValues(@Nullable Object[] objects) { + Varargs toValues(@Nullable Object[] objects) throws LuaError { if (objects == null || objects.length == 0) return Constants.NONE; if (objects.length == 1) return toValue(objects[0], null); diff --git a/projects/core/src/main/java/dan200/computercraft/core/lua/VarargArguments.java b/projects/core/src/main/java/dan200/computercraft/core/lua/VarargArguments.java index 51b71de8c..f8ecee139 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/lua/VarargArguments.java +++ b/projects/core/src/main/java/dan200/computercraft/core/lua/VarargArguments.java @@ -113,6 +113,13 @@ final class VarargArguments implements IArguments { return varargs.arg(index + 1).toString(); } + @Override + public ByteBuffer getBytesCoerced(int index) { + checkAccessible(); + var arg = varargs.arg(index + 1); + return arg instanceof LuaString s ? s.toBuffer() : LuaValues.encode(arg.toString()); + } + @Override public String getType(int index) { checkAccessible(); diff --git a/projects/core/src/main/java/dan200/computercraft/core/util/StringUtil.java b/projects/core/src/main/java/dan200/computercraft/core/util/StringUtil.java index 1d8a920d1..689775a6f 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/util/StringUtil.java +++ b/projects/core/src/main/java/dan200/computercraft/core/util/StringUtil.java @@ -8,18 +8,48 @@ public final class StringUtil { private StringUtil() { } - public static String normaliseLabel(String label) { - var length = Math.min(32, label.length()); + private static boolean isAllowed(char c) { + return (c >= ' ' && c <= '~') || (c >= 161 && c <= 172) || (c >= 174 && c <= 255); + } + + private static String removeSpecialCharacters(String text, int length) { var builder = new StringBuilder(length); for (var i = 0; i < length; i++) { - var c = label.charAt(i); - if ((c >= ' ' && c <= '~') || (c >= 161 && c <= 172) || (c >= 174 && c <= 255)) { - builder.append(c); - } else { - builder.append('?'); - } + var c = text.charAt(i); + builder.append(isAllowed(c) ? c : '?'); } return builder.toString(); } + + public static String normaliseLabel(String text) { + return removeSpecialCharacters(text, Math.min(32, text.length())); + } + + /** + * Normalise a string from the clipboard, suitable for pasting into a computer. + *

    + * This removes special characters and strips to the first line of text. + * + * @param clipboard The text from the clipboard. + * @return The normalised clipboard text. + */ + public static String normaliseClipboardString(String clipboard) { + // Clip to the first occurrence of \r or \n + var newLineIndex1 = clipboard.indexOf('\r'); + var newLineIndex2 = clipboard.indexOf('\n'); + + int length; + if (newLineIndex1 >= 0 && newLineIndex2 >= 0) { + length = Math.min(newLineIndex1, newLineIndex2); + } else if (newLineIndex1 >= 0) { + length = newLineIndex1; + } else if (newLineIndex2 >= 0) { + length = newLineIndex2; + } else { + length = clipboard.length(); + } + + return removeSpecialCharacters(clipboard, Math.min(length, 512)); + } } diff --git a/projects/core/src/main/resources/data/computercraft/lua/bios.lua b/projects/core/src/main/resources/data/computercraft/lua/bios.lua index 2f3493dd7..2ba511e82 100644 --- a/projects/core/src/main/resources/data/computercraft/lua/bios.lua +++ b/projects/core/src/main/resources/data/computercraft/lua/bios.lua @@ -18,33 +18,6 @@ do expect = f().expect end -if _VERSION == "Lua 5.1" then - -- If we're on Lua 5.1, install parts of the Lua 5.2/5.3 API so that programs can be written against it - local nativeload = load - - function load(x, name, mode, env) - expect(1, x, "function", "string") - expect(2, name, "string", "nil") - expect(3, mode, "string", "nil") - expect(4, env, "table", "nil") - - local ok, p1, p2 = pcall(function() - local result, err = nativeload(x, name, mode, env) - if result and env then - env._ENV = env - end - return result, err - end) - if ok then - return p1, p2 - else - error(p1, 2) - end - end - - loadstring = function(string, chunkname) return nativeload(string, chunkname) end -end - -- Inject a stub for the old bit library _G.bit = { bnot = bit32.bnot, @@ -58,7 +31,7 @@ _G.bit = { -- Install lua parts of the os api function os.version() - return "CraftOS 1.8" + return "CraftOS 1.9" end function os.pullEventRaw(sFilter) diff --git a/projects/core/src/main/resources/data/computercraft/lua/rom/apis/http/http.lua b/projects/core/src/main/resources/data/computercraft/lua/rom/apis/http/http.lua index 9e074a475..bc7f209e5 100644 --- a/projects/core/src/main/resources/data/computercraft/lua/rom/apis/http/http.lua +++ b/projects/core/src/main/resources/data/computercraft/lua/rom/apis/http/http.lua @@ -66,9 +66,8 @@ end @tparam string url The url to request @tparam[opt] { [string] = string } headers Additional headers to send as part of this request. -@tparam[opt] boolean binary Whether to make a binary HTTP request. If true, -the body will not be UTF-8 encoded, and the received response will not be -decoded. +@tparam[opt=false] boolean binary Whether the [response handle][`fs.ReadHandle`] +should be opened in binary mode. @tparam[2] { url = string, headers? = { [string] = string }, @@ -89,6 +88,8 @@ error or connection timeout. @changed 1.80pr1.6 Added support for table argument. @changed 1.86.0 Added PATCH and TRACE methods. @changed 1.105.0 Added support for custom timeouts. +@changed 1.109.0 The returned response now reads the body as raw bytes, rather + than decoding from UTF-8. @usage Make a request to [example.tweaked.cc](https://example.tweaked.cc), and print the returned page. @@ -118,9 +119,8 @@ end @tparam string body The body of the POST request. @tparam[opt] { [string] = string } headers Additional headers to send as part of this request. -@tparam[opt] boolean binary Whether to make a binary HTTP request. If true, -the body will not be UTF-8 encoded, and the received response will not be -decoded. +@tparam[opt=false] boolean binary Whether the [response handle][`fs.ReadHandle`] +should be opened in binary mode. @tparam[2] { url = string, body? = string, headers? = { [string] = string }, @@ -142,6 +142,8 @@ error or connection timeout. @changed 1.80pr1.6 Added support for table argument. @changed 1.86.0 Added PATCH and TRACE methods. @changed 1.105.0 Added support for custom timeouts. +@changed 1.109.0 The returned response now reads the body as raw bytes, rather + than decoding from UTF-8. ]] function post(_url, _post, _headers, _binary) if type(_url) == "table" then @@ -166,9 +168,8 @@ once the request has completed. request. If specified, a `POST` request will be made instead. @tparam[opt] { [string] = string } headers Additional headers to send as part of this request. -@tparam[opt] boolean binary Whether to make a binary HTTP request. If true, -the body will not be UTF-8 encoded, and the received response will not be -decoded. +@tparam[opt=false] boolean binary Whether the [response handle][`fs.ReadHandle`] +should be opened in binary mode. @tparam[2] { url = string, body? = string, headers? = { [string] = string }, @@ -194,6 +195,8 @@ from above are passed in as fields instead (for instance, @changed 1.80pr1.6 Added support for table argument. @changed 1.86.0 Added PATCH and TRACE methods. @changed 1.105.0 Added support for custom timeouts. +@changed 1.109.0 The returned response now reads the body as raw bytes, rather + than decoding from UTF-8. ]] function request(_url, _post, _headers, _binary) local url @@ -296,6 +299,8 @@ these options behave. @since 1.80pr1.3 @changed 1.95.3 Added User-Agent to default headers. @changed 1.105.0 Added support for table argument and custom timeout. +@changed 1.109.0 Non-binary websocket messages now use the raw bytes rather than + using UTF-8. @see websocket_success @see websocket_failure ]] @@ -346,6 +351,8 @@ from above are passed in as fields instead (for instance, @changed 1.80pr1.3 No longer asynchronous. @changed 1.95.3 Added User-Agent to default headers. @changed 1.105.0 Added support for table argument and custom timeout. +@changed 1.109.0 Non-binary websocket messages now use the raw bytes rather than + using UTF-8. @usage Connect to an echo websocket and send a message. diff --git a/projects/core/src/main/resources/data/computercraft/lua/rom/apis/io.lua b/projects/core/src/main/resources/data/computercraft/lua/rom/apis/io.lua index 2ffe044c7..34d6d075a 100644 --- a/projects/core/src/main/resources/data/computercraft/lua/rom/apis/io.lua +++ b/projects/core/src/main/resources/data/computercraft/lua/rom/apis/io.lua @@ -307,7 +307,7 @@ end -- @since 1.55 function input(file) if type_of(file) == "string" then - local res, err = open(file, "rb") + local res, err = open(file, "r") if not res then error(err, 2) end currentInput = res elseif type_of(file) == "table" and getmetatable(file) == handleMetatable then @@ -349,7 +349,7 @@ end function lines(filename, ...) expect(1, filename, "string", "nil") if filename then - local ok, err = open(filename, "rb") + local ok, err = open(filename, "r") if not ok then error(err, 2) end -- We set this magic flag to mark this file as being opened by io.lines and so should be @@ -381,7 +381,7 @@ function open(filename, mode) expect(1, filename, "string") expect(2, mode, "string", "nil") - local sMode = mode and mode:gsub("%+", "") or "rb" + local sMode = mode and mode:gsub("%+", "") or "r" local file, err = fs.open(filename, sMode) if not file then return nil, err end diff --git a/projects/core/src/main/resources/data/computercraft/lua/rom/modules/main/cc/audio/dfpwm.lua b/projects/core/src/main/resources/data/computercraft/lua/rom/modules/main/cc/audio/dfpwm.lua index 01ca95ee3..73783ee1c 100644 --- a/projects/core/src/main/resources/data/computercraft/lua/rom/modules/main/cc/audio/dfpwm.lua +++ b/projects/core/src/main/resources/data/computercraft/lua/rom/modules/main/cc/audio/dfpwm.lua @@ -9,8 +9,8 @@ DFPWM (Dynamic Filter Pulse Width Modulation) is an audio codec designed by Grea format compared to raw PCM data, only using 1 bit per sample, but is simple enough to simple enough to encode and decode in real time. -Typically DFPWM audio is read from [the filesystem][`fs.BinaryReadHandle`] or a [a web request][`http.Response`] as a -string, and converted a format suitable for [`speaker.playAudio`]. +Typically DFPWM audio is read from [the filesystem][`fs.ReadHandle`] or a [a web request][`http.Response`] as a string, +and converted a format suitable for [`speaker.playAudio`]. ## Encoding and decoding files This modules exposes two key functions, [`make_decoder`] and [`make_encoder`], which construct a new decoder or encoder. diff --git a/projects/core/src/main/resources/data/computercraft/lua/rom/modules/main/cc/internal/syntax/errors.lua b/projects/core/src/main/resources/data/computercraft/lua/rom/modules/main/cc/internal/syntax/errors.lua index 1bd652e42..f3397237b 100644 --- a/projects/core/src/main/resources/data/computercraft/lua/rom/modules/main/cc/internal/syntax/errors.lua +++ b/projects/core/src/main/resources/data/computercraft/lua/rom/modules/main/cc/internal/syntax/errors.lua @@ -535,6 +535,28 @@ function errors.unexpected_end(start_pos, end_pos) } end +--[[- A label statement was opened but not closed. + +@tparam number open_start The start position of the opening label. +@tparam number open_end The end position of the opening label. +@tparam number tok_start The start position of the current token. +@return The resulting parse error. +]] +function errors.unclosed_label(open_start, open_end, token, start_pos, end_pos) + expect(1, open_start, "number") + expect(2, open_end, "number") + expect(3, token, "number") + expect(4, start_pos, "number") + expect(5, end_pos, "number") + + return { + "Unexpected " .. token_names[token] .. ".", + annotate(open_start, open_end, "Label was started here."), + annotate(start_pos, end_pos, "Tip: Try adding " .. code("::") .. " here."), + + } +end + -------------------------------------------------------------------------------- -- Generic parsing errors -------------------------------------------------------------------------------- diff --git a/projects/core/src/main/resources/data/computercraft/lua/rom/modules/main/cc/internal/syntax/lexer.lua b/projects/core/src/main/resources/data/computercraft/lua/rom/modules/main/cc/internal/syntax/lexer.lua index 278b2b749..0b9d45a7e 100644 --- a/projects/core/src/main/resources/data/computercraft/lua/rom/modules/main/cc/internal/syntax/lexer.lua +++ b/projects/core/src/main/resources/data/computercraft/lua/rom/modules/main/cc/internal/syntax/lexer.lua @@ -32,12 +32,12 @@ local tokens = require "cc.internal.syntax.parser".tokens local sub, find = string.sub, string.find local keywords = { - ["and"] = tokens.AND, ["break"] = tokens.BREAK, ["do"] = tokens.DO, ["else"] = tokens.ELSE, - ["elseif"] = tokens.ELSEIF, ["end"] = tokens.END, ["false"] = tokens.FALSE, ["for"] = tokens.FOR, - ["function"] = tokens.FUNCTION, ["if"] = tokens.IF, ["in"] = tokens.IN, ["local"] = tokens.LOCAL, - ["nil"] = tokens.NIL, ["not"] = tokens.NOT, ["or"] = tokens.OR, ["repeat"] = tokens.REPEAT, - ["return"] = tokens.RETURN, ["then"] = tokens.THEN, ["true"] = tokens.TRUE, ["until"] = tokens.UNTIL, - ["while"] = tokens.WHILE, + ["and"] = tokens.AND, ["break"] = tokens.BREAK, ["do"] = tokens.DO, ["else"] = tokens.ELSE, + ["elseif"] = tokens.ELSEIF, ["end"] = tokens.END, ["false"] = tokens.FALSE, ["for"] = tokens.FOR, + ["function"] = tokens.FUNCTION, ["goto"] = tokens.GOTO, ["if"] = tokens.IF, ["in"] = tokens.IN, + ["local"] = tokens.LOCAL, ["nil"] = tokens.NIL, ["not"] = tokens.NOT, ["or"] = tokens.OR, + ["repeat"] = tokens.REPEAT, ["return"] = tokens.RETURN, ["then"] = tokens.THEN, ["true"] = tokens.TRUE, + ["until"] = tokens.UNTIL, ["while"] = tokens.WHILE, } --- Lex a newline character @@ -292,12 +292,15 @@ local function lex_token(context, str, pos) local next_pos = pos + 1 if sub(str, next_pos, next_pos) == "=" then return tokens.LE, next_pos end return tokens.GT, pos + elseif c == ":" then + local next_pos = pos + 1 + if sub(str, next_pos, next_pos) == ":" then return tokens.DOUBLE_COLON, next_pos end + return tokens.COLON, pos elseif c == "~" and sub(str, pos + 1, pos + 1) == "=" then return tokens.NE, pos + 1 -- Single character tokens elseif c == "," then return tokens.COMMA, pos elseif c == ";" then return tokens.SEMICOLON, pos - elseif c == ":" then return tokens.COLON, pos elseif c == "(" then return tokens.OPAREN, pos elseif c == ")" then return tokens.CPAREN, pos elseif c == "]" then return tokens.CSQUARE, pos diff --git a/projects/core/src/main/resources/data/computercraft/lua/rom/modules/main/cc/internal/syntax/parser.lua b/projects/core/src/main/resources/data/computercraft/lua/rom/modules/main/cc/internal/syntax/parser.lua index 4e60da420..c1d14dd66 100644 --- a/projects/core/src/main/resources/data/computercraft/lua/rom/modules/main/cc/internal/syntax/parser.lua +++ b/projects/core/src/main/resources/data/computercraft/lua/rom/modules/main/cc/internal/syntax/parser.lua @@ -32,10 +32,10 @@ for i, token in ipairs({ "WHILE", "UNTIL", "TRUE", "THEN", "SUB", "STRING", "SEMICOLON", "RETURN", "REPEAT", "POW", "OSQUARE", "OR", "OPAREN", "OBRACE", "NUMBER", "NOT", "NIL", "NE", "MUL", "MOD", "LT", "LOCAL", "LEN", "LE", "IN", "IF", - "IDENT", "GT", "GE", "FUNCTION", "FOR", "FALSE", "EQUALS", "EQ", "EOF", - "END", "ELSEIF", "ELSE", "DOTS", "DOT", "DO", "DIV", "CSQUARE", "CPAREN", - "CONCAT", "COMMA", "COLON", "CBRACE", "BREAK", "AND", "ADD", "COMMENT", - "ERROR", + "IDENT", "GT", "GOTO", "GE", "FUNCTION", "FOR", "FALSE", "EQUALS", "EQ", + "EOF", "END", "ELSEIF", "ELSE", "DOUBLE_COLON", "DOTS", "DOT", "DO", + "DIV", "CSQUARE", "CPAREN", "CONCAT", "COMMA", "COLON", "CBRACE", + "BREAK", "AND", "ADD", "COMMENT", "ERROR", }) do tokens[token] = i end setmetatable(tokens, { __index = function(_, name) error("No such token " .. tostring(name), 2) end }) @@ -134,15 +134,20 @@ local error_messages = { -- parse_errors.mlyl, line 64 return errors.unclosed_brackets(lp.s, lp.e, token.v, token.s, token.e) end, + function(context, stack, stack_n, regs, token) + local lp = { s = stack[regs[2] + 1], e = stack[regs[2] + 2] } + -- parse_errors.mlyl, line 66 + return errors.unclosed_label(lp.s, lp.e, token.v, token.s, token.e) + end, function(context, stack, stack_n, regs, token) local loc = { s = stack[regs[2] + 1], e = stack[regs[2] + 2] } - -- parse_errors.mlyl, line 69 + -- parse_errors.mlyl, line 71 if token.v == tokens.DOT then return errors.local_function_dot(loc.s, loc.e, token.s, token.e) end end, function(context, stack, stack_n, regs, token) - -- parse_errors.mlyl, line 77 + -- parse_errors.mlyl, line 79 local end_pos = stack[stack_n + 2] -- Hack to get the last position if is_same_line(context, end_pos, token) then return errors.standalone_name(token.s) @@ -152,22 +157,22 @@ local error_messages = { end, function(context, stack, stack_n, regs, token) local start = { s = stack[regs[2] + 1], e = stack[regs[2] + 2] } - -- parse_errors.mlyl, line 88 + -- parse_errors.mlyl, line 90 return errors.expected_then(start.s, start.e, line_end_position(context, stack[stack_n + 2], token)) end, function(context, stack, stack_n, regs, token) local start = { s = stack[regs[2] + 1], e = stack[regs[2] + 2] } - -- parse_errors.mlyl, line 116 + -- parse_errors.mlyl, line 118 return errors.expected_end(start.s, start.e, token.v, token.s, token.e) end, function(context, stack, stack_n, regs, token) local func = { s = stack[regs[2] + 1], e = stack[regs[2] + 2] } local loc = { s = stack[regs[3] + 1], e = stack[regs[3] + 2] } - -- parse_errors.mlyl, line 120 + -- parse_errors.mlyl, line 122 return errors.expected_end(loc.s, func.e, token.v, token.s, token.e) end, function(context, stack, stack_n, regs, token) - -- parse_errors.mlyl, line 124 + -- parse_errors.mlyl, line 126 if token.v == tokens.END then return errors.unexpected_end(token.s, token.e) elseif token ~= tokens.EOF then @@ -175,20 +180,20 @@ local error_messages = { end end, function(context, stack, stack_n, regs, token) - -- parse_errors.mlyl, line 134 + -- parse_errors.mlyl, line 136 return errors.expected_function_args(token.v, token.s, token.e) end, function(context, stack, stack_n, regs, token) - -- parse_errors.mlyl, line 138 + -- parse_errors.mlyl, line 140 return errors.expected_expression(token.v, token.s, token.e) end, function(context, stack, stack_n, regs, token) - -- parse_errors.mlyl, line 142 + -- parse_errors.mlyl, line 144 return errors.expected_var(token.v, token.s, token.e) end, } -local error_program_start, error_program = 471, "\6\1\0\3\5\186\0\3\6B\0\3\0060\0\3\6(\0\3\6 \0\3\6\21\0\3\6\7\0\3\5\253\0\3\5\236\0\3\5\223\0\1\0\3\5\203\0\3\5\195\0\1\0\3\5\186\0\3\5\178\0\3\5\170\0\3\5\170\0\3\5\170\0\3\5\170\0\3\5\170\0\3\5\146\0\3\5\146\0\3\5\170\0\3\5\162\0\3\5\154\0\3\5\154\0\3\5\154\0\3\5\146\0\3\5\138\0\3\5p\0\3\5h\0\3\5`\0\3\5X\0\3\5P\0\3\4\158\0\3\5F\0\3\5B\0\3\0057\0\3\4\171\0\3\4\167\0\3\4\159\0\3\1\226\0\3\4\158\0\3\4\152\0\3\4\146\0\3\4\141\0\3\4\131\0\3\4{\0\3\4p\0\3\4O\0\3\4J\0\1\0\3\4E\0\1\0\3\4@\0\3\0043\0\3\4(\0\3\3\139\0\3\3\131\0\3\3\127\0\3\3w\0\3\3g\0\3\3{\0\3\3w\0\3\3w\0\3\3s\0\3\3o\0\3\2\233\0\3\3k\0\3\2\218\0\3\2\218\0\3\3g\0\3\3`\0\3\2\218\0\3\2\233\0\3\2\218\0\3\2\218\0\3\2\218\0\3\2\218\0\3\2\225\0\3\2\218\0\3\2\218\0\3\2\218\0\3\2\218\0\3\2Q\0\3\2I\0\3\2=\0\3\2E\0\3\2A\0\3\2\25\0\3\2\21\0\3\2=\0\3\0029\0\3\0025\0\3\0021\0\3\2\17\0\3\2-\0\3\2!\0\3\2)\0\3\2%\0\3\2!\0\3\2\29\0\3\2\25\0\3\2\21\0\3\2\17\0\3\2\r\0\3\2\t\0\3\2\5\0\3\2\1\0\3\2\1\0\3\1\253\0\3\1\249\0\3\1\245\0\3\1\245\0\3\1\235\0\3\1\241\0\3\1\235\0\3\1\226\0\5\0\0\3\4\136\0\3\6M\0\5\0\14\1\0\3\4@\0\1\0\3\4@\0\3\6M\0\3\6U\0\3\6U\0\3\1\249\0\3\6^\0\3\6b\0\3\4J\0\3\6f\0\3\2)\0\3\4p\0\3\2\21\0\3\2\25\0\3\2\17\0\3\2I\0\3\2=\0\3\0029\0\3\2-\0\3\6j\0\3\2!\0\3\2%\0\3\6\142\0\3\2A\0\3\6\142\0\3\2\21\0\5\0\5\1\0\3\4@\0\1\0\3\7\29\0\3\7\r\0\1\0\3\7\4\0\1\0\3\6\251\0\1\0\3\6\242\0\3\6\234\0\3\6\226\0\3\6\226\0\3\6\226\0\3\6\226\0\3\6\226\0\3\6\202\0\3\6\202\0\3\6\226\0\3\6\218\0\3\6\210\0\3\6\210\0\3\6\210\0\3\6\202\0\3\6\194\0\3\6\186\0\3\6\178\0\3\6\178\0\3\6\170\0\3\6\162\0\3\6\154\0\3\2\218\0\3\2\218\0\3\2\218\0\3\3w\0\5\0\190\3\6\149\0\3\3g\0\3\7.\0\5\0\8\3\7\182\0\1\0\3\7\29\0\3\7\r\0\1\0\3\7\4\0\1\0\3\6\251\0\1\0\3\6\242\0\3\6\234\0\3\6\226\0\3\6\226\0\3\6\226\0\3\6\226\0\3\6\226\0\3\6\202\0\3\6\202\0\3\6\226\0\3\6\218\0\3\6\210\0\3\6\210\0\3\6\210\0\3\6\202\0\3\6\194\0\3\6\186\0\3\6\178\0\3\6\178\0\3\6\170\0\3\6\162\0\3\6\154\0\5\1\3\3\6\149\0\3\3w\0\3\7\189\0\3\7.\0\3\7\182\0\3\2\218\0\3\7\193\0\3\3\131\0\3\7\197\0\3\7\r\0\5\0\27\1\0\3\7\29\0\3\7\211\0\1\0\3\7\4\0\1\0\3\6\251\0\1\0\3\6\242\0\3\4J\0\1\0\3\4@\0\3\6\234\0\3\6\226\0\3\6\226\0\3\6\226\0\3\6\226\0\3\6\226\0\3\6\202\0\3\6\202\0\3\6\226\0\3\6\218\0\3\6\210\0\3\6\210\0\3\6\210\0\3\6\202\0\3\6\194\0\3\6\186\0\3\6\178\0\3\6\178\0\3\6\170\0\3\6\162\0\3\6\154\0\3\2\218\0\3\2\218\0\3\2\218\0\3\3w\0\3\7\201\0\3\2I\0\3\6b\0\3\6M\0\5\1f\3\6\149\0\3\1\249\0\4\2\0\0\5\0\31\1\0\3\4E\0\4\4\0\1\6\4\5\0\1\6\4\8\0\0\6\4\12\0\0\6\1\0\3\7\219\0\3\7\243\0\3\7\239\0\3\7\235\0\3\7\228\0\1\0\3\7\219\0\4\12\0\0\5\0\214\3\8\1\0\4\12\0\0\3\8$\0\4\r\0\0\6\4\14\0\0\6\4\15\0\0\6\1\0\3\4@\0\1\0\3\4E\0\6\3\7\211\0\3\2I\0\5\0\18\6\3\7\201\0\1\0\3\7\29\0\3\7\r\0\1\0\3\7\4\0\1\0\3\6\251\0\1\0\3\6\242\0\3\4J\0\3\6\234\0\3\6\226\0\3\6\226\0\3\6\226\0\3\6\226\0\3\6\226\0\3\6\202\0\3\6\202\0\3\6\226\0\3\6\218\0\3\6\210\0\3\6\210\0\3\6\210\0\3\6\202\0\3\6\194\0\3\6\186\0\3\6\178\0\3\6\178\0\3\6\170\0\3\6\162\0\3\6\154\0\3\2\218\0\3\2\218\0\3\2\218\0\3\3w\0\3\6b\0\5\1\233\3\6\149\0\3\7\235\0\5\0\30\6\3\7\239\0\1\0\3\8+\0\4\1\0\0\5\0B\6\4\1\0\0\3\0080\0\4\1\0\0\3\0084\0\4\1\0\0\3\2=\0\4\1\0\0\3\0088\0\1\0\3\4@\0\3\2%\0\3\2=\0\3\2\21\0\4\1\0\0\5\0T\6\4\1\0\0\3\8<\0\4\1\0\0\3\8@\0\4\1\0\0\3\8D\0\4\1\0\0\3\8H\0\4\1\0\0\3\8L\0\4\12\0\0\4\n\0\1\6\4\r\0\0\3\8P\0\4\14\0\0\3\8Z\0\3\8\1\0\3\7\243\0\3\7\228\0\5\1\19\1\0\3\7\219\0\3\8^\0\4\1\0\0\4\0\0\0\5\0008\1\0\3\8f\0\4\1\0\0\1\0\3\4@\0\4\1\0\0\1\0\3\8o\0\3\7\243\0\4\12\0\0\5\0%\3\8t\0\4\12\0\0\3\7\243\0\4\12\0\0\3\8z\0\4\12\0\0\1\0\3\7\219\0\3\7\243\0\3\8\128\0\4\12\0\0\5\0\224\3\8\132\0\3\1\235\0\3\1\249\0\5\0c\1\0\3\4E\0\3\8\136\0\3\2\t\0\3\8\150\0\3\0021\0\1\0\3\5\186\0\3\0060\0\3\6(\0\3\6 \0\3\6\21\0\1\0\3\5\186\0\3\4O\0\5\1L\3\6B\0\4\1\0\0\6\4\1\0\0\3\8\157\0\4\1\0\0\3\8\165\0\4\1\0\0\3\4p\0\4\1\0\0\3\2%\0\4\1\0\0\3\2I\0\4\1\0\0\3\8\192\0\4\1\0\0\3\t \0\4\1\0\0\3\t\139\0\4\1\0\0\3\t\202\0\4\1\0\0\3\n\17\0\4\1\0\0\3\nT\0\4\4\0\1\4\1\0\0\6\4\6\0\1\4\1\0\0\6\4\t\0\1\4\1\0\0\6\4\2\0\0\4\1\0\0\4\0\0\0\3\6U\0\4\5\0\1\4\2\0\0\4\1\0\0\4\0\0\0\6\3\3s\0\1\0\3\7\29\0\3\7\r\0\1\0\3\7\4\0\1\0\3\6\251\0\1\0\3\6\242\0\3\6\234\0\3\6\226\0\3\6\226\0\3\6\226\0\3\6\226\0\3\6\226\0\3\6\202\0\3\6\202\0\3\6\226\0\3\6\218\0\3\6\210\0\3\6\210\0\3\6\210\0\3\6\202\0\3\6\194\0\3\6\186\0\3\6\178\0\3\6\178\0\3\6\170\0\3\6\162\0\3\6\154\0\3\2\218\0\3\2\218\0\3\2\218\0\3\3w\0\3\6\142\0\5\2L\3\6\149\0\3\2\233\0\3\n\227\0\3\0057\0\3\4\167\0\1\0\3\n\234\0\4\r\0\0\5\0V\6\4\n\0\1\6\3\7\243\0\5\0=\3\8t\0\3\7\243\0\3\8z\0\1\0\3\7\219\0\3\7\243\0\3\8\128\0\5\0\230\3\8\132\0\1\0\3\7\219\0\3\7\243\0\3\7\239\0\3\7\235\0\3\7\228\0\1\0\3\7\219\0\5\1U\3\8\1\0\4\t\0\1\6\3\8\157\0\3\8\165\0\3\8\192\0\3\t \0\3\t\139\0\3\t\202\0\3\n\17\0\3\nT\0\1\0\3\n\234\0\3\n\239\0\5\0\198\6\4\2\0\0\3\6U\0\4\5\0\1\4\2\0\0\6\4\6\0\1\6\1\0\3\n\246\0\1\0\3\n\255\0\3\11\7\0\3\11\11\0\3\4\131\0\1\0\3\5\186\0\3\11\15\0\5\0\192\3\0060\0\3\0084\0\3\8^\0\5\0m\1\0\3\8f\0\1\0\3\4@\0\3\2%\0\3\2=\0\3\2\21\0\5\0\148\6\1\0\3\7\29\0\3\7\r\0\1\0\3\7\4\0\1\0\3\6\251\0\1\0\3\6\242\0\3\6\234\0\3\6\226\0\3\6\226\0\3\6\226\0\3\6\226\0\3\6\226\0\3\6\202\0\3\6\226\0\3\6\218\0\3\6\194\0\3\6\186\0\3\6\178\0\3\6\178\0\3\6\170\0\3\6\162\0\3\6\154\0\5\2\143\3\6\149\0\1\0\3\7\29\0\3\7\r\0\1\0\3\7\4\0\1\0\3\6\251\0\1\0\3\6\242\0\3\6\234\0\3\6\226\0\3\6\226\0\3\6\226\0\3\6\226\0\3\6\226\0\3\6\202\0\3\6\202\0\3\6\226\0\3\6\218\0\3\6\202\0\3\6\194\0\3\6\186\0\3\6\178\0\3\6\178\0\3\6\170\0\3\6\162\0\3\6\154\0\5\2\212\3\6\149\0\1\0\3\7\29\0\3\7\r\0\1\0\3\7\4\0\1\0\3\6\251\0\1\0\3\6\242\0\3\6\194\0\3\6\186\0\3\6\178\0\3\6\178\0\3\6\170\0\3\6\162\0\3\6\154\0\5\2c\3\6\149\0\1\0\3\7\29\0\3\7\r\0\1\0\3\7\4\0\1\0\3\6\251\0\1\0\3\6\242\0\3\6\234\0\3\6\218\0\3\6\194\0\3\6\186\0\3\6\178\0\3\6\178\0\3\6\170\0\3\6\162\0\3\6\154\0\5\3\23\3\6\149\0\1\0\3\7\29\0\3\7\r\0\1\0\3\7\4\0\1\0\3\6\251\0\1\0\3\6\242\0\3\6\218\0\3\6\194\0\3\6\186\0\3\6\178\0\3\6\178\0\3\6\170\0\3\6\162\0\3\6\154\0\5\3 \3\6\149\0\1\0\3\7\29\0\3\7\r\0\1\0\3\7\4\0\1\0\3\6\251\0\1\0\3\6\242\0\3\6\234\0\3\6\226\0\3\6\226\0\3\6\226\0\3\6\226\0\3\6\226\0\3\6\202\0\3\6\202\0\3\6\226\0\3\6\218\0\3\6\210\0\3\6\210\0\3\6\210\0\3\6\202\0\3\6\194\0\3\6\186\0\3\6\178\0\3\6\178\0\3\6\170\0\3\6\162\0\3\6\154\0\3\2\218\0\3\2\218\0\3\2\218\0\3\7\182\0\3\7.\0\3\3w\0\5\3\163\3\6\149\0\4\7\0\1\6\5\0\11\3\11\25\0\2\1\0\1\0\3\11\30\0\4\n\0\1\3\4\158\0\3\7\243\0\3\11'\0\4\12\0\0\1\0\3\n\246\0\4\3\0\1\6\4\11\1\2\6\3\11.\0\5\0\136\3\0112\0\3\7\243\0\3\0116\0\3\11.\0" -local error_tbl_ks, error_tbl_vs, error_tbl = 1, 2, "\0\0\199\1\0\147\2\0\0\3\0\195\0\0\0\5\1K\0\0\0\7\1G\0\0\0\t\0\207\0\0\0\11\1C\0\0\0\r\1?\0\0\0\15\0\223\16\0\187\17\0\213\18\1\211\19\0\167\20\1\207\21\0\0\22\1\203\23\0\179\24\1\163\25\1\199\26\0\11\27\0'\28\1;\29\0017\30\0013\31\0\151 \1/!\1+\"\1'\21\1\222$\1#%\1\31\0\0\0'\1\27(\1\23)\1\19*\0\27\0\0\0,\0o\0\0\0.\0k\0\0\0000\0g\0\0\0002\0c\0\0\0004\0_\0\0\0006\0[\0\0\0008\0W\0\0\0:\0S\0\0\0<\0O\0\0\0>\0K\0\0\0@\0G\0\0\0B\0C\0\0\0D\0?\0\0\0F\0;G\0\235H\0\213I\1OJ\0+K\0wL\0\179M\1\15N\0sO\0\0P\0\231Q\0\0R\0\0S\1\11T\1\7U\1\3V\0\255W\0\251X\0\27Y\0\0R\2\229[\0\131\\\0\227R\0\0^\0\127_\0\219`\1\195a\1\191b\1\187c\1\183d\0#e\0\175f\0\247g\0\31h\0\243i\0\239j\0\135k\0\7l\0'm\1\159n\1\155o\1\151p\1\147q\0\199r\0\147n\2Mt\0{u\0\0v\0\183w\0001x\0\23y\0'z\1\143{\0\159|\1\139b\3\135~\1\135\127\0\183\128\0\155b\4/\130\0\135\131\0\19\132\0\147\133\0\139\134\1\131u\4\163\136\0\135\137\0\15\138\0\143\139\0005\140\0'\141\1\127\142\0\183\143\0\163\144\0\187\145\0\0\146\1\179\147\0\0\148\1\175\149\0\23\150\0'\151\1{\152\0\183\153\0\171b\5\232\155\0\135H\5x\157\0\135\158\0\7\159\0'\160\1w\131\5>\162\0\135\163\0\7\164\0'\165\1s\166\0\0\137\5>\168\0\0\169\0\7\170\0'\171\1o\172\0\1\173\0'\174\1k\175\1g\176\1c\177\1_\178\1[\179\0\0\180\0\203\144\6\17\182\1W\183\0\183\184\1\171\185\1\167\186\0\191\187\1S\188\0\0\189\0\0\190\0\0\191\0\0\192\0\0\3\0\0n\5\134\129\5J\6\2\202b\6Q\8\2p\t\2Z\n\2j\135\5J\12\2\206u\7\205\14\2\210\144\7\224\8\8Vb\8\161\16\8\140}\5\130" .. ("\0"):rep(15) .. "\17\8V\0\0\0\0\0\0\0\0\0\0\0\0H\8\174\0\0\0\0\0\0\0\0\0\0\0\0#\2jZ\11#\0\0\0&\2\214]\11#\0\0\0\0\0\0\0\0\0+\2\170\0\0\0-\2\166\0\0\0/\2\162\0\0\0001\2\158\26\4Z3\2\154\0\0\0005\2\150\0\0\0007\2\146\0\0\0009\2\142\0\0\0;\2\138\0\0\0=\2\134\0\0\0?\2\130\0\0\0A\2~\0\0\0C\2zn\8\188E\2v\0\0\0}\11#H\2p\0\0\0J\2\174\181\5~\0\0\0\8\3\6\t\2\240\n\3\0H\8V\0\0\0\0\0\0}\8\184" .. ("\0"):rep(18) .. "Z\2\198\0\0\0\0\0\0]\2\194\0\0\0\0\0\0\0\0\0\0\0\0b\2`\0\0\0\154\11#\0\0\0\0\0\0\0\0\0#\3\0\0\0\0\0\0\0I\6>\0\0\0\0\0\0n\2\190\26\5\215+\3@I\7\253-\3\137\4^]\3X\139\4j\0\0\0\0\0\0~\7\253b\2\246\26\6t\0\0\0\0\0\0\3\3\170\0\0\0\149\4f\6\4\8\0\0\0\8\3\164\26\8\14\n\3\158n\3T\12\4\12\181\2\178\14\4\16\183\0\0s\3P\17\3\174\0\0\0\0\0\0\0\0\0\21\4$\0\0\0\0\0\0k\5\211\0\0\0}\3L\0\0\0\172\4T\0\0\0\129\2\250\0\0\0\0\0\0\0\0\0\168\6>#\3\158\135\2\250x\5\219&\4\20\0\0\0\168\7\253\0\0\0\0\0\0+\3\232\0\0\0-\3\228\0\0\0/\3\224\182\6>1\3\220\0\0\0003\3\216\0\0\0005\3\212\182\7\2537\3\208\190\6>9\3\204\0\0\0;\3\200\0\0\0=\3\196\190\7\253?\3\192\0\0\0A\3\188\149\5\219C\3\184\0\0\0E\3\180\0\0\0\0\0\0H\3\164\0\0\0J\3\236\158\5\211\0\0\0\0\0\0\0\0\0\0\0\0\163\5\211\0\0\0\181\3H\0\0\0\0\0\0\0\0\0\169\5\211q\6\138\0\0\0\0\0\0Z\4\4\0\0\0\0\0\0]\4\0x\6\128\0\0\0q" .. ("\0"):rep(20) .. "x\8\26\0\0\0\131\6|\0\0\0\0\0\0\0\0\0\0\0\0n\3\252\137\6x\0\0\0\139\6\132\131\8\22s\3\248\0\0\0u\4\28v\3\148\0\0\0\137\8\18\0\0\0\139\8\30\149\6\128\0\0\0}\3\244\0\0\0\127\4\24\0\0\0\129\3\152\0\0\0\0\0\0\149\8\26\0\0\0\3\4\203\135\3\152\0\0\0\6\5#\0\0\0\8\4\197\t\4\175\n\4\191\142\3\148\12\5'\0\0\0\14\5+\172\6n" .. ("\0"):rep(15) .. "\152\0\0\0\0\0\0\0\0\172\8\8" .. ("\0"):rep(30) .. "#\4\191\0\0\0\0\0\0&\5/\0\0\0\0\0\0\0\0\0\0\0\0+\5\3\0\0\0-\4\255\0\0\0/\4\251\0\0\0001\4\247\181\3\2403\4\243\183\4 5\4\239\0\0\0007\4\235\0\0\0009\4\231\0\0\0;\4\227\0\0\0=\4\223\0\0\0?\4\219\0\0\0A\4\215\0\0\0C\4\211\0\0\0E\4\207\0\0\0\0\0\0H\4\197\0\0\0J\5\7" .. ("\0"):rep(45) .. "Z\5\31\0\0\0\0\0\0]\5\27\0\0\0\0\0\0\0\0\0\0\0\0b\4\181\0\0\0\0\0\0\0\0\0\3\7\178\0\0\0\0\0\0\6\7\162\0\0\0\8\7H\t\0072\n\7Bn\5\23\12\7\166\0\0\0\14\7\170\0\0\0s\5\19" .. ("\0"):rep(27) .. "}\5\15\0\0\0\0\0\0\0\0\0\129\4\185\8\t\168\t\t\146\n\t\162\0\0\0#\7B\135\4\185\0\0\0&\7\174\0\0\0\0\0\0\0\0\0\0\0\0+\7\130\0\0\0-\7~\0\0\0/\7z\0\0\0001\7v\0\0\0003\7r\0\0\0005\7n\0\0\0007\7j\0\0\0009\7f#\t\162;\7b\0\0\0=\7^\0\0\0?\7Z\0\0\0A\7V\0\0\0C\7R\0\0\0E\7N\0\0\0\0\0\0H\7H\0\0\0J\7\134\8\8\218\t\8\196\n\8\212\0\0\0\0\0\0\0\0\0\0\0\0\181\5\11\0\0\0\183\0053" .. ("\0"):rep(15) .. "Z\7\158\0\0\0\0\0\0]\7\154\0\0\0H\t\168\0\0\0J\t\174b\0078\0\0\0\0\0\0\0\0\0#\8\212" .. ("\0"):rep(21) .. "n\7\150\0\0\0\0\0\0Z\t\198\0\0\0s\7\146]\t\194\0\0\0003\t\0\0\0\0005\8\252b\t\1527\8\248\0\0\0\0\0\0}\7\142;\8\244\0\0\0=\8\240\129\7\0O\0\0\0@\0K\0\0\0B\0G\0\0\0D\0C\0\0\0F\0?\0\0\0H\0;I\0\251J\0\217K\1_L\0+M\0wN\0\183O\1\31P\0sQ\0\0R\0\247S\0\0T\0\0U\1\27V\1\23W\1\19X\1\15Y\1\11Z\0\27[\0\0T\2\245]\0\131^\0\223_\1\215`\1\211a\1\207b\1\203c\0\243a\3\151e\0\127f\0#g\0\179h\1\7i\0\31j\1\3k\0\255l\0\135m\0\7n\0'o\1\179p\1\175q\1\171r\1\167s\1\163t\0\203u\0\147q\2]w\0{x\0\0y\0\187z\0001{\0\23|\0'}\1\159~\0\159\127\1\155a\5\161\129\1\151\130\0\187\131\0\155x\6\27\133\0\135\134\0\19\135\0\147\136\0\139\137\1\147a\7`\139\0\135\140\0\15\141\0\143\142\0005\143\0'\144\1\143\145\0\235\146\1\139\147\0\187\148\0\163\149\0\191\150\0\0\151\1\199\152\0\0\153\1\195\154\0\23\155\0'\156\1\135\157\0\187\158\0\171\28\7O\160\0\135\149\7\137\162\0\135\163\0\7\164\0'\165\1\131\134\6\182\167\0\135\168\0\7\169\0'\170\1\127\171\0\0\140\6\182\173\0\0\174\0\7\175\0'\176\1{\177\0\0\178\0\175\179\1w\180\0\1\181\0'\182\1s\183\1o\184\1k\185\0\0\186\0\207a\7\201\188\1g\189\0\187\190\1\191\191\1\187\192\0\195\193\1c\194\0\0\195\0\0\196\0\0\197\0\0\198\0\0\3\0\0x\tE\132\6\194\6\2\218\149\t]\8\2\128\t\2j\n\2z\138\6\194\12\2\222a\n\30\14\2\226\8\t\211T\0\0\17\n\t\0\0\0\0\0\0\0\0\0J\6\240\0\0\0J\n+\0\0\0\18\t\211" .. ("\0"):rep(33) .. "%\2z\0\0\0\0\0\0(\2\230\0\0\0\0\0\0\0\0\0m\7K-\2\186\0\0\0/\2\182\0\0\0001\2\178K\7\1823\2\174K\tz5\2\170\0\0\0007\2\166\0\0\0009\2\162{\7S;\2\158q\6\254=\2\154q\n9?\2\150\0\0\0A\2\146\0\0\0C\2\142\0\0\0E\2\138\0\0\0G\2\134\0\0\0\0\0\0J\2\128\128\6\250L\2\190\128\n5\8\3\22\t\3\0\n\3\16J\t\211\0\0\0l\7\178\0\0\0l\tv\0\0\0\0\0\0\0\0\0\154\7S\0\0\0\0\0\0\\\2\214\0\0\0\0\0\0\0\0\0\0\0\0a\2p\163\7K\0\0\0d\2\210\0\0\0\0\0\0\168\7K\129\7\182\0\0\0\129\tz%\3\16\0\0\0\174\7K\0\0\0\0\0\0\0\0\0q\2\206\0\0\0-\3P\28\5\204/\3Lv\2\2021\3H\0\0\0003\3Dz\n\0155\3@\0\0\0007\3<\0\0\0009\0038\128\2\198;\0034\0\0\0=\0030\132\2t?\3,\187\6\246A\3(\187\n1C\3$\138\2tE\3 \0\7\254G\3\28\0\0\0\\\12\160J\3\22\0\0\0L\3T\0\0\0\173\7\182\0\0\0\173\tzd\12\160" .. ("\0"):rep(30) .. "\\\3l\188\7\182\0\0\0\188\tz\0\0\0a\3\6\28\7\232\0\0\0d\3h\196\7\182\0\0\0\196\tz\0\0\0\3\3\186\0\0\0\0\0\0\6\4\24\128\12\160\8\3\180\0\0\0\n\3\174q\3d\12\4\28\0\0\0\14\4 \187\2\194v\3`\189\0\0\18\3\190\0\0\0\0\0\0\0\0\0\22\0044\0\0\0\0\0\0\0\0\0\128\3\\\0\0\0\0\0\0\0\0\0\132\3\n\0\0\0t\0\0\0\0\0\0\0\0\0\0\0\138\3\n%\3\174\159\12\160{\5\216(\4$\0\0\0\0\0\0\0\0\0\0\0\0-\3\248\0\0\0/\3\244\0\0\0001\3\240\134\5\2123\3\236\0\0\0005\3\232\0\0\0007\3\228\140\5\2089\3\224\142\5\220;\3\220\0\0\0=\3\216\0\0\0?\3\212\0\0\0A\3\208\187\12\160C\3\204\0\0\0E\3\200\154\5\216G\3\196\0\0\0\0\0\0J\3\180\0\0\0L\3\252" .. ("\0"):rep(21) .. "t\7\254\187\3X" .. ("\0"):rep(15) .. "{\7\244\\\4\20\0\0\0\0\0\0\0\0\0\180\5\198\0\0\0\0\0\0\0\0\0d\4\16\0\0\0\134\7\240" .. ("\0"):rep(15) .. "\140\7\236\0\0\0\142\7\248\0\0\0\0\0\0q\4\12\0\0\0\28\t\139\0\0\0\0\0\0v\4\8\0\0\0x\4,y\3\164\154\7\244" .. ("\0"):rep(15) .. "\128\4\4\0\0\0\130\4(\0\0\0\132\3\168\0\0\0\3\4_\0\0\0\0\0\0\6\4\199\138\3\168\8\4Y\t\4?\n\4S\0\0\0\12\4\203\0\0\0\14\4\207\0\0\0\147\3\164\180\7\226\18\4i\8\11%\t\11\15\n\11\31\22\4\231\0\0\0\0\0\0\0\0\0\157" .. ("\0"):rep(32) .. "%\4S\0\0\0\0\0\0(\4\211\0\0\0\0\0\0\0\0\0\0\0\0-\4\163\0\0\0/\4\159%\11\0311\4\155\0\0\0003\4\151\0\0\0005\4\147\0\0\0007\4\143\187\4\0009\4\139\189\0040;\4\135\0\0\0=\4\131\0\0\0?\4\127\0\0\0A\4{\0\0\0C\4w\0\0\0E\4s\0\0\0G\4ot\0\0\0\0\0J\4Y\0\0\0L\4\167\0\0\0\0\0\0{\t\151\0\0\0Q\4\195\0\0\0S\0\0\0\0\0J\11%\0\0\0L\11+\0\0\0\0\0\0\134\t\147\0\0\0\\\4\191\0\0\0\0\0\0\0\0\0\140\t\143a\4E\142\t\155\0\0\0d\4\187\0\0\0\0\0\0\\\11C\0\0\0\0\0\0\0\0\0\0\0\0a\11\21\0\0\0\154\t\151d\11?\0\0\0q\4\183\0\0\0\0\0\0\0\0\0\0\0\0v\4\179\0\0\0x\4\223y\4I\0\0\0\0\0\0q\11;\0\0\0\0\0\0\0\0\0\128\4\175v\0117\130\4\219\0\0\0\132\4M\0\0\0\0\0\0\0\0\0\180\t\133\0\0\0\138\4M\128\0113\0\0\0\0\0\0\0\0\0\132\11\25\0\0\0\145\4\215\0\0\0\147\4I\0\0\0\138\11\25\0\0\0\0\0\0\6\5v\0\0\0\8\5\12\t\4\242\n\5\6\157\0\0\12\5z\0\0\0\14\5~\0\0\0\0\0\0\0\0\0\18\5\24\0\0\0\0\0\0\0\0\0\22\5\150" .. ("\0"):rep(24) .. "\177\4c" .. ("\0"):rep(15) .. "%\5\6\0\0\0\0\0\0(\5\130\187\4\171\0\0\0\189\4\227\0\0\0-\5R\0\0\0/\5N\0\0\0001\5J\0\0\0003\5F\187\11/5\5B\0\0\0007\5>\0\0\0009\5:\0\0\0;\0056\0\0\0=\0052\0\0\0?\5.\0\0\0A\5*\0\0\0C\5&\0\0\0E\5\"\0\0\0G\5\30\0\0\0\0\0\0J\5\12\0\0\0L\5V\0\0\0\0\0\0\0\0\0\0\0\0Q\5r\0\0\0S" .. ("\0"):rep(26) .. "\\\5n\0\0\0\0\0\0\0\0\0\0\0\0a\4\248\0\0\0\0\0\0d\5j" .. ("\0"):rep(36) .. "q\5f\0\0\0\0\0\0\0\0\0\0\0\0v\5b\0\0\0x\5\142y\4\252" .. ("\0"):rep(18) .. "\128\5^\0\0\0\130\5\138\0\0\0\132\5" .. ("\0"):rep(16) .. "\138\5" .. ("\0"):rep(19) .. "\145\5\134\0\0\0\147\4\252\0\0\0\3\6C\0\0\0\0\0\0\6\6\155\0\0\0\8\6=\t\6'\n\0067\157\0\0\12\6\159\0\0\0\14\6\163" .. ("\0"):rep(48) .. "\177\5\18" .. ("\0"):rep(15) .. "%\0067\0\0\0\0\0\0(\6\167\187\5Z\0\0\0\189\5\146\0\0\0-\6{\0\0\0/\6w\0\0\0001\6s\0\0\0003\6o\0\0\0005\6k\0\0\0007\6g\0\0\0009\6c\0\0\0;\6_\0\0\0=\6[\0\0\0?\6W\0\0\0A\6S\0\0\0C\6O\0\0\0E\6K\0\0\0G\6G\0\0\0\0\0\0J\6=\3\t*L\6\127\0\0\0\6\t\26\0\0\0\8\8\192\t\8\170\n\8\186\0\0\0\12\t\30\0\0\0\14\t\"" .. ("\0"):rep(15) .. "\\\6\151\0\0\0\0\0\0\0\0\0\0\0\0a\6-\0\0\0\0\0\0d\6\147" .. ("\0"):rep(24) .. "%\8\186\0\0\0\0\0\0(\t&q\6\143\0\0\0\0\0\0\0\0\0-\8\250v\6\139/\8\246\0\0\0001\8\242\0\0\0003\8\238\0\0\0005\8\234\0\0\0007\8\230\128\6\1359\8\226\0\0\0;\8\222\132\0061=\8\218\0\0\0?\8\214\0\0\0A\8\210\138\0061C\8\206\0\0\0E\8\202\0\0\0G\8\198\0\0\0\0\0\0J\8\192\0\0\0L\8\254\0\0\0\8\nW\t\nA\n\nQ" .. ("\0"):rep(33) .. "\\\t\22\0\0\0\0\0\0\0\0\0\0\0\0a\8\176\0\0\0\0\0\0d\t\18" .. ("\0"):rep(18) .. "%\nQ" .. ("\0"):rep(15) .. "q\t\14\0\0\0\187\6\131\0\0\0\189\6\171v\t\n\0\0\0\0\0\0\0\0\0\0\0\0005\n}\0\0\0007\ny\0\0\0009\nu\128\t\6\0\0\0\0\0\0=\nq\132\8\180?\nm\0\0\0A\ni\0\0\0C\ne\138\8\180E\na\0\0\0G\n]\0\0\0\0\0\0J\nW\0\0\0L\n\129\0\0\0\8\n\186\t\n\164\n\n\180\0\0\0\0\0\0\0\0\0\0\0\0\8\11d\t\11N\n\11^\0\0\0\0\0\0\0\0\0\0\0\0\\\n\153\0\0\0\0\0\0\0\0\0\0\0\0a\nG\0\0\0\0\0\0d\n\149" .. ("\0"):rep(18) .. "%\n\180" .. ("\0"):rep(15) .. "q\n\145%\11^-\n\232\0\0\0\187\t\2v\n\141\189\0\0\0\0\0\0\0\0\0\0\0005\n\228\0\0\0007\n\224\0\0\0009\n\220\128\n\137;\n\2165\11n=\n\212\132\nK?\n\208\0\0\0A\n\204\0\0\0C\n\200\138\nKE\n\196\0\0\0G\n\192\0\0\0\0\0\0J\n\186\0\0\0L\n\236\0\0\0G\11j\0\0\0\0\0\0J\11d\0\0\0L\11r\0\0\0\8\11\171\t\11\149\n\11\165\0\0\0\0\0\0\0\0\0\0\0\0\\\11\4\0\0\0\0\0\0\0\0\0\0\0\0a\n\170\0\0\0\\\11\138d\11\0\0\0\0\0\0\0\0\0\0a\11T\0\0\0\0\0\0d\11\134" .. ("\0"):rep(15) .. "q\n\252%\11\165\0\0\0\0\0\0\187\n\133v\n\248\0\0\0q\11\130\0\0\0\0\0\0\0\0\0\0\0\0v\11~\0\0\0\0\0\0\128\n\244\0\0\0005\11\177\0\0\0\132\n\174\0\0\0\0\0\0\128\11z\0\0\0\0\0\0\138\n\174\132\11X" .. ("\0"):rep(15) .. "\138\11X" .. ("\0"):rep(15) .. "J\11\171\0\0\0L\11\181" .. ("\0"):rep(45) .. "\\\11\205\0\0\0\0\0\0\0\0\0\0\0\0a\11\155\0\0\0\0\0\0d\11\201" .. ("\0"):rep(27) .. "\187\n\240\0\0\0\0\0\0q\11\197\0\0\0\0\0\0\0\0\0\187\11vv\11\193\0\0\0\0\0\0\6\12H\0\0\0\8\11\238\t\11\216\n\11\232\0\0\0\12\12L\128\11\189\14\12P\0\0\0\0\0\0\132\11\159" .. ("\0"):rep(15) .. "\138\11\159" .. ("\0"):rep(33) .. "#\12T\0\0\0%\11\232\0\0\0\0\0\0(\12\\\0\0\0\0\0\0\0\0\0\0\0\0-\12(\0\0\0/\12$\0\0\0001\12 \0\0\0003\12\28\0\0\0005\12\24\0\0\0007\12\20\0\0\0009\12\16\0\0\0;\12\12\0\0\0=\12\8\0\0\0?\12\4\0\0\0A\12\0\0\0\0C\11\252\0\0\0E\11\248\0\0\0G\11\244\187\11\185\0\0\0J\11\238\0\0\0L\12," .. ("\0"):rep(21) .. "T\12X" .. ("\0"):rep(21) .. "\\\12D\0\0\0\0\0\0\0\0\0\0\0\0a\11\222\0\0\0\0\0\0d\12@" .. ("\0"):rep(36) .. "q\12<\0\0\0\0\0\0\0\0\0\0\0\0v\0128" .. ("\0"):rep(27) .. "\128\0124\0\0\0\0\0\0\0\0\0\132\11\226" .. ("\0"):rep(15) .. "\138\11\226" .. ("\0"):rep(138) .. "\185\12T\0\0\0\187\0120" local function handle_error(context, stack, stack_n, token, token_start, token_end) -- Run our error handling virtual machine. @@ -249,23 +254,23 @@ end --- The list of productions in our grammar. Each is a tuple of `terminal * production size`. local productions = { - { 53, 1 }, { 52, 1 }, { 81, 1 }, { 81, 1 }, { 80, 3 }, { 79, 1 }, - { 79, 1 }, { 79, 1 }, { 79, 1 }, { 79, 1 }, { 79, 1 }, { 79, 1 }, - { 79, 1 }, { 79, 4 }, { 78, 2 }, { 78, 4 }, { 77, 3 }, { 77, 1 }, - { 77, 1 }, { 76, 1 }, { 76, 3 }, { 76, 3 }, { 76, 3 }, { 76, 3 }, - { 76, 3 }, { 76, 3 }, { 76, 3 }, { 76, 3 }, { 76, 3 }, { 76, 3 }, - { 76, 3 }, { 76, 3 }, { 76, 3 }, { 76, 3 }, { 75, 1 }, { 75, 3 }, - { 75, 2 }, { 75, 2 }, { 75, 2 }, { 74, 1 }, { 74, 3 }, { 74, 3 }, - { 73, 0 }, { 73, 2 }, { 73, 3 }, { 73, 1 }, { 73, 2 }, { 72, 1 }, - { 72, 3 }, { 72, 4 }, { 71, 2 }, { 70, 2 }, { 69, 0 }, { 69, 2 }, - { 69, 3 }, { 68, 0 }, { 68, 5 }, { 67, 0 }, { 67, 1 }, { 66, 0 }, - { 66, 1 }, { 65, 1 }, { 65, 3 }, { 64, 1 }, { 64, 3 }, { 63, 1 }, - { 63, 3 }, { 62, 1 }, { 62, 3 }, { 61, 1 }, { 61, 3 }, { 61, 1 }, - { 60, 3 }, { 60, 3 }, { 60, 5 }, { 60, 4 }, { 60, 6 }, { 60, 8 }, - { 60, 9 }, { 60, 11 }, { 60, 7 }, { 60, 2 }, { 60, 4 }, { 60, 6 }, - { 60, 5 }, { 60, 1 }, { 59, 2 }, { 58, 3 }, { 57, 0 }, { 57, 1 }, - { 57, 3 }, { 56, 1 }, { 56, 3 }, { 56, 5 }, { 55, 1 }, { 55, 1 }, - { 54, 1 }, + { 55, 1 }, { 54, 1 }, { 84, 1 }, { 84, 1 }, { 83, 3 }, { 82, 1 }, + { 82, 1 }, { 82, 1 }, { 82, 1 }, { 82, 1 }, { 82, 1 }, { 82, 1 }, + { 82, 1 }, { 82, 4 }, { 81, 2 }, { 81, 4 }, { 80, 3 }, { 80, 1 }, + { 80, 1 }, { 79, 1 }, { 79, 3 }, { 79, 3 }, { 79, 3 }, { 79, 3 }, + { 79, 3 }, { 79, 3 }, { 79, 3 }, { 79, 3 }, { 79, 3 }, { 79, 3 }, + { 79, 3 }, { 79, 3 }, { 79, 3 }, { 79, 3 }, { 78, 1 }, { 78, 3 }, + { 78, 2 }, { 78, 2 }, { 78, 2 }, { 77, 1 }, { 77, 3 }, { 77, 3 }, + { 76, 1 }, { 76, 1 }, { 75, 0 }, { 75, 2 }, { 75, 3 }, { 74, 1 }, + { 74, 3 }, { 74, 4 }, { 73, 2 }, { 72, 2 }, { 71, 0 }, { 71, 5 }, + { 70, 0 }, { 70, 2 }, { 69, 0 }, { 69, 1 }, { 68, 0 }, { 68, 1 }, + { 67, 1 }, { 67, 3 }, { 66, 1 }, { 66, 3 }, { 65, 1 }, { 65, 3 }, + { 64, 1 }, { 64, 3 }, { 63, 1 }, { 63, 3 }, { 63, 1 }, { 62, 3 }, + { 62, 3 }, { 62, 5 }, { 62, 4 }, { 62, 6 }, { 62, 8 }, { 62, 9 }, + { 62, 11 }, { 62, 7 }, { 62, 2 }, { 62, 4 }, { 62, 6 }, { 62, 5 }, + { 62, 1 }, { 62, 1 }, { 62, 1 }, { 62, 2 }, { 62, 3 }, { 61, 2 }, + { 60, 3 }, { 59, 0 }, { 59, 1 }, { 59, 3 }, { 58, 1 }, { 58, 3 }, + { 58, 5 }, { 57, 1 }, { 57, 1 }, { 56, 1 }, } local f = false @@ -290,199 +295,205 @@ table is a 2D lookup table of `action = transitions[state][value]`, where stack. ]] local transitions = { - { -53, f, f, f, f, f, f, -53, -53, f, f, f, -53, f, f, f, f, f, f, f, f, -53, f, f, f, -53, -53, f, f, -53, -53, f, f, f, -53, f, f, f, f, f, -53, f, f, f, f, f, f, f, -53, f, f, f, f, f, f, f, f, f, 2, f, f, f, f, f, f, f, f, f, 4, f, 189 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 3 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -51 }, - { 5, -43, f, f, f, f, f, 111, 114, f, f, f, 9, f, f, f, f, f, f, f, f, 118, f, f, f, 130, 16, f, f, 143, 153, f, f, f, -43, -43, -43, -43, f, f, 173, f, f, f, f, f, f, f, 176, f, f, f, f, 32, f, f, f, f, f, 178, 180, f, 181, f, f, f, f, f, f, f, f, 186, 187, f, f, f, f, 188 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 107, f, 41, 42 }, - { -9, -9, f, -9, -9, f, -9, -9, -9, -9, f, -9, -9, f, f, f, f, -9, -9, -9, -9, -9, f, -9, f, -9, -9, -9, -9, -9, -9, f, f, -9, -9, -9, -9, -9, f, f, -9, -9, -9, -9, -9, -9, f, -9, -9, -9, -9 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 106, f, f, 41, 42 }, - { -13, -13, f, -13, -13, f, -13, -13, -13, -13, f, -13, -13, f, f, f, f, -13, -13, -13, -13, -13, f, -13, f, -13, -13, -13, -13, -13, -13, f, f, -13, -13, -13, -13, -13, f, f, -13, -13, -13, -13, -13, -13, f, -13, -13, -13, -13 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 104, f, 41, 42 }, - { f, f, 6, f, 7, 8, f, f, f, f, 11, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 93, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, -89, f, f, f, f, f, 32, f, 96, 102, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 101, f, 41, 42 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 89, f, 41, 42 }, - { -12, -12, f, -12, -12, f, -12, -12, -12, -12, f, -12, -12, f, f, f, f, -12, -12, -12, -12, -12, f, -12, f, -12, -12, -12, -12, -12, -12, f, f, -12, -12, -12, -12, -12, f, f, -12, -12, -12, -12, -12, -12, f, -12, -12, -12, -12 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 88, f, f, 41, 42 }, - { -8, -8, f, -8, -8, f, -8, -8, -8, -8, f, -8, -8, f, f, f, f, -8, -8, -8, -8, -8, f, -8, f, -8, -8, -8, -8, -8, -8, f, f, -8, -8, -8, -8, -8, f, f, -8, -8, -8, -8, -8, -8, f, -8, -8, -8, -8 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 87, f, f, 41, 42 }, - { -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97 }, - { f, f, f, f, f, f, f, f, f, f, f, f, 18, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 27 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 16, f, f, f, f, f, f, f, f, f, f, f, 19, f, f, f, f, -58, f, f, f, f, f, f, f, f, f, 20, f, f, f, f, f, f, f, f, f, f, 21, f, 24, f, f, f, f, f, f, f, f, f, f, f, f, f, 26 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -4, f, -4 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -3, f, -3 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -59, f, 22 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 16, f, f, f, f, f, f, f, f, f, f, f, 19, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 20, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 23 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -63, f, -63 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 25 }, - { -5, f, f, f, f, f, f, -5, -5, f, f, f, -5, f, f, f, f, f, f, f, f, -5, f, f, f, -5, -5, f, f, -5, -5, f, f, f, f, -5, f, f, f, f, -5, f, f, f, f, f, f, f, -5 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -62, f, -62 }, - { -53, f, f, f, f, f, f, -53, -53, f, f, f, -53, f, f, f, f, f, f, f, f, -53, f, f, f, -53, -53, f, f, -53, -53, f, f, f, f, -53, f, f, f, f, -53, f, f, f, f, f, f, f, -53, f, f, f, f, f, f, f, f, f, 28, f, f, f, f, f, f, f, f, f, 4 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 29 }, - { -14, -14, f, -14, -14, f, -14, -14, -14, -14, f, -14, -14, f, f, f, f, -14, -14, -14, -14, -14, f, -14, f, -14, -14, -14, -14, -14, -14, f, f, -14, -14, -14, -14, -14, f, f, -14, -14, -14, -14, -14, -14, f, -14, -14, -14, -14 }, - { -10, -10, f, -10, -10, f, -10, -10, -10, -10, f, -10, -10, f, f, f, f, -10, -10, -10, -10, -10, f, -10, f, -10, -10, -10, -10, -10, -10, f, f, -10, -10, -10, -10, -10, f, f, -10, -10, -10, -10, -10, -10, f, -10, -10, -10, -10 }, - { -11, -11, f, -11, -11, f, -11, -11, -11, -11, f, -11, -11, f, f, f, f, -11, -11, -11, -11, -11, f, -11, f, -11, -11, -11, -11, -11, -11, f, f, -11, -11, -11, -11, -11, f, f, -11, -11, -11, -11, -11, -11, f, -11, -11, -11, -11 }, - { -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48 }, - { -7, -7, f, -7, -7, f, -7, -7, -7, -7, f, -7, -7, f, f, f, f, -7, -7, -7, -7, -7, f, -7, f, -7, -7, -7, -7, -7, -7, f, f, -7, -7, -7, -7, -7, f, f, -7, -7, -7, -7, -7, -7, f, -7, -7, -7, -7 }, - { -6, -6, f, -6, -6, 35, -6, -6, -6, -6, 36, -6, 73, 10, f, f, f, -6, -6, -6, -6, -6, f, -6, f, -6, -6, -6, -6, -6, -6, f, f, -6, -6, -6, -6, -6, f, 80, -6, -6, -6, -6, -6, -6, 82, -6, -6, -6, -6, f, f, f, f, f, f, 84, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 86 }, - { -18, -18, f, -18, -18, -18, -18, -18, -18, -18, -18, -18, -18, -18, f, f, f, -18, -18, -18, -18, -18, f, -18, f, -18, -18, -18, -18, -18, -18, f, f, -18, -18, -18, -18, -18, f, -18, -18, -18, -18, -18, -18, -18, -18, -18, -18, -18, -18 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 43, f, 41, 42 }, - { -70, -70, f, -70, -70, -70, -70, -70, -70, -70, -70, -70, -70, -70, f, f, f, -70, -70, -70, -70, -70, f, -70, f, -70, -70, -70, -70, -70, -70, f, f, -70, -70, -70, -70, -70, f, -70, -70, -70, -70, -70, -70, -70, -70, -70, -70, -70, -70 }, - { -20, -20, f, -20, -20, f, -20, -20, -20, 39, f, -20, -20, f, f, f, f, -20, -20, -20, -20, -20, f, -20, f, -20, -20, -20, -20, -20, -20, f, f, -20, -20, -20, -20, -20, f, f, -20, -20, -20, -20, -20, -20, f, -20, -20, -20, -20 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 40, f, f, 41, 42 }, - { -36, -36, -36, -36, -36, -36, -36, -36, -36, 39, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36 }, - { -72, -72, f, -72, -72, -72, -72, -72, -72, -72, -72, -72, -72, -72, f, f, f, -72, -72, -72, -72, -72, f, -72, f, -72, -72, -72, -72, -72, -72, f, f, -72, -72, -72, -72, -72, f, -72, -72, -72, -72, -72, -72, -72, -72, -72, -72, -72, -72 }, - { -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35 }, - { f, f, f, f, 44, f, f, f, f, f, f, 52, f, f, f, f, f, 54, 46, 48, 60, f, f, 62, f, f, f, 64, 66, f, f, f, f, 68, f, f, f, f, f, f, f, 50, 72, f, 56, f, f, f, f, 70, 58 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 45, f, 41, 42 }, - { -24, -24, f, -24, -24, f, -24, -24, -24, f, f, -24, -24, f, f, f, f, -24, 46, 48, -24, -24, f, -24, f, -24, -24, -24, -24, -24, -24, f, f, -24, -24, -24, -24, -24, f, f, -24, 50, -24, -24, -24, -24, f, -24, -24, -24, -24 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 47, f, 41, 42 }, - { -25, -25, f, -25, -25, f, -25, -25, -25, f, f, -25, -25, f, f, f, f, -25, -25, -25, -25, -25, f, -25, f, -25, -25, -25, -25, -25, -25, f, f, -25, -25, -25, -25, -25, f, f, -25, -25, -25, -25, -25, -25, f, -25, -25, -25, -25 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 49, f, 41, 42 }, - { -27, -27, f, -27, -27, f, -27, -27, -27, f, f, -27, -27, f, f, f, f, -27, -27, -27, -27, -27, f, -27, f, -27, -27, -27, -27, -27, -27, f, f, -27, -27, -27, -27, -27, f, f, -27, -27, -27, -27, -27, -27, f, -27, -27, -27, -27 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 51, f, 41, 42 }, - { -26, -26, f, -26, -26, f, -26, -26, -26, f, f, -26, -26, f, f, f, f, -26, -26, -26, -26, -26, f, -26, f, -26, -26, -26, -26, -26, -26, f, f, -26, -26, -26, -26, -26, f, f, -26, -26, -26, -26, -26, -26, f, -26, -26, -26, -26 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 53, f, 41, 42 }, - { -22, -22, f, -22, 44, f, -22, -22, -22, f, f, -22, -22, f, f, f, f, 54, 46, 48, 60, -22, f, 62, f, -22, -22, 64, 66, -22, -22, f, f, 68, -22, -22, -22, -22, f, f, -22, 50, -22, -22, 56, -22, f, -22, -22, 70, 58 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 55, f, 41, 42 }, - { -30, -30, f, -30, 44, f, -30, -30, -30, f, f, -30, -30, f, f, f, f, -30, 46, 48, -30, -30, f, -30, f, -30, -30, -30, -30, -30, -30, f, f, -30, -30, -30, -30, -30, f, f, -30, 50, -30, -30, 56, -30, f, -30, -30, -30, 58 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 57, f, 41, 42 }, - { -28, -28, f, -28, 44, f, -28, -28, -28, f, f, -28, -28, f, f, f, f, -28, 46, 48, -28, -28, f, -28, f, -28, -28, -28, -28, -28, -28, f, f, -28, -28, -28, -28, -28, f, f, -28, 50, -28, -28, 56, -28, f, -28, -28, -28, 58 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 59, f, 41, 42 }, - { -23, -23, f, -23, -23, f, -23, -23, -23, f, f, -23, -23, f, f, f, f, -23, 46, 48, -23, -23, f, -23, f, -23, -23, -23, -23, -23, -23, f, f, -23, -23, -23, -23, -23, f, f, -23, 50, -23, -23, -23, -23, f, -23, -23, -23, -23 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 61, f, 41, 42 }, - { -31, -31, f, -31, 44, f, -31, -31, -31, f, f, -31, -31, f, f, f, f, -31, 46, 48, -31, -31, f, -31, f, -31, -31, -31, -31, -31, -31, f, f, -31, -31, -31, -31, -31, f, f, -31, 50, -31, -31, 56, -31, f, -31, -31, -31, 58 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 63, f, 41, 42 }, - { -32, -32, f, -32, 44, f, -32, -32, -32, f, f, -32, -32, f, f, f, f, -32, 46, 48, -32, -32, f, -32, f, -32, -32, -32, -32, -32, -32, f, f, -32, -32, -32, -32, -32, f, f, -32, 50, -32, -32, 56, -32, f, -32, -32, -32, 58 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 65, f, 41, 42 }, - { -33, -33, f, -33, 44, f, -33, -33, -33, f, f, -33, -33, f, f, f, f, -33, 46, 48, -33, -33, f, -33, f, -33, -33, -33, -33, -33, -33, f, f, -33, -33, -33, -33, -33, f, f, -33, 50, -33, -33, 56, -33, f, -33, -33, -33, 58 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 67, f, 41, 42 }, - { -34, -34, f, -34, 44, f, -34, -34, -34, f, f, -34, -34, f, f, f, f, -34, 46, 48, -34, -34, f, -34, f, -34, -34, -34, -34, -34, -34, f, f, -34, -34, -34, -34, -34, f, f, -34, 50, -34, -34, 56, -34, f, -34, -34, -34, 58 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 69, f, 41, 42 }, - { -29, -29, f, -29, 44, f, -29, -29, -29, f, f, -29, -29, f, f, f, f, -29, 46, 48, -29, -29, f, -29, f, -29, -29, -29, -29, -29, -29, f, f, -29, -29, -29, -29, -29, f, f, -29, 50, -29, -29, 56, -29, f, -29, -29, -29, 58 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 71, f, 41, 42 }, - { -21, -21, f, -21, 44, f, -21, -21, -21, f, f, -21, -21, f, f, f, f, 54, 46, 48, 60, -21, f, 62, f, -21, -21, 64, 66, -21, -21, f, f, 68, -21, -21, -21, -21, f, f, -21, 50, -21, -21, 56, -21, f, -21, -21, -21, 58 }, - { -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, -60, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, 74, f, 77, f, f, f, f, f, 37, f, f, 38, 79, f, 41, 42 }, - { f, -61, f, f, f, f, -61, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -61, -61, -61, -61, f, f, f, f, f, -61, f, 75 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 76, f, 41, 42 }, - { -65, -65, f, f, 44, f, -65, -65, -65, f, f, 52, -65, f, f, f, f, 54, 46, 48, 60, -65, f, 62, f, -65, -65, 64, 66, -65, -65, f, f, 68, -65, -65, -65, -65, f, f, -65, 50, f, -65, 56, -65, f, f, -65, 70, 58 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 78 }, - { -17, -17, f, -17, -17, -17, -17, -17, -17, -17, -17, -17, -17, -17, f, f, f, -17, -17, -17, -17, -17, f, -17, f, -17, -17, -17, -17, -17, -17, f, f, -17, -17, -17, -17, -17, f, -17, -17, -17, -17, -17, -17, -17, -17, -17, -17, -17, -17 }, - { -64, -64, f, f, 44, f, -64, -64, -64, f, f, 52, -64, f, f, f, f, 54, 46, 48, 60, -64, f, 62, f, -64, -64, 64, 66, -64, -64, f, f, 68, -64, -64, -64, -64, f, f, -64, 50, f, -64, 56, -64, f, f, -64, 70, 58 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 81 }, - { -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 83 }, - { f, f, f, f, f, 35, f, f, f, f, f, f, 73, 10, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 84, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 85 }, - { -19, -19, f, -19, -19, -19, -19, -19, -19, -19, -19, -19, -19, -19, f, f, f, -19, -19, -19, -19, -19, f, -19, f, -19, -19, -19, -19, -19, -19, f, f, -19, -19, -19, -19, -19, f, -19, -19, -19, -19, -19, -19, -19, -19, -19, -19, -19, -19 }, - { -16, -16, f, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, f, f, f, -16, -16, -16, -16, -16, f, -16, f, -16, -16, -16, -16, -16, -16, f, f, -16, -16, -16, -16, -16, f, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16 }, - { -15, -15, f, -15, -15, -15, -15, -15, -15, -15, -15, -15, -15, -15, f, f, f, -15, -15, -15, -15, -15, f, -15, f, -15, -15, -15, -15, -15, -15, f, f, -15, -15, -15, -15, -15, f, -15, -15, -15, -15, -15, -15, -15, -15, -15, -15, -15, -15 }, - { -38, -38, -38, -38, -38, -38, -38, -38, -38, 39, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38 }, - { -39, -39, -39, -39, -39, -39, -39, -39, -39, 39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39 }, - { f, f, f, f, 44, f, f, f, f, f, f, 52, f, f, f, f, f, 54, 46, 48, 60, f, f, 62, f, f, f, 64, 66, f, f, f, f, 68, f, f, f, f, f, f, f, 50, 90, f, 56, f, f, f, f, 70, 58 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 91 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 92, f, 41, 42 }, - { f, f, f, f, 44, f, -94, f, f, f, f, 52, f, f, f, f, f, 54, 46, 48, 60, f, f, 62, f, f, f, 64, 66, f, f, f, f, 68, f, f, f, f, f, f, f, 50, f, f, 56, -94, f, -94, f, 70, 58 }, - { -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, 94, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, -97 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 95, f, 41, 42 }, - { f, f, f, f, 44, f, -93, f, f, f, f, 52, f, f, f, f, f, 54, 46, 48, 60, f, f, 62, f, f, f, 64, 66, f, f, f, f, 68, f, f, f, f, f, f, f, 50, f, f, 56, -93, f, -93, f, 70, 58 }, - { f, f, f, f, f, f, 97, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 98, f, -90, f, f, f, f, f, f, 99 }, - { f, f, -95, f, -95, -95, f, f, f, f, -95, f, -95, -95, -95, -95, -95, f, f, f, f, f, -95, f, f, f, -95, f, f, -95, f, -95, f, f, f, f, f, f, -95, f, f, f, f, f, f, f, f, -95 }, - { f, f, -96, f, -96, -96, f, f, f, f, -96, f, -96, -96, -96, -96, -96, f, f, f, f, f, -96, f, f, f, -96, f, f, -96, f, -96, f, f, f, f, f, f, -96, f, f, f, f, f, f, f, f, -96 }, - { f, f, 6, f, 7, 8, f, f, f, f, 11, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 93, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, -89, f, f, f, f, f, 32, f, 96, 100, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 101, f, 41, 42 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -91 }, - { f, f, f, f, 44, f, -92, f, f, f, f, 52, f, f, f, f, f, 54, 46, 48, 60, f, f, 62, f, f, f, 64, 66, f, f, f, f, 68, f, f, f, f, f, f, f, 50, f, f, 56, -92, f, -92, f, 70, 58 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 103 }, - { -88, -88, f, -88, -88, -88, -88, -88, -88, -88, -88, -88, -88, -88, f, f, f, -88, -88, -88, -88, -88, f, -88, f, -88, -88, -88, -88, -88, -88, f, f, -88, -88, -88, -88, -88, f, -88, -88, -88, -88, -88, -88, -88, -88, -88, -88, -88, -88 }, - { f, f, f, f, 44, f, f, f, f, f, f, 52, f, f, f, f, f, 54, 46, 48, 60, f, f, 62, f, f, f, 64, 66, f, f, f, f, 68, f, f, f, f, f, f, f, 50, f, 105, 56, f, f, f, f, 70, 58 }, - { -71, -71, f, -71, -71, -71, -71, -71, -71, -71, -71, -71, -71, -71, f, f, f, -71, -71, -71, -71, -71, f, -71, f, -71, -71, -71, -71, -71, -71, f, f, -71, -71, -71, -71, -71, f, -71, -71, -71, -71, -71, -71, -71, -71, -71, -71, -71, -71 }, - { -37, -37, -37, -37, -37, -37, -37, -37, -37, 39, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37 }, - { f, f, f, f, 44, f, f, f, f, f, f, 52, f, f, f, f, f, 54, 46, 48, 60, f, f, 62, f, f, f, 64, 66, f, f, f, f, 68, f, f, f, f, f, f, 108, 50, f, f, 56, f, f, f, f, 70, 58 }, - { -53, f, f, f, f, f, f, -53, -53, f, f, f, -53, f, f, f, f, f, f, f, f, -53, f, f, f, -53, -53, f, f, -53, -53, f, f, f, f, -53, f, f, f, f, -53, f, f, f, f, f, f, f, -53, f, f, f, f, f, f, f, f, f, 109, f, f, f, f, f, f, f, f, f, 4 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 110 }, - { -75, -75, f, f, f, f, -75, -75, -75, f, f, f, -75, f, f, f, f, f, f, f, f, -75, f, f, f, -75, -75, f, f, -75, -75, f, f, f, -75, -75, -75, -75, f, f, -75, f, f, f, f, f, f, f, -75 }, - { f, -60, 6, f, 7, 8, -60, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, -60, -60, -60, -60, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, 74, f, 112, f, f, f, f, f, 37, f, f, 38, 79, f, 41, 42 }, - { f, -44, f, f, f, f, 113, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -44, -44, -44, -44 }, - { f, -45, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -45, -45, -45, -45 }, - { -53, -53, f, f, f, f, f, -53, -53, f, f, f, -53, f, f, f, f, f, f, f, f, -53, f, f, f, -53, -53, f, f, -53, -53, f, f, f, f, f, f, f, f, f, -53, f, f, f, f, f, f, f, -53, f, f, f, f, f, f, f, f, f, 115, f, f, f, f, f, f, f, f, f, 4 }, - { f, 116 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 117, f, 41, 42 }, - { -76, -76, f, f, 44, f, -76, -76, -76, f, f, 52, -76, f, f, f, f, 54, 46, 48, 60, -76, f, 62, f, -76, -76, 64, 66, -76, -76, f, f, 68, -76, -76, -76, -76, f, f, -76, 50, f, f, 56, f, f, f, -76, 70, 58 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 16, f, f, 119, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 124, f, f, f, f, f, f, f, 125 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 16, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 120 }, - { f, f, f, f, f, f, f, f, f, f, f, f, 18, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 121 }, - { -53, f, f, f, f, f, f, -53, -53, f, f, f, -53, f, f, f, f, f, f, f, f, -53, f, f, f, -53, -53, f, f, -53, -53, f, f, f, f, -53, f, f, f, f, -53, f, f, f, f, f, f, f, -53, f, f, f, f, f, f, f, f, f, 122, f, f, f, f, f, f, f, f, f, 4 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 123 }, - { -84, -84, f, f, f, f, -84, -84, -84, f, f, f, -84, f, f, f, f, f, f, f, f, -84, f, f, f, -84, -84, f, f, -84, -84, f, f, f, -84, -84, -84, -84, f, f, -84, f, f, f, f, f, f, f, -84 }, - { -68, -68, f, f, f, f, -68, -68, -68, f, f, f, -68, f, f, f, f, f, f, f, f, -68, f, f, f, -68, -68, f, f, -68, -68, f, -68, f, -68, -68, -68, -68, f, f, -68, f, f, f, f, -68, f, f, -68 }, - { -82, -82, f, f, f, f, -82, -82, -82, f, f, f, -82, f, f, f, f, f, f, f, f, -82, f, f, f, -82, -82, f, f, -82, -82, f, 126, f, -82, -82, -82, -82, f, f, -82, f, f, f, f, 128, f, f, -82 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, 127, f, f, f, f, f, f, f, 37, f, f, 38, 79, f, 41, 42 }, - { -83, -83, f, f, f, f, -83, -83, -83, f, f, f, -83, f, f, f, f, f, f, f, f, -83, f, f, f, -83, -83, f, f, -83, -83, f, f, f, -83, -83, -83, -83, f, f, -83, f, f, f, f, 75, f, f, -83 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 16, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 129 }, - { -69, -69, f, f, f, f, -69, -69, -69, f, f, f, -69, f, f, f, f, f, f, f, f, -69, f, f, -69, -69, -69, f, f, -69, -69, f, -69, f, -69, -69, -69, -69, f, f, -69, f, f, f, f, -69, f, f, -69 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 131, f, 41, 42 }, - { f, f, f, 132, 44, f, f, f, f, f, f, 52, f, f, f, f, f, 54, 46, 48, 60, f, f, 62, f, f, f, 64, 66, f, f, f, f, 68, f, f, f, f, f, f, f, 50, f, f, 56, f, f, f, f, 70, 58 }, - { -53, f, f, f, f, f, f, -53, -53, f, f, f, -53, f, f, f, f, f, f, f, f, -53, f, f, f, -53, -53, f, f, -53, -53, f, f, f, f, -53, -53, -53, f, f, -53, f, f, f, f, f, f, f, -53, f, f, f, f, f, f, f, f, f, 133, f, f, f, f, f, f, f, f, f, 4 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -56, -56, -56, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 134 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 135, 136, 140 }, - { -77, -77, f, f, f, f, -77, -77, -77, f, f, f, -77, f, f, f, f, f, f, f, f, -77, f, f, f, -77, -77, f, f, -77, -77, f, f, f, -77, -77, -77, -77, f, f, -77, f, f, f, f, f, f, f, -77 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 137, f, 41, 42 }, - { f, f, f, 138, 44, f, f, f, f, f, f, 52, f, f, f, f, f, 54, 46, 48, 60, f, f, 62, f, f, f, 64, 66, f, f, f, f, 68, f, f, f, f, f, f, f, 50, f, f, 56, f, f, f, f, 70, 58 }, - { -53, f, f, f, f, f, f, -53, -53, f, f, f, -53, f, f, f, f, f, f, f, f, -53, f, f, f, -53, -53, f, f, -53, -53, f, f, f, f, -53, -53, -53, f, f, -53, f, f, f, f, f, f, f, -53, f, f, f, f, f, f, f, f, f, 139, f, f, f, f, f, f, f, f, f, 4 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -57, -57, -57 }, - { -53, f, f, f, f, f, f, -53, -53, f, f, f, -53, f, f, f, f, f, f, f, f, -53, f, f, f, -53, -53, f, f, -53, -53, f, f, f, f, -53, f, f, f, f, -53, f, f, f, f, f, f, f, -53, f, f, f, f, f, f, f, f, f, 141, f, f, f, f, f, f, f, f, f, 4 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 142 }, - { -78, -78, f, f, f, f, -78, -78, -78, f, f, f, -78, f, f, f, f, f, f, f, f, -78, f, f, f, -78, -78, f, f, -78, -78, f, f, f, -78, -78, -78, -78, f, f, -78, f, f, f, f, f, f, f, -78 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 16, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 144, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 145 }, - { f, f, f, f, f, f, f, f, f, f, f, f, -40, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -40, f, f, f, f, f, f, -40 }, - { f, f, f, f, f, f, f, f, f, f, f, f, 18, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 146, f, f, f, f, f, f, 148, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 150 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 147 }, - { f, f, f, f, f, f, f, f, f, f, f, f, -41, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -41, f, f, f, f, f, f, -41 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 149 }, - { f, f, f, f, f, f, f, f, f, f, f, f, -42, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -42, f, f, f, f, f, f, -42 }, - { -53, f, f, f, f, f, f, -53, -53, f, f, f, -53, f, f, f, f, f, f, f, f, -53, f, f, f, -53, -53, f, f, -53, -53, f, f, f, f, -53, f, f, f, f, -53, f, f, f, f, f, f, f, -53, f, f, f, f, f, f, f, f, f, 151, f, f, f, f, f, f, f, f, f, 4 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 152 }, - { -85, -85, f, f, f, f, -85, -85, -85, f, f, f, -85, f, f, f, f, f, f, f, f, -85, f, f, f, -85, -85, f, f, -85, -85, f, f, f, -85, -85, -85, -85, f, f, -85, f, f, f, f, f, f, f, -85 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 16, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 154, f, f, f, f, f, f, f, 167 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -68, f, f, f, f, f, f, f, 155, f, f, f, f, f, f, f, f, f, f, f, f, -68 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 156, f, 41, 42 }, - { f, f, f, f, 44, f, f, f, f, f, f, 52, f, f, f, f, f, 54, 46, 48, 60, f, f, 62, f, f, f, 64, 66, f, f, f, f, 68, f, f, f, f, f, f, f, 50, f, f, 56, 157, f, f, f, 70, 58 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 158, f, 41, 42 }, - { f, f, f, f, 44, f, f, f, f, f, f, 52, f, f, f, f, f, 54, 46, 48, 60, f, f, 62, f, f, f, 64, 66, f, f, f, f, 68, f, f, f, f, f, f, 159, 50, f, f, 56, 162, f, f, f, 70, 58 }, - { -53, f, f, f, f, f, f, -53, -53, f, f, f, -53, f, f, f, f, f, f, f, f, -53, f, f, f, -53, -53, f, f, -53, -53, f, f, f, f, -53, f, f, f, f, -53, f, f, f, f, f, f, f, -53, f, f, f, f, f, f, f, f, f, 160, f, f, f, f, f, f, f, f, f, 4 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 161 }, - { -79, -79, f, f, f, f, -79, -79, -79, f, f, f, -79, f, f, f, f, f, f, f, f, -79, f, f, f, -79, -79, f, f, -79, -79, f, f, f, -79, -79, -79, -79, f, f, -79, f, f, f, f, f, f, f, -79 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, f, f, f, f, f, f, f, f, 37, f, f, 38, 163, f, 41, 42 }, - { f, f, f, f, 44, f, f, f, f, f, f, 52, f, f, f, f, f, 54, 46, 48, 60, f, f, 62, f, f, f, 64, 66, f, f, f, f, 68, f, f, f, f, f, f, 164, 50, f, f, 56, f, f, f, f, 70, 58 }, - { -53, f, f, f, f, f, f, -53, -53, f, f, f, -53, f, f, f, f, f, f, f, f, -53, f, f, f, -53, -53, f, f, -53, -53, f, f, f, f, -53, f, f, f, f, -53, f, f, f, f, f, f, f, -53, f, f, f, f, f, f, f, f, f, 165, f, f, f, f, f, f, f, f, f, 4 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 166 }, - { -80, -80, f, f, f, f, -80, -80, -80, f, f, f, -80, f, f, f, f, f, f, f, f, -80, f, f, f, -80, -80, f, f, -80, -80, f, f, f, -80, -80, -80, -80, f, f, -80, f, f, f, f, f, f, f, -80 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 168, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 128 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, 169, f, f, f, f, f, f, f, 37, f, f, 38, 79, f, 41, 42 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 170, f, f, f, f, 75 }, - { -53, f, f, f, f, f, f, -53, -53, f, f, f, -53, f, f, f, f, f, f, f, f, -53, f, f, f, -53, -53, f, f, -53, -53, f, f, f, f, -53, f, f, f, f, -53, f, f, f, f, f, f, f, -53, f, f, f, f, f, f, f, f, f, 171, f, f, f, f, f, f, f, f, f, 4 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 172 }, - { -81, -81, f, f, f, f, -81, -81, -81, f, f, f, -81, f, f, f, f, f, f, f, f, -81, f, f, f, -81, -81, f, f, -81, -81, f, f, f, -81, -81, -81, -81, f, f, -81, f, f, f, f, f, f, f, -81 }, - { -53, f, f, f, f, f, f, -53, -53, f, f, f, -53, f, f, f, f, f, f, f, f, -53, f, f, f, -53, -53, f, f, -53, -53, f, f, f, f, -53, f, f, f, f, -53, f, f, f, f, f, f, f, -53, f, f, f, f, f, f, f, f, f, 174, f, f, f, f, f, f, f, f, f, 4 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 175 }, - { -73, -73, f, f, f, f, -73, -73, -73, f, f, f, -73, f, f, f, f, f, f, f, f, -73, f, f, f, -73, -73, f, f, -73, -73, f, f, f, -73, -73, -73, -73, f, f, -73, f, f, f, f, f, f, f, -73 }, - { f, -46, f, f, f, f, 177, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -46, -46, -46, -46 }, - { f, -47, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -47, -47, -47, -47 }, - { -54, -54, f, f, f, f, 179, -54, -54, f, f, f, -54, f, f, f, f, f, f, f, f, -54, f, f, f, -54, -54, f, f, -54, -54, f, f, f, -54, -54, -54, -54, f, f, -54, f, f, f, f, f, f, f, -54 }, - { -55, -55, f, f, f, f, f, -55, -55, f, f, f, -55, f, f, f, f, f, f, f, f, -55, f, f, f, -55, -55, f, f, -55, -55, f, f, f, -55, -55, -55, -55, f, f, -55, f, f, f, f, f, f, f, -55 }, - { f, f, f, f, f, 35, f, f, f, f, 36, f, 73, 10, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 80, f, f, f, f, f, f, 82, f, f, f, f, f, f, f, f, f, f, 84, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 86 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 182, f, f, f, f, f, f, f, f, f, f, f, f, 184 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, 183, f, f, f, f, f, f, f, 37, f, f, 38, 79, f, 41, 42 }, - { -74, -74, f, f, f, f, -74, -74, -74, f, f, f, -74, f, f, f, f, f, f, f, f, -74, f, f, f, -74, -74, f, f, -74, -74, f, f, f, -74, -74, -74, -74, f, f, -74, f, f, f, f, 75, f, f, -74 }, - { f, f, f, f, f, f, f, f, f, f, f, f, 9, f, f, f, f, f, f, f, f, f, f, f, f, f, 16, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, f, f, f, 180, f, f, f, f, f, f, f, f, f, f, 185, f, f, f, f, f, 41 }, - { f, f, f, f, f, -70, f, f, f, f, -70, f, -70, -70, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -67, f, f, f, f, f, f, -70, f, f, f, f, f, -67, -70 }, - { f, f, f, f, f, -70, f, f, f, f, -70, f, -70, -70, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -66, f, f, f, f, f, f, -70, f, f, f, f, f, -66, -70 }, - { -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87, -87 }, - { -86, -86, f, f, f, -72, -86, -86, -86, f, -72, f, -72, -72, f, f, f, f, f, f, f, -86, f, f, f, -86, -86, f, f, -86, -86, f, f, f, -86, -86, -86, -86, f, -72, -86, f, f, f, f, f, -72, f, -86 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -1 }, - { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, f, 17, f, 30, f, f, f, f, f, f, 31, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 32, f, f, f, 33, f, f, 34, f, f, 191, f, f, f, f, f, 193, f, 37, f, f, 38, 79, f, 41, 42 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 192, f, f, f, f, f, f, f, f, f, f, 75 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -52 }, - { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -2 }, + { -55, f, f, f, f, f, -55, -55, -55, f, f, f, -55, f, f, f, f, f, f, f, f, -55, f, f, f, -55, -55, f, -55, f, -55, -55, f, f, f, -55, f, f, f, -55, f, f, -55, f, f, f, f, f, f, f, -55, f, f, f, f, f, f, f, f, f, 2, f, f, f, f, f, f, f, f, 4, f, f, 195 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 3 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -51 }, + { 5, -45, f, f, f, f, 113, 114, 117, f, f, f, 9, f, f, f, f, f, f, f, f, 121, f, f, f, 133, 16, f, 146, f, 148, 158, f, f, f, -45, -45, -45, -45, 178, f, f, 181, f, f, f, f, f, f, f, 184, f, f, f, f, 34, f, f, f, f, f, 185, 186, f, 187, f, f, f, f, f, f, f, f, 192, 193, 24, f, f, f, f, 194 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 109, f, 43, 44 }, + { -9, -9, f, -9, -9, f, -9, -9, -9, -9, f, -9, -9, f, f, f, f, -9, -9, -9, -9, -9, f, -9, f, -9, -9, -9, -9, -9, -9, -9, f, f, -9, -9, -9, -9, -9, -9, f, f, -9, -9, -9, -9, -9, -9, f, -9, -9, -9, -9 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 108, f, f, 43, 44 }, + { -13, -13, f, -13, -13, f, -13, -13, -13, -13, f, -13, -13, f, f, f, f, -13, -13, -13, -13, -13, f, -13, f, -13, -13, -13, -13, -13, -13, -13, f, f, -13, -13, -13, -13, -13, -13, f, f, -13, -13, -13, -13, -13, -13, f, -13, -13, -13, -13 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 106, f, 43, 44 }, + { f, f, 6, f, 7, 8, f, f, f, f, 11, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, -92, f, f, f, f, f, 34, f, 95, 104, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 100, f, 40, 103, f, 43, 44 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 91, f, 43, 44 }, + { -12, -12, f, -12, -12, f, -12, -12, -12, -12, f, -12, -12, f, f, f, f, -12, -12, -12, -12, -12, f, -12, f, -12, -12, -12, -12, -12, -12, -12, f, f, -12, -12, -12, -12, -12, -12, f, f, -12, -12, -12, -12, -12, -12, f, -12, -12, -12, -12 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 90, f, f, 43, 44 }, + { -8, -8, f, -8, -8, f, -8, -8, -8, -8, f, -8, -8, f, f, f, f, -8, -8, -8, -8, -8, f, -8, f, -8, -8, -8, -8, -8, -8, -8, f, f, -8, -8, -8, -8, -8, -8, f, f, -8, -8, -8, -8, -8, -8, f, -8, -8, -8, -8 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 89, f, f, 43, 44 }, + { -43, -43, f, -43, -43, -43, -43, -43, -43, -43, -43, -43, -43, -43, f, f, f, -43, -43, -43, -43, -43, f, -43, -43, -43, -43, -43, -43, -43, -43, -43, f, -43, -43, -43, -43, -43, -43, -43, f, -43, -43, -43, -43, -43, -43, -43, -43, -43, -43, -43, -43 }, + { -44, -44, f, -44, -44, -44, -44, -44, -44, -44, -44, -44, -44, -44, f, f, f, -44, -44, -44, -44, -44, f, -44, -44, -44, -44, -44, -44, -44, -44, -44, f, -44, -44, -44, -44, -44, -44, -44, f, -44, -44, -44, -44, -44, -44, -44, -44, -44, -44, -44, -44 }, + { f, f, f, f, f, f, f, f, f, f, f, f, 19, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 29 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 16, f, 17, f, f, f, f, f, f, f, f, f, f, f, 20, f, f, f, f, -57, f, f, f, f, f, f, f, f, f, 21, f, f, f, f, f, f, f, f, f, f, 22, f, 26, f, f, f, f, f, f, 24, f, f, f, f, f, f, f, 28 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -4, f, -4 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -3, f, -3 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -58, f, 23 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 16, f, 17, f, f, f, f, f, f, f, f, f, f, f, 20, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 21, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 24, f, f, f, f, f, f, f, 25 }, + { -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -62, f, -62 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 27 }, + { -5, f, f, f, f, f, -5, -5, -5, f, f, f, -5, f, f, f, f, f, f, f, f, -5, f, f, f, -5, -5, f, -5, f, -5, -5, f, f, f, f, -5, f, f, -5, f, f, -5, f, f, f, f, f, f, f, -5 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -61, f, -61 }, + { -55, f, f, f, f, f, -55, -55, -55, f, f, f, -55, f, f, f, f, f, f, f, f, -55, f, f, f, -55, -55, f, -55, f, -55, -55, f, f, f, f, -55, f, f, -55, f, f, -55, f, f, f, f, f, f, f, -55, f, f, f, f, f, f, f, f, f, 30, f, f, f, f, f, f, f, f, 4 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 31 }, + { -14, -14, f, -14, -14, f, -14, -14, -14, -14, f, -14, -14, f, f, f, f, -14, -14, -14, -14, -14, f, -14, f, -14, -14, -14, -14, -14, -14, -14, f, f, -14, -14, -14, -14, -14, -14, f, f, -14, -14, -14, -14, -14, -14, f, -14, -14, -14, -14 }, + { -10, -10, f, -10, -10, f, -10, -10, -10, -10, f, -10, -10, f, f, f, f, -10, -10, -10, -10, -10, f, -10, f, -10, -10, -10, -10, -10, -10, -10, f, f, -10, -10, -10, -10, -10, -10, f, f, -10, -10, -10, -10, -10, -10, f, -10, -10, -10, -10 }, + { -11, -11, f, -11, -11, f, -11, -11, -11, -11, f, -11, -11, f, f, f, f, -11, -11, -11, -11, -11, f, -11, f, -11, -11, -11, -11, -11, -11, -11, f, f, -11, -11, -11, -11, -11, -11, f, f, -11, -11, -11, -11, -11, -11, f, -11, -11, -11, -11 }, + { -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48 }, + { -7, -7, f, -7, -7, f, -7, -7, -7, -7, f, -7, -7, f, f, f, f, -7, -7, -7, -7, -7, f, -7, f, -7, -7, -7, -7, -7, -7, -7, f, f, -7, -7, -7, -7, -7, -7, f, f, -7, -7, -7, -7, -7, -7, f, -7, -7, -7, -7 }, + { -6, -6, f, -6, -6, 37, -6, -6, -6, -6, 38, -6, 75, 10, f, f, f, -6, -6, -6, -6, -6, f, -6, f, -6, -6, -6, -6, -6, -6, -6, f, f, -6, -6, -6, -6, -6, -6, f, 82, -6, -6, -6, -6, -6, -6, 84, -6, -6, -6, -6, f, f, f, f, f, f, 86, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 88 }, + { -18, -18, f, -18, -18, -18, -18, -18, -18, -18, -18, -18, -18, -18, f, f, f, -18, -18, -18, -18, -18, f, -18, f, -18, -18, -18, -18, -18, -18, -18, f, f, -18, -18, -18, -18, -18, -18, f, -18, -18, -18, -18, -18, -18, -18, -18, -18, -18, -18, -18 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 45, f, 43, 44 }, + { -69, -69, f, -69, -69, -69, -69, -69, -69, -69, -69, -69, -69, -69, f, f, f, -69, -69, -69, -69, -69, f, -69, f, -69, -69, -69, -69, -69, -69, -69, f, f, -69, -69, -69, -69, -69, -69, f, -69, -69, -69, -69, -69, -69, -69, -69, -69, -69, -69, -69 }, + { -20, -20, f, -20, -20, f, -20, -20, -20, 41, f, -20, -20, f, f, f, f, -20, -20, -20, -20, -20, f, -20, f, -20, -20, -20, -20, -20, -20, -20, f, f, -20, -20, -20, -20, -20, -20, f, f, -20, -20, -20, -20, -20, -20, f, -20, -20, -20, -20 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 42, f, f, 43, 44 }, + { -36, -36, -36, -36, -36, -36, -36, -36, -36, 41, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, -36 }, + { -71, -71, f, -71, -71, -71, -71, -71, -71, -71, -71, -71, -71, -71, f, f, f, -71, -71, -71, -71, -71, f, -71, f, -71, -71, -71, -71, -71, -71, -71, f, f, -71, -71, -71, -71, -71, -71, f, -71, -71, -71, -71, -71, -71, -71, -71, -71, -71, -71, -71 }, + { -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35, -35 }, + { f, f, f, f, 46, f, f, f, f, f, f, 54, f, f, f, f, f, 56, 48, 50, 62, f, f, 64, f, f, f, 66, f, 68, f, f, f, f, 70, f, f, f, f, f, f, f, f, 52, 74, f, 58, f, f, f, f, 72, 60 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 47, f, 43, 44 }, + { -24, -24, f, -24, -24, f, -24, -24, -24, f, f, -24, -24, f, f, f, f, -24, 48, 50, -24, -24, f, -24, f, -24, -24, -24, -24, -24, -24, -24, f, f, -24, -24, -24, -24, -24, -24, f, f, -24, 52, -24, -24, -24, -24, f, -24, -24, -24, -24 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 49, f, 43, 44 }, + { -25, -25, f, -25, -25, f, -25, -25, -25, f, f, -25, -25, f, f, f, f, -25, -25, -25, -25, -25, f, -25, f, -25, -25, -25, -25, -25, -25, -25, f, f, -25, -25, -25, -25, -25, -25, f, f, -25, -25, -25, -25, -25, -25, f, -25, -25, -25, -25 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 51, f, 43, 44 }, + { -27, -27, f, -27, -27, f, -27, -27, -27, f, f, -27, -27, f, f, f, f, -27, -27, -27, -27, -27, f, -27, f, -27, -27, -27, -27, -27, -27, -27, f, f, -27, -27, -27, -27, -27, -27, f, f, -27, -27, -27, -27, -27, -27, f, -27, -27, -27, -27 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 53, f, 43, 44 }, + { -26, -26, f, -26, -26, f, -26, -26, -26, f, f, -26, -26, f, f, f, f, -26, -26, -26, -26, -26, f, -26, f, -26, -26, -26, -26, -26, -26, -26, f, f, -26, -26, -26, -26, -26, -26, f, f, -26, -26, -26, -26, -26, -26, f, -26, -26, -26, -26 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 55, f, 43, 44 }, + { -22, -22, f, -22, 46, f, -22, -22, -22, f, f, -22, -22, f, f, f, f, 56, 48, 50, 62, -22, f, 64, f, -22, -22, 66, -22, 68, -22, -22, f, f, 70, -22, -22, -22, -22, -22, f, f, -22, 52, -22, -22, 58, -22, f, -22, -22, 72, 60 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 57, f, 43, 44 }, + { -30, -30, f, -30, 46, f, -30, -30, -30, f, f, -30, -30, f, f, f, f, -30, 48, 50, -30, -30, f, -30, f, -30, -30, -30, -30, -30, -30, -30, f, f, -30, -30, -30, -30, -30, -30, f, f, -30, 52, -30, -30, 58, -30, f, -30, -30, -30, 60 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 59, f, 43, 44 }, + { -28, -28, f, -28, 46, f, -28, -28, -28, f, f, -28, -28, f, f, f, f, -28, 48, 50, -28, -28, f, -28, f, -28, -28, -28, -28, -28, -28, -28, f, f, -28, -28, -28, -28, -28, -28, f, f, -28, 52, -28, -28, 58, -28, f, -28, -28, -28, 60 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 61, f, 43, 44 }, + { -23, -23, f, -23, -23, f, -23, -23, -23, f, f, -23, -23, f, f, f, f, -23, 48, 50, -23, -23, f, -23, f, -23, -23, -23, -23, -23, -23, -23, f, f, -23, -23, -23, -23, -23, -23, f, f, -23, 52, -23, -23, -23, -23, f, -23, -23, -23, -23 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 63, f, 43, 44 }, + { -31, -31, f, -31, 46, f, -31, -31, -31, f, f, -31, -31, f, f, f, f, -31, 48, 50, -31, -31, f, -31, f, -31, -31, -31, -31, -31, -31, -31, f, f, -31, -31, -31, -31, -31, -31, f, f, -31, 52, -31, -31, 58, -31, f, -31, -31, -31, 60 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 65, f, 43, 44 }, + { -32, -32, f, -32, 46, f, -32, -32, -32, f, f, -32, -32, f, f, f, f, -32, 48, 50, -32, -32, f, -32, f, -32, -32, -32, -32, -32, -32, -32, f, f, -32, -32, -32, -32, -32, -32, f, f, -32, 52, -32, -32, 58, -32, f, -32, -32, -32, 60 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 67, f, 43, 44 }, + { -33, -33, f, -33, 46, f, -33, -33, -33, f, f, -33, -33, f, f, f, f, -33, 48, 50, -33, -33, f, -33, f, -33, -33, -33, -33, -33, -33, -33, f, f, -33, -33, -33, -33, -33, -33, f, f, -33, 52, -33, -33, 58, -33, f, -33, -33, -33, 60 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 69, f, 43, 44 }, + { -34, -34, f, -34, 46, f, -34, -34, -34, f, f, -34, -34, f, f, f, f, -34, 48, 50, -34, -34, f, -34, f, -34, -34, -34, -34, -34, -34, -34, f, f, -34, -34, -34, -34, -34, -34, f, f, -34, 52, -34, -34, 58, -34, f, -34, -34, -34, 60 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 71, f, 43, 44 }, + { -29, -29, f, -29, 46, f, -29, -29, -29, f, f, -29, -29, f, f, f, f, -29, 48, 50, -29, -29, f, -29, f, -29, -29, -29, -29, -29, -29, -29, f, f, -29, -29, -29, -29, -29, -29, f, f, -29, 52, -29, -29, 58, -29, f, -29, -29, -29, 60 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 73, f, 43, 44 }, + { -21, -21, f, -21, 46, f, -21, -21, -21, f, f, -21, -21, f, f, f, f, 56, 48, 50, 62, -21, f, 64, f, -21, -21, 66, -21, 68, -21, -21, f, f, 70, -21, -21, -21, -21, -21, f, f, -21, 52, -21, -21, 58, -21, f, -21, -21, -21, 60 }, + { -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, -59, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, 76, f, 79, f, f, f, f, f, 39, f, 24, f, 40, 81, f, 43, 44 }, + { f, -60, f, f, f, f, -60, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -60, -60, -60, -60, f, f, f, f, f, f, -60, f, 77 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 78, f, 43, 44 }, + { -64, -64, f, f, 46, f, -64, -64, -64, f, f, 54, -64, f, f, f, f, 56, 48, 50, 62, -64, f, 64, f, -64, -64, 66, -64, 68, -64, -64, f, f, 70, -64, -64, -64, -64, -64, f, f, -64, 52, f, -64, 58, -64, f, f, -64, 72, 60 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 80 }, + { -17, -17, f, -17, -17, -17, -17, -17, -17, -17, -17, -17, -17, -17, f, f, f, -17, -17, -17, -17, -17, f, -17, f, -17, -17, -17, -17, -17, -17, -17, f, f, -17, -17, -17, -17, -17, -17, f, -17, -17, -17, -17, -17, -17, -17, -17, -17, -17, -17, -17 }, + { -63, -63, f, f, 46, f, -63, -63, -63, f, f, 54, -63, f, f, f, f, 56, 48, 50, 62, -63, f, 64, f, -63, -63, 66, -63, 68, -63, -63, f, f, 70, -63, -63, -63, -63, -63, f, f, -63, 52, f, -63, 58, -63, f, f, -63, 72, 60 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 16, f, 17, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 83 }, + { -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 16, f, 17, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 85 }, + { f, f, f, f, f, 37, f, f, f, f, f, f, 75, 10, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 86, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 87 }, + { -19, -19, f, -19, -19, -19, -19, -19, -19, -19, -19, -19, -19, -19, f, f, f, -19, -19, -19, -19, -19, f, -19, f, -19, -19, -19, -19, -19, -19, -19, f, f, -19, -19, -19, -19, -19, -19, f, -19, -19, -19, -19, -19, -19, -19, -19, -19, -19, -19, -19 }, + { -16, -16, f, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, f, f, f, -16, -16, -16, -16, -16, f, -16, f, -16, -16, -16, -16, -16, -16, -16, f, f, -16, -16, -16, -16, -16, -16, f, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16 }, + { -15, -15, f, -15, -15, -15, -15, -15, -15, -15, -15, -15, -15, -15, f, f, f, -15, -15, -15, -15, -15, f, -15, f, -15, -15, -15, -15, -15, -15, -15, f, f, -15, -15, -15, -15, -15, -15, f, -15, -15, -15, -15, -15, -15, -15, -15, -15, -15, -15, -15 }, + { -38, -38, -38, -38, -38, -38, -38, -38, -38, 41, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, -38 }, + { -39, -39, -39, -39, -39, -39, -39, -39, -39, 41, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, -39 }, + { f, f, f, f, 46, f, f, f, f, f, f, 54, f, f, f, f, f, 56, 48, 50, 62, f, f, 64, f, f, f, 66, f, 68, f, f, f, f, 70, f, f, f, f, f, f, f, f, 52, 92, f, 58, f, f, f, f, 72, 60 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 93 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 94, f, 43, 44 }, + { f, f, f, f, 46, f, -97, f, f, f, f, 54, f, f, f, f, f, 56, 48, 50, 62, f, f, 64, f, f, f, 66, f, 68, f, f, f, f, 70, f, f, f, f, f, f, f, f, 52, f, f, 58, -97, f, -97, f, 72, 60 }, + { f, f, f, f, f, f, 96, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 97, f, -93, f, f, f, f, f, f, 98 }, + { f, f, -98, f, -98, -98, f, f, f, f, -98, f, -98, -98, -98, -98, -98, f, f, f, f, f, -98, f, f, f, -98, f, -98, f, -98, f, -98, f, f, f, f, f, f, f, -98, f, f, f, f, f, f, f, f, -98 }, + { f, f, -99, f, -99, -99, f, f, f, f, -99, f, -99, -99, -99, -99, -99, f, f, f, f, f, -99, f, f, f, -99, f, -99, f, -99, f, -99, f, f, f, f, f, f, f, -99, f, f, f, f, f, f, f, f, -99 }, + { f, f, 6, f, 7, 8, f, f, f, f, 11, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, -92, f, f, f, f, f, 34, f, 95, 99, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 100, f, 40, 103, f, 43, 44 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -94 }, + { -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, 101, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 102, f, 43, 44 }, + { f, f, f, f, 46, f, -96, f, f, f, f, 54, f, f, f, f, f, 56, 48, 50, 62, f, f, 64, f, f, f, 66, f, 68, f, f, f, f, 70, f, f, f, f, f, f, f, f, 52, f, f, 58, -96, f, -96, f, 72, 60 }, + { f, f, f, f, 46, f, -95, f, f, f, f, 54, f, f, f, f, f, 56, 48, 50, 62, f, f, 64, f, f, f, 66, f, 68, f, f, f, f, 70, f, f, f, f, f, f, f, f, 52, f, f, 58, -95, f, -95, f, 72, 60 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 105 }, + { -91, -91, f, -91, -91, -91, -91, -91, -91, -91, -91, -91, -91, -91, f, f, f, -91, -91, -91, -91, -91, f, -91, f, -91, -91, -91, -91, -91, -91, -91, f, f, -91, -91, -91, -91, -91, -91, f, -91, -91, -91, -91, -91, -91, -91, -91, -91, -91, -91, -91 }, + { f, f, f, f, 46, f, f, f, f, f, f, 54, f, f, f, f, f, 56, 48, 50, 62, f, f, 64, f, f, f, 66, f, 68, f, f, f, f, 70, f, f, f, f, f, f, f, f, 52, f, 107, 58, f, f, f, f, 72, 60 }, + { -70, -70, f, -70, -70, -70, -70, -70, -70, -70, -70, -70, -70, -70, f, f, f, -70, -70, -70, -70, -70, f, -70, f, -70, -70, -70, -70, -70, -70, -70, f, f, -70, -70, -70, -70, -70, -70, f, -70, -70, -70, -70, -70, -70, -70, -70, -70, -70, -70, -70 }, + { -37, -37, -37, -37, -37, -37, -37, -37, -37, 41, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37 }, + { f, f, f, f, 46, f, f, f, f, f, f, 54, f, f, f, f, f, 56, 48, 50, 62, f, f, 64, f, f, f, 66, f, 68, f, f, f, f, 70, f, f, f, f, f, f, f, 110, 52, f, f, 58, f, f, f, f, 72, 60 }, + { -55, f, f, f, f, f, -55, -55, -55, f, f, f, -55, f, f, f, f, f, f, f, f, -55, f, f, f, -55, -55, f, -55, f, -55, -55, f, f, f, f, -55, f, f, -55, f, f, -55, f, f, f, f, f, f, f, -55, f, f, f, f, f, f, f, f, f, 111, f, f, f, f, f, f, f, f, 4 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 112 }, + { -74, -74, f, f, f, f, -74, -74, -74, f, f, f, -74, f, f, f, f, f, f, f, f, -74, f, f, f, -74, -74, f, -74, f, -74, -74, f, f, f, -74, -74, -74, -74, -74, f, f, -74, f, f, f, f, f, f, f, -74 }, + { -86, -86, f, f, f, f, -86, -86, -86, f, f, f, -86, f, f, f, f, f, f, f, f, -86, f, f, f, -86, -86, f, -86, f, -86, -86, f, f, f, -86, -86, -86, -86, -86, f, f, -86, f, f, f, f, f, f, f, -86 }, + { f, -59, 6, f, 7, 8, -59, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, -59, -59, -59, -59, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, 76, f, 115, f, f, f, f, f, 39, f, 24, f, 40, 81, f, 43, 44 }, + { f, -46, f, f, f, f, 116, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -46, -46, -46, -46 }, + { f, -47, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -47, -47, -47, -47 }, + { -55, -55, f, f, f, f, -55, -55, -55, f, f, f, -55, f, f, f, f, f, f, f, f, -55, f, f, f, -55, -55, f, -55, f, -55, -55, f, f, f, f, f, f, f, -55, f, f, -55, f, f, f, f, f, f, f, -55, f, f, f, f, f, f, f, f, f, 118, f, f, f, f, f, f, f, f, 4 }, + { f, 119 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 120, f, 43, 44 }, + { -75, -75, f, f, 46, f, -75, -75, -75, f, f, 54, -75, f, f, f, f, 56, 48, 50, 62, -75, f, 64, f, -75, -75, 66, -75, 68, -75, -75, f, f, 70, -75, -75, -75, -75, -75, f, f, -75, 52, f, f, 58, f, f, f, -75, 72, 60 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 16, f, 17, f, 122, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 127, f, f, f, f, f, f, f, 128, f, f, f, f, f, f, f, f, f, f, f, 24 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 16, f, 17, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 123, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 24 }, + { f, f, f, f, f, f, f, f, f, f, f, f, 19, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 124 }, + { -55, f, f, f, f, f, -55, -55, -55, f, f, f, -55, f, f, f, f, f, f, f, f, -55, f, f, f, -55, -55, f, -55, f, -55, -55, f, f, f, f, -55, f, f, -55, f, f, -55, f, f, f, f, f, f, f, -55, f, f, f, f, f, f, f, f, f, 125, f, f, f, f, f, f, f, f, 4 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 126 }, + { -83, -83, f, f, f, f, -83, -83, -83, f, f, f, -83, f, f, f, f, f, f, f, f, -83, f, f, f, -83, -83, f, -83, f, -83, -83, f, f, f, -83, -83, -83, -83, -83, f, f, -83, f, f, f, f, f, f, f, -83 }, + { -67, -67, f, f, f, f, -67, -67, -67, f, f, f, -67, f, f, f, f, f, f, f, f, -67, f, f, f, -67, -67, f, -67, f, -67, -67, f, -67, f, -67, -67, -67, -67, -67, f, f, -67, f, f, f, f, -67, f, f, -67 }, + { -81, -81, f, f, f, f, -81, -81, -81, f, f, f, -81, f, f, f, f, f, f, f, f, -81, f, f, f, -81, -81, f, -81, f, -81, -81, f, 129, f, -81, -81, -81, -81, -81, f, f, -81, f, f, f, f, 131, f, f, -81 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, 130, f, f, f, f, f, f, f, 39, f, 24, f, 40, 81, f, 43, 44 }, + { -82, -82, f, f, f, f, -82, -82, -82, f, f, f, -82, f, f, f, f, f, f, f, f, -82, f, f, f, -82, -82, f, -82, f, -82, -82, f, f, f, -82, -82, -82, -82, -82, f, f, -82, f, f, f, f, 77, f, f, -82 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 16, f, 17, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 132, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 24 }, + { -68, -68, f, f, f, f, -68, -68, -68, f, f, f, -68, f, f, f, f, f, f, f, f, -68, f, f, -68, -68, -68, f, -68, f, -68, -68, f, -68, f, -68, -68, -68, -68, -68, f, f, -68, f, f, f, f, -68, f, f, -68 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 134, f, 43, 44 }, + { f, f, f, 135, 46, f, f, f, f, f, f, 54, f, f, f, f, f, 56, 48, 50, 62, f, f, 64, f, f, f, 66, f, 68, f, f, f, f, 70, f, f, f, f, f, f, f, f, 52, f, f, 58, f, f, f, f, 72, 60 }, + { -55, f, f, f, f, f, -55, -55, -55, f, f, f, -55, f, f, f, f, f, f, f, f, -55, f, f, f, -55, -55, f, -55, f, -55, -55, f, f, f, f, -55, -55, -55, -55, f, f, -55, f, f, f, f, f, f, f, -55, f, f, f, f, f, f, f, f, f, 136, f, f, f, f, f, f, f, f, 4 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -53, -53, -53, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 137 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 138, 139, 143 }, + { -76, -76, f, f, f, f, -76, -76, -76, f, f, f, -76, f, f, f, f, f, f, f, f, -76, f, f, f, -76, -76, f, -76, f, -76, -76, f, f, f, -76, -76, -76, -76, -76, f, f, -76, f, f, f, f, f, f, f, -76 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 140, f, 43, 44 }, + { f, f, f, 141, 46, f, f, f, f, f, f, 54, f, f, f, f, f, 56, 48, 50, 62, f, f, 64, f, f, f, 66, f, 68, f, f, f, f, 70, f, f, f, f, f, f, f, f, 52, f, f, 58, f, f, f, f, 72, 60 }, + { -55, f, f, f, f, f, -55, -55, -55, f, f, f, -55, f, f, f, f, f, f, f, f, -55, f, f, f, -55, -55, f, -55, f, -55, -55, f, f, f, f, -55, -55, -55, -55, f, f, -55, f, f, f, f, f, f, f, -55, f, f, f, f, f, f, f, f, f, 142, f, f, f, f, f, f, f, f, 4 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -54, -54, -54 }, + { -55, f, f, f, f, f, -55, -55, -55, f, f, f, -55, f, f, f, f, f, f, f, f, -55, f, f, f, -55, -55, f, -55, f, -55, -55, f, f, f, f, -55, f, f, -55, f, f, -55, f, f, f, f, f, f, f, -55, f, f, f, f, f, f, f, f, f, 144, f, f, f, f, f, f, f, f, 4 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 145 }, + { -77, -77, f, f, f, f, -77, -77, -77, f, f, f, -77, f, f, f, f, f, f, f, f, -77, f, f, f, -77, -77, f, -77, f, -77, -77, f, f, f, -77, -77, -77, -77, -77, f, f, -77, f, f, f, f, f, f, f, -77 }, + { f, f, f, f, f, -44, f, f, f, f, -44, f, -44, -44, f, f, f, f, f, f, f, f, f, f, f, f, 16, f, 17, f, f, f, f, -44, f, f, f, f, f, f, f, -44, f, f, f, f, f, -44, -44, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 147 }, + { -88, -88, f, f, f, f, -88, -88, -88, f, f, f, -88, f, f, f, f, f, f, f, f, -88, f, f, f, -88, -88, f, -88, f, -88, -88, f, f, f, -88, -88, -88, -88, -88, f, f, -88, f, f, f, f, f, f, f, -88 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 16, f, 17, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 149, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 24, 150 }, + { f, f, f, f, f, f, f, f, f, f, f, f, -40, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -40, f, f, f, f, f, f, -40 }, + { f, f, f, f, f, f, f, f, f, f, f, f, 19, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 151, f, f, f, f, f, f, 153, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 155 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 152 }, + { f, f, f, f, f, f, f, f, f, f, f, f, -41, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -41, f, f, f, f, f, f, -41 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 154 }, + { f, f, f, f, f, f, f, f, f, f, f, f, -42, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -42, f, f, f, f, f, f, -42 }, + { -55, f, f, f, f, f, -55, -55, -55, f, f, f, -55, f, f, f, f, f, f, f, f, -55, f, f, f, -55, -55, f, -55, f, -55, -55, f, f, f, f, -55, f, f, -55, f, f, -55, f, f, f, f, f, f, f, -55, f, f, f, f, f, f, f, f, f, 156, f, f, f, f, f, f, f, f, 4 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 157 }, + { -84, -84, f, f, f, f, -84, -84, -84, f, f, f, -84, f, f, f, f, f, f, f, f, -84, f, f, f, -84, -84, f, -84, f, -84, -84, f, f, f, -84, -84, -84, -84, -84, f, f, -84, f, f, f, f, f, f, f, -84 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 16, f, 17, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 159, f, f, f, f, f, f, f, 172, f, f, f, f, f, f, f, f, f, f, f, 24 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -67, f, f, f, f, f, f, f, f, 160, f, f, f, f, f, f, f, f, f, f, f, f, f, -67 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 161, f, 43, 44 }, + { f, f, f, f, 46, f, f, f, f, f, f, 54, f, f, f, f, f, 56, 48, 50, 62, f, f, 64, f, f, f, 66, f, 68, f, f, f, f, 70, f, f, f, f, f, f, f, f, 52, f, f, 58, 162, f, f, f, 72, 60 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 163, f, 43, 44 }, + { f, f, f, f, 46, f, f, f, f, f, f, 54, f, f, f, f, f, 56, 48, 50, 62, f, f, 64, f, f, f, 66, f, 68, f, f, f, f, 70, f, f, f, f, f, f, f, 164, 52, f, f, 58, 167, f, f, f, 72, 60 }, + { -55, f, f, f, f, f, -55, -55, -55, f, f, f, -55, f, f, f, f, f, f, f, f, -55, f, f, f, -55, -55, f, -55, f, -55, -55, f, f, f, f, -55, f, f, -55, f, f, -55, f, f, f, f, f, f, f, -55, f, f, f, f, f, f, f, f, f, 165, f, f, f, f, f, f, f, f, 4 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 166 }, + { -78, -78, f, f, f, f, -78, -78, -78, f, f, f, -78, f, f, f, f, f, f, f, f, -78, f, f, f, -78, -78, f, -78, f, -78, -78, f, f, f, -78, -78, -78, -78, -78, f, f, -78, f, f, f, f, f, f, f, -78 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, f, f, f, f, f, f, f, f, 39, f, 24, f, 40, 168, f, 43, 44 }, + { f, f, f, f, 46, f, f, f, f, f, f, 54, f, f, f, f, f, 56, 48, 50, 62, f, f, 64, f, f, f, 66, f, 68, f, f, f, f, 70, f, f, f, f, f, f, f, 169, 52, f, f, 58, f, f, f, f, 72, 60 }, + { -55, f, f, f, f, f, -55, -55, -55, f, f, f, -55, f, f, f, f, f, f, f, f, -55, f, f, f, -55, -55, f, -55, f, -55, -55, f, f, f, f, -55, f, f, -55, f, f, -55, f, f, f, f, f, f, f, -55, f, f, f, f, f, f, f, f, f, 170, f, f, f, f, f, f, f, f, 4 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 171 }, + { -79, -79, f, f, f, f, -79, -79, -79, f, f, f, -79, f, f, f, f, f, f, f, f, -79, f, f, f, -79, -79, f, -79, f, -79, -79, f, f, f, -79, -79, -79, -79, -79, f, f, -79, f, f, f, f, f, f, f, -79 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 173, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 131 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, 174, f, f, f, f, f, f, f, 39, f, 24, f, 40, 81, f, 43, 44 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 175, f, f, f, f, 77 }, + { -55, f, f, f, f, f, -55, -55, -55, f, f, f, -55, f, f, f, f, f, f, f, f, -55, f, f, f, -55, -55, f, -55, f, -55, -55, f, f, f, f, -55, f, f, -55, f, f, -55, f, f, f, f, f, f, f, -55, f, f, f, f, f, f, f, f, f, 176, f, f, f, f, f, f, f, f, 4 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 177 }, + { -80, -80, f, f, f, f, -80, -80, -80, f, f, f, -80, f, f, f, f, f, f, f, f, -80, f, f, f, -80, -80, f, -80, f, -80, -80, f, f, f, -80, -80, -80, -80, -80, f, f, -80, f, f, f, f, f, f, f, -80 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 16, f, 17, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 179 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 180 }, + { -89, -89, f, f, f, f, -89, -89, -89, f, f, f, -89, f, f, f, f, f, f, f, f, -89, f, f, f, -89, -89, f, -89, f, -89, -89, f, f, f, -89, -89, -89, -89, -89, f, f, -89, f, f, f, f, f, f, f, -89 }, + { -55, f, f, f, f, f, -55, -55, -55, f, f, f, -55, f, f, f, f, f, f, f, f, -55, f, f, f, -55, -55, f, -55, f, -55, -55, f, f, f, f, -55, f, f, -55, f, f, -55, f, f, f, f, f, f, f, -55, f, f, f, f, f, f, f, f, f, 182, f, f, f, f, f, f, f, f, 4 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 183 }, + { -72, -72, f, f, f, f, -72, -72, -72, f, f, f, -72, f, f, f, f, f, f, f, f, -72, f, f, f, -72, -72, f, -72, f, -72, -72, f, f, f, -72, -72, -72, -72, -72, f, f, -72, f, f, f, f, f, f, f, -72 }, + { -87, -87, f, f, f, f, -87, -87, -87, f, f, f, -87, f, f, f, f, f, f, f, f, -87, f, f, f, -87, -87, f, -87, f, -87, -87, f, f, f, -87, -87, -87, -87, -87, f, f, -87, f, f, f, f, f, f, f, -87 }, + { -56, -56, f, f, f, f, -56, -56, -56, f, f, f, -56, f, f, f, f, f, f, f, f, -56, f, f, f, -56, -56, f, -56, f, -56, -56, f, f, f, -56, -56, -56, -56, -56, f, f, -56, f, f, f, f, f, f, f, -56 }, + { f, f, f, f, f, 37, f, f, f, f, 38, f, 75, 10, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 82, f, f, f, f, f, f, 84, f, f, f, f, f, f, f, f, f, f, 86, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 88 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 188, f, f, f, f, f, f, f, f, f, f, f, f, f, 190 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, 189, f, f, f, f, f, f, f, 39, f, 24, f, 40, 81, f, 43, 44 }, + { -73, -73, f, f, f, f, -73, -73, -73, f, f, f, -73, f, f, f, f, f, f, f, f, -73, f, f, f, -73, -73, f, -73, f, -73, -73, f, f, f, -73, -73, -73, -73, -73, f, f, -73, f, f, f, f, 77, f, f, -73 }, + { f, f, f, f, f, f, f, f, f, f, f, f, 9, f, f, f, f, f, f, f, f, f, f, f, f, f, 16, f, 17, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, f, f, f, 186, f, f, f, f, f, f, f, f, f, f, 191, f, 24, f, f, f, f, 43 }, + { f, f, f, f, f, -69, f, f, f, f, -69, f, -69, -69, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -66, f, f, f, f, f, f, f, -69, f, f, f, f, f, -66, -69 }, + { f, f, f, f, f, -69, f, f, f, f, -69, f, -69, -69, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -65, f, f, f, f, f, f, f, -69, f, f, f, f, f, -65, -69 }, + { -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90, -90 }, + { -85, -85, f, f, f, -71, -85, -85, -85, f, -71, f, -71, -71, f, f, f, f, f, f, f, -85, f, f, f, -85, -85, f, -85, f, -85, -85, f, f, f, -85, -85, -85, -85, -85, f, -71, -85, f, f, f, f, f, -71, f, -85 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -1 }, + { f, f, 6, f, 7, 8, f, f, f, f, f, f, 9, 10, 12, 13, 14, f, f, f, f, f, 15, f, f, f, 16, f, 17, f, 18, f, 32, f, f, f, f, f, f, f, 33, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 34, f, f, f, 35, f, f, 36, f, f, 197, f, f, f, f, f, 199, f, 39, f, 24, f, 40, 81, f, 43, 44 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, 198, f, f, f, f, f, f, f, f, f, f, f, 77 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -52 }, + { f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, -2 }, } --- Run the parser across a sequence of tokens. @@ -583,6 +594,6 @@ end return { tokens = tokens, parse = parse, - repl_exprs = 190, --[[- The repl_exprs starting state. ]] + repl_exprs = 196, --[[- The repl_exprs starting state. ]] program = 1, --[[- The program starting state. ]] } diff --git a/projects/core/src/main/resources/data/computercraft/lua/rom/programs/fun/speaker.lua b/projects/core/src/main/resources/data/computercraft/lua/rom/programs/fun/speaker.lua index de6b03e64..a26565c97 100644 --- a/projects/core/src/main/resources/data/computercraft/lua/rom/programs/fun/speaker.lua +++ b/projects/core/src/main/resources/data/computercraft/lua/rom/programs/fun/speaker.lua @@ -48,9 +48,9 @@ elseif cmd == "play" then local handle, err if http and file:match("^https?://") then print("Downloading...") - handle, err = http.get{ url = file, binary = true } + handle, err = http.get(file) else - handle, err = fs.open(file, "rb") + handle, err = fs.open(file, "r") end if not handle then diff --git a/projects/core/src/main/resources/data/computercraft/lua/rom/programs/http/wget.lua b/projects/core/src/main/resources/data/computercraft/lua/rom/programs/http/wget.lua index bd568c366..44de78b78 100644 --- a/projects/core/src/main/resources/data/computercraft/lua/rom/programs/http/wget.lua +++ b/projects/core/src/main/resources/data/computercraft/lua/rom/programs/http/wget.lua @@ -45,7 +45,7 @@ local function get(sUrl) write("Connecting to " .. sUrl .. "... ") - local response = http.get(sUrl , nil , true) + local response = http.get(sUrl) if not response then print("Failed.") return nil diff --git a/projects/core/src/test/java/dan200/computercraft/core/ComputerTestDelegate.java b/projects/core/src/test/java/dan200/computercraft/core/ComputerTestDelegate.java index da6ecab5e..7426e2235 100644 --- a/projects/core/src/test/java/dan200/computercraft/core/ComputerTestDelegate.java +++ b/projects/core/src/test/java/dan200/computercraft/core/ComputerTestDelegate.java @@ -5,6 +5,7 @@ package dan200.computercraft.core; import com.google.common.base.Splitter; +import dan200.computercraft.api.filesystem.MountConstants; import dan200.computercraft.api.filesystem.WritableMount; import dan200.computercraft.api.lua.ILuaAPI; import dan200.computercraft.api.lua.LuaException; @@ -105,7 +106,7 @@ public class ComputerTestDelegate { for (var child : children) mount.delete(child); // And add our startup file - try (var channel = mount.openForWrite("startup.lua"); + try (var channel = mount.openFile("startup.lua", MountConstants.WRITE_OPTIONS); var writer = Channels.newWriter(channel, StandardCharsets.UTF_8.newEncoder(), -1)) { writer.write("loadfile('test-rom/mcfly.lua', nil, _ENV)('test-rom/spec') cct_test.finish()"); } diff --git a/projects/core/src/test/java/dan200/computercraft/core/LuaCoverage.java b/projects/core/src/test/java/dan200/computercraft/core/LuaCoverage.java index 8da47d0a2..e7306c780 100644 --- a/projects/core/src/test/java/dan200/computercraft/core/LuaCoverage.java +++ b/projects/core/src/test/java/dan200/computercraft/core/LuaCoverage.java @@ -10,6 +10,8 @@ import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.ints.IntSet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.squiddev.cobalt.LuaError; +import org.squiddev.cobalt.LuaState; import org.squiddev.cobalt.Prototype; import org.squiddev.cobalt.compiler.CompileException; import org.squiddev.cobalt.compiler.LuaC; @@ -108,9 +110,9 @@ class LuaCoverage { Queue queue = new ArrayDeque<>(); try (InputStream stream = new FileInputStream(file)) { - var proto = LuaC.compile(stream, "@" + file.getPath()); + var proto = LuaC.compile(new LuaState(), stream, "@" + file.getPath()); queue.add(proto); - } catch (CompileException e) { + } catch (LuaError | CompileException e) { throw new IllegalStateException("Cannot compile", e); } diff --git a/projects/core/src/test/java/dan200/computercraft/core/apis/handles/BinaryReadableHandleTest.java b/projects/core/src/test/java/dan200/computercraft/core/apis/handles/BinaryReadableHandleTest.java index 2e8a2ce79..465847b20 100644 --- a/projects/core/src/test/java/dan200/computercraft/core/apis/handles/BinaryReadableHandleTest.java +++ b/projects/core/src/test/java/dan200/computercraft/core/apis/handles/BinaryReadableHandleTest.java @@ -54,7 +54,7 @@ public class BinaryReadableHandleTest { @Test public void testReadLine() throws LuaException { - var handle = BinaryReadableHandle.of(new ArrayByteChannel("hello\r\nworld\r!".getBytes(StandardCharsets.UTF_8))); + var handle = new ReadHandle(new ArrayByteChannel("hello\r\nworld\r!".getBytes(StandardCharsets.UTF_8)), false); assertArrayEquals("hello".getBytes(StandardCharsets.UTF_8), cast(byte[].class, handle.readLine(Optional.empty()))); assertArrayEquals("world\r!".getBytes(StandardCharsets.UTF_8), cast(byte[].class, handle.readLine(Optional.empty()))); assertNull(handle.readLine(Optional.empty())); @@ -62,16 +62,16 @@ public class BinaryReadableHandleTest { @Test public void testReadLineTrailing() throws LuaException { - var handle = BinaryReadableHandle.of(new ArrayByteChannel("hello\r\nworld\r!".getBytes(StandardCharsets.UTF_8))); + var handle = new ReadHandle(new ArrayByteChannel("hello\r\nworld\r!".getBytes(StandardCharsets.UTF_8)), false); assertArrayEquals("hello\r\n".getBytes(StandardCharsets.UTF_8), cast(byte[].class, handle.readLine(Optional.of(true)))); assertArrayEquals("world\r!".getBytes(StandardCharsets.UTF_8), cast(byte[].class, handle.readLine(Optional.of(true)))); assertNull(handle.readLine(Optional.of(true))); } - private static BinaryReadableHandle fromLength(int length) { + private static ReadHandle fromLength(int length) { var input = new byte[length]; Arrays.fill(input, (byte) 'A'); - return BinaryReadableHandle.of(new ArrayByteChannel(input)); + return new ReadHandle(new ArrayByteChannel(input), true); } private static T cast(Class type, @Nullable Object[] values) { diff --git a/projects/core/src/test/java/dan200/computercraft/core/apis/handles/EncodedReadableHandleTest.java b/projects/core/src/test/java/dan200/computercraft/core/apis/handles/EncodedReadableHandleTest.java deleted file mode 100644 index 46c61342b..000000000 --- a/projects/core/src/test/java/dan200/computercraft/core/apis/handles/EncodedReadableHandleTest.java +++ /dev/null @@ -1,66 +0,0 @@ -// SPDX-FileCopyrightText: 2018 The CC: Tweaked Developers -// -// SPDX-License-Identifier: MPL-2.0 - -package dan200.computercraft.core.apis.handles; - -import dan200.computercraft.api.lua.LuaException; -import org.junit.jupiter.api.Test; - -import javax.annotation.Nullable; -import java.io.BufferedReader; -import java.io.CharArrayReader; -import java.util.Arrays; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class EncodedReadableHandleTest { - @Test - public void testReadChar() throws LuaException { - var handle = fromLength(5); - assertEquals("A", cast(String.class, handle.read(Optional.empty()))); - } - - @Test - public void testReadShortComplete() throws LuaException { - var handle = fromLength(10); - assertEquals("AAAAA", cast(String.class, handle.read(Optional.of(5)))); - } - - @Test - public void testReadShortPartial() throws LuaException { - var handle = fromLength(5); - assertEquals("AAAAA", cast(String.class, handle.read(Optional.of(10)))); - } - - - @Test - public void testReadLongComplete() throws LuaException { - var handle = fromLength(10000); - assertEquals(9000, cast(String.class, handle.read(Optional.of(9000))).length()); - } - - @Test - public void testReadLongPartial() throws LuaException { - var handle = fromLength(10000); - assertEquals(10000, cast(String.class, handle.read(Optional.of(11000))).length()); - } - - @Test - public void testReadLongPartialSmaller() throws LuaException { - var handle = fromLength(1000); - assertEquals(1000, cast(String.class, handle.read(Optional.of(11000))).length()); - } - - private static EncodedReadableHandle fromLength(int length) { - var input = new char[length]; - Arrays.fill(input, 'A'); - return new EncodedReadableHandle(new BufferedReader(new CharArrayReader(input))); - } - - private static T cast(Class type, @Nullable Object[] values) { - if (values == null || values.length < 1) throw new NullPointerException(); - return type.cast(values[0]); - } -} diff --git a/projects/core/src/test/java/dan200/computercraft/core/filesystem/FileSystemTest.java b/projects/core/src/test/java/dan200/computercraft/core/filesystem/FileSystemTest.java index 30dab1990..90f67a9b5 100644 --- a/projects/core/src/test/java/dan200/computercraft/core/filesystem/FileSystemTest.java +++ b/projects/core/src/test/java/dan200/computercraft/core/filesystem/FileSystemTest.java @@ -5,11 +5,12 @@ package dan200.computercraft.core.filesystem; import com.google.common.io.Files; +import dan200.computercraft.api.filesystem.MountConstants; import dan200.computercraft.api.filesystem.WritableMount; -import dan200.computercraft.api.lua.Coerced; import dan200.computercraft.api.lua.LuaException; +import dan200.computercraft.api.lua.ObjectArguments; import dan200.computercraft.core.TestFiles; -import dan200.computercraft.core.apis.handles.EncodedWritableHandle; +import dan200.computercraft.core.apis.handles.WriteHandle; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -43,19 +44,19 @@ public class FileSystemTest { var fs = mkFs(); { - var writer = fs.openForWrite("out.txt", false, EncodedWritableHandle::openUtf8); - var handle = new EncodedWritableHandle(writer.get(), writer); - handle.write(new Coerced<>("This is a long line")); - handle.doClose(); + var writer = fs.openForWrite("out.txt", MountConstants.WRITE_OPTIONS); + var handle = WriteHandle.of(writer.get(), writer, false, true); + handle.write(new ObjectArguments("This is a long line")); + handle.close(); } assertEquals("This is a long line", Files.asCharSource(new File(ROOT, "out.txt"), StandardCharsets.UTF_8).read()); { - var writer = fs.openForWrite("out.txt", false, EncodedWritableHandle::openUtf8); - var handle = new EncodedWritableHandle(writer.get(), writer); - handle.write(new Coerced<>("Tiny line")); - handle.doClose(); + var writer = fs.openForWrite("out.txt", MountConstants.WRITE_OPTIONS); + var handle = WriteHandle.of(writer.get(), writer, false, true); + handle.write(new ObjectArguments("Tiny line")); + handle.close(); } assertEquals("Tiny line", Files.asCharSource(new File(ROOT, "out.txt"), StandardCharsets.UTF_8).read()); @@ -67,12 +68,12 @@ public class FileSystemTest { WritableMount mount = new WritableFileMount(new File(ROOT, "child"), CAPACITY); fs.mountWritable("disk", "disk", mount); - var writer = fs.openForWrite("disk/out.txt", false, EncodedWritableHandle::openUtf8); - var handle = new EncodedWritableHandle(writer.get(), writer); + var writer = fs.openForWrite("disk/out.txt", MountConstants.WRITE_OPTIONS); + var handle = WriteHandle.of(writer.get(), writer, false, true); fs.unmount("disk"); - var err = assertThrows(LuaException.class, () -> handle.write(new Coerced<>("Tiny line"))); + var err = assertThrows(LuaException.class, () -> handle.write(new ObjectArguments("Tiny line"))); assertEquals("attempt to use a closed file", err.getMessage()); } diff --git a/projects/core/src/test/java/dan200/computercraft/core/filesystem/MemoryMountTest.java b/projects/core/src/test/java/dan200/computercraft/core/filesystem/MemoryMountTest.java index 0d456a51d..968032a54 100644 --- a/projects/core/src/test/java/dan200/computercraft/core/filesystem/MemoryMountTest.java +++ b/projects/core/src/test/java/dan200/computercraft/core/filesystem/MemoryMountTest.java @@ -10,7 +10,7 @@ import dan200.computercraft.test.core.filesystem.MountContract; import dan200.computercraft.test.core.filesystem.WritableMountContract; import org.opentest4j.TestAbortedException; -import static dan200.computercraft.core.filesystem.MountHelpers.EPOCH; +import static dan200.computercraft.api.filesystem.MountConstants.EPOCH; public class MemoryMountTest implements MountContract, WritableMountContract { @Override diff --git a/projects/core/src/test/java/dan200/computercraft/core/lua/VarargArgumentsTest.java b/projects/core/src/test/java/dan200/computercraft/core/lua/VarargArgumentsTest.java index 97a6aa36c..5c4da7722 100644 --- a/projects/core/src/test/java/dan200/computercraft/core/lua/VarargArgumentsTest.java +++ b/projects/core/src/test/java/dan200/computercraft/core/lua/VarargArgumentsTest.java @@ -7,6 +7,7 @@ package dan200.computercraft.core.lua; import dan200.computercraft.api.lua.LuaException; import org.junit.jupiter.api.Test; import org.squiddev.cobalt.Constants; +import org.squiddev.cobalt.LuaError; import org.squiddev.cobalt.LuaTable; import org.squiddev.cobalt.ValueFactory; @@ -18,7 +19,11 @@ import static org.junit.jupiter.api.Assertions.assertThrows; class VarargArgumentsTest { private static LuaTable tableWithCustomType() { var metatable = new LuaTable(); - metatable.rawset(Constants.NAME, ValueFactory.valueOf("some type")); + try { + metatable.rawset(Constants.NAME, ValueFactory.valueOf("some type")); + } catch (LuaError e) { + throw new IllegalStateException("Cannot create metatable", e); + } var table = new LuaTable(); table.setMetatable(null, metatable); diff --git a/projects/core/src/test/kotlin/dan200/computercraft/core/apis/http/TestHttpApi.kt b/projects/core/src/test/kotlin/dan200/computercraft/core/apis/http/TestHttpApi.kt index 13145d6db..8078da185 100644 --- a/projects/core/src/test/kotlin/dan200/computercraft/core/apis/http/TestHttpApi.kt +++ b/projects/core/src/test/kotlin/dan200/computercraft/core/apis/http/TestHttpApi.kt @@ -6,10 +6,11 @@ package dan200.computercraft.core.apis.http import dan200.computercraft.api.lua.Coerced import dan200.computercraft.api.lua.LuaException +import dan200.computercraft.api.lua.LuaValues import dan200.computercraft.api.lua.ObjectArguments import dan200.computercraft.core.CoreConfig import dan200.computercraft.core.apis.HTTPAPI -import dan200.computercraft.core.apis.handles.EncodedReadableHandle +import dan200.computercraft.core.apis.handles.ReadHandle import dan200.computercraft.core.apis.http.HttpServer.URL import dan200.computercraft.core.apis.http.HttpServer.WS_URL import dan200.computercraft.core.apis.http.HttpServer.runServer @@ -58,8 +59,8 @@ class TestHttpApi { assertThat(result, array(equalTo("http_success"), equalTo(URL), isA(HttpResponseHandle::class.java))) val handle = result[2] as HttpResponseHandle - val reader = handle.extra.iterator().next() as EncodedReadableHandle - assertThat(reader.readAll(), array(equalTo("Hello, world!"))) + val reader = handle.extra.iterator().next() as ReadHandle + assertThat(reader.readAll(), array(equalTo("Hello, world!".toByteArray()))) } } } @@ -75,10 +76,10 @@ class TestHttpApi { assertThat(connectEvent, array(equalTo("websocket_success"), equalTo(WS_URL), isA(WebsocketHandle::class.java))) val websocket = connectEvent[2] as WebsocketHandle - websocket.send(Coerced("Hello"), Optional.of(false)) + websocket.send(Coerced(LuaValues.encode("Hello")), Optional.of(false)) val message = websocket.receive(Optional.empty()).await() - assertThat("Received a return message", message, array(equalTo("HELLO"), equalTo(false))) + assertThat("Received a return message", message, array(equalTo("HELLO".toByteArray()), equalTo(false))) websocket.close() @@ -110,7 +111,7 @@ class TestHttpApi { ) assertThrows("Throws an exception when sending") { - websocket.send(Coerced("hello"), Optional.of(false)) + websocket.send(Coerced(LuaValues.encode("hello")), Optional.of(false)) } } } diff --git a/projects/core/src/test/resources/test-rom/mcfly.lua b/projects/core/src/test/resources/test-rom/mcfly.lua index 971fddb3f..2407e6227 100644 --- a/projects/core/src/test/resources/test-rom/mcfly.lua +++ b/projects/core/src/test/resources/test-rom/mcfly.lua @@ -188,6 +188,9 @@ local function format(value) -- TODO: Look into something like mbs's pretty printer. if type(value) == "string" and value:find("\n") then return "<<<\n" .. value .. "\n>>>" + elseif type(value) == "string" then + local escaped = value:gsub("[^%g ]", function(x) return ("\\x%02x"):format(x:byte()) end) + return "\"" .. escaped .. "\"" else local ok, res = pcall(textutils.serialise, value) if ok then return res else return tostring(value) end diff --git a/projects/core/src/test/resources/test-rom/spec/apis/fs_spec.lua b/projects/core/src/test/resources/test-rom/spec/apis/fs_spec.lua index 5a61bd6c4..37d6d5b15 100644 --- a/projects/core/src/test/resources/test-rom/spec/apis/fs_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/apis/fs_spec.lua @@ -212,9 +212,7 @@ describe("The fs library", function() handle.close() end) - -- readLine(true) has odd behaviour in text mode - skip for now. - local it_binary = mode == "rb" and it or pending - it_binary("can read a line of text with the trailing separator", function() + it("can read a line of text with the trailing separator", function() local file = create_test_file "some\nfile\r\ncontents\r!\n\n" local handle = fs.open(file, mode) @@ -238,7 +236,7 @@ describe("The fs library", function() expect { fs.open("x", "r") }:same { nil, "/x: No such file" } end) - it("supports reading a single byte", function() + it("reads a single byte", function() local file = create_test_file "an example file" local handle = fs.open(file, "r") @@ -261,6 +259,28 @@ describe("The fs library", function() read_tests("rb") end) + describe("opening in r+ mode", function() + it("fails when reading non-files", function() + expect { fs.open("x", "r+") }:same { nil, "/x: No such file" } + expect { fs.open("", "r+") }:same { nil, "/: Not a file" } + end) + + read_tests("r+") + + it("can read and write to a file", function() + local file = create_test_file "an example file" + + local handle = fs.open(file, "r+") + expect(handle.read(3)):eq("an ") + + handle.write("exciting file") + expect(handle.seek("cur")):eq(16) + + handle.seek("set", 0) + expect(handle.readAll()):eq("an exciting file") + end) + end) + describe("writing", function() it("fails on directories", function() expect { fs.open("", "w") }:same { nil, "/: Cannot write to directory" } @@ -327,6 +347,29 @@ describe("The fs library", function() end) end) + describe("opening in w+ mode", function() + it("can write a file", function() + local handle = fs.open(test_file "out.txt", "w+") + handle.write("hello") + handle.seek("set", 0) + expect(handle.readAll()):eq("hello") + + handle.write(", world!") + handle.seek("set", 0) + handle.write("H") + + handle.seek("set", 0) + expect(handle.readAll()):eq("Hello, world!") + end) + + it("truncates an existing file", function() + local file = create_test_file "an example file" + + local handle = fs.open(file, "w+") + expect(handle.readAll()):eq("") + end) + end) + describe("appending", function() it("fails on directories", function() expect { fs.open("", "a") }:same { nil, "/: Cannot write to directory" } diff --git a/projects/core/src/test/resources/test-rom/spec/apis/io_spec.lua b/projects/core/src/test/resources/test-rom/spec/apis/io_spec.lua index e5d7667e7..dd850d530 100644 --- a/projects/core/src/test/resources/test-rom/spec/apis/io_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/apis/io_spec.lua @@ -28,7 +28,7 @@ describe("The io library", function() end local function setup() - write_file(file, "\"οΏ½lo\"{a}\nsecond line\nthird line \nοΏ½fourth_line\n\n\9\9 3450\n") + write_file(file, "\"\225lo\"{a}\nsecond line\nthird line \n\225fourth_line\n\n\9\9 3450\n") end describe("io.close", function() @@ -223,14 +223,14 @@ describe("The io library", function() io.input(file) expect(io.read(0)):eq("") -- not eof - expect(io.read(5, '*l')):eq('"οΏ½lo"') + expect(io.read(5, '*l')):eq('"\225lo"') expect(io.read(0)):eq("") expect(io.read()):eq("second line") local x = io.input():seek() expect(io.read()):eq("third line ") assert(io.input():seek("set", x)) expect(io.read('*l')):eq("third line ") - expect(io.read(1)):eq("οΏ½") + expect(io.read(1)):eq("\225") expect(io.read(#"fourth_line")):eq("fourth_line") assert(io.input():seek("cur", -#"fourth_line")) expect(io.read()):eq("fourth_line") @@ -304,8 +304,8 @@ describe("The io library", function() expect(io.output():seek("set")):equal(0) - assert(io.write('"οΏ½lo"', "{a}\n", "second line\n", "third line \n")) - assert(io.write('οΏ½fourth_line')) + assert(io.write('"\225lo"', "{a}\n", "second line\n", "third line \n")) + assert(io.write('\225fourth_line')) io.output(io.stdout) expect(io.output()):equals(io.stdout) diff --git a/projects/core/src/test/resources/test-rom/spec/base_spec.lua b/projects/core/src/test/resources/test-rom/spec/base_spec.lua index fe37fb653..5ea044f37 100644 --- a/projects/core/src/test/resources/test-rom/spec/base_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/base_spec.lua @@ -79,20 +79,6 @@ describe("The Lua base library", function() end) describe("load", function() - it("validates arguments", function() - load("") - load(function() - end) - load("", "") - load("", "", "") - load("", "", "", _ENV) - - expect.error(load, nil):eq("bad argument #1 (function or string expected, got nil)") - expect.error(load, "", false):eq("bad argument #2 (string expected, got boolean)") - expect.error(load, "", "", false):eq("bad argument #3 (string expected, got boolean)") - expect.error(load, "", "", "", false):eq("bad argument #4 (table expected, got boolean)") - end) - local function generator(parts) return coroutine.wrap(function() for i = 1, #parts do diff --git a/projects/core/src/test/resources/test-rom/spec/modules/cc/internal/syntax/parser_exhaustive_spec.md b/projects/core/src/test/resources/test-rom/spec/modules/cc/internal/syntax/parser_exhaustive_spec.md index 153b4e15a..83e540c60 100644 --- a/projects/core/src/test/resources/test-rom/spec/modules/cc/internal/syntax/parser_exhaustive_spec.md +++ b/projects/core/src/test/resources/test-rom/spec/modules/cc/internal/syntax/parser_exhaustive_spec.md @@ -8,32 +8,6 @@ An exhaustive list of all error states in the parser, and the error messages we generate for each one. This is _not_ a complete collection of all possible errors, but is a useful guide for where we might be providing terrible messages. -```lua -break while --- Line 1: unexpected symbol near (program) -``` - -```txt -Unexpected while. Expected a statement. - | - 1 | break while - | ^^^^^ -``` - - -```lua -do end true --- Line 1: unexpected symbol near 'true' (program) -``` - -```txt -Unexpected true. Expected a statement. - | - 1 | do end true - | ^^^^ -``` - - ```lua do until -- Line 1: 'end' expected near 'until' (program) @@ -63,6 +37,35 @@ Unexpected true. ``` +```lua +:: xyz while +-- Line 1: '::' expected near 'while' (program) +``` + +```txt +Unexpected while. + | + 1 | :: xyz while + | ^^ Label was started here. + | + 1 | :: xyz while + | ^^^^^ Tip: Try adding :: here. +``` + + +```lua +:: while +-- Line 1: expected near 'while' (program) +``` + +```txt +Unexpected while. + | + 1 | :: while + | ^^^^^ +``` + + ```lua for xyz , xyz while -- Line 1: 'in' expected near 'while' (program) @@ -849,6 +852,20 @@ Unexpected while. ``` +```lua +xyz while +-- Line 1: syntax error near 'while' (program) +``` + +```txt +Unexpected symbol after name. + | + 1 | xyz while + | ^ +Did you mean to assign this or call it as a function? +``` + + ```lua if xyz then else until -- Line 1: 'end' expected near 'until' (program) @@ -1059,22 +1076,6 @@ Unexpected while. Expected an expression. ``` -```lua {repl_exprs} -{ xyz , while --- Line 1: unexpected symbol near 'while' (repl_exprs) -``` - -```txt -Unexpected while. Are you missing a closing bracket? - | - 1 | { xyz , while - | ^ Brackets were opened here. - | - 1 | { xyz , while - | ^^^^^ Unexpected while here. -``` - - ```lua {repl_exprs} { xyz = xyz while -- Line 1: '}' expected near 'while' (repl_exprs) @@ -1104,6 +1105,22 @@ Unexpected while. Expected an expression. ``` +```lua {repl_exprs} +{ xyz ; while +-- Line 1: unexpected symbol near 'while' (repl_exprs) +``` + +```txt +Unexpected while. Are you missing a closing bracket? + | + 1 | { xyz ; while + | ^ Brackets were opened here. + | + 1 | { xyz ; while + | ^^^^^ Unexpected while here. +``` + + ```lua {repl_exprs} { xyz while -- Line 1: '}' expected near 'while' (repl_exprs) diff --git a/projects/core/src/test/resources/test-rom/spec/modules/cc/internal/syntax/parser_spec.md b/projects/core/src/test/resources/test-rom/spec/modules/cc/internal/syntax/parser_spec.md index 979c8bd1e..b5b94eae4 100644 --- a/projects/core/src/test/resources/test-rom/spec/modules/cc/internal/syntax/parser_spec.md +++ b/projects/core/src/test/resources/test-rom/spec/modules/cc/internal/syntax/parser_spec.md @@ -417,6 +417,49 @@ Unexpected end. Your program contains more ends than needed. Check each block (if, for, function, ...) only has one end. ``` +## `goto` and labels +We `goto` the same as normal identifiers. + +```lua +goto 2 +``` + +```txt +Unexpected symbol after name. + | + 1 | goto 2 + | ^ +Did you mean to assign this or call it as a function? +``` + +Labels have a basic closing check: +```lua +::foo +``` + +```txt +Unexpected end of file. + | + 1 | ::foo + | ^^ Label was started here. + | + 1 | ::foo + | ^ Tip: Try adding :: here. +``` + +But we do nothing fancy for just a `::` + +```lua +:: +``` + +```txt +Unexpected end of file. + | + 1 | :: + | ^ +``` + # Function calls ## Additional commas diff --git a/projects/core/src/test/resources/test-rom/spec/programs/import_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/import_spec.lua index 6420a9e14..4d2215c87 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/import_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/import_spec.lua @@ -31,7 +31,7 @@ describe("The import program", function() for _, event in pairs(queue) do assert(coroutine.resume(co, table.unpack(event))) end end) - local handle = fs.open("transfer.txt", "rb") + local handle = fs.open("transfer.txt", "r") local contents = handle.readAll() handle.close() diff --git a/projects/core/src/test/resources/test-rom/spec/programs/shell_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/shell_spec.lua index 92e19172a..bdd4ed99c 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/shell_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/shell_spec.lua @@ -214,7 +214,7 @@ describe("The shell", function() local lines = {} for i = 1, 5 do lines[i] = win.getLine(i):gsub(" +$", "") end expect(lines):same { - "CraftOS 1.8", + "CraftOS 1.9", "> xyz", "Transferring transfer.txt", "> xyz", diff --git a/projects/core/src/testFixtures/java/dan200/computercraft/test/core/filesystem/MountContract.java b/projects/core/src/testFixtures/java/dan200/computercraft/test/core/filesystem/MountContract.java index 3b6fa3122..459423241 100644 --- a/projects/core/src/testFixtures/java/dan200/computercraft/test/core/filesystem/MountContract.java +++ b/projects/core/src/testFixtures/java/dan200/computercraft/test/core/filesystem/MountContract.java @@ -21,7 +21,7 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; -import static dan200.computercraft.core.filesystem.MountHelpers.*; +import static dan200.computercraft.api.filesystem.MountConstants.*; import static org.junit.jupiter.api.Assertions.*; /** diff --git a/projects/core/src/testFixtures/java/dan200/computercraft/test/core/filesystem/Mounts.java b/projects/core/src/testFixtures/java/dan200/computercraft/test/core/filesystem/Mounts.java index 5874453de..d167e97b8 100644 --- a/projects/core/src/testFixtures/java/dan200/computercraft/test/core/filesystem/Mounts.java +++ b/projects/core/src/testFixtures/java/dan200/computercraft/test/core/filesystem/Mounts.java @@ -4,6 +4,7 @@ package dan200.computercraft.test.core.filesystem; +import dan200.computercraft.api.filesystem.MountConstants; import dan200.computercraft.api.filesystem.WritableMount; import java.io.IOException; @@ -26,7 +27,7 @@ public final class Mounts { * @throws IOException If writing fails. */ public static void writeFile(WritableMount mount, String path, String contents) throws IOException { - try (var handle = Channels.newWriter(mount.openForWrite(path), StandardCharsets.UTF_8)) { + try (var handle = Channels.newWriter(mount.openFile(path, MountConstants.WRITE_OPTIONS), StandardCharsets.UTF_8)) { handle.write(contents); } } diff --git a/projects/core/src/testFixtures/java/dan200/computercraft/test/core/filesystem/WritableMountContract.java b/projects/core/src/testFixtures/java/dan200/computercraft/test/core/filesystem/WritableMountContract.java index 5404b2388..9069d331e 100644 --- a/projects/core/src/testFixtures/java/dan200/computercraft/test/core/filesystem/WritableMountContract.java +++ b/projects/core/src/testFixtures/java/dan200/computercraft/test/core/filesystem/WritableMountContract.java @@ -4,6 +4,7 @@ package dan200.computercraft.test.core.filesystem; +import dan200.computercraft.api.filesystem.MountConstants; import dan200.computercraft.api.filesystem.WritableMount; import dan200.computercraft.api.lua.LuaValues; import dan200.computercraft.test.core.ReplaceUnderscoresDisplayNameGenerator; @@ -16,7 +17,7 @@ import org.opentest4j.TestAbortedException; import java.io.IOException; import java.util.stream.Stream; -import static dan200.computercraft.core.filesystem.MountHelpers.MINIMUM_FILE_SIZE; +import static dan200.computercraft.api.filesystem.MountConstants.MINIMUM_FILE_SIZE; import static org.junit.jupiter.api.Assertions.*; /** @@ -118,12 +119,12 @@ public interface WritableMountContract { var access = createExisting(CAPACITY); var mount = access.mount(); - var handle = mount.openForWrite("file.txt"); + var handle = mount.openFile("file.txt", MountConstants.WRITE_OPTIONS); handle.write(LuaValues.encode(LONG_CONTENTS)); assertEquals(CAPACITY - LONG_CONTENTS.length(), mount.getRemainingSpace()); assertEquals(access.computeRemainingSpace(), access.mount().getRemainingSpace(), "Free space is inconsistent"); - var handle2 = mount.openForWrite("file.txt"); + var handle2 = mount.openFile("file.txt", MountConstants.WRITE_OPTIONS); handle.write(LuaValues.encode("test")); assertEquals(CAPACITY - LONG_CONTENTS.length() - 4, mount.getRemainingSpace()); @@ -144,7 +145,7 @@ public interface WritableMountContract { Mounts.writeFile(mount, "a.txt", "example"); - try (var handle = mount.openForAppend("a.txt")) { + try (var handle = mount.openFile("a.txt", MountConstants.APPEND_OPTIONS)) { assertEquals(7, handle.position()); handle.write(LuaValues.encode(" text")); assertEquals(12, handle.position()); diff --git a/projects/standalone/src/main/java/cc/tweaked/standalone/InputState.java b/projects/standalone/src/main/java/cc/tweaked/standalone/InputState.java index 9246fa475..70a0ea6c1 100644 --- a/projects/standalone/src/main/java/cc/tweaked/standalone/InputState.java +++ b/projects/standalone/src/main/java/cc/tweaked/standalone/InputState.java @@ -8,6 +8,7 @@ import dan200.computercraft.core.apis.handles.ArrayByteChannel; import dan200.computercraft.core.apis.transfer.TransferredFile; import dan200.computercraft.core.apis.transfer.TransferredFiles; import dan200.computercraft.core.computer.Computer; +import dan200.computercraft.core.util.StringUtil; import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFWDropCallback; import org.lwjgl.glfw.GLFWKeyCallbackI; @@ -54,16 +55,24 @@ public class InputState { } } - public void onKeyEvent(int key, int action, int modifiers) { + public void onKeyEvent(long window, int key, int action, int modifiers) { switch (action) { - case GLFW.GLFW_PRESS, GLFW.GLFW_REPEAT -> keyPressed(key, modifiers); + case GLFW.GLFW_PRESS, GLFW.GLFW_REPEAT -> keyPressed(window, key, modifiers); case GLFW.GLFW_RELEASE -> keyReleased(key); } } - private void keyPressed(int key, int modifiers) { + private void keyPressed(long window, int key, int modifiers) { if (key == GLFW.GLFW_KEY_ESCAPE) return; + if (key == GLFW.GLFW_KEY_V && modifiers == GLFW.GLFW_MOD_CONTROL) { + var string = GLFW.glfwGetClipboardString(window); + if (string != null) { + var clipboard = StringUtil.normaliseClipboardString(string); + if (!clipboard.isEmpty()) computer.queueEvent("paste", new Object[]{ clipboard }); + } + return; + } if ((modifiers & GLFW.GLFW_MOD_CONTROL) != 0) { switch (key) { diff --git a/projects/standalone/src/main/java/cc/tweaked/standalone/Main.java b/projects/standalone/src/main/java/cc/tweaked/standalone/Main.java index a4b0ac248..b866a9018 100644 --- a/projects/standalone/src/main/java/cc/tweaked/standalone/Main.java +++ b/projects/standalone/src/main/java/cc/tweaked/standalone/Main.java @@ -204,7 +204,7 @@ public class Main { } // Add all our callbacks - glfwSetKeyCallback(window, (w, key, scancode, action, mods) -> inputState.onKeyEvent(key, action, mods)); + glfwSetKeyCallback(window, (w, key, scancode, action, mods) -> inputState.onKeyEvent(w, key, action, mods)); glfwSetCharModsCallback(window, (w, codepoint, mods) -> inputState.onCharEvent(codepoint)); glfwSetDropCallback(window, (w, count, files) -> inputState.onFileDrop(count, files)); glfwSetMouseButtonCallback(window, (w, button, action, mods) -> inputState.onMouseClick(button, action)); diff --git a/projects/web/src/main/java/cc/tweaked/web/js/JavascriptConv.java b/projects/web/src/main/java/cc/tweaked/web/js/JavascriptConv.java index b1123bd6b..18f2732e0 100644 --- a/projects/web/src/main/java/cc/tweaked/web/js/JavascriptConv.java +++ b/projects/web/src/main/java/cc/tweaked/web/js/JavascriptConv.java @@ -16,6 +16,7 @@ import org.teavm.jso.typedarrays.ArrayBuffer; import org.teavm.jso.typedarrays.Int8Array; import javax.annotation.Nullable; +import java.nio.ByteBuffer; /** * Utility methods for converting between Java and Javascript representations. @@ -79,4 +80,10 @@ public class JavascriptConv { public static byte[] asByteArray(ArrayBuffer view) { return asByteArray(Int8Array.create(view)); } + + public static Int8Array toArray(ByteBuffer buffer) { + var array = Int8Array.create(buffer.remaining()); + for (var i = 0; i < array.getLength(); i++) array.set(i, buffer.get(i)); + return array; + } } diff --git a/projects/web/src/main/java/dan200/computercraft/core/apis/http/request/THttpRequest.java b/projects/web/src/main/java/dan200/computercraft/core/apis/http/request/THttpRequest.java index 1a87e517f..d8318ae09 100644 --- a/projects/web/src/main/java/dan200/computercraft/core/apis/http/request/THttpRequest.java +++ b/projects/web/src/main/java/dan200/computercraft/core/apis/http/request/THttpRequest.java @@ -9,9 +9,7 @@ import cc.tweaked.web.js.JavascriptConv; import dan200.computercraft.core.Logging; import dan200.computercraft.core.apis.IAPIEnvironment; import dan200.computercraft.core.apis.handles.ArrayByteChannel; -import dan200.computercraft.core.apis.handles.BinaryReadableHandle; -import dan200.computercraft.core.apis.handles.EncodedReadableHandle; -import dan200.computercraft.core.apis.handles.HandleGeneric; +import dan200.computercraft.core.apis.handles.ReadHandle; import dan200.computercraft.core.apis.http.HTTPRequestException; import dan200.computercraft.core.apis.http.Resource; import dan200.computercraft.core.apis.http.ResourceGroup; @@ -24,10 +22,9 @@ import org.teavm.jso.ajax.XMLHttpRequest; import org.teavm.jso.typedarrays.ArrayBuffer; import javax.annotation.Nullable; -import java.io.BufferedReader; -import java.io.StringReader; import java.net.URI; import java.net.URISyntaxException; +import java.nio.ByteBuffer; import java.nio.channels.SeekableByteChannel; import java.util.HashMap; import java.util.Locale; @@ -44,24 +41,24 @@ public class THttpRequest extends Resource { private final IAPIEnvironment environment; private final String address; - private final @Nullable String postBuffer; + private final @Nullable ByteBuffer postBuffer; private final HttpHeaders headers; private final boolean binary; private final boolean followRedirects; public THttpRequest( - ResourceGroup limiter, IAPIEnvironment environment, String address, @Nullable String postText, + ResourceGroup limiter, IAPIEnvironment environment, String address, @Nullable ByteBuffer postBody, HttpHeaders headers, boolean binary, boolean followRedirects, int timeout ) { super(limiter); this.environment = environment; this.address = address; - postBuffer = postText; + postBuffer = postBody; this.headers = headers; this.binary = binary; this.followRedirects = followRedirects; - if (postText != null) { + if (postBody != null) { if (!headers.contains(HttpHeaderNames.CONTENT_TYPE)) { headers.set(HttpHeaderNames.CONTENT_TYPE, "application/x-www-form-urlencoded; charset=utf-8"); } @@ -97,7 +94,7 @@ public class THttpRequest extends Resource { try { var request = XMLHttpRequest.create(); request.setOnReadyStateChange(() -> onResponseStateChange(request)); - request.setResponseType(binary ? "arraybuffer" : "text"); + request.setResponseType("arraybuffer"); var address = uri.toASCIIString(); request.open(method.toString(), Main.CORS_PROXY.isEmpty() ? address : Main.CORS_PROXY.replace("{}", address)); for (var iterator = headers.iteratorAsString(); iterator.hasNext(); ) { @@ -105,7 +102,7 @@ public class THttpRequest extends Resource { request.setRequestHeader(header.getKey(), header.getValue()); } request.setRequestHeader("X-CC-Redirect", followRedirects ? "true" : "false"); - request.send(postBuffer); + request.send(postBuffer == null ? null : JavascriptConv.toArray(postBuffer)); checkClosed(); } catch (Exception e) { failure("Could not connect"); @@ -120,14 +117,9 @@ public class THttpRequest extends Resource { return; } - HandleGeneric reader; - if (binary) { - ArrayBuffer buffer = request.getResponse().cast(); - SeekableByteChannel contents = new ArrayByteChannel(JavascriptConv.asByteArray(buffer)); - reader = BinaryReadableHandle.of(contents); - } else { - reader = new EncodedReadableHandle(new BufferedReader(new StringReader(request.getResponseText()))); - } + ArrayBuffer buffer = request.getResponse().cast(); + SeekableByteChannel contents = new ArrayByteChannel(JavascriptConv.asByteArray(buffer)); + var reader = new ReadHandle(contents, binary); Map responseHeaders = new HashMap<>(); for (var header : request.getAllResponseHeaders().split("\r\n")) { diff --git a/projects/web/src/main/java/dan200/computercraft/core/apis/http/websocket/TWebsocket.java b/projects/web/src/main/java/dan200/computercraft/core/apis/http/websocket/TWebsocket.java index 6e8c42123..e90e5a4f2 100644 --- a/projects/web/src/main/java/dan200/computercraft/core/apis/http/websocket/TWebsocket.java +++ b/projects/web/src/main/java/dan200/computercraft/core/apis/http/websocket/TWebsocket.java @@ -70,10 +70,7 @@ public class TWebsocket extends Resource implements WebsocketClient @Override public void sendBinary(ByteBuffer message) { if (websocket == null) return; - - var array = Int8Array.create(message.remaining()); - for (var i = 0; i < array.getLength(); i++) array.set(i, message.get(i)); - websocket.send(array); + websocket.send(JavascriptConv.toArray(message)); } @Override