Skip to content
This repository was archived by the owner on Oct 12, 2026. It is now read-only.

Commit e64c31e

Browse files
committed
feat: support negative numbers and fixed type warnings in scripts
1 parent 978b785 commit e64c31e

5 files changed

Lines changed: 31 additions & 9 deletions

File tree

‎README.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,4 @@ lbd [options]
4949

5050
## TODO
5151

52-
- TODO: Add build instructions for Windows (MSVC toolchain).
5352
- TODO: Provide better examples (e.g., Advent of Code snippets).

‎examples/std.lbd‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,26 @@ false: Bool = \x: Any. \y: Any. y
66

77
if_then: Any = \condition: Any.
88
\then_clause: Any. \else_clause: Any.
9-
(condition then_clause else_clause)
9+
(condition then_clause else_clause)
1010

1111
-- pairs
1212
pair: Any = \x: Any. \y: Any. \fn: Any. (fn x y)
1313

1414
first: Any = \x: Any. \y: Any. x
1515
second: Any = \x: Any. \y: Any. y
1616

17-
-- misc
18-
float_eq: Float -> Float -> Bool = \x: Float. \y: Float.
19-
(if_zero (cmp x y) true false)
17+
-- Relational Operators
18+
eq: Float -> Float -> Bool = \x: Float. \y: Float.
19+
(if_zero (cmp x y) true false)
20+
21+
lt: Float -> Float -> Bool = \x: Float. \y: Float.
22+
(if_zero (cmp (cmp x y) -1) true false)
23+
24+
gt: Float -> Float -> Bool = \x: Float. \y: Float.
25+
(if_zero (cmp (cmp x y) 1) true false)
26+
27+
lte: Float -> Float -> Bool = \x: Float. \y: Float.
28+
(if_zero (cmp x y) true (if_zero (cmp (cmp x y) -1) true false))
29+
30+
gte: Float -> Float -> Bool = \x: Float. \y: Float.
31+
(if_zero (cmp x y) true (if_zero (cmp (cmp x y) 1) true false))

‎scripts/dump_todo.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
with open(GITIGNORE_PATH, "r", encoding="utf-8") as f:
2424
spec = pathspec.PathSpec.from_lines("gitwildmatch", f)
2525

26+
root: str
2627
for root, _, files in os.walk(BASE_DIR):
28+
filename: str
2729
for filename in files:
2830
filepath: str = os.path.join(root, filename)
2931
rel_path: str = os.path.relpath(filepath, BASE_DIR)

‎src/fe/lexer.cpp‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ namespace fe::lexer {
6666
const std::string value = source.substr(start, pos - start);
6767
return {token::Iden{value}, cur_loc};
6868
}
69-
// Float
70-
// TODO: Negative numbers
71-
if (std::isdigit(c)) {
69+
auto lex_float = [this, &c]() -> double {
7270
const size_t start = pos;
7371
while (std::isdigit(c)) {
7472
get();
@@ -83,7 +81,11 @@ namespace fe::lexer {
8381
}
8482
}
8583
const double value = std::stod(source.substr(start, pos - start));
86-
return {token::Float{value}, cur_loc};
84+
return value;
85+
};
86+
// Positive Float
87+
if (std::isdigit(c)) {
88+
return {token::Float(lex_float()), cur_loc};
8789
}
8890
// String Literal: " ... "
8991
if (c == '"') {
@@ -138,6 +140,10 @@ namespace fe::lexer {
138140
// After skipping comment, return the next token
139141
return next_token();
140142
}
143+
// Negative Float
144+
if (std::isdigit(c)) {
145+
return {token::Float(-lex_float()), cur_loc};
146+
}
141147
break;
142148
default:
143149
break;

‎src/repl.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#include "lbd/fe/parser.h"
66
#include "lbd/intp/interpreter.h"
77

8+
// TODO: Implement loading a file to repl
9+
// syntax: :load <filepath> or :l <filepath>
10+
811
namespace repl {
912
static bool force_on_env_dump = false;
1013
static bool debug_enabled = false;

0 commit comments

Comments
 (0)