Skip to content

Commit f3bda25

Browse files
committed
Support my function. func is always typed. Reorg docs.
1 parent 3d19f65 commit f3bda25

36 files changed

Lines changed: 608 additions & 457 deletions

docs/docs.md

Lines changed: 174 additions & 216 deletions
Large diffs are not rendered by default.

docs/gen-docs.cy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ func text(text_t md.SPANTYPE, ptr pointer, len int, userdata pointer) int:
375375
out += str
376376
return 0
377377

378-
func getAttrText(attr) String:
378+
func getAttrText(attr dynamic) String:
379379
if attr.size == 0:
380380
return ''
381381
return (attr.text as pointer).toArray(0, attr.size).decode()

docs/style.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ h3 {
187187
border-radius: 0rem;
188188
}
189189

190+
main h2 > code {
191+
color: var(--header);
192+
font-size: 0.9em;
193+
background-color: transparent;
194+
}
195+
190196
main h3 > code {
191197
color: var(--header);
192198
font-size: 0.9em;

examples/account.cy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ type Account:
22
name String
33
balance float
44

5-
func deposit(amt):
5+
func deposit(amt float):
66
balance += amt
77

8-
func withdraw(amt):
8+
func withdraw(amt float):
99
if amt > balance:
1010
throw error.InsufficientFunds
1111
else:
1212
balance -= amt
1313

14-
func show(title):
14+
func show(title String):
1515
print "$(title), $(name), $(balance)"
1616

17-
func Account.new(name) Account:
17+
func Account.new(name String) Account:
1818
return [Account name: name, balance: 0.0]
1919

2020
var a = Account.new('Savings')

src/ast.zig

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,10 @@ const NodeData = union {
302302
comptimeStmt: struct {
303303
expr: NodeId,
304304
},
305-
func: struct {
305+
func: packed struct {
306306
header: NodeId,
307-
bodyHead: NodeId,
307+
bodyHead: cy.Nullable(u24),
308+
sig_t: FuncSigType,
308309
},
309310
funcHeader: struct {
310311
/// Can be NullNode for lambdas.
@@ -437,6 +438,12 @@ const NodeData = union {
437438
},
438439
};
439440

441+
const FuncSigType = enum(u8) {
442+
func,
443+
my,
444+
infer,
445+
};
446+
440447
/// TODO: See if separating `head`, `srcPos`, and `data` improves perf for a large project.
441448
pub const Node = struct {
442449
head: NodeHead,

src/compiler.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ fn performChunkInitSema(self: *Compiler, c: *cy.Chunk) !void {
485485
c.parser.ast.setNodeData(decl, .{ .func = .{
486486
.header = header,
487487
.bodyHead = cy.NullNode,
488+
.sig_t = .func,
488489
}});
489490
c.updateAstView(c.parser.ast.view());
490491

0 commit comments

Comments
 (0)