Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/lexer/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,20 @@

/** @internal Symbol to token type mapping */
static const SymbolEntry symbols[] = {
{"%", TOK_MODL}, {"(", TOK_LPAREN}, {")", TOK_RPAREN},
{"{", TOK_LBRACE}, {"}", TOK_RBRACE}, {"[", TOK_LBRACKET},
{"]", TOK_RBRACKET}, {"..", TOK_RANGE}, {";", TOK_SEMICOLON},
{",", TOK_COMMA}, {".", TOK_DOT}, {"=>", TOK_RIGHT_ARROW},
{"==", TOK_EQEQ}, {"!=", TOK_NEQ}, {"<=", TOK_LE},
{">=", TOK_GE}, {"&&", TOK_AND}, {"||", TOK_OR},
{"=", TOK_EQUAL}, {"+", TOK_PLUS}, {"-", TOK_MINUS},
{"*", TOK_STAR}, {"/", TOK_SLASH}, {"<", TOK_LT},
{">", TOK_GT}, {"&", TOK_AMP}, {"|", TOK_PIPE},
{"^", TOK_CARET}, {"~", TOK_TILDE}, {"!", TOK_BANG},
{"?", TOK_QUESTION}, {"::", TOK_RESOLVE}, {":", TOK_COLON},
{"_", TOK_SYMBOL}, {"++", TOK_PLUSPLUS}, {"--", TOK_MINUSMINUS},
{"<<", TOK_SHIFT_LEFT}, {">>", TOK_SHIFT_RIGHT}, {"@", TOK_AT},
{"%", TOK_MODL}, {"(", TOK_LPAREN}, {")", TOK_RPAREN},
{"{", TOK_LBRACE}, {"}", TOK_RBRACE}, {"[", TOK_LBRACKET},
{"]", TOK_RBRACKET}, {"..", TOK_RANGE}, {";", TOK_SEMICOLON},
{",", TOK_COMMA}, {".", TOK_DOT}, {"->", TOK_RIGHT_ARROW},
{"<-", TOK_LEFT_ARROW}, {"==", TOK_EQEQ}, {"!=", TOK_NEQ},
{"<=", TOK_LE}, {">=", TOK_GE}, {"&&", TOK_AND},
{"||", TOK_OR}, {"=", TOK_EQUAL}, {"+", TOK_PLUS},
{"-", TOK_MINUS}, {"*", TOK_STAR}, {"/", TOK_SLASH},
{"<", TOK_LT}, {">", TOK_GT}, {"&", TOK_AMP},
{"|", TOK_PIPE}, {"^", TOK_CARET}, {"~", TOK_TILDE},
{"!", TOK_BANG}, {"?", TOK_QUESTION}, {"::", TOK_RESOLVE},
{":", TOK_COLON}, {"_", TOK_SYMBOL}, {"++", TOK_PLUSPLUS},
{"--", TOK_MINUSMINUS}, {"<<", TOK_SHIFT_LEFT}, {">>", TOK_SHIFT_RIGHT},
{"@", TOK_AT},
};

/** @internal Keyword text to token type mapping */
Expand Down
3 changes: 2 additions & 1 deletion src/lexer/lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ typedef enum {
TOK_SHIFT_LEFT, /**< << */
TOK_SHIFT_RIGHT, /**< >> */
TOK_RANGE, /**< .. */
TOK_RIGHT_ARROW, /**< => */
TOK_RIGHT_ARROW, /**< -> */
TOK_LEFT_ARROW, /**< <- */
TOK_MODL, /**< % */
TOK_WHITESPACE, /**< whitespace */
TOK_COMMENT /**< comment */
Expand Down
2 changes: 1 addition & 1 deletion src/parser/stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Stmt *const_stmt(Parser *parser, bool is_public, bool returns_ownership,
is_public, line, col);
}

p_consume(parser, TOK_EQUAL, "Expected '=' after const name");
p_consume(parser, TOK_RIGHT_ARROW, "Expected '->' after const name");

