diff --git a/sallyforth/0.sf b/sallyforth/0.sf index 2ee5de9..b032e18 100644 --- a/sallyforth/0.sf +++ b/sallyforth/0.sf @@ -15,7 +15,9 @@ \ Basic aliases -: ->inline { *last-word* inline } +: ->inline { *last-word* inline } +: ->static { false *last-word* dynamic } +: ->dynamic { true *last-word* dynamic } : -- { 1 - } ->inline : ++ { 1 + } ->inline diff --git a/sallyforth/basic_words.py b/sallyforth/basic_words.py index cb73f82..61296b3 100644 --- a/sallyforth/basic_words.py +++ b/sallyforth/basic_words.py @@ -10,6 +10,7 @@ def dynamic(forth): name = forth.stack.pop() isdyn = forth.stack.pop() var = forth.ns[name] + print(f'name: {name} var: {var} dyn: {isdyn}') var.dynamic = isdyn @word() @@ -25,6 +26,18 @@ def native(forth): wrapped_f = native_word(native_f, name, n, has_return) forth.set(name, wrapped_f) +@word("function") +def function_word(forth): + name = forth.stack.pop() + var = forth.ns[name] + word_f = var.value + def native_f(*args): + forth.stack.push(args) + word_f(forth) + result = forth.stack.pop() + return result + forth.stack.push(native_f) + @word('raise') def w_raise(forth): ex = forth.stack.pop() @@ -134,7 +147,7 @@ def stack(forth): @word() def ns(forth): print(forth.ns.name) - print(forth.ns.contents) + pprint(forth.ns.contents) @word(':', True) def colon(forth): @@ -147,6 +160,7 @@ def colon(forth): @word() def inline(forth): name = forth.stack.pop() + print('name', name) var = forth.ns[name] value = var.value if not value.forth_primitive: