Skip to content

Commit 16606f9

Browse files
committed
Don't try and remember module path in functions
It doesn't work with inlining and the semantics are too hard to maintain when inlining. Update docs to match new (/actual in the case of inlined functions) behaviour.
1 parent 02da4cd commit 16606f9

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

docs/language.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -948,9 +948,12 @@ names](builtins.md) will be defined in a module, but not runtime names (such as
948948
values in an imported function they must be passed in as arguments. However,
949949
called functions *do* have access to the current [state](#state).
950950

951-
If a function in a module is called from the main program, and this function
952-
makes use of any file built-ins – such as `read()` – then these will load files
953-
relative to the *module* file.
951+
During execution of an imported module, any calls to [file
952+
built-ins](builtins.md#file-functions) – such as `read()` – will resolve
953+
filenames relative to the path of the module. However, if a function in a module
954+
is called from the main program, and that function calls any file built-ins,
955+
then these will resolve filenames relative to the path of the main program, not
956+
the module.
954957

955958
Modules may import from other modules, provided that a cycle is not created: if
956959
a module attempts to import a module further up the current import chain, then

src/flitter/language/vm.pyx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,6 @@ cdef class Function:
484484
cdef readonly tuple defaults
485485
cdef readonly Program program
486486
cdef readonly int64_t address
487-
cdef readonly object root_path
488487
cdef readonly bint record_stats
489488
cdef readonly tuple captures
490489
cdef readonly int64_t call_depth
@@ -501,7 +500,6 @@ cdef class Function:
501500
return null_
502501
cdef int64_t i, lnames_top, stack_top, k=PyTuple_GET_SIZE(self.captures), m=PyTuple_GET_SIZE(self.parameters), n=PyTuple_GET_SIZE(args)
503502
cdef PyObject* objptr
504-
cdef object saved_path
505503
if context.state is None:
506504
context.state = StateDict()
507505
cdef VectorStack lnames = context.lnames
@@ -522,8 +520,6 @@ cdef class Function:
522520
push(lnames, <Vector>objptr)
523521
else:
524522
push(lnames, <Vector>PyTuple_GET_ITEM(self.defaults, i))
525-
saved_path = context.path
526-
context.path = self.root_path
527523
self.call_depth += 1
528524
try:
529525
self.program._execute(context, self.address, self.record_stats)
@@ -533,7 +529,6 @@ cdef class Function:
533529
cdef Vector result = pop(stack)
534530
assert stack.top == stack_top, "Bad function return stack"
535531
assert lnames.top == lnames_top, "Bad function return lnames"
536-
context.path = saved_path
537532
return result
538533

539534

@@ -1386,7 +1381,6 @@ cdef class Program:
13861381
function.parameters = (<InstructionFunc>instruction).parameters
13871382
function.program = self
13881383
function.address = (<InstructionFunc>instruction).offset + pc
1389-
function.root_path = context.path
13901384
function.record_stats = record_stats
13911385
n = PyTuple_GET_SIZE(function.parameters)
13921386
function.defaults = pop_tuple(stack, n)

0 commit comments

Comments
 (0)