Skip to content

Commit

Permalink
refact(rivetc+rivet): use := for for fields with default values
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS committed Nov 5, 2023
1 parent a1315bf commit ba53efe
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions lib/rivet/src/ast/Expr.ri
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public enum Expr < traits.Stringable {
mut is_sym: bool;
mut found: bool;
mut sym: Sym;
mut builtin: Builtin = .Invalid();
mut builtin: Builtin := .Invalid();
pos: token.Pos;
mut type: Type;
},
Expand Down Expand Up @@ -207,7 +207,7 @@ public enum Expr < traits.Stringable {
args: []CallArg;
vec_is_mut: bool;
pos: token.Pos;
mut builtin: Builtin = .Invalid();
mut builtin: Builtin := .Invalid();
mut type: Type;
},
Unary {
Expand Down
2 changes: 1 addition & 1 deletion lib/rivet/src/ast/Sym.ri
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public enum ABI as uint8 < traits.Stringable {

#[default_value(InvalidSym())]
public trait Sym {
id: usize = new_sym_id();
id: usize := new_sym_id();
abi: ABI;
mut is_public: bool;
mut parent: ?Sym;
Expand Down
2 changes: 1 addition & 1 deletion lib/rivet/src/ast/TypeSym.ri
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public struct Field {
public struct TypeSym < Sym {
public mut fields: []Field;
public mut full_fields_: []Field;
public mut info: TypeInfo = .Invalid();
public mut info: TypeInfo := .Invalid();
public mut size: usize;
public mut align: usize;
public mut default_value: ?Expr;
Expand Down
2 changes: 1 addition & 1 deletion lib/rivet/src/checker/mod.ri
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public struct Checker {
mut prefs: prefs.Prefs;

mut source_file: ast.SourceFile;
mut sym: ast.Sym = ast.InvalidSym();
mut sym: ast.Sym := ast.InvalidSym();
mut cur_fn: ast.Func;

mut inside_extern: bool;
Expand Down
2 changes: 1 addition & 1 deletion lib/rivet/src/codegen/mir/Block.ri
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public enum Stmt < traits.Stringable {
},
Return {
has_expr: bool;
expr: Expr = .Empty();
expr: Expr := .Empty();
};

public func to_string(self) -> string {
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 @@ -425,7 +425,7 @@ extend Parser {
name := self.parse_name();
self.expect(.Colon);
type := self.parse_type();
has_def_expr := self.accept(.Assign);
has_def_expr := self.accept(.DeclAssign);
def_expr := if has_def_expr {
self.parse_expr()
} else {
Expand Down
14 changes: 7 additions & 7 deletions lib/rivet/src/prefs/mod.ri
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public enum LinkMode as uint8 {
#[boxed]
public struct Prefs {
// Target info
public mut target_os: sys.OS = sys.os();
public mut target_arch: sys.Arch = sys.arch();
public mut target_is_64bit: bool = sys.is_64bit();
public mut target_is_little_endian: bool = sys.is_little_endian();
public mut target_c_runtime: sys.CRuntime = sys.c_runtime();
public mut target_os: sys.OS := sys.os();
public mut target_arch: sys.Arch := sys.arch();
public mut target_is_64bit: bool := sys.is_64bit();
public mut target_is_little_endian: bool := sys.is_little_endian();
public mut target_c_runtime: sys.CRuntime := sys.c_runtime();
public mut target_backend: Backend;
public mut target_backend_compiler: string = "cc";
public mut target_backend_compiler: string := "cc";

// Module info
public mut input: string;
Expand All @@ -66,7 +66,7 @@ public struct Prefs {
public mut run_output: bool;
public mut run_output_args: []string;

public mut library_path: []string = [rivetcLibDir, libDir];
public mut library_path: []string := [rivetcLibDir, libDir];
public mut libraries_to_link: []string;
public mut objects_to_link: []string;

Expand Down
2 changes: 1 addition & 1 deletion lib/rivet/src/report/mod.ri
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public func warn_builder(msg: string, pos: token.Pos) -> ReportBuilder {
public struct ReportBuilder {
mut kind: ReportKind;
msg: string;
pos: token.Pos = token.noPos;
pos: token.Pos := token.noPos;
mut attributes: []Attribute;

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion lib/rivet/src/resolver/Register.ri
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public struct Register {
mut is_core_mod: bool;

mut abi: ast.ABI;
mut sym: ast.Sym = ast.InvalidSym();
mut sym: ast.Sym := ast.InvalidSym();
mut source_file: ast.SourceFile;

public func walk_files(mut self, source_files: []ast.SourceFile) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rivet/src/resolver/mod.ri
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public struct Resolver {
mut table: ast.Table;
mut prefs: prefs.Prefs;

mut sym: ast.Sym = ast.InvalidSym();
mut sym: ast.Sym := ast.InvalidSym();
mut self_sym: ast.TypeSym;
mut preludes: []Prelude;

Expand Down
2 changes: 1 addition & 1 deletion lib/rivet/src/tokenizer/mod.ri
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const NUM_SEP := b'_';
public struct Tokenizer {
table: ast.Table;
prefs: prefs.Prefs;
file: string = "<internal-memory>";
file: string := "<internal-memory>";
text: string;
mut pos: usize;
mut line: usize;
Expand Down
4 changes: 2 additions & 2 deletions lib/std/src/flag/mod.ri
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public struct FlagParser {
/// $ <appname> <usage_examples[1]>
/// $ ...
public mut usage_examples: []string;
public mut default_help_label: string = "Display this help and exit.";
public mut default_version_label: string = "Show version information and exit.";
public mut default_help_label: string := "Display this help and exit.";
public mut default_version_label: string := "Show version information and exit.";
public mut flags: []Flag;
/// The current list of processed args.
public mut args: []string;
Expand Down
2 changes: 1 addition & 1 deletion rivetc/src/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def parse_field_decl(self, attributes, doc_comment, is_public):
name = self.parse_name()
self.expect(Kind.Colon)
typ = self.parse_type()
has_def_expr = self.accept(Kind.Assign)
has_def_expr = self.accept(Kind.DeclAssign)
def_expr = None
if has_def_expr:
def_expr = self.parse_expr()
Expand Down
2 changes: 1 addition & 1 deletion tests/valid/src/embedded_structs.ri
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
struct D {
m: uint8 = 155;
m: uint8 := 155;
}

struct E < D {
Expand Down

0 comments on commit ba53efe

Please sign in to comment.