# Copyright 2022 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 # These variables can be tweaked to debug and test various components of the toolchain var debugLexer* = false # Print the tokenizer's output var debugParser* = false # Print the AST generated by the parser var debugCompiler* = false # Disassemble and/or print the code generated by the compiler 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) var debugSerializer* = false # Validate the bytecode serializer's output 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 (nim-wise) 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: 1, 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) 2023 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. Basic Usage ----------- $ peon file.pn Run the given Peon source file $ peon 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 Execute the passed string as if it was a file -n, --noDump Don't dump the result of compilation to a file. Note that no dump is created when using -s/--string -b, --breakpoints Run the debugger at specific bytecode offsets (comma-separated). Only available with --target:bytecode and when compiled with VM debugging on (-d:debugVM at build time) -d, --disassemble Disassemble the output of compilation (only makes sense with --target:bytecode) -m, --mode Set the compilation mode. Acceptable values are 'debug' and 'release'. Defaults to 'debug' -c, --compile Compile the code, but do not execute it. Useful along with -d -w, --warnings Turn warnings on or off (default: on). Acceptable values are yes/on and no/off --noWarn Disable a specific warning (for example, --noWarn:unusedVariable) --showMismatches Show all mismatches when function dispatching fails (output is really verbose) --target Select the compilation target (valid values are: 'c' and 'bytecode'). Defaults to 'bytecode' -o, --output Rename the output file with this value (with --target:bytecode, a '.pbc' extension is added if not already present) --debug-dump Debug the bytecode serializer. Only makes sense with --target:bytecode --debug-lexer Show the lexer's output --debug-parser Show the parser's output """