• R/O
  • SSH

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2


Commit MetaInfo

修订版054f0dcf5959469d781367d262b1bdf57f8df916 (tree)
时间2024-05-28 01:00:16
作者Albert Mietus < albert AT mietus DOT nl >
CommiterAlbert Mietus < albert AT mietus DOT nl >

Log Message

AIGR: added literals/Constant

更改概述

差异

diff -r b42f9200ebf9 -r 054f0dcf5959 base_packages/castle-aigr/Makefile
--- a/base_packages/castle-aigr/Makefile Sun May 26 18:44:26 2024 +0200
+++ b/base_packages/castle-aigr/Makefile Mon May 27 18:00:16 2024 +0200
@@ -16,14 +16,15 @@
1616 pytst/expressions/test_LRmore.py \
1717 pytst/expressions/test_RL.py \
1818 pytst/statements/test_body.py \
19-#
20-CURRENT = \
2119 pytst/extra/test_mangle.py \
2220 pytst/statements/test_method.py \
2321 pytst/statements/test_components.py \
2422 pytst/statements/test_0_dataclass.py \
2523 pytst/statements/test_0_kids.py \
2624 #
25+CURRENT = \
26+ pytst/expressions/test_literals.py \
27+#
2728 TODO = \
2829 pytst/test_3_namespaces.py \
2930 pytst/machinery/test_9_todo.py \
diff -r b42f9200ebf9 -r 054f0dcf5959 base_packages/castle-aigr/castle/aigr/expressions/__init__.py
--- a/base_packages/castle-aigr/castle/aigr/expressions/__init__.py Sun May 26 18:44:26 2024 +0200
+++ b/base_packages/castle-aigr/castle/aigr/expressions/__init__.py Mon May 27 18:00:16 2024 +0200
@@ -8,3 +8,4 @@
88
99 from .operator_expressions import *
1010 from .calls import *
11+from .literals import *
diff -r b42f9200ebf9 -r 054f0dcf5959 base_packages/castle-aigr/castle/aigr/expressions/literals.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/base_packages/castle-aigr/castle/aigr/expressions/literals.py Mon May 27 18:00:16 2024 +0200
@@ -0,0 +1,26 @@
1+# (C) Albert Mietus, 2023-2024. Part of Castle/CCastle project
2+
3+from __future__ import annotations # Postponed evaluation of annotations
4+import logging; logger = logging.getLogger(__name__)
5+
6+import typing as PTH # Python TypeHints
7+from dataclasses import dataclass, KW_ONLY
8+from dataclasses import field as dc_field
9+
10+from .. import AIGR
11+from . import _expression
12+
13+class _literal(_expression):pass # _kids = _expression._kids
14+
15+@dataclass
16+class Constant(_literal):
17+ """A (literal) Constant is a value that is given in code-text, like 0 (an int), 3.14 (a float) or "Hoi" (a string)"""
18+
19+ _kids = _literal._kids + ('value', 'type')
20+
21+ _: KW_ONLY
22+ value : AIGR
23+ type : PTH.Optional[type] = None
24+
25+
26+
diff -r b42f9200ebf9 -r 054f0dcf5959 base_packages/castle-aigr/pytst/expressions/test_literals.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/base_packages/castle-aigr/pytst/expressions/test_literals.py Mon May 27 18:00:16 2024 +0200
@@ -0,0 +1,23 @@
1+# (C) Albert Mietus, 2024. Part of Castle/CCastle project
2+
3+import logging; logger = logging.getLogger(__name__)
4+
5+import pytest
6+
7+from castle.aigr.expressions import literals
8+
9+def test_1_aConstant():
10+ e = literals.Constant(value=-1)
11+ assert e.value == -1
12+ assert e.type == None
13+
14+def test_2_ConstantInt():
15+ e = literals.Constant(value=42, type=int) # XXX Really? **python-types?**
16+ assert e.value == 42
17+ assert e.type == int
18+
19+def test_3_ConstantStr():
20+ e = literals.Constant(value="42", type=str) # XXX Really? **python-types?**
21+ assert e.value == "42"
22+ assert e.type == str
23+