From b74085e811654ba3a055098e84d9933cc04854e4 Mon Sep 17 00:00:00 2001 From: "Nahuel J. Sacchetti" Date: Tue, 8 Oct 2024 13:07:54 -0500 Subject: [PATCH] feat: rename constants --- compiler/frontend.go | 12 ++++++------ compiler/ir.go | 2 ++ compiler/scanner.go | 23 +++++++++++------------ compiler/validate.go | 2 +- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/compiler/frontend.go b/compiler/frontend.go index 1bb22c4..a656e6d 100644 --- a/compiler/frontend.go +++ b/compiler/frontend.go @@ -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) @@ -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) diff --git a/compiler/ir.go b/compiler/ir.go index 26657b3..628418d 100644 --- a/compiler/ir.go +++ b/compiler/ir.go @@ -66,7 +66,9 @@ const ( DATA_CHAR DATA_INFER DATA_INT + DATA_INT_PTR DATA_PTR + DATA_STR ) type Program struct { diff --git a/compiler/scanner.go b/compiler/scanner.go index 3f535a6..5b868e3 100644 --- a/compiler/scanner.go +++ b/compiler/scanner.go @@ -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 @@ -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: ">=" }, @@ -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" }, } @@ -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) { @@ -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) { @@ -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) { diff --git a/compiler/validate.go b/compiler/validate.go index 5893bfb..e0b6f97 100644 --- a/compiler/validate.go +++ b/compiler/validate.go @@ -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)