Dirty awful hacks to get exec working

This commit is contained in:
Reid 'arrdem' McKenzie 2021-08-21 21:38:42 -06:00
parent 726870be94
commit 7ef2f53db8
4 changed files with 88 additions and 71 deletions

View file

@ -6,6 +6,9 @@ py_project(
py_requirement("pyyaml"), py_requirement("pyyaml"),
py_requirement("markdown"), py_requirement("markdown"),
], ],
main_deps = [
py_requirement("prompt-toolkit"),
],
test_deps = [ test_deps = [
py_requirement("hypothesis"), py_requirement("hypothesis"),
], ],

View file

@ -1,4 +1,4 @@
!def[pitch, md[]] !def[pitch, md]
# The Lilith Pitch # The Lilith Pitch
Code is more than .. just code for the compiler. Code is more than .. just code for the compiler.
@ -14,7 +14,7 @@ idea: the parser is going to IGNORE stuff by default.
Let's build an M-expression syntax with support for multiple co-equal languages and fragments/scopes with a meta-syntax allowing for references between them and consuming fragment-notation-defined blocks? (FIXME: better word?) Let's build an M-expression syntax with support for multiple co-equal languages and fragments/scopes with a meta-syntax allowing for references between them and consuming fragment-notation-defined blocks? (FIXME: better word?)
!def[sytnax, md[]] !def[syntax, md]
\![] bang-brackets is a meta-syntactic directive used both by the lil tangler and the lil object language. \![] bang-brackets is a meta-syntactic directive used both by the lil tangler and the lil object language.
@ -34,9 +34,16 @@ FIXME: we need bare words, we need strings
FIXME: We need the object language FIXME: We need the object language
!def[openapi, yaml[]] !def[openapi, yaml]
---
openapi: 3.1.0
!def[main, lang[lilith]] !def[join, py]
; is importing a bang-operation? return lambda s, frags: s.join(frags)
print[str.join["", [pitch, syntax]]] !def[md, py]
from markdown import markdown
return lambda *args, body=None, **kwargs: markdown(body)
!def[main, lil]
print[join["\n", [pitch, syntax]]]

View file

@ -40,6 +40,7 @@ def repl(opts, args, runtime):
session = PromptSession(history=FileHistory(".lilith.history")) session = PromptSession(history=FileHistory(".lilith.history"))
module = Module( module = Module(
"__repl__", "__repl__",
[],
{}, {},
) )
@ -143,7 +144,11 @@ if __name__ == "__main__":
def py(runtime=None, module=None, expr=None, body=None, name=None): def py(runtime=None, module=None, expr=None, body=None, name=None):
"""The implementation of the Python lang as an eval type.""" """The implementation of the Python lang as an eval type."""
return eval(body) g = globals().copy()
l = {}
body = f"def _shim():\n" + "\n".join(" " + l for l in body.splitlines()) + "\n\n_escape = _shim()"
exec(body, g, l)
return l["_escape"]
def lil(runtime=None, module=None, expr=None, body=None, name=None): def lil(runtime=None, module=None, expr=None, body=None, name=None):
"""The implementation of the Lilith lang as an eval type.""" """The implementation of the Lilith lang as an eval type."""

View file

@ -1,131 +1,133 @@
!import[lilith.bootstrap, [py, lil]] !import[lilith.bootstrap, [py, lil]]
!def[lil, lilith.bootstrap.lil] !def[lil, lilith.bootstrap.lil]
lilith.bootstrap.lil lilith.bootstrap.lil
!def[py, lilith.bootstrap.lil]
lilith.bootstrap.py
!def[abs, py] !def[abs, py]
abs return abs
!def[delattr, py] !def[delattr, py]
delattr return delattr
!def[hash, py] !def[hash, py]
hash return hash
!def[set, py] !def[set, py]
set return set
!def[all, py] !def[all, py]
all return all
!def[dict, py] !def[dict, py]
dict return dict
!def[min, py] !def[min, py]
min return min
!def[any, py] !def[any, py]
any return any
!def[dir, py] !def[dir, py]
dir return dir
!def[hex, py] !def[hex, py]
hex return hex
!def[next, py] !def[next, py]
next return next
!def[slice, py] !def[slice, py]
slice return slice
!def[ascii, py] !def[ascii, py]
ascii return ascii
!def[divmod, py] !def[divmod, py]
divmod return divmod
!def[id, py] !def[id, py]
id return id
!def[object, py] !def[object, py]
object return object
!def[sorted, py] !def[sorted, py]
sorted return sorted
!def[bin, py] !def[bin, py]
bin return bin
!def[enumerate, py] !def[enumerate, py]
enumerate return enumerate
!def[input, py] !def[input, py]
input return input
!def[oct, py] !def[oct, py]
oct return oct
!def[staticmethod, py] !def[staticmethod, py]
staticmethod return staticmethod
!def[bool, py] !def[bool, py]
bool return bool
!def[eval, py] !def[eval, py]
eval return eval
!def[int, py] !def[int, py]
int return int
!def[open, py] !def[open, py]
open return open
!def[str, py] !def[str, py]
str return str
!def[breakpoint, py] !def[breakpoint, py]
breakpoint return breakpoint
!def[exec, py] !def[exec, py]
exec return exec
!def[isinstance, py] !def[isinstance, py]
isinstance return isinstance
!def[ord, py] !def[ord, py]
ord return ord
!def[sum, py] !def[sum, py]
sum return sum
!def[bytearray, py] !def[bytearray, py]
bytearray return bytearray
!def[filter, py] !def[filter, py]
filter return filter
!def[issubclass, py] !def[issubclass, py]
issubclass return issubclass
!def[pow, py] !def[pow, py]
pow return pow
!def[super, py] !def[super, py]
super return super
!def[bytes, py] !def[bytes, py]
bytes return bytes
!def[float, py] !def[float, py]
float return float
!def[iter, py] !def[iter, py]
iter return iter
!def[print, py] !def[print, py]
print return print
!def[tuple, py] !def[tuple, py]
tuple return tuple
!def[callable, py] !def[callable, py]
callable return callable
!def[format, py] !def[format, py]
format return format
!def[len, py] !def[len, py]
len return len
!def[property, py] !def[property, py]
property return property
!def[type, py] !def[type, py]
type return type
!def[chr, py] !def[chr, py]
chr return chr
!def[frozenset, py] !def[frozenset, py]
frozenset return frozenset
!def[list, py] !def[list, py]
list return list
!def[range, py] !def[range, py]
range return range
!def[vars, py] !def[vars, py]
vars return vars
!def[classmethod, py] !def[classmethod, py]
classmethod return classmethod
!def[getattr, py] !def[getattr, py]
getattr return getattr
!def[locals, py] !def[locals, py]
locals return locals
!def[repr, py] !def[repr, py]
repr return repr
!def[zip, py] !def[zip, py]
zip return zip
!def[compile, py] !def[compile, py]
compile return compile
!def[map, py] !def[map, py]
map return map
!def[reversed, py] !def[reversed, py]
reversed return reversed
!def[complex, py] !def[complex, py]
complex return complex
!def[hasattr, py] !def[hasattr, py]
hasattr return hasattr
!def[max, py] !def[max, py]
max return max
!def[round, py] !def[round, py]
round return round