diff options
Diffstat (limited to 'ast.cpp')
-rw-r--r-- | ast.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -17,14 +17,25 @@ */ #include "ast.hpp" +#include <charconv> +#include <iostream> + int ThunkAST::tcount = 0; NumberAST::NumberAST(const std::string& n): BaseAST(n) {} llvm::Value *NumberAST::codegen(LLVMState& llvmState) const { - auto val = llvmState.createInt(std::stoi(name)); - return llvmState.builder.CreateStore(val, llvmState.createPush()); + int value; + auto [ptr, _] = std::from_chars(&name.front(), &name.back() + 1, value); + + if (ptr <= &name.back()) { + std::cerr << "error: not a number: " << name << std::endl; + return nullptr; + } else { + auto val = llvmState.createInt(value); + return llvmState.builder.CreateStore(val, llvmState.createPush()); + } } PushAST::PushAST(const std::string& n): BaseAST(n) {} @@ -38,6 +49,7 @@ llvm::Value *PushAST::codegen(LLVMState& llvmState) const return llvmState.builder.CreateStore(var, dsget); } else { + std::cerr << "error: not defined: " << name << std::endl; return nullptr; } } @@ -68,6 +80,8 @@ llvm::Value *CallAST::codegen(LLVMState& llvmState) const return llvmState.builder.CreateCall(llvmState.ftype, cast); } } else { + std::cerr << "warning: anticipating external function: " + << name << std::endl; auto func = llvmState.createFunction(name); Var::addGlobal(name, Var {func, true}); return llvmState.builder.CreateCall(llvmState.ftype, func); |