Skip to content

Commit

Permalink
feat: rename constants
Browse files Browse the repository at this point in the history
  • Loading branch information
nawetimebomb committed Oct 8, 2024
1 parent 61e3351 commit b74085e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
12 changes: 6 additions & 6 deletions compiler/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ func addAssembly(token Token) {
val = strconv.Itoa(g.value.(int))
}

case TOKEN_INT: val = strconv.Itoa(t.value.(int))
case TOKEN_CONSTANT_INT: val = strconv.Itoa(t.value.(int))
}

line = append(line, val)
Expand Down Expand Up @@ -559,20 +559,20 @@ func parseToken(token Token) {

switch token.typ {
// Constants
case TOKEN_CHAR:
case TOKEN_CONSTANT_CHAR:
code.op = OP_PUSH_CHAR
emit(code)
case TOKEN_FALSE:
case TOKEN_CONSTANT_FALSE:
code.op = OP_PUSH_BOOL
code.value = 0
emit(code)
case TOKEN_INT:
case TOKEN_CONSTANT_INT:
code.op = OP_PUSH_INT
emit(code)
case TOKEN_STR:
case TOKEN_CONSTANT_STR:
code.op = OP_PUSH_STR
emit(code)
case TOKEN_TRUE:
case TOKEN_CONSTANT_TRUE:
code.op = OP_PUSH_BOOL
code.value = 1
emit(code)
Expand Down
2 changes: 2 additions & 0 deletions compiler/ir.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ const (
DATA_CHAR
DATA_INFER
DATA_INT
DATA_INT_PTR
DATA_PTR
DATA_STR
)

type Program struct {
Expand Down
23 changes: 11 additions & 12 deletions compiler/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ import (
type TokenType int

const (
// Constants
TOKEN_CHAR TokenType = iota
TOKEN_FALSE
TOKEN_INT
TOKEN_PTR
TOKEN_STR
TOKEN_TRUE
// CONSTANTS
TOKEN_CONSTANT_CHAR TokenType = iota
TOKEN_CONSTANT_FALSE
TOKEN_CONSTANT_INT
TOKEN_CONSTANT_STR
TOKEN_CONSTANT_TRUE

// Types
TOKEN_DTYPE_ANY
Expand Down Expand Up @@ -119,7 +118,7 @@ var reservedWords = []reserved{
reserved{typ: TOKEN_CONST, word: "const" },
reserved{typ: TOKEN_ELSE, word: "else" },
reserved{typ: TOKEN_EQUAL, word: "=" },
reserved{typ: TOKEN_FALSE, word: "false" },
reserved{typ: TOKEN_CONSTANT_FALSE, word: "false" },
reserved{typ: TOKEN_FN, word: "fn" },
reserved{typ: TOKEN_GREATER, word: ">" },
reserved{typ: TOKEN_GREATER_EQUAL, word: ">=" },
Expand All @@ -134,7 +133,7 @@ var reservedWords = []reserved{
reserved{typ: TOKEN_SLASH, word: "/" },
reserved{typ: TOKEN_STAR, word: "*" },
reserved{typ: TOKEN_THIS, word: "this" },
reserved{typ: TOKEN_TRUE, word: "true" },
reserved{typ: TOKEN_CONSTANT_TRUE, word: "true" },
reserved{typ: TOKEN_USING, word: "using" },
reserved{typ: TOKEN_VAR, word: "var" },
}
Expand Down Expand Up @@ -213,7 +212,7 @@ func makeNumber(c byte, line string, index *int) {
}

value, _ := strconv.Atoi(result)
makeToken(TOKEN_INT, value)
makeToken(TOKEN_CONSTANT_INT, value)
}

func makeString(c byte, line string, index *int) {
Expand All @@ -231,7 +230,7 @@ func makeString(c byte, line string, index *int) {
}
}

makeToken(TOKEN_STR, result)
makeToken(TOKEN_CONSTANT_STR, result)
}

func makeChar(c byte, line string, index *int) {
Expand Down Expand Up @@ -264,7 +263,7 @@ func makeChar(c byte, line string, index *int) {
ExitWithError(CodeParseError)
}

makeToken(TOKEN_CHAR, result)
makeToken(TOKEN_CONSTANT_CHAR, result)
}

func makeWord(c byte, line string, index *int) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ func ValidateRun() {
case OP_FUNCTION_CALL:
var have []DataType
var want []DataType
var funcRef Function
var fns []Function
var funcRef Function

calls := code.value.([]FunctionCall)

Expand Down

0 comments on commit b74085e

Please sign in to comment.