Skip to content

Commit cedc205

Browse files
committed
revert(examples): the ones we accidentally removed.
1 parent 97b1e0b commit cedc205

File tree

29 files changed

+265
-0
lines changed

29 files changed

+265
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
section .data
2+
hello db 'Hello, World!',0
3+
4+
section .text
5+
global print_hello
6+
7+
print_hello:
8+
; Write the message to stdout
9+
mov eax, 1 ; Syscall number for write
10+
mov edi, 1 ; File descriptor 1: stdout
11+
mov rsi, hello ; Address of the string
12+
mov edx, 13 ; Length of the string
13+
syscall
14+
15+
ret
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
section .data
2+
extern hello
3+
4+
section .text
5+
extern print_hello
6+
7+
global _start
8+
9+
_start:
10+
; Call the print_hello function
11+
call print_hello
12+
13+
; Exit the program
14+
mov eax, 60 ; Syscall number for exit
15+
xor edi, edi ; Exit status 0
16+
syscall
17+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <stdio.h>
2+
3+
void printHello() {
4+
printf("Hello, World!\n");
5+
}
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef HELPER_H
2+
#define HELPER_H
3+
4+
void printHello();
5+
6+
#endif
7+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <stdio.h>
2+
#include "helper.h"
3+
4+
int main() {
5+
printHello();
6+
return 0;
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <iostream>
2+
3+
void printHello() {
4+
std::cout << "Hello, World!" << std::endl;
5+
}
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef HELPER_H
2+
#define HELPER_H
3+
4+
void printHello();
5+
6+
#endif
7+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <iostream>
2+
#include "helper.h"
3+
4+
int main() {
5+
printHello();
6+
return 0;
7+
}
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
3+
class Helper
4+
{
5+
public static void PrintHello()
6+
{
7+
Console.WriteLine("Hello, World!");
8+
}
9+
}
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
class Program
4+
{
5+
static void Main()
6+
{
7+
Helper.PrintHello();
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
void printGreeting() {
2+
print("Hello, World!");
3+
}
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import 'helper.dart';
2+
3+
void main() {
4+
printGreeting();
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module main
2+
3+
go 1.22.3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// helper.go
2+
3+
package main
4+
5+
func getMessage() string {
6+
return "Hello, World!"
7+
}
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// main.go
2+
3+
package main
4+
5+
import "fmt"
6+
7+
func main() {
8+
msg := getMessage() // Calling the function from "helper.go"
9+
fmt.Println(msg)
10+
}
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class Helper {
2+
public static void printHello() {
3+
System.out.println("Hello, World!");
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public class Main {
2+
public static void main(String[] args) {
3+
Helper.printHello();
4+
}
5+
}
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object Helper {
2+
fun printMessage() {
3+
println("Hello from helper.kt!")
4+
}
5+
}
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fun main() {
2+
Helper.printMessage()
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def hello_world():
2+
print('Hello, World!')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import helper
2+
3+
helper.hello_world()
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def hello_world():
2+
print('Hello, World!')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import helper
2+
3+
helper.hello_world()
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pub fn print_hello() {
2+
println!("Hello, World!");
3+
}
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
mod helper;
2+
3+
fn main() {
4+
helper::print_hello();
5+
}
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
func sayHello() {
2+
print("Hello, World!")
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sayHello()
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
const std = @import("std");
2+
3+
// Although this function looks imperative, note that its job is to
4+
// declaratively construct a build graph that will be executed by an external
5+
// runner.
6+
pub fn build(b: *std.Build) void {
7+
// Standard target options allows the person running `zig build` to choose
8+
// what target to build for. Here we do not override the defaults, which
9+
// means any target is allowed, and the default is native. Other options
10+
// for restricting supported target set are available.
11+
const target = b.standardTargetOptions(.{});
12+
13+
// Standard optimization options allow the person running `zig build` to select
14+
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
15+
// set a preferred release mode, allowing the user to decide how to optimize.
16+
const optimize = b.standardOptimizeOption(.{});
17+
18+
const exe = b.addExecutable(.{
19+
.name = "build-and-run",
20+
// In this case the main source file is merely a path, however, in more
21+
// complicated build scripts, this could be a generated file.
22+
.root_source_file = .{ .path = "src/main.zig" },
23+
.target = target,
24+
.optimize = optimize,
25+
});
26+
27+
// This declares intent for the executable to be installed into the
28+
// standard location when the user invokes the "install" step (the default
29+
// step when running `zig build`).
30+
b.installArtifact(exe);
31+
32+
// This *creates* a Run step in the build graph, to be executed when another
33+
// step is evaluated that depends on it. The next line below will establish
34+
// such a dependency.
35+
const run_cmd = b.addRunArtifact(exe);
36+
37+
// By making the run step depend on the install step, it will be run from the
38+
// installation directory rather than directly from within the cache directory.
39+
// This is not necessary, however, if the application depends on other installed
40+
// files, this ensures they will be present and in the expected location.
41+
run_cmd.step.dependOn(b.getInstallStep());
42+
43+
// This allows the user to pass arguments to the application in the build
44+
// command itself, like this: `zig build run -- arg1 arg2 etc`
45+
if (b.args) |args| {
46+
run_cmd.addArgs(args);
47+
}
48+
49+
// This creates a build step. It will be visible in the `zig build --help` menu,
50+
// and can be selected like this: `zig build run`
51+
// This will evaluate the `run` step rather than the default, which is "install".
52+
const run_step = b.step("run", "Run the app");
53+
run_step.dependOn(&run_cmd.step);
54+
55+
// Creates a step for unit testing. This only builds the test executable
56+
// but does not run it.
57+
const unit_tests = b.addTest(.{
58+
.root_source_file = .{ .path = "src/main.zig" },
59+
.target = target,
60+
.optimize = optimize,
61+
});
62+
63+
const run_unit_tests = b.addRunArtifact(unit_tests);
64+
65+
// Similar to creating the run step earlier, this exposes a `test` step to
66+
// the `zig build --help` menu, providing a way for the user to request
67+
// running the unit tests.
68+
const test_step = b.step("test", "Run unit tests");
69+
test_step.dependOn(&run_unit_tests.step);
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const std = @import("std");
2+
3+
pub fn main() !void {
4+
// Prints to stderr (it's a shortcut based on `std.io.getStdErr()`)
5+
std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
6+
7+
// stdout is for the actual output of your application, for example if you
8+
// are implementing gzip, then only the compressed bytes should be sent to
9+
// stdout, not any debugging messages.
10+
const stdout_file = std.io.getStdOut().writer();
11+
var bw = std.io.bufferedWriter(stdout_file);
12+
const stdout = bw.writer();
13+
14+
try stdout.print("Run `zig build test` to run the tests.\n", .{});
15+
16+
try bw.flush(); // don't forget to flush!
17+
}
18+
19+
test "simple test" {
20+
var list = std.ArrayList(i32).init(std.testing.allocator);
21+
defer list.deinit(); // try commenting this out and see if zig detects the memory leak!
22+
try list.append(42);
23+
try std.testing.expectEqual(@as(i32, 42), list.pop());
24+
}

0 commit comments

Comments
 (0)