Skip to content

Commit

Permalink
all: rename float to number
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS committed Jul 2, 2024
1 parent 563bba3 commit 21a925a
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 20 deletions.
4 changes: 2 additions & 2 deletions bsc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ def __init__(self):

self.universe.add_sym(
TypeSym(
AccessModifier.private, TypeKind.float, "float", [], Scope()
AccessModifier.private, TypeKind.number, "number", [], Scope()
)
)
self.float_type = BasicType.with_typesym(self.universe.syms[6])
self.number_type = BasicType.with_typesym(self.universe.syms[6])

self.universe.add_sym(
TypeSym(
Expand Down
4 changes: 2 additions & 2 deletions bsc/astgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,8 @@ def user_type(self, *names):
return self.ctx.bool_type
case "int":
return self.ctx.int_type
case "float":
return self.ctx.float_type
case "number":
return self.ctx.number_type
case "string":
return self.ctx.string_type
case _:
Expand Down
4 changes: 2 additions & 2 deletions bsc/lua_ast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ def __init__(self, value):
self.value = value

class LuaNumberLit:
def __init__(self, value, is_float = False):
def __init__(self, value, is_number = False):
self.value = value
self.is_float = is_float
self.is_number = is_number

class LuaBooleanLit:
def __init__(self, value):
Expand Down
10 changes: 3 additions & 7 deletions bsc/sema.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,7 @@ def check_expr(self, expr):
elif isinstance(expr, BoolLiteral):
expr.typ = self.ctx.bool_type
elif isinstance(expr, NumberLiteral):
if any(ch in expr.value for ch in [".", "e", "E"]
) and expr.value[:2].lower() not in ['0x', '0o', '0b']:
expr.typ = self.ctx.float_type
else:
expr.typ = self.ctx.int_type
expr.typ = self.ctx.number_type
elif isinstance(expr, StringLiteral):
expr.typ = self.ctx.string_type
elif isinstance(expr, Ident):
Expand All @@ -232,11 +228,11 @@ def check_expr(self, expr):
["operator `!` is only defined for type `bool`"]
)
case UnaryOp.minus:
if right_t not in (self.ctx.int_type, self.ctx.float_type):
if right_t not in (self.ctx.int_type, self.ctx.number_type):
report.error(
f"operator `-` is not defined for type `{right_t}`",
expr.pos, [
"operator `-` is only defined for `int` and `float` types"
"operator `-` is only defined for `int` and `number` types"
]
)
case UnaryOp.bit_not:
Expand Down
6 changes: 3 additions & 3 deletions bsc/sym.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class TypeKind(IntEnum):
any = auto()
bool = auto()
int = auto()
float = auto()
number = auto()
string = auto()
array = auto()
map = auto()
Expand All @@ -128,8 +128,8 @@ def __str__(self):
return "bool"
case TypeKind.int:
return "int"
case TypeKind.float:
return "float"
case TypeKind.number:
return "number"
case TypeKind.string:
return "string"
case TypeKind.array:
Expand Down
4 changes: 2 additions & 2 deletions tests/invalid_code/unary_expr.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
tests/invalid_code/unary_expr.bs:2:10: error: operator `~` is not defined for type `float`
tests/invalid_code/unary_expr.bs:2:10: error: operator `~` is not defined for type `number`
└ note: operator `~` is only defined for type `int`
tests/invalid_code/unary_expr.bs:3:10: error: operator `!` is not defined for type `int`
└ note: operator `!` is only defined for type `bool`
tests/invalid_code/unary_expr.bs:4:10: error: operator `-` is not defined for type `string`
└ note: operator `-` is only defined for `int` and `float` types
└ note: operator `-` is only defined for `int` and `number` types
2 changes: 1 addition & 1 deletion tests/main.bs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const dec_num = 616;
const hex_num = 0xFFFF;
const bin_num = 0b10101;
const octal_num = 0o666;
const float_num = 0.5e4;
const number_num = 0.5e4;

fn main() void {
print("hello");
Expand Down
2 changes: 1 addition & 1 deletion tests/syntax.bs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fn add_int(a: int) int {
return a + a;
}

fn add_float(a: float) float {
fn add_number(a: number) number {
return a + a;
}

0 comments on commit 21a925a

Please sign in to comment.