Fix lint errors in pallenec
Unused variables, lack of copyright headers, etc.
-local argparse = require "argparse"
+-- Copyright (c) 2022, The Pallene Developers
+-- Pallene is licensed under the MIT license.
+-- Please refer to the LICENSE and AUTHORS files for details
+-- SPDX-License-Identifier: MIT
+
+-- PALLENEC SCRIPT
+-- ===============
+-- This is the main entry point for the pallenec compiler
+local argparse = require "argparse"
local driver = require "pallene.driver"
local print_ir = require "pallene.print_ir"
local util = require "pallene.util"
-local C = require "pallene.C"
local pallenec = {}
---
--- Command-line options
---
+-- For compilation errors that don't happen inside a source file.
+-- Inspired by gcc, eg. "gcc: fatal error: no input files".
+local compiler_name = arg[0]
+-- Command-line options
+local args
+do
local p = argparse("pallenec", "Pallene compiler")
p:argument("source_file", "File to compile")
@@ -22,8 +32,6 @@ p:mutex(
p:flag("--print-ir", "Show the intermediate representation for a program")
)
--- Optimization levels for the Pallene and C compiler. (-O0 disables optimizations for both)
--- NOTE: *For C compiler only* this option may be overridden using the CFLAGS environment variable.
p:option("-O", "Optimization level")
:args(1):convert(tonumber)
:choices({"0", "1", "2", "3"})
@@ -31,30 +39,20 @@ p:option("-O", "Optimization level")
p:option("-o --output", "Output file path")
-
-local args = p:parse()
-
-local opt_level = args.O
-
--- For compilation errors that don't happen inside a source file.
--- Inspired by gcc, eg. "gcc: fatal error: no input files".
-local compiler_name = arg[0]
+ args = p:parse()
+end
local function compile(in_ext, out_ext)
- local ok, errs = driver.compile(compiler_name, opt_level, in_ext, out_ext, args.source_file,
+ local ok, errs = driver.compile(compiler_name, args.O, in_ext, out_ext, args.source_file,
args.output)
if not ok then util.abort(table.concat(errs, "\n")) end
end
-
local function compile_up_to(stop_after)
- local filename = args.source_file
- local opt_level = args.O
-
- local input, err = driver.load_input(filename)
+ local input, err = driver.load_input(args.source_file)
if err then util.abort(err) end
- local out, errs = driver.compile_internal(filename, input, stop_after, opt_level)
+ local out, errs = driver.compile_internal(args.source_file, input, stop_after, args.O)
if not out then util.abort(table.concat(errs, "\n")) end
return out
