mirror of
https://github.com/kanaka/mal.git
synced 2024-09-11 13:55:55 +03:00
Merge pull request #494 from alimpfard/master
[jq impl] fix atoms not leaking out of let* (related to pr #493)
This commit is contained in:
commit
f5ee114f00
45
jq/env.jq
45
jq/env.jq
@ -174,21 +174,9 @@ def env_req(env; key):
|
||||
end;
|
||||
|
||||
def env_set(env; $key; $value):
|
||||
(if $value.kind == "function" or $value.kind == "atom" then
|
||||
(if $value.kind == "function" then
|
||||
# inform the function/atom of its names
|
||||
$value | (.names += [$key]) | (.names |= unique) |
|
||||
if $value.kind == "atom" then
|
||||
# check if the one we have is newer
|
||||
env_req(env; $key) as $ours |
|
||||
if $ours.last_modified > $value.last_modified then
|
||||
$ours
|
||||
else
|
||||
# update modification timestamp
|
||||
$value | .last_modified |= now
|
||||
end
|
||||
else
|
||||
.
|
||||
end
|
||||
$value | (.names += [$key]) | (.names |= unique)
|
||||
else
|
||||
$value
|
||||
end) as $value | {
|
||||
@ -268,17 +256,26 @@ def addToEnv(envexp; name):
|
||||
|
||||
def _env_remove_references(refs):
|
||||
if . != null then
|
||||
{
|
||||
environment: (.environment | to_entries | map(select(.key as $key | refs | contains([$key]) | not)) | from_entries),
|
||||
parent: (.parent | _env_remove_references(refs)),
|
||||
fallback: (.fallback | _env_remove_references(refs))
|
||||
}
|
||||
if .environment == null then
|
||||
_debug("This one broke the rules, officer: \(.)")
|
||||
else
|
||||
{
|
||||
environment: (.environment | to_entries | map(select(.key as $key | refs | contains([$key]) | not)) | from_entries),
|
||||
parent: (.parent | _env_remove_references(refs)),
|
||||
fallback: (.fallback | _env_remove_references(refs))
|
||||
}
|
||||
end
|
||||
else . end;
|
||||
|
||||
def env_remove_references(refs):
|
||||
. as $env
|
||||
| if has("replEnv") then
|
||||
.currentEnv |= _env_remove_references(refs)
|
||||
else
|
||||
_env_remove_references(refs)
|
||||
end;
|
||||
| if (refs|length == 0) then
|
||||
# optimisation: most functions are purely lexical
|
||||
$env
|
||||
else
|
||||
if has("replEnv") then
|
||||
.currentEnv |= _env_remove_references(refs)
|
||||
else
|
||||
_env_remove_references(refs)
|
||||
end
|
||||
end;
|
@ -9,7 +9,7 @@ from sys import argv
|
||||
import fcntl
|
||||
|
||||
DEBUG = False
|
||||
HALT = False
|
||||
HALT = False
|
||||
|
||||
# Bestow IO upon jq
|
||||
|
||||
@ -63,7 +63,7 @@ def get_one(fd):
|
||||
if s == "":
|
||||
return None
|
||||
return s.decode('utf-8')
|
||||
|
||||
|
||||
|
||||
def main(args):
|
||||
args = [
|
||||
@ -109,4 +109,4 @@ def main(args):
|
||||
print("RTS Error:", e)
|
||||
|
||||
|
||||
main(argv[1:])
|
||||
main(argv[1:])
|
||||
|
@ -115,7 +115,7 @@ def EVAL(env):
|
||||
($value[2] | find_free_references($currentEnv | env_dump_keys + $binds)) as $free_referencess | {
|
||||
kind: "function",
|
||||
binds: $binds,
|
||||
env: (env | env_remove_references($free_referencess)),
|
||||
env: ($_menv | env_remove_references($free_referencess)),
|
||||
body: $value[2],
|
||||
names: [], # we can't do that circular reference thing
|
||||
free_referencess: $free_referencess # for dynamically scoped variables
|
||||
|
@ -149,7 +149,7 @@ def EVAL(env):
|
||||
($value[2] | find_free_references($currentEnv | env_dump_keys + $binds)) as $free_referencess | {
|
||||
kind: "function",
|
||||
binds: $binds,
|
||||
env: (env | env_remove_references($free_referencess)),
|
||||
env: ($_menv | env_remove_references($free_referencess)),
|
||||
body: $value[2],
|
||||
names: [], # we can't do that circular reference thing
|
||||
free_referencess: $free_referencess # for dynamically scoped variables
|
||||
|
@ -241,7 +241,7 @@ def EVAL(env):
|
||||
($value[2] | find_free_references($currentEnv | env_dump_keys + $binds)) as $free_referencess | {
|
||||
kind: "function",
|
||||
binds: $binds,
|
||||
env: (env | env_remove_references($free_referencess)),
|
||||
env: ($_menv | env_remove_references($free_referencess)),
|
||||
body: $value[2],
|
||||
names: [], # we can't do that circular reference thing
|
||||
free_referencess: $free_referencess, # for dynamically scoped variables
|
||||
|
@ -270,7 +270,7 @@ def EVAL(env):
|
||||
($value[2] | find_free_references($currentEnv | env_dump_keys + $binds)) as $free_referencess | {
|
||||
kind: "function",
|
||||
binds: $binds,
|
||||
env: (env | env_remove_references($free_referencess)),
|
||||
env: ($_menv | env_remove_references($free_referencess)),
|
||||
body: $value[2],
|
||||
names: [], # we can't do that circular reference thing
|
||||
free_referencess: $free_referencess, # for dynamically scoped variables
|
||||
|
@ -276,7 +276,7 @@ def EVAL(env):
|
||||
($value[2] | find_free_references($currentEnv | env_dump_keys + $binds)) as $free_referencess | {
|
||||
kind: "function",
|
||||
binds: $binds,
|
||||
env: $_menv,
|
||||
env: ($_menv | env_remove_references($free_referencess)),
|
||||
body: $value[2],
|
||||
names: [], # we can't do that circular reference thing
|
||||
free_referencess: $free_referencess, # for dynamically scoped variables
|
||||
|
Loading…
Reference in New Issue
Block a user