Just got basic conditional branching working. With this code:

    :::felix
    >>> type int = "%i32";
    >>> typedef bool = 2;
    >>> fun add : int*int -> int = "%add";
    >>> fun eq : int*int -> bool = "%eq";
    >>> fun lnot : bool -> bool = "%lnot";
    >>> proc exit : int = "exit";
    >>> fun foo (x:int) = {
    ...  if x == 1 do
    ...    return 2;
    ...  else
    ...    return 3;
    ...  done;
    ... }
    >>> exit $ foo 1;

`flxc` will generate and execute this code:

    :::llvm
    declare void @exit(i32)
 
    define i32 @foo(i32 %x) {
    entry:
      %x1 = alloca i32                                ; <i32*> [#uses=2]
      store i32 %x, i32* %x1
      %0 = load i32* %x1                              ; <i32> [#uses=1]
      %1 = icmp eq i32 %0, 1                          ; <i1> [#uses=1]
      %2 = icmp eq i1 %1, false                       ; <i1> [#uses=1]
      br i1 %2, label %_ifdoend_1, label %else
 
    _ifdoend_1:                                       ; preds = %entry
      ret i32 3
 
    else:                                             ; preds = %entry
      ret i32 2
    }
 
    define void @0() {
    entry:
      %0 = call i32 @foo(i32 1)                       ; <i32> [#uses=1]
      call void @exit(i32 %0)
      ret void
    }

The program will exit with `2`. It'll even return `3` if you call `foo` with 
`2`. Unfortunately, branching only works inside functions.

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to