Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Make an interpreter for this abomination #74

Open
wants to merge 78 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
2ffb75a
Groundwork
Bytestorm5 Jun 4, 2023
5aa5b4a
typo
Bytestorm5 Jun 4, 2023
7dc2119
tokenizer nearly done?
Bytestorm5 Jun 4, 2023
d32846c
mobile coding???????
Bytestorm5 Jun 4, 2023
75ead99
added more yelling
Bytestorm5 Jun 4, 2023
2a9fb21
newline and debugging
Bytestorm5 Jun 4, 2023
f68141e
Merge pull request #1 from TodePond/main
Bytestorm5 Jun 5, 2023
7aba489
very indecisive about the naming
Bytestorm5 Jun 5, 2023
347110d
Merge branch 'main' of https://github.com/Bytestorm5/DreamBerd
Bytestorm5 Jun 5, 2023
1d3a98d
forgot to save
Bytestorm5 Jun 5, 2023
23407e7
tokenizer probably works
Bytestorm5 Jun 5, 2023
50732c2
Put Tokenizer in a box
Bytestorm5 Jun 5, 2023
e678549
Tokenizer error handling
Bytestorm5 Jun 5, 2023
c52f87b
Generalize crawler to hopefully make parsing easier
Bytestorm5 Jun 5, 2023
448aef7
Improved AI
Bytestorm5 Jun 5, 2023
7a558c2
Implicit AI with newlines
Bytestorm5 Jun 5, 2023
d3c5655
Added Americentrism
Bytestorm5 Jun 5, 2023
25bd3ad
Removed Americentrism
Bytestorm5 Jun 5, 2023
2be54ab
Merge branch 'TodePond:main' into main
Bytestorm5 Jun 5, 2023
0ccea99
Added className and other misc changes
Bytestorm5 Jun 5, 2023
d392846
Individual tokens for Exclamations
Bytestorm5 Jun 5, 2023
d9320f5
totally didn't forget boolean operators who would do that not this gu…
Bytestorm5 Jun 5, 2023
6ab9618
Merge branch 'TodePond:main' into main
Bytestorm5 Jun 5, 2023
806a8b3
Check for internet connection
Bytestorm5 Jun 6, 2023
2f0f120
Parser groundwork
Bytestorm5 Jun 6, 2023
c074a2f
Improved "FUNCTION" keyword checks.
Odinmylord Jun 6, 2023
872ba48
Reformatted file.
Odinmylord Jun 6, 2023
62b2214
Update template.tsx
Bytestorm5 Jun 6, 2023
64f17fe
REGEX REGEX REGEX REGEX REGEX REGEX REGEX REGEX REGEX REGEX REGEX REGEX
Bytestorm5 Jun 6, 2023
dfede24
Made the regex even more cursed, now matches triple const
Odinmylord Jun 7, 2023
2865c10
Started implementing single line function declaration
Odinmylord Jun 7, 2023
0ae9440
Fixed the regex (splitting it in multiple lines wasn't a good idea) a…
Odinmylord Jun 7, 2023
11881fc
Fixed small issue with indentation
Odinmylord Jun 7, 2023
d82fd46
Fixed issues with variable assignment and function keyword
Odinmylord Jun 7, 2023
df530c0
Re-enable identification requirement && Lifetime functionality in com…
Bytestorm5 Jun 8, 2023
7917404
it is way too late to figure out time travel
Bytestorm5 Jun 8, 2023
5493a41
Preparing for chicanery
Bytestorm5 Jun 8, 2023
5a0a0e8
Variables tracked in a map now for greater flexibility
Bytestorm5 Jun 8, 2023
9036f89
This is a first try to check function syntax it isn't complete yet
Odinmylord Jun 8, 2023
ccaf1a4
some processor functions
Bytestorm5 Jun 8, 2023
efac972
Wrap expr in get_var
Bytestorm5 Jun 8, 2023
3445a8d
forgot to delete a keyword
Bytestorm5 Jun 8, 2023
265a27f
Dynamically determine if quotes are needed
Bytestorm5 Jun 8, 2023
645885a
expressions are hard
Bytestorm5 Jun 9, 2023
b7c0580
Merge remote-tracking branch 'origin/main' into functions
Odinmylord Jun 9, 2023
babf1d2
Added indentation check and fixed issue with newlines on linux
Odinmylord Jun 12, 2023
9082e9c
Now the script works with python 3.8+
Odinmylord Jun 12, 2023
945b278
almost finished parsing expressions
Bytestorm5 Jun 13, 2023
e3d7fab
why was I parsing to begin with?
Bytestorm5 Jun 13, 2023
4036885
Revert "why was I parsing to begin with?"
Bytestorm5 Jun 13, 2023
336ccac
Figured out parsing but do exponents *really* have to be right-associ…
Bytestorm5 Jun 13, 2023
04165bc
Finished expression parsing except for right associativity
Bytestorm5 Jun 13, 2023
a3bc397
Line preprocessor now solves precise equalities
Bytestorm5 Jun 13, 2023
08cae0c
Moved condition block manager to helper file
Bytestorm5 Jun 13, 2023
91dd845
keeping equality check simple for now, might change
Bytestorm5 Jun 13, 2023
ee6b452
Moved precise equality to expr processor
Bytestorm5 Jun 13, 2023
f218614
When check conditions and advanced variable geting
Bytestorm5 Jun 13, 2023
d88389b
We have some sort of function syntax check
Odinmylord Jun 13, 2023
92f60d7
Added const const var to invalid mix
Odinmylord Jun 13, 2023
aceda74
Merge pull request #2 from Bytestorm5/functions
Bytestorm5 Jun 13, 2023
8155a62
Recursive scoping
Bytestorm5 Jun 13, 2023
08c55da
Added type identifiers (they don't do anything)
Bytestorm5 Jun 13, 2023
11e4722
All functions lead to arrows
Bytestorm5 Jun 13, 2023
91a11b4
attempt at block handling
Bytestorm5 Jun 13, 2023
c06b6df
fix(compiler): variable declaration statements
gabrielchl Jun 22, 2023
8f71680
Add slots and fix type annotations
CoolCat467 Jun 22, 2023
3fd1c02
Add pyproject.toml for dependancies and mypy flags
CoolCat467 Jun 22, 2023
793ef9b
Merge pull request #3 from gabrielchl/main
Bytestorm5 Jun 22, 2023
fd84740
Merge branch 'pr/4'
Bytestorm5 Jun 22, 2023
2fd43e7
Merge pull request #5 from TodePond/main
Bytestorm5 Jun 22, 2023
03dc576
"serious" compiler boilerplate
Bytestorm5 Jun 23, 2023
baa183a
Reduce code duplication
CoolCat467 Jun 23, 2023
59701a6
Add code formatting
CoolCat467 Jun 23, 2023
ff68d1d
Revert "Reduce code duplication", wrong branch
CoolCat467 Jun 23, 2023
78255b8
refactor
Bytestorm5 Jun 23, 2023
f1c62af
feat: use filepath from args
gabrielchl Jun 23, 2023
6dbda7d
Merge pull request #8 from gabrielchl/feat-filepath-from-args
Bytestorm5 Jun 23, 2023
435eba3
Merge pull request #7 from CoolCat467/add-formatting
Bytestorm5 Jun 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
venv/
*.pyc
test/db/db/*.js
37 changes: 37 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-ast
- id: check-yaml
- id: check-toml
- id: check-merge-conflict
- id: mixed-line-ending
- id: check-case-conflict
- repo: https://github.com/hadialqattan/pycln
rev: v2.1.5
hooks:
- id: pycln
args: [--config=pyproject.toml, src]
types: [file]
types_or: [python, pyi]
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
language_version: python3.11
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
args: ["--profile", "black", "--filter-files"]

ci:
autofix_commit_msg: "[pre-commit.ci] auto fixes from pre-commit.com hooks"
autofix_prs: true
autoupdate_commit_msg: "[pre-commit.ci] pre-commit autoupdate"
autoupdate_schedule: weekly
submodules: false
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ import add!
add(3, 2)!
```

Note that due to the fact that it is impossible to export all functions of a file to all other DreamBerd files in existence, there is __no__ DreamBerd standard library.

By the way, to see DreamBerd in action, check out [this page](https://github.com/TodePond/DreamBerd/blob/main/LICENSE.md).

## Classes
Expand Down
211 changes: 211 additions & 0 deletions built/helper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
export class VarState {
name: string
variable: any;
allow_reassign: boolean;
priority: number;
history: Array<any>;
updateCount: number;
onUpdatePromises: Array<UpdatePromise>;
expiry: number

constructor(name, variable, allow_reassign, priority, lifetime=-1) {
this.name = name
this.variable = variable;
this.allow_reassign = allow_reassign;
this.priority = priority;
this.history = [undefined];
this.expiry = Infinity

// Lifetime will be left as default unless infinity or seconds
// Line-based lifetime will be done manually with kill()
if (lifetime != -1) {
if (lifetime === Infinity) {
localStorage.setItem(name, variable);
this.expiry = -1
}
else {
this.expiry = Date.now() + (1000 * lifetime)
}
}

this.updateCount = 0;
this.onUpdatePromises = [];
}

get() {
if (this.dead()) {
this.kill()
}
return this.variable;
}

dead() {
return this.expiry !== -1 && Date.now() >= this.expiry
}

kill() {
this.history.push(this.variable)
this.variable = undefined
}

assign(value, priority) {
if (this.dead()) {
this.kill()
}
if (!this.allow_reassign || priority < this.priority) {
return false;
} else {
this.history.push(this.variable);
if (this.expiry == -1) {
localStorage.setItem(this.name, value);
}
this.variable = value;
this.updateCount++;

// Check all `next` calls
const resolvedPromises: Array<UpdatePromise> = [];
for (const promise of this.onUpdatePromises) {
if (this.updateCount >= promise.targetCount) {
promise.resolve(this.variable);
resolvedPromises.push(promise);
}
}

for (const promise of resolvedPromises) {
const index = this.onUpdatePromises.indexOf(promise);
if (index !== -1) {
this.onUpdatePromises.splice(index, 1);
}
}

return true;
}
}

previous(prev_iter = 1) {
if (prev_iter > this.history.length) {
console.log(`Soft Error: Attempting to access prehistoric value of ${this.name}.`)
return Math.random() * Number.MAX_VALUE // Approximation of unassigned memory
}
return this.history[this.history.length - prev_iter];
}

next(count: number): Promise<any> {
const targetCount = this.updateCount + count;

if (targetCount <= this.updateCount) {
console.log(`Variable already updated ${count} times. Current value: ${this.get()}`);
return Promise.resolve(this.get());
}

return new Promise((resolve) => {
const promise: UpdatePromise = {
targetCount: targetCount,
resolve: resolve,
};
this.onUpdatePromises.push(promise);
});
}
}

export interface UpdatePromise {
targetCount: number;
resolve: Function;
}
/// USED FOR WHEN BLOCKS
class ConditionBlockPair {
condition: () => boolean;
codeBlock: () => void;

constructor(condition: () => boolean, codeBlock: () => void) {
this.condition = condition;
this.codeBlock = codeBlock;
}
}

// Define a class to manage the conditions and code blocks
export class ConditionBlockManager {
pairs: ConditionBlockPair[];

constructor() {
this.pairs = [];
}

addPair(condition: () => boolean, codeBlock: () => void) {
const pair = new ConditionBlockPair(condition, codeBlock);
this.pairs.push(pair);
}

checkConditions() {
this.pairs = this.pairs.filter((pair) => {
if (pair.condition()) {
pair.codeBlock();
return false; // Remove the pair from the list
}
return true; // Keep the pair in the list
});
}

startCheckingRegularly(interval: number) {
setInterval(() => {
this.checkConditions();
}, interval);
}
}

export class Scope {
parent?: Scope
variables: Map<any, VarState>

constructor(parent=undefined) {
this.variables = new Map<any, VarState>;
this.parent = parent
}
assign(name, value, allow_reassign, priority, lifetime=-1) {
const varState = this.variables.get(name);

if (varState !== undefined) {
// Update the existing object properties
varState.assign(value, priority);
}
else if (this.parent && this.parent.has_var(name)) {
// Only run if variable already exists
// RECUSRION RECUSRION RECUSRION RECUSRION RECUSRION RECUSRION RECUSRION RECUSRION RECUSRION
this.parent.assign(name, value, allow_reassign, priority, lifetime)
} else {
// Create a new object and store it in the map
this.variables.set(name, new VarState(name, value, allow_reassign, priority, lifetime));
}
}

has_var(name) {
if (this.variables.get(name) !== undefined) {
return true
}
else {
return this.parent && this.parent.has_var(name)
}
}

get_var(name) {
if (this.variables.get(name) !== undefined) {
return this.variables.get(name)!.get()
}
else if (this.parent) {
return this.parent.get_var(name)
}
else { // Will only go here if this scope is an orphan
// Check for infinite lifetime variables
let local_var = localStorage.getItem(name)
if (local_var != null) {
return local_var;
}

// TODO: 3const server


// Return literal value only if all other possibilities are ruled out
return name
}
}
}
70 changes: 70 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "DreamBerd"
version = "0.9.9.9.9.9.9.9.9d"
description = "DreamBerd Compiler"
readme = {file = "README.md", content-type = "text/markdown"}
license = {file = "LICENSE"}
requires-python = ">=3.10"
classifiers = [
"Development Status :: 5 - Alpha",
"Intended Audience :: Developers",
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
"Topic :: Utilities",
"Typing :: Typed",
]
keywords = ["dream", "berd", "dreamberd", "compiler"]
dependencies = [
"requests~=2.31.0",
]

[project.optional-dependencies]
dev = [
"mypy~=1.3.0", # must match .pre-commit-config.yaml
"pre-commit",
"pre-commit-hooks~=4.4.0", # must match .pre-commit-config.yaml
"black~=23.3.0", # must match .pre-commit-config.yaml
"isort~=5.12.0", # must match .pre-commit-config.yaml
"pycln~=2.1.3", # must match .pre-commit-config.yaml
]

[project.urls]
"Homepage" = "https://github.com/TodePond/DreamBerd"
"Source" = "https://github.com/TodePond/DreamBerd"
"Bug Tracker" = "https://github.com/TodePond/DreamBerd/issues"

[tool.mypy]
mypy_path = "src"
check_untyped_defs = true
disallow_any_generics = true
disallow_untyped_calls = true
disallow_untyped_defs = true
ignore_missing_imports = true
no_implicit_optional = true
no_implicit_reexport = true
show_column_numbers = true
show_error_codes = true
strict = true
strict_equality = true
warn_redundant_casts = true
warn_return_any = true
warn_unreachable = true
warn_unused_configs = true
warn_unused_ignores = true

[tool.black]
target-version = ['py311']

[tool.isort]
profile = "black"
combine_as_imports = true
line_length = 79
skip = [".git", ".github", ".venv"]

[tool.pycln]
all = true
disable_all_dunder_policy = true
8 changes: 8 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
**Note:** This code is __under development__ and is not yet functional, let alone efficient.
# Comp-Trans-Piler
Running a perfect programming language requires a perfect compiler to run it. As such, the DreamBerd foundation has devised the next innovation in the field of compiling. The **Comp-Trans-Piler**.

The Comp-Trans-Piler works by independently compiling DreamBerd while at the same time transpiling it to JavaScript, maximizing efficiency while staying true to DreamBerd.

While the JavaScript compiler is extensive, it forgives barbaric practices such as loops, while at the same time lacking modern features such as Exact Equalities. As such DreamBerd first ensures that the code abides by the DreamBerd standard before passing it to lesser compilers.

Loading