Skip to content

Commit

Permalink
(fmt) run formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
xTrayambak committed Sep 28, 2024
1 parent 17b3d4d commit eb0bd03
Show file tree
Hide file tree
Showing 36 changed files with 795 additions and 830 deletions.
14 changes: 7 additions & 7 deletions bali.nimble
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Package

version = "0.3.0"
author = "xTrayambak"
description = "The Bali JavaScript Engine"
license = "MIT"
srcDir = "src"
backend = "cpp"
version = "0.3.0"
author = "xTrayambak"
description = "The Bali JavaScript Engine"
license = "MIT"
srcDir = "src"
backend = "cpp"

# Dependencies

Expand Down Expand Up @@ -33,4 +33,4 @@ task test262, "Compile the Test262 suite tester against Bali":

exec "nim c -d:release --path:src -o:./test262 tests/test262.nim"

requires "https://github.com/ferus-web/sanchar >= 2.0.0"
requires "https://github.com/ferus-web/sanchar >= 2.0.0"
1 change: 1 addition & 0 deletions src/bali.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

51 changes: 23 additions & 28 deletions src/bali/balde.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import bali/internal/sugar
import bali/runtime/prelude
import climate, colored_logger, jsony, pretty

var
var
enableProfiler = false
profile = initTable[string, int64]()

proc enableLogging {.inline.} =
proc enableLogging() {.inline.} =
addHandler newColoredLogger()

template profileThis(task: string, body: untyped) =
Expand All @@ -24,7 +24,7 @@ template profileThis(task: string, body: untyped) =
start = getMonoTime()

body

if enableProfiler:
let ant = getMonoTime()
profile[task] = inMilliseconds(ant - start)
Expand All @@ -42,47 +42,46 @@ proc execFile(ctx: Context, file: string) {.inline.} =
profileThis "execFile() sanity checks":
if not fileExists(file):
die "file not found:", file

let perms = getFilePermissions(file)
if fpGroupRead notin perms and fpUserRead notin perms:
die "access denied:", file

profileThis "read source file":
let source = try:
readFile(file)
except IOError as exc:
die "failed to open file:", exc.msg
""
let source =
try:
readFile(file)
except IOError as exc:
die "failed to open file:", exc.msg
""

if ctx.cmdOptions.contains("dump-tokens"):
let excludeWs = ctx.cmdOptions.contains("no-whitespace")
let tok = newTokenizer(source)
while not tok.eof:
if excludeWs:
let val = tok.nextExceptWhitespace()
if !val: break
if !val:
break
print &val
else:
print tok.next()

quit(0)

profileThis "allocate parser":
profileThis "allocate parser":
let parser = newParser(source)

profileThis "parse source code":
let ast = parser.parse()

if ctx.cmdOptions.contains("dump-ast"):
print ast
quit(0)

profileThis "allocate runtime":
let runtime = newRuntime(
file, ast,
InterpreterOpts(
test262: ctx.cmdOptions.contains("test262")
)
file, ast, InterpreterOpts(test262: ctx.cmdOptions.contains("test262"))
)

profileThis "execution time":
Expand All @@ -95,28 +94,24 @@ proc baldeRun(ctx: Context): int =
if not ctx.cmdOptions.contains("verbose") or ctx.cmdOptions.contains("v"):
setLogFilter(lvlWarn)

enableProfiler = ctx.cmdOptions.contains("enable-profiler") or ctx.cmdOptions.contains("P")
enableProfiler =
ctx.cmdOptions.contains("enable-profiler") or ctx.cmdOptions.contains("P")

ctx.arg:
execFile(ctx, arg)
do:
die "`run` requires a file to evaluate."

proc main {.inline.} =
proc main() {.inline.} =
enableLogging()

const commands = {
"run": baldeRun
}
const commands = {"run": baldeRun}

let value = parseCommands(commands)

if enableProfiler:
writeFile(
"balde_profiler.txt",
toJson profile
)

writeFile("balde_profiler.txt", toJson profile)

quit(value)

when isMainModule:
Expand Down
30 changes: 14 additions & 16 deletions src/bali/grammar/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import bali/internal/sugar
import pretty
import ./[statement, scopes]

type
AST* = ref object
currentScope*: int
scopes*: seq[Scope]
type AST* = ref object
currentScope*: int
scopes*: seq[Scope]

doNotEvaluate*: bool = false # For Test262
doNotEvaluate*: bool = false # For Test262

proc `&=`*(ast: AST, scope: Scope) =
ast.scopes &= scope
Expand All @@ -31,23 +30,22 @@ proc append*(ast: AST, name: string, stmt: Statement) =
if fn.name == name:
fn.stmts &= stmt
return

raise newException(ValueError, "No such scope: " & name)

iterator items*(ast: AST): Scope =
for scope in ast.scopes:
yield scope

func function*(name: string, stmts: seq[Statement], args: seq[string]): Function {.inline.} =
Function(
name: name,
stmts: stmts,
arguments: args
)
func function*(
name: string, stmts: seq[Statement], args: seq[string]
): Function {.inline.} =
Function(name: name, stmts: stmts, arguments: args)

proc newAST*: AST {.inline.} =
proc newAST*(): AST {.inline.} =
AST(
scopes: @[
Scope() # top-level scope
]
scopes:
@[
Scope() # top-level scope
]
)
Loading

0 comments on commit eb0bd03

Please sign in to comment.