implemented hseval

This commit is contained in:
Luxferre
2026-07-03 11:58:39 +03:00
parent 4023323d5f
commit 1b583b2ff5
3 changed files with 16 additions and 0 deletions
+1
View File
@@ -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())))
+4
View File
@@ -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
+11
View File
@@ -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
]