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

View File

@ -48,12 +48,21 @@ rule:
..=: ..=:
lua expr "compiler:run(vars.code)" lua expr "compiler:run(vars.code)"
macro: source code %code ..=: rule: source code from tree %tree ..=:
lua block ".." lua block ".."
|if vars.code.value.type ~= "Thunk" then |local _,_,leading_space = vars.tree.src:find("\\n(%s*)%S")
| compiler:error("'source code %' only takes code blocks, not "..vars.code.value.type) |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 |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 ..=: rule: run file %filename ..=:
lua block ".." lua block ".."
@ -71,11 +80,12 @@ rule: error %msg ..=:
|table.remove(compiler.callstack) |table.remove(compiler.callstack)
|compiler:error(vars.msg) |compiler:error(vars.msg)
# TODO: Make useful
macro: as lua %block ..=: 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 ..=: 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 # Macro helper functions
rule: %tree as value ..=: rule: %tree as value ..=: