Skip to content

Commit

Permalink
feat: Refactor REPL method names and usage in
Browse files Browse the repository at this point in the history
interpreter classes

The commit renames the `run` methods in the `Program` and `BabyJs`
classes to `repl` to better reflect their functionality as
Read-Eval-Print-Loop functions. The usage of these methods is updated
throughout the codebase accordingly. This change enables improved
readability and clarity when interacting with the interpreter. No
notable issues were observed during testing.

Issue: N/A
  • Loading branch information
panzerstadt committed Dec 5, 2023
1 parent 91501ab commit 860deec
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion components/interpreter/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ export class Program {
}

this.clearStd();
return this.interpreter.run(code, this.verbose, true);
return this.interpreter.repl(code, this.verbose, true);
}
}
6 changes: 3 additions & 3 deletions programs/babyjs/babyjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ export class BabyJs {
}

runOnce(code: string | null, debug: boolean = false) {
this.run(code, debug, true);
this.repl(code, debug, true);
}
/**
* when the interpreter stores global variables.
* Those variables should persist throughout the REPL session.
*/
run(code: string | null = null, debug: boolean = false, once: boolean = false) {
repl(code: string | null = null, debug: boolean = false, once: boolean = false) {
if (!code) return this.nextLoop(debug, once);

// 1. scan text, turn them into tokens that the language recognizes
Expand Down Expand Up @@ -94,7 +94,7 @@ export class BabyJs {
return;
}

this.run(nextCode, debug);
this.repl(nextCode, debug);
}

runFile(filepath: string) {
Expand Down
2 changes: 1 addition & 1 deletion programs/babyjs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ const baby = new BabyJs();
// const initialTest = "print 0 + 3 / (2 * 5);";
const initialTest = `let test = "hello world";`;
console.log("running initial test of: ", initialTest);
baby.run(initialTest, true);
baby.repl(initialTest, true);
6 changes: 3 additions & 3 deletions programs/dagdog/dagdog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ export class DagDog {
}

runOnce(code: string | null, debug: boolean = false) {
this.run(code, debug, true);
this.repl(code, debug, true);
}
/**
* when the interpreter stores global variables.
* Those variables should persist throughout the REPL session.
*/
run(code: string | null = null, debug: boolean = false, once: boolean = false) {
repl(code: string | null = null, debug: boolean = false, once: boolean = false) {
if (!code) return this.nextLoop(debug, once);

// 1. scan text, turn them into tokens that the language recognizes
Expand Down Expand Up @@ -94,7 +94,7 @@ export class DagDog {
return;
}

this.run(nextCode, debug);
this.repl(nextCode, debug);
}

runFile(filepath: string) {
Expand Down
2 changes: 1 addition & 1 deletion programs/dagdog/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ const puppy = new DagDog();
// const initialTest = "print 0 + 3 / (2 * 5);";
const initialTest = `let test = "hello world";`;
console.log("running initial test of: ", initialTest);
puppy.run(initialTest, true);
puppy.repl(initialTest, true);

0 comments on commit 860deec

Please sign in to comment.