Skip to content

Commit

Permalink
first draft of concrete syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmuth committed Feb 5, 2024
1 parent f5f7b2d commit 1deed0b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions FrontEnd/ConcteteSyntax/print_argv.concrete.cw
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import fmt
fun strlen(s ptr(u8)) uint:
let! i uint = 0
-- pinc is adds an integer to a pointer it also has an options bound
while ^pinc(s, i) != 0:
while *pinc(s, i) != 0:
set i += 1
return i

@cdecl fun main(argc s32, argv ptr(ptr(u8))) s32:
for i = 0, as(argc, u32), 1:
let s ptr(u8) = ^pinc(argv, i)
let s ptr(u8) = *pinc(argv, i)
-- the print# macro does not supprt zero terminated strings
-- but it does support slices.
let t = slice(s, strlen(s))
Expand Down
6 changes: 3 additions & 3 deletions FrontEnd/ConcteteSyntax/wordcount.concrete.cw
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ fun WordCount(fd os::FD) union(TextStats, os::Error):
let! buf array(1024, u8) = undef
while true:
-- if FileRead returns an uint, assign it to n else return it
trylet n, uint, os::FileRead(fd, buf), err:
trylet n uint = os::FileRead(fd, buf), err:
return err
if n == 0:
break
set stats.num_chars += n
-- index variable has the same type as n.
for i, 0, n, 1:
for i = 0, n, 1:
let c = buf[i]
cond:
case c == '\n':
Expand All @@ -45,7 +45,7 @@ fun WordCount(fd os::FD) union(TextStats, os::Error):

-- cdecl attribute disables name mangling
@cdecl fun main(argc s32, argv ptr(ptr(u8))) s32:
trylet stats, TextStats, WordCount(os::Stdin), err:
trylet stats TextStats = WordCount(os::Stdin), err:
return 1
-- print# is a stmt macro for printing arbitrary values.
-- It is possible to define formatters for custom types.
Expand Down
2 changes: 1 addition & 1 deletion FrontEnd/pp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ def TokensExprIndex(ts: TS, node: cwast.ExprIndex):
cwast.ExprWrap: lambda ts, n: TokensFunctional(ts, "wrapas", [n.expr, n.type]),
cwast.ExprUnwrap: lambda ts, n: TokensFunctional(ts, "unwrap", n.expr),
cwast.ExprField: lambda ts, n: TokensBinaryInfix(ts, ".", n.container, n.field, n),
cwast.ExprDeref: lambda ts, n: TokensUnaryPrefix(ts, "^", n.expr),
cwast.ExprDeref: lambda ts, n: TokensUnaryPrefix(ts, "*", n.expr),
cwast.ExprAddrOf: lambda ts, n: TokensUnaryPrefix(ts, WithMut("&", n.mut), n.expr_lhs),
cwast.Expr2: lambda ts, n: TokensBinaryInfix(ts, cwast.BINARY_EXPR_SHORTCUT_INV[n.binary_expr_kind],
n.expr1, n.expr2, n),
Expand Down

0 comments on commit 1deed0b

Please sign in to comment.