From 08e110c4f67eef9d93ac1b26aebcba2164ca943e Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 31 Mar 2025 19:25:37 +0800 Subject: [PATCH 01/14] Refactor main to simplify allocator and error handling code. Signed-off-by: Your Name --- src/main.zig | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/main.zig b/src/main.zig index 19935e6..d93cc66 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,6 +1,4 @@ const std = @import("std"); -const Allocator = mem.Allocator; -const mem = std.mem; const process = std.process; const aro = @import("aro"); const Compilation = aro.Compilation; @@ -11,13 +9,8 @@ const assembly_backend = @import("assembly_backend"); var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){}; pub fn main() u8 { - const gpa = if (@import("builtin").link_libc) - std.heap.raw_c_allocator - else - general_purpose_allocator.allocator(); - defer if (!@import("builtin").link_libc) { - _ = general_purpose_allocator.deinit(); - }; + const gpa = if (@import("builtin").link_libc) std.heap.raw_c_allocator else general_purpose_allocator.allocator(); + defer if (!@import("builtin").link_libc) _ = general_purpose_allocator.deinit(); var arena_instance = std.heap.ArenaAllocator.init(gpa); defer arena_instance.deinit(); @@ -25,13 +18,13 @@ pub fn main() u8 { const fast_exit = @import("builtin").mode != .Debug; - const args = process.argsAlloc(arena) catch { + const args = process.argsAlloc(arena) catch |err| { std.debug.print("out of memory\n", .{}); if (fast_exit) process.exit(1); return 1; }; - const aro_name = std.fs.selfExePathAlloc(gpa) catch { + const aro_name = std.fs.selfExePathAlloc(gpa) catch |err| { std.debug.print("unable to find Aro executable path\n", .{}); if (fast_exit) process.exit(1); return 1; @@ -47,11 +40,8 @@ pub fn main() u8 { }; defer comp.deinit(); - var driver: Driver = .{ .comp = &comp, .aro_name = aro_name }; - defer driver.deinit(); - - var toolchain: Toolchain = .{ .driver = &driver, .arena = arena, .filesystem = .{ .real = comp.cwd } }; - defer toolchain.deinit(); + var driver = Driver{ .comp = &comp, .aro_name = aro_name }; + var toolchain = Toolchain{ .driver = &driver, .arena = arena, .filesystem = .{ .real = comp.cwd } }; driver.main(&toolchain, args, fast_exit, assembly_backend.genAsm) catch |er| switch (er) { error.OutOfMemory => { -- Gitee From 1ca6989cd20e0a69f1ebfd5cfa5ce3053a890ce5 Mon Sep 17 00:00:00 2001 From: dfdfsd <58477+huhu5@user.noreply.gitee.com> Date: Wed, 9 Apr 2025 03:35:42 +0000 Subject: [PATCH 02/14] Refactor Signed-off-by: dfdfsd <58477+huhu5@user.noreply.gitee.com> --- src/main.zig | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/src/main.zig b/src/main.zig index d93cc66..4743f49 100644 --- a/src/main.zig +++ b/src/main.zig @@ -6,11 +6,15 @@ const Driver = aro.Driver; const Toolchain = aro.Toolchain; const assembly_backend = @import("assembly_backend"); -var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){}; +fn handleOutOfMemory(fast_exit: bool) u8 { + std.debug.print("out of memory\n", .{}); + if (fast_exit) process.exit(1); + return 1; +} pub fn main() u8 { - const gpa = if (@import("builtin").link_libc) std.heap.raw_c_allocator else general_purpose_allocator.allocator(); - defer if (!@import("builtin").link_libc) _ = general_purpose_allocator.deinit(); + const gpa = if (@import("builtin").link_libc) std.heap.raw_c_allocator else std.heap.GeneralPurposeAllocator(.{}).allocator(); + defer if (!@import("builtin").link_libc) _ = std.heap.GeneralPurposeAllocator(.{}).deinit(); var arena_instance = std.heap.ArenaAllocator.init(gpa); defer arena_instance.deinit(); @@ -18,25 +22,13 @@ pub fn main() u8 { const fast_exit = @import("builtin").mode != .Debug; - const args = process.argsAlloc(arena) catch |err| { - std.debug.print("out of memory\n", .{}); - if (fast_exit) process.exit(1); - return 1; - }; + const args = process.argsAlloc(arena) catch handleOutOfMemory(fast_exit); - const aro_name = std.fs.selfExePathAlloc(gpa) catch |err| { - std.debug.print("unable to find Aro executable path\n", .{}); - if (fast_exit) process.exit(1); - return 1; - }; + const aro_name = std.fs.selfExePathAlloc(gpa) catch handleOutOfMemory(fast_exit); defer gpa.free(aro_name); var comp = Compilation.initDefault(gpa, std.fs.cwd()) catch |er| switch (er) { - error.OutOfMemory => { - std.debug.print("out of memory\n", .{}); - if (fast_exit) process.exit(1); - return 1; - }, + error.OutOfMemory => handleOutOfMemory(fast_exit), }; defer comp.deinit(); @@ -44,11 +36,7 @@ pub fn main() u8 { var toolchain = Toolchain{ .driver = &driver, .arena = arena, .filesystem = .{ .real = comp.cwd } }; driver.main(&toolchain, args, fast_exit, assembly_backend.genAsm) catch |er| switch (er) { - error.OutOfMemory => { - std.debug.print("out of memory\n", .{}); - if (fast_exit) process.exit(1); - return 1; - }, + error.OutOfMemory => handleOutOfMemory(fast_exit), error.FatalError => { driver.renderErrors(); if (fast_exit) process.exit(1); @@ -57,4 +45,4 @@ pub fn main() u8 { }; if (fast_exit) process.exit(@intFromBool(comp.diagnostics.errors != 0)); return @intFromBool(comp.diagnostics.errors != 0); -} +} \ No newline at end of file -- Gitee From 4ff80c98487441d7d8dfdd67d3b382a148eed4fd Mon Sep 17 00:00:00 2001 From: dfdfsd <58477+huhu5@user.noreply.gitee.com> Date: Wed, 9 Apr 2025 06:17:09 +0000 Subject: [PATCH 03/14] update src/main.zig. Signed-off-by: dfdfsd <58477+huhu5@user.noreply.gitee.com> --- src/main.zig | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/main.zig b/src/main.zig index 4743f49..cd0c056 100644 --- a/src/main.zig +++ b/src/main.zig @@ -12,9 +12,16 @@ fn handleOutOfMemory(fast_exit: bool) u8 { return 1; } +fn handleError(fast_exit: bool, er: anyerror) u8 { + return switch (er) { + error.OutOfMemory => handleOutOfMemory(fast_exit), + }; +} + pub fn main() u8 { - const gpa = if (@import("builtin").link_libc) std.heap.raw_c_allocator else std.heap.GeneralPurposeAllocator(.{}).allocator(); - defer if (!@import("builtin").link_libc) _ = std.heap.GeneralPurposeAllocator(.{}).deinit(); + const link_libc = @import("builtin").link_libc; + const gpa = if (link_libc) std.heap.raw_c_allocator else std.heap.GeneralPurposeAllocator(.{}).allocator(); + defer if (!link_libc) _ = std.heap.GeneralPurposeAllocator(.{}).deinit(); var arena_instance = std.heap.ArenaAllocator.init(gpa); defer arena_instance.deinit(); @@ -22,27 +29,26 @@ pub fn main() u8 { const fast_exit = @import("builtin").mode != .Debug; - const args = process.argsAlloc(arena) catch handleOutOfMemory(fast_exit); + const args = process.argsAlloc(arena) catch handleError(fast_exit, @errorFromAny(error.OutOfMemory)); - const aro_name = std.fs.selfExePathAlloc(gpa) catch handleOutOfMemory(fast_exit); + const aro_name = std.fs.selfExePathAlloc(gpa) catch handleError(fast_exit, @errorFromAny(error.OutOfMemory)); defer gpa.free(aro_name); - var comp = Compilation.initDefault(gpa, std.fs.cwd()) catch |er| switch (er) { - error.OutOfMemory => handleOutOfMemory(fast_exit), - }; + var comp = Compilation.initDefault(gpa, std.fs.cwd()) catch |er| handleError(fast_exit, er); defer comp.deinit(); var driver = Driver{ .comp = &comp, .aro_name = aro_name }; var toolchain = Toolchain{ .driver = &driver, .arena = arena, .filesystem = .{ .real = comp.cwd } }; - driver.main(&toolchain, args, fast_exit, assembly_backend.genAsm) catch |er| switch (er) { - error.OutOfMemory => handleOutOfMemory(fast_exit), - error.FatalError => { + driver.main(&toolchain, args, fast_exit, assembly_backend.genAsm) catch |er| { + handleError(fast_exit, er); + if (@errorIntoBool(er)) { driver.renderErrors(); if (fast_exit) process.exit(1); return 1; - }, + } }; + if (fast_exit) process.exit(@intFromBool(comp.diagnostics.errors != 0)); return @intFromBool(comp.diagnostics.errors != 0); } \ No newline at end of file -- Gitee From 497e2dc2796b4929c69c19986b99674b9be49299 Mon Sep 17 00:00:00 2001 From: dfdfsd <58477+huhu5@user.noreply.gitee.com> Date: Wed, 9 Apr 2025 06:42:48 +0000 Subject: [PATCH 04/14] update README.md. Signed-off-by: dfdfsd <58477+huhu5@user.noreply.gitee.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 159e4fc..c548e7c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Aro -# Aro +# AroCC A C compiler with the goal of providing fast compilation and low memory usage with good diagnostics. -- Gitee From cef2676dbf45cfa12590ca91c86c5e37d8554202 Mon Sep 17 00:00:00 2001 From: dfdfsd <58477+huhu5@user.noreply.gitee.com> Date: Wed, 9 Apr 2025 06:43:55 +0000 Subject: [PATCH 05/14] Revert "update README.md." This reverts commit 497e2dc2796b4929c69c19986b99674b9be49299. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c548e7c..159e4fc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Aro -# AroCC +# Aro A C compiler with the goal of providing fast compilation and low memory usage with good diagnostics. -- Gitee From 3a335a25841f462759bf7bc18a0a209cedf9a848 Mon Sep 17 00:00:00 2001 From: dfdfsd <58477+huhu5@user.noreply.gitee.com> Date: Wed, 9 Apr 2025 06:45:23 +0000 Subject: [PATCH 06/14] update README.md. Signed-off-by: dfdfsd <58477+huhu5@user.noreply.gitee.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 159e4fc..e5d81ed 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Aro -# Aro +# Aro CC A C compiler with the goal of providing fast compilation and low memory usage with good diagnostics. -- Gitee From 78f9d7bf536ee6f75cd50c6377828f9d15fe1108 Mon Sep 17 00:00:00 2001 From: dfdfsd <58477+huhu5@user.noreply.gitee.com> Date: Wed, 9 Apr 2025 06:49:49 +0000 Subject: [PATCH 07/14] update README.md. Signed-off-by: dfdfsd <58477+huhu5@user.noreply.gitee.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e5d81ed..159e4fc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Aro -# Aro CC +# Aro A C compiler with the goal of providing fast compilation and low memory usage with good diagnostics. -- Gitee From 66ef5e61432243994c2ff2eb1504522f225b8b92 Mon Sep 17 00:00:00 2001 From: dfdfsd <58477+huhu5@user.noreply.gitee.com> Date: Wed, 9 Apr 2025 06:51:33 +0000 Subject: [PATCH 08/14] update README.md. Signed-off-by: dfdfsd <58477+huhu5@user.noreply.gitee.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 159e4fc..537297e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Aro -# Aro +# Aro CCC A C compiler with the goal of providing fast compilation and low memory usage with good diagnostics. -- Gitee From d82dab39973ca6d08eca06b2ab06d8ddf0d59264 Mon Sep 17 00:00:00 2001 From: dfdfsd <58477+huhu5@user.noreply.gitee.com> Date: Wed, 9 Apr 2025 06:55:16 +0000 Subject: [PATCH 09/14] update README.md. Signed-off-by: dfdfsd <58477+huhu5@user.noreply.gitee.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 537297e..159e4fc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Aro -# Aro CCC +# Aro A C compiler with the goal of providing fast compilation and low memory usage with good diagnostics. -- Gitee From 807e9604626a88cd78e0b290f1b282fbdafb4d76 Mon Sep 17 00:00:00 2001 From: dfdfsd <58477+huhu5@user.noreply.gitee.com> Date: Wed, 9 Apr 2025 06:56:47 +0000 Subject: [PATCH 10/14] update README.md. Signed-off-by: dfdfsd <58477+huhu5@user.noreply.gitee.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 159e4fc..9bd0eb4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Aro -# Aro +# Aroccc A C compiler with the goal of providing fast compilation and low memory usage with good diagnostics. -- Gitee From 20286181cbd5fea4e36d03ed6177f7ddca05c3b3 Mon Sep 17 00:00:00 2001 From: dfdfsd <58477+huhu5@user.noreply.gitee.com> Date: Wed, 9 Apr 2025 07:00:37 +0000 Subject: [PATCH 11/14] update README.md. Signed-off-by: dfdfsd <58477+huhu5@user.noreply.gitee.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9bd0eb4..505877a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Aro -# Aroccc +# Aro ccc A C compiler with the goal of providing fast compilation and low memory usage with good diagnostics. -- Gitee From 4307fa7b745b88800beb04a7840343ab2d6da827 Mon Sep 17 00:00:00 2001 From: dfdfsd <58477+huhu5@user.noreply.gitee.com> Date: Wed, 9 Apr 2025 07:07:09 +0000 Subject: [PATCH 12/14] update README.md. Signed-off-by: dfdfsd <58477+huhu5@user.noreply.gitee.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 505877a..f112cf4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Aro -# Aro ccc +# Aro c A C compiler with the goal of providing fast compilation and low memory usage with good diagnostics. -- Gitee From 8b0557ac7be5e2e4f858ca7bea28a5db7e3b690f Mon Sep 17 00:00:00 2001 From: dfdfsd <58477+huhu5@user.noreply.gitee.com> Date: Wed, 9 Apr 2025 09:06:55 +0000 Subject: [PATCH 13/14] Update Signed-off-by: dfdfsd <58477+huhu5@user.noreply.gitee.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f112cf4..17b59ea 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Aro -# Aro c +# Aro cccc A C compiler with the goal of providing fast compilation and low memory usage with good diagnostics. -- Gitee From 4ae61d7223c309271ab055743e8697f992f272bb Mon Sep 17 00:00:00 2001 From: dfdfsd <58477+huhu5@user.noreply.gitee.com> Date: Thu, 12 Jun 2025 03:44:32 +0000 Subject: [PATCH 14/14] asdfd --- ZfAbsMean.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 ZfAbsMean.py diff --git a/ZfAbsMean.py b/ZfAbsMean.py new file mode 100644 index 0000000..77b654b --- /dev/null +++ b/ZfAbsMean.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +""" +中性策略框架 | 邢不行 | 2024分享会 +author: 邢不行 +微信: xbx6660 +""" +import numpy as np + +""" +波动因子 +""" +def signal(*args): + df = args[0] + n = args[1] + factor_name = args[2] + + df['均价'] = (df['close'] + df['high'] + df['low']) / 3 + + df['涨跌幅'] = df['均价'].pct_change() + df['振幅'] = (df['high'] - df['low']) / df['open'] + df['振幅'] = np.where(df['涨跌幅'] > 0, df['振幅'], 0) + df['振幅均值'] = df['振幅'].rolling(n, min_periods=1).mean() + + df[factor_name] = df['振幅均值'].rolling(n, min_periods=1).rank(ascending=True, pct=True) + + return df -- Gitee