Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated test.ooc.

  • Loading branch information...
commit 5c7cb664d0a288607cd145478cdaa108b796b417 1 parent 28c1a12
@tsion authored
Showing with 11 additions and 20 deletions.
  1. +11 −20 test.ooc
View
31 test.ooc
@@ -12,30 +12,21 @@ main: func {
myModule := Module new("my_module")
// Get the i32 type
- int_t := Type int32()
-
- // We need to represent the class of functions that accept three integers
- // and return an integer. This is represented by an object of the
- // function type
- func_t := Type function(int_t, [int_t, int_t, int_t] as ArrayList<Type>)
+ i32 := Type int32()
// Now we need a function named 'sum' using this type. Functions are not
// free-standing; thye need to be contained in a module.
- sum := myModule addFunction(func_t, "sum")
-
// Let's name the function arguments 'a', 'b', and 'c'.
- sum args[0] setName("a")
- sum args[1] setName("b")
- sum args[2] setName("c")
+ sum := myModule addFunction("sum", i32,
+ [i32, i32, i32] as ArrayList<Type>,
+ ["a", "b", "c"] as ArrayList<String>)
// Our function needs a "basic block" -- a set of instructions that
// end with a terminator (like return, branch etc.). By convention
- // the first block is called "entry".
- bb := sum appendBasicBlock("entry")
-
- // Let's add instructions into the block. For this, we need an
- // instruction builder:
- builder := Builder new(bb)
+ // the first block is called "entry". Instead of explicitly
+ // creating an "entry" basic block and then getting an instruction
+ // builderyou can just call builder() on a function:
+ builder := sum builder()
// OK, now for the instructions themselves. We'll create an add
// instruction that returns the sum as a value, which we'll use
@@ -52,9 +43,9 @@ main: func {
provider := ModuleProvider new(myModule)
engine := ExecutionEngine new(provider)
- arg1 := GenericValue new(int_t, 10 as ULLong, 0)
- arg2 := GenericValue new(int_t, 5 as ULLong, 0)
- arg3 := GenericValue new(int_t, 2 as ULLong, 0)
+ arg1 := GenericValue new(i32, 10 as ULLong, 0)
+ arg2 := GenericValue new(i32, 5 as ULLong, 0)
+ arg3 := GenericValue new(i32, 2 as ULLong, 0)
result := engine runFunction(sum, 3, [arg1, arg2, arg3] as GenericValue*)
result toInt(0) toString() println()
Please sign in to comment.
Something went wrong with that request. Please try again.