Skip to content

Commit

Permalink
refactor: remove comptime keyword, use $ instead
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS committed Dec 25, 2023
1 parent 0b2b8a5 commit 1edc63a
Show file tree
Hide file tree
Showing 28 changed files with 49 additions and 46 deletions.
2 changes: 1 addition & 1 deletion lib/c/src/errno.c.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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().* };
Expand Down
4 changes: 2 additions & 2 deletions lib/c/src/libc/errno.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -12,7 +12,7 @@ comptime if _LINUX_ {
pub const ERANGE := 34;
}

comptime if _WINDOWS_ {
$if _WINDOWS_ {
extern (C) {
#[dllimport]
pub func _errno() -> &mut int32;
Expand Down
6 changes: 3 additions & 3 deletions lib/c/src/libc/signal.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/c/src/libc/stat.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lib/c/src/libc/stdio.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/c/src/libc/stdlib.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/c/src/libc/unistd.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion lib/c/src/wyhash.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion lib/core/src/TestRunner.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/backtrace.c.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/core/src/entry_point.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions lib/core/src/int.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/uint.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/rivet/src/ast/Expr.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/rivet/src/parser/decls.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/rivet/src/parser/exprs.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/rivet/src/parser/stmts.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions lib/rivet/src/token/Kind.ri
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -46,6 +46,7 @@ var kind_strings := [
KindMap(.Ellipsis, "..."),
KindMap(.Hash, "#"),
KindMap(.At, "@"),
KindMap(.Dollar, "$"),
KindMap(.Arrow, "->"),
KindMap(.Comma, ","),
KindMap(.Colon, ":"),
Expand All @@ -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"),
Expand Down Expand Up @@ -144,6 +144,7 @@ pub enum Kind < traits.Stringable {
Ellipsis, // ...
Hash, // #
At, // @
Dollar, // $
Arrow, // ->
Comma, // ,
Colon, // :
Expand All @@ -170,7 +171,6 @@ pub enum Kind < traits.Stringable {
KwAs, // as
KwBreak, // break
KwCatch, // catch
KwComptime, // comptime
KwConst, // const
KwContinue, // continue
KwDefer, // defer
Expand Down
1 change: 1 addition & 0 deletions lib/rivet/src/tokenizer/next.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lib/std/src/dynlib/mod.c.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
}

Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lib/std/src/env/mod.c.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions lib/std/src/fs/Path.c.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions lib/std/src/sys/arch.ri
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// file.

import ../traits;
comptime if !(_X86_ || _AMD64_) {
$if !(_X86_ || _AMD64_) {
import ../process;
}

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lib/std/src/sys/mod.c.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
Expand Down
4 changes: 2 additions & 2 deletions lib/std/src/sys/os.ri
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// file.

import ../traits;
comptime if !(_X86_ || _AMD64_) {
$if !(_X86_ || _AMD64_) {
import ../process;
}

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions rivetc/src/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "=":
Expand Down
6 changes: 3 additions & 3 deletions rivetc/src/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Loading

0 comments on commit 1edc63a

Please sign in to comment.