99 lines
5.8 KiB
Nim
99 lines
5.8 KiB
Nim
# Copyright 2024 Mattia Giambirtone & All Contributors
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
import std/strformat
|
|
import std/os
|
|
|
|
|
|
type
|
|
PeonBackend* = enum
|
|
Bytecode,
|
|
NativeC # Coming soon
|
|
|
|
# These variables can be tweaked to debug and test various components of the toolchain. Do not modify them directly,
|
|
# use the command-line options instead (or -d:option=value for constants)
|
|
var debugLexer* = false # Print the tokenizer's output (main module only)
|
|
var debugParser* = false # Print the AST generated by the parser (main module only)
|
|
var debugTypeChecker* = false # Debug the typechecker's output (main module only)
|
|
var debugCompiler* = false # Disassemble and/or print the code generated by the compiler
|
|
var debugSerializer* = false # Validate the bytecode serializer's output
|
|
const debugVM* {.booldefine.} = false # Enable the runtime debugger in the bytecode VM
|
|
const debugGC* {.booldefine.} = false # Debug the Garbage Collector (extremely verbose)
|
|
const debugAlloc* {.booldefine.} = false # Trace object allocation (extremely verbose)
|
|
const debugMem* {.booldefine.} = false # Debug the memory allocator (extremely verbose)
|
|
const debugStressGC* {.booldefine.} = false # Make the GC run a collection at every allocation (VERY SLOW!)
|
|
const debugMarkGC* {.booldefine.} = false # Trace the marking phase object by object (extremely verbose)
|
|
const PeonBytecodeMarker* = "PEON_BYTECODE" # Magic value at the beginning of bytecode files
|
|
const HeapGrowFactor* = 2 # The growth factor used by the GC to schedule the next collection
|
|
const FirstGC* = 1024 * 1024; # How many bytes to allocate before running the first GC
|
|
const enableVMChecks* {.booldefine.} = true; # Enables all types of compiler checks in the VM
|
|
# List of paths where peon looks for modules, in order (empty path means current directory, which always takes precedence)
|
|
const moduleLookupPaths*: seq[string] = @["", "src/peon/stdlib", absolutePath(joinPath(".local", "peon", "stdlib"), getenv("HOME"))]
|
|
when HeapGrowFactor <= 1:
|
|
{.fatal: "Heap growth factor must be > 1".}
|
|
const PeonVersion* = (major: 0, minor: 2, patch: 0)
|
|
const PeonRelease* = "alpha"
|
|
const PeonCommitHash* = staticExec("git rev-parse HEAD")
|
|
const PeonBranch* = staticExec("git symbolic-ref HEAD 2>/dev/null | cut -f 3 -d /")
|
|
const PeonVersionString* = &"Peon {PeonVersion.major}.{PeonVersion.minor}.{PeonVersion.patch} {PeonRelease} ({PeonBranch}, {CompileDate}, {CompileTime}, {PeonCommitHash[0..PeonCommitHash.high() mod 8]}) [Nim {NimVersion}] on {hostOS} ({hostCPU})"
|
|
const HelpMessage* = """The peon programming language, Copyright (C) 2024 Mattia Giambirtone & All Contributors
|
|
|
|
This program is free software, see the license distributed with this program or check
|
|
http://www.apache.org/licenses/LICENSE-2.0 for more info.
|
|
|
|
Note: This is very much a work in progress
|
|
|
|
Basic Usage
|
|
-----------
|
|
|
|
peon [options] <file>[.pn] Run the given peon file
|
|
peon [options] file.pbc Run the given peon bytecode file
|
|
|
|
|
|
Options
|
|
-------
|
|
|
|
-h, --help Show this help text and exit
|
|
-v, --version Print the current peon version and exit
|
|
-s, --string Use the passed string as if it was a file
|
|
-w, --warnings Turn warnings on or off (default: on). Acceptable values are
|
|
yes/on and no/off
|
|
--noWarn Disable a specific warning (example: --noWarn:UserWarning)
|
|
--noGen Don't generate any code (i.e. stop at the typechecking stage)
|
|
--noParse Don't parse the code (i.e. stop at the tokenization stage)
|
|
--noTC, --noTypeCheck Don't typecheck the code (i.e. stop at the parsing stage)
|
|
|
|
--showMismatches Show all mismatches when type dispatching fails (output is really verbose)
|
|
--debugLexer Show the lexer's output
|
|
--debugParser Show the parser's output
|
|
--debugTypeChecker Show the typechecker's output
|
|
--debugCompiler Show the generated code (backend-specific)
|
|
--listWarns Show a list of all warnings
|
|
-b, --backend Select the compilation backend. Currently only supports 'bytecode' (the default)
|
|
-c, --compile Compile the code, but do not run the main module
|
|
-o, --output Rename the output executable to this (a "pbc" extension is added for bytecode files,
|
|
if not already present)
|
|
-s, --string Run the given string as if it were a file (the filename is set to '<string>')
|
|
--cacheDir Specify a directory where the peon compiler will dump code generation results
|
|
to speed up subsequent builds. Defaults to ".buildcache"
|
|
|
|
The following options are specific to the 'bytecode' backend:
|
|
-n, --noDump Do not dump bytecode files to the source directory. Redundant
|
|
when using -s/--string
|
|
--breakpoints Pause execution and invoke the debugger at the given bytecode offsets.
|
|
Input should be a comma-separated list of positive integers
|
|
(spacing is irrelevant). Only works if peon was compiled with
|
|
VM debugging enabled
|
|
"""
|