uncommented lines setting the error number in hak_geterrbinf() and hak_geterruinf()
This commit is contained in:
68
pas/main.pas
68
pas/main.pas
@ -2,19 +2,65 @@ program main;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses HAK, SysUtils;
|
||||
uses Hak, SysUtils, GetOpts;
|
||||
|
||||
var
|
||||
x: HAK.Interp = nil;
|
||||
begin
|
||||
(* System.ParamCount() returns only the number of argumetns except System.ParamStr(0). It is the upper bound to System.ParamStr(). *)
|
||||
if System.ParamCount() <> 1 then begin
|
||||
|
||||
(*c: System.AnsiChar;*)
|
||||
c: Char;
|
||||
optind: System.LongInt;
|
||||
opts: array[0..2] of GetOpts.TOption;
|
||||
|
||||
source_file: string;
|
||||
x: Hak.Interp = nil;
|
||||
|
||||
procedure print_usage_and_halt();
|
||||
begin
|
||||
writeln(System.Stderr, SysUtils.Format('Usage: %s <filename>', [SysUtils.ExtractFileName(System.ParamStr(0))]));
|
||||
System.Halt(-1);
|
||||
end;
|
||||
|
||||
begin
|
||||
(* System.ParamCount() returns only the number of argumetns except System.ParamStr(0). It is the upper bound to System.ParamStr(). *)
|
||||
|
||||
opts[0].name := 'heapsize';
|
||||
opts[0].has_arg := 1;
|
||||
opts[0].value := #0;
|
||||
opts[0].flag := nil;
|
||||
opts[1].name := 'modlibdirs';
|
||||
opts[1].has_arg := 1;
|
||||
opts[1].value := #0;
|
||||
opts[1].flag := nil;
|
||||
opts[2].name := ''; (* marker for the last item *)
|
||||
opts[2].has_arg := 0;
|
||||
opts[2].value := #0;
|
||||
opts[2].flag := nil;
|
||||
|
||||
(* TODO: proper command-line options handling *)
|
||||
c := #0;
|
||||
GetOpts.OptErr := false;
|
||||
repeat
|
||||
c := GetOpts.GetLongOpts(':', @opts[0], optind);
|
||||
case c of
|
||||
#0:
|
||||
begin
|
||||
(*TODO: process options.. *)
|
||||
(*opts[optind].name*)
|
||||
(*GetOpts.OptArg is the value *)
|
||||
end;
|
||||
|
||||
'?', ':':
|
||||
print_usage_and_halt;
|
||||
end;
|
||||
until c = GetOpts.EndOfOptions;
|
||||
|
||||
if GetOpts.OptInd <> System.ParamCount() then begin
|
||||
print_usage_and_halt;
|
||||
end;
|
||||
|
||||
source_file := System.ParamStr(GetOpts.OptInd);
|
||||
try
|
||||
x := HAK.Interp.Create(100);
|
||||
x := Hak.Interp.Create(100);
|
||||
x.Ignite(0);
|
||||
|
||||
x.AddBuiltinPrims();
|
||||
@ -30,13 +76,17 @@ begin
|
||||
x.Compile(pwidechar('(printf "%d %d\n" 동가리오 (동가리오 * 동가리오))'#10'printf "hello, world\n";;;'#10));
|
||||
*)
|
||||
|
||||
x.CompileFile(pansichar(ansistring(System.ParamStr(1))));
|
||||
x.CompileFile(pansichar(ansistring(source_file)));
|
||||
x.Execute(); // check if exception...
|
||||
except
|
||||
on e: Hak.ErrorException do begin
|
||||
if e.FileName <> '' then source_file := e.FileName;
|
||||
writeln('ERROR: ', SysUtils.Format('%s[%u,%u] %s', [source_file, e.Line, e.Column, e.Message]));
|
||||
end;
|
||||
on e: Exception do
|
||||
writeln('exception: ', e.Message);
|
||||
writeln('ERROR: ', e.Message);
|
||||
else
|
||||
writeln('unknonw exception');
|
||||
writeln('ERROR: unknonw exception');
|
||||
end;
|
||||
|
||||
if x <> nil then x.Destroy();
|
||||
|
||||
Reference in New Issue
Block a user