Improved source code business.

This commit is contained in:
Bruce Hill 2017-09-19 01:30:05 -07:00
parent b1b36fead5
commit a6cd8907c8
2 changed files with 37 additions and 15 deletions

View File

@ -90,7 +90,7 @@ rule:
|do
| local old_you = compiler.you
| compiler.you = vars.person
| ret = compiler:call('do %', vars.action)
| ret = vars.action(compiler, vars)
| compiler.you = old_you
|end
@ -100,22 +100,25 @@ say "===================================================="
# Unanimity for proposals
with secrets:
secret %approvals =: []
rule: pending proposal ..=:
secret %pending
rule: propose source %src ..=:
if (secret %pending):
error "A proposal is already pending."
secret %pending =: %src
secret %approvals =: []
say ".."
|Proposal\%src\
|Proposal:
|\%src\
macro block: propose %action ..=: ".."
|compiler:call("propose source %", \repr (%action's "src")\)
macro block: propose %action ..=:
%source =: source code from tree %action
".."
|compiler:call("propose source %", \repr %source\)
rule: with everyone's approval do %action ..=:
do (..)
eval ".."
|return: \%action\
run %action
rule: mark %who as approving ..=:
if (not (pending proposal)):
@ -131,9 +134,12 @@ with secrets:
# No one dissents
with everyone's approval do (pending proposal)
secret %pending =: nil
secret %approvals =: nil
rule: mark %who as rejecting ..=:
secret %pending =: nil
secret %approvals =: nil
rule:
approve
@ -173,13 +179,19 @@ say "Rule making is now restricted"
join
propose:
say "fart"
say "Hello world"
approve
propose:
say "Hello world again"
approve
propose:
give "democracy" 1 "possibility"
if ("democracy" has "possibility"):
say "DEMOCRACY WORKS!!!"
..else:
say "democracy has failed :("
approve
propose:

View File

@ -48,12 +48,21 @@ rule:
..=:
lua expr "compiler:run(vars.code)"
macro: source code %code ..=:
rule: source code from tree %tree ..=:
lua block ".."
|if vars.code.value.type ~= "Thunk" then
| compiler:error("'source code %' only takes code blocks, not "..vars.code.value.type)
|local _,_,leading_space = vars.tree.src:find("\\n(%s*)%S")
|if leading_space then
| local chunk1, chunk2 = vars.tree.src:match(":%s*([^\\n]*)(\\n.*)")
| chunk2 = chunk2:gsub("\\n"..leading_space, "\\n")
| vars.source = chunk1..chunk2.."\\n"
|else
| vars.source = vars.tree.src:match(":%s*(%S.*)").."\\n"
|end
lua expr "compiler.utils.repr(vars.code.value.value.src, true)"
%source
macro: source code %body ..=:
repr (source code from tree %body)
rule: run file %filename ..=:
lua block ".."
@ -71,11 +80,12 @@ rule: error %msg ..=:
|table.remove(compiler.callstack)
|compiler:error(vars.msg)
# TODO: Make useful
macro: as lua %block ..=:
lua expr "compiler.utils.repr(compiler:tree_to_lua(vars.block.value.value, vars), true)"
lua expr "compiler.utils.repr(compiler:tree_to_lua(vars.block.value.value, 'Statement'), true)"
macro block: show generated lua %block ..=:
".."|compiler:writeln(\lua expr "compiler.utils.repr(compiler:tree_to_lua(vars.block.value.value, vars), true)"\)
".."|compiler:writeln(\lua expr "compiler.utils.repr(compiler:tree_to_lua(vars.block.value.value, 'Statement'), true)"\)
# Macro helper functions
rule: %tree as value ..=: