Skip to content

Commit 0f460d1

Browse files
committed
Nim 2.0.2
1 parent 662f572 commit 0f460d1

10 files changed

+106
-130
lines changed

enu.nimble

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ bin_dir = "app/_dlls"
2323
src_dir = "src"
2424
bin = @["enu" & lib_ext]
2525

26-
requires "nim >= 1.6.10",
27-
"https://github.com/dsrw/Nim#3b33173",
26+
requires "nim 2.0.2",
27+
"https://github.com/dsrw/Nim#ccf10a81f",
2828
"https://github.com/arnetheduck/nim-results#f3c666a",
2929
"https://github.com/dsrw/godot-nim#43addc1",
3030
"https://github.com/dsrw/model_citizen 0.19.0",

src/controllers/node_controllers.nim

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ proc find_nested_changes(parent: Change[Unit]) =
115115
elif Removed in change.changes:
116116
parent.item.set_global(false)
117117

118-
proc watch_units(self: NodeController, unit: Unit) =
118+
proc watch_units(self: NodeController, unit: Unit) {.gcsafe.} =
119119
unit.units.watch(unit):
120120
if added:
121121
change.item.fix_parents(unit)

src/controllers/script_controllers/host_bridge.nim

+5-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ proc get_build(self: Worker, a: VmArgs, pos: int): Build =
6363
Build(unit)
6464

6565
proc get_sign(self: Worker, a: VmArgs, pos: int): Sign =
66-
let unit = self.get_unit(a, pos)
67-
assert not unit.is_nil and unit of Sign
68-
Sign(unit)
66+
let pnode = a.get_node(pos)
67+
if pnode.kind != nkNilLit:
68+
let unit = self.get_unit(a, pos)
69+
assert not unit.is_nil and unit of Sign
70+
result = Sign(unit)
6971

7072
proc to_node(self: Worker, unit: Unit): PNode =
7173
if ?unit:

src/controllers/script_controllers/host_bridge_utils.nim

+21-20
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,26 @@ macro bridged_from_vm(self: Worker,
6060
arg_nodes = proc_impl[3][1..^1]
6161

6262
let args = collect:
63-
var pos = -1
64-
for ident_def in arg_nodes:
65-
let typ = ident_def[1].str_val
66-
if typ == $Worker.type:
67-
ident"script_engine"
68-
elif typ == "VmArgs":
69-
ident"a"
70-
elif typ == "ScriptCtx":
71-
quote do: script_engine.active_unit.script_ctx
72-
elif typ in ["Unit", "Bot", "Build", "Sign"]:
73-
let getter = "get_" & typ
74-
pos.inc
75-
new_call(bind_sym(getter), ident"script_engine",
76-
ident"a", new_lit(pos))
77-
78-
else:
79-
let getter = "get_" & typ
80-
pos.inc
81-
new_call(bind_sym(getter), ident"a", new_lit(pos))
63+
block:
64+
var pos = -1
65+
for ident_def in arg_nodes:
66+
let typ = ident_def[1].str_val
67+
if typ == $Worker.type:
68+
ident"script_engine"
69+
elif typ == "VmArgs":
70+
ident"a"
71+
elif typ == "ScriptCtx":
72+
quote do: script_engine.active_unit.script_ctx
73+
elif typ in ["Unit", "Bot", "Build", "Sign"]:
74+
let getter = "get_" & typ
75+
pos.inc
76+
new_call(bind_sym(getter), ident"script_engine",
77+
ident"a", new_lit(pos))
78+
79+
else:
80+
let getter = "get_" & typ
81+
pos.inc
82+
new_call(bind_sym(getter), ident"a", new_lit(pos))
8283

8384
var call = new_call(proc_ref, args)
8485
if return_node.kind == nnk_sym:
@@ -96,7 +97,7 @@ macro bridged_from_vm(self: Worker,
9697

9798
result.add quote do:
9899
mixin implement_routine
99-
`self`.interpreter.implement_routine "*", `module_name`, `proc_impl_name`,
100+
`self`.interpreter.implement_routine "enu", `module_name`, `proc_impl_name`,
100101
proc(a {.inject.}: VmArgs) {.gcsafe.} =
101102

102103
debug "calling routine", name = `proc_name`

src/controllers/script_controllers/worker.nim

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ proc watch_units(self: Worker,
126126
parent: Unit,
127127
body: proc(unit: Unit, change: Change[Unit], added: bool,
128128
removed: bool) {.gcsafe.}
129-
) =
129+
) {.gcsafe.} =
130130

131-
units.track proc(changes: seq[Change[Unit]]) =
131+
units.track proc(changes: seq[Change[Unit]]) {.gcsafe.} =
132132
for change in changes:
133133
let unit = change.item
134134
let added = Added in change.changes

src/game.nim

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import std / [monotimes, os, jsonutils, json, math, locks, random, net]
1+
import std / [monotimes, os, json, math, random, net]
22
import pkg / [godot, metrics, metrics / stdlib_httpserver]
33
from dotenv import nil
44
import godotapi / [input, input_event, gd_os, node, scene_tree, packed_scene,

src/libs/eval.nim

+69-89
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,31 @@ import compiler / [syntaxes, reorder, vmdef, msgs]
33
import compiler / passes {.all.}
44

55
{.warning[UnusedImport]: off.}
6-
include compiler / [nimeval]
6+
include compiler / [nimeval, pipelines]
77

88
export Interpreter, VmArgs, PCtx, PStackFrame, TLineInfo
99

10+
# NOTE: This file is mostly made up of modified functions pulled from the nim
11+
# compiler, and must be updated occasionally to keep up with changes to the vm.
12+
# To make diffing easier, the original casing has been preserved, so this file
13+
# is in `camelCase` rather than `snake_case` like the rest of the project.
14+
1015
# adapted from
11-
# https://github.com/nim-lang/Nim/blob/version-1-6/compiler/passes.nim#L120
12-
# Normal module loading procedure, but makes TPassContextArray a var param
13-
# so it can be passed to extend_module
16+
# https://github.com/nim-lang/Nim/blob/v2.0.2/compiler/pipelines.nim#L88
17+
# Normal module loading procedure, but makes PContext a param so it can be
18+
# passed to extend_module
1419
proc processModule*(graph: ModuleGraph; module: PSym; idgen: IdGenerator;
15-
stream: PLLStream, a: var TPassContextArray): bool {.discardable.} =
20+
stream: PLLStream, ctx: var PContext): bool {.discardable.} =
21+
1622
if graph.stopCompile(): return true
23+
let bModule = setupEvalGen(graph, module, idgen)
24+
1725
var
1826
p: Parser
1927
s: PLLStream
2028
fileIdx = module.fileIdx
29+
2130
prepareConfigNotes(graph, module)
22-
openPasses(graph, a, module, idgen)
2331
if stream == nil:
2432
let filename = toFullPathConsiderDirty(graph.config, fileIdx)
2533
s = llStreamOpen(filename, fmRead)
@@ -29,62 +37,42 @@ proc processModule*(graph: ModuleGraph; module: PSym; idgen: IdGenerator;
2937
else:
3038
s = stream
3139

32-
when defined(nimsuggest):
33-
let filename = toFullPathConsiderDirty(graph.config, fileIdx).string
34-
msgs.setHash(graph.config, fileIdx, $sha1.secureHashFile(filename))
35-
3640
while true:
37-
openParser(p, fileIdx, s, graph.cache, graph.config)
41+
syntaxes.openParser(p, fileIdx, s, graph.cache, graph.config)
3842

3943
if not belongsToStdlib(graph, module) or (belongsToStdlib(graph, module) and module.name.s == "distros"):
4044
# XXX what about caching? no processing then? what if I change the
4145
# modules to include between compilation runs? we'd need to track that
4246
# in ROD files. I think we should enable this feature only
4347
# for the interactive mode.
4448
if module.name.s != "nimscriptapi":
45-
processImplicits graph, graph.config.implicitImports, nkImportStmt, a, module
46-
processImplicits graph, graph.config.implicitIncludes, nkIncludeStmt, a, module
49+
processImplicitImports graph, graph.config.implicitImports, nkImportStmt, module, ctx, bModule, idgen
50+
processImplicitImports graph, graph.config.implicitIncludes, nkIncludeStmt, module, ctx, bModule, idgen
4751

48-
while true:
49-
if graph.stopCompile(): break
52+
checkFirstLineIndentation(p)
53+
block processCode:
54+
if graph.stopCompile(): break processCode
5055
var n = parseTopLevelStmt(p)
51-
if n.kind == nkEmpty: break
52-
if (sfSystemModule notin module.flags and
53-
({sfNoForward, sfReorder} * module.flags != {} or
54-
codeReordering in graph.config.features)):
55-
# read everything, no streaming possible
56-
var sl = newNodeI(nkStmtList, n.info)
56+
if n.kind == nkEmpty: break processCode
57+
# read everything, no streaming possible
58+
var sl = newNodeI(nkStmtList, n.info)
59+
sl.add n
60+
while true:
61+
var n = parseTopLevelStmt(p)
62+
if n.kind == nkEmpty: break
5763
sl.add n
58-
while true:
59-
var n = parseTopLevelStmt(p)
60-
if n.kind == nkEmpty: break
61-
sl.add n
62-
if sfReorder in module.flags or codeReordering in graph.config.features:
63-
sl = reorder(graph, sl, module)
64-
discard processTopLevelStmt(graph, sl, a)
65-
break
66-
elif n.kind in imperativeCode:
67-
# read everything until the next proc declaration etc.
68-
var sl = newNodeI(nkStmtList, n.info)
69-
sl.add n
70-
var rest: PNode = nil
71-
while true:
72-
var n = parseTopLevelStmt(p)
73-
if n.kind == nkEmpty or n.kind notin imperativeCode:
74-
rest = n
75-
break
76-
sl.add n
77-
#echo "-----\n", sl
78-
if not processTopLevelStmt(graph, sl, a): break
79-
if rest != nil:
80-
#echo "-----\n", rest
81-
if not processTopLevelStmt(graph, rest, a): break
82-
else:
83-
#echo "----- single\n", n
84-
if not processTopLevelStmt(graph, n, a): break
64+
65+
prePass(ctx, sl)
66+
var semNode = semWithPContext(ctx, sl)
67+
discard processPipeline(graph, semNode, bModule)
68+
8569
closeParser(p)
8670
if s.kind != llsStdIn: break
87-
closePasses(graph, a)
71+
72+
assert graph.pipelinePass == EvalPass
73+
let finalNode = closePContext(graph, ctx, nil)
74+
discard interpreterCode(bModule, finalNode)
75+
8876
if graph.config.backend notin {backendC, backendCpp, backendObjc}:
8977
# We only write rod files here if no C-like backend is active.
9078
# The C-like backends have been patched to support the IC mechanism.
@@ -130,8 +118,8 @@ proc resetModule*(i: Interpreter, moduleName: string) =
130118
iface.module.ast = nil
131119
break
132120

133-
proc loadModule*(i: Interpreter, fileName, code: string,
134-
a: var TPassContextArray) {.gcsafe.} =
121+
proc loadModule*(i: Interpreter, fileName, code: string, ctx: var PContext
122+
) {.gcsafe.} =
135123

136124
assert i != nil
137125

@@ -156,61 +144,53 @@ proc loadModule*(i: Interpreter, fileName, code: string,
156144
# which causes "cannot evaluate at compile time" issues with some variables.
157145
# Force things back to emRepl.
158146
PCtx(i.graph.vm).mode = emRepl
147+
148+
ctx = preparePContext(i.graph, module, i.idgen)
149+
159150
{.gcsafe.}:
160-
discard processModule(i.graph, module, i.idgen, stream, a)
151+
discard processModule(i.graph, module, i.idgen, stream, ctx)
161152

162153
# adapted from
163-
# https://github.com/nim-lang/Nim/blob/version-1-6/compiler/passes.nim#L120
164-
proc extendModule(graph: ModuleGraph; a: var TPassContextArray, module: PSym;
165-
idgen: IdGenerator; stream: PLLStream): bool {.discardable.} =
154+
# https://github.com/nim-lang/Nim/blob/v2.0.2/compiler/pipelines.nim#L88
155+
proc extendModule*(graph: ModuleGraph; module: PSym; idgen: IdGenerator;
156+
stream: PLLStream, ctx: var PContext): bool {.discardable.} =
166157

167158
if graph.stopCompile(): return true
159+
let bModule = setupEvalGen(graph, module, idgen)
160+
168161
var
169162
p: Parser
170163
s = stream
171164
fileIdx = module.fileIdx
172165

173166
while true:
174-
openParser(p, fileIdx, s, graph.cache, graph.config)
167+
syntaxes.openParser(p, fileIdx, s, graph.cache, graph.config)
175168

176-
while true:
177-
if graph.stopCompile(): break
169+
checkFirstLineIndentation(p)
170+
assert graph.pipelinePass == EvalPass
171+
block processCode:
172+
if graph.stopCompile(): break processCode
178173
var n = parseTopLevelStmt(p)
179-
if n.kind == nkEmpty: break
180-
if (sfSystemModule notin module.flags and
181-
({sfNoForward, sfReorder} * module.flags != {} or
182-
codeReordering in graph.config.features)):
183-
# read everything, no streaming possible
184-
var sl = newNodeI(nkStmtList, n.info)
185-
sl.add n
186-
while true:
187-
var n = parseTopLevelStmt(p)
188-
if n.kind == nkEmpty: break
189-
sl.add n
190-
191-
discard processTopLevelStmt(graph, sl, a)
192-
break
193-
elif n.kind in imperativeCode:
194-
# read everything until the next proc declaration etc.
195-
var sl = newNodeI(nkStmtList, n.info)
174+
if n.kind == nkEmpty: break processCode
175+
# read everything, no streaming possible
176+
var sl = newNodeI(nkStmtList, n.info)
177+
sl.add n
178+
while true:
179+
var n = parseTopLevelStmt(p)
180+
if n.kind == nkEmpty: break
196181
sl.add n
197-
var rest: PNode = nil
198-
while true:
199-
var n = parseTopLevelStmt(p)
200-
if n.kind == nkEmpty or n.kind notin imperativeCode:
201-
rest = n
202-
break
203-
sl.add n
204-
if not processTopLevelStmt(graph, sl, a): break
205-
if rest != nil:
206-
if not processTopLevelStmt(graph, rest, a): break
207-
else:
208-
if not processTopLevelStmt(graph, n, a): break
182+
183+
prePass(ctx, sl)
184+
185+
var semNode = semWithPContext(ctx, sl)
186+
discard processPipeline(graph, semNode, bModule)
187+
209188
closeParser(p)
210189
if s.kind != llsStdIn: break
190+
211191
result = true
212192

213-
proc eval*(i: Interpreter, a: var TPassContextArray, fileName, code: string) =
193+
proc eval*(i: Interpreter, ctx: var PContext, fileName, code: string) =
214194
## This can also be used to *reload* the script.
215195
assert i != nil
216196
var module: PSym
@@ -222,7 +202,7 @@ proc eval*(i: Interpreter, a: var TPassContextArray, fileName, code: string) =
222202

223203
assert module != nil, "no valid module selected"
224204
let s = llStreamOpen(code)
225-
extendModule(i.graph, a, module, i.idgen, s)
205+
extendModule(i.graph, module, i.idgen, s, ctx)
226206

227207
proc config*(i: Interpreter): ConfigRef = i.graph.config
228208

src/libs/interpreters.nim

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ proc run*(self: ScriptCtx): bool =
3939

4040
try:
4141
self.interpreter.load_module(self.file_name, self.code, self.pass_context)
42+
4243
result = false
4344
except VMPause:
4445
private_access ScriptCtx

src/types.nim

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import std / [tables, monotimes, sets, options, macros]
22
import godotapi / [spatial, ray_cast]
33
import pkg/core/godotcoretypes except Color
44
import pkg / core / [vector3, basis, aabb, godotbase]
5-
import pkg / compiler / passes {.all.}
6-
import pkg / compiler / [ast, lineinfos]
5+
import pkg / compiler / [ast, lineinfos, semdata]
76
import pkg / [model_citizen]
87
import models / colors, libs / [eval]
98

@@ -228,7 +227,7 @@ type
228227
interpreter*: Interpreter
229228
code*: string
230229
dependents*: HashSet[string]
231-
pass_context*: TPassContextArray
230+
pass_context*: PContext
232231
last_ran*: MonoTime
233232
file_index*: int
234233

tools/build_helpers.nim

+2-9
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import godotapigen
88
include "../installer/export_presets.cfg.nimf"
99
include "../installer/Info.plist.nimf"
1010

11-
const
12-
stdlib = find_nim_std_lib_compile_time()
13-
macros_url = "https://raw.githubusercontent.com/dsrw/Nim/v1.6.4-enu/lib/core/macros.nim"
11+
const stdlib = find_nim_std_lib_compile_time()
1412

1513
proc core_count = echo count_processors()
1614

@@ -34,15 +32,10 @@ proc copy_stdlib(destination: string) =
3432
for path in @["core", "pure", "std", "fusion", "system"]:
3533
copy_dir join_path(stdlib, path), join_path(destination, path)
3634

37-
for file in @["system.nim", "stdlib.nimble", "compilation.nim"]:
35+
for file in @["system.nim", "stdlib.nimble", "system" / "compilation.nim"]:
3836
copy_file join_path(stdlib, file),
3937
join_path(destination, file)
4038

41-
when (NimMajor, NimMinor) < (1, 7):
42-
var client = new_http_client()
43-
let macros_source = client.get_content(macros_url)
44-
write_file destination / "core" / "macros.nim", macros_source
45-
4639
proc run_tests =
4740
discard
4841

0 commit comments

Comments
 (0)