- ios: --target ios/ios-sim shorthands, iOS SDK auto-discovery,
#framework directive + BuildOptions.add_framework hook,
.app bundle + Info.plist + codesign (ad-hoc and real),
--codesign-identity/--provisioning-profile/--entitlements flags,
modules/std/{objc,uikit}.sx, dynamic class registration,
typed objc_msgSend cast pattern, UIApplicationMain handoff,
UIWindow scene attach. Runs on iPhone hardware.
- ir: silent .s64 defaults → loud diagnostics,
resolveReturnType infers from body, sub-byte int sizes match LLVM,
tuple type interning includes names, compile errors exit 1
- issue-NNNN convention: resolved bugs rename to focused features
- 50 regression tests passing
240 lines
5.6 KiB
Zig
240 lines
5.6 KiB
Zig
pub const Tag = enum {
|
|
// Literals
|
|
int_literal,
|
|
float_literal,
|
|
string_literal,
|
|
raw_string_literal,
|
|
|
|
// Identifiers and keywords
|
|
identifier,
|
|
kw_if,
|
|
kw_else,
|
|
kw_then,
|
|
kw_true,
|
|
kw_false,
|
|
kw_enum,
|
|
kw_case,
|
|
kw_break,
|
|
kw_continue,
|
|
kw_while,
|
|
kw_for,
|
|
kw_return,
|
|
kw_defer,
|
|
kw_f32,
|
|
kw_f64,
|
|
kw_struct,
|
|
kw_union,
|
|
kw_xx,
|
|
kw_and,
|
|
kw_or,
|
|
kw_Type, // Type (metatype keyword)
|
|
kw_null, // null
|
|
kw_push, // push
|
|
kw_ufcs, // ufcs
|
|
kw_in, // in
|
|
kw_closure, // closure
|
|
kw_protocol, // protocol
|
|
kw_impl, // impl
|
|
kw_Self, // Self (in protocol declarations)
|
|
kw_inline, // inline (compile-time if/for/while)
|
|
kw_callconv, // callconv (calling convention annotation)
|
|
|
|
// Symbols
|
|
colon, // :
|
|
colon_colon, // ::
|
|
colon_equal, // :=
|
|
semicolon, // ;
|
|
comma, // ,
|
|
dot, // .
|
|
dot_dot, // ..
|
|
dollar, // $
|
|
|
|
// Operators
|
|
plus, // +
|
|
minus, // -
|
|
star, // *
|
|
slash, // /
|
|
equal, // =
|
|
equal_equal, // ==
|
|
bang, // !
|
|
bang_equal, // !=
|
|
less, // <
|
|
less_equal, // <=
|
|
greater, // >
|
|
greater_equal, // >=
|
|
plus_equal, // +=
|
|
minus_equal, // -=
|
|
star_equal, // *=
|
|
slash_equal, // /=
|
|
percent, // %
|
|
percent_equal, // %=
|
|
ampersand, // &
|
|
ampersand_equal, // &=
|
|
at, // @
|
|
pipe, // |
|
|
pipe_equal, // |=
|
|
pipe_arrow, // |>
|
|
caret, // ^
|
|
caret_equal, // ^=
|
|
question, // ?
|
|
question_question, // ??
|
|
question_dot, // ?.
|
|
tilde, // ~
|
|
less_less, // <<
|
|
less_less_equal, // <<=
|
|
greater_greater, // >>
|
|
greater_greater_equal, // >>=
|
|
|
|
// Delimiters
|
|
l_paren, // (
|
|
r_paren, // )
|
|
l_brace, // {
|
|
r_brace, // }
|
|
l_bracket, // [
|
|
r_bracket, // ]
|
|
|
|
// Arrows
|
|
arrow, // ->
|
|
fat_arrow, // =>
|
|
|
|
// Directives
|
|
hash_run, // #run
|
|
hash_import, // #import
|
|
hash_insert, // #insert
|
|
hash_builtin, // #builtin
|
|
hash_compiler, // #compiler
|
|
hash_foreign, // #foreign
|
|
hash_library, // #library
|
|
hash_framework, // #framework
|
|
hash_using, // #using
|
|
hash_include, // #include (inside #import c { ... })
|
|
hash_source, // #source (inside #import c { ... })
|
|
hash_define, // #define (inside #import c { ... })
|
|
hash_flags, // #flags (inside #import c { ... })
|
|
hash_inline, // #inline (protocol layout modifier)
|
|
triple_minus, // ---
|
|
|
|
// Special
|
|
eof,
|
|
invalid,
|
|
|
|
pub fn lexeme(tag: Tag) ?[]const u8 {
|
|
return switch (tag) {
|
|
.colon => ":",
|
|
.colon_colon => "::",
|
|
.colon_equal => ":=",
|
|
.semicolon => ";",
|
|
.comma => ",",
|
|
.dot => ".",
|
|
.dot_dot => "..",
|
|
.dollar => "$",
|
|
.plus => "+",
|
|
.minus => "-",
|
|
.star => "*",
|
|
.slash => "/",
|
|
.equal => "=",
|
|
.equal_equal => "==",
|
|
.bang => "!",
|
|
.bang_equal => "!=",
|
|
.less => "<",
|
|
.less_equal => "<=",
|
|
.greater => ">",
|
|
.greater_equal => ">=",
|
|
.plus_equal => "+=",
|
|
.minus_equal => "-=",
|
|
.star_equal => "*=",
|
|
.slash_equal => "/=",
|
|
.percent => "%",
|
|
.percent_equal => "%=",
|
|
.ampersand => "&",
|
|
.ampersand_equal => "&=",
|
|
.at => "@",
|
|
.pipe => "|",
|
|
.pipe_equal => "|=",
|
|
.pipe_arrow => "|>",
|
|
.caret => "^",
|
|
.caret_equal => "^=",
|
|
.question => "?",
|
|
.question_question => "??",
|
|
.question_dot => "?.",
|
|
.tilde => "~",
|
|
.less_less => "<<",
|
|
.less_less_equal => "<<=",
|
|
.greater_greater => ">>",
|
|
.greater_greater_equal => ">>=",
|
|
.kw_null => "null",
|
|
.l_paren => "(",
|
|
.r_paren => ")",
|
|
.l_brace => "{",
|
|
.r_brace => "}",
|
|
.l_bracket => "[",
|
|
.r_bracket => "]",
|
|
.arrow => "->",
|
|
.fat_arrow => "=>",
|
|
.triple_minus => "---",
|
|
else => null,
|
|
};
|
|
}
|
|
|
|
pub fn isTypeKeyword(tag: Tag) bool {
|
|
return switch (tag) {
|
|
.kw_f32, .kw_f64, .kw_Type, .kw_Self => true,
|
|
else => false,
|
|
};
|
|
}
|
|
};
|
|
|
|
pub const Token = struct {
|
|
tag: Tag,
|
|
loc: Loc,
|
|
|
|
pub const Loc = struct {
|
|
start: u32,
|
|
end: u32,
|
|
};
|
|
|
|
pub fn slice(self: Token, source: []const u8) []const u8 {
|
|
return source[self.loc.start..self.loc.end];
|
|
}
|
|
};
|
|
|
|
pub const keywords = std.StaticStringMap(Tag).initComptime(.{
|
|
.{ "if", .kw_if },
|
|
.{ "else", .kw_else },
|
|
.{ "then", .kw_then },
|
|
.{ "true", .kw_true },
|
|
.{ "false", .kw_false },
|
|
.{ "enum", .kw_enum },
|
|
.{ "case", .kw_case },
|
|
.{ "break", .kw_break },
|
|
.{ "continue", .kw_continue },
|
|
.{ "while", .kw_while },
|
|
.{ "for", .kw_for },
|
|
.{ "return", .kw_return },
|
|
.{ "defer", .kw_defer },
|
|
.{ "f32", .kw_f32 },
|
|
.{ "f64", .kw_f64 },
|
|
.{ "struct", .kw_struct },
|
|
.{ "union", .kw_union },
|
|
.{ "xx", .kw_xx },
|
|
.{ "and", .kw_and },
|
|
.{ "or", .kw_or },
|
|
.{ "Type", .kw_Type },
|
|
.{ "null", .kw_null },
|
|
.{ "push", .kw_push },
|
|
.{ "ufcs", .kw_ufcs },
|
|
.{ "in", .kw_in },
|
|
.{ "closure", .kw_closure },
|
|
.{ "protocol", .kw_protocol },
|
|
.{ "impl", .kw_impl },
|
|
.{ "Self", .kw_Self },
|
|
.{ "inline", .kw_inline },
|
|
.{ "callconv", .kw_callconv },
|
|
});
|
|
|
|
pub fn getKeyword(bytes: []const u8) ?Tag {
|
|
return keywords.get(bytes);
|
|
}
|
|
|
|
const std = @import("std");
|