mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
For now, a builtin function is defined by specifying a string literal initializer in a function declaration: ```carbon fn MyBuiltin(a: i32) -> i32 = "builtin.name"; ``` End-to-end support is included for a sample `"int.add"` builtin performing integer addition, covering constant evaluation and code generation. The implementation here needs substantial refactoring before we'll be ready to start adding more builtins. That refactoring work will be coming next. This change is aiming to checkpoint some incremental progress.
23 lines
898 B
Plaintext
23 lines
898 B
Plaintext
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
// AUTOUPDATE
|
|
|
|
// CHECK:STDERR: fail_unknown.carbon:[[@LINE+3]]:23: ERROR: Unknown builtin function name "unknown.builtin.name".
|
|
// CHECK:STDERR: fn UnknownBuiltin() = "unknown.builtin.name";
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~
|
|
fn UnknownBuiltin() = "unknown.builtin.name";
|
|
|
|
// CHECK:STDOUT: --- fail_unknown.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [template] {
|
|
// CHECK:STDOUT: .UnknownBuiltin = %UnknownBuiltin
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %UnknownBuiltin: <function> = fn_decl @UnknownBuiltin [template] {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @UnknownBuiltin();
|
|
// CHECK:STDOUT:
|