Skip to content

Commit

Permalink
objpascal: fix empty list evaluation.
Browse files Browse the repository at this point in the history
Part of kanaka#194.
  • Loading branch information
kanaka committed Apr 2, 2016
1 parent 203e959 commit 75b9209
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions objpascal/step2_eval.pas
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ function EVAL(Ast: TMal; Env: TEnv) : TMal;

// Apply list
Arr := (eval_ast(Ast, Env) as TMalList).Val;
if Length(Arr) = 0 then
Exit(Ast);
if Arr[0] is TMalFunc then
begin
Fn := (Arr[0] as TMalFunc).Val;
Expand Down
2 changes: 2 additions & 0 deletions objpascal/step3_env.pas
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ function EVAL(Ast: TMal; Env: TEnv) : TMal;

// Apply list
Arr := (Ast as TMalList).Val;
if Length(Arr) = 0 then
Exit(Ast);
if Arr[0] is TMalSymbol then
A0Sym := (Arr[0] as TMalSymbol).Val
else
Expand Down
2 changes: 2 additions & 0 deletions objpascal/step4_if_fn_do.pas
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ function EVAL(Ast: TMal; Env: TEnv) : TMal;
// Apply list
Lst := (Ast as TMalList);
Arr := Lst.Val;
if Length(Arr) = 0 then
Exit(Ast);
if Arr[0] is TMalSymbol then
A0Sym := (Arr[0] as TMalSymbol).Val
else
Expand Down
2 changes: 2 additions & 0 deletions objpascal/step5_tco.pas
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ function EVAL(Ast: TMal; Env: TEnv) : TMal;
// Apply list
Lst := (Ast as TMalList);
Arr := Lst.Val;
if Length(Arr) = 0 then
Exit(Ast);
if Arr[0] is TMalSymbol then
A0Sym := (Arr[0] as TMalSymbol).Val
else
Expand Down
2 changes: 2 additions & 0 deletions objpascal/step6_file.pas
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ function EVAL(Ast: TMal; Env: TEnv) : TMal;
// Apply list
Lst := (Ast as TMalList);
Arr := Lst.Val;
if Length(Arr) = 0 then
Exit(Ast);
if Arr[0] is TMalSymbol then
A0Sym := (Arr[0] as TMalSymbol).Val
else
Expand Down
2 changes: 2 additions & 0 deletions objpascal/step7_quote.pas
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ function EVAL(Ast: TMal; Env: TEnv) : TMal;
// Apply list
Lst := (Ast as TMalList);
Arr := Lst.Val;
if Length(Arr) = 0 then
Exit(Ast);
if Arr[0] is TMalSymbol then
A0Sym := (Arr[0] as TMalSymbol).Val
else
Expand Down
5 changes: 4 additions & 1 deletion objpascal/step8_macros.pas
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ function is_macro_call(Ast: TMal; Env: TEnv): Boolean;
Mac : TMal;
begin
is_macro_call := false;
if (Ast.ClassType = TMalList) then
if (Ast.ClassType = TMalList) and
(Length((Ast as TMalList).Val) > 0) then
begin
A0 := (Ast as TMalList).Val[0];
if (A0 is TMalSymbol) and
Expand Down Expand Up @@ -171,6 +172,8 @@ function EVAL(Ast: TMal; Env: TEnv) : TMal;
// Apply list
Lst := (Ast as TMalList);
Arr := Lst.Val;
if Length(Arr) = 0 then
Exit(Ast);
if Arr[0] is TMalSymbol then
A0Sym := (Arr[0] as TMalSymbol).Val
else
Expand Down
5 changes: 4 additions & 1 deletion objpascal/step9_try.pas
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ function is_macro_call(Ast: TMal; Env: TEnv): Boolean;
Mac : TMal;
begin
is_macro_call := false;
if (Ast.ClassType = TMalList) then
if (Ast.ClassType = TMalList) and
(Length((Ast as TMalList).Val) > 0) then
begin
A0 := (Ast as TMalList).Val[0];
if (A0 is TMalSymbol) and
Expand Down Expand Up @@ -172,6 +173,8 @@ function EVAL(Ast: TMal; Env: TEnv) : TMal;
// Apply list
Lst := (Ast as TMalList);
Arr := Lst.Val;
if Length(Arr) = 0 then
Exit(Ast);
if Arr[0] is TMalSymbol then
A0Sym := (Arr[0] as TMalSymbol).Val
else
Expand Down
5 changes: 4 additions & 1 deletion objpascal/stepA_mal.pas
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ function is_macro_call(Ast: TMal; Env: TEnv): Boolean;
Mac : TMal;
begin
is_macro_call := false;
if (Ast.ClassType = TMalList) then
if (Ast.ClassType = TMalList) and
(Length((Ast as TMalList).Val) > 0) then
begin
A0 := (Ast as TMalList).Val[0];
if (A0 is TMalSymbol) and
Expand Down Expand Up @@ -172,6 +173,8 @@ function EVAL(Ast: TMal; Env: TEnv) : TMal;
// Apply list
Lst := (Ast as TMalList);
Arr := Lst.Val;
if Length(Arr) = 0 then
Exit(Ast);
if Arr[0] is TMalSymbol then
A0Sym := (Arr[0] as TMalSymbol).Val
else
Expand Down

0 comments on commit 75b9209

Please sign in to comment.