1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-27 16:49:31 +00:00

Changed a few things

- Bumped to 0.15.0
- Add boot script
- Change variable definition syntax, using a = to distinguish more cleary between identifier and value
- Variables initial values are evaluated on first use instead of at parsing time
- Error on variable redefinition. Means you should make sure to load saves after your scripts.
- Improve string parsing, support for escape codes
- Remove support for number literals with empty decimal part (42. for 42.0) as there's no distinction in Anselme and it conflicts with .function call suffix
- Changed priority of : pair operator
- Add type type, and type annotations to variables and function parameters
- Change Lua function system to use regular Anselme functions
  - Defining a function from Lua is now way simpler and require providing a full Anselme function signature
- Change Anselme function system
  - Dynamic dispatch, based on arity, type annotation and parameter names. Will select the most specific function at runtime.
  - Define way to overload most operators
  - Allow custom type to text formatters
  - Allow assignment to custom functions
  - Index operator ( renamed to ()
  - Functions with parameters each have their own private namespace (scoping ersatz)
  - Internal: "custom"-mode operators now have their own expression AST type instead of cluttering the function system
- Remove static type checker as it is barely useful with new function system. May or may not rewrite one in the future.
- Improve error messages here and there
- Internal: cleaning
This commit is contained in:
Étienne Fildadut 2021-06-03 15:29:25 +02:00
parent 4b139019c9
commit 64bc85741a
86 changed files with 2096 additions and 1012 deletions

View file

@ -88,6 +88,8 @@ if args.script then
elseif t == "choice" then
print(format_text(d, "\n> "))
istate:choose(io.read())
elseif t == "error" then
print(t, d)
else
print(t, inspect(d))
end
@ -110,51 +112,38 @@ else
vm:setaliases("seen", "checkpoint", "reached")
vm:loadfunction {
-- custom event test
["wait"] = {
{
arity = 1, types = { "number" },
value = function(duration)
coroutine.yield("wait", duration)
end
}
["wait(time::number)"] = {
value = function(duration)
coroutine.yield("wait", duration)
end
},
-- run another function in parallel
["run"] = {
{
arity = 1, types = { "string" },
value = function(str)
local istate, e = anselme.running.vm:run(str, anselme.running:current_namespace())
if not istate then coroutine.yield("error", e) end
local event, data = istate:step()
coroutine.yield(event, data)
end
}
["run(name::string)"] = {
value = function(str)
local istate, e = anselme.running.vm:run(str, anselme.running:current_namespace())
if not istate then coroutine.yield("error", e) end
local event, data = istate:step()
coroutine.yield(event, data)
end
},
-- manual choice
choose = {
{
arity = 1, types = { "number" },
value = function(c)
anselme.running:choose(c)
end
}
["choose(choice::number)"] = {
value = function(c)
anselme.running:choose(c)
end
},
-- manual interrupt
interrupt = {
{
arity = 1, types = { "string" },
value = function(str)
anselme.running:interrupt(str)
coroutine.yield("wait", 0)
end
},
{
arity = 0,
value = function()
anselme.running:interrupt()
coroutine.yield("wait", 0)
end
}
["interrupt(name::string)"] = {
value = function(str)
anselme.running:interrupt(str)
coroutine.yield("wait", 0)
end
},
["interrupt()"] = {
value = function()
anselme.running:interrupt()
coroutine.yield("wait", 0)
end
}
}
local state, err = vm:loadfile(file, namespace)