Skip to content

Commit

Permalink
feat: add booleans into expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
vasiltop committed Jan 11, 2024
1 parent 6f3a754 commit 21f8594
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
6 changes: 4 additions & 2 deletions examples/a.whirl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import "./b.whirl";
proc main() :: int {
b::hello();
b::sum(1, 2);
let a: bool = false;
$printf("%d", true);

let c: bool = false;
printf("%d", c);

escape 0;
}
2 changes: 1 addition & 1 deletion examples/b.whirl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ proc hello() :: void {
}

proc sum(a: int, b: int) :: int {
printf("%d + %d = %d", a, b, a + b);
printf("%d + %d = %d\n", a, b, a + b);
}

proc s() :: string {
Expand Down
6 changes: 3 additions & 3 deletions pkg/codegen/c.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ func (i Int) CValue(ctx Context) string {
}

func (b Bool) CType(ctx Context) string {
return "bool"
return "int"
}

func (b Bool) CValue(ctx Context) string {
if b.Value {
return "true"
return "1"
}

return "false"
return "0"
}

func (c Char) CType(ctx Context) string {
Expand Down
4 changes: 2 additions & 2 deletions pkg/lexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ func (iter *TokenIterator) Next() (Token, error) {

//Check for booleans
if iter.FoundToken([]byte("false"), true) {
return Token{BOOLEAN_LIT, "false"}, nil
return Token{BOOLEAN_LIT, "0"}, nil
}

if iter.FoundToken([]byte("true"), true) {
return Token{BOOLEAN_LIT, "true"}, nil
return Token{BOOLEAN_LIT, "1"}, nil
}

//Check for strings
Expand Down
2 changes: 1 addition & 1 deletion pkg/lexer/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestLexerEmptyMain(t *testing.T) {
}

func TestLexerVariables(t *testing.T) {
err := CheckForErrorsInIterator([]byte("proc main() :: int { let a: int = 5; escape 0; }"))
err := CheckForErrorsInIterator([]byte("proc main() :: int { let a: int = 5; let b: bool = true; escape 0; }"))

if err != nil {
t.Fatalf(err.Error())
Expand Down

0 comments on commit 21f8594

Please sign in to comment.