mirror of
https://github.com/Nexoniarz/Finch.git
synced 2026-11-03 00:44:27 +00:00
boot: methods (fn T.m, self by address, mutation analysis), str() of any value
Methods are functions whose first parameter is the receiver's address; a method that changes self can't be called on a temporary or a read-only value, and calling one on a variable keeps a parameter from being borrowed. An argument that lives inside the receiver is copied (c.merge(c)). str(x) and print of arrays and structs go through one formatter, as in the C++ compiler. boot.sh: 12 passed, 0 failed, 10 skipped.
This commit is contained in:
parent
873b52565d
commit
051af1a04e
6 changed files with 284 additions and 34 deletions
|
|
@ -195,6 +195,10 @@ fn parseFn(ptr[Parser] p) -> ast.Node {
|
|||
f := node(p, "fn")
|
||||
expect(p, "fn", "'fn', 'struct' or 'import'")
|
||||
f.name = expect(p, "ident", "a function name").text
|
||||
if accept(p, ".") {
|
||||
f.recv = f.name
|
||||
f.name = expect(p, "ident", "a method name").text
|
||||
}
|
||||
expect(p, "(", "'('")
|
||||
p.depth += 1
|
||||
if !at(p, ")") {
|
||||
|
|
|
|||
Loading…
Reference in a new issue