From 1b583b2ff50bb10bbbefb815966feb521e5886ea Mon Sep 17 00:00:00 2001 From: Luxferre Date: Fri, 3 Jul 2026 11:58:39 +0300 Subject: [PATCH] implemented hseval --- clyx-python/clyx/clyx.py | 1 + clyx_manual.md | 4 ++++ test.clx | 11 +++++++++++ 3 files changed, 16 insertions(+) diff --git a/clyx-python/clyx/clyx.py b/clyx-python/clyx/clyx.py index 58d1dbe..87aa27a 100755 --- a/clyx-python/clyx/clyx.py +++ b/clyx-python/clyx/clyx.py @@ -62,6 +62,7 @@ class Clyx: 'delf': lambda: os.remove(self._stack.pop()), 'maked': lambda: os.mkdir(self._stack.pop()), 'listd': lambda: self._stack.append(os.listdir(self._stack.pop())), 'deld': lambda: os.rmdir(self._stack.pop()), 'rand': lambda: self._stack.append(randrange(int(self._stack.pop()))), '.s': lambda: self._out_num(repr(self._stack)), 'dip': lambda: (lambda q, y: (self._exec_quot(q), self._stack.append(y)))(self._stack.pop(), self._stack.pop()), 'loop': lambda: (lambda body, cond: self._exec_loop(cond, body))(self._stack.pop(), self._stack.pop()), + 'hseval': lambda: self._stack.append(eval(self._stack.pop())), 'chr': lambda: self._stack.append(chr(int(self._stack.pop()))), 'asc': lambda: self._stack.append(ord(self._stack.pop())), 'sin': lambda: self._stack.append(math.sin(float(self._stack.pop()))), 'cos': lambda: self._stack.append(math.cos(float(self._stack.pop()))), 'atan': lambda: self._stack.append(math.atan(float(self._stack.pop()))), 'exp': lambda: self._stack.append(math.exp(float(self._stack.pop()))), 'log': lambda: self._stack.append(math.log(float(self._stack.pop()))) diff --git a/clyx_manual.md b/clyx_manual.md index cb0caef..21011ed 100644 --- a/clyx_manual.md +++ b/clyx_manual.md @@ -274,6 +274,10 @@ Any line fragment starting with `#` to the end of the physical source line is re - **Stack Effect**: `( -- )` - **Description**: Prints the current stack representation to standard output (useful for debugging). +### `hseval` (Host Language Evaluation) +- **Stack Effect**: `( expr -- val )` +- **Description**: Pops the string `expr` from the stack, evaluates it as an expression in the host language (e.g., Python), and pushes the resulting value back onto the stack. + --- ## 8. Bootstrapped Core Words diff --git a/test.clx b/test.clx index aa23b70..851a6d6 100755 --- a/test.clx +++ b/test.clx @@ -204,3 +204,14 @@ if [ "my_const" [ 99 ] defw my_const 99 = if [ " defw (no-inline) PASS" puts cr ] [ " defw (no-inline) FAIL" puts cr ] # Test defw :: my_inline [ 100 ] my_inline 100 = if [ " :: (inline) PASS" puts cr ] [ " :: (inline) FAIL" puts cr ] # Test inline :: + +# 11. Host Language Evaluation: hseval +"Testing host language evaluation..." puts cr +"[1, 2] * 2" hseval [ 1 2 1 2 ] streq +"1 + 2" hseval 3 = and +if [ + " hseval PASS" puts cr +] [ + " hseval FAIL" puts cr +] +