import { getInternalName } from "../intrinsics" ; import * as Specification from "./specification" ; export function func ( name , returnType , ... args ) { return { type : "function" , functionName : getInternalName ( { name : name , argTypes : args . map ( ( arg ) => arg . valueType ) , returnType : returnType } ) , arguments : args , valueType : returnType } as Specification . ExpressionFunction ; } export function op ( name , returnType , ... args ) { return { type : "function" , functionName : getInternalName ( { name : `@${ name }` , argTypes : args . map ( ( arg ) => arg . valueType ) , returnType : returnType } ) , valueType : returnType , arguments : args , } as Specification . ExpressionFunction ; } export function cast ( from , to ) { return { type : "function" , functionName : getInternalName ( { name : `cast:${ from . valueType }:${ to }` , argTypes : [ from . valueType ] , returnType : to } ) , valueType : to , arguments : [ from ] , } as Specification . ExpressionFunction ; } export function variable ( varName , varType ) { return { type : "variable" , variableName : varName , valueType : varType } as Specification . ExpressionVariable ; } export function constant ( value , valueType ) { return { type : "constant" , value : value , valueType : valueType } as Specification . ExpressionConstant ; } export function mix ( a1 , a2 , t ) { return func ( "mix" , a1 . valueType , a1 , a2 , t ) ; } export function exp ( x ) { return func ( "exp" , "float" , x ) ; } export function log ( x ) { return func ( "log" , "float" , x ) ; } export function add ( a1 , a2 ) { return op ( "+" , a1 . valueType , a1 , a2 ) ; } export function sub ( a1 , a2 ) { return op ( "-" , a1 . valueType , a1 , a2 ) ; } export function mul ( a1 , a2 ) { return op ( "*" , a1 . valueType , a1 , a2 ) ; } export function div ( a1 , a2 ) { return op ( "/" , a1 . valueType , a1 , a2 ) ; } export function equals ( a1 , a2 ) { return op ( "==" , "bool" , a1 , a2 ) ; } export function greaterThan ( a1 , a2 ) { return op ( ">" , "bool" , a1 , a2 ) ; } export function lessThan ( a1 , a2 ) { return op ( "<" , "bool" , a1 , a2 ) ; } export function greaterThanOrEquals ( a1 , a2 ) { return op ( ">=" , "bool" , a1 , a2 ) ; } export function lessThanOrEquals ( a1 , a2 ) { return op ( "<=" , "bool" , a1 , a2 ) ; }