module "/pliant/language/os.pli" module "/pliant/language/compiler.pli" module "/pliant/language/generator.pli"
if os_api="win32" constant math_library "msvcrt.dll" else constant math_library (replace os_libc_filename "libc" "libm")
public constant pi 3.141592653589793238462
function i386_fstp f arg_w Float f function generate_i386_fstp64 i f arg_rw Instruction i ; arg_rw Function f i386_regmem f 11011101b 1 011b i:0 (the_function i386_fstp Float) set_generate_binary (the_function generate_i386_fstp64 Instruction Function)
function assemble_math1 i gc arg_rw Instruction i ; arg_rw GeneratorContext gc var Pointer:Instruction cur :> i if i:0:where=argument_indirect var Link:Argument a :> argument indirect Int i:0:pointer i:0:offset+4 eif i:0:where=argument_constant a :> argument indirect Int (argument constant Address (i:0:constant translate Int 1)) 0 else error error_id_unexpected "Argument location for function "+i:function:name+" is unexpected ("+(string i:0:where)+")" cur :> gc insert_after_instruction cur (instruction (the_function i386_push Int) a) cur :> gc insert_after_instruction cur (instruction (the_function i386_push Int) i:0) var Link:Instruction ii :> new Instruction ii function :> i function cur :> gc insert_after_instruction cur ii cur :> gc insert_after_instruction cur (instruction (the_function i386_add Int Int) (argument constant Int 8) (gc register i386_esp)) cur :> gc insert_after_instruction cur (instruction (the_function i386_fstp Float) i:1) gc remove i
named_expression math1_expr function name f -> r arg Float f r external math_library string_name
|
has_no_side_effect gvar Int temp := (the_function name Float -> Float) modify_registers
|
(the_function name Float -> Float) set_generate_assembly (the_function assemble_math1 Instruction GeneratorContext)
|
(the_function name Float -> Float) modify_registers := temp
|
export name
meta math1 e if e:size<>1 or e:0:ident="" return var Str name := e:0:ident
|
e compile_as (expression duplicate math1_expr substitute name (expression ident name near e:0) substitute string_name (expression constant name near e:0))
|
e compile_as (expression duplicate math1_expr substitute name (expression ident name near e:0) substitute string_name (expression constant name near e:0) substitute temp (expression ident "temp_"+name near e:0))
|
function assemble_math2 i gc arg_rw Instruction i ; arg_rw GeneratorContext gc var Pointer:Instruction cur :> i if i:0:where=argument_indirect var Link:Argument a :> argument indirect Int i:0:pointer i:0:offset+4 eif i:0:where=argument_constant a :> argument indirect Int (argument constant Address (i:0:constant translate Int 1)) 0 else error error_id_unexpected "Argument location for function "+i:function:name+" is unexpected ("+(string i:0:where)+")" if i:1:where=argument_indirect var Link:Argument b :> argument indirect Int i:1:pointer i:1:offset+4 eif i:1:where=argument_constant b :> argument indirect Int (argument constant Address (i:1:constant translate Int 1)) 0 else error error_id_unexpected "Argument location for function "+i:function:name+" is unexpected ("+(string i:1:where)+")" cur :> gc insert_after_instruction cur (instruction (the_function i386_push Int) b) cur :> gc insert_after_instruction cur (instruction (the_function i386_push Int) i:1) cur :> gc insert_after_instruction cur (instruction (the_function i386_push Int) a) cur :> gc insert_after_instruction cur (instruction (the_function i386_push Int) i:0) var Link:Instruction ii :> new Instruction ii function :> i function cur :> gc insert_after_instruction cur ii cur :> gc insert_after_instruction cur (instruction (the_function i386_add Int Int) (argument constant Int 16) (gc register i386_esp)) cur :> gc insert_after_instruction cur (instruction (the_function i386_fstp Float) i:2) gc remove i
named_expression math2_expr function name a b -> r arg Float a b r external math_library string_name
|
has_no_side_effect gvar Int temp := (the_function name Float Float -> Float) modify_registers
|
(the_function name Float Float -> Float) set_generate_assembly (the_function assemble_math2 Instruction GeneratorContext)
|
(the_function name Float Float -> Float) modify_registers := temp
|
export name
meta math2 e if e:size<>1 or e:0:ident="" return var Str name := e:0 ident
|
e compile_as (expression duplicate math2_expr substitute name (expression ident name near e:0) substitute string_name (expression constant name near e:0))
|
e compile_as (expression duplicate math2_expr substitute name (expression ident name near e:0) substitute string_name (expression constant name near e:0) substitute temp (expression ident "temp_"+name near e:0))
|
math1 sin math1 cos math1 tan math1 asin math1 acos math1 atan math1 exp math1 log math2 pow
|
|