diff --git a/gcc/elna-generic.cc b/gcc/elna-generic.cc index 6626adb..620c32c 100644 --- a/gcc/elna-generic.cc +++ b/gcc/elna-generic.cc @@ -154,7 +154,9 @@ namespace elna::gcc } else if (constant_expression != boolean_true_node) { - this->current_expression = call_built_in(call_location, "__builtin_trap", void_type_node); + tree assert_expression = call_built_in(call_location, "__builtin_trap", void_type_node); + this->current_expression = build3(COND_EXPR, void_type_node, this->current_expression, + NULL_TREE, assert_expression); } else { @@ -486,7 +488,6 @@ namespace elna::gcc { gcc_unreachable(); } - if (left_type == elna_bool_type_node) { return build2_loc(expression_location, logical_code, elna_bool_type_node, left, right); @@ -497,8 +498,7 @@ namespace elna::gcc } else { - error_at(expression_location, - "Invalid operands of type '%s' and '%s' for operator %s", + error_at(expression_location, "Invalid operands of type '%s' and '%s' for operator %s", print_type(left_type).c_str(), print_type(right_type).c_str(), elna::boot::print_binary_operator(expression->operation())); return error_mark_node; @@ -810,21 +810,18 @@ namespace elna::gcc this->current_expression = error_mark_node; return; } - if (this->current_expression != elna_word_type_node) - { - this->current_expression = convert(elna_word_type_node, this->current_expression); - } - tree offset = build2(MINUS_EXPR, elna_word_type_node, this->current_expression, size_one_node); + tree offset = fold_convert(elna_word_type_node, this->current_expression); if (TREE_CODE(TREE_TYPE(designator)) == ARRAY_TYPE) { tree element_type = TREE_TYPE(TREE_TYPE(designator)); this->current_expression = build4_loc(location, - ARRAY_REF, element_type, designator, offset, NULL_TREE, NULL_TREE); + ARRAY_REF, element_type, designator, offset, size_one_node, NULL_TREE); } else if (TREE_TYPE(designator) == elna_string_type_node) { + offset = build2(MINUS_EXPR, elna_word_type_node, offset, size_one_node); tree string_ptr = build3_loc(location, COMPONENT_REF, TREE_TYPE(elna_string_ptr_field_node), designator, elna_string_ptr_field_node, NULL_TREE); diff --git a/gcc/elna-tree.cc b/gcc/elna-tree.cc index d00a39a..7860d75 100644 --- a/gcc/elna-tree.cc +++ b/gcc/elna-tree.cc @@ -21,7 +21,6 @@ along with GCC; see the file COPYING3. If not see #include "function.h" #include "stor-layout.h" -#include "fold-const.h" #include "diagnostic-core.h" namespace elna::gcc @@ -248,9 +247,8 @@ namespace elna::gcc tree build_static_array_type(tree type, const std::uint64_t size) { - tree lower_bound = build_int_cst_type(integer_type_node, 0); tree upper_bound = build_int_cst_type(integer_type_node, size); - tree range_type = build_range_type(integer_type_node, lower_bound, upper_bound); + tree range_type = build_range_type(integer_type_node, size_one_node, upper_bound); return build_array_type(type, range_type); } diff --git a/include/elna/gcc/elna-tree.h b/include/elna/gcc/elna-tree.h index e605d51..f1402a7 100644 --- a/include/elna/gcc/elna-tree.h +++ b/include/elna/gcc/elna-tree.h @@ -25,6 +25,7 @@ along with GCC; see the file COPYING3. If not see #include "tree.h" #include "tree-iterator.h" #include "stringpool.h" +#include "fold-const.h" #include "elna/boot/ast.h" #include "elna/boot/symbol.h" @@ -97,6 +98,8 @@ namespace elna::gcc tree fndecl_type = build_function_type(return_type, TYPE_ARG_TYPES(*builtin)); tree builtin_addr = build1_loc(call_location, ADDR_EXPR, build_pointer_type(fndecl_type), *builtin); - return build_call_nary(return_type, builtin_addr, sizeof...(Args), arguments...); + tree argument_trees[sizeof...(Args)] = {arguments...}; + + return fold_build_call_array(return_type, builtin_addr, sizeof...(Args), argument_trees); } } diff --git a/source/main.elna b/source/main.elna index f6c7ce7..0f3d001 100644 --- a/source/main.elna +++ b/source/main.elna @@ -196,10 +196,10 @@ begin end; while value <> 0 do digit := value % 10; - value := value / 10; + value := value / 10; - buffer[n] := cast(cast('0': Int) + digit: Char); - n := n - 1u + buffer[n] := cast(cast('0': Int) + digit: Char); + n := n - 1u end; while n < 10u do n := n + 1u; @@ -309,7 +309,7 @@ begin if source_file^.index > source_file^.size then source_file^.size := fread(cast(@source_file^.buffer: Pointer), 1u, 1024u, source_file^.handle); - source_file^.index := 1u + source_file^.index := 1u end; return source_file^.size = 0u @@ -366,41 +366,41 @@ var successful: Bool; begin if escape = 'n' then - result^ := '\n'; - successful := true + result^ := '\n'; + successful := true elsif escape = 'a' then - result^ := '\a'; - successful := true + result^ := '\a'; + successful := true elsif escape = 'b' then - result^ := '\b'; - successful := true + result^ := '\b'; + successful := true elsif escape = 't' then - result^ := '\t'; - successful := true + result^ := '\t'; + successful := true elsif escape = 'f' then - result^ := '\f'; - successful := true + result^ := '\f'; + successful := true elsif escape = 'r' then - result^ := '\r'; - successful := true + result^ := '\r'; + successful := true elsif escape = 'v' then - result^ := '\v'; - successful := true + result^ := '\v'; + successful := true elsif escape = '\\' then - result^ := '\\'; - successful := true + result^ := '\\'; + successful := true elsif escape = '\'' then - result^ := '\''; - successful := true + result^ := '\''; + successful := true elsif escape = '"' then - result^ := '"'; - successful := true + result^ := '"'; + successful := true elsif escape = '?' then - result^ := '\?'; - successful := true + result^ := '\?'; + successful := true elsif escape = '0' then - result^ := '\0'; - successful := true + result^ := '\0'; + successful := true else successful := false end; @@ -417,8 +417,8 @@ begin if current = '\n' then source_code_break(source_code) - end; - source_code_advance(source_code) + end; + source_code_advance(source_code) end end; @@ -433,7 +433,7 @@ var begin while ~source_code_empty(source_code) & lexer_is_ident(source_code_head(source_code^)) do string_buffer_push(token_content, source_code_head(source_code^)); - source_code_advance(source_code) + source_code_advance(source_code) end end; @@ -445,15 +445,15 @@ begin while ~source_code_empty(source_code) & trailing < 2u do if source_code_head(source_code^) = '*' then - string_buffer_push(token_content, '*'); - trailing := 1u - elsif source_code_head(source_code^) = ')' & trailing = 1u then + string_buffer_push(token_content, '*'); + trailing := 1u + elsif source_code_head(source_code^) = ')' & trailing = 1u then string_buffer_pop(token_content, 1u); - trailing := 2u - else - string_buffer_push(token_content, source_code_head(source_code^)); - trailing := 0u - end; + trailing := 2u + else + string_buffer_push(token_content, source_code_head(source_code^)); + trailing := 0u + end; source_code_advance(source_code) end; @@ -471,9 +471,9 @@ begin source_code_advance(source_code); successful := ~source_code_empty(source_code) & lexer_escape(source_code_head(source_code^), token_content) - else + else token_content^ := source_code_head(source_code^); - successful := true + successful := true end end; if successful then @@ -524,64 +524,64 @@ var current_token: Token; begin if token_content = "if" then - current_token.kind := TokenKind._if + current_token.kind := TokenKind._if elsif token_content = "then" then - current_token.kind := TokenKind._then + current_token.kind := TokenKind._then elsif token_content = "else" then - current_token.kind := TokenKind._else + current_token.kind := TokenKind._else elsif token_content = "elsif" then - current_token.kind := TokenKind._elsif + current_token.kind := TokenKind._elsif elsif token_content = "while" then - current_token.kind := TokenKind._while + current_token.kind := TokenKind._while elsif token_content = "do" then - current_token.kind := TokenKind._do + current_token.kind := TokenKind._do elsif token_content = "proc" then - current_token.kind := TokenKind._proc + current_token.kind := TokenKind._proc elsif token_content = "begin" then - current_token.kind := TokenKind._begin + current_token.kind := TokenKind._begin elsif token_content = "end" then - current_token.kind := TokenKind._end + current_token.kind := TokenKind._end elsif token_content = "extern" then - current_token.kind := TokenKind._extern + current_token.kind := TokenKind._extern elsif token_content = "const" then - current_token.kind := TokenKind._const + current_token.kind := TokenKind._const elsif token_content = "var" then - current_token.kind := TokenKind._var + current_token.kind := TokenKind._var elsif token_content = "case" then - current_token.kind := TokenKind._case + current_token.kind := TokenKind._case elsif token_content = "of" then - current_token.kind := TokenKind._of + current_token.kind := TokenKind._of elsif token_content = "type" then - current_token.kind := TokenKind._type + current_token.kind := TokenKind._type elsif token_content = "record" then - current_token.kind := TokenKind._record + current_token.kind := TokenKind._record elsif token_content = "union" then - current_token.kind := TokenKind._union + current_token.kind := TokenKind._union elsif token_content = "true" then - current_token.kind := TokenKind.boolean; - current_token.value.boolean_value := true + current_token.kind := TokenKind.boolean; + current_token.value.boolean_value := true elsif token_content = "false" then - current_token.kind := TokenKind.boolean; - current_token.value.boolean_value := false + current_token.kind := TokenKind.boolean; + current_token.value.boolean_value := false elsif token_content = "nil" then - current_token.kind := TokenKind.null + current_token.kind := TokenKind.null elsif token_content = "or" then - current_token.kind := TokenKind._or + current_token.kind := TokenKind._or elsif token_content = "return" then - current_token.kind := TokenKind._return + current_token.kind := TokenKind._return elsif token_content = "cast" then - current_token.kind := TokenKind._cast + current_token.kind := TokenKind._cast elsif token_content = "defer" then - current_token.kind := TokenKind._defer + current_token.kind := TokenKind._defer elsif token_content = "program" then - current_token.kind := TokenKind._program + current_token.kind := TokenKind._program elsif token_content = "module" then current_token.kind := TokenKind._module elsif token_content = "import" then current_token.kind := TokenKind._import else - current_token.kind := TokenKind.identifier; - current_token.value.string := string_dup(token_content) + current_token.kind := TokenKind.identifier; + current_token.value.string := string_dup(token_content) end; return current_token @@ -611,162 +611,162 @@ begin lexer_identifier(@source_code, token_buffer); current_token := lexer_categorize(string_buffer_clear(token_buffer)) elsif first_char = '#' then - source_code_advance(@source_code); - lexer_identifier(@source_code, token_buffer); + source_code_advance(@source_code); + lexer_identifier(@source_code, token_buffer); - current_token.kind := TokenKind.trait; - current_token.value.string := string_dup(string_buffer_clear(token_buffer)) + current_token.kind := TokenKind.trait; + current_token.value.string := string_dup(string_buffer_clear(token_buffer)) elsif is_digit(first_char) then - lexer_number(@source_code, @current_token.value.int_value); + lexer_number(@source_code, @current_token.value.int_value); - if source_code_expect(@source_code, 'u') then - current_token.kind := TokenKind.word; - source_code_advance(@source_code) - else - current_token.kind := TokenKind.integer - end + if source_code_expect(@source_code, 'u') then + current_token.kind := TokenKind.word; + source_code_advance(@source_code) + else + current_token.kind := TokenKind.integer + end elsif first_char = '(' then - source_code_advance(@source_code); + source_code_advance(@source_code); - if source_code_empty(@source_code) then - current_token.kind := TokenKind.left_paren - elsif source_code_head(source_code) = '*' then - source_code_advance(@source_code); + if source_code_empty(@source_code) then + current_token.kind := TokenKind.left_paren + elsif source_code_head(source_code) = '*' then + source_code_advance(@source_code); - if lexer_comment(@source_code, token_buffer) then - current_token.value.string := string_dup(string_buffer_clear(token_buffer)); - current_token.kind := TokenKind.comment - else - current_token.kind := TokenKind.unknown - end - else - current_token.kind := TokenKind.left_paren - end + if lexer_comment(@source_code, token_buffer) then + current_token.value.string := string_dup(string_buffer_clear(token_buffer)); + current_token.kind := TokenKind.comment + else + current_token.kind := TokenKind.unknown + end + else + current_token.kind := TokenKind.left_paren + end elsif first_char = ')' then - current_token.kind := TokenKind.right_paren; - source_code_advance(@source_code) + current_token.kind := TokenKind.right_paren; + source_code_advance(@source_code) elsif first_char = '\'' then source_code_advance(@source_code); - if lexer_character(@source_code, @current_token.value.char_value) & source_code_expect(@source_code, '\'') then - current_token.kind := TokenKind.character; - source_code_advance(@source_code) - else - current_token.kind := TokenKind.unknown - end + if lexer_character(@source_code, @current_token.value.char_value) & source_code_expect(@source_code, '\'') then + current_token.kind := TokenKind.character; + source_code_advance(@source_code) + else + current_token.kind := TokenKind.unknown + end elsif first_char = '"' then source_code_advance(@source_code); - + if lexer_string(@source_code, token_buffer) then - current_token.kind := TokenKind.string; - current_token.value.string := string_dup(string_buffer_clear(token_buffer)) - else - current_token.kind := TokenKind.unknown - end + current_token.kind := TokenKind.string; + current_token.value.string := string_dup(string_buffer_clear(token_buffer)) + else + current_token.kind := TokenKind.unknown + end elsif first_char = '[' then - current_token.kind := TokenKind.left_square; - source_code_advance(@source_code) + current_token.kind := TokenKind.left_square; + source_code_advance(@source_code) elsif first_char = ']' then - current_token.kind := TokenKind.right_square; - source_code_advance(@source_code) + current_token.kind := TokenKind.right_square; + source_code_advance(@source_code) elsif first_char = '>' then - source_code_advance(@source_code); + source_code_advance(@source_code); if source_code_empty(@source_code) then - current_token.kind := TokenKind.greater_than - elsif source_code_head(source_code) = '=' then - current_token.kind := TokenKind.greater_equal; - source_code_advance(@source_code) - elsif source_code_head(source_code) = '>' then - current_token.kind := TokenKind.shift_right; - source_code_advance(@source_code) - else - current_token.kind := TokenKind.greater_than - end + current_token.kind := TokenKind.greater_than + elsif source_code_head(source_code) = '=' then + current_token.kind := TokenKind.greater_equal; + source_code_advance(@source_code) + elsif source_code_head(source_code) = '>' then + current_token.kind := TokenKind.shift_right; + source_code_advance(@source_code) + else + current_token.kind := TokenKind.greater_than + end elsif first_char = '<' then - source_code_advance(@source_code); - - if source_code_empty(@source_code) then - current_token.kind := TokenKind.less_than - elsif source_code_head(source_code) = '=' then - current_token.kind := TokenKind.less_equal; - source_code_advance(@source_code) - elsif source_code_head(source_code) = '<' then - current_token.kind := TokenKind.shift_left; - source_code_advance(@source_code) - elsif source_code_head(source_code) = '>' then - current_token.kind := TokenKind.not_equal; - source_code_advance(@source_code) - else - current_token.kind := TokenKind.less_than - end - elsif first_char = '=' then - current_token.kind := TokenKind.equal; - source_code_advance(@source_code) - elsif first_char = ';' then - current_token.kind := TokenKind.semicolon; - source_code_advance(@source_code) - elsif first_char = '.' then - current_token.kind := TokenKind.dot; - source_code_advance(@source_code) - elsif first_char = ',' then - current_token.kind := TokenKind.comma; - source_code_advance(@source_code) - elsif first_char = '+' then - current_token.kind := TokenKind.plus; - source_code_advance(@source_code) - elsif first_char = '-' then - source_code_advance(@source_code); + source_code_advance(@source_code); if source_code_empty(@source_code) then - current_token.kind := TokenKind.minus - elsif source_code_head(source_code) = '>' then - current_token.kind := TokenKind.arrow; - source_code_advance(@source_code) - else - current_token.kind := TokenKind.minus - end - elsif first_char = '*' then - current_token.kind := TokenKind.multiplication; - source_code_advance(@source_code) - elsif first_char = '/' then - current_token.kind := TokenKind.division; - source_code_advance(@source_code) - elsif first_char = '%' then - current_token.kind := TokenKind.remainder; - source_code_advance(@source_code) - elsif first_char = ':' then - source_code_advance(@source_code); + current_token.kind := TokenKind.less_than + elsif source_code_head(source_code) = '=' then + current_token.kind := TokenKind.less_equal; + source_code_advance(@source_code) + elsif source_code_head(source_code) = '<' then + current_token.kind := TokenKind.shift_left; + source_code_advance(@source_code) + elsif source_code_head(source_code) = '>' then + current_token.kind := TokenKind.not_equal; + source_code_advance(@source_code) + else + current_token.kind := TokenKind.less_than + end + elsif first_char = '=' then + current_token.kind := TokenKind.equal; + source_code_advance(@source_code) + elsif first_char = ';' then + current_token.kind := TokenKind.semicolon; + source_code_advance(@source_code) + elsif first_char = '.' then + current_token.kind := TokenKind.dot; + source_code_advance(@source_code) + elsif first_char = ',' then + current_token.kind := TokenKind.comma; + source_code_advance(@source_code) + elsif first_char = '+' then + current_token.kind := TokenKind.plus; + source_code_advance(@source_code) + elsif first_char = '-' then + source_code_advance(@source_code); - if source_code_empty(@source_code) then - current_token.kind := TokenKind.colon - elsif source_code_head(source_code) = '=' then - current_token.kind := TokenKind.assignment; - source_code_advance(@source_code) - else - current_token.kind := TokenKind.colon - end + if source_code_empty(@source_code) then + current_token.kind := TokenKind.minus + elsif source_code_head(source_code) = '>' then + current_token.kind := TokenKind.arrow; + source_code_advance(@source_code) + else + current_token.kind := TokenKind.minus + end + elsif first_char = '*' then + current_token.kind := TokenKind.multiplication; + source_code_advance(@source_code) + elsif first_char = '/' then + current_token.kind := TokenKind.division; + source_code_advance(@source_code) + elsif first_char = '%' then + current_token.kind := TokenKind.remainder; + source_code_advance(@source_code) + elsif first_char = ':' then + source_code_advance(@source_code); + + if source_code_empty(@source_code) then + current_token.kind := TokenKind.colon + elsif source_code_head(source_code) = '=' then + current_token.kind := TokenKind.assignment; + source_code_advance(@source_code) + else + current_token.kind := TokenKind.colon + end elsif first_char = '^' then - current_token.kind := TokenKind.hat; - source_code_advance(@source_code) + current_token.kind := TokenKind.hat; + source_code_advance(@source_code) elsif first_char = '@' then - current_token.kind := TokenKind.at; - source_code_advance(@source_code) + current_token.kind := TokenKind.at; + source_code_advance(@source_code) elsif first_char = '!' then - current_token.kind := TokenKind.exclamation; - source_code_advance(@source_code) + current_token.kind := TokenKind.exclamation; + source_code_advance(@source_code) elsif first_char = '&' then - current_token.kind := TokenKind.and; - source_code_advance(@source_code) + current_token.kind := TokenKind.and; + source_code_advance(@source_code) elsif first_char = '~' then - current_token.kind := TokenKind.not; - source_code_advance(@source_code) + current_token.kind := TokenKind.not; + source_code_advance(@source_code) elsif first_char = '|' then - current_token.kind := TokenKind.pipe; - source_code_advance(@source_code) + current_token.kind := TokenKind.pipe; + source_code_advance(@source_code) else - current_token.kind := TokenKind.unknown; - source_code_advance(@source_code) + current_token.kind := TokenKind.unknown; + source_code_advance(@source_code) end; return current_token @@ -785,16 +785,16 @@ begin lexer_spaces(@source_code); while ~source_code_empty(@source_code) do - current_token := lexer_next(source_code, @token_buffer); + current_token := lexer_next(source_code, @token_buffer); - if current_token.kind <> TokenKind.unknown then - lexer_add_token(@lexer, current_token); - lexer_spaces(@source_code) - else - write_s("Lexical analysis error on \""); - write_c(source_code_head(source_code)); - write_s("\".\n") - end + if current_token.kind <> TokenKind.unknown then + lexer_add_token(@lexer, current_token); + lexer_spaces(@source_code) + else + write_s("Lexical analysis error on \""); + write_c(source_code_head(source_code)); + write_s("\".\n") + end end; return lexer @@ -824,12 +824,12 @@ begin elsif strcmp(parameter^, "--parse\0".ptr) = 0 then result^.parse := true elsif parameter^^ <> '-' then - if result^.input <> nil then - write_s("Fatal error: Only one source file can be given.\n"); - result := nil - else + if result^.input <> nil then + write_s("Fatal error: Only one source file can be given.\n"); + result := nil + else result^.input := parameter^ - end + end else write_s("Fatal error: Unknown command line options: "); @@ -843,7 +843,7 @@ begin end; if result <> nil & result^.input = nil then write_s("Fatal error: no input files.\n"); - result := nil + result := nil end; return result @@ -863,151 +863,151 @@ begin current_token := tokens + i; case current_token^.kind of - TokenKind._if: - write_s("IF") + TokenKind._if: + write_s("IF") | TokenKind._then: - write_s("THEN") + write_s("THEN") | TokenKind._else: - write_s("ELSE") + write_s("ELSE") | TokenKind._elsif: - write_s("ELSIF") + write_s("ELSIF") | TokenKind._while: - write_s("WHILE") + write_s("WHILE") | TokenKind._do: - write_s("DO") - | TokenKind._proc: - write_s("PROC") - | TokenKind._begin: - write_s("BEGIN") - | TokenKind._end: - write_s("END") - | TokenKind._extern: - write_s("EXTERN") - | TokenKind._const: - write_s("CONST") - | TokenKind._var: - write_s("VAR") - | TokenKind._case: - write_s("CASE") - | TokenKind._of: - write_s("OF") - | TokenKind._type: - write_s("TYPE") - | TokenKind._record: - write_s("RECORD") - | TokenKind._union: - write_s("UNION") - | TokenKind.pipe: - write_s("|") - | TokenKind.to: - write_s("TO") - | TokenKind.boolean: - write_s("BOOLEAN<"); - write_b(current_token^.value.boolean_value); - write_c('>') - | TokenKind.null: - write_s("NIL") - | TokenKind.and: - write_s("&") - | TokenKind._or: - write_s("OR") - | TokenKind.not: - write_s("~") - | TokenKind._return: - write_s("RETURN") - | TokenKind._cast: - write_s("CAST") - | TokenKind.shift_left: - write_s("<<") - | TokenKind.shift_right: - write_s(">>") - | TokenKind.identifier: - write_c('<'); + write_s("DO") + | TokenKind._proc: + write_s("PROC") + | TokenKind._begin: + write_s("BEGIN") + | TokenKind._end: + write_s("END") + | TokenKind._extern: + write_s("EXTERN") + | TokenKind._const: + write_s("CONST") + | TokenKind._var: + write_s("VAR") + | TokenKind._case: + write_s("CASE") + | TokenKind._of: + write_s("OF") + | TokenKind._type: + write_s("TYPE") + | TokenKind._record: + write_s("RECORD") + | TokenKind._union: + write_s("UNION") + | TokenKind.pipe: + write_s("|") + | TokenKind.to: + write_s("TO") + | TokenKind.boolean: + write_s("BOOLEAN<"); + write_b(current_token^.value.boolean_value); + write_c('>') + | TokenKind.null: + write_s("NIL") + | TokenKind.and: + write_s("&") + | TokenKind._or: + write_s("OR") + | TokenKind.not: + write_s("~") + | TokenKind._return: + write_s("RETURN") + | TokenKind._cast: + write_s("CAST") + | TokenKind.shift_left: + write_s("<<") + | TokenKind.shift_right: + write_s(">>") + | TokenKind.identifier: + write_c('<'); write_s(current_token^.value.string); - write_c('>') - | TokenKind.trait: - write_c('#'); - write_s(current_token^.value.string) - | TokenKind.left_paren: - write_s("(") - | TokenKind.right_paren: - write_s(")") - | TokenKind.left_square: - write_s("[") - | TokenKind.right_square: - write_s("]") - | TokenKind.greater_equal: - write_s(">=") - | TokenKind.less_equal: - write_s("<=") - | TokenKind.greater_than: - write_s(">") - | TokenKind.less_than: - write_s("<") - | TokenKind.equal: - write_s("=") - | TokenKind.not_equal: - write_s("<>") - | TokenKind.semicolon: - write_c(';') - | TokenKind.dot: - write_c('.') - | TokenKind.comma: - write_c(',') - | TokenKind.plus: - write_c('+') - | TokenKind.minus: - write_c('-') - | TokenKind.multiplication: - write_c('*') - | TokenKind.division: - write_c('/') - | TokenKind.remainder: - write_c('%') - | TokenKind.assignment: - write_s(":=") - | TokenKind.colon: - write_c(':') - | TokenKind.hat: - write_c('^') - | TokenKind.at: - write_c('@') - | TokenKind.comment: - write_s("(* COMMENT *)") - | TokenKind.integer: - write_c('<'); + write_c('>') + | TokenKind.trait: + write_c('#'); + write_s(current_token^.value.string) + | TokenKind.left_paren: + write_s("(") + | TokenKind.right_paren: + write_s(")") + | TokenKind.left_square: + write_s("[") + | TokenKind.right_square: + write_s("]") + | TokenKind.greater_equal: + write_s(">=") + | TokenKind.less_equal: + write_s("<=") + | TokenKind.greater_than: + write_s(">") + | TokenKind.less_than: + write_s("<") + | TokenKind.equal: + write_s("=") + | TokenKind.not_equal: + write_s("<>") + | TokenKind.semicolon: + write_c(';') + | TokenKind.dot: + write_c('.') + | TokenKind.comma: + write_c(',') + | TokenKind.plus: + write_c('+') + | TokenKind.minus: + write_c('-') + | TokenKind.multiplication: + write_c('*') + | TokenKind.division: + write_c('/') + | TokenKind.remainder: + write_c('%') + | TokenKind.assignment: + write_s(":=") + | TokenKind.colon: + write_c(':') + | TokenKind.hat: + write_c('^') + | TokenKind.at: + write_c('@') + | TokenKind.comment: + write_s("(* COMMENT *)") + | TokenKind.integer: + write_c('<'); write_i(current_token^.value.int_value); - write_c('>') - | TokenKind.word: - write_c('<'); + write_c('>') + | TokenKind.word: + write_c('<'); write_i(current_token^.value.int_value); - write_s("u>") - | TokenKind.character: - write_c('<'); + write_s("u>") + | TokenKind.character: + write_c('<'); write_i(cast(current_token^.value.char_value: Int)); - write_s("c>") - | TokenKind.string: - write_s("\"...\"") - | TokenKind._defer: - write_s("DEFER") - | TokenKind.exclamation: - write_c('!') - | TokenKind.arrow: - write_s("->") - | TokenKind._program: - write_s("PROGRAM") - | TokenKind._module: - write_s("MODULE") - | TokenKind._import: - write_s("IMPORT") - else - write_s("UNKNOWN<"); - write_i(cast(current_token^.kind: Int)); - write_c('>') - end; - write_c(' '); + write_s("c>") + | TokenKind.string: + write_s("\"...\"") + | TokenKind._defer: + write_s("DEFER") + | TokenKind.exclamation: + write_c('!') + | TokenKind.arrow: + write_s("->") + | TokenKind._program: + write_s("PROGRAM") + | TokenKind._module: + write_s("MODULE") + | TokenKind._import: + write_s("IMPORT") + else + write_s("UNKNOWN<"); + write_i(cast(current_token^.kind: Int)); + write_c('>') + end; + write_c(' '); - i := i + 1u + i := i + 1u end; write_c('\n') end; @@ -1052,22 +1052,22 @@ begin if return_code = 0 then source_file := read_source(command_line^.input); - if source_file = nil then - perror(command_line^.input); - return_code := 3 - end + if source_file = nil then + perror(command_line^.input); + return_code := 3 + end end; if return_code = 0 then defer - fclose(source_file^.handle) - end; + fclose(source_file^.handle) + end; - source_code.position := TextLocation(1u, 1u); - source_code.input := cast(source_file: Pointer); - source_code.empty := source_file_empty; - source_code.head := source_file_head; - source_code.advance := source_file_advance; + source_code.position := TextLocation(1u, 1u); + source_code.input := cast(source_file: Pointer); + source_code.empty := source_file_empty; + source_code.head := source_file_head; + source_code.advance := source_file_advance; return_code := compile_in_stages(command_line, source_code) end;