Skip to content

Commit

Permalink
jule: data types are considered as built-in type aliases instead of k…
Browse files Browse the repository at this point in the history
…eywords
  • Loading branch information
mertcandav committed Jul 21, 2024
1 parent c4936ca commit c64df4a
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 112 deletions.
7 changes: 0 additions & 7 deletions std/jule/ast/node.jule
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,6 @@ struct IdentTypeDecl {
Generics: []&TypeDecl
}

impl IdentTypeDecl {
// Reports whether identifier is primitive type.
fn IsPrim(self): bool {
ret self.Token.Id == TokenId.Prim
}
}

// Sub-identifier type.
struct SubIdentTypeDecl {
Idents: []&IdentTypeDecl
Expand Down
16 changes: 0 additions & 16 deletions std/jule/lex/lex.jule
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,6 @@ struct kindPair {
}

static keywords: [...]kindPair = [
{TokenKind.I8, TokenId.Prim},
{TokenKind.I16, TokenId.Prim},
{TokenKind.I32, TokenId.Prim},
{TokenKind.I64, TokenId.Prim},
{TokenKind.U8, TokenId.Prim},
{TokenKind.U16, TokenId.Prim},
{TokenKind.U32, TokenId.Prim},
{TokenKind.U64, TokenId.Prim},
{TokenKind.F32, TokenId.Prim},
{TokenKind.F64, TokenId.Prim},
{TokenKind.Uint, TokenId.Prim},
{TokenKind.Int, TokenId.Prim},
{TokenKind.Uintptr, TokenId.Prim},
{TokenKind.Bool, TokenId.Prim},
{TokenKind.Str, TokenId.Prim},
{TokenKind.Any, TokenId.Prim},
{TokenKind.True, TokenId.Lit},
{TokenKind.False, TokenId.Lit},
{TokenKind.Nil, TokenId.Lit},
Expand Down
17 changes: 0 additions & 17 deletions std/jule/lex/token.jule
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ enum Ident: str {
// Token identities.
enum TokenId: uint {
Na,
Prim,
Ident,
Range,
Ret,
Expand Down Expand Up @@ -208,22 +207,6 @@ enum TokenKind: str {
LBrace: "{",
RBrace: "}",
Hash: "#",
I8: "i8",
I16: "i16",
I32: "i32",
I64: "i64",
U8: "u8",
U16: "u16",
U32: "u32",
U64: "u64",
F32: "f32",
F64: "f64",
Uint: "uint",
Int: "int",
Uintptr: "uintptr",
Bool: "bool",
Str: "str",
Any: "any",
True: "true",
False: "false",
Nil: "nil",
Expand Down
7 changes: 1 addition & 6 deletions std/jule/parser/expr.jule
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ impl exprBuilder {
| TokenId.Self
| TokenId.Error:
ret buildIdentExpr(token)
| TokenId.Prim:
ret self.buildPrimitiveType(token)
}
self.pushErr(token, LogMsg.InvalidSyntax)
ret nil
Expand Down Expand Up @@ -775,7 +773,7 @@ impl exprBuilder {
// Handle pointer to primitive type.
if len(tokens) > 1 && token.Kind == TokenKind.Star {
token = tokens[1]
if token.Id == TokenId.Prim || token.Id == TokenId.Unsafe {
if token.Id == TokenId.Unsafe {
ret self.buildType(tokens)
}
}
Expand Down Expand Up @@ -803,9 +801,6 @@ impl exprBuilder {
match token.Id {
| TokenId.Ident:
ret self.buildSubIdent(tokens)
| TokenId.Prim:
// Catch slice, and array types.
ret self.buildType(tokens)
| TokenId.Op:
ret self.buildOpRight(tokens)
| TokenId.Range:
Expand Down
8 changes: 0 additions & 8 deletions std/jule/parser/type.jule
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ impl typeBuilder {
}
}

unsafe fn buildPrim(mut self): &TypeDecl {
let mut t = buildPrimType(self.tokens[*self.i])
*self.i++
ret t
}

unsafe fn buildNamespace(mut self): &TypeDecl {
let mut t = &TypeDecl{
Token: self.tokens[*self.i],
Expand Down Expand Up @@ -384,8 +378,6 @@ impl typeBuilder {
unsafe fn step(mut self): &TypeDecl {
let token = self.tokens[*self.i]
match token.Id {
| TokenId.Prim:
ret self.buildPrim()
| TokenId.Ident:
ret self.buildIdent()
| TokenId.Cpp:
Expand Down
75 changes: 57 additions & 18 deletions std/jule/sema/builtin.jule
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,66 @@ fn findBuiltinFn(ident: str): &FnIns {
}
}

fn primTypeAlias(k: PrimKind): &TypeAlias {
ret &TypeAlias{
Public: true,
Kind: &TypeSymbol{
Kind: &TypeKind{
Kind: buildPrimType(k),
},
},
}
}

fn findBuiltinTypeAlias(ident: str): &TypeAlias {
match ident {
| "byte":
static mut t = &TypeAlias{
Public: true,
Kind: &TypeSymbol{
Kind: &TypeKind{
Kind: buildPrimType(PrimKind.U8),
},
},
}
| "any":
static mut t = primTypeAlias(PrimKind.Any)
ret t
| "rune":
static mut t = &TypeAlias{
Public: true,
Kind: &TypeSymbol{
Kind: &TypeKind{
Kind: buildPrimType(PrimKind.I32),
},
},
}
| "str":
static mut t = primTypeAlias(PrimKind.Str)
ret t
| "bool":
static mut t = primTypeAlias(PrimKind.Bool)
ret t
| "uintptr":
static mut t = primTypeAlias(PrimKind.Uintptr)
ret t
| "uint":
static mut t = primTypeAlias(PrimKind.Uint)
ret t
| "int":
static mut t = primTypeAlias(PrimKind.Int)
ret t
| "i8":
static mut t = primTypeAlias(PrimKind.I8)
ret t
| "i16":
static mut t = primTypeAlias(PrimKind.I16)
ret t
| "i64":
static mut t = primTypeAlias(PrimKind.I64)
ret t
| "u16":
static mut t = primTypeAlias(PrimKind.U16)
ret t
| "u32":
static mut t = primTypeAlias(PrimKind.U32)
ret t
| "u64":
static mut t = primTypeAlias(PrimKind.U64)
ret t
| "f32":
static mut t = primTypeAlias(PrimKind.F32)
ret t
| "f64":
static mut t = primTypeAlias(PrimKind.F64)
ret t
| "byte" | "u8":
static mut t = primTypeAlias(PrimKind.U8)
ret t
| "rune" | "i32":
static mut t = primTypeAlias(PrimKind.I32)
ret t
|:
ret nil
Expand Down
41 changes: 1 addition & 40 deletions std/jule/sema/type.jule
Original file line number Diff line number Diff line change
Expand Up @@ -834,20 +834,6 @@ impl typeChecker {
self.disBuiltin = true
}

fn buildPrim(mut self, &decl: &IdentTypeDecl): &Prim {
if !isPrim(decl.Ident) {
self.pushErr(self.errorToken, LogMsg.InvalidType)
ret nil
}

if len(decl.Generics) > 0 {
self.pushErr(decl.Token, LogMsg.TypeNotSupportsGenerics, decl.Ident)
ret nil
}

ret buildPrimType(decl.Ident)
}

fn pushReference[T](mut self, mut &t: T) {
if self.refers == nil {
ret
Expand Down Expand Up @@ -1284,12 +1270,7 @@ impl typeChecker {
}

fn buildIdent(mut self, mut decl: &IdentTypeDecl): Kind {
match {
| isPrim(decl.Ident):
ret self.buildPrim(decl)
|:
ret self.getDef(decl)
}
ret self.getDef(decl)
}

fn buildSubIdent(mut self, mut decl: &SubIdentTypeDecl): Kind {
Expand Down Expand Up @@ -1824,26 +1805,6 @@ fn getStructFromKind(mut k: &TypeKind): &Struct {
}
}

// Reports whether kind is primitive type.
fn isPrim(kind: str): bool {
ret kind == TokenKind.I8 ||
kind == TokenKind.I16 ||
kind == TokenKind.I32 ||
kind == TokenKind.I64 ||
kind == TokenKind.U8 ||
kind == TokenKind.U16 ||
kind == TokenKind.U32 ||
kind == TokenKind.U64 ||
kind == TokenKind.F32 ||
kind == TokenKind.F64 ||
kind == TokenKind.Int ||
kind == TokenKind.Uint ||
kind == TokenKind.Uintptr ||
kind == TokenKind.Bool ||
kind == TokenKind.Str ||
kind == TokenKind.Any
}

fn applyImplicitCast(mut &dest: &TypeKind, mut &d: &Data) {
if d.Kind.IsNil() {
ret
Expand Down

0 comments on commit c64df4a

Please sign in to comment.