Skip to content

Commit

Permalink
updated CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
aName2050 committed Apr 9, 2024
1 parent bee39d5 commit 41db32d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/GigaScript/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

export interface CLIArguments {
file: string;
useCUDA: boolean;
ASTOnly: boolean;
useCUDA: boolean | undefined;
ASTOnly: boolean | undefined;
debug: boolean | undefined;
}
61 changes: 54 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import { Program } from './GigaScript/ast/ast';
import { CLIArguments } from './GigaScript/types';
import { createGlobalScope } from './GigaScript/runtime/env';
import { evaluate } from './GigaScript/runtime/interpreter/interpreter';
import { getTokenByTypeEnum } from './GigaScript/tokens';
import { NodeType } from './GigaScript/nodes';
// import interpretor
// import env

Expand All @@ -28,24 +26,37 @@ argParser.add_argument('-v', '--version', {
});
argParser.add_argument('-f', '--file', {
metavar: 'FILE',
type: 'str',
type: String,
help: 'the file to run',
});
argParser.add_argument('--useCUDA', {
// action: 'enableCUDA',
help: 'enable CUDA for tokenization. Requires NVIDIA GPU with CUDA Cores.',
type: Boolean,
help: 'enable CUDA(R) for tokenization. Requires NVIDIA(R) GPU with CUDA(R) Cores.',
action: 'store_true',
});
argParser.add_argument('--ASTOnly', {
// action: 'disableEvaluation'
help: 'disables evaluation and only outputs the AST for debugging purposes.',
type: Boolean,
action: 'store_true',
});
argParser.add_argument('-d', '--debug', {
help: 'enables debug mode',
action: 'store_true',
});

const CLIArgs: CLIArguments = argParser.parse_args();
const file: string | undefined = CLIArgs.file;
const useCUDA: boolean = CLIArgs.useCUDA || false;
const ASTOnly: boolean = CLIArgs.ASTOnly || false;
const debug: boolean = CLIArgs.debug || false;

if (debug) {
console.log('GS.DEBUGGER: GigaScript Debugger v1');
}

if (useCUDA) {
throw 'Tokenization using NVIDIA(R) CUDA(R) Cores';
}

const fileLocation: string = file ? path.parse(file).dir : '';

Expand Down Expand Up @@ -76,12 +87,48 @@ function runFile(filename: string, location: string) {

if (filename.endsWith('.g')) {
// Run GigaScript code
const runtimeStart = Date.now();
const tokenizeStart = Date.now();

parser.tokenizeSource(file);

if (debug)
console.log(
`GS.DEBUGGER: source tokenized in ${
Date.now() - tokenizeStart
}ms`
);

const parseStart = Date.now();

const program: Program = parser.generateAST();

if (ASTOnly) return console.log(JSON.stringify(program));
if (debug)
console.log(
`GS.DEBUGGER: tokens parsed in ${Date.now() - parseStart}ms`
);

if (ASTOnly) {
if (debug)
console.log(
`GS.DEBUGGER: GigaScript ran in ${
Date.now() - runtimeStart
}ms`
);
return console.log(JSON.stringify(program));
}

const evalStart = Date.now();

const res = evaluate(program, env);
if (debug)
console.log(
`GS.DEBUGGER: AST evaluated in ${Date.now() - evalStart}ms`
);
if (debug)
console.log(
`GS.DEBUGGER: GigaScript ran in ${Date.now() - runtimeStart}ms`
);

return res;
} else if (filename.endsWith('.gsx')) {
Expand Down

0 comments on commit 41db32d

Please sign in to comment.