diff --git a/lib/c/src/errno.c.ri b/lib/c/src/errno.c.ri index f0d8a75f2..ae720cd4f 100644 --- a/lib/c/src/errno.c.ri +++ b/lib/c/src/errno.c.ri @@ -16,7 +16,7 @@ pub struct ErrnoError < Throwable { #[inline] pub func errno() -> int32 { - comptime if _LINUX_ { + $if _LINUX_ { return unsafe { libc.__errno_location()?.* }; } else { return unsafe { libc._errno().* }; diff --git a/lib/c/src/libc/errno.ri b/lib/c/src/libc/errno.ri index 3bf5d3600..70128454b 100644 --- a/lib/c/src/libc/errno.ri +++ b/lib/c/src/libc/errno.ri @@ -2,7 +2,7 @@ // source code is governed by an MIT license that can be found in the LICENSE // file. -comptime if _LINUX_ { +$if _LINUX_ { extern (C) { pub func __errno_location() -> ?&mut int32; } @@ -12,7 +12,7 @@ comptime if _LINUX_ { pub const ERANGE := 34; } -comptime if _WINDOWS_ { +$if _WINDOWS_ { extern (C) { #[dllimport] pub func _errno() -> &mut int32; diff --git a/lib/c/src/libc/signal.ri b/lib/c/src/libc/signal.ri index de5637a7c..236e3fff7 100644 --- a/lib/c/src/libc/signal.ri +++ b/lib/c/src/libc/signal.ri @@ -9,7 +9,7 @@ import ../ctypes.{ pid_t, uid_t }; pub alias SignalHandler := func(int32, &mut siginfo_t, rawptr); -comptime if _LINUX_ { +$if _LINUX_ { pub const SA_ONSTACK := 0x08000000; pub const SA_SIGINFO := 0x00000004; pub const SA_NOCLDWAIT := 0x00000002; @@ -50,7 +50,7 @@ comptime if _LINUX_ { pub const SEGV_ACCERR := 0x2; pub struct sigset_t { - pub __val: [comptime if _X86_ { 32 } else { 16 }]uint32; + pub __val: [$if _X86_ { 32 } else { 16 }]uint32; } pub struct sigval { @@ -88,7 +88,7 @@ comptime if _LINUX_ { } extern (C) { - comptime if _LINUX_ { + $if _LINUX_ { pub func sigaction(signum: int32, act: ?&sigaction_t, old_act: ?&mut sigaction_t) -> int32; } pub func signal(sig: int32, handler: SignalHandler) -> ?SignalHandler; diff --git a/lib/c/src/libc/stat.ri b/lib/c/src/libc/stat.ri index f2b280af7..8d18aef84 100644 --- a/lib/c/src/libc/stat.ri +++ b/lib/c/src/libc/stat.ri @@ -4,7 +4,7 @@ import c/ctypes.*; -comptime if _AMD64_ { +$if _AMD64_ { // The `stat` definition used by the Linux kernel. pub struct Stat { pub dev: dev_t; diff --git a/lib/c/src/libc/stdio.ri b/lib/c/src/libc/stdio.ri index a49067a9d..d4ec6c3a2 100644 --- a/lib/c/src/libc/stdio.ri +++ b/lib/c/src/libc/stdio.ri @@ -35,7 +35,7 @@ pub const O_CLOEXEC := 0x80000; pub struct FILE; -comptime if _LINUX_ { +$if _LINUX_ { extern (C) { pub var stdin: &mut FILE; pub var stdout: &mut FILE; @@ -64,7 +64,7 @@ comptime if _LINUX_ { pub const TMP_MAX := 308915776; } -comptime if _WINDOWS_ { +$if _WINDOWS_ { extern (C) { func __acrt_iob_fn(index: uint32) -> &mut FILE; } diff --git a/lib/c/src/libc/stdlib.ri b/lib/c/src/libc/stdlib.ri index 8d0a0afae..efe3c98b8 100644 --- a/lib/c/src/libc/stdlib.ri +++ b/lib/c/src/libc/stdlib.ri @@ -2,7 +2,7 @@ // source code is governed by an MIT license that can be found in the LICENSE // file. -comptime if _LINUX_ { +$if _LINUX_ { pub const RAND_MAX := 0x7fffffff; } else if _WINDOWS_ { pub const RAND_MAX := 0x7fff; diff --git a/lib/c/src/libc/unistd.ri b/lib/c/src/libc/unistd.ri index 7f2681fa2..67dd7b206 100644 --- a/lib/c/src/libc/unistd.ri +++ b/lib/c/src/libc/unistd.ri @@ -21,7 +21,7 @@ extern (C) { pub func readlink(path: [&]uint8, buf: [&]uint8, size: uint) -> int; - comptime if _LINUX_ { + $if _LINUX_ { pub func get_nprocs() -> int32; } } diff --git a/lib/c/src/wyhash.ri b/lib/c/src/wyhash.ri index 4dcbed466..58111a249 100644 --- a/lib/c/src/wyhash.ri +++ b/lib/c/src/wyhash.ri @@ -20,7 +20,7 @@ extern (C) { func wy2u01(r: uint64) -> float64; func wy2gau(r: uint64) -> float64; - comptime if !WYHASH_32BIT_MUM { + $if !WYHASH_32BIT_MUM { func wy2u0k(r: uint64, k: uint64) -> uint64; } } diff --git a/lib/core/src/TestRunner.ri b/lib/core/src/TestRunner.ri index ab27041d3..4e4998796 100644 --- a/lib/core/src/TestRunner.ri +++ b/lib/core/src/TestRunner.ri @@ -2,7 +2,7 @@ // source code is governed by an MIT license that can be found in the LICENSE // file. -comptime if _TESTS_ { +$if _TESTS_ { var support_color := console_is_atty(1); var ok_status := bold(green("-> OK")); diff --git a/lib/core/src/backtrace.c.ri b/lib/core/src/backtrace.c.ri index 445bf1853..bdd9c29cb 100644 --- a/lib/core/src/backtrace.c.ri +++ b/lib/core/src/backtrace.c.ri @@ -2,7 +2,7 @@ // source code is governed by an MIT license that can be found in the LICENSE // file. -comptime if !_RELEASE_ { // skip backtrace in release mode +$if !_RELEASE_ { // skip backtrace in release mode #![compile_c_source("../thirdparty/libbacktrace/backtrace.c")] import c; @@ -78,7 +78,7 @@ comptime if !_RELEASE_ { // skip backtrace in release mode } pub func bt_print(frames_to_skip: int32 := 0) { - comptime if _RELEASE_ { + $if _RELEASE_ { _ = frames_to_skip; } else { unsafe { diff --git a/lib/core/src/entry_point.ri b/lib/core/src/entry_point.ri index 5a3b43a97..b1be3db74 100644 --- a/lib/core/src/entry_point.ri +++ b/lib/core/src/entry_point.ri @@ -20,7 +20,7 @@ func init_args(_argc: uint, _argv: [&][&]uint8) { } } -comptime if _TESTS_ { +$if _TESTS_ { func main(_argc: int32, _argv: [&][&]uint8, mut test_runner: TestRunner) { setup_signals_handler(); init_args(@as(uint, _argc), _argv); diff --git a/lib/core/src/int.ri b/lib/core/src/int.ri index e91d3dce4..74cac38aa 100644 --- a/lib/core/src/int.ri +++ b/lib/core/src/int.ri @@ -149,12 +149,12 @@ extend int64 < Stringable { } extend int < Stringable { - pub const MIN := @as(int, comptime if _x64_ { int64.MIN } else { int32.MIN }); - pub const MAX := @as(int, comptime if _x64_ { int64.MAX } else { int32.MAX }); + pub const MIN := @as(int, $if _x64_ { int64.MIN } else { int32.MIN }); + pub const MAX := @as(int, $if _x64_ { int64.MAX } else { int32.MAX }); #[inline] pub func bits() -> uint32 { - return comptime if _x64_ { 64 } else { 32 }; + return $if _x64_ { 64 } else { 32 }; } /// Returns the value of `self` as a string. diff --git a/lib/core/src/uint.ri b/lib/core/src/uint.ri index 4acf1290d..fc88eeff7 100644 --- a/lib/core/src/uint.ri +++ b/lib/core/src/uint.ri @@ -197,11 +197,11 @@ extend uint64 < Stringable { } extend uint < Stringable { - pub const MAX := @as(uint, comptime if _x64_ { uint64.MAX } else { uint32.MAX }); + pub const MAX := @as(uint, $if _x64_ { uint64.MAX } else { uint32.MAX }); #[inline] pub func bits() -> uint32 { - return comptime if _x64_ { 64 } else { 32 }; + return $if _x64_ { 64 } else { 32 }; } /// Returns the value of `self` as a string. diff --git a/lib/rivet/src/ast/Expr.ri b/lib/rivet/src/ast/Expr.ri index 41701db10..cf9fbf186 100644 --- a/lib/rivet/src/ast/Expr.ri +++ b/lib/rivet/src/ast/Expr.ri @@ -534,7 +534,7 @@ pub enum Expr < traits.Stringable { sb.write_string("else if "); sb.write_string(branch.cond.to_string()); } else { - sb.write_string("comptime if "); + sb.write_string("$if "); sb.write_string(branch.cond.to_string()); } sb.write_fmt("{{ {} nodes }}", branch.nodes.len); diff --git a/lib/rivet/src/parser/decls.ri b/lib/rivet/src/parser/decls.ri index bf8eb3273..e1759fd7d 100644 --- a/lib/rivet/src/parser/decls.ri +++ b/lib/rivet/src/parser/decls.ri @@ -99,7 +99,7 @@ extend Parser { mut pos := self.tok.pos; match { self.tok.kind == .Comment -> return .Comment(self.parse_comment()), - self.accept(.KwComptime) -> match self.tok.kind { + self.accept(.Dollar) -> match self.tok.kind { .KwIf -> return .ComptimeIf(self.parse_comptime_if(.Decl)), else -> { report.error("invalid comptime construction", self.tok.pos); diff --git a/lib/rivet/src/parser/exprs.ri b/lib/rivet/src/parser/exprs.ri index 36f9b73ed..d62b17d5f 100644 --- a/lib/rivet/src/parser/exprs.ri +++ b/lib/rivet/src/parser/exprs.ri @@ -214,7 +214,7 @@ extend Parser { func parse_primary_expr(mut self) -> ast.Expr { mut expr: ast.Expr := match { - self.accept(.KwComptime) -> match self.tok.kind { + self.accept(.Dollar) -> match self.tok.kind { .KwIf -> .ComptimeIf(self.parse_comptime_if(.Expr)), else -> { report.error("invalid comptime construction", self.tok.pos); diff --git a/lib/rivet/src/parser/stmts.ri b/lib/rivet/src/parser/stmts.ri index 59aa0573b..5b5d921b4 100644 --- a/lib/rivet/src/parser/stmts.ri +++ b/lib/rivet/src/parser/stmts.ri @@ -9,7 +9,7 @@ extend Parser { func parse_stmt(mut self) -> ast.Stmt { return match { self.tok.kind == .Comment -> .Comment(self.parse_comment()), - self.accept(.KwComptime) -> match self.tok.kind { + self.accept(.Dollar) -> match self.tok.kind { .KwIf -> .ComptimeIf(self.parse_comptime_if(.Stmt)), else -> { report.error("invalid comptime construction", self.tok.pos); diff --git a/lib/rivet/src/token/Kind.ri b/lib/rivet/src/token/Kind.ri index 06a3dc301..d9e3df245 100644 --- a/lib/rivet/src/token/Kind.ri +++ b/lib/rivet/src/token/Kind.ri @@ -1,5 +1,5 @@ -// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this -// source code is governed by an MIT license that can be found in the LICENSE +// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this +// source code is governed by an MIT license that can be found in the LICENSE // file. import std/traits; @@ -46,6 +46,7 @@ var kind_strings := [ KindMap(.Ellipsis, "..."), KindMap(.Hash, "#"), KindMap(.At, "@"), + KindMap(.Dollar, "$"), KindMap(.Arrow, "->"), KindMap(.Comma, ","), KindMap(.Colon, ":"), @@ -71,7 +72,6 @@ var kind_strings := [ KindMap(.KwAs, "as"), KindMap(.KwBreak, "break"), KindMap(.KwCatch, "catch"), - KindMap(.KwComptime, "comptime"), KindMap(.KwConst, "const"), KindMap(.KwContinue, "continue"), KindMap(.KwDefer, "defer"), @@ -144,6 +144,7 @@ pub enum Kind < traits.Stringable { Ellipsis, // ... Hash, // # At, // @ + Dollar, // $ Arrow, // -> Comma, // , Colon, // : @@ -170,7 +171,6 @@ pub enum Kind < traits.Stringable { KwAs, // as KwBreak, // break KwCatch, // catch - KwComptime, // comptime KwConst, // const KwContinue, // continue KwDefer, // defer diff --git a/lib/rivet/src/tokenizer/next.ri b/lib/rivet/src/tokenizer/next.ri index 334f047e0..b3271acd2 100644 --- a/lib/rivet/src/tokenizer/next.ri +++ b/lib/rivet/src/tokenizer/next.ri @@ -162,6 +162,7 @@ extend Tokenizer { return self.new_token(.Mod); }, '@' -> return self.new_token(.At), + '$' -> return self.new_token(.Dollar), '=' -> { if nextc == '=' { self.pos += 1; diff --git a/lib/std/src/dynlib/mod.c.ri b/lib/std/src/dynlib/mod.c.ri index 5bd7ddeb5..59ecc45a5 100644 --- a/lib/std/src/dynlib/mod.c.ri +++ b/lib/std/src/dynlib/mod.c.ri @@ -2,7 +2,7 @@ // source code is governed by an MIT license that can be found in the LICENSE // file. -comptime if _LINUX_ { +$if _LINUX_ { #![link_library("dl")] } @@ -92,7 +92,7 @@ func dlerror() -> ?string { #[inline] func get_shared_library_extension() -> string { - return comptime if _LINUX_ { + return $if _LINUX_ { ".so" } else if _WINDOWS_ { ".dll" diff --git a/lib/std/src/env/mod.c.ri b/lib/std/src/env/mod.c.ri index cf5aa4a0d..fa20a7171 100644 --- a/lib/std/src/env/mod.c.ri +++ b/lib/std/src/env/mod.c.ri @@ -6,7 +6,7 @@ import core; import c/libc; /// User's home directory. -pub var home_dir := get(comptime if _LINUX_ { "HOME" } else { "USERPROFILE" }) ?? ""; +pub var home_dir := get($if _LINUX_ { "HOME" } else { "USERPROFILE" }) ?? ""; /// Returns `true` if the environment variable exists. #[inline] diff --git a/lib/std/src/fs/Path.c.ri b/lib/std/src/fs/Path.c.ri index d439b1eda..f7796707c 100644 --- a/lib/std/src/fs/Path.c.ri +++ b/lib/std/src/fs/Path.c.ri @@ -9,9 +9,9 @@ import ../mem; pub struct Path { pub alias MAX_LEN := libc.MAX_PATH_LEN; - pub const SEPARATOR := comptime if _WINDOWS_ { b'\\' } else { b'/' }; - pub var separator_str := comptime if _WINDOWS_ { "\\" } else { "/" }; - pub var delimiter := comptime if _WINDOWS_ { ";" } else { ":" }; + pub const SEPARATOR := $if _WINDOWS_ { b'\\' } else { b'/' }; + pub var separator_str := $if _WINDOWS_ { "\\" } else { "/" }; + pub var delimiter := $if _WINDOWS_ { ";" } else { ":" }; /// Returns `true` if the given byte is a valid path separator #[inline] diff --git a/lib/std/src/sys/arch.ri b/lib/std/src/sys/arch.ri index 4610d342f..8009d20ae 100644 --- a/lib/std/src/sys/arch.ri +++ b/lib/std/src/sys/arch.ri @@ -3,7 +3,7 @@ // file. import ../traits; -comptime if !(_X86_ || _AMD64_) { +$if !(_X86_ || _AMD64_) { import ../process; } @@ -31,7 +31,7 @@ pub enum Arch as uint8 < traits.Stringable { /// Returns the current architecture. #[inline] pub func arch() -> Arch { - comptime if _X86_ { + $if _X86_ { return .X86; } else if _AMD64_ { return .Amd64; diff --git a/lib/std/src/sys/mod.c.ri b/lib/std/src/sys/mod.c.ri index 86887445f..a3e422395 100644 --- a/lib/std/src/sys/mod.c.ri +++ b/lib/std/src/sys/mod.c.ri @@ -4,14 +4,14 @@ import c/libc; -comptime if !_LINUX_ { +$if !_LINUX_ { import ../process; } /// Returns the number of virtual CPU cores found on the system. #[inline] pub func nr_cpus() -> int32 { - comptime if _LINUX_ { + $if _LINUX_ { return unsafe { libc.get_nprocs() }; } else { process.panic("`nr_cpus` only works on linux (for now)"); diff --git a/lib/std/src/sys/os.ri b/lib/std/src/sys/os.ri index 33f6c41f6..5e91e4305 100644 --- a/lib/std/src/sys/os.ri +++ b/lib/std/src/sys/os.ri @@ -3,7 +3,7 @@ // file. import ../traits; -comptime if !(_X86_ || _AMD64_) { +$if !(_X86_ || _AMD64_) { import ../process; } @@ -34,7 +34,7 @@ pub enum OS as uint8 < traits.Stringable { /// Returns the current operating system. #[inline] pub func os() -> OS { - comptime if _LINUX_ { + $if _LINUX_ { return .Linux; } else if _WINDOWS_ { return .Windows; diff --git a/rivetc/src/lexer.py b/rivetc/src/lexer.py index 922c535ae..f44999c73 100644 --- a/rivetc/src/lexer.py +++ b/rivetc/src/lexer.py @@ -560,6 +560,8 @@ def internal_next(self): return token.Token("", Kind.Mod, pos) elif ch == "@": return token.Token("", Kind.At, pos) + elif ch == "$": + return token.Token("", Kind.Dollar, pos) # elif ch == "=": if nextc == "=": diff --git a/rivetc/src/parser.py b/rivetc/src/parser.py index 0f54f30a4..466624dd0 100644 --- a/rivetc/src/parser.py +++ b/rivetc/src/parser.py @@ -208,7 +208,7 @@ def parse_decls(self): return decls def parse_decl(self): - if self.accept(Kind.KwComptime): + if self.accept(Kind.Dollar): if self.tok.kind == Kind.KwIf: return self.parse_comptime_if(0) else: @@ -632,7 +632,7 @@ def decl_operator_is_used(self): return False def parse_stmt(self): - if self.accept(Kind.KwComptime): + if self.accept(Kind.Dollar): if self.tok.kind == Kind.KwIf: return self.parse_comptime_if(1) else: @@ -872,7 +872,7 @@ def parse_unary_expr(self): def parse_primary_expr(self): expr = self.empty_expr() - if self.accept(Kind.KwComptime): + if self.accept(Kind.Dollar): if self.tok.kind == Kind.KwIf: expr = self.parse_comptime_if(3) else: diff --git a/rivetc/src/token.py b/rivetc/src/token.py index 6505ce796..fee4a72a0 100644 --- a/rivetc/src/token.py +++ b/rivetc/src/token.py @@ -40,6 +40,7 @@ class Kind(Enum): Ellipsis = auto_enum() # ... Hash = auto_enum() # # At = auto_enum() # @ + Dollar = auto_enum() # $ Arrow = auto_enum() # -> Comma = auto_enum() # , Colon = auto_enum() # : @@ -66,7 +67,6 @@ class Kind(Enum): KwAs = auto_enum() # as KwBreak = auto_enum() # break KwCatch = auto_enum() # catch - KwComptime = auto_enum() # comptime KwConst = auto_enum() # const KwContinue = auto_enum() # continue KwDefer = auto_enum() # defer @@ -185,6 +185,7 @@ def __str__(self): Kind.Ellipsis: "...", Kind.Hash: "#", Kind.At: "@", + Kind.Dollar: "$", Kind.Arrow: "->", Kind.Comma: ",", Kind.Colon: ":", @@ -210,7 +211,6 @@ def __str__(self): Kind.KwAs: "as", Kind.KwBreak: "break", Kind.KwCatch: "catch", - Kind.KwComptime: "comptime", Kind.KwConst: "const", Kind.KwContinue: "continue", Kind.KwDefer: "defer",