Skip to content

Commit

Permalink
Merge pull request #2 from kassane/fixes
Browse files Browse the repository at this point in the history
some fixes
  • Loading branch information
alvarorichard committed Aug 3, 2023
2 parents 23ac762 + 2956f50 commit cee4eac
Show file tree
Hide file tree
Showing 70 changed files with 82 additions and 874 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Zig Build

on: [push, pull_request]

jobs:
build:
strategy:
fail-fast: false
matrix:
runs-on: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0
- uses: goto-bus-stop/setup-zig@v2
with:
version: 0.10.1

- name: Build Summary
run: zig build -freference-trace
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
zig-cache/
zig-out/
File renamed without changes.
35 changes: 35 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const Builder = @import("std").build.Builder;

pub fn build(b: *Builder) void {
const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions(); //-Drelease-safe|release-fast|release-small

const lib = b.addSharedLibrary("function_parameter", "src/function_parameter.zig", .unversioned);
lib.setBuildMode(mode);
lib.setTarget(target);
lib.linkLibC(); // next function need libc
lib.install();

const exe = b.addExecutable("CortexC", null);
exe.addCSourceFile("src/main.c", &.{
"-Wall",
"-Wextra",
// "-Werror",
});
exe.setBuildMode(mode);
exe.setTarget(target);
exe.addIncludePath("src");
exe.linkLibrary(lib);
exe.linkLibC();
exe.install();

const run_cmd = exe.run();
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}

// zig build run - running Exe.
const run_step = b.step("run", b.fmt("Run the {s} app.", .{exe.name}));
run_step.dependOn(&run_cmd.step);
}
11 changes: 0 additions & 11 deletions src/build.zig

This file was deleted.

33 changes: 23 additions & 10 deletions src/function_parameter.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const std = @import("std");

extern fn next() callconv(.C) void;

extern fn next() callconv(.C) void;

const Token = enum {
Int,
Expand All @@ -27,21 +26,31 @@ var line: i32 = undefined;
var currentId: Identifier = undefined;
var index_of_bp: i32 = undefined;

export fn functionParameter() i32 {
// empty functions
export fn functionParameter() void {}
export fn function_body() void {}

export fn function_parameter() i32 {
var params: i32 = 0;
var type_: Token = .Int;

while (token != .RParen) {
type_ = .Int;
if (token == .Int) {
if (match(.Int) != 0) { return -1; }
if (match(.Int) != 0) {
return -1;
}
} else if (token == .Char) {
type_ = .Char;
if (match(.Char) != 0) { return -1; }
if (match(.Char) != 0) {
return -1;
}
}

while (token == .Mul) {
if (match(.Mul) != 0) { return -1; }
if (match(.Mul) != 0) {
return -1;
}
type_ = .Mul;
}

Expand All @@ -54,7 +63,9 @@ export fn functionParameter() i32 {
return -1;
}

if (match(.Id) != 0) { return -1; }
if (match(.Id) != 0) {
return -1;
}

currentId.bclass = currentId.class;
currentId.class = .Loc;
Expand All @@ -65,7 +76,9 @@ export fn functionParameter() i32 {
params += 1;

if (token == .Comma) {
if (match(.Comma) != 0) { return -1; }
if (match(.Comma) != 0) {
return -1;
}
}
}

Expand All @@ -75,9 +88,9 @@ export fn functionParameter() i32 {

fn match(expectedToken: Token) i32 {
if (token != expectedToken) {
std.debug.print("expected token: {}, got: {}\n", .{expectedToken, token});
std.debug.print("expected token: {}, got: {}\n", .{ expectedToken, token });
return -1;
}
next();
return 0;
}
}
Binary file removed src/libfunction_parameter.a
Binary file not shown.
Binary file removed src/libfunction_parameter.a.o
Binary file not shown.
Binary file removed src/libfunction_parameter.so.o
Binary file not shown.
Empty file.
Empty file.
147 changes: 0 additions & 147 deletions src/zig-cache/h/7dbe17386227a0c02c669a44dacede0f.txt

This file was deleted.

Loading

0 comments on commit cee4eac

Please sign in to comment.