-
Notifications
You must be signed in to change notification settings - Fork 22
/
main.fy
105 lines (92 loc) · 3.21 KB
/
main.fy
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# main.fy
# This file gets run directly from bin/fancy.
# It handles any given built-in ARGV options.
# If any .fy source filename is passed in via ARGV, it is loaded and
# executed, otherwise ifancy, Fancy's REPL, gets loaded.
if: (ARGV size == 1) then: {
ARGV for_options: ["-v", "--version"] do: {
"Fancy #{Fancy VERSION}" println
"(C) 2010, 2011, 2012 Christopher Bertels <chris@fancy-lang.org>" println
System exit
}
ARGV for_options: ["--help", "-h"] do: {
["Usage: fancy [option] [programfile] [arguments]",
" --help Print this output",
" -h Print this output",
" --version Print Fancy's version number",
" -v Print Fancy's version number",
" -I directory Add directory to Fancy's LOAD_PATH",
" -e 'command' One line of Fancy code that gets evaluated immediately",
" -c [filenames] Compile given files to Rubinius bytecode",
" -cv [filenames] Compile given files to Rubinius bytecode verbosely (outputting the generated bytecode)",
" -debug Start the Rubinius Debugger with Fancy",
"",
"Fancy package management:",
" install [packagename] Install a Fancy package with a given name to $FANCYPACK_DIR",
" install --deps Install dependencies specified in .fancypack file (expected in current directory)",
" uninstall [packagename] Uninstall a Fancy package with a given name from $FANCYPACK_DIR",
" list-packages List all installed packages"] println
System exit # quit when running --help
}
}
ARGV for_option: "-I" do: |path| {
Fancy CodeLoader push_loadpath: path
}
ARGV for_option: "-e" do: |eval_string| {
eval_string eval
System exit # quit when running with -e
}
ARGV for_option: "-c" do: {
ARGV index: "-c" . if_true: |idx| {
ARGV[[idx + 1, -1]] . tap: |filenames| {
filenames each: |filename| {
"Compiling " ++ filename println
Fancy Compiler compile_file: filename to: nil line: 1 print: false
}
files = "file"
{ files = "files" } if: $ filenames size != 1
"Compiled #{filenames size} #{files}." println
}
}
System exit
}
ARGV for_option: "-cv" do: {
ARGV index: "-cv" . if_true: |idx| {
ARGV[[idx + 1, -1]] each: |filename| {
"Compiling " ++ filename println
Fancy Compiler compile_file: filename to: nil line: 1 print: true
}
}
System exit
}
ARGV for_option: "-debug" do: {
require: "rbx/debugger"
}
ARGV for_option: "install" do: |package_name| {
match package_name {
case "--deps" -> Fancy Package install_dependencies
case _ -> Fancy Package install: package_name
}
System exit
}
ARGV for_option: "uninstall" do: |package_name| {
Fancy Package uninstall: package_name
System exit
}
ARGV for_option: "list-packages" do: {
Fancy Package list_packages
System exit
}
# push package install dir to load_path
Fancy Package add_to_loadpath
# Load a source file, if any given:
ARGV first if_true: |file| {
try {
Fancy CodeLoader load_compiled_file: file
} catch Fancy Parser ParseError => e {
e message println
}
}
ARGV empty? if_true: {
require: "../bin/ifancy"
}