import { Interpreter } from "../core/interpreter" ; import { Token , TokenValue } from "../structures/token" ; import { getType } from "../data/types" ; import { capitilizeFirstLetter , isCallable } from "../data/helper" ; export type FuncObj = { arity ( ) : [ number , number ] ; call ( interpreter , token , args ) : any ; stringify ( ) : string ; } ; export type ModuleObj = { name : string ; func : FuncObj ; } ; export let Funcs = [ { name : "print" , func : { arity ( ) { return [ 1 , 255 ] ; } , call ( interpreter , token , args ) { let outputs = args . map ( i => { let value = i . value ; if ( isCallable ( value ) ) value = value . stringify ( ) ; return value ; } ) ; console . log ( ... outputs ) ; return null ; } , stringify ( ) { return "<nativefunc print>" ; } } } , { name : "typeof" , func : { arity ( ) { return [ 1 , 1 ] ; } , call ( interpreter , token , args ) { let value = args [ 0 ] . value ; if ( isCallable ( value ) ) return value . stringify ( ) ; return capitilizeFirstLetter ( getType ( args [ 0 ] . value ) ) ; } , stringify ( ) { return "<nativefunc typeof>" ; } } } ] ;