Skip to content

Commit 404c5f4

Browse files
committed
cleanup
1 parent 0d894d6 commit 404c5f4

7 files changed

Lines changed: 112 additions & 52 deletions

File tree

Justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test-compiler:
1313
uv run python test.py
1414

1515
one NAME:
16-
python3 easy.py tests/{{NAME}}/test.easy && cc tests/{{NAME}}/test.c -o tests/{{NAME}}/test.exe -I . && ./tests/{{NAME}}/test.exe
16+
python3 easy.py tests/{{NAME}}/test.easy && cc -std=c23 tests/{{NAME}}/test.c -o tests/{{NAME}}/test.exe -I . && ./tests/{{NAME}}/test.exe
1717

1818
life:
1919
python easy.py life.easy && clang life.c -o life && ./life

easy.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,12 @@ def c(self) -> str:
938938
_, reference = expand_variable_reference(variable, self)
939939
return reference
940940

941+
@property
942+
def type(self) -> Type:
943+
variable = discover_variable(self)
944+
type, _ = expand_variable_reference(variable, self)
945+
return type
946+
941947

942948
@dataclass
943949
class Variable(Entity):
@@ -965,7 +971,9 @@ def s(self, scope: str) -> list[str]:
965971

966972
@dataclass
967973
class BuiltinLiteral(Expression):
968-
pass
974+
975+
def format(self) -> str:
976+
raise NotImplementedError(f"format() not implemented for {self.__class__.__name__} at {self.token}")
969977

970978

971979
@dataclass
@@ -1578,15 +1586,15 @@ def expression_ADDING(self) -> Expression:
15781586
operations = ("+", "-")
15791587
while operation := self.accept(operations):
15801588
right = self.expression_MULTIPLYING()
1581-
left = BinaryOperation(operation, self.scope(), type, operation.value, left, right)
1589+
left = BinaryOperation(operation, self.scope(), left.type, operation.value, left, right)
15821590
return left
15831591

15841592
def expression_MULTIPLYING(self) -> Expression:
15851593
token = self.current()
15861594
left = self.expression_FUNCTION_CALL()
15871595
while operation := self.accept(("*", "/", "MOD")):
15881596
right = self.expression_FUNCTION_CALL()
1589-
left = BinaryOperation(token, self.scope(), type, operation.value, left, right)
1597+
left = BinaryOperation(token, self.scope(), left.type, operation.value, left, right)
15901598
return left
15911599

