Advertisement
Guest User

маньячества

a guest
Jun 29th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.07 KB | None | 0 0
  1. type Unit = llvm { void }
  2. type Int = llvm { i32 }
  3. type Vec3i = (x: Int, y: Int, z: Int)
  4.  
  5. def vec3i = llvm { x: Int, y: Int, z: Int ->
  6.     %1 = getelementptr %struct.Vec3i, %struct.Vec3i* %ret, i32 0, i32 0
  7.     store i32 %x, i32* %1
  8.  
  9.     %2 = getelementptr %struct.Vec3i, %struct.Vec3i* %ret, i32 0, i32 1
  10.     store i32 %y, i32* %2
  11.  
  12.     %3 = getelementptr %struct.Vec3i, %struct.Vec3i* %ret, i32 0, i32 0
  13.     store i32 %z, i32* %3
  14.  
  15.     ret void
  16. }: Vec3i
  17.  
  18. def printInt = llvm { i: Int ->
  19.     %str = alloca [4 x i8], align 1
  20.     store [4 x i8] c"%d\0A\00", [4 x i8]* %str, align 1
  21.     %1 = getelementptr [4 x i8], [4 x i8]* %str, i32 0, i32 0
  22.     %2 = call i32 (i8*, ...) @printf(i8* %1, i32 %i)
  23.     ret void
  24. }: Unit
  25.  
  26. def + = llvm { self: Int, other: Int ->
  27.   %1 = add nsw i32 %other, %self
  28.   ret i32 %1
  29. }: Int
  30.  
  31. def * = llvm { self: Int, other: Int ->
  32.   %1 = mul nsw i32 %other, %self
  33.   ret i32 %1
  34. }: Int
  35.  
  36. def main = {
  37.     val a: Int = 1
  38.     a + 1 * 3
  39.     2
  40.     val v: Vec3i = vec3i(2,3,1)
  41.     val b: Int  = a * 10 + 1 + v.y * 2
  42.     printInt(b)
  43.     0
  44. }: Int
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement