/
sharkc.shk
65 lines (62 loc) · 3.21 KB
/
sharkc.shk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
################################################################################
### Copyright ##################################################################
##
## Copyright 2022 Daniel Alvarez <shogundevel@gmail.com>
##
## Permission is hereby granted, free of charge, to any person
## obtaining a copy of this software and associated documentation files
## (the "Software"), to deal in the Software without restriction,
## including without limitation the rights to use, copy, modify, merge,
## publish, distribute, sublicense, and/or sell copies of the Software,
## and to permit persons to whom the Software is furnished to do so,
## subject to the following conditions:
##
## The above copyright notice and this permission notice shall be
## included in all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
## IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
## CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
## TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
## SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
##
################################################################################
import system.io: printf, puts
import sharkc.compiler: compile
import sharkc.backend.cshark: bytecode_generator
import sharkc.backend.python: python_generator
import sharkc.backend.javascript: javascript_generator
import sharkc.backend.lua: lua_generator
import sharkc.backend.renpy: renpy_generator
import sharkc.backend.actionscript: actionscript_generator
function main(args)
if sizeof(args) != 4 then
printf("usage: % <target> <filename> <out>\n", [args[0]])
puts("\tCompiles the provided <filename> (and its dependences) to <out> using the specified backend.\n")
puts("\tThe target argument may be any of <c | py | js | lua | rpy | as> and will select the backend.\n")
puts("\t<filename> should point to a top level module or executable program which may depend on any number of other modules in the same directory.\n")
puts("\tNOTE: linking will be necesary to get a final executable program.\n")
puts("\tNOTE: the generated code can't be executed without a compatible runtime. For more info see the 'guide' file that should come with this compiler.")
return
var backend_name = args[1]
var backend = null
if backend_name == "c" then
backend = new bytecode_generator ()
else if backend_name == "py" then
backend = new python_generator ()
else if backend_name == "js" then
backend = new javascript_generator ()
else if backend_name == "lua" then
backend = new lua_generator ()
else if backend_name == "rpy" then
backend = new renpy_generator ()
else if backend_name == "as" then
backend = new actionscript_generator ()
else
printf("can't recognize the desired backend '%' (must be one of <c | py | js | lua | rpy | as>).", [backend_name])
return
var filename = args[2]
var out = args[3]
compile(filename, backend, out)