Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0bb9501

Browse files
Update NectarCPP
1 parente8d318c commit0bb9501

File tree

8 files changed

+61
-7
lines changed

8 files changed

+61
-7
lines changed

‎compiler/native/env/node.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ var NODE =
134134
var_opt="-O";
135135
if(os.platform()=="darwin"||compiler.indexOf("clang")>-1)_opt+="3";
136136
else_opt+="fast";
137-
137+
console.log(`${compiler}${_hashmap} -D__NJS_REGISTER_SIZE=${COMPILER.REGISTER}${_stack} -std=c++17${_uvParam}${_files}${_opt} -s${COMPILER.LIBS}${_uvLib} -o a.exe && mv a.exe${out}${_cliOption}`);
138138
return`${compiler}${_hashmap} -D__NJS_REGISTER_SIZE=${COMPILER.REGISTER}${_stack} -std=c++17${_uvParam}${_files}${_opt} -s${COMPILER.LIBS}${_uvLib} -o a.exe && mv a.exe${out}${_cliOption}`;
139139
}
140140
}

‎compiler/native/lib/createFunction.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function createFunction(_code, _scope)
6262
_variadic=true;
6363
_parameters="var __Nectar_THIS, NectarCore::VAR* __Nectar_VARARGS, int __Nectar_VARLENGTH";
6464

65-
if(COMPILER.INFO.SCOPE[_match[1]].param.length==1)
65+
if(COMPILER.INFO.SCOPE[_match[1]]&&COMPILER.INFO.SCOPE[_match[1]].param.length==1)
6666
{
6767
for(vari=0;i<_match[2].length;i++)
6868
{

‎compiler/native/src/operator.h‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
*
2121
*/
2222

23+
NectarCore::VARoperator+ (constchar* _left,const NectarCore::VAR &_right)
24+
{
25+
returnstd::string(_left) + (std::string)_right;
26+
}
27+
28+
2329
NectarCore::VAR__Nectar_Boolean_Result(NectarCore::VAR _v)
2430
{
2531
if (_v.type == NectarCore::Enum::Type::Number)
@@ -73,7 +79,7 @@ std::ostream &operator<<(std::ostream &os, const NectarCore::VAR &_v)
7379
else os <<"false";
7480
break;
7581
case NectarCore::Enum::Type::Number:
76-
os <<(std::string)_v;
82+
os <<_v.data.number;
7783
break;
7884
case NectarCore::Enum::Type::String:
7985
os << (std::string)(*(NectarCore::Class::String*)_v.data.ptr);

‎compiler/native/src/operator_header.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ void *__Nectar_Get_Native(NectarCore::VAR _native);
3636

3737
/*** REDIFINING STD OPERATORS ***/
3838

39+
NectarCore::VARoperator+ (constchar* _left,const NectarCore::VAR &_right);
40+
3941
template<typename t>
4042
toperator+(t _left,const NectarCore::VAR &_right)
4143
{

‎compiler/native/src/stdfn.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222

2323
namespaceNectarCore::Functions
2424
{
25+
NectarCore::VARprintln()
26+
{
27+
#ifndef __Nectar_ENV_ARDUINO
28+
std::cout << std::endl;
29+
#endif
30+
return NectarCore::Global::undefined;
31+
}
2532
NectarCore::VARprintln(NectarCore::VAR _var)
2633
{
2734
#ifndef __Nectar_ENV_ARDUINO
@@ -30,6 +37,11 @@ namespace NectarCore::Functions
3037
return NectarCore::Global::undefined;
3138
}
3239

40+
NectarCore::VARprint()
41+
{
42+
return NectarCore::Global::undefined;
43+
}
44+
3345
NectarCore::VARprint(NectarCore::VAR _var)
3446
{
3547
#ifndef __Nectar_ENV_ARDUINO

‎compiler/native/src/stdfn_header.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
namespaceNectarCore::Functions
2424
{
25+
NectarCore::VARprintln();
2526
NectarCore::VARprintln(NectarCore::VAR _var);
27+
NectarCore::VARprint();
2628
NectarCore::VARprint(NectarCore::VAR _var);
2729
}

‎compiler/native/src/var.h‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ namespace NectarCore
101101
type = NectarCore::Enum::Type::String;
102102
data.ptr =newNectarCore::Class::String(_value);
103103
}
104-
105-
VAR::VAR(std::string _value)
104+
105+
VAR::VAR(conststd::string _value)
106106
{
107107
type = NectarCore::Enum::Type::String;
108108
data.ptr =newNectarCore::Class::String(_value);
@@ -113,6 +113,12 @@ namespace NectarCore
113113
type = NectarCore::Enum::Type::String;
114114
data.ptr =newNectarCore::Class::String(_value);
115115
}
116+
117+
VAR::VAR(std::string_view _value)
118+
{
119+
type = NectarCore::Enum::Type::String;
120+
data.ptr =newNectarCore::Class::String({_value.data(), _value.size()});
121+
}
116122

117123
VAR::VAR(NectarCore::Class::FixedArray *_value)
118124
{
@@ -592,6 +598,18 @@ namespace NectarCore
592598
elseif(type == NectarCore::Enum::Type::Boolean || type == NectarCore::Enum::Type::Number)return data.number;
593599
elsereturn (bool)(*(NectarCore::Class::Base*)data.ptr);
594600
}
601+
602+
VAR::operatorconstchar*()const
603+
{
604+
if(type == NectarCore::Enum::Type::String)
605+
{
606+
return ((NectarCore::Class::String*)this->data.ptr)->value.c_str();
607+
}
608+
else
609+
{
610+
throw(NectarCore::VAR("Char* conversion error: variable is not a string"));
611+
}
612+
}
595613

596614
VAR::operatorstd::string()const
597615
{
@@ -617,5 +635,17 @@ namespace NectarCore
617635
return (longlong)((double)*this);
618636
}
619637

638+
VAR::operatorstd::string_view()const
639+
{
640+
if(type == NectarCore::Enum::Type::String)
641+
{
642+
returnstd::string_view(((NectarCore::Class::String*)this->data.ptr)->value.c_str());
643+
}
644+
else
645+
{
646+
throw(NectarCore::VAR("string_view conversion error: variable is not a string"));
647+
}
648+
}
649+
620650

621651
}// namespace NectarCore

‎compiler/native/src/var_header.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ namespace NectarCore
5454
VAR(char *_value);
5555
VAR(std::string _value);
5656
VAR(constchar *_value);
57+
VAR(std::string_view _value);
5758
VAR(NectarCore::Class::FixedArray *_value);
5859
VAR(NectarCore::Class::Array *_value);
5960
VAR(const NectarCore::Class::Array *_value);
@@ -165,9 +166,10 @@ namespace NectarCore
165166
operatorbool();
166167
explicitoperatorstd::string()const;
167168
operatorstd::string();
168-
explicitoperatorconstchar*()const;
169-
explicitoperatorlonglong();
169+
operatorconstchar*()const;
170+
operatorlonglong();
170171
explicitoperatorlonglong()const;
172+
operatorstd::string_view()const;
171173

172174
};
173175
}// namespace NectarCore

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp