mirror of
https://github.com/russolsen/sallyforth
synced 2024-11-16 19:48:49 +01:00
Replace Ref with smarter Vars.
This commit is contained in:
parent
a1669f996c
commit
6c67d2350f
2 changed files with 3 additions and 33 deletions
|
@ -1,5 +1,5 @@
|
|||
from tokenstream import Token
|
||||
from wrappers import value_f, inner_f, inner2_f, inner3_f, ref_f, noop
|
||||
from wrappers import value_f, inner_f, inner2_f, inner3_f, noop
|
||||
from recoder import concat_functions
|
||||
|
||||
LBrace = Token('word', '{')
|
||||
|
@ -23,7 +23,7 @@ def compile_word(forth, w):
|
|||
if value.forth_immediate:
|
||||
return value(forth)
|
||||
elif var.dynamic:
|
||||
return ref_f(var)
|
||||
return var
|
||||
else:
|
||||
return value
|
||||
|
||||
|
|
|
@ -1,34 +1,3 @@
|
|||
class Reference:
|
||||
def __init__(self, var):
|
||||
self.var = var
|
||||
|
||||
def __call__(self, forth):
|
||||
#print("indirect call on", self.var.name)
|
||||
return self.var.value(forth)
|
||||
|
||||
@property
|
||||
def forth_immediate(self):
|
||||
return self.var.value.forth_immediate
|
||||
|
||||
@property
|
||||
def forth_contents(self):
|
||||
return self.var.value.forth_contents
|
||||
|
||||
@property
|
||||
def forth_primitive(self):
|
||||
return self.var.value.forth_primitive
|
||||
|
||||
@property
|
||||
def forth_name(self):
|
||||
return self.var.value.forth_name
|
||||
|
||||
@property
|
||||
def forth_inline(self):
|
||||
return self.var.value.forth_inline
|
||||
|
||||
def ref_f(var):
|
||||
return Reference(var)
|
||||
|
||||
def value_f(value):
|
||||
def push_constant(f):
|
||||
f.stack.push(value)
|
||||
|
@ -50,6 +19,7 @@ def inner_f(contents):
|
|||
|
||||
def inner2_f(f1, f2):
|
||||
def inner2(forth):
|
||||
#print('inner2:', f1, f2)
|
||||
f1(forth)
|
||||
f2(forth)
|
||||
inner2.forth_primitive = False
|
||||
|
|
Loading…
Reference in a new issue