Skip to content

Commit 4ea5148

Browse files
committed
Add TypeScript version of Forthic interp
- Extracted interpreter from forthix.com codebase - Scrub Interpreter, Module, and GlobalModule classes - Port interpreter and global module tests from forthic-py - Create npm package for @forthic/interp with version 0.1.0
1 parent 99ca1fb commit 4ea5148

23 files changed

+13273
-0
lines changed

forthic-ts/.gitignore

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# These are some examples of commonly ignored file patterns.
2+
# You should customize this list as applicable to your project.
3+
# Learn more about .gitignore:
4+
# https://www.atlassian.com/git/tutorials/saving-changes/gitignore
5+
6+
# Node artifact files
7+
node_modules/
8+
dist/
9+
10+
# Compiled Java class files
11+
*.class
12+
13+
# Compiled Python bytecode
14+
*.py[cod]
15+
16+
# Log files
17+
*.log
18+
19+
# Package files
20+
*.jar
21+
22+
# Maven
23+
target/
24+
dist/
25+
26+
# JetBrains IDE
27+
.idea/
28+
29+
# Unit test reports
30+
TEST*.xml
31+
32+
# Generated by MacOS
33+
.DS_Store
34+
35+
# Generated by Windows
36+
Thumbs.db
37+
38+
# Applications
39+
*.app
40+
*.exe
41+
*.war
42+
43+
# Large media files
44+
*.mp4
45+
*.tiff
46+
*.avi
47+
*.flv
48+
*.mov
49+
*.wmv
50+
51+
*.pdf
52+
build

forthic-ts/.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Ignore artifacts:
2+
build
3+
coverage
4+
dist

forthic-ts/.prettierrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

forthic-ts/LICENSE

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
BSD 2-CLAUSE LICENSE
2+
3+
Copyright 2024 LinkedIn Corporation.
4+
All Rights Reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are
8+
met:
9+
10+
1. Redistributions of source code must retain the above copyright
11+
notice, this list of conditions and the following disclaimer.
12+
13+
2. Redistributions in binary form must reproduce the above copyright
14+
notice, this list of conditions and the following disclaimer in the
15+
documentation and/or other materials provided with the
16+
distribution.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

forthic-ts/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# @forthic/interp
2+
3+
A Forthic interpreter that runs within TypeScript.
4+
5+
## Description
6+
7+
This package provides a Forthic interpreter that allows you to execute Forthic code within your JavaScript/TypeScript projects. Forthic is a stack-based programming language inspired by Forth.
8+
9+
## Installation
10+
11+
You can install the package using npm:
12+
13+
```sh
14+
npm install @forthic/interp
15+
```
16+
17+
Or using yarn:
18+
19+
```sh
20+
yarn add @forthic/interp
21+
```
22+
23+
## Usage
24+
Here's a basic example of how to use the Forthic interpreter:
25+
26+
```js
27+
import { Interpreter } from "@forthic/interp"
28+
29+
30+
(async () => {
31+
const interp = new Interpreter();
32+
await interp.run("[1 2 3] '3 *' MAP");
33+
const result = interp.stack_pop();
34+
console.log("Howdy!", {result});
35+
})();
36+
37+
// Output:
38+
//
39+
// Howdy! { result: [ 3, 6, 9 ] }
40+
```
41+
42+
## License
43+
This project is licensed under the BSD-2-Clause License see the [LICENSE](./LICENSE) file for details.
44+
45+
## Author
46+
Rino Jose
47+
48+
## Links
49+
- [Repository](https://github.com/linkedin/forthic/forthic-ts)
50+
- [Issues](https://github.com/linkedin/forthic/issues)

forthic-ts/eslint.config.mjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import globals from "globals";
2+
import pluginJs from "@eslint/js";
3+
import tseslint from "typescript-eslint";
4+
5+
export default [
6+
{ files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"] },
7+
{ languageOptions: { globals: { ...globals.browser, ...globals.node } } },
8+
pluginJs.configs.recommended,
9+
...tseslint.configs.recommended,
10+
{
11+
rules: {
12+
"@typescript-eslint/no-explicit-any": "off",
13+
"@typescript-eslint/no-this-alias": "off",
14+
"@typescript-eslint/no-unused-vars": [
15+
"error",
16+
{ argsIgnorePattern: "^_" },
17+
],
18+
},
19+
},
20+
];

forthic-ts/jest.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} **/
2+
module.exports = {
3+
testEnvironment: "node",
4+
transform: {
5+
"^.+.tsx?$": ["ts-jest", {}],
6+
},
7+
testMatch: ["**/tests/**/*.test.[jt]s?(x)"],
8+
};

0 commit comments

Comments
 (0)