Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLTypes.java @ 12752:71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 11 Nov 2013 21:34:44 +0100 |
parents | 3faec5ab0696 |
children |
comparison
equal
deleted
inserted
replaced
12712:882a0aadfed6 | 12752:71991b7a0f14 |
---|---|
22 */ | 22 */ |
23 package com.oracle.truffle.sl; | 23 package com.oracle.truffle.sl; |
24 | 24 |
25 import java.math.*; | 25 import java.math.*; |
26 | 26 |
27 import com.oracle.truffle.api.*; | |
27 import com.oracle.truffle.api.dsl.*; | 28 import com.oracle.truffle.api.dsl.*; |
29 import com.oracle.truffle.sl.runtime.*; | |
28 | 30 |
29 @TypeSystem({int.class, BigInteger.class, boolean.class, String.class}) | 31 @TypeSystem({int.class, BigInteger.class, boolean.class, String.class, CallTarget.class, SLNull.class, Object[].class}) |
30 public class SLTypes { | 32 public class SLTypes { |
31 | 33 |
32 @TypeCheck | 34 @TypeCheck |
33 public boolean isInteger(Object value) { | 35 public boolean isSLNull(Object value) { |
34 return value instanceof Integer || (value instanceof BigInteger && ((BigInteger) value).bitLength() < Integer.SIZE); | 36 return SLNull.INSTANCE == value; |
35 } | 37 } |
36 | 38 |
37 @TypeCast | 39 @TypeCast |
38 public int asInteger(Object value) { | 40 public SLNull asSLNull(Object value) { |
39 assert isInteger(value); | 41 assert isSLNull(value); |
40 if (value instanceof Integer) { | 42 return SLNull.INSTANCE; |
41 return (int) value; | |
42 } else { | |
43 int result = ((BigInteger) value).intValue(); | |
44 assert BigInteger.valueOf(result).equals(value) : "Losing precision"; | |
45 return result; | |
46 } | |
47 } | 43 } |
48 | 44 |
49 @ImplicitCast | 45 @ImplicitCast |
50 public BigInteger castBigInteger(int integer) { | 46 public BigInteger castBigInteger(int integer) { |
51 return BigInteger.valueOf(integer); | 47 return BigInteger.valueOf(integer); |