45 lines
1.8 KiB
Modula-2
45 lines
1.8 KiB
Modula-2
// Built-in function definitions for basic2c
|
|
// Format: BUILTIN(name, return_type, c_template)
|
|
// This file is #included into basic2c.c with BUILTIN macro defined
|
|
//
|
|
// Template placeholders: % or %1 = first arg, %2 = second arg, etc.
|
|
// Return types: TYPE_BYTE, TYPE_INT, TYPE_LONG, TYPE_FLOAT, TYPE_DBL, TYPE_STR
|
|
|
|
// Standard math functions
|
|
BUILTIN("SQR", TYPE_DBL, "sqrt(%)")
|
|
BUILTIN("SIN", TYPE_DBL, "sin(%)")
|
|
BUILTIN("COS", TYPE_DBL, "cos(%)")
|
|
BUILTIN("TAN", TYPE_DBL, "tan(%)")
|
|
BUILTIN("ATN", TYPE_DBL, "atan(%)")
|
|
BUILTIN("LOG", TYPE_DBL, "log(%)")
|
|
BUILTIN("EXP", TYPE_DBL, "exp(%)")
|
|
BUILTIN("SGN", TYPE_INT, "((%) > 0 ? 1 : ((%) < 0 ? -1 : 0))")
|
|
BUILTIN("RND", TYPE_DBL, "((double)rand() / (double)RAND_MAX)")
|
|
|
|
// Extended math functions
|
|
BUILTIN("CEIL", TYPE_DBL, "ceil(%)")
|
|
BUILTIN("FLOOR", TYPE_DBL, "floor(%)")
|
|
BUILTIN("ROUND", TYPE_DBL, "round(%)")
|
|
BUILTIN("FRAC", TYPE_DBL, "((%) - floor(%))")
|
|
BUILTIN("FIX", TYPE_DBL, "trunc(%)")
|
|
BUILTIN("HYPOT", TYPE_DBL, "hypot(%, %2)")
|
|
BUILTIN("MAX", TYPE_DBL, "((double)((%) > (%2) ? (%) : (%2)))")
|
|
BUILTIN("MIN", TYPE_DBL, "((double)((%) < (%2) ? (%) : (%2)))")
|
|
|
|
// System/Time
|
|
BUILTIN("TIMER", TYPE_DBL, "((double)clock() / CLOCKS_PER_SEC)")
|
|
|
|
// String functions
|
|
BUILTIN("CHR$", TYPE_STR, "_bchr((int)(%))")
|
|
BUILTIN("STR$", TYPE_STR, "_bstr_of_int(%)")
|
|
BUILTIN("UCASE$", TYPE_STR, "_bucase(%)")
|
|
BUILTIN("LCASE$", TYPE_STR, "_blcase(%)")
|
|
BUILTIN("LTRIM$", TYPE_STR, "_bltrim(%)")
|
|
BUILTIN("RTRIM$", TYPE_STR, "_brtrim(%)")
|
|
BUILTIN("TRIM$", TYPE_STR, "_btrim(%)")
|
|
BUILTIN("SPACE$", TYPE_STR, "_bspace((int)(%))")
|
|
BUILTIN("HEX$", TYPE_STR, "_bhex((int)(%))")
|
|
BUILTIN("OCT$", TYPE_STR, "_boct((int)(%))")
|
|
BUILTIN("TAB", TYPE_STR, "_btab((int)(%))")
|
|
BUILTIN("SPC", TYPE_STR, "_bspace((int)(%))")
|
|
BUILTIN("ENVIRON$", TYPE_STR, "_bgetenv(%)")
|