Initial commit
This commit is contained in:
commit
f12d41e580
9 changed files with 1953 additions and 0 deletions
BIN
Main.class
Normal file
BIN
Main.class
Normal file
Binary file not shown.
19
Main.java
Normal file
19
Main.java
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
|
public class Main implements Runnable, Callable<Integer> {
|
||||||
|
private static final String message = "Hello, World";
|
||||||
|
private static final int number = 42;
|
||||||
|
private static final double funnyNumber = 6.9;
|
||||||
|
|
||||||
|
public static void main() {
|
||||||
|
System.out.println(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
Main.main();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer call() {
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
}
|
||||||
36
build.zig
Normal file
36
build.zig
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
pub fn build(b: *std.Build) void {
|
||||||
|
const target = b.standardTargetOptions(.{});
|
||||||
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
|
||||||
|
const exe_mod = b.createModule(.{
|
||||||
|
.root_source_file = b.path("src/main.zig"),
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
});
|
||||||
|
const exe = b.addExecutable(.{
|
||||||
|
.name = "zig_jvm",
|
||||||
|
.root_module = exe_mod,
|
||||||
|
});
|
||||||
|
|
||||||
|
b.installArtifact(exe);
|
||||||
|
|
||||||
|
const run_cmd = b.addRunArtifact(exe);
|
||||||
|
run_cmd.step.dependOn(b.getInstallStep());
|
||||||
|
if (b.args) |args| {
|
||||||
|
run_cmd.addArgs(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
const run_step = b.step("run", "Run the app");
|
||||||
|
run_step.dependOn(&run_cmd.step);
|
||||||
|
|
||||||
|
const exe_unit_tests = b.addTest(.{
|
||||||
|
.root_module = exe_mod,
|
||||||
|
});
|
||||||
|
|
||||||
|
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
|
||||||
|
|
||||||
|
const test_step = b.step("test", "Run unit tests");
|
||||||
|
test_step.dependOn(&run_exe_unit_tests.step);
|
||||||
|
}
|
||||||
13
build.zig.zon
Normal file
13
build.zig.zon
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
.{
|
||||||
|
.name = .zig_jvm,
|
||||||
|
.version = "0.0.0",
|
||||||
|
.fingerprint = 0x4dd537434033c2ad, // Changing this has security and trust implications.
|
||||||
|
.minimum_zig_version = "0.14.0-dev.3462+edabcf619",
|
||||||
|
.dependencies = .{
|
||||||
|
},
|
||||||
|
.paths = .{
|
||||||
|
"build.zig",
|
||||||
|
"build.zig.zon",
|
||||||
|
"src",
|
||||||
|
},
|
||||||
|
}
|
||||||
61
flake.lock
generated
Normal file
61
flake.lock
generated
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1731533236,
|
||||||
|
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1781577229,
|
||||||
|
"narHash": "sha256-lrp67w8AulE9Ks53n27I45ADSzbOCn4H+CNW1Ck8B+8=",
|
||||||
|
"owner": "nixos",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "567a49d1913ce81ac6e9582e3553dd90a955875f",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nixos",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
40
flake.nix
Normal file
40
flake.nix
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
{
|
||||||
|
description = "A Java class file parser written in Zig";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||||
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = {
|
||||||
|
nixpkgs,
|
||||||
|
flake-utils,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
flake-utils.lib.eachDefaultSystem (
|
||||||
|
system: let
|
||||||
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
nativeBuildInputs = with pkgs; [
|
||||||
|
zig
|
||||||
|
zls
|
||||||
|
];
|
||||||
|
|
||||||
|
buildInputs = with pkgs; [];
|
||||||
|
in {
|
||||||
|
devShells.default = pkgs.mkShell { inherit nativeBuildInputs buildInputs; };
|
||||||
|
|
||||||
|
packages.default = pkgs.stdenv.mkDerivation {
|
||||||
|
pname = "zig-class-parser";
|
||||||
|
version = "0.0.0";
|
||||||
|
src = ./.;
|
||||||
|
|
||||||
|
nativeBuildInputs =
|
||||||
|
nativeBuildInputs
|
||||||
|
++ [
|
||||||
|
pkgs.zig.hook
|
||||||
|
];
|
||||||
|
inherit buildInputs;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
1735
src/Class.zig
Normal file
1735
src/Class.zig
Normal file
File diff suppressed because it is too large
Load diff
49
src/main.zig
Normal file
49
src/main.zig
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
const Class = @import("Class.zig");
|
||||||
|
|
||||||
|
pub fn main(init: std.process.Init) !void {
|
||||||
|
const io = init.io;
|
||||||
|
const allocator = init.gpa;
|
||||||
|
|
||||||
|
var args = try init.minimal.args.iterateAllocator(init.arena.allocator());
|
||||||
|
defer args.deinit();
|
||||||
|
|
||||||
|
var stderr_writer: std.Io.File.Writer = .init(.stderr(), io, &.{});
|
||||||
|
const stderr = &stderr_writer.interface;
|
||||||
|
|
||||||
|
var stdout_buf: [1024]u8 = undefined;
|
||||||
|
var stdout_writer: std.Io.File.Writer = .init(.stdout(), io, &stdout_buf);
|
||||||
|
const stdout = &stdout_writer.interface;
|
||||||
|
|
||||||
|
std.debug.assert(args.skip());
|
||||||
|
const file_path = if (args.next()) |fp| fp else {
|
||||||
|
try stderr.writeAll("No file argument provided.\n");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
const file = std.Io.Dir.cwd().openFile(io, file_path, .{}) catch |err| switch (err) {
|
||||||
|
error.FileNotFound => {
|
||||||
|
try stderr.writeAll("File not found.\n");
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
error.IsDir => {
|
||||||
|
try stderr.writeAll("Path is a directory.\n");
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
else => return err,
|
||||||
|
};
|
||||||
|
defer file.close(io);
|
||||||
|
|
||||||
|
var file_buf: [1024]u8 = undefined;
|
||||||
|
var file_reader = file.reader(io, &file_buf);
|
||||||
|
const reader = &file_reader.interface;
|
||||||
|
|
||||||
|
var class = try Class.parse(reader, allocator);
|
||||||
|
defer class.deinit();
|
||||||
|
|
||||||
|
try stdout.print("{f}", .{ class });
|
||||||
|
|
||||||
|
try stdout.flush();
|
||||||
|
}
|
||||||
|
|
||||||
BIN
zig-out/bin/zig_jvm
Executable file
BIN
zig-out/bin/zig_jvm
Executable file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue