YAVGroup / Verilog-OJ

Online judge server for Verilog | verilogoj.ustc.edu.cn
GNU Affero General Public License v3.0
75 stars 12 forks source link

Python代码bug for循环局部变量i多次使用 #91

Open Yang-Xijie opened 2 years ago

Yang-Xijie commented 2 years ago

https://github.com/YAVGroup/Verilog-OJ/blob/109225ed74f5cfe809fa093af10e63b07ada8fde/assets/2to1mux.yml#L247-L277

在上面的代码中,for i in range(0, local_time_max + 1):使用变量i作为局部变量。但是下方多次再次使用i作为局部变量。在大多数module中,这并未引发问题,VCD文件可以转为WaveJSON。一个出现问题的例子如下:

top_module = "population_count"
    signal_names = ["in", "out"]
    code_reference = """
module population_count(
    input [2:0] in,
    output [1:0] out
);
    assign out = in[2] + in[1] + in[0];
endmodule
    """

    code_student = code_reference

    testbench = """
module testbench();
    reg [2:0] in;
    wire [1:0] out;
    population_count PopCount(in, out);

    initial begin
        $dumpfile(`DUMP_FILE_NAME);
        $dumpvars;
    end

    integer i;
    initial begin
        for (i = 0; i < 8; i = i + 1) begin
            #1 in = i;
        end
    end
endmodule
    """

解决方案

将(247行)

for i in range(0, local_time_max + 1): 
    if sig_inst['data'][cur_step_ptr][0] > i: 

改为

for time_i in range(0, local_time_max + 1): 
    if sig_inst['data'][cur_step_ptr][0] > time_i: 

将(254行)

if new_wave == cur_wave: 
    waves[i] += "." 

改为

if new_wave == cur_wave:
    for i in range(0, width):
        waves[i] += "."

其他保持不变。


不方便提issue,因为在所有题目中都有。

libreliu commented 2 years ago

谢谢反馈!我们之后找个时间统一来处理处理 XD