Workspace#
(name := "") -> Workspace
Starts a new workspace, an independent build with its own options, code and output. name shows up in messages and errors.
(w: Workspace)
Frees a workspace made with compiler_create_workspace . Do it after its build is complete.
(pointer: *void )
(x: *void )
(w: Workspace = -1) -> string
Returns the name of workspace w; the default is the workspace running the code.
Returns a copy of the options of workspace w; the default is the workspace running the code. Change the copy and hand it back with set_build_options .
(options:
Build_Options , w: Workspace = -1, loc := #caller_location)
Replaces the options of workspace w. Set them before adding code.
Changes the few options that may still change while a build is running, such as its output name and path. Build_Options_During_Compile says which.
(filename: string , w: Workspace, loc := #caller_location)
Adds the source file filename to workspace w, as if it were passed on the command line.
Doesn't run in the browser (skipped on wasm).
(data: string , w: Workspace, code := #code,null, loc := #caller_location)
(data:
string , w: Workspace, message: *
Message , loc := #caller_location)
Adds the source text data to workspace w. Pass code to compile it in the scope that code was written in, so it can see that scope's names.
(message: string , loc := #caller_location, mode := Report.ERROR)
(filename: string , line_number: s64 , character_number: s64 , error_text: string , mode := Report.ERROR)
Reports a problem at loc (by default the call site). The default mode, .ERROR, fails the build once the current step ends; .WARNING and .INFO only print.
Fills version_info with the compiler's version numbers and returns the version as a string.
() -> [] string
Returns the arguments of the command line the compiler was started with, so a build script can read its own options.
() -> string
Returns the folder the compiler installation lives in.
(path: string )
Adds path to the folders searched for native libraries named by #library.
(w: Workspace, info: *Type_Info_Struct) -> Source_Code_Location
(w: Workspace, host_module_name: string , import_name: string , replacement_name: string )
Makes #import "import_name" inside host_module_name load replacement_name instead. Use it from a message handler to swap in another version of a module.
Answers a Message_Failed_Import : tells the compiler where to find the module it could not. type says whether value is a module name, a file, a folder or the full source text.
Returns the syntax tree of code as its root node and the flat list of expressions in it.
(node: *
Code_Node , code_to_copy_scope_from:
Code = #code,null) ->
Code
Turns the node node back into a Code value you can insert with #insert. code_to_copy_scope_from says which scope the new code is read in.
Returns the type a typed Code value stands for, and a status that says why there is none when it fails.
(ti: *Type_Info) -> Type
Returns the Type that goes with a Type_Info pointer.
(w: Workspace = -1) -> [] *Type_Info
Returns the Type_Info of every type in workspace w.
Makes sure the procedure header is compiled into the program even if nothing calls it.
Replaces the body of a procedure with the (edited) tree under body, then compiles it again.
Starts receiving the compiler's Message s for workspace w. Read them with compiler_wait_for_message and finish with compiler_end_intercept . flags skips kinds of typechecked code you do not care about.
(w: Workspace)
Stops receiving messages for w, which lets the build carry on to its end.
Marks workspace w as failed, so that building it ends with an error.
Blocks until the compiler has a message for an intercepted workspace, and returns it. Check kind and cast to the matching Message_* type. The last message of a build is .COMPLETE.
(w: Workspace)
(section_name:
string , characteristics := Data_Segment_Characteristics.READ | .WRITE, alignment:
s32 = 16, w: Workspace = -1) -> (segment: *
Data_Segment , actual_segment_will_be_created:
bool )
Asks for a named data segment in the program being built. Returns it and whether the compiler will really create it on this target.
Copies data into a data segment and returns the stored bytes, which live in the built program.
Returns the type table and the global data layout of workspace w. Used by tools that read a program's memory.
:: struct
A data segment added to the built program with add_data_segment . Pass it back as user_segment to add_global_data .
:: enum_flags
What a custom data segment allows: reading, writing, executing, and whether it starts zeroed.
READ
WRITE
EXECUTE
ZEROED
:: enum
Which segment add_global_data puts data in: one of the built-in ones, or USER_SEGMENT for one you added.
WRITABLE
WRITABLE_NO_RESET
READ_ONLY
BSS
USER_SEGMENT
:: struct
The global data of a built program, as a list of segments. Part of Runtime_Info .
:: struct
One segment of the global data: what kind it is (zeroed, writable, read-only, ...) and its bytes.
segment_tag : enum u16 { BSS :: 0; DATA :: 1; RDATA :: 2; NO_RESET :: 3; USER :: 5; }
data : [] u8
:: struct
What a program knows about itself at run time: its type table and its global data. Get it from get_runtime_info .
type_table : [] *Type_Info
:: enum
Switches for how much type information a workspace keeps, set with compiler_set_type_info_flags .
NO_TYPE_INFO
PROCEDURES_ARE_VOID_POINTERS
NO_SIZE_COMPLAINT
:: struct
Every setting of a build: what to produce (output_type), where to write it, the checks to compile in, the optimizer and the backend. Get a copy with get_build_options , change it, and apply it with set_build_options . set_optimization fills in the fields that go with an optimization level.
output_type : := Output_Type.EXECUTABLE
Commonly_Propagated : struct { write_added_strings := true; runtime_storageless_type_info := false; shorten_filenames_in_error_messages := false; use_visual_studio_message_format := false; use_natvis_compatible_types := false; minimum_os_version: Os_Version; lazy_foreign_function_lookups := false; disable_redzone := false; enable_bytecode_inliner := true; enable_bytecode_deduplication := true; stack_trace := true; use_ansi_color := true; interactive_bytecode_debugger := false; debug_for_expansions := false; enable_frame_pointers := true; runtime_support_definitions: enum u8 { AUTO; ENTRY_POINT_AND_INIT; ONLY_INIT; OMIT; } = .AUTO; backtrace_on_crash: enum u8 { OFF; ON; } = .ON; array_bounds_check: enum u8 { OFF; ON; ALWAYS; } = .ON; cast_bounds_check: enum u8 { OFF; NONFATAL; FATAL; } = .FATAL; null_pointer_check: enum u8 { OFF; ON; } = .ON; arithmetic_overflow_check: enum u8 { OFF; NONFATAL; FATAL; } = .OFF; dead_code_elimination: enum u8 { NONE; ALL; MODULES_ONLY; } = .MODULES_ONLY; max_bytecode_instructions_for_inlined_initializer: s32 = 8; context_size_max: s32 = 4096; prevent_compile_time_calls_from_runtime := false; info_flags: enum_flags u32 { POLYMORPH_MATCH :: 0x1; POLYMORPH_DEDUPLICATE :: 0x2; } text_output_flags: enum_flags u32 { OUTPUT_LINK_LINE :: 0x1; OUTPUT_TIMING_INFO :: 0x2; } = xx 3; os_target := OS; cpu_target := CPU; backend: enum u32 { X64; LLVM; } = .LLVM; machine_options: [MACHINE_OPTIONS_SIZE] u8 ; emit_debug_info: enum u32 { NONE :: 0; DWARF :: 1; CODEVIEW :: 2; DEFAULT :: 3; } = .DEFAULT; maximum_polymorph_depth := 100; maximum_array_count_before_compile_time_returns_are_not_reflected_in_ast := 5000; x64_options: X64_Options ; llvm_options: Llvm_Options ; }
output_executable_name : string
output_path : string
intermediate_path : string
entry_point_name : string
compile_time_command_line : [] string
append_executable_filename_extension : := true
use_custom_link_command : := false
temporary_storage_size : s32
import_path : [] string
additional_linker_arguments : [] string
user_data_u64 : u64
user_data_string : string
user_data_pointer : *void
user_data_pointer_size : s32
options: Build_Options;
assert (options.output_type == .EXECUTABLE);
options.output_type = .NO_OUTPUT;
options.array_bounds_check = .OFF;Reset Copy ↗ Run ▸
:: struct
The build options that can still change while a build is running. Apply them with set_build_options_dc .
do_output : := true
write_added_strings : := true
append_executable_filename_extension : := true
interactive_bytecode_debugger : := false
append_linker_arguments : [] string
output_executable_name : string
output_path : string
:: enum
How hard LLVM optimizes the program: O0 to O3 for speed, OS and OZ for size.
:: enum
How hard LLVM optimizes when it turns the program into machine code.
UNSET
NONE
LESS
DEFAULT
AGGRESSIVE
:: struct
Settings for the LLVM backend: optimization levels, inlining, vectorization, and what intermediate output to keep.
function_sections : bool
enable_tail_calls : := false
enable_loop_unrolling : := false
enable_slp_vectorization : := false
enable_loop_vectorization : := false
preserve_debug_info : := true
merge_functions : := false
disable_inlining : := true
disable_mem2reg : := false
enable_split_modules : := true
output_bitcode_before_optimizations : := false
output_llvm_ir_before_optimizations : := false
output_bitcode : := false
output_llvm_ir : := false
target_system_triple : string
target_system_cpu : string
target_system_features : string
command_line : [] string
:: enum
An optimization preset for set_optimization , from DEBUG to VERY_OPTIMIZED, plus two that favor size.
DEBUG
VERY_DEBUG
OPTIMIZED
VERY_OPTIMIZED
OPTIMIZED_SMALL
OPTIMIZED_VERY_SMALL
:: struct
The compiler's version, filled in by compiler_get_version_info .
major : s32
minor : s32
micro : s32
:: struct
Settings for the built-in x64 backend.
use_dlls : := false
enable_register_allocation : := false
enable_unix_runtime_frame_information : := true
:: enum_flags
Which kinds of typechecked code compiler_begin_intercept should leave out of its messages, and which performance reports to send.
SKIP_EXPRESSIONS_WITHOUT_NOTES
SKIP_DECLARATIONS
SKIP_PROCEDURE_HEADERS
SKIP_PROCEDURE_BODIES
SKIP_STRUCTS
SKIP_OTHERS
SKIP_ALL
DO_PERFORMANCE_REPORT_POLYMORPHS
DO_PERFORMANCE_REPORT_RUNS
:: struct
The start of every compiler message. kind says which Message_* type it really is; cast to that type to read the rest. workspace is the build it belongs to.
kind : enum u8 { UNINITIALIZED :: 0; FILE; IMPORT; FAILED_IMPORT; PHASE; TYPECHECKED; COMPLETE; DEBUG_DUMP; ERROR; PERFORMANCE_REPORT; }
workspace : Workspace
:: struct
The last message of a build. error_code says whether it worked.
error_code : enum u8 { NONE :: 0; COMPILATION_FAILED :: 1; COMPILER_SHUTDOWN :: 2; }
:: struct
The text of a #debug_dump request.
:: struct
A module could not be found. Answer it with provide_import , or the build fails.
status : enum u8 { UNINITIALIZED :: 0; BLOCKED :: 1; NOT_FOUND :: 2; }
host_module_name : string
target_module_name : string
:: struct
A source file was loaded, with its full path and the import it belongs to.
fully_pathed_filename : string
from_a_string : bool
:: struct
A module was imported, with its name, path and kind.
module_type : enum u8 { UNINITIALIZED :: 0; PRELOAD :: 1; RUNTIME_SUPPORT :: 2; MAIN_PROGRAM :: 3; FILE :: 4; }
module_name : string
fully_pathed_filename : string
:: struct
Timing and counts about the build, sent when Intercept_Flags asks for them.
:: struct
The build reached a stage, such as all source being parsed or the executable being written.
phase : enum u32 { ALL_SOURCE_CODE_PARSED :: 0; TYPECHECKED_ALL_WE_CAN :: 1; ALL_TARGET_CODE_BUILT :: 2; PRE_WRITE_EXECUTABLE :: 3; POST_WRITE_EXECUTABLE :: 4; READY_FOR_CUSTOM_LINK_COMMAND :: 5; }
executable_name : string
executable_write_failed : := false
linker_exit_code : s32
num_items_waiting_to_typecheck : s32
compiler_generated_object_files : [] string
support_object_files : [] string
system_libraries : [] string
user_libraries : [] string
:: struct
A batch of code finished type checking: declarations, procedure headers and bodies, structs and everything else, each with the nodes inside it.
:: enum
What the answer to a Message_Failed_Import is: a module name, a file, a folder or source text.
SHORT_NAME
PATH_TO_FILE
PATH_TO_DIRECTORY
FULL_TEXT
:: enum
How serious a compiler_report is. ERROR fails the build; the others only print.
ERROR
ERROR_CONTINUABLE
WARNING
INFO
:: enum
Whether a workspace is still good, for compiler_set_workspace_status .
:: struct
One argument in a call or return: its expression, and its name if it was passed by name.
:: struct
The details of an array literal: element type, alignment and members.
array_literal_flags : enum_flags u8 { WAS_UNTYPED :: 0x01; }
:: struct
An inline assembly block.
b1 : *void
b2 : [] *void
b3 : [] u64
:: struct
A two-operand expression such as a + b: the operator and the left and right nodes.
:: struct
A { ... } block: its statements and the declarations it makes.
block_type : enum s32 { UNINITIALIZED :: 0; IMPERATIVE :: 1; DATA_DECLARATIONS :: 2; ARGUMENTS :: 3; RETURNS :: 4; STRUCT_ARGUMENTS :: 5; CONSTANTS :: 6; }
block_flags : enum u32 { NO_ARRAY_BOUNDS_CHECK :: 0x1; NO_ARITHMETIC_OVERFLOW_CHECK :: 0x2; }
:: struct
One case of an if == switch.
marked_as_fallthrough : := false
:: struct
A cast, explicit or inserted by the compiler, with the type it converts to.
cast_flags : enum_flags u32 { IS_IMPLICIT :: 0x1; IS_POINTER_DEREFERENCE :: 0x2; IS_AUTO :: 0x4; NO_BOUNDS_CHECK :: 0x8; TRUNCATE :: 0x10; AS :: 0x20; ISA :: 0x40; FORCE :: 0x80; VERY_FORCE :: 0x100; HAS_FUNCTION_SYNTAX :: 0x800; HAS_POSTFIX_SYNTAX :: 0x1000; }
:: struct
One entry of a Code_Comma_Separated_Arguments list.
modifier : enum u8 { NONE :: 0; DECLARE :: 1; ASSIGN :: 2; }
:: struct
A comma-separated list on the left of := or =, as in a, b := f();.
:: struct
A declaration of several names at once, as in a, b := f();.
:: struct
The context value.
:: struct
A declaration: a variable, constant, parameter or procedure name, with its type, value, notes and flags.
flags : enum_flags u32 { IS_CONSTANT :: 0x1; IS_MARKED_AS_AS :: 0x2; IS_MARKED_AS_DISCARD :: 0x4; IS_ITERATOR :: 0x10; NO_RESET :: 0x40; IS_UNINITIALIZED :: 0x80; COMES_FROM_ASM :: 0x100; IS_IMPORTED :: 0x200; AUTO_VALUE_BAKE :: 0x4000; AUTO_VALUE_BAKE_IS_REQUIRED :: 0x8000; IS_OVERLAY :: 0x1_0000; PROGRAM_EXPORT :: 0x2_0000; ELSEWHERE :: 0x4_0000; SCOPE_FILE :: 0x8_0000; IS_GLOBAL :: 0x10_0000; HAS_SCOPE_MODIFIER :: 0x20_0000; }
program_export_name : string
:: struct
A defer statement and its block.
:: struct
An #add_context directive.
:: struct
A #bake or $$ expression, which fixes some arguments of a procedure.
bake_type : enum u8 { CONSTANTS_BAKE :: 0; PARAMETER_VALUE_BAKE :: 1; DYNAMIC_SPECIALIZE :: 2; }
:: struct
A #bytes directive.
:: struct
A #code expression, whose body becomes a Code value.
code_flags : enum u32 { IMPLICITLY_GENERATED :: 0x1; NULL :: 0x2; TYPED :: 0x8; }
:: struct
A #context directive.
:: struct
An #exists query.
:: struct
An #import directive: the module name and its parameters.
name : string
flags : enum u32 { UNSHARED :: 0x1; }
:: struct
An #insert directive and the code it inserts.
:: struct
A #library directive naming a native library.
name : string
library_flags : enum u32 { IS_SYSTEM_LIBRARY :: 0x1; DYNAMIC_LIBRARY_UNAVAILABLE :: 0x2; STATIC_LIBRARY_UNAVAILABLE :: 0x4; LINK_ALWAYS :: 0x8; }
:: struct
A #load directive: the file it names and its resolved path.
short_name : string
fully_pathed_filename : string
loaded_string : string
load_flags : s32
:: struct
A #location expression.
is_caller_location : := false
:: struct
A #modify block on a procedure or struct.
:: struct
A #module_parameters directive.
:: struct
An #overlay directive.
:: struct
A #poke_name directive.
:: struct
A #procedure_name directive.
:: struct
A #run directive and the procedure it runs.
flags : enum u32 { ASSERTION :: 0x1; STALLABLE :: 0x2; SYNTACTICALLY_IMPLICIT :: 0x4; HAS_IMPLICIT_RETURN_TYPES :: 0x8; }
assertion_string : string
:: struct
A #scope_export, #scope_file or #scope_module directive.
scope_type : enum u32 { EXPORT :: 0; FILE :: 1; INTERNAL :: 2; }
:: struct
A #through directive.
:: struct
A #wildcard placeholder.
:: struct
An enum definition: its members, notes and whether it is a flags or complete enum.
internal_type : *Type_Info
external_type : *Type_Info_Enum
marked_as_complete : := false
marked_as_specified : := false
is_flags : := false
:: struct
A type_of, is_constant or #code_of query about an expression.
query_kind : enum u32 { TYPE_OF :: 0; IS_CONSTANT :: 1; CODE_OF :: 2; }
:: struct
A for loop: what it iterates, its body and its it and it_index names.
:: struct
A name, and the declaration it resolved to.
name : string
flags : enum_flags u32 { DEFINES_POLYMORPH_VARIABLE :: 0x01; IS_RHS_OF_DOT_DEREFERENCE :: 0x02; RESOLVES_ONLY_SHALLOWLY :: 0x04; GENERATED_BY_OPERATOR_OVERLOAD :: 0x08; DO_NOT_RESOLVE_DUE_TO_PARSER :: 0x10; CAN_RESOLVE_TO_REG :: 0x20; HAS_SCOPE_MODIFIER :: 0x40; }
:: struct
An if or ifx, including a #if and an if == switch.
if_flags : enum_flags u16 { IS_SWITCH_STATEMENT :: 0x1; IS_IFX :: 0x2; IS_STATIC :: 0x4; MARKED_AS_COMPLETE :: 0x8; }
static_if_flags : enum_flags u16 { EVALUATED_AS_TRUE :: 0x1; }
:: struct
A literal: a number, string, boolean, array, struct, pointer or type. value_type says which, and the matching union member holds the value.
value_type : enum s16 { UNINITIALIZED :: 0; NUMBER :: 1; STRING :: 2; BOOLEAN :: 3; ARRAY :: 6; STRUCT :: 7; POINTER :: 8; TYPE_INFO :: 9; }
value_flags : enum_flags u32 { IS_A_NUMBER :: 0x1; HEX :: 0x2; FLOAT :: 0x4; BINARY :: 0x20; MINUS_SIGN :: 0x40; HERE_STRING :: 0x80; DEFAULTS_TO_FLOAT64 :: 0x100; REQUIRES_FLOAT64 :: 0x200; }
:: struct
A break, continue or remove.
control_type : enum u8 { BREAK :: 0; CONTINUE :: 1; REMOVE :: 2; }
:: struct
The list of extra arguments a call passes to a variadic procedure.
element_type : *Type_Info
is_for_non_native_calling_convention : bool
:: struct
The part every syntax node shares: its kind, where it is in the source, its type once checked and flags. Cast a node to the Code_* type that matches its kind to read the rest.
location : Location
kind : := Kind.UNINITIALIZED
node_flags : enum u32 { EXPRESSION_IS_SPREAD :: 0x1; NO_ARRAY_BOUNDS_CHECK :: 0x2; ALLOWED_BY_CONTEXT :: 0x4; STATEMENT_IS_DEFERRED :: 0x8; IS_PARENTHESIZED :: 0x10; CREATED_BY_DESUGARING :: 0x100; EXPRESSION_IS_DEPRECATED :: 0x8000_0000 }
type : *Type_Info
serial : s64
:: struct
A @note attached to a declaration, procedure or struct.
text : string
note_flags : u32
:: struct
A stand-in for code that is not there yet.
:: struct
The details of a pointer constant: the symbol or literal it points into, and an offset.
data_pointer : *u8
pointer_literal_type : enum u8 { GLOBAL_SYMBOL :: 0; STRING_OR_ARRAY_LITERAL_DATA_POINTER :: 1; CONSTANT_VALUE :: 2; }
offset_from_symbol : s64
:: struct
The body of a procedure, with its header.
body_flags : enum u32 { ALREADY_MODIFIED :: 0x1; }
:: struct
A procedure call: the procedure, its arguments (as written and in parameter order) and the overload it resolved to.
num_return_values_received : s64
context_modification : *Context_Modification
flags : Flags
:: struct
A push_context statement and its block.
push_context_flags : enum u32 { IS_BACKTICKED :: 0x1; DEFER_POP :: 0x2; }
:: struct
An overloaded name after the compiler chose a procedure.
:: struct
A return statement and its values.
:: struct
Something named in a scope. Code_Declaration builds on it.
:: struct
A struct or union definition: its members, notes and the type it defines.
textual_flags : Struct_Textual_Flags
alignment : s32
defined_type : *Type_Info_Struct
:: struct
The details of a struct literal: its type and its arguments.
:: struct
A type that is used as a value, with its Type_Info.
:: struct
A type as written in source, such as *[] int, and the Type_Info it resolved to.
result : *Type_Info
inst_flags : enum_flags u32 { VARARGS :: 0x1; RESIZABLE :: 0x2; TYPE_OF_PROCEDURE :: 0x4; TYPE_DIRECTIVE :: 0x8; TYPE_DIRECTIVE_DISTINCT :: 0x10; TYPE_DIRECTIVE_ISA :: 0x20; ARRAY_VIEW :: 0x40; INTERFACE :: 0x80; }
:: struct
A size_of, type_info or initializer_of expression.
query_kind : enum u32 { SIZE_OF :: 0; TYPE_INFO :: 1; INITIALIZER_OF :: 2; }
:: struct
A one-operand expression such as -x or !x.
:: struct
A using statement or parameter.
filter_type : enum u8 { NONE :: 0; ONLY :: 1; EXCEPT :: 2; MAP :: 3; }
no_parameters : := false
:: struct
A while loop and its body.
:: enum
Why get_root_type succeeded or failed.
UNINITIALIZED
SUCCESS
INPUT_IS_CODE_NULL
CORRUPTED
NOT_TYPED
:: enum
An operator that has no single-character name. Single-character operators use their character, as in cast(Operator_Type) #char "+".
IS_EQUAL
IS_NOT_EQUAL
LOGICAL_AND
LOGICAL_OR
LESS_OR_EQUAL
GREATER_OR_EQUAL
SHIFT_LEFT
SHIFT_RIGHT
ROTATE_LEFT
ROTATE_RIGHT
PLUS_ASSIGN
MINUS_ASSIGN
TIMES_ASSIGN
DIV_ASSIGN
MOD_ASSIGN
SHIFT_LEFT_ASSIGN
SHIFT_RIGHT_ASSIGN
ROTATE_LEFT_ASSIGN
ROTATE_RIGHT_ASSIGN
BITWISE_AND_ASSIGN
BITWISE_OR_ASSIGN
BITWISE_XOR_ASSIGN
LOGICAL_AND_ASSIGN
LOGICAL_OR_ASSIGN
POINTER_DEREFERENCE
POSTFIX_DEREFERENCE
ARRAY_SUBSCRIPT
:: struct
How many calls and instructions the compile-time interpreter ran, and how many were inlined.
num_calls_inlined : s64
num_calls_total : s64
num_instructions_inlined : s64
num_instructions_total : s64
:: struct
:: struct
A plugin for a metaprogram. Fill in the procedures you care about and the compiler calls them: init once, message for every compiler message, finish at the end. workspace is the build it works on.
plugin: Metaprogram_Plugin;
plugin.message = (p: *Metaprogram_Plugin, message: *Message) {};
assert (plugin.init == null );Reset Copy ↗ Run ▸
:: struct
Counts of the polymorphic procedures the compiler instantiated, and from where.
num_solves_invoked : s64
num_solves_used : s64
reported : := false
records : [] Record
:: struct
How long each #run took.
reported : := false
records : [] Record
:: struct
How long the compile-time interpreter spent running code, inlining and generating bytecode.
run_directives : float64
bytecode_inlining : float64
bytecode_generating : float64
:: struct
A node that has finished type checking, with all the nodes inside it. Found in Message_Typechecked .