I have been trying to integrate the SmartPy compiler toolchain within Cryptoverse wars Learning interface and have been going through this video (OCaml Under The Hood: SmartPy) and have encountered blocker with the approach mentioned within the video used by SmartPy.io web IDE for compiling SmartPy code to Michelson.
What I want to achieve.
On a click of a button(frontend side), compile SmartPy code and generate JSON object which includes:
- Michelson JSON and plain code
- Contract initial storage JSON and plain Michelson code
- Contract size info(optional)
From within the run function in smartpyio.py file.
def run(withTests): window.pythonTests.clear() window.cleanAll() import smartpy smartpy.defaultVerifyMessage = None smartpy.sp.types.unknownIds = 0 smartpy.sp.types.seqCounter = 0 code = window.editor.getValue() changes = syntaxChanges() for change in changes: if change in code: if window.in_browser: message = ( "Warning: syntax change: %s -> %s" % (change, change) + "\n\nMigrate Syntax to adapt your script automatically?\n\nOther changes:\n" + "\n".join( "%s -> %s" % (change, change) for change in changes ) ) from browser import confirm if confirm(message): for ch in changes: code = code.replace(ch, ch) window.editor.setValue(code) break else: print( "Warning: syntax change: %s -> %s. You can use the editor to adapt it." % (change, change) ) code = adaptBlocks(code) env = context.copy() exec(code, env) window.cleanAll() for test in window.pythonTests: window.addButton(test.name, test.f) if withTests and test.is_default: test.eval() if withTests and len(window.pythonTests) == 0: html = "" for c in env: if "$" in c: continue if hasattr(env[c], "collectMessages"): html += ( "There is a sp.Contract class '%s' but no test is defined.\n\nPlease add a test such as:\n%s" % (str(c), testTemplate % (c, c)) ) if html: alert(html)
I wasn't able to understand at what line is the smartml experssion is generated within the function and when does smartmljs script gets trigger from it to generate Michelson code.
From the smartmljs file, how do I get the Michelson & initial storage exported to the browser?
- From my understanding, smartmljs code is tightly coupled and compiled to js for SmartPy.io IDE needs. How can I generate generic smartmljs for just compiling SmartPy code to Michelson within the browser ?