diff --git a/examples/a.whirl b/examples/a.whirl index 183fb6f..2200cfe 100644 --- a/examples/a.whirl +++ b/examples/a.whirl @@ -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; } diff --git a/examples/b.whirl b/examples/b.whirl index caec329..3b30e53 100644 --- a/examples/b.whirl +++ b/examples/b.whirl @@ -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 { diff --git a/pkg/codegen/c.go b/pkg/codegen/c.go index ac911f3..6b46ce0 100644 --- a/pkg/codegen/c.go +++ b/pkg/codegen/c.go @@ -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 { diff --git a/pkg/lexer/lexer.go b/pkg/lexer/lexer.go index 05658c2..ef5d3f1 100644 --- a/pkg/lexer/lexer.go +++ b/pkg/lexer/lexer.go @@ -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 diff --git a/pkg/lexer/lexer_test.go b/pkg/lexer/lexer_test.go index 3bf0839..87e6a67 100644 --- a/pkg/lexer/lexer_test.go +++ b/pkg/lexer/lexer_test.go @@ -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())