15921600
def expression_FUNCTION_CALL(self) -> Expression | FunctionCall:
@@ -1611,10 +1619,10 @@ def factor(
16111619
token = self.current()
16121620
if token.type == "INTEGER":
16131621
token = self.eat(token.type)
1614-
return IntegerLiteral(token, self.scope(), token.type, int(token.value))
1622+
return IntegerLiteral(token, self.scope(), IntegerType(), int(token.value))
16151623
if token.type == "REAL":
16161624
token = self.eat(token.type)
1617-
return RealLiteral(token, self.scope(), token.type, float(token.value))
1625+
return RealLiteral(token, self.scope(), RealType(), float(token.value))
16181626
if token.type == "STRING":
16191627
token = self.eat(token.type)
16201628

@@ -1647,7 +1655,7 @@ def factor(
16471655
return expression
16481656
if token.value in ("TRUE", "FALSE"):
16491657
token = self.eat(token.value)
1650-
return BoolLiteral(token, self.scope(), "BOOLEAN", token.value == "TRUE")
1658+
return BoolLiteral(token, self.scope(), BooleanType(), token.value == "TRUE")
16511659
if token.type == "IDENT":
16521660
variable = self.variable_reference()
16531661
return variable

test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ def process(test: Path) -> None:
126126

127127
skip_run = expected_c.exists() and os.getenv("SKIP_RUN")
128128

129+
cc_flags = ["-Wall", "-Wextra", "-Werror", "-std=c23"]
130+
129131
expected_output = x.with_suffix(".output")
130132
if expected_output.exists() and not skip_run:
131133
created_output = test.with_suffix(".output")
@@ -135,7 +137,6 @@ def process(test: Path) -> None:
135137
exe = test.with_suffix(".exe")
136138
removals.append(exe)
137139

138-
cc_flags = ["-Wall", "-Wextra", "-Werror"]
139140
run(["clang", *cc_flags, test.with_suffix(".c"), "-I", ".", "-o", exe])
140141

141142
cmd = [exe, ">" + str(test.with_suffix(".output"))]
@@ -153,7 +154,6 @@ def process(test: Path) -> None:
153154
obj = test.with_suffix(".o")
154155
removals.append(obj)
155156

156-
cc_flags = ["-Wall", "-Wextra", "-Werror"]
157157
run(["clang", *cc_flags, test.with_suffix(".c"), "-I", ".", "-c", "-o", obj])
158158

159159
for removal in removals:

tests/eval/test.easy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
PROGRAM Eval:
2+
DECLARE a INTEGER;
3+
4+
SET a := 1 + 42*3;
5+
OUTPUT a;
6+
END PROGRAM Eval;

tests/hw/x/test.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ segment:
3030
node: IntegerLiteral
3131
token: <100|INTEGER tests/hw/test.easy:3:10>
3232
scope: PROGRAM:hw
33-
type: INTEGER
33+
type:
34+
node: IntegerType
3435
value: 100
3536
- node: OUTPUT
3637
token: <OUTPUT|KEYWORD tests/hw/test.easy:4:1>
@@ -64,7 +65,8 @@ segment:
6465
node: IntegerLiteral
6566
token: <0|INTEGER tests/hw/test.easy:5:10>
6667
scope: PROGRAM:hw
67-
type: INTEGER
68+
type:
69+
node: IntegerType
6870
value: 0
6971
do:
7072
node: Segment
@@ -88,7 +90,8 @@ segment:
8890
node: IntegerLiteral
8991
token: <10|INTEGER tests/hw/test.easy:5:15>
9092
scope: PROGRAM:hw
91-
type: INTEGER
93+
type:
94+
node: IntegerType
9295
value: 10
9396
condition:
9497
- node: EXIT

tests/quine/x/test.yaml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,14 @@ segment:
6363
- node: IntegerLiteral
6464
token: <0|INTEGER tests/quine/test.easy:1:216>
6565
scope: PROGRAM:Q
66-
type: INTEGER
66+
type:
67+
node: IntegerType
6768
value: 0
6869
- node: IntegerLiteral
6970
token: <38|INTEGER tests/quine/test.easy:1:219>
7071
scope: PROGRAM:Q
71-
type: INTEGER
72+
type:
73+
node: IntegerType
7274
value: 38
7375
- node: FunctionCall
7476
token: <CHARACTER|IDENT tests/quine/test.easy:1:226>
@@ -84,7 +86,8 @@ segment:
8486
- node: IntegerLiteral
8587
token: <34|INTEGER tests/quine/test.easy:1:236>
8688
scope: PROGRAM:Q
87-
type: INTEGER
89+
type:
90+
node: IntegerType
8891
value: 34
8992
- node: VariableReference
9093
token: <s|IDENT tests/quine/test.easy:1:243>
@@ -105,7 +108,8 @@ segment:
105108
- node: IntegerLiteral
106109
token: <34|INTEGER tests/quine/test.easy:1:258>
107110
scope: PROGRAM:Q
108-
type: INTEGER
111+
type:
112+
node: IntegerType
109113
value: 34
110114
- node: FunctionCall
111115
token: <SUBSTR|IDENT tests/quine/test.easy:1:265>
@@ -126,12 +130,17 @@ segment:
126130
- node: IntegerLiteral
127131
token: <39|INTEGER tests/quine/test.easy:1:275>
128132
scope: PROGRAM:Q
129-
type: INTEGER
133+
type:
134+
node: IntegerType
130135
value: 39
131136
- node: BinaryOperation
132137
token: <-|SYMBOL tests/quine/test.easy:1:288>
133138
scope: PROGRAM:Q
134-
type: <class 'type'>
139+
type:
140+
node: BuiltinFunction
141+
name: LENGTH
142+
type:
143+
node: IntegerType
135144
operation: '-'
136145
left:
137146
node: FunctionCall
@@ -153,7 +162,8 @@ segment:
153162
node: IntegerLiteral
154163
token: <38|INTEGER tests/quine/test.easy:1:289>
155164
scope: PROGRAM:Q
156-
type: INTEGER
165+
type:
166+
node: IntegerType
157167
value: 38
158168
- node: EXIT
159169
token: <EXIT|KEYWORD tests/quine/test.easy:1:294>

0 commit comments

Comments
 (0)