// Handle complex constant types (functions, structs, enums)
switch (p_current(parser).type_) {
Expand Down
2 changes: 1 addition & 1 deletion src/typechecker/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ AstNode *typecheck_input_expr(AstNode *expr, Scope *scope,
}

// Check that message is a string type
AstNode *expected_string = create_basic_type(arena, "string", 0, 0);
AstNode *expected_string = create_basic_type(arena, "str", 0, 0);
TypeMatchResult match = types_match(expected_string, msg_type);

if (match == TYPE_MATCH_NONE) {
Expand Down
32 changes: 16 additions & 16 deletions std/math.lx
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,37 @@ pub const SIN_TABLE: [double; 129] = [
1.000000
];

pub const rand = fn (seed: *int) int {
pub const rand -> fn (seed: *int) int {
*seed = (*seed * 1103515245 + 12345) % 2147483648;
return *seed;
}

pub const add = fn (x: int, y: int) int { return x + y; }
pub const subtract = fn (x: int, y: int) int { return x - y; }
pub const multiply = fn (x: int, y: int) int { return x * y; }
pub const divide = fn (x: int, y: int) int {
pub const add -> fn (x: int, y: int) int { return x + y; }
pub const subtract -> fn (x: int, y: int) int { return x - y; }
pub const multiply -> fn (x: int, y: int) int { return x * y; }
pub const divide -> fn (x: int, y: int) int {
if (y == 0) {
output("(Division by zero error) ");
return 0;
}
return x / y;
}

pub const mod = fn (x: int, y: int) int {
pub const mod -> fn (x: int, y: int) int {
if (y == 0) {
output("(Division by zero error) ");
return 0;
}
return x % y;
}

pub const fib = fn (n: int, a: int, b: int) int {
pub const fib -> fn (n: int, a: int, b: int) int {
if (n == 0) { return a; }
if (n == 1) { return b; }
return fib(n - 1, b, a + b);
}

pub const power = fn (base: double, exponent: int) double {
pub const power -> fn (base: double, exponent: int) double {
if (exponent == 0) { return 1.0; }

let result: double = 1.0;
Expand All @@ -76,17 +76,17 @@ pub const power = fn (base: double, exponent: int) double {
return result;
}

pub const max_size = fn (a: int, b: int) int {
pub const max_size -> fn (a: int, b: int) int {
if (a > b) { return a; }
return b;
}

pub const min_size = fn (a: int, b: int) int {
pub const min_size -> fn (a: int, b: int) int {
if (a < b) { return a; }
return b;
}

pub const sin = fn (a: double) double {
pub const sin -> fn (a: double) double {
// Normalize into [0, TWO_PI)
let k: int = cast<int>(a / TWO_PI);
a = a - k * TWO_PI;
Expand Down Expand Up @@ -122,15 +122,15 @@ pub const sin = fn (a: double) double {
}
}

pub const cos = fn (x: double) double { return sin(x + HALF_PI); }
pub const cos -> fn (x: double) double { return sin(x + HALF_PI); }

pub const tan = fn (x: double) double { return sin(x)/(cos(x)+0.000000001); }
pub const tan -> fn (x: double) double { return sin(x)/(cos(x)+0.000000001); }

pub const sec = fn (x: double) double { return 1/(cos(x)+0.000000001); }
pub const sec -> fn (x: double) double { return 1/(cos(x)+0.000000001); }

pub const csc = fn (x: double) double { return 1/(sin(x)+0.000000001); }
pub const csc -> fn (x: double) double { return 1/(sin(x)+0.000000001); }

pub const cot = fn (x: double) double { return cos(x)/(sin(x)+0.000000001); }
pub const cot -> fn (x: double) double { return cos(x)/(sin(x)+0.000000001); }

// const f = fn (x: double) double {
// return math::sin(x);
Expand Down
34 changes: 17 additions & 17 deletions std/memory.lx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@module "memory"

pub const memcpy = fn (dest: *void, src: *void, n: int) *void {
pub const memcpy -> fn (dest: *void, src: *void, n: int) *void {
let d: *char = cast<*char>(dest);
let s: *char = cast<*char>(src);

Expand All @@ -11,7 +11,7 @@ pub const memcpy = fn (dest: *void, src: *void, n: int) *void {
return dest;
}

pub const memcmp = fn (a: *void, b: *void, n: int) int {
pub const memcmp -> fn (a: *void, b: *void, n: int) int {
let x: *char = cast<*char>(a);
let y: *char = cast<*char>(b);
loop [i: int = 0](i < n) : (++i) {
Expand All @@ -22,7 +22,7 @@ pub const memcmp = fn (a: *void, b: *void, n: int) int {
return 0;
}

pub const memset = fn (dest: *void, value: int, n: int) *void {
pub const memset -> fn (dest: *void, value: int, n: int) *void {
let d: *char = cast<*char>(dest);
let c: char = cast<char>(value);
let i: int = 0;
Expand All @@ -40,7 +40,7 @@ pub const memset = fn (dest: *void, value: int, n: int) *void {
}

// Move memory regions (handles overlapping regions correctly)
pub const memmove = fn (dest: *void, src: *void, n: int) *void {
pub const memmove -> fn (dest: *void, src: *void, n: int) *void {
let d: *char = cast<*char>(dest);
let s: *char = cast<*char>(src);

Expand All @@ -60,7 +60,7 @@ pub const memmove = fn (dest: *void, src: *void, n: int) *void {
}

// Find first occurrence of byte in memory
pub const memchr = fn (ptr: *void, value: int, n: int) *void {
pub const memchr -> fn (ptr: *void, value: int, n: int) *void {
let p: *char = cast<*char>(ptr);
let target: char = cast<char>(value);

Expand All @@ -74,11 +74,11 @@ pub const memchr = fn (ptr: *void, value: int, n: int) *void {
}

// Zero out memory (common operation)
pub const memzero = fn (dest: *void, n: int) *void { return memset(dest, 0, n); }
pub const memzero -> fn (dest: *void, n: int) *void { return memset(dest, 0, n); }

// Allocate and zero memory (calloc equivalent)
#returns_ownership
pub const calloc = fn (count: int, size: int) *void {
pub const calloc -> fn (count: int, size: int) *void {
let total_size: int = count * size;
let ptr: *void = alloc(total_size);

Expand All @@ -91,7 +91,7 @@ pub const calloc = fn (count: int, size: int) *void {

// Reallocate memory (simplified version - allocates new and copies)
#returns_ownership
pub const realloc = fn (ptr: *void, new_size: int) *void {
pub const realloc -> fn (ptr: *void, new_size: int) *void {
if (ptr == cast<*void>(0)) {
return alloc(new_size);
}
Expand All @@ -104,7 +104,7 @@ pub const realloc = fn (ptr: *void, new_size: int) *void {
}

// Memory swap (swap contents of two memory regions)
pub const memswap = fn (a: *void, b: *void, n: int) void {
pub const memswap -> fn (a: *void, b: *void, n: int) void {
let p1: *char = cast<*char>(a);
let p2: *char = cast<*char>(b);

Expand All @@ -115,7 +115,7 @@ pub const memswap = fn (a: *void, b: *void, n: int) void {
}
}

pub const memswapn = fn (a: *void, b: *void, count: int, size: int) void {
pub const memswapn -> fn (a: *void, b: *void, count: int, size: int) void {
let temp: *void = alloc(size);

loop [i: int = 0](i < count) : (++i) {
Expand All @@ -130,7 +130,7 @@ pub const memswapn = fn (a: *void, b: *void, count: int, size: int) void {
free(temp);
}

pub const memfill = fn (dest: *void, value: int, size: int, count: int) *void {
pub const memfill -> fn (dest: *void, value: int, size: int, count: int) *void {
if (size == 1) {
// Fill char/byte
let d: *char = cast<*char>(dest);
Expand Down Expand Up @@ -158,7 +158,7 @@ pub const memfill = fn (dest: *void, value: int, size: int, count: int) *void {
}

// Reverse bytes in memory region
pub const memrev = fn (ptr: *void, n: int) *void {
pub const memrev -> fn (ptr: *void, n: int) *void {
let p: *char = cast<*char>(ptr);
let start: int = 0;
let end: int = n - 1;
Expand All @@ -174,7 +174,7 @@ pub const memrev = fn (ptr: *void, n: int) *void {
}

// Count occurrences of a byte in memory
pub const memcount = fn (ptr: *void, value: int, n: int) int {
pub const memcount -> fn (ptr: *void, value: int, n: int) int {
let p: *char = cast<*char>(ptr);
let target: char = cast<char>(value);
let count: int = 0;
Expand All @@ -190,7 +190,7 @@ pub const memcount = fn (ptr: *void, value: int, n: int) int {

// Duplicate memory region
#returns_ownership
pub const memdup = fn (src: *void, n: int) *void {
pub const memdup -> fn (src: *void, n: int) *void {
let dest: *void = alloc(n);
if (dest != cast<*void>(0)) {
memcpy(dest, src, n);
Expand All @@ -199,12 +199,12 @@ pub const memdup = fn (src: *void, n: int) *void {
}

// Check if memory regions are equal
pub const memeq = fn (a: *void, b: *void, n: int) bool {
pub const memeq -> fn (a: *void, b: *void, n: int) bool {
return memcmp(a, b, n) == 0;
}

// Find substring in memory
pub const memmem = fn (haystack: *void, haystack_len: int, needle: *void, needle_len: int) *void {
pub const memmem -> fn (haystack: *void, haystack_len: int, needle: *void, needle_len: int) *void {
if (needle_len == 0) { return haystack; }
if (needle_len > haystack_len) { return cast<*void>(0); }

Expand All @@ -228,7 +228,7 @@ pub const memmem = fn (haystack: *void, haystack_len: int, needle: *void, needle
return cast<*void>(0);
}

pub const align = fn (member_alignments: *int, count: int) int {
pub const align -> fn (member_alignments: *int, count: int) int {
let max: int = 1;
loop [i: int = 0](i < count) : (++i) {
if (max < cast<*int>(member_alignments)[i]) {
Expand Down
Loading