File:  [gforth] / gforth / vmgen-ex2 / test.mini
Revision 1.1: download - view: text, annotated - select for diffs
Sun Jun 2 15:46:18 2002 UTC (17 years, 2 months ago) by anton
Branches: MAIN
CVS tags: v0-7-0, v0-6-2, v0-6-1, v0-6-0, HEAD
vmgen-related changes:
in prims2x:
  Conversion macros for single items now take 2 arguments
  Converting from two items to a type has changed order
  argument printing for disassembler disabled (for now)
  disassembler now also uses VM_IS_INST
in Gforth and vmgen-ex: adapted to work with changed prims2x
new: vmgen-ex2: uses union for Cell instead of casting (lots of
   changes compared to vmgen-ex)

func operators()
  print 3 = 3;
  print (3+5) = 8;
  print (5-3) = 2;
  print (3*5) = 15;
  print (3&5) = 1;
  print (3|5) = 7;
  print (3<5) = 1;
  print (5<3) = 0;
  print (3=5) = 0;
  print (5=5) = 1;
  print (!3) = 0;
  print (!0) = 1;
  print (-3) = (0-3);
  return 0;
end func;

func params(a, b, c)
  print a = 3;
  print b = 5;
  print c = 7;
  return 9;
end func;

func locals(a)
  var b;
  var c;
  b:=a+1;
  c:=b+1;
  a:=c+1;
  return a;
end func;

func inc(x)
  return x+1;
end func;

func sign(n)
  var r;
  if (n<0) then
    r:=-1;
  else
    if (0<n) then
      r:=1;
    else
      r:=0;
    end if;
  end if;
  return r;
end func;

func recfac(n)
  var r;
  if (n<1) then
    r:=1;
  else
    r:=recfac(n-1)*n;
  end if;
  return r;
end func;

func itfac(n)
  var r;
  r:=1;
  while (0<n) do
    r:=r*n;
    n:=n-1;
  end while;
  return r;
end func;

func testfac()
  var i;
  i:=0;
  while (i<10) do
    print itfac(i) = recfac(i);
    i:=i+1;
  end while;
  return 0;
end func;

func main()
  operators();
  print params(3,5,7) = 9;
  print locals(3) = 6;
  print (inc(1)+inc(inc(inc(3))))=8;
  print sign(5) = 1;
  print sign(0) = 0;
  print sign(-5) = (-1);
  print itfac(5) = 120;
  testfac();
  return 0;
end func;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>