Skip to content

Commit

Permalink
feat: allow addition of char types
Browse files Browse the repository at this point in the history
  • Loading branch information
nawetimebomb committed Oct 8, 2024
1 parent 6390167 commit 61e3351
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
8 changes: 4 additions & 4 deletions compiler/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,6 @@ func parseToken(token Token) {
code.value = v.value
emit(code)
}
case TOKEN_VAR:
newVar, newOffset := newVariable(token, frontend.current.localMemorySize)
frontend.current.variables = append(frontend.current.variables, newVar)
frontend.current.localMemorySize = newOffset

// TYPE CASTING
case TOKEN_DTYPE_BOOL:
Expand All @@ -619,6 +615,10 @@ func parseToken(token Token) {
// Definition
case TOKEN_CONST:
registerConstant(token)
case TOKEN_VAR:
newVar, newOffset := newVariable(token, frontend.current.localMemorySize)
frontend.current.variables = append(frontend.current.variables, newVar)
frontend.current.localMemorySize = newOffset

// Intrinsics
case TOKEN_ARGC:
Expand Down
2 changes: 2 additions & 0 deletions compiler/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ func ValidateRun() {
assertArgumentType(dtArray(a, b), dtArray(DATA_ANY, DATA_INT), code, loc)
if a == DATA_INT && b == DATA_INT {
tc.push(DATA_INT)
} else if a == DATA_CHAR || b == DATA_CHAR {
tc.push(DATA_CHAR)
} else {
tc.push(DATA_PTR)
}
Expand Down
6 changes: 3 additions & 3 deletions libs/strings.sk
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ fn itoa (int ptr)
const BUFFER_CAP 20
var buffer ptr &buffer !
var number int &number !
"00000000000000000000" buffer !
"--------------------" buffer !
buffer @ ptr &buffer !
48 buffer !

number 0 != if
0 BUFFER_CAP <= until
0 buffer I + c!
0 buffer I + c!
I -- loop

0 number len 1 - <= until
'0' number 10 % + char buffer I + c!
'0' number 10 % + buffer I + c!
number 10 / &number !
I -- loop
fi
Expand Down

0 comments on commit 61e3351

Please sign in to comment.