diff --git a/src/config.nim b/src/config.nim index e5642dd..04dcb28 100644 --- a/src/config.nim +++ b/src/config.nim @@ -56,7 +56,7 @@ Options -h, --help Show this help text and exits -v, --version Print the current peon version and exits -s, --string Execute the passed string as if it was a file --n, --nodump Don't dump the result of compilation to a *.pbc file +-n, --noDump Don't dump the result of compilation to a *.pbc file -b, --breakpoints Run the debugger at specific bytecode offsets (comma-separated). Only available when compiled with VM debugging on -d, --disassemble Disassemble the given bytecode file instead of executing it @@ -65,5 +65,5 @@ Options --warnings Turn warnings on/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 dispatching function calls (quite verbose!) +--showMismatches Show all mismatches when dispatching function calls fails (quite verbose!) """ diff --git a/src/frontend/compiler.nim b/src/frontend/compiler.nim index 87f9315..d6766de 100644 --- a/src/frontend/compiler.nim +++ b/src/frontend/compiler.nim @@ -277,7 +277,6 @@ proc handleErrorPragma(self: Compiler, pragma: Pragma, name: Name) proc dispatchPragmas(self: Compiler, name: Name) proc dispatchDelayedPragmas(self: Compiler, name: Name) proc funDecl(self: Compiler, node: FunDecl, name: Name) -proc typeDecl(self: Compiler, node: TypeDecl, name: Name) proc compileModule(self: Compiler, module: Name) proc generateCall(self: Compiler, fn: Name, args: seq[Expression], line: int) proc prepareFunction(self: Compiler, fn: Name) @@ -351,7 +350,9 @@ proc error(self: Compiler, message: string, node: ASTNode = nil) {.raises: [Comp proc warning(self: Compiler, kind: WarningKind, message: string, name: Name = nil, node: ASTNode = nil) = - ## Raises a warning + ## Raises a warning. Note that warnings are always disabled in REPL mode + if self.replMode or kind in self.disabledWarnings: + return var node: ASTNode = node var fn: Declaration if name.isNil(): @@ -370,19 +371,28 @@ proc warning(self: Compiler, kind: WarningKind, message: string, name: Name = ni if not name.isNil(): file = name.owner.file var pos = node.getRelativeBoundaries() - #let line = self.source.splitLines()[node.token.line - 1].strip(chars={'\n'}) if file notin ["", ""]: file = relativePath(file, getCurrentDir()) - if kind notin self.disabledWarnings: - stderr.styledWrite(fgYellow, styleBright, "Warning in ", fgRed, &"{file}:{node.token.line}:{pos.start}") - if not fn.isNil() and fn.kind == funDecl: - stderr.styledWrite(fgYellow, styleBright, " in function ", fgRed, FunDecl(fn).name.token.lexeme) - stderr.styledWriteLine(styleBright, fgDefault, ": ", message) - #[ - stderr.styledWrite(fgYellow, styleBright, "Source line: ", resetStyle, fgDefault, line[0.. 16777215: + # If someone ever hits this limit in real-world scenarios, I swear I'll + # slap myself 100 times with a sign saying "I'm dumb". Mark my words + self.error("cannot declare more than 16777215 names at a time") case node.kind: of NodeKind.varDecl: var node = VarDecl(node) - if self.names.high() > 16777215: - # If someone ever hits this limit in real-world scenarios, I swear I'll - # slap myself 100 times with a sign saying "I'm dumb". Mark my words - self.error("cannot declare more than 16777215 variables at a time") declaredName = node.name.token.lexeme # Creates a new Name entry so that self.identifier emits the proper stack offset self.names.add(Name(depth: self.depth, @@ -2500,11 +2505,7 @@ proc varDecl(self: Compiler, node: VarDecl) = self.declareName(node) var name = self.names[^1] name.valueType = typ - - -proc typeDecl(self: Compiler, node: TypeDecl, name: Name) = - ## Compiles type declarations - # TODO + proc funDecl(self: Compiler, node: FunDecl, name: Name) = diff --git a/src/frontend/parser.nim b/src/frontend/parser.nim index 38d9519..e55e95a 100644 --- a/src/frontend/parser.nim +++ b/src/frontend/parser.nim @@ -139,7 +139,11 @@ proc newOperatorTable: OperatorTable = result.tokens = @[] for prec in Precedence: result.precedence[prec] = @[] - result.addOperator("=") # Assignment is the only builtin + # Assignment and attribute accessing are (currently) + # the only builtins that cannot be easily implemented + # from within peon itself + result.addOperator("=") + result.addOperator(".") proc getPrecedence(self: OperatorTable, lexeme: string): Precedence = @@ -1293,7 +1297,6 @@ proc parse*(self: Parser, tokens: seq[Token], file: string, lines: seq[tuple[sta self.tree = @[] if not persist: self.operators = newOperatorTable() - self.operators.addOperator("=") self.findOperators(tokens) while not self.done(): self.tree.add(self.declaration()) diff --git a/src/main.nim b/src/main.nim index a662b47..79ab3f5 100644 --- a/src/main.nim +++ b/src/main.nim @@ -261,12 +261,21 @@ when isMainModule: var breaks: seq[uint64] = @[] var dis: bool = false var mismatches: bool = false + var mode: CompileMode = CompileMode.Debug for kind, key, value in optParser.getopt(): case kind: of cmdArgument: file = key of cmdLongOption: case key: + of "mode": + if value.toLowerAscii() == "release": + mode = CompileMode.Release + elif value.toLowerAscii() == "debug": + discard + else: + stderr.styledWriteLine(fgRed, styleBright, "Error: ", fgDefault, "invalid value for option 'mode' (valid options are: debug, release)") + quit() of "help": echo HELP_MESSAGE quit() @@ -276,7 +285,7 @@ when isMainModule: of "string": file = key fromString = true - of "no-dump": + of "noDump": dump = false of "warnings": if value.toLowerAscii() in ["yes", "on"]: @@ -349,7 +358,7 @@ when isMainModule: if file == "": repl() else: - runFile(file, fromString, dump, breaks, dis, warnings, mismatches) + runFile(file, fromString, dump, breaks, dis, warnings, mismatches, mode)