Skip to content

Instantly share code, notes, and snippets.

@mildred
Created January 24, 2012 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mildred/1669653 to your computer and use it in GitHub Desktop.
Save mildred/1669653 to your computer and use it in GitHub Desktop.
Lizzy Syntax
var ::= exp
assign exp to var. Type of exp is set to var (type inference)
var := exp
var an already existing variable, with a type
set exp to var, check the type is correct statically
var :type := exp
var a new variable of type type
set exp to var, and check statically its type is conform
function_type ::= declare_special_type("function",
doc "a function"
)
caller_env ::= declare_special_type("caller_env",
doc "represents the caller's environment"
)
input_output_env ::= declare_type(
method("doc",
input(string_type,
doc "documentation about the input")
)
method("env",
inputs(type_type,
doc "the environments in which the function can be executed, if not specified, caller_env")
)
)
method_env ::= declare_type(
method("doc",
input(string_type,
doc "documentation about the method")
)
method("input",
doc "input"
input(type_type,
doc "the type accepted as an input argument")
input(function_type,
doc "the options to the function"
env(input_output_env, caller_env))
)
method("inputs",
doc "vararg inputs"
input(type_type,
doc "the type accepted as an input argument")
input(function_type,
doc "the options to the function"
env(input_output_env, caller_env))
)
method("output",
doc "output"
input(type_type,
doc "the type that is returned in this argument slot")
input(function_type,
doc "the options to the function"
env(input_output_env, caller_env))
)
method("outputs",
doc "vararg as outputs"
input(type_type,
doc "the type that is returned in these argument slot")
input(function_type,
doc "the options to the function"
env(input_output_env, caller_env))
)
method("return",
doc "declare the returned value, void by default"
input(type_type,
doc "the type that is returned")
input(function_type,
doc "the options to the function"
env(input_output_env, caller_env))
)
)
declare_type_env ::= declare_type(
method("method",
input(string_type,
doc "the name of the method")
input(function_type,
doc "the declaration of the function"
env(method_env, caller_env))
)
)
env ::= declare_type(
method("declare_type",
input(function_type,
env(declare_type_env, caller_env))
return(type_type)
)
)
function type(o)
t = _G.getmetatable(o)
if t then
return t.__type(o)
else
return _M.none_type
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment