Skip to content

Commit

Permalink
feat: rename types
Browse files Browse the repository at this point in the history
  • Loading branch information
nawetimebomb committed Oct 8, 2024
1 parent b74085e commit 050f12d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
36 changes: 18 additions & 18 deletions compiler/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,16 +347,16 @@ func newVariable(token Token, offset int) (Variable, int) {
vt := parser.previous

switch vt.typ {
case TOKEN_DTYPE_BOOL:
case TOKEN_BOOL:
newVar.dtype = DATA_BOOL
newOffset += SIZE_64b
case TOKEN_DTYPE_INT:
case TOKEN_INT:
newVar.dtype = DATA_INT
newOffset += SIZE_64b
case TOKEN_DTYPE_PTR:
case TOKEN_PTR:
newVar.dtype = DATA_PTR
newOffset += SIZE_64b
case TOKEN_DTYPE_CHAR:
case TOKEN_CHAR:
newVar.dtype = DATA_CHAR
newOffset += SIZE_8b
default:
Expand Down Expand Up @@ -595,19 +595,19 @@ func parseToken(token Token) {
}

// TYPE CASTING
case TOKEN_DTYPE_BOOL:
case TOKEN_BOOL:
code.op = OP_CAST
code.value = DATA_BOOL
emit(code)
case TOKEN_DTYPE_CHAR:
case TOKEN_CHAR:
code.op = OP_CAST
code.value = DATA_CHAR
emit(code)
case TOKEN_DTYPE_INT:
case TOKEN_INT:
code.op = OP_CAST
code.value = DATA_INT
emit(code)
case TOKEN_DTYPE_PTR:
case TOKEN_PTR:
code.op = OP_CAST
code.value = DATA_PTR
emit(code)
Expand Down Expand Up @@ -813,13 +813,13 @@ func parseArityInAssembly(token Token, args *Arity) {
var newArg Argument

switch token.typ {
case TOKEN_DTYPE_BOOL:
case TOKEN_BOOL:
newArg.typ = DATA_BOOL
case TOKEN_DTYPE_CHAR:
case TOKEN_CHAR:
newArg.typ = DATA_CHAR
case TOKEN_DTYPE_INT:
case TOKEN_INT:
newArg.typ = DATA_INT
case TOKEN_DTYPE_PTR:
case TOKEN_PTR:
newArg.typ = DATA_PTR
default:
msg := fmt.Sprintf(MsgParseTypeUnknown, token.value.(string))
Expand All @@ -834,22 +834,22 @@ func parseArityInFunction(token Token, function *Function, parsingArguments bool
var newArg Argument

switch token.typ {
case TOKEN_DTYPE_ANY:
case TOKEN_ANY:
if !parser.internal {
errorAt(&token, MsgParseArityArgumentAnyOnlyInternal)
ExitWithError(CodeParseError)
}

newArg.typ = DATA_ANY
case TOKEN_DTYPE_BOOL:
case TOKEN_BOOL:
newArg.typ = DATA_BOOL
case TOKEN_DTYPE_CHAR:
case TOKEN_CHAR:
newArg.typ = DATA_CHAR
case TOKEN_DTYPE_INT:
case TOKEN_INT:
newArg.typ = DATA_INT
case TOKEN_DTYPE_PTR:
case TOKEN_PTR:
newArg.typ = DATA_PTR
case TOKEN_DTYPE_PARAPOLY:
case TOKEN_PARAPOLY:
if !parsingArguments {
errorAt(&token, MsgParseArityReturnParapolyNotAllowed)
ExitWithError(CodeParseError)
Expand Down
27 changes: 14 additions & 13 deletions compiler/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ const (
TOKEN_CONSTANT_TRUE

// Types
TOKEN_DTYPE_ANY
TOKEN_DTYPE_BOOL
TOKEN_DTYPE_CHAR
TOKEN_DTYPE_INT
TOKEN_DTYPE_PARAPOLY
TOKEN_DTYPE_PTR
TOKEN_ANY
TOKEN_BOOL
TOKEN_CHAR
TOKEN_INT
TOKEN_PARAPOLY
TOKEN_PTR

// Flow Control
TOKEN_CASE
Expand Down Expand Up @@ -88,18 +88,19 @@ type reserved struct {
}

var reservedWords = []reserved{
// DATA TYPES
reserved{typ: TOKEN_ANY, word: "any" },
reserved{typ: TOKEN_BOOL, word: "bool" },
reserved{typ: TOKEN_CHAR, word: "char" },
reserved{typ: TOKEN_INT, word: "int" },
reserved{typ: TOKEN_PTR, word: "ptr" },

reserved{typ: TOKEN_DASH_DASH_DASH, word: "---" },
reserved{typ: TOKEN_LET, word: "let" },
reserved{typ: TOKEN_LETSTAR, word: "let*" },
reserved{typ: TOKEN_IN, word: "in" },
reserved{typ: TOKEN_DONE, word: "done" },

reserved{typ: TOKEN_DTYPE_ANY, word: "any" },
reserved{typ: TOKEN_DTYPE_BOOL, word: "bool" },
reserved{typ: TOKEN_DTYPE_CHAR, word: "char" },
reserved{typ: TOKEN_DTYPE_INT, word: "int" },
reserved{typ: TOKEN_DTYPE_PTR, word: "ptr" },

reserved{typ: TOKEN_BANG, word: "!" },
reserved{typ: TOKEN_AT, word: "@" },
reserved{typ: TOKEN_C_BANG, word: "c!" },
Expand Down Expand Up @@ -295,7 +296,7 @@ func makeParapolyToken(c byte, line string, index *int) {
word += string(c)
}

makeToken(TOKEN_DTYPE_PARAPOLY, word)
makeToken(TOKEN_PARAPOLY, word)
}

func TokenizeFile(f string, s string) []Token {
Expand Down

0 comments on commit 050f12d

Please sign in to comment.