mirror of
https://github.com/chrim05/nds-console.git
synced 2025-06-18 21:55:34 -04:00
trying to use fat libs but initdefault fails even on hw
This commit is contained in:
parent
50083a49b9
commit
6cbba104ce
2
Makefile
2
Makefile
@ -38,7 +38,7 @@ LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
|||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# any extra libraries we wish to link with the project
|
# any extra libraries we wish to link with the project
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
LIBS := -lnds9
|
LIBS := -lfat -lnds9
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
|
BIN
dlms4.dldi
Normal file
BIN
dlms4.dldi
Normal file
Binary file not shown.
@ -66,7 +66,7 @@ class NDSConsole
|
|||||||
|
|
||||||
private: inline std::string getPromptPrefix()
|
private: inline std::string getPromptPrefix()
|
||||||
{
|
{
|
||||||
return "/ $ ";
|
return evaluator.cwd + " $ ";
|
||||||
}
|
}
|
||||||
|
|
||||||
private: void printPromptParsingError(NScript::Error e);
|
private: void printPromptParsingError(NScript::Error e);
|
||||||
|
@ -281,10 +281,10 @@ std::string NScript::Parser::escapesToEscaped(std::string s, Position pos)
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
NScript::Node NScript::Evaluator::expectType(Node node, NodeKind type, Position pos)
|
NScript::Node NScript::Evaluator::expectType(Node node, NodeKind type)
|
||||||
{
|
{
|
||||||
if (node.kind != type)
|
if (node.kind != type)
|
||||||
throw Error({"expected a value with type ", Node::kindToString(type), " (found ", Node::kindToString(node.kind), ")"}, pos);
|
throw Error({"expected a value with type ", Node::kindToString(type), " (found ", Node::kindToString(node.kind), ")"}, node.pos);
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
@ -300,20 +300,19 @@ NScript::Node NScript::Evaluator::builtinFloor(CallNode call)
|
|||||||
expectArgsCount(call, 1);
|
expectArgsCount(call, 1);
|
||||||
|
|
||||||
// truncating the float value
|
// truncating the float value
|
||||||
auto expr = expectType(evaluateNode(call.args[0]), NodeKind::Num, call.args[0].pos);
|
auto expr = expectType(evaluateNode(call.args[0]), NodeKind::Num);
|
||||||
expr.value.num = uint64_t(expr.value.num);
|
expr.value.num = uint64_t(expr.value.num);
|
||||||
|
|
||||||
return expr;
|
return expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
NScript::Node NScript::Evaluator::builtinPrint(CallNode call, Position pos)
|
void NScript::Evaluator::builtinPrint(CallNode call)
|
||||||
{
|
{
|
||||||
// printing all arguments without separation and flushing
|
// printing all arguments without separation and flushing
|
||||||
for (auto arg : call.args)
|
for (auto arg : call.args)
|
||||||
iprintf("%s", arg.toString().c_str());
|
iprintf("%s", arg.toString().c_str());
|
||||||
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
return Node::none(pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NScript::Node NScript::Evaluator::evaluateCallProcess(CallNode call, Position pos)
|
NScript::Node NScript::Evaluator::evaluateCallProcess(CallNode call, Position pos)
|
||||||
@ -332,9 +331,15 @@ NScript::Node NScript::Evaluator::evaluateCall(CallNode call, Position pos)
|
|||||||
auto name = std::string(call.name.value.str);
|
auto name = std::string(call.name.value.str);
|
||||||
|
|
||||||
if (name == "print")
|
if (name == "print")
|
||||||
return builtinPrint(call, pos);
|
builtinPrint(call);
|
||||||
else if (name == "floor")
|
else if (name == "floor")
|
||||||
return builtinFloor(call);
|
return builtinFloor(call);
|
||||||
|
else if (name == "cd")
|
||||||
|
builtinCd(call);
|
||||||
|
else if (name == "clear")
|
||||||
|
builtinClear(call);
|
||||||
|
else if (name == "shutdown")
|
||||||
|
builtinShutdown(call);
|
||||||
else
|
else
|
||||||
throw Error({"unknown builtin function"}, call.name.pos);
|
throw Error({"unknown builtin function"}, call.name.pos);
|
||||||
|
|
||||||
@ -455,4 +460,57 @@ NScript::Node NScript::Evaluator::evaluateNode(Node node)
|
|||||||
case NodeKind::Call: return evaluateCall(*node.value.call, node.pos);
|
case NodeKind::Call: return evaluateCall(*node.value.call, node.pos);
|
||||||
default: panic("unimplemented evaluateNode for some NodeKind"); return Node::none(node.pos);
|
default: panic("unimplemented evaluateNode for some NodeKind"); return Node::none(node.pos);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string NScript::Evaluator::expectStringLengthAndGetString(Node node, std::function<bool(uint64_t)> f)
|
||||||
|
{
|
||||||
|
auto s = std::string(node.value.str);
|
||||||
|
|
||||||
|
if (!f(s.length()))
|
||||||
|
throw Error({"expected a string with a different length"}, node.pos);
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NScript::Evaluator::builtinCd(CallNode call)
|
||||||
|
{
|
||||||
|
expectArgsCount(call, 1);
|
||||||
|
|
||||||
|
// expecting the only 1 arg is a string and expecting it to be a non-empty one
|
||||||
|
auto arg = call.args[0];
|
||||||
|
auto dir = expectStringLengthAndGetString(expectType(evaluateNode(arg), NodeKind::String), [] (uint64_t l) { return l > 0; });
|
||||||
|
auto isRelativePath = dir[0] != '/';
|
||||||
|
|
||||||
|
// dir must always have a character `/` at the end of the string
|
||||||
|
if (dir[dir.length() - 1] != '/')
|
||||||
|
dir.push_back('/');
|
||||||
|
|
||||||
|
if (isRelativePath)
|
||||||
|
dir = cwd + dir;
|
||||||
|
|
||||||
|
// opening dir
|
||||||
|
DIR* openedDir = opendir(dir.c_str());
|
||||||
|
|
||||||
|
// checking for dir correctly opened
|
||||||
|
if (!openedDir)
|
||||||
|
throw Error({"unknown dir"}, arg.pos);
|
||||||
|
|
||||||
|
// closing old dir
|
||||||
|
closedir(openedCwd);
|
||||||
|
|
||||||
|
// changing dir
|
||||||
|
cwd = dir;
|
||||||
|
openedCwd = openedDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NScript::Evaluator::builtinClear(CallNode call)
|
||||||
|
{
|
||||||
|
expectArgsCount(call, 0);
|
||||||
|
consoleClear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NScript::Evaluator::builtinShutdown(CallNode call)
|
||||||
|
{
|
||||||
|
expectArgsCount(call, 0);
|
||||||
|
systemShutDown();
|
||||||
}
|
}
|
@ -5,6 +5,8 @@
|
|||||||
#include <c++/12.1.0/vector>
|
#include <c++/12.1.0/vector>
|
||||||
#include <c++/12.1.0/functional>
|
#include <c++/12.1.0/functional>
|
||||||
#include <c++/12.1.0/utility>
|
#include <c++/12.1.0/utility>
|
||||||
|
#include <fat.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
#include "basics.h"
|
#include "basics.h"
|
||||||
|
|
||||||
@ -391,11 +393,21 @@ namespace NScript
|
|||||||
|
|
||||||
class Evaluator
|
class Evaluator
|
||||||
{
|
{
|
||||||
private: std::vector<KeyPair<std::string, Node>> map;
|
private: DIR* openedCwd; // current working directory pointer
|
||||||
|
public: std::string cwd; // current working directory
|
||||||
|
public: std::vector<KeyPair<std::string, Node>> map; // declared variables map
|
||||||
|
|
||||||
public: Evaluator()
|
public: Evaluator()
|
||||||
{
|
{
|
||||||
|
if (!fatInitDefault())
|
||||||
|
panic("could not initialize fat lib with default settings");
|
||||||
|
|
||||||
this->map = std::vector<KeyPair<std::string, Node>>();
|
this->map = std::vector<KeyPair<std::string, Node>>();
|
||||||
|
this->cwd = "/";
|
||||||
|
this->openedCwd = opendir(cwd.c_str());
|
||||||
|
|
||||||
|
if (!openedCwd)
|
||||||
|
panic("could not open root dir");
|
||||||
}
|
}
|
||||||
|
|
||||||
public: Node evaluateNode(Node node);
|
public: Node evaluateNode(Node node);
|
||||||
@ -416,12 +428,20 @@ namespace NScript
|
|||||||
|
|
||||||
private: Node evaluateCallProcess(CallNode call, Position pos);
|
private: Node evaluateCallProcess(CallNode call, Position pos);
|
||||||
|
|
||||||
private: Node builtinPrint(CallNode call, Position pos);
|
private: void builtinPrint(CallNode call);
|
||||||
|
|
||||||
private: Node builtinFloor(CallNode call);
|
private: Node builtinFloor(CallNode call);
|
||||||
|
|
||||||
|
private: void builtinCd(CallNode call);
|
||||||
|
|
||||||
|
private: void builtinClear(CallNode call);
|
||||||
|
|
||||||
|
private: void builtinShutdown(CallNode call);
|
||||||
|
|
||||||
private: void expectArgsCount(CallNode call, uint64_t count);
|
private: void expectArgsCount(CallNode call, uint64_t count);
|
||||||
|
|
||||||
private: Node expectType(Node node, NodeKind type, Position pos);
|
private: Node expectType(Node node, NodeKind type);
|
||||||
|
|
||||||
|
private: std::string expectStringLengthAndGetString(Node node, std::function<bool(uint64_t)> f);
|
||||||
};
|
};
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user