Compiladores

Delta: An Incremental Compiler
Step 2: Boolean Literals

Description

Add support for the boolean literals true and false. In the WAT code, true should be converted to 1 and false should be converted to 0.

Example

The Delta program:

true

should produce the following WAT code:

(module
  (func
    (export "_start")
    (result i32)
    i32.const 1
  )
)

The above WAT function’s return value should be:

1

Unit Tests

# File: tests/test_02_boolean.py 

from unittest import TestCase
from delta import Compiler, SyntaxMistake


class TestBoolean(TestCase):

    def setUp(self):
        self.c = Compiler('program')

    def test_syntax_mistake(self):
        with self.assertRaises(SyntaxMistake):
            self.c.realize('true.')

    def test_true(self):
        self.assertEqual(1,
                         self.c.realize('true'))

    def test_false(self):
        self.assertEqual(0,
                         self.c.realize('false'))