Exemplo n.º 1
0
def compile():
    i = topc.start(False, dev= True, init= True)
    topc.error = ""
    if i[0]:
        return "var ended= false;var error= false;\n"+i[1]+";\nmain_Init();ended=true;"

    return """var error= true; document.getElementById("error").innerHTML = " """+i[1] + """ ";"""
Exemplo n.º 2
0
def hot(received):
    i = topc.start(False, dev= True, init= received == "false")
    topc.error = ""

    if i[0]:
        return "error= false;\n"+i[1]+ "ended=true;\n"

    if i[1] == "":
        return ""
    return """var error= true; document.getElementById("error").innerHTML = " """+i[1] + """ ";"""
Exemplo n.º 3
0
from TopCompiler import topc
from TopCompiler import Error
import sys

if __name__ == "__main__":
    if len(sys.argv) > 1:

        if sys.argv[1] == "new":
            if sys.argv[2] == "project":
                topc.newProj(sys.argv[3])
            elif sys.argv[2] == "package":
                topc.newPack(sys.argv[3])
            elif sys.argv[2] == "linkWith":
                topc.linkWith(sys.argv[3])
            else:
                Error.error("invalid option to new" + sys.argv[2])
            sys.exit()
        elif sys.argv[1] == "build":
            topc.start()
        elif sys.argv[1] == "run":
            topc.start(True)
        else:
            Error.error("invalid option " + sys.argv[1])
Exemplo n.º 4
0
pasteInto = "../runtime/runtimeTop.c"
modules = ["array", "maybe", "memory"]

from TopCompiler import topc
topc.start(compileRuntime=True)

output = open("lib/_global.c", mode="r")
output_h = open("lib/_global.h", mode="r")

code = output_h.read() + output.read()

file = open(pasteInto, mode="w")
file.write(code)
file.close()
output.close()
output_h.close()
Exemplo n.º 5
0
def compile():
    code = request.data.decode("utf-8")

    if code == "":
        return ""

    try:
        object = tempfile.TemporaryDirectory(dir= "temps")
        id = object.name
        os.chdir(id)
        os.mkdir("src")
        os.mkdir("src/main")
        os.mkdir("bin")

        ignore = {}
        for item in os.listdir("../../src"):
            if not item in ["main", "port.json"]:
                ignore[item] = True
                os.symlink("../../../src/"+item, "src/"+item, target_is_directory=True)
        os.symlink("../../js", "js")
        os.symlink("../../lib", "lib")

        jsonFile = open("src/port.json", "w")
        json = """
        {
            "name": "code",
            "target": "client",
            "linkWith-client": ["js/exports.js", "js/bundle.js"],
            "linkWith-node": ["js/node.js"]
        }
        """

        jsonFile.write(json)
        jsonFile.close()

        jsonMainFile = open("src/main/port.json", "w")
        jsonMain = """
        {
            "files": ["anonymous"]
        }
        """

        jsonMainFile.write(jsonMain)
        jsonMainFile.close()

        anonymous = open("src/main/anonymous.top", "w")
        anonymous.write(code)
        anonymous.close()

        try:
            topc.modified_ = {"main": True}
            ImportParser.ignore = ignore
            topc.start(cache= core, _raise=True, _hotswap=True)

            res = open("bin/code.html", mode="r").read()
            os.chdir("../../")

            return res
        except EOFError as e:
            os.chdir("../../")
            return str(e).replace("\n", "<br>")
    except Exception as e:
        os.chdir("../../")
        raise e
