mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 11:40:14 +01:00
Add Core.PrintStr and a "hello world" example (#6493)
Thanks to @ammaralassal for #6329 which did the heavy lifting to make this possible! Co-authored-by: Josh L <josh11b@users.noreply.github.com>
This commit is contained in:
@@ -13,6 +13,16 @@ import library "prelude";
|
||||
// TODO: Consider rewriting using native support once library support exists.
|
||||
fn Print(x: i32) = "print.int";
|
||||
fn PrintChar(x: char) -> i32 = "print.char";
|
||||
|
||||
fn PrintStr(msg: str) {
|
||||
let size: i64 = msg.Size() as i64;
|
||||
var i: i64 = 0;
|
||||
while (i < size) {
|
||||
PrintChar(msg[i]);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Return an `Optional(char)` instead of `i32`.
|
||||
fn ReadChar() -> i32 = "read.char";
|
||||
|
||||
|
||||
@@ -8,3 +8,8 @@ carbon_binary(
|
||||
name = "sieve",
|
||||
srcs = ["sieve.carbon"],
|
||||
)
|
||||
|
||||
carbon_binary(
|
||||
name = "hello_world",
|
||||
srcs = ["hello_world.carbon"],
|
||||
)
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// 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
|
||||
|
||||
import Core library "io";
|
||||
|
||||
fn Run() {
|
||||
Core.PrintStr("Hello world!\n");
|
||||
}
|
||||
Reference in New Issue
Block a user