-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NodeJS compatibility & mod function
- Loading branch information
Showing
15 changed files
with
316 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,26 @@ | ||
{ | ||
"name": "sigmascript", | ||
"version": "1.0.0", | ||
"description": "", | ||
"description": "Programming language made for sigma males", | ||
"main": "index.js", | ||
"scripts": { | ||
"build": "webpack --config webpack.prod.js", | ||
"start": "webpack --watch --config webpack.dev.js" | ||
}, | ||
"bin": "bin/sigmascript.js", | ||
"keywords": [], | ||
"author": "", | ||
"author": "Gulg", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"terser-webpack-plugin": "^5.3.10", | ||
"ts-loader": "^9.5.1", | ||
"typescript": "^5.4.5", | ||
"webpack": "^5.91.0", | ||
"webpack-cli": "^5.1.4", | ||
"webpack-dev-server": "^5.0.4", | ||
"webpack-merge": "^5.10.0" | ||
}, | ||
"dependencies": { | ||
"node-fetch": "^3.3.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { NodeRuntime } from "./runtimes/node"; | ||
import { SigmaScript } from "./sigmascript/sigmascript"; | ||
import fetch from "node-fetch"; | ||
import { readFile } from "fs/promises"; | ||
|
||
function isURL(path: string) { | ||
let url; | ||
try { | ||
url = new URL(path); | ||
} catch { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
const sigmaScript = new SigmaScript(); | ||
NodeRuntime.addLibraries(sigmaScript); | ||
|
||
for (const path of process.argv.slice(2)) { | ||
let source; | ||
if (isURL(path)) { | ||
let response; | ||
try { | ||
response = await fetch(path); | ||
} catch (err) { | ||
console.error(`${path} - ${err.message}`); | ||
continue; | ||
} | ||
if (!response.ok) { | ||
console.error(`${path} - ${response.status} (${response.statusText})`); | ||
continue; | ||
} | ||
try { | ||
source = await response.text(); | ||
} catch (err) { | ||
console.error(`${path} - ${err.message}`); | ||
continue; | ||
} | ||
} else { | ||
try { | ||
source = await readFile(path, { encoding: "utf8" }); | ||
} catch (err) { | ||
console.error(`${path} - ${err.message}`); | ||
continue; | ||
} | ||
} | ||
sigmaScript.load(source); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { SigmaScript } from "../sigmascript/sigmascript"; | ||
import { DOMLib } from "../sigmascript/lib/dom"; | ||
import { FnLib } from "../sigmascript/lib/fn"; | ||
import { BrowserJSLib } from "../sigmascript/lib/js-browser"; | ||
import { RefLib } from "../sigmascript/lib/ref"; | ||
import { StringLib } from "../sigmascript/lib/string"; | ||
import { StructLib } from "../sigmascript/lib/struct"; | ||
import { ArrayLib } from "../sigmascript/lib/array"; | ||
import { MathLib } from "../sigmascript/lib/math"; | ||
|
||
export namespace BrowserRuntime { | ||
export function addLibraries(sigmaScript: SigmaScript) { | ||
sigmaScript.addLib("dom", new DOMLib(sigmaScript)); | ||
sigmaScript.addLib("fn", new FnLib(sigmaScript)); | ||
sigmaScript.addLib("js", new BrowserJSLib(sigmaScript)); | ||
sigmaScript.addLib("ref", new RefLib(sigmaScript)); | ||
sigmaScript.addLib("string", new StringLib(sigmaScript)); | ||
sigmaScript.addLib("struct", new StructLib(sigmaScript)); | ||
sigmaScript.addLib("array", new ArrayLib(sigmaScript)); | ||
sigmaScript.addLib("math", new MathLib(sigmaScript)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { SigmaScript } from "../sigmascript/sigmascript"; | ||
import { FnLib } from "../sigmascript/lib/fn"; | ||
import { NodeJSLib } from "../sigmascript/lib/js-node"; | ||
import { RefLib } from "../sigmascript/lib/ref"; | ||
import { StringLib } from "../sigmascript/lib/string"; | ||
import { StructLib } from "../sigmascript/lib/struct"; | ||
import { ArrayLib } from "../sigmascript/lib/array"; | ||
import { MathLib } from "../sigmascript/lib/math"; | ||
|
||
export namespace NodeRuntime { | ||
export function addLibraries(sigmaScript: SigmaScript) { | ||
sigmaScript.addLib("fn", new FnLib(sigmaScript)); | ||
sigmaScript.addLib("js", new NodeJSLib(sigmaScript)); | ||
sigmaScript.addLib("ref", new RefLib(sigmaScript)); | ||
sigmaScript.addLib("string", new StringLib(sigmaScript)); | ||
sigmaScript.addLib("struct", new StructLib(sigmaScript)); | ||
sigmaScript.addLib("array", new ArrayLib(sigmaScript)); | ||
sigmaScript.addLib("math", new MathLib(sigmaScript)); | ||
} | ||
} |
Oops, something went wrong.