Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS committed Dec 25, 2023
1 parent 3d373a4 commit 91797b4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
8 changes: 5 additions & 3 deletions lib/rivet/src/parser/decls.ri
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ extend Parser {

func parse_decl(mut self) -> ast.Decl {
doc_comment := self.parse_doc_comments();
attributes := self.parse_attributes(
self.tok.kind == .Hash && self.peek_tok.kind == .Bang
);
is_mod_attr := self.tok.kind == .Hash && self.peek_tok.kind == .Bang;
attributes := self.parse_attributes(is_mod_attr);
if is_mod_attr {
return .Empty();
}
is_public := self.is_public();
mut pos := self.tok.pos;
match {
Expand Down
3 changes: 1 addition & 2 deletions lib/std/src/dynlib/mod.c.ri
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ pub func load(path: string, global_symbols: bool := false) -> !Library {
}
if dl_error := dlerror() {
throw CannotLoadLibraryError("cannot load '{}': {}".fmt(path, dl_error));
} else {
throw CannotLoadLibraryError("cannot load '{}'".fmt(path));
}
throw CannotLoadLibraryError("cannot load '{}'".fmt(path));
}

#[boxed]
Expand Down
8 changes: 4 additions & 4 deletions rivetc/src/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __str__(self):
# ---- Declarations ----
class EmptyDecl:
def __init__(self):
self.attributes = Annotations()
self.attributes = Attributes()

class DocComment:
def __init__(self, lines, pos):
Expand All @@ -95,13 +95,13 @@ def merge(self):
res += " "
return res

class AnnotationArg:
class AttributeArg:
def __init__(self, name, expr):
self.name = name
self.expr = expr
self.is_named = name != ""

class Annotation:
class Attribute:
def __init__(self, name, args, pos):
self.name = name
self.args = args
Expand All @@ -113,7 +113,7 @@ def find_arg(self, name):
return arg
return None

class Annotations:
class Attributes:
def __init__(self):
self.attributes = []

Expand Down
16 changes: 8 additions & 8 deletions rivetc/src/codegen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ def gen_source_files(self, source_files):

# generate 'init_string_lits_fn' function
self.init_string_lits_fn = ir.FuncDecl(
False, ast.Annotations(), False, "_R4core16init_string_litsF", [],
False, ast.Attributes(), False, "_R4core16init_string_litsF", [],
False, ir.VOID_T, False
)
self.out_rir.decls.append(self.init_string_lits_fn)

# generate '_R4core12init_globalsF' function
self.init_global_vars_fn = ir.FuncDecl(
False, ast.Annotations(), False, "_R4core12init_globalsF", [],
False, ast.Attributes(), False, "_R4core12init_globalsF", [],
False, ir.VOID_T, False
)
self.out_rir.decls.append(self.init_global_vars_fn)

# generate '_R12drop_globalsZ' function
g_fn = ir.FuncDecl(
False, ast.Annotations(), False, "_R4core12drop_globalsF", [],
False, ast.Attributes(), False, "_R4core12drop_globalsF", [],
False, ir.VOID_T, False
)
self.out_rir.decls.append(g_fn)
Expand All @@ -88,7 +88,7 @@ def gen_source_files(self, source_files):
argc = ir.Ident(ir.C_INT_T, "_argc")
argv = ir.Ident(ir.CHAR_T.ptr().ptr(), "_argv")
main_fn = ir.FuncDecl(
False, ast.Annotations(), False, "main", [argc, argv], False,
False, ast.Attributes(), False, "main", [argc, argv], False,
ir.C_INT_T, False
)
if self.comp.prefs.build_mode == prefs.BuildMode.Test:
Expand Down Expand Up @@ -375,7 +375,7 @@ def gen_decl(self, decl):
test_func = f"__test{len(self.generated_tests)}__"
test_func = f"_R{len(test_func)}{test_func}"
test_fn = ir.FuncDecl(
False, ast.Annotations(), False, test_func,
False, ast.Attributes(), False, test_func,
[ir.Ident(ir.TEST_T.ptr(), "test")], False, ir.VOID_T, False
)
self.cur_func = test_fn
Expand Down Expand Up @@ -1907,7 +1907,7 @@ def gen_expr(self, expr, custom_tmp = None):
self.ir_type(expr_left_typ), "_elem_"
)
contains_decl = ir.FuncDecl(
False, ast.Annotations(), False, full_name,
False, ast.Attributes(), False, full_name,
[self_idx_, elem_idx_], False, ir.BOOL_T, False
)
else:
Expand All @@ -1918,7 +1918,7 @@ def gen_expr(self, expr, custom_tmp = None):
self.ir_type(expr_left_typ), "_elem_"
)
contains_decl = ir.FuncDecl(
False, ast.Annotations(), False, full_name, [
False, ast.Attributes(), False, full_name, [
self_idx_,
ir.Ident(ir.UINT_T, "_len_"), elem_idx_
], False, ir.BOOL_T, False
Expand Down Expand Up @@ -3112,7 +3112,7 @@ def gen_types(self):
)
)
index_of_vtbl_fn = ir.FuncDecl(
False, ast.Annotations(), False,
False, ast.Attributes(), False,
cg_utils.mangle_symbol(ts) + "17__index_of_vtbl__",
[ir.Ident(ir.UINT_T, "self")], False, ir.UINT_T, False
)
Expand Down
23 changes: 12 additions & 11 deletions rivetc/src/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ def parse_doc_comment(self):

def parse_attributes(self, parse_mod_attributes = False):
if parse_mod_attributes and self.mod_sym.attributes == None:
self.mod_sym.attributes = ast.Annotations()
attributes = ast.Annotations()
self.mod_sym.attributes = ast.Attributes()
attributes = ast.Attributes()
while self.accept(Kind.Hash):
if parse_mod_attributes:
self.expect(Kind.Bang)
Expand All @@ -173,11 +173,11 @@ def parse_attributes(self, parse_mod_attributes = False):
else:
name = ""
expr = self.parse_expr()
args.append(ast.AnnotationArg(name, expr))
args.append(ast.AttributeArg(name, expr))
if not self.accept(Kind.Comma):
break
self.expect(Kind.Rparen)
attribute = ast.Annotation(attribute_name, args, pos)
attribute = ast.Attribute(attribute_name, args, pos)
if parse_mod_attributes:
self.mod_sym.attributes.add(attribute)
else:
Expand Down Expand Up @@ -208,19 +208,20 @@ def parse_decls(self):
return decls

def parse_decl(self):
doc_comment = self.parse_doc_comment()
attributes = self.parse_attributes(
self.tok.kind == Kind.Hash and self.peek_tok.kind == Kind.Bang
)
is_public = self.is_public()
pos = self.tok.pos
if self.accept(Kind.KwComptime):
if self.tok.kind == Kind.KwIf:
return self.parse_comptime_if(0)
else:
report.error("invalid comptime construction", self.tok.pos)
return
elif self.accept(Kind.KwImport):
doc_comment = self.parse_doc_comment()
is_mod_attr = self.tok.kind == Kind.Hash and self.peek_tok.kind == Kind.Bang
attributes = self.parse_attributes(is_mod_attr)
if is_mod_attr:
return ast.EmptyDecl()
is_public = self.is_public()
pos = self.tok.pos
if self.accept(Kind.KwImport):
path = self.parse_import_path()
alias = ""
import_list = []
Expand Down

0 comments on commit 91797b4

Please sign in to comment.