#Not sure whats even going on

36 messages · Page 1 of 1 (latest)

jade geyser
#
import Parser from "./frontend/parser.ts";
import { createGlobalEnv } from "./runtime/environment.ts";
import { evaluate } from "./runtime/interpreter.ts";

async function run(filename: string) {
  const parser = new Parser();
  const env = createGlobalEnv();

  try {

    if (!filename.toLowerCase().endsWith(".cvs")) {
      console.error("Invalid file type. You must provide a CVSCode file (.cvs).");
      return;
    }

    const input = await Deno.readTextFile(filename);
    const program = parser.produceAST(input);

    const result = evaluate(program, env);
    // console.log(result);
  } catch (error) {
    console.error(`Error reading or evaluating file: ${error.message}`);
  }
}

async function repl() {
  const parser = new Parser();
  const env = createGlobalEnv();
  console.log("\nRepl v0.3");

  // Continue Repl Until User Stops Or Types `exit`
  while (true) {
    const input = prompt("> ");

    // Check for no user input or exit keyword.
    if (!input || input.includes("exit")) {
      Deno.exit(1);
    }

    if(input == "clear") {
      console.clear();
      console.log("\nRepl v0.3");

      continue;
    }

    // Check if the input contains the "run" keyword.
    if (input.includes("run")) {

      // Extract the filename from the input.
      const fileNameMatch = input.match(/run\s+(\S+)/);
      if (fileNameMatch) {

        const fileName = fileNameMatch[1];

        await run(fileName);

        continue;
      } else {
        console.error("Invalid run command. Use 'run <filename>.cvs'.");

        continue; // Prompt for the next input.
      }
    }

    const program = parser.produceAST(input);

    const result = evaluate(program, env);

    console.log(result);
  }
}

await repl();

I have a Repl in ts, but it only works if i run it through vscode?

if i run it through cmd it just doesnt process anything like the run <filename> command just freezes.

calm oak
#

@jade geyser is that a Deno program?

#

you have .ts imports, which isn't common when writing TS code for nodejs/targets other than Deno

#

nvm, just saw the Deno.readTextFile

drowsy stump
#

@jade geyser can you be more specific? you say "the run <filename> command", what actual command are you running?

calm oak
#

deno run file.ts?

jade geyser
#

it works perfectly in vscode

jade geyser
drowsy stump
#

sorry, but can you be even more specific?

  1. you open a terminal
  2. ???
  3. program is frozen
    we need to know what ??? is in order to have any chance of helping. ideally you'd provide a minimum reproducible example so we could see the issue for ourselves, but short of that any additional details would help
jade geyser
#

Then inside that repl i do "run <filename>.cvs""

#

and it seems to freeze.

#

It works perfectly in vscode powershell

#

I am using windows powershell in the same dir but it doesnt work still.

drowsy stump
#

how far does it get? if you put a console.log before and after your await run(fileName) line, do you see both? (my guess is no, you'll see the one before but not after)

#

and if you sprinkle more logging in run, how far does it get there? which specific line is hanging?

jade geyser
#

Yeah, it doesnt reach the console.log before the await run for some reason.

#

So the program still works if you dont add an arguement.

#

As soon as i run the command in my cmd it still does NOTHING, BUT when i do ctrl+c it will show SOME output.

C:\Users\cvs0_\Documents\GitHub\CVSCode>deno run -A main.ts

Repl v0.3

run test.cvs
Checking filename.
Running file: test.cvs
^C
C:\Users\cvs0_\Documents\GitHub\CVSCode>

drowsy stump
#

really you should just get as much info as you can up to the point where it freezes. you should be able to identify exactly what line is hanging (e.g. does execution ever make it into evaluate or is the problem before that?)

jade geyser
#

Yeah i have done that. I have reason to believe its an issue with the parsing of the filename arg, as it will work as intended without a <filename>.cvs arg, same as every other command.

drowsy stump
#

what directory is this relative to? maybe it's just a difference of the working directory from which you run the program?

#

also seems like you're using the default command prompt? i dunno much about programming on windows but does VSCode use WSL or whatever it's called these days? if so that's a totally different environment

jade geyser
#

Oh actually?

jade geyser
#

Its using powershell for me. But i even switched to default CMD inside vscode and it worked normally.

#

And trying to run it through powershell, not inside vscode had the same issue too.

drowsy stump
#

have you narrowed down exactly what line it's hanging on?

jade geyser
#

Nope.

#

Ive been trying.

drowsy stump
#

if you attach a debugger you should be able to step through your code. eventually you'll get to a point where things freeze or you'll see it looping forever and you can see where that happens

#

or if you sprinkle console.log statements all over the place you should be able to see how far it gets based on the output

jade geyser
#

Yeah i did the console.log.