Exemplo n.º 6
0
            "files": ["anonymous"]
        }
        """

        jsonMainFile.write(jsonMain)
        jsonMainFile.close()

        anonymous = open("src/main/anonymous.top", "w")
        anonymous.write(code)
        anonymous.close()

        try:
            topc.modified_ = {"main": True}
            ImportParser.ignore = ignore
            topc.start(cache= core, _raise=True, _hotswap=True)

            res = open("bin/code.html", mode="r").read()
            os.chdir("../../")

            return res
        except EOFError as e:
            os.chdir("../../")
            return str(e).replace("\n", "<br>")
    except Exception as e:
        os.chdir("../../")
        raise e

if __name__ == "__main__":
    topc._modified = {"main": True}
    core = topc.start(_raise= True)
    app.run(port=8080)
Exemplo n.º 7
0
def main():
    debug = False
    if len(sys.argv) > 1:
        if sys.argv[1] == "--" and sys.argv[2] == "debug":
            debug = True
        else:
            print("Unexpected", sys.argv[1])
            sys.exit()

    try:
        if True:
            error = ""
            mutex.acquire()
            while True:
                try:
                    parser = topc.start(run=True, dev=True, debug=debug)
                    time.sleep(0.2)
                    error = False
                    break
                except EOFError as e:
                    e = str(e)
                    if error != e:
                        print(e, file=sys.stderr)

                    error = e
                    time.sleep(0.2)

            mutex.release()

            socketRepl.init()
            socketRepl.parser = parser

            server = threading.Thread(target=initRepl).start()

            while True:
                time.sleep(0.2)
                mutex.acquire()
                try:
                    parser = topc.start(run=False,
                                        dev=True,
                                        _hotswap=True,
                                        cache=parser,
                                        debug=debug)

                    if parser.didCompile:
                        reloadCSS(parser.cssFiles, parser.outputFile,
                                  parser.global_target)
                        socketRepl.socketio.emit(
                            "reload",
                            open("bin/" + parser.outputFile +
                                 "-client.js").read())
                    error = False
                except EOFError as e:
                    e = str(e)
                    if error != e:
                        print(e, file=sys.stderr)
                        #socketRepl.socketio.emit("error", "Compile Error\n\n"+str(e))
                        socketRepl.socketio.emit(
                            "comp_error",
                            str(e).replace("\t", "    ").replace(
                                " ", "&nbsp;").replace("\n", "<br>"))
                    error = e
                    removeTransforms(topc.global_parser)
                finally:
                    mutex.release()
    except (KeyboardInterrupt, SystemExit):
        pass

    parser = topc.global_parser
    topc.clearMain(parser)

    from TopCompiler import saveParser
    saveParser.save(parser)
Exemplo n.º 8
0
from TopCompiler import topc
from TopCompiler import Error
import sys

if __name__ == "__main__":
    if len(sys.argv) > 1:

        if sys.argv[1] == "new":
            if sys.argv[2] == "project":
                topc.newProj(sys.argv[3])
            elif sys.argv[2] == "package":
                topc.newPack(sys.argv[3])
            elif sys.argv[2] == "linkWith":
                topc.linkWith(sys.argv[3])
            else:
                Error.error("invalid option to new"+sys.argv[2])
            sys.exit()
        elif sys.argv[1] == "build":
            topc.start()
        elif sys.argv[1] == "run":
            topc.start(True)
        else:
            Error.error("invalid option "+sys.argv[1])
Exemplo n.º 9
0
from TopCompiler import topc
from TopCompiler import Error
import sys

if __name__ == "__main__":
    if len(sys.argv) > 1:

        if sys.argv[1] == "new":
            if sys.argv[2] == "project":
                topc.newProj(sys.argv[3])
            elif sys.argv[2] == "package":
                topc.newPack(sys.argv[3])
            elif sys.argv[2] == "linkWith":
                topc.linkWith(sys.argv[3])
            else:
                Error.error("invalid option to new" + sys.argv[2])
            sys.exit()
        elif sys.argv[1] == "build":
            topc.start()
        elif sys.argv[1] == "run":
            topc.start(True)
        elif sys.argv[1] == "debug":
            topc.start(debug=True)
        else:
            Error.error("invalid option " + sys.argv[1])
Exemplo n.º 10
0
def doc(port):
    docs = []
    try:
        readme = pypandoc.convert_file("README.md", "html5", "markdown_github")

        docs.append(["", readme])

    except FileNotFoundError:
        print("Missing README.md", file=sys.stderr)
        sys.exit()

    try:
        parser = topc.start(doc=True)
    except EOFError as e:
        print(e, file=sys.stderr)
        sys.exit()

    lexed = parser.lexed

    def splitBy(content):
        arr = [i.split(" ") for i in content.split("\n")]

        tmp = []
        for c in arr:
            for i in c:
                tmp.append(i)
                tmp.append(" ")
            tmp.append("\n")

        return tmp

    def gen(generics):
        if len(generics) == 0:
            return ""
        else:
            i = "["
            for name in generics:
                typ = generics[name].type
                n = generics[name].realName
                if type(typ) is Types.Interface and len(typ.types) == 0:
                    i += n
                else:
                    i += n+":"+generics[name].type.name

                i += ", "
            i = i[:-2] + "]"

            return i

    def parse(package, filename, cont, token):
        comment = token.token[4:-2]
        split = splitBy(comment)
        inCode = False

        for i in split:
            if len(i) > 0 and i[:3] == "```" and inCode:
                inCode = False
                cont.append(i)
            elif len(i) > 0 and i[:3] == "```" and not inCode:
                cont.append("```scala"+i[3:])
                inCode = True
            elif len(i) > 0 and i[0] == "@":
                name = i[1:]

                cont.append("```scala\n")


                if name in parser.structs[package]:
                    typ = parser.structs[package][name]
                    cont.append("type " + name + gen(typ.generic) + " =")
                    for c in Struct.offsetsToList(parser.structs[package][name].offsets):
                        cont.append("\n   " + c + ": " + typ.types[c].name + "")
                elif name in parser.interfaces[package]:
                    typ = parser.interfaces[package][name]

                    if type(typ) is Types.Interface:
                        cont.append("type " + name + " with\n")
                        for c in typ.types:
                            cont.append("   " + c + ": " + typ.types[c].name + "\n")
                    elif type(typ) is Types.Enum:
                        cont.append("type " + name + " either\n")
                        for c in typ.types:
                            args = typ.types[c]
                            if len(args) == 0:
                                cont.append("   " + c + "\n")
                            else:
                                cont.append("   " + c + "(" + ", ".join([d.name for d in args]) + ")\n")
                else:
                    try:

                        n = Scope.typeOfVar(PlaceHolder(package, filename, token), parser, package, name)
                        cont.append(name+": "+str(n))
                    except EOFError:
                        try:
                            PlaceHolder(package, filename, token).error("no variable named "+name)
                        except EOFError as e:
                            print(e, file=sys.stderr)
                            sys.exit()

                cont.append("\n```")
            else:
                cont.append(i)

    for package in lexed:
        if package == "main":
            continue


        content = []
        count = -1
        for file in lexed[package]:
            count += 1
            filename = parser.filenames[package][count][1]
            for token in file:
                if token.type in ["comment", "commentLine"] and token.token[2] == "*":
                    parse(package, filename, content, token)

        f = open("src/"+package+"/README.md", "w")
        s = "".join(content)
        f.write(s)
        f.close()

        #print( open("src/"+package+"/README.md", "r").read())

        html = pypandoc.convert_file("src/"+package+"/README.md", "html5", "markdown_github")

        docs.append([package, html])
    return docs