This version does not work for the minimal.onyx.
casts X to type T
- [ ] Numeric literals are parsed and minimum type detected
+ [X] Curly braces are required for all bodies of blocks
+ [ ] Numeric literals are parsed
+ [ ] Numeric literals have the minimum type detected (automatically upcasts)
[ ] Comparison operators
[ ] Proper boolean type
[ ] Conditional branching works as expected
- [ ] Curly braces are required for all bodies of blocks
[ ] Simple while loop is functioning as expected
[ ] break and continue semantics
[ ] Function calling works for the builtin types
[ ] Devise and implement a simple set of implicit type casting rules.
- Numeric literals always type cast to whatever type is needed (very flexible).
+ [ ] Strings should work as pointers to data.
+ - Literals should be placed in data section with pointers to the start.
+ - Should strings be null-terminated or a length at the start of the string?
+
[ ] Start work on evaluating compile time known values.
- An expression marked COMPTIME will be reduced to its value in the parse tree.
TOKEN_TYPE_KEYWORD_FOR,
TOKEN_TYPE_KEYWORD_DO,
TOKEN_TYPE_KEYWORD_RETURN,
- TOKEN_TYPE_KEYWORD_CONST,
TOKEN_TYPE_KEYWORD_FOREIGN,
TOKEN_TYPE_KEYWORD_PROC,
TOKEN_TYPE_KEYWORD_GLOBAL,
TOKEN_TYPE_CLOSE_BRACE,
TOKEN_TYPE_OPEN_BRACKET,
TOKEN_TYPE_CLOSE_BRACKET,
- TOKEN_TYPE_OPEN_ANGLE,
- TOKEN_TYPE_CLOSE_ANGLE,
TOKEN_TYPE_SYM_PLUS,
TOKEN_TYPE_SYM_MINUS,
TOKEN_TYPE_SYM_COLON,
TOKEN_TYPE_SYM_SEMICOLON,
TOKEN_TYPE_SYM_COMMA,
+ TOKEN_TYPE_SYM_GREATER,
+ TOKEN_TYPE_SYM_GREATER_EQUAL,
+ TOKEN_TYPE_SYM_LESS,
+ TOKEN_TYPE_SYM_LESS_EQUAL,
TOKEN_TYPE_SYM_EQUALS,
- TOKEN_TYPE_SYM_GRAVE,
TOKEN_TYPE_SYM_TILDE,
TOKEN_TYPE_SYM_BANG,
TOKEN_TYPE_SYM_CARET,
typedef struct OnyxAstNodeBlock OnyxAstNodeBlock;
typedef struct OnyxAstNodeParam OnyxAstNodeParam;
typedef struct OnyxAstNodeFuncDef OnyxAstNodeFuncDef;
+typedef struct OnyxAstNodeCall OnyxAstNodeCall;
typedef struct OnyxParser {
OnyxTokenizer *tokenizer; // NOTE: not used since all tokens are lexed before parsing starts
OnyxAstNodeParam *params;
};
+struct OnyxAstNodeCall {
+ OnyxAstNodeKind kind;
+ u32 flags;
+ OnyxToken *token; // NOTE: Not specified (undefined)
+ OnyxTypeInfo *type; // NOTE: The type that the function returns
+ OnyxAstNode *next;
+ OnyxAstNode *callee; // NOTE: Function definition node
+ OnyxAstNode *arguments; // NOTE: Expressions that form the actual param list
+ // They will be chained down using the "next" property
+ // unless this becomes used by something else
+};
+
union OnyxAstNode {
// Generic node structure for capturing all binary ops and statements
OnyxAstNodeParam as_param;
OnyxAstNodeLocal as_local;
OnyxAstNodeScope as_scope;
+ OnyxAstNodeCall as_call;
};
const char* onyx_ast_node_kind_string(OnyxAstNodeKind kind);
-/* This is a comment
-This is also the only way to do comments
-*/
-
use "core"; /* Looks for "core.onyx" in the current directory */
Foo :: struct { x i32, y i32 };
add :: proc (a i32, b i32) -> i32 {
return a + b + 1234.56;
-};
\ No newline at end of file
+};
c := a - b; // Mutable
d :: a + b; // Constant
- {
- f :: 10;
- };
-
return (c * d) as i32;
}
export main :: proc () {
-
+ add(2, 3);
}
-/* Comments need to be parsed
- /* nested comments /* are /* okay */ */ */
-*/
-
foreign console {
log :: proc (data ptr, length i32) -> void ---;
}
export add :: proc (a i32, b i32) -> i32 {
return a + b;
-};
+}
export max :: proc (a i32, b i32) -> i32 {
- /* Curly braces are required */
- x := "String literal! HERE \\\"Woot Woot\" done";
-
+ // Curly braces are always required
if a > b {
return a;
} else {
return b;
}
-};
+}
-export main :: proc () -> void {
+export main :: proc () {
console.log(add(2, 3));
console.log(max(5, 10));
-};
+}
"for", //"TOKEN_TYPE_KEYWORD_FOR",
"do", //"TOKEN_TYPE_KEYWORD_DO",
"return", //"TOKEN_TYPE_KEYWORD_RETURN",
- "const", //"TOKEN_TYPE_KEYWORD_CONST",
"foreign", //"TOKEN_TYPE_KEYWORD_FOREIGN",
"proc", //"TOKEN_TYPE_KEYWORD_PROC",
"global", //"TOKEN_TYPE_KEYWORD_GLOBAL",
"}", //"TOKEN_TYPE_CLOSE_BRACE",
"[", //"TOKEN_TYPE_OPEN_BRACKET",
"]", //"TOKEN_TYPE_CLOSE_BRACKET",
- "<", //"TOKEN_TYPE_OPEN_ANGLE",
- ">", //"TOKEN_TYPE_CLOSE_ANGLE",
"+", // "TOKEN_TYPE_SYM_PLUS",
"-", // "TOKEN_TYPE_SYM_MINUS",
":", // "TOKEN_TYPE_SYM_COLON",
";", // "TOKEN_TYPE_SYM_SEMICOLON",
",", // "TOKEN_TYPE_SYM_COMMA",
+ ">", // "TOKEN_TYPE_SYM_GREATER",
+ ">=", // "TOKEN_TYPE_SYM_GREATER_EQUAL",
+ "<", // "TOKEN_TYPE_SYM_LESS",
+ "<=", // "TOKEN_TYPE_SYM_LESS_EQUAL",
"=", // "TOKEN_TYPE_SYM_EQUALS",
- "`", // "TOKEN_TYPE_SYM_GRAVE",
"~", // "TOKEN_TYPE_SYM_TILDE",
"!", // "TOKEN_TYPE_SYM_BANG",
"^", // "TOKEN_TYPE_SYM_CARET",
LITERAL_TOKEN("foreign", TOKEN_TYPE_KEYWORD_FOREIGN);
LITERAL_TOKEN("for", TOKEN_TYPE_KEYWORD_FOR);
LITERAL_TOKEN("return", TOKEN_TYPE_KEYWORD_RETURN);
- LITERAL_TOKEN("const", TOKEN_TYPE_KEYWORD_CONST);
LITERAL_TOKEN("do", TOKEN_TYPE_KEYWORD_DO);
LITERAL_TOKEN("proc", TOKEN_TYPE_KEYWORD_PROC);
LITERAL_TOKEN("global", TOKEN_TYPE_KEYWORD_GLOBAL);
LITERAL_TOKEN("as", TOKEN_TYPE_KEYWORD_CAST);
LITERAL_TOKEN("->", TOKEN_TYPE_RIGHT_ARROW);
LITERAL_TOKEN("<-", TOKEN_TYPE_RIGHT_ARROW);
+ LITERAL_TOKEN("<=", TOKEN_TYPE_SYM_LESS_EQUAL);
+ LITERAL_TOKEN(">=", TOKEN_TYPE_SYM_GREATER_EQUAL);
LITERAL_TOKEN("(", TOKEN_TYPE_OPEN_PAREN);
LITERAL_TOKEN(")", TOKEN_TYPE_CLOSE_PAREN);
LITERAL_TOKEN("{", TOKEN_TYPE_OPEN_BRACE);
LITERAL_TOKEN("}", TOKEN_TYPE_CLOSE_BRACE);
LITERAL_TOKEN("[", TOKEN_TYPE_OPEN_BRACKET);
LITERAL_TOKEN("]", TOKEN_TYPE_CLOSE_BRACKET);
- LITERAL_TOKEN("<", TOKEN_TYPE_OPEN_ANGLE);
- LITERAL_TOKEN(">", TOKEN_TYPE_CLOSE_ANGLE);
LITERAL_TOKEN("+", TOKEN_TYPE_SYM_PLUS);
LITERAL_TOKEN("-", TOKEN_TYPE_SYM_MINUS);
LITERAL_TOKEN("*", TOKEN_TYPE_SYM_STAR);
LITERAL_TOKEN(":", TOKEN_TYPE_SYM_COLON);
LITERAL_TOKEN(";", TOKEN_TYPE_SYM_SEMICOLON);
LITERAL_TOKEN(",", TOKEN_TYPE_SYM_COMMA);
+ LITERAL_TOKEN(">", TOKEN_TYPE_SYM_GREATER);
+ LITERAL_TOKEN("<", TOKEN_TYPE_SYM_LESS);
LITERAL_TOKEN("=", TOKEN_TYPE_SYM_EQUALS);
- LITERAL_TOKEN("`", TOKEN_TYPE_SYM_GRAVE);
LITERAL_TOKEN("~", TOKEN_TYPE_SYM_TILDE);
LITERAL_TOKEN("!", TOKEN_TYPE_SYM_BANG);
LITERAL_TOKEN("^", TOKEN_TYPE_SYM_CARET);
-
#include "onyxlex.h"
#include "onyxmsgs.h"
#include "onyxparser.h"
static void parser_prev_token(OnyxParser* parser) {
// TODO: This is probably wrong
- parser->prev_token--;
while (parser->prev_token->type == TOKEN_TYPE_COMMENT) parser->prev_token--;
parser->curr_token = parser->prev_token;
parser->prev_token--;
onyx_token_null_toggle(*sym_token);
}
- // TODO: Handle calling a function
- return sym_node;
+ if (parser->curr_token->type != TOKEN_TYPE_OPEN_PAREN) {
+ return sym_node;
+ }
+
+ // NOTE: Function call
+ expect(parser, TOKEN_TYPE_OPEN_PAREN);
+
+ OnyxAstNodeCall* call_node = (OnyxAstNodeCall *) onyx_ast_node_new(parser->allocator, ONYX_AST_NODE_KIND_CALL);
+ call_node->callee = sym_node;
+ OnyxAstNode** prev = &call_node->arguments;
+ OnyxAstNode* curr = NULL;
+ while (parser->curr_token->type != TOKEN_TYPE_CLOSE_PAREN) {
+ curr = parse_expression(parser);
+
+ if (curr != NULL && curr->kind != ONYX_AST_NODE_KIND_ERROR) {
+ *prev = curr;
+ prev = &curr->next;
+ }
+
+ if (parser->curr_token->type == TOKEN_TYPE_CLOSE_PAREN)
+ break;
+
+ if (parser->curr_token->type != TOKEN_TYPE_SYM_COMMA) {
+ onyx_message_add(parser->msgs,
+ ONYX_MESSAGE_TYPE_EXPECTED_TOKEN,
+ parser->curr_token->pos,
+ onyx_get_token_type_name(TOKEN_TYPE_SYM_COMMA),
+ onyx_get_token_type_name(parser->curr_token->type));
+ return &error_node;
+ }
+
+ parser_next_token(parser);
+ }
+ parser_next_token(parser);
+
+ return (OnyxAstNode *) call_node;
}
case TOKEN_TYPE_LITERAL_NUMERIC:
case TOKEN_TYPE_SYM_STAR: kind = ONYX_AST_NODE_KIND_MULTIPLY; break;
case TOKEN_TYPE_SYM_FSLASH: kind = ONYX_AST_NODE_KIND_DIVIDE; break;
case TOKEN_TYPE_SYM_PERCENT: kind = ONYX_AST_NODE_KIND_MODULUS; break;
+ default: break;
}
if (kind != -1) {
return cast_node;
}
+ default: break;
}
return left;
break;
}
}
+
+ default: break;
}
parser_next_token(parser);
case ONYX_AST_NODE_KIND_BLOCK: process_block(mod, func, (OnyxAstNodeBlock *) expr); break;
+ case ONYX_AST_NODE_KIND_CALL:
+ {
+ DEBUG_HERE;
+ break;
+ }
+
default:
DEBUG_HERE;
bh_printf("Unhandled case: %d\n", expr->kind);