Skip to content

Commit beb95aa

Browse files
committed
update
Signed-off-by: George Lemon <georgelemon@protonmail.com>
1 parent 695953d commit beb95aa

4 files changed

Lines changed: 19 additions & 16 deletions

File tree

src/vancode/interpreter/ast.nim

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ proc add*(node, child: Node): Node {.discardable.} =
173173
node.children.add(child)
174174
result = node
175175

176-
proc add*(node: Node, children: openarray[Node]): Node {.discardable.} =
176+
proc add*(node: Node, children: openArray[Node]): Node {.discardable.} =
177177
node.children.add(children)
178178
result = node
179179

@@ -190,13 +190,16 @@ proc hash*(node: Node): Hash =
190190
of nkIdent: h = h !& hash(node.ident)
191191
else:
192192
h = h !& hash(node.len)
193-
h = h !& hash(node.children)
193+
for child in node.children: # guard nil children (e.g. nkInfix operator slot)
194+
if child != nil:
195+
h = h !& hash(child)
194196
result = h
195197

196198
proc `$`*(node: Node): string =
197199
## Stringify a node. This only supports leaf nodes, for trees,
198-
## use ``treeRepr``.
199-
assert node.kind in LeafNodes, "only leaf nodes can be `$`'ed. Got " & $node.kind
200+
## use `treeRepr`.
201+
assert node.kind in LeafNodes,
202+
"only leaf nodes can be `$`'ed. Got " & $node.kind
200203
result =
201204
case node.kind
202205
of nkBool: $node.boolVal

src/vancode/interpreter/codegen.nim

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ type
6868

6969
CodeGen* {.acyclic.} = ref object
7070
## a code generator for a module or proc.
71-
includePath: Option[string]
71+
includeBasePath: Option[string]
7272
## the base path for including partials
7373
script: Script
7474
# the script all procs go into
@@ -1547,7 +1547,9 @@ proc genProc*(node: Node, isInstantiation = false): Sym {.codegen.} =
15471547
# add the proc into the script
15481548
gen.script.procs.add(theProc)
15491549
if sym.procExport:
1550-
# export the proc if needed (exported procs need to be in procsExport for the runtime to find them, but they also need to be in procs for the compiler to compile them, so we add them to both)
1550+
# export the proc if needed (exported procs need to be in procsExport
1551+
# for the runtime to find them, but they also need to be in procs for
1552+
# the compiler to compile them, so we add them to both)
15511553
gen.script.procsExport.add(theProc)
15521554

15531555
# compile the proc's body
@@ -2328,13 +2330,13 @@ proc genImport*(node: Node) {.codegen.} =
23282330

23292331
# generate the module's script based
23302332
# on the parsed module AST program
2331-
moduleGen.genScript(astProgram, gen.includePath)
2333+
moduleGen.genScript(astProgram, gen.includeBasePath)
23322334

23332335
# once the module is generated, we can load it
23342336
# into the current module
23352337
if not gen.module.load(moduleGen.module, fromOtherModule = true):
23362338
node.warn(WarnModuleAlreadyImported % pathNode.stringVal)
2337-
2339+
23382340
# add the module to the current script's modules
23392341
gen.script.scripts[importChunk.file] = moduleGen.script
23402342

@@ -2343,13 +2345,13 @@ proc genImport*(node: Node) {.codegen.} =
23432345
gen.chunk.emit(gen.chunk.getString(importChunk.file))
23442346

23452347
of nkInclude:
2346-
if gen.includePath.isSome:
2347-
# if the include path is set,
2348-
# we can use it to resolve the module
2349-
path = absolutePath(gen.includePath.get() / path)
2348+
if gen.includeBasePath.isSome:
2349+
# if the include path is set, we can use it to resolve the module
2350+
path = absolutePath(gen.includeBasePath.get() / path)
23502351

23512352
# resolve the module's path
23522353
let aFile = absolutePath(gen.module.src.get())
2354+
23532355
try:
23542356
gen.resolver.resolveFile(aFile, path)
23552357
except ResolverError as e:
@@ -2429,7 +2431,7 @@ proc genBlock*(node: Node, isStmt: bool): Sym {.codegen.} =
24292431
proc genScript*(program: Ast, includePath: Option[string],
24302432
emitHalt: static bool = true) {.codegen.} =
24312433
## Generates the code for a full script.
2432-
gen.includePath = includePath
2434+
gen.includeBasePath = includePath
24332435
for node in program.nodes:
24342436
gen.genStmt(node)
24352437
when emitHalt == true:

src/vancode/interpreter/sym.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ type
137137
of ttyHtmlElement: discard
138138
of ttyPointer:
139139
pointerTarget*: Sym ## The type this pointer points to (type info only)
140-
else: discard # other types don't have any special fields
140+
else: discard # other types don't have any special fields
141141
of skHtmlType:
142142
tag*, innerText*: string ## the tag of the HTML element (e.g., "div", "span", etc.)
143143
isVoidElement*: bool ## whether this HTML element is a void element or not (e.g., "img", "br", etc.)

src/vancode/manager/remote.nim

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
import std/[tables, httpcore, httpclient, os, strutils, base64]
88
import pkg/openparser/dotenv
9-
10-
from std/os import existsEnv, getEnv
119
export base64
1210

1311
type

0 commit comments

Comments
 (0)