introduced hseval

This commit is contained in:
Luxferre
2026-07-03 12:21:19 +03:00
parent 1b583b2ff5
commit 318adf11fe
3 changed files with 24 additions and 7 deletions
+6
View File
@@ -93,6 +93,12 @@ Clyx combines the conceptual simplicity of Forth (and concatenative/RPN programm
While diverging from some "purity" aspects, Clyx is a decent choice for newcomers that want to try out a totally new programming paradigm without investing too much time into fighting the language's quirks. While diverging from some "purity" aspects, Clyx is a decent choice for newcomers that want to try out a totally new programming paradigm without investing too much time into fighting the language's quirks.
### Doesn't `hseval` primitive make Clyx programs non-portable across different implementations?
Yes, it does, because it works differently across different host languages (and Clyx implementations are allowed to not support it at all), so it must only be used as a last resort when any other attempts to interact with the outside world are unsuccessful. Additionally, using `hseval` introduces extra security risks. Nevertheless, this primitive had been added in order to enable some host-specific interoperability that would otherwise be impossible or very cumbersome to implement, such as browser-based deployments.
In other words, `hseval` is sometimes very useful in very specific cases, but please avoid using it unless you have a really good reason to use it.
## Credits ## Credits
Created by Luxferre in 2026, released into the public domain with no warranties. Created by Luxferre in 2026, released into the public domain with no warranties.
+1 -1
View File
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project] [project]
name = "clyx" name = "clyx"
version = "0.1.0" version = "0.1.1"
description = "Clyx programming language interpreter" description = "Clyx programming language interpreter"
readme = "README.md" readme = "README.md"
requires-python = ">=3.7" requires-python = ">=3.7"
+17 -6
View File
@@ -2,7 +2,7 @@
Clyx is a concatenative, stack-oriented programming language designed for simplicity, minimalism, and metaprogramming capabilities. It uses postfix notation (aka Reverse Polish Notation, RPN), where operations are performed on a global stack. Clyx features homoiconicity: code is structured as quotations (lists), which can be manipulated as data and executed dynamically. Clyx is a concatenative, stack-oriented programming language designed for simplicity, minimalism, and metaprogramming capabilities. It uses postfix notation (aka Reverse Polish Notation, RPN), where operations are performed on a global stack. Clyx features homoiconicity: code is structured as quotations (lists), which can be manipulated as data and executed dynamically.
This document describes the stack effects and behavior of the **47 primitive core words**, **3 bootstrapped core words**, and **41 standard library words** present in the reference implementation. This document describes the stack effects and behavior of the **48 primitive core words**, **3 bootstrapped core words**, and **41 standard library words** present in the reference implementation.
The Clyx runtime itself allows the programmer to redefine any already defined word, including the core ones and the ones from the standard library. Unlike e.g. Forth, where words are resolved at compile-time, Clyx words are resolved at runtime, so such redefinitions may affect all previously established behavior. That's why, as a rule, any **predefined** Clyx word, both in the language core and the standard library, must not exceed 6 characters. This is done to encourage programmers to define their own human-readable words (7+ characters long) without any risk of overwriting existing word definitions. The Clyx runtime itself allows the programmer to redefine any already defined word, including the core ones and the ones from the standard library. Unlike e.g. Forth, where words are resolved at compile-time, Clyx words are resolved at runtime, so such redefinitions may affect all previously established behavior. That's why, as a rule, any **predefined** Clyx word, both in the language core and the standard library, must not exceed 6 characters. This is done to encourage programmers to define their own human-readable words (7+ characters long) without any risk of overwriting existing word definitions.
@@ -235,6 +235,8 @@ Any line fragment starting with `#` to the end of the physical source line is re
- Otherwise, it creates a client TCP connection to `host` on `port` and pushes the connection file-like descriptor onto the stack. - Otherwise, it creates a client TCP connection to `host` on `port` and pushes the connection file-like descriptor onto the stack.
- Sets `SO_REUSEADDR` to ensure the socket is instantly released upon termination. - Sets `SO_REUSEADDR` to ensure the socket is instantly released upon termination.
**N.B.**: this primitive may not be supported on all targets.
### `write` ### `write`
- **Stack Effect**: `( fd data -- count )` - **Stack Effect**: `( fd data -- count )`
- **Description**: Writes the string/bytes `data` to the descriptor `fd`. Returns the number of characters/bytes written. Automatically flushes standard/socket buffers if possible. - **Description**: Writes the string/bytes `data` to the descriptor `fd`. Returns the number of characters/bytes written. Automatically flushes standard/socket buffers if possible.
@@ -258,14 +260,20 @@ Any line fragment starting with `#` to the end of the physical source line is re
- **Stack Effect**: `( path -- )` - **Stack Effect**: `( path -- )`
- **Description**: Creates a new directory at the specified `path`. - **Description**: Creates a new directory at the specified `path`.
**N.B.**: this primitive may not be supported on all targets.
### `listd` (List Directory) ### `listd` (List Directory)
- **Stack Effect**: `( path -- [contents] )` - **Stack Effect**: `( path -- [contents] )`
- **Description**: Lists the contents of the directory at `path`. Pushes a quotation containing a list of strings representing the names of the files and directories inside the directory. - **Description**: Lists the contents of the directory at `path`. Pushes a quotation containing a list of strings representing the names of the files and directories inside the directory.
**N.B.**: this primitive may not be supported on all targets.
### `deld` (Delete Directory) ### `deld` (Delete Directory)
- **Stack Effect**: `( path -- )` - **Stack Effect**: `( path -- )`
- **Description**: Deletes the directory at `path` from the file system. The directory must be empty. - **Description**: Deletes the directory at `path` from the file system. The directory must be empty.
**N.B.**: this primitive may not be supported on all targets.
### `rand` (Random) ### `rand` (Random)
- **Stack Effect**: `( limit -- val )` - **Stack Effect**: `( limit -- val )`
- **Description**: Generates a random integer in the range `[0, limit - 1]` and pushes it to the stack. - **Description**: Generates a random integer in the range `[0, limit - 1]` and pushes it to the stack.
@@ -278,6 +286,8 @@ Any line fragment starting with `#` to the end of the physical source line is re
- **Stack Effect**: `( expr -- val )` - **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. - **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.
**N.B.**: this primitive may not be supported on all targets. Only use as a last resort in controlled and/or sandboxed environments. Never pass user input to this primitive.
--- ---
## 8. Bootstrapped Core Words ## 8. Bootstrapped Core Words
@@ -406,6 +416,8 @@ These words are defined in the standard library file `lib.clx` and loaded dynami
- **Stack Effect**: `( port -- fd )` - **Stack Effect**: `( port -- fd )`
- **Description**: Creates a server TCP socket listening on all interfaces (`"0.0.0.0"`) on the specified `port`. Pushes the server socket descriptor onto the stack. - **Description**: Creates a server TCP socket listening on all interfaces (`"0.0.0.0"`) on the specified `port`. Pushes the server socket descriptor onto the stack.
**N.B.**: this word may not be supported on all targets.
### 9.6 Type Checking & Comparison ### 9.6 Type Checking & Comparison
#### `isnum` (Is Number) #### `isnum` (Is Number)
@@ -443,17 +455,16 @@ These words are defined in the standard library file `lib.clx` and loaded dynami
#### `<=` (Less Than or Equal) #### `<=` (Less Than or Equal)
- **Stack Effect**: `( a b -- c )` - **Stack Effect**: `( a b -- c )`
- **Description**: Pops `b`, pops `a`, and pushes `1` if `a` is less than or equal to `b`; otherwise pushes `0`. - **Description**: Pops `b`, pops `a`, and pushes `1` if `a` is less than or equal to `b`; otherwise pushes `0`.
#### `streq` (String Equal)
- **Stack Effect**: `( s1 s2 -- c )`
- **Description**: Pops `s2`, pops `s1`, and pushes `1` if the two strings `s1` and `s2` (or their character list equivalents) are equal; otherwise pushes `0`.
#### `vlen` (Value Length) #### `vlen` (Value Length)
- **Stack Effect**: `( val -- len )` - **Stack Effect**: `( val -- len )`
- **Description**: Pushes the length of `val`. If `val` is a list, it returns the number of elements; if it is a string, it returns the number of characters. - **Description**: Pushes the length of `val`. If `val` is a list, it returns the number of elements; if it is a string, it returns the number of characters.
### 9.7 String Operations ### 9.7 String Operations
#### `streq` (String Equal)
- **Stack Effect**: `( s1 s2 -- c )`
- **Description**: Pops `s2`, pops `s1`, and pushes `1` if the two strings `s1` and `s2` (or their character list equivalents) are equal; otherwise pushes `0`.
#### `lower` (To Lowercase) #### `lower` (To Lowercase)
- **Stack Effect**: `( s -- s_lower )` - **Stack Effect**: `( s -- s_lower )`
- **Description**: Pops the string `s` and pushes its lowercase equivalent `s_lower` onto the stack. - **Description**: Pops the string `s` and pushes its lowercase equivalent `s_lower` onto the stack.