From f46acdf87a6a3061828dc153f196e0588c7ec1db Mon Sep 17 00:00:00 2001 From: water Date: Sun, 13 Sep 2020 12:11:49 -0400 Subject: [PATCH] what is going on with clang format --- goalc/compiler/Compiler.h | 1 + goalc/compiler/IR.h | 18 +++++++++++++++++ goalc/compiler/compilation/Atoms.cpp | 2 +- goalc/compiler/compilation/Math.cpp | 29 ++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/goalc/compiler/Compiler.h b/goalc/compiler/Compiler.h index d77bd0df34..2dbfb5386b 100644 --- a/goalc/compiler/Compiler.h +++ b/goalc/compiler/Compiler.h @@ -136,6 +136,7 @@ class Compiler { Val* compile_add(const goos::Object& form, const goos::Object& rest, Env* env); Val* compile_sub(const goos::Object& form, const goos::Object& rest, Env* env); Val* compile_mul(const goos::Object& form, const goos::Object& rest, Env* env); + Val* compile_div(const goos::Object& form, const goos::Object& rest, Env* env); // Function Val* compile_lambda(const goos::Object& form, const goos::Object& rest, Env* env); diff --git a/goalc/compiler/IR.h b/goalc/compiler/IR.h index 635005e391..cd9a59ae64 100644 --- a/goalc/compiler/IR.h +++ b/goalc/compiler/IR.h @@ -221,4 +221,22 @@ class IR_IntegerMath : public IR { RegVal* m_arg; }; +enum class FloatMathKind { DIV_SS }; + +class IR_FloatMath : public IR { + public: + IR_FloatMath(FloatMathKind kind, RegVal* dest, RegVal* arg); + std::string print() override; + RegAllocInstr to_rai() override; + void do_codegen(emitter::ObjectGenerator* gen, + const AllocationResult& allocs, + emitter::IR_Record irec) override; + FloatMathKind get_kind() const { return m_kind; } + + protected: + FloatMathKind m_kind; + RegVal* m_dest; + RegVal* m_arg; +}; + #endif // JAK_IR_H diff --git a/goalc/compiler/compilation/Atoms.cpp b/goalc/compiler/compilation/Atoms.cpp index bfc4cc7ef9..e66d14065b 100644 --- a/goalc/compiler/compilation/Atoms.cpp +++ b/goalc/compiler/compilation/Atoms.cpp @@ -101,7 +101,7 @@ static const std::unordered_map< {"+", &Compiler::compile_add}, {"-", &Compiler::compile_sub}, {"*", &Compiler::compile_mul}, - // {"/", &Compiler::compile_divide}, + {"/", &Compiler::compile_div}, // {"shlv", &Compiler::compile_shlv}, // {"shrv", &Compiler::compile_shrv}, // {"sarv", &Compiler::compile_sarv}, diff --git a/goalc/compiler/compilation/Math.cpp b/goalc/compiler/compilation/Math.cpp index d9bba8916f..2fa8634058 100644 --- a/goalc/compiler/compilation/Math.cpp +++ b/goalc/compiler/compilation/Math.cpp @@ -203,4 +203,33 @@ Val* Compiler::compile_sub(const goos::Object& form, const goos::Object& rest, E } assert(false); return get_none(); +} + +Val* Compiler::compile_div(const goos::Object& form, const goos::Object& rest, Env* env) { + auto args = get_va(form, rest); + if (!args.named.empty() || args.unnamed.size() != 2) { + throw_compile_error(form, "Invalid / form"); + } + + auto first_val = compile_error_guard(args.unnamed.at(0), env); + auto first_type = first_val->type(); + auto math_type = get_math_mode(first_type); + switch (math_type) { + case MATH_FLOAT: + + { + auto result = env->make_xmm(first_type); + env->emit(std::make_unique(result, first_val->to_xmm(env))); + env->emit(std::make_unique(FloatMathKind::DIV_SS, result, to_math_type(compile_error_guard(args.unnamed.at(1), env), math_type, env)->to_xmm(env)))); + } + + case MATH_INVALID: + throw_compile_error( + form, "Cannot determine the math mode for object of type " + first_type.print()); + break; + default: + assert(false); + } + assert(false); + return get_none(); } \ No newline at end of file