-
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.
- Loading branch information
1 parent
845bcf2
commit 0c7f290
Showing
12 changed files
with
1,051 additions
and
84 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
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,16 @@ | ||
import { ASTNode } from "./ast"; | ||
import { Config } from "./common"; | ||
import { Visitor } from "./visitor"; | ||
|
||
export function analyze(node: ASTNode, config: Config): ASTNode { | ||
// Analyzing Visitor (imports, allow/disallow features) | ||
// imports only for \use{\file...} or \use{\url...} or \use{stdlib} -> scan full ast -> add imports to config | ||
// other \url,\file IGNORE. they are on demand in-place reads as-is without eval. do not eval | ||
// scan for node types: use>raw, use>url, use>file | ||
|
||
return node; | ||
} | ||
|
||
export class Analyzer implements Visitor<void> { | ||
|
||
} |
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
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
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
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,45 +1,66 @@ | ||
import fs from "fs"; | ||
import { tokenize } from "./lexer"; | ||
import { log } from "console"; | ||
import { TokenType } from "./common"; | ||
import assert from "node:assert/strict"; | ||
import { parse } from "./parser"; | ||
import { Interpreter } from "./visitor"; | ||
import { Program } from "./ast"; | ||
import { interpret } from "./visitor"; | ||
import { preprocess } from "./preprocessor"; | ||
import chalk from "chalk"; | ||
import { analyze } from "./analyzer"; | ||
|
||
let original = ""; | ||
// original = fs.readFileSync(__dirname + "/../tests/loop.txt", "utf8"); | ||
original = fs.readFileSync(__dirname + "/../tests/t1.txt", "utf8"); | ||
// original = fs.readFileSync(__dirname + "/../tests/t1.txt", "utf8"); | ||
// original = fs.readFileSync(__dirname + "/../tests/t3.php", "utf8"); | ||
original = fs.readFileSync(__dirname + "/../tests/t4.txt", "utf8"); | ||
|
||
// 1. add default stuff | ||
// original = "\\version{1}\n\\prefix{\\}\n\\config{files}{true}\n\\config{net}{true}\n\\config{env}{true}\n\\config{js}{true}\n" + original; | ||
// \rawfile{path} imports the file, just copo/pastes the file content, no pipeline | ||
// allow file importsw: \file{name} just copo/pastes the file content | ||
// \use{realtivePathOrURL} imports the file, usign this pipeline and executes it | ||
// pro: own \\\utppp[] block | ||
// no easy. In Interperter for \file{} just do the pipeline (except interpret) preprocess>tokenize>parse | ||
|
||
// original += "\n\\halt"; | ||
// read cli: -q quiet? (print debug) | ||
|
||
log("===== content: ====="); | ||
log(original); | ||
const pj = require("../package.json"); | ||
console.log(chalk.yellowBright(chalk.bold(`🚀 utpp ${pj.version} `))); | ||
|
||
// log("===== content: ====="); | ||
// log(original); | ||
|
||
// 1. preprocessor (Meta Config) | ||
log("===== preprocess: ====="); | ||
const [input, config] = preprocess(original); | ||
|
||
console.log("with config: ", config); | ||
|
||
// 2. lexer (Tokens) | ||
log("===== tokenize: ====="); | ||
const tokenized = tokenize(original); | ||
const tokenized = tokenize(input, config); | ||
log(tokenized); | ||
|
||
const reconstructedFromLexer = tokenized.map((t) => t.value).join(""); | ||
assert.strictEqual(original, reconstructedFromLexer); | ||
log("lexer verified ✅"); | ||
// const reconstructedFromLexer = tokenized.map((t) => t.value).join(""); | ||
// assert.strictEqual(original, reconstructedFromLexer); | ||
// log("lexer verified ✅"); // doesnt work when metaconfig used | ||
|
||
// TODO: allow export/import (serialize) AST for faster executing | ||
|
||
// 3. parser (AST) | ||
log("===== parse: ====="); | ||
const ast = parse(tokenized) as Program; | ||
const treeify = require("./utils/treeify"); | ||
treeify.asLines(ast, true, false, log); | ||
|
||
// 4. interpreter (Execute) | ||
const ast = parse(tokenized); | ||
const treeify = require("./utils/treeify"); // debug | ||
treeify.asLines(ast, true, false, log); // debug | ||
|
||
// 4. AST Analyzer (imports, verify enabled/disabled features) | ||
log("===== analyze: ====="); | ||
const program = analyze(ast, config); | ||
|
||
// 5. interpreter (Execute on complete resolved AST) | ||
log("===== interpret: ====="); | ||
const visitor = new Interpreter(); | ||
const generated = ast.accept(visitor); | ||
const generated = interpret(program); | ||
log(generated); | ||
log("----------------------") | ||
log("----------------------"); | ||
|
||
// ?. Validator/Rewriter (check enabled/disabled features) | ||
// ?. Optimizer (dead code elimination, constant folding, etc.) | ||
|
||
// maybe IR-Representation SSA form optimize... |
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
Oops, something went wrong.