Skip to content

Commit

Permalink
Update: support to compile functions from MeTTa expression
Browse files Browse the repository at this point in the history
  • Loading branch information
patham9 committed Nov 14, 2023
1 parent 474ce00 commit 8948b50
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 9 additions & 0 deletions extend/example6.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
!(extend-py! mettamorph)
!(compile! (
(= (test1) 42)
(: test2 (-> Number Number))
(= (test2 $x) 42)
))

!(test1)
!(test2 33)
9 changes: 7 additions & 2 deletions extend/mettamorph.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,14 @@ def inject_calltypewrapper(content):
wrappers += line + "\n"
globalmetta.run(wrappers)

compiled = False
def call_compilefile(*a):
global mettamorphlib, globalmetta
loadfile = a[0][1:-1] if a[0].startswith('"') else a[0]
global mettamorphlib, globalmetta, compiled
if compiled:
return E(S("Compilation:"), S("unsupported"))
compiled = True
loadfiletoken = str(a[0]).replace(") (=", ")\n(=").replace(") (:", ")\n(:")
loadfile = loadfiletoken[1:-1] if loadfiletoken.startswith('"') or loadfiletoken.startswith('(') else loadfiletoken
if not loadfile.endswith(".metta"):
content = loadfile
loadfile = "TEMP.metta"
Expand Down

0 comments on commit 8948b50

Please sign in to comment.