From 944d5d74e13fb4100185d51324ba45bdbe878477 Mon Sep 17 00:00:00 2001 From: Seggan Date: Mon, 20 Nov 2023 19:29:53 -0500 Subject: [PATCH] Camelcase --- docs/index.papyri | 32 ------------ docs/lang/core/coroutine.papyri | 6 +-- docs/lang/core/index.papyri | 6 +-- docs/lang/core/io.papyri | 14 +++--- docs/lang/core/list.papyri | 2 +- docs/lang/core/number.papyri | 4 +- docs/lang/core/string.papyri | 8 +-- docs/lang/index.papyri | 22 ++++---- docs/lang/std/os.papyri | 8 +-- docs/lang/std/path.papyri | 30 +++++------ .../seggan/metis/compilation/Compiler.kt | 2 +- .../io/github/seggan/metis/runtime/State.kt | 4 +- .../metis/runtime/intrinsics/Coroutine.kt | 4 +- .../metis/runtime/intrinsics/Intrinsics.kt | 2 +- .../metis/runtime/intrinsics/NativeLibrary.kt | 30 +++++------ .../metis/runtime/intrinsics/NativeObjects.kt | 2 +- .../metis/runtime/intrinsics/ValueInit.kt | 8 +-- metis-lang/src/main/resources/core.metis | 4 +- .../src/main/resources/core/collection.metis | 4 +- .../src/main/resources/core/coroutine.metis | 2 +- metis-lang/src/main/resources/core/io.metis | 18 +++---- metis-lang/src/main/resources/core/list.metis | 4 +- .../src/main/resources/core/range.metis | 2 +- .../src/main/resources/core/string.metis | 10 ++-- .../src/main/resources/core/table.metis | 2 +- metis-lang/src/main/resources/std/json.metis | 50 +++++++++---------- metis-lang/src/main/resources/std/path.metis | 28 +++++------ 27 files changed, 138 insertions(+), 170 deletions(-) diff --git a/docs/index.papyri b/docs/index.papyri index e854039..b0a888c 100644 --- a/docs/index.papyri +++ b/docs/index.papyri @@ -42,38 +42,6 @@ This will create a JAR file in `app/build/libs` that can be run with `java -jar @h2 Changelog -@h3 { v1.2.2 } -[ - { Nothing new, just configured Gradle to publish } -] - -@h3 { v1.2.1 } -[ - { Fixed `in` giving wrong result } -] - -@h3 { v1.2.0 } -[ - { Added a ton of functions to `path` }, - { Added some functions to tables and lists }, - { Fixed `import` not caching to `package.loaded` }, - { Finally documented everything } -] - -@h3 { v1.1.0 } -[ - { `.` now behaves like `:` when used with a function that has a `self` argument }, - { Removed `:` operator }, - { Added the `math` module }, - { Moved the `path` module from the core library to the standard library }, - { Added `import` } -] - -@h3 { v1.0.0 } -[ - { Initial release } -] - @h2 Credits Metis is made by @href(`https://github.com/Seggan`) Seggan. diff --git a/docs/lang/core/coroutine.papyri b/docs/lang/core/coroutine.papyri index a27fb01..2c042f1 100644 --- a/docs/lang/core/coroutine.papyri +++ b/docs/lang/core/coroutine.papyri @@ -16,16 +16,16 @@ If `args` is not given, the function will be called without arguments. @h2 { Member functions } -@h3 { last_result(self): string } +@h3 { lastResult(self): string } Returns the last thing returned by `step`. -@h3 { last_yielded(self): any } +@h3 { lastYielded(self): any } Returns the last thing yielded by the coroutine, if any. @h3 { run(self): null } Performs `step` until the coroutine returns something other than `continue`. -@h3 { run_at_most(self, n: number): null } +@h3 { runAtMost(self, n: number): null } Performs `step` at most `n` times or until the coroutine returns something other than `continue`. @h3 { step(self): string } diff --git a/docs/lang/core/index.papyri b/docs/lang/core/index.papyri index 0c68398..5d006ca 100644 --- a/docs/lang/core/index.papyri +++ b/docs/lang/core/index.papyri @@ -18,12 +18,12 @@ If the prompt is `null`, then no prompt is printed. Returns the line of text ent @h3 { iter(value: any): any } Returns an iterator for the given value. Requires the `__iter__` metamethod to be defined on the value. -The iterator must have the `has_next(self): boolean` and the `next(self): any` methods defined. +The iterator must have the `hasNext(self): boolean` and the `next(self): any` methods defined. @h3 { len(value: any): number } Returns the length of the value. Requires the `__len__` metamethod to be defined on the value. -@h3 { load_chunk(chunk: string): callable } +@h3 { loadChunk(chunk: string): callable } Loads the given Metis code as a callable function. Returns the function. @h3 { print(value: any): null } @@ -49,7 +49,7 @@ Returns the type of the value as a string. Can be one of the following: `unknown` ] -@h3 { with_metatable(value: any, metatable: table): any } +@h3 { withMetatable(value: any, metatable: table): any } Sets the metatable of the value to the given table, and returns the value. @h3 { yield(value: any): null } diff --git a/docs/lang/core/io.papyri b/docs/lang/core/io.papyri index bcbe418..d0db182 100644 --- a/docs/lang/core/io.papyri +++ b/docs/lang/core/io.papyri @@ -17,7 +17,7 @@ Returns a reference to the standard input stream. @h3 { stdout(): native } Returns a reference to the standard output stream. -@h1 { Submodule `in_stream` } +@h1 { Submodule `inStream` } This submodule provides a set of functions for manipulating input streams. It is also the metatable for input streams. @@ -32,20 +32,20 @@ Reads a sequence of bytes from the stream into the buffer. Returns the number of If buffer is not provided or is `null`, the function reads and returns a single byte. Returns `null` if the end of the stream is reached. -@h3 { read_all(self): bytes } +@h3 { readAll(self): bytes } Reads all bytes from the stream and returns them. -@h3 { read_line(self): string } +@h3 { readLine(self): string } Reads a line from the stream and returns it. -@h3 { read_text(self): string } +@h3 { readText(self): string } Reads all text from the stream and returns it. @h3 { use(self, f: callable\[native -> any\]): any } Calls the function `f` with the stream as its argument and returns the result. The stream is closed after the function returns, even if it throws an error. -@h1 { Submodule `out_stream` } +@h1 { Submodule `outStream` } This submodule provides a set of functions for manipulating output streams. It is also the metatable for output streams. @@ -66,10 +66,10 @@ the function writes at most `len` bytes starting from the byte at offset `off`. not provided, the function starts writing from the first byte in the buffer. If `len` is not provided, the function writes to the end of the buffer. -@h3 { write_line(self, line: string): null } +@h3 { writeLine(self, line: string): null } Writes a line to the stream. -@h3 { write_text(self, text: string): null } +@h3 { writeText(self, text: string): null } Writes text to the stream. @h3 { use(self, f: callable\[native -> any\]): any } diff --git a/docs/lang/core/list.papyri b/docs/lang/core/list.papyri index 5cf0777..0bd0398 100644 --- a/docs/lang/core/list.papyri +++ b/docs/lang/core/list.papyri @@ -28,7 +28,7 @@ separator. @h3 { remove(self, value: any): null } Removes the first occurrence of the given value from the list. -@h3 { remove_at(self, index: number): any } +@h3 { removeAt(self, index: number): any } Removes the element at the given index from the list and returns it. @h3 { reverse(self): list } diff --git a/docs/lang/core/number.papyri b/docs/lang/core/number.papyri index 6601c1e..3200453 100644 --- a/docs/lang/core/number.papyri +++ b/docs/lang/core/number.papyri @@ -12,7 +12,7 @@ It is the metatable for all numbers. @h3 { inf: number } The infinity value as defined by IEEE 754. -@h3 { neg_inf: number } +@h3 { negInf: number } The negative infinity value as defined by IEEE 754. @h3 { nan: number } @@ -28,7 +28,7 @@ Parse a string into a number with a given radix. The radix must be between 2 and @h3 { char(self): string } Convert a number to its character representation. -@h3 { string_with_radix(self, radix: number): string } +@h3 { stringWithRadix(self, radix: number): string } Convert a number to a string with a given radix. The radix must be between 2 and 36. @h2 Metamethods diff --git a/docs/lang/core/string.papyri b/docs/lang/core/string.papyri index 8d04650..685c468 100644 --- a/docs/lang/core/string.papyri +++ b/docs/lang/core/string.papyri @@ -16,13 +16,13 @@ is implementation-defined. @h2 { Member functions } -@h3 { char_code(self): number } +@h3 { charCode(self): number } Get the character code of the first character in the string. @h3 { encode(self, encoding: string = "UTF-8"): bytes } Encode the string using the specified encoding. The default encoding is UTF-8. -@h3 { equal_ignore_case(self, other: string): boolean } +@h3 { equalIgnoreCase(self, other: string): boolean } Compare two strings for equality, ignoring case. @h3 { remove(self, start: number, end: number \| null): string } @@ -83,10 +83,10 @@ Clear the builder. @h3 { delete(self, start: number, end: number): self } Delete a range of characters from the builder from `start` to `end` (exclusive). -@h3 { delete_at(self, index: number): self } +@h3 { deleteAt(self, index: number): self } Delete a character from the builder at the specified index. -@h3 { delete_last(self, count: number): self } +@h3 { deleteLast(self, count: number): self } Delete the last `count` characters from the builder. @h2 Metamethods diff --git a/docs/lang/index.papyri b/docs/lang/index.papyri index f3547e4..93935c8 100644 --- a/docs/lang/index.papyri +++ b/docs/lang/index.papyri @@ -48,11 +48,11 @@ Functions can also have @i upvalues, which are variables that are from an enclos @metis ``` let x = 5 -fn print_x() +fn printX() print(x) end -print_x() // 5 +printX() // 5 ``` Upvalues can also be mutated: @@ -60,11 +60,11 @@ Upvalues can also be mutated: @metis ``` let x = 5 -fn add_to_x(y) +fn addToX(y) x = x + y end -add_to_x(5) +addToX(5) print(x) // 10 ``` @@ -101,11 +101,11 @@ a self function from a table, the table is passed as the first argument: @metis ``` let x = { "a" = 1, "b" = 2 } -fn x.get_a(self) +fn x.getA(self) return self.a end -print(x.get_a()) // 1 +print(x.getA()) // 1 ``` @h2 { Anonymous Functions } @@ -415,9 +415,9 @@ end ``` All iterables implement the `__iter__` metamethod, which returns an iterator. The iterator implements -the `next` and `has_next` metamethods (note the absence of underscores). `next` returns the next value, -and `has_next` returns `true` if there are more values, and `false` otherwise. The `for` loop calls -`next` (and assigns it to the loop variable) until `has_next` returns `false`. +the `next` and `hasNext` metamethods (note the absence of underscores). `next` returns the next value, +and `hasNext` returns `true` if there are more values, and `false` otherwise. The `for` loop calls +`next` (and assigns it to the loop variable) until `hasNext` returns `false`. @h2 { Try Statements } @@ -473,7 +473,7 @@ Metis has a module system similar to Python. Modules have the same name as the f All globals in the module are part of its @i exports. Modules are loaded with the `import` statement: -@metis `import module_name` +@metis `import moduleName` This will load the module as a table and assign it to a variable with the same name as the module. The module table will have the same members as the modules exports, or globals in the module. For example, if @@ -481,7 +481,7 @@ the module is called `foo`, it will be assigned to a variable called `foo`. Another thing you can do is @i {global imports} with `global import`: -@metis `global import module_name` +@metis `global import moduleName` This will load the module and assign it to a global variable with the same name as the module. This can be used for implementing transient modules as such: diff --git a/docs/lang/std/os.papyri b/docs/lang/std/os.papyri index 1b0ca05..e7958d2 100644 --- a/docs/lang/std/os.papyri +++ b/docs/lang/std/os.papyri @@ -8,16 +8,16 @@ The `os` module provides functions for interacting with the operating system. @h2 { Free functions } -@h3 { get_cwd(): string } +@h3 { getCwd(): string } Returns the current working directory as a string. -@h3 { get_env(name: string): string \| null } +@h3 { getEnv(name: string): string \| null } Gets the value of an environment variable by providing its name as a string. Returns the value as a string if the variable is found, or `null` if the variable is not set. -@h3 { set_cwd(path: string): void } +@h3 { setCwd(path: string): void } Sets the current working directory to the specified absolute path. Raises `IOError` if the provided path is not absolute. -@h3 { set_env(name: string, value: string): void } +@h3 { setEnv(name: string, value: string): void } Sets an environment variable with the provided name and value as strings. diff --git a/docs/lang/std/path.papyri b/docs/lang/std/path.papyri index 08e4f2d..0742a49 100644 --- a/docs/lang/std/path.papyri +++ b/docs/lang/std/path.papyri @@ -17,41 +17,41 @@ The path separator for the current platform. This is either `/` or `\`. @h3 { absolute(path: string): string } Returns the absolute path of the given path. -@h3 { file_name(path: string): string } +@h3 { fileName(path: string): string } Returns the filename of the given path. @h3 { copy(from: string, to: string): null } Copies the file at the given path `from` to the given path `to`. -@h3 { create_dir(path: string): string } +@h3 { createDir(path: string): string } Creates a directory at the given path and returns the path of the created directory. -@h3 { create_dirs(path: string): string } +@h3 { createDirs(path: string): string } Creates a directory at the given path and all parent directories that do not exist yet. Returns the path of the created directory. @h3 { delete(path: string): null } Deletes the file or directory at the given path. Directories must be empty. -@h3 { delete_recursive(path: string): null } +@h3 { deleteRecursive(path: string): null } Deletes the file or directory at the given path recursively. @h3 { exists(path: string): boolean } Returns a boolean value indicating whether the file or directory at the given path exists. -@h3 { is_absolute(path: string): boolean } +@h3 { isAbsolute(path: string): boolean } Returns a boolean value indicating whether the given path is absolute. -@h3 { is_dir(path: string): boolean } +@h3 { isDir(path: string): boolean } Returns a boolean value indicating whether the given path points to a directory. -@h3 { is_file(path: string): boolean } +@h3 { isFile(path: string): boolean } Returns a boolean value indicating whether the given path points to a file. -@h3 { is_hidden(path: string): boolean } +@h3 { isHidden(path: string): boolean } Returns a boolean value indicating whether the given path is hidden. -@h3 { is_symlink(path: string): boolean } +@h3 { isSymlink(path: string): boolean } Returns a boolean value indicating whether the given path is a symbolic link. @h3 { list(path: string): list\[string\] } @@ -63,19 +63,19 @@ Moves the file at the given path `from` to the given path `to`. @h3 { normalize(path: string): string } Normalizes the given path and returns the normalized path as a string. -@h3 { open_read(path: string): native } +@h3 { openRead(path: string): native } Opens the file at the given path for reading and returns an input stream. -@h3 { open_write(path: string): native } +@h3 { openWrite(path: string): native } Opens the file at the given path for writing and returns an output stream. @h3 { parent(path: string): string } Returns the parent directory of the given path. -@h3 { read_all(path: string): bytes } +@h3 { readAll(path: string): bytes } Reads the entire file at the given path and returns the contents as a byte array. -@h3 { read_text(path: string): string } +@h3 { readText(path: string): string } Reads the entire file at the given path and returns the contents as a string. @h3 { resolve(base: string, other: string): string } @@ -84,8 +84,8 @@ Resolves the given path `other` against the base path `base` and returns the res @h3 { root(path: string): string } Returns the root of the given path. -@h3 { write_all(path: string, data: bytes) } +@h3 { writeAll(path: string, data: bytes) } Writes the given byte array to the file at the given path. -@h3 { write_text(path: string, data: string) } +@h3 { writeText(path: string, data: string) } Writes the given string to the file at the given path. diff --git a/metis-lang/src/main/kotlin/io/github/seggan/metis/compilation/Compiler.kt b/metis-lang/src/main/kotlin/io/github/seggan/metis/compilation/Compiler.kt index 3d86c2e..620abaa 100644 --- a/metis-lang/src/main/kotlin/io/github/seggan/metis/compilation/Compiler.kt +++ b/metis-lang/src/main/kotlin/io/github/seggan/metis/compilation/Compiler.kt @@ -296,7 +296,7 @@ class Compiler private constructor( +start +Insn.CopyUnder(0) +Insn.CopyUnder(0) - +Insn.Push("has_next") + +Insn.Push("hasNext") +Insn.Index +Insn.Call(1, true) +Insn.RawJumpIf(end, false) diff --git a/metis-lang/src/main/kotlin/io/github/seggan/metis/runtime/State.kt b/metis-lang/src/main/kotlin/io/github/seggan/metis/runtime/State.kt index faa64d2..c6efcff 100644 --- a/metis-lang/src/main/kotlin/io/github/seggan/metis/runtime/State.kt +++ b/metis-lang/src/main/kotlin/io/github/seggan/metis/runtime/State.kt @@ -129,8 +129,8 @@ class State(parentState: State? = null) { io["stderr"] = zeroArgFunction { wrapOutStream(stderr) } io["stdin"] = zeroArgFunction { wrapInStream(stdin) } - io["in_stream"] = inStreamMetatable - io["out_stream"] = outStreamMetatable + io["inStream"] = inStreamMetatable + io["outStream"] = outStreamMetatable globals["io"] = io globals["string"] = Value.String.metatable diff --git a/metis-lang/src/main/kotlin/io/github/seggan/metis/runtime/intrinsics/Coroutine.kt b/metis-lang/src/main/kotlin/io/github/seggan/metis/runtime/intrinsics/Coroutine.kt index 8be8722..fcc29ad 100644 --- a/metis-lang/src/main/kotlin/io/github/seggan/metis/runtime/intrinsics/Coroutine.kt +++ b/metis-lang/src/main/kotlin/io/github/seggan/metis/runtime/intrinsics/Coroutine.kt @@ -63,10 +63,10 @@ class Coroutine(state: State, chunk: Chunk.Instance, args: Value.List) : Value { result.name.lowercase().metisValue() } } - table["last_result"] = oneArgFunction { self -> + table["lastResult"] = oneArgFunction { self -> self.convertTo().lastResult.name.lowercase().metisValue() } - table["last_yielded"] = oneArgFunction { self -> + table["lastYielded"] = oneArgFunction { self -> self.convertTo().lastYielded } diff --git a/metis-lang/src/main/kotlin/io/github/seggan/metis/runtime/intrinsics/Intrinsics.kt b/metis-lang/src/main/kotlin/io/github/seggan/metis/runtime/intrinsics/Intrinsics.kt index 4452a27..600a559 100644 --- a/metis-lang/src/main/kotlin/io/github/seggan/metis/runtime/intrinsics/Intrinsics.kt +++ b/metis-lang/src/main/kotlin/io/github/seggan/metis/runtime/intrinsics/Intrinsics.kt @@ -26,7 +26,7 @@ object Intrinsics { } internal fun registerDefault() { - _intrinsics["load_chunk"] = twoArgFunction { name, chunk -> + _intrinsics["loadChunk"] = twoArgFunction { name, chunk -> val source = CodeSource.constant(name.stringValue(), chunk.stringValue()) Chunk.load(source).Instance(this) } diff --git a/metis-lang/src/main/kotlin/io/github/seggan/metis/runtime/intrinsics/NativeLibrary.kt b/metis-lang/src/main/kotlin/io/github/seggan/metis/runtime/intrinsics/NativeLibrary.kt index 130a729..e2acce9 100644 --- a/metis-lang/src/main/kotlin/io/github/seggan/metis/runtime/intrinsics/NativeLibrary.kt +++ b/metis-lang/src/main/kotlin/io/github/seggan/metis/runtime/intrinsics/NativeLibrary.kt @@ -81,15 +81,15 @@ object RegexLib : NativeLibrary("regex") { */ object OsLib : NativeLibrary("os") { override fun init(lib: MutableMap) { - lib["get_env"] = oneArgFunction { value -> + lib["getEnv"] = oneArgFunction { value -> System.getenv(value.stringValue())?.metisValue() ?: Value.Null } - lib["set_env"] = twoArgFunction { value, other -> + lib["setEnv"] = twoArgFunction { value, other -> System.setProperty(value.stringValue(), other.stringValue()) Value.Null } - lib["get_cwd"] = zeroArgFunction { currentDir.absolutePathString().metisValue() } - lib["set_cwd"] = oneArgFunction { p -> + lib["getCwd"] = zeroArgFunction { currentDir.absolutePathString().metisValue() } + lib["setCwd"] = oneArgFunction { p -> val path = fileSystem.getPath(p.stringValue()) if (!path.isAbsolute) { throw MetisRuntimeException( @@ -128,9 +128,9 @@ object PathLib : NativeLibrary("__path") { } } lib["parent"] = pathFunction { it.parent.toString().metisValue() } - lib["file_name"] = pathFunction { it.fileName.toString().metisValue() } + lib["fileName"] = pathFunction { it.fileName.toString().metisValue() } lib["root"] = pathFunction { it.root.toString().metisValue() } - lib["is_absolute"] = pathFunction { it.isAbsolute.metisValue() } + lib["isAbsolute"] = pathFunction { it.isAbsolute.metisValue() } lib["list"] = pathFunction { path -> val list = Value.List() path.toFile().listFiles()?.forEach { @@ -139,10 +139,10 @@ object PathLib : NativeLibrary("__path") { list } lib["exists"] = pathFunction { it.exists().metisValue() } - lib["is_file"] = pathFunction { it.isRegularFile().metisValue() } - lib["is_dir"] = pathFunction { it.isDirectory().metisValue() } - lib["is_symlink"] = pathFunction { it.isSymbolicLink().metisValue() } - lib["is_hidden"] = pathFunction { it.isHidden().metisValue() } + lib["isFile"] = pathFunction { it.isRegularFile().metisValue() } + lib["isDir"] = pathFunction { it.isDirectory().metisValue() } + lib["isSymlink"] = pathFunction { it.isSymbolicLink().metisValue() } + lib["isHidden"] = pathFunction { it.isHidden().metisValue() } lib["move"] = twoArgFunction { src, dest -> translateIoError { toPath(src).moveTo(toPath(dest)) @@ -150,11 +150,11 @@ object PathLib : NativeLibrary("__path") { Value.Null } lib["delete"] = pathFunction { it.deleteIfExists().metisValue() } - lib["create_dir"] = pathFunction { it.createDirectory().absolutePathString().metisValue() } - lib["create_dirs"] = pathFunction { it.createDirectories().absolutePathString().metisValue() } - lib["delete_recursive"] = pathFunction { it.deleteRecursively(); Value.Null } - lib["open_write"] = pathFunction { wrapOutStream(it.outputStream()) } - lib["open_read"] = pathFunction { wrapInStream(it.inputStream()) } + lib["createDir"] = pathFunction { it.createDirectory().absolutePathString().metisValue() } + lib["createDirs"] = pathFunction { it.createDirectories().absolutePathString().metisValue() } + lib["deleteRecursive"] = pathFunction { it.deleteRecursively(); Value.Null } + lib["openWrite"] = pathFunction { wrapOutStream(it.outputStream()) } + lib["openRead"] = pathFunction { wrapInStream(it.inputStream()) } } } diff --git a/metis-lang/src/main/kotlin/io/github/seggan/metis/runtime/intrinsics/NativeObjects.kt b/metis-lang/src/main/kotlin/io/github/seggan/metis/runtime/intrinsics/NativeObjects.kt index c4820f0..d2a34c4 100644 --- a/metis-lang/src/main/kotlin/io/github/seggan/metis/runtime/intrinsics/NativeObjects.kt +++ b/metis-lang/src/main/kotlin/io/github/seggan/metis/runtime/intrinsics/NativeObjects.kt @@ -124,7 +124,7 @@ private val sbMetatable = buildTable { table -> self.asObj().delete(start.intValue(), end.intValue()) self } - table["delete_at"] = twoArgFunction(true) { self, index -> + table["deleteAt"] = twoArgFunction(true) { self, index -> self.asObj().deleteCharAt(index.intValue()) self } diff --git a/metis-lang/src/main/kotlin/io/github/seggan/metis/runtime/intrinsics/ValueInit.kt b/metis-lang/src/main/kotlin/io/github/seggan/metis/runtime/intrinsics/ValueInit.kt index 36b31da..68f87ef 100644 --- a/metis-lang/src/main/kotlin/io/github/seggan/metis/runtime/intrinsics/ValueInit.kt +++ b/metis-lang/src/main/kotlin/io/github/seggan/metis/runtime/intrinsics/ValueInit.kt @@ -62,7 +62,7 @@ internal fun initString() = buildTable { table -> self.stringValue().substring(start.intValue(), end.intValue()).metisValue() } } - table["equal_ignore_case"] = twoArgFunction(true) { self, other -> + table["equalIgnoreCase"] = twoArgFunction(true) { self, other -> self.stringValue().equals(other.stringValue(), ignoreCase = true).metisValue() } @@ -110,7 +110,7 @@ internal fun initNumber() = buildTable { table -> table["__neg__"] = oneArgFunction(true) { self -> (-self.doubleValue()).metisValue() } - table["string_with_radix"] = twoArgFunction(true) { self, radix -> + table["stringWithRadix"] = twoArgFunction(true) { self, radix -> self.intValue().toString(radix.intValue()).metisValue() } @@ -127,7 +127,7 @@ internal fun initNumber() = buildTable { table -> } table["nan"] = Value.Number.NAN table["inf"] = Value.Number.INF - table["neg_inf"] = Value.Number.NEG_INF + table["negInf"] = Value.Number.NEG_INF } internal fun initBoolean() = buildTable { table -> @@ -213,7 +213,7 @@ internal fun initList() = buildTable { table -> self.convertTo().remove(value) Value.Null } - table["remove_at"] = twoArgFunction(true) { self, index -> + table["removeAt"] = twoArgFunction(true) { self, index -> self.convertTo().removeAt(index.intValue()) } table["slice"] = threeArgFunction(true) { self, start, end -> diff --git a/metis-lang/src/main/resources/core.metis b/metis-lang/src/main/resources/core.metis index 7a20225..6d6b260 100644 --- a/metis-lang/src/main/resources/core.metis +++ b/metis-lang/src/main/resources/core.metis @@ -2,7 +2,7 @@ global fn str(x) = x.__str__() global fn len(x) = x.__len__() global fn iter(x) = x.__iter__() -global fn with_metatable(x, mt) +global fn withMetatable(x, mt) x.metatable = mt return x end @@ -20,5 +20,5 @@ global fn input(prompt) io.stdout().write(prompt.encode("UTF-8")) io.stdout().flush() end - return io.stdin().read_line() + return io.stdin().readLine() end \ No newline at end of file diff --git a/metis-lang/src/main/resources/core/collection.metis b/metis-lang/src/main/resources/core/collection.metis index 811a5fc..6d0869d 100644 --- a/metis-lang/src/main/resources/core/collection.metis +++ b/metis-lang/src/main/resources/core/collection.metis @@ -8,9 +8,9 @@ fn iterator.next(self) return res end -fn iterator.has_next(self) = self.index < len(self.coll) +fn iterator.hasNext(self) = self.index < len(self.coll) -fn collection.__iter__(self) = with_metatable({ "coll" = self, "index" = 0 }, iterator) +fn collection.__iter__(self) = withMetatable({ "coll" = self, "index" = 0 }, iterator) fn collection.__eq__(self, other) if type(self) != type(other) or len(self) != len(other) diff --git a/metis-lang/src/main/resources/core/coroutine.metis b/metis-lang/src/main/resources/core/coroutine.metis index 0c83bd2..bc293ba 100644 --- a/metis-lang/src/main/resources/core/coroutine.metis +++ b/metis-lang/src/main/resources/core/coroutine.metis @@ -6,7 +6,7 @@ fn coroutine.run(self) end end -fn coroutine.run_at_most(self, n) +fn coroutine.runAtMost(self, n) let x = 0 while x < n if self.step() != "continue" diff --git a/metis-lang/src/main/resources/core/io.metis b/metis-lang/src/main/resources/core/io.metis index 34cbe2c..c4c293d 100644 --- a/metis-lang/src/main/resources/core/io.metis +++ b/metis-lang/src/main/resources/core/io.metis @@ -1,5 +1,5 @@ let BUFSIZE = 2048 -fn io.in_stream.read_all(self) +fn io.inStream.readAll(self) let result = [] let buffer = bytes.allocate(BUFSIZE) let read = self.read(buffer) @@ -10,17 +10,17 @@ fn io.in_stream.read_all(self) return bytes.concat(result) end -fn io.in_stream.read_text(self) +fn io.inStream.readText(self) let result = "" do - result = self.read_all().decode() + result = self.readAll().decode() finally self.close() end return result end -fn io.in_stream.read_line(self) +fn io.inStream.readLine(self) let result = string.builder() let c = self.read() while c is not null and c != 10 @@ -30,7 +30,7 @@ fn io.in_stream.read_line(self) return str(result) end -fn io.in_stream.copy_to(self, out) +fn io.inStream.copyTo(self, out) let buffer = bytes.allocate(BUFSIZE) let read = self.read(buffer) while read is not null and read > 0 @@ -39,16 +39,16 @@ fn io.in_stream.copy_to(self, out) end end -fn io.out_stream.write_line(self, line) +fn io.outStream.writeLine(self, line) self.write(line.encode()) self.write('\n') end -fn io.out_stream.write_text(self, text) +fn io.outStream.writeText(self, text) self.write(text.encode()) end -fn io.in_stream.use(self, f) +fn io.inStream.use(self, f) let result = null do result = f(self) @@ -58,7 +58,7 @@ fn io.in_stream.use(self, f) return result end -fn io.out_stream.use(self, f) +fn io.outStream.use(self, f) let result = null do result = f(self) diff --git a/metis-lang/src/main/resources/core/list.metis b/metis-lang/src/main/resources/core/list.metis index b7dcfee..7af50ba 100644 --- a/metis-lang/src/main/resources/core/list.metis +++ b/metis-lang/src/main/resources/core/list.metis @@ -9,7 +9,7 @@ fn list.__str__(self) end sb.append(", ") end - sb.delete_last(2) + sb.deleteLast(2) return str(sb.append("]")) end @@ -18,7 +18,7 @@ fn list.join(self, sep) for v in self sb.append(v).append(sep) end - sb.delete_last(len(sep)) + sb.deleteLast(len(sep)) return str(sb) end diff --git a/metis-lang/src/main/resources/core/range.metis b/metis-lang/src/main/resources/core/range.metis index 70afb6e..5a93c90 100644 --- a/metis-lang/src/main/resources/core/range.metis +++ b/metis-lang/src/main/resources/core/range.metis @@ -15,7 +15,7 @@ end fn range.__len__(self) = (self.stop - self.start) / self.step -fn range.exclusive(start, stop, step) = with_metatable({ +fn range.exclusive(start, stop, step) = withMetatable({ "start" = start, "stop" = stop, "step" = step diff --git a/metis-lang/src/main/resources/core/string.metis b/metis-lang/src/main/resources/core/string.metis index 83ed0e3..9e5c9f4 100644 --- a/metis-lang/src/main/resources/core/string.metis +++ b/metis-lang/src/main/resources/core/string.metis @@ -1,16 +1,16 @@ do - let sb_meta = string.builder().metatable - fn sb_meta.append(self, value) = self.__append(str(value)) - fn sb_meta.delete_last(self, n) + let sbMeta = string.builder().metatable + fn sbMeta.append(self, value) = self.__append(str(value)) + fn sbMeta.deleteLast(self, n) let length = len(self) self.delete(length - n, length) return self end // THIS GOES LAST - fn sb_meta.__set__(self, index, value) = self.__set(self, index, str(value)) + fn sbMeta.__set__(self, index, value) = self.__set(self, index, str(value)) end -fn string.char_code(self) = self.encode("UTF-8")[0] +fn string.charCode(self) = self.encode("UTF-8")[0] fn string.repeat(self, n) let sb = string.builder(len(self) * n) diff --git a/metis-lang/src/main/resources/core/table.metis b/metis-lang/src/main/resources/core/table.metis index e6cc0b5..22eb4a0 100644 --- a/metis-lang/src/main/resources/core/table.metis +++ b/metis-lang/src/main/resources/core/table.metis @@ -8,7 +8,7 @@ fn table.__str__(self) .append(v) .append(", ") end - sb.delete_at(len(sb) - 2) + sb.deleteAt(len(sb) - 2) return str(sb.append("}")) end diff --git a/metis-lang/src/main/resources/std/json.metis b/metis-lang/src/main/resources/std/json.metis index 1a85be9..b427ac4 100644 --- a/metis-lang/src/main/resources/std/json.metis +++ b/metis-lang/src/main/resources/std/json.metis @@ -1,11 +1,11 @@ let parser = {} -let number_chars = "0123456789.eE+-" -fn parser.parse_number(self) +let numberChars = "0123456789.eE+-" +fn parser.parseNumber(self) let sb = string.builder() while self.pos < self.len let c = self.text[self.pos] - if c in number_chars + if c in numberChars sb.append(c) self.pos = self.pos + 1 else @@ -15,7 +15,7 @@ fn parser.parse_number(self) return number.parse(str(sb)) end -fn parser.parse_string(self) +fn parser.parseString(self) let sb = string.builder() self.pos = self.pos + 1 while true @@ -58,17 +58,17 @@ fn parser.parse_string(self) return str(sb) end -fn parser.parse_array(self) +fn parser.parseArray(self) let result = [] self.pos = self.pos + 1 while true - self.skip_whitespace() + self.skipWhitespace() if self.text[self.pos] == "]" self.pos = self.pos + 1 break end - result.append(self.parse_value()) - self.skip_whitespace() + result.append(self.parseValue()) + self.skipWhitespace() if self.text[self.pos] == "]" self.pos = self.pos + 1 break @@ -81,25 +81,25 @@ fn parser.parse_array(self) return result end -fn parser.parse_object(self) +fn parser.parseObject(self) let result = {} self.pos = self.pos + 1 while true - self.skip_whitespace() + self.skipWhitespace() if self.text[self.pos] == "}" self.pos = self.pos + 1 break end - let key = self.parse_string() - self.skip_whitespace() + let key = self.parseString() + self.skipWhitespace() if self.text[self.pos] != ":" raise error ParseError("Expected ':' at " + str(self.pos)) : { "pos" = self.pos } end self.pos = self.pos + 1 - self.skip_whitespace() - let value = self.parse_value() + self.skipWhitespace() + let value = self.parseValue() result[key] = value - self.skip_whitespace() + self.skipWhitespace() if self.text[self.pos] == "}" self.pos = self.pos + 1 break @@ -112,17 +112,17 @@ fn parser.parse_object(self) return result end -fn parser.parse_value(self) - self.skip_whitespace() +fn parser.parseValue(self) + self.skipWhitespace() let c = self.text[self.pos] if c == "{" - return self.parse_object() + return self.parseObject() elif c == "[" - return self.parse_array() + return self.parseArray() elif c == "\"" - return self.parse_string() - elif c in number_chars - return self.parse_number() + return self.parseString() + elif c in numberChars + return self.parseNumber() elif self.text.sub(self.pos, self.pos + 4) == "true" self.pos = self.pos + 4 return true @@ -138,7 +138,7 @@ fn parser.parse_value(self) end end -fn parser.skip_whitespace(self) +fn parser.skipWhitespace(self) while self.pos < self.len let c = self.text[self.pos] if c == " " or c == "\t" or c == "\n" or c == "\r" @@ -149,11 +149,11 @@ fn parser.skip_whitespace(self) end end -global fn parse(text) = with_metatable({ +global fn parse(text) = withMetatable({ "text" = text, "pos" = 0, "len" = len(text) -}, parser).parse_value() +}, parser).parseValue() global fn stringify(value) if type(value) == "string" diff --git a/metis-lang/src/main/resources/std/path.metis b/metis-lang/src/main/resources/std/path.metis index 1dac184..738f80d 100644 --- a/metis-lang/src/main/resources/std/path.metis +++ b/metis-lang/src/main/resources/std/path.metis @@ -2,30 +2,30 @@ import __path globals().merge(__path) -global fn read_all(p) +global fn readAll(p) let result = null - let stream = __path.open_read(p) + let stream = __path.openRead(p) do - result = stream.read_all() + result = stream.readAll() finally stream.close() end return result end -global fn read_text(p) +global fn readText(p) let result = null - let stream = __path.open_read(p) + let stream = __path.openRead(p) do - result = stream.read_text() + result = stream.readText() finally stream.close() end return result end -global fn write_all(p, data) - let stream = __path.open_write(p) +global fn writeAll(p, data) + let stream = __path.openWrite(p) do stream.write(data) finally @@ -33,20 +33,20 @@ global fn write_all(p, data) end end -global fn write_text(p, data) - let stream = __path.open_write(p) +global fn writeText(p, data) + let stream = __path.openWrite(p) do - stream.write_text(data) + stream.writeText(data) finally stream.close() end end global fn copy(src, dest) - let source = __path.open_read(src) - let destination = __path.open_write(dest) + let source = __path.openRead(src) + let destination = __path.openWrite(dest) do - source.copy_to(destination) + source.copyTo(destination) finally source.close() destination.close()