Преглед на файлове

Simplify variable lookup and implicit variable declarations.

master
Ian Piumarta преди 11 месеца
родител
ревизия
4622db9d34
променени са 1 файла, в които са добавени 11 реда и са изтрити 18 реда
  1. +11
    -18
      minproto.leg

+ 11
- 18
minproto.leg Целия файл

@ -1,6 +1,6 @@
# minproto.leg -- minimal prototype langauge for semantic experiments
#
# last edited: 2024-05-29 11:05:04 by piumarta on zora
# last edited: 2024-05-29 14:20:52 by piumarta on zora
%{
;
@ -784,24 +784,21 @@ oop Object_get(oop obj, oop key)
oop *_refvar(oop obj, oop key)
{
while (is(Object, obj)) {
while (is(Object, obj)) { // look for a binding of key in the local scopes
ssize_t ind = Object_find(obj, key);
if (ind >= 0) return &_get(obj, Object,properties)[ind].val;
obj = _getDelegate(obj);
}
int numspaces = _get(namespaces, Object,isize);
if (numspaces) {
if (numspaces) { // look for a binding of key in the namespace stack
oop *nss = _get(namespaces, Object,indexed);
for (int i = numspaces; i--;) {
oop ns = nss[i];
while (is(Object, ns)) {
ssize_t ind = Object_find(ns, key);
if (ind >= 0) return &_get(ns, Object,properties)[ind].val;
ns = _getDelegate(ns);
}
ssize_t ind = Object_find(ns, key);
if (ind >= 0) return &_get(ns, Object,properties)[ind].val;
}
}
oop *ref = &_get(key, Symbol,value); // asserts is(Symbol,key)
oop *ref = &_get(key, Symbol,value); // use the global binding
return ref;
}
@ -822,18 +819,14 @@ oop Object_put(oop obj, oop key, oop val);
oop setvar(oop obj, oop key, oop val)
{
oop env = obj;
while (is(Object, env)) {
while (is(Object, env)) { // look for a binding of key in the local scopes
ssize_t ind = Object_find(env, key);
if (ind >= 0) return _get(env, Object,properties)[ind].val = val;
if (ind >= 0) return _get(env, Object,properties)[ind].val = val; // set it
env = _getDelegate(env);
}
int numspaces = _get(namespaces, Object,isize);
if (numspaces) {
oop *nss = _get(namespaces, Object,indexed);
return Object_put(nss[numspaces - 1], key, val);
}
if (nil != obj) return Object_put(obj, key, val);
return _get(key, Symbol,value) = val; // asserts is(Symbol,key)
return (nil == obj) // are we at the top level?
? _get(key, Symbol,value) = val // set a global variable
: Object_put(obj, key, val); // create a new local variable
}
oop Object_put(oop obj, oop key, oop val)

Зареждане…
Отказ
Запис