Skip to content

Commit

Permalink
Merge pull request #394 from xlang-foundation/Jit
Browse files Browse the repository at this point in the history
Jit
  • Loading branch information
OliviaGalaxy3DVision authored Mar 3, 2025
2 parents d1a6dec + 03424ad commit e7ef496
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Core/import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ bool X::AST::Import::FindAndLoadXModule(XlangRuntime* rt,
else
{
prefixPath = m_path;
ReplaceAll(prefixPath, ".", Path_Sep_S);
if (!m_pathHasQuotation)
{
//if not use from "path", then python style, replce . with /
ReplaceAll(prefixPath, ".", Path_Sep_S);
}
}
}
if (!bHaveX)
Expand Down Expand Up @@ -228,6 +232,7 @@ bool X::AST::Import::Exec(XlangRuntime* rt, ExecAction& action, XObj* pContext,
Value v0;
if (ExpExec(m_from,rt, action, pContext, v0, nullptr))
{
m_pathHasQuotation = m_from->PathHasQuotation();
m_path = v0.ToString();
}
}
Expand Down
7 changes: 7 additions & 0 deletions Core/import.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ class ThruOp :
class From :
public UnaryOp
{
bool m_pathHasQuotation = false;
std::string m_path;
public:
From() :
Expand All @@ -236,6 +237,10 @@ class From :
{
return m_path;
}
bool PathHasQuotation()
{
return m_pathHasQuotation;
}
bool Exec(XlangRuntime* rt,ExecAction& action, XObj* pContext,
Value& v, LValue* lValue) override
{
Expand All @@ -247,6 +252,7 @@ class From :
{
Str* pStr = dynamic_cast<Str*>(R);
m_path = std::string(pStr->GetChars(), pStr->Size());
m_pathHasQuotation = true;
}
else if (R->m_type == ObType::Var)
{
Expand Down Expand Up @@ -358,6 +364,7 @@ class Import :
//from path import moudule_lists
//only put one path after term: from
std::string m_path;
bool m_pathHasQuotation = false;
std::string m_thruUrl;
std::vector<ImportInfo> m_importInfos;
bool FindAndLoadExtensions(XlangRuntime* rt,
Expand Down
3 changes: 3 additions & 0 deletions test/import/sub/func_from_sub.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

def SubFunc():
return "SubFunc"
9 changes: 9 additions & 0 deletions test/import/test102.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from "sub" import func_from_sub as sub

x = sub.SubFunc()
print("call from sub folder's module, x=${x}")

from "../misc" import simple
y = simple.test_return(100)
print("y=${y}")
print("Done")

0 comments on commit e7ef496

Please sign in to comment.