Compare commits
2 Commits
8fea13cc17
...
2ae3086481
| Author | SHA1 | Date | |
|---|---|---|---|
| 2ae3086481 | |||
| 38557cdf4c |
52
.vim/indent/kyn.vim
Normal file
52
.vim/indent/kyn.vim
Normal file
@@ -0,0 +1,52 @@
|
||||
" Vim indent file
|
||||
" Language: Kyn
|
||||
" Maintainer: Gemini
|
||||
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal indentexpr=GetKynIndent()
|
||||
setlocal indentkeys+=={,},0)
|
||||
|
||||
let b:undo_indent = "setlocal indentexpr< indentkeys<"
|
||||
|
||||
" Only define the function once
|
||||
if exists("*GetKynIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
function GetKynIndent()
|
||||
" Get the line number of the current line
|
||||
let lnum = v:lnum
|
||||
|
||||
" Get the current line
|
||||
let cline = getline(lnum)
|
||||
|
||||
" If the current line has a '}', decrease indent
|
||||
if cline =~ '^\s*}'
|
||||
let lnum = prevnonblank(lnum - 1)
|
||||
return indent(lnum)
|
||||
endif
|
||||
|
||||
" Find the previous non-blank line
|
||||
let lnum = prevnonblank(lnum - 1)
|
||||
|
||||
" At the start of the file, no indent
|
||||
if lnum == 0
|
||||
return 0
|
||||
endif
|
||||
|
||||
" Get the indent of the previous line
|
||||
let prev_indent = indent(lnum)
|
||||
let prev_line = getline(lnum)
|
||||
|
||||
" If the previous line ends with '{', increase indent
|
||||
if prev_line =~ '{\s*$'
|
||||
return prev_indent + &shiftwidth
|
||||
endif
|
||||
|
||||
" Otherwise, keep the same indent
|
||||
return prev_indent
|
||||
endfunction
|
||||
@@ -39,7 +39,7 @@ Value handleListGet(const Value& subject, const std::vector<Value>& args) {
|
||||
return Value();
|
||||
}
|
||||
Value accessor = args[0];
|
||||
if (accessor.valtype == ValueType::String && accessor.string_val == "size") {
|
||||
if (accessor.valtype == ValueType::Identifier && accessor.string_val == "size") {
|
||||
return Value((long long)subject.list.size());
|
||||
}
|
||||
if (accessor.valtype != ValueType::Int) {
|
||||
|
||||
@@ -39,7 +39,7 @@ Value handleStringGet(const Value& subject, const std::vector<Value>& args) {
|
||||
}
|
||||
Value accessor = args[0];
|
||||
if (accessor.valtype != ValueType::Int) {
|
||||
if (accessor.valtype == ValueType::String && accessor.string_val == "size") {
|
||||
if (accessor.valtype == ValueType::Identifier && accessor.string_val == "size") {
|
||||
return Value((long long)subject.string_val.length());
|
||||
}
|
||||
error("String accessor must be an integer or \"size\"");
|
||||
|
||||
@@ -45,11 +45,7 @@ Value execute(Instruction inst) {
|
||||
return modules::assert(inst.args);
|
||||
}
|
||||
|
||||
// For all other instructions, evaluate the arguments first
|
||||
for(auto& arg : inst.args) {
|
||||
arg = evaluate(arg);
|
||||
}
|
||||
|
||||
// Handle variable operations that require unevaluated arguments
|
||||
if (inst.instruction == InstructionType::Variable) {
|
||||
auto& args = inst.args;
|
||||
|
||||
@@ -123,8 +119,6 @@ Value execute(Instruction inst) {
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Indexed assignment: $var index = value
|
||||
if (args.size() == 4 && args[2].valtype == ValueType::Identifier && args[2].string_val == "=") {
|
||||
std::string var_name;
|
||||
@@ -172,14 +166,23 @@ Value execute(Instruction inst) {
|
||||
data::modifyValue(var_name, new_val);
|
||||
return Value();
|
||||
}
|
||||
|
||||
// Variable access or indexed get
|
||||
// If args[0] is an Identifier and there are no args, it's a variable access.
|
||||
if (args[0].valtype == ValueType::Identifier && args.empty()) {
|
||||
return data::getValue(args[0].string_val);
|
||||
}
|
||||
|
||||
Value subject = evaluate(args[0]);
|
||||
// For all other instructions, evaluate the arguments first
|
||||
for(auto& arg : inst.args) {
|
||||
arg = evaluate(arg);
|
||||
}
|
||||
|
||||
if (inst.instruction == InstructionType::Variable) {
|
||||
// This part handles variable access and member/method access on evaluated arguments
|
||||
auto& args = inst.args;
|
||||
|
||||
if (args.empty()) {
|
||||
error("Empty variable instruction after evaluation");
|
||||
return Value();
|
||||
}
|
||||
|
||||
Value subject = args[0]; // First arg is already evaluated
|
||||
std::vector<Value> op_args(args.begin() + 1, args.end());
|
||||
|
||||
if (op_args.empty()) {
|
||||
@@ -195,8 +198,8 @@ Value execute(Instruction inst) {
|
||||
if (op_args.empty()) {
|
||||
return subject;
|
||||
}
|
||||
if (op_args[0].valtype != ValueType::Identifier) {
|
||||
error("Struct member name must be an identifier.");
|
||||
if (op_args[0].valtype != ValueType::Identifier && op_args[0].valtype != ValueType::String) {
|
||||
error("Struct member name must be an identifier or string.");
|
||||
return Value();
|
||||
}
|
||||
std::string member_name = op_args[0].string_val;
|
||||
@@ -218,7 +221,7 @@ Value execute(Instruction inst) {
|
||||
data::pushScope();
|
||||
data::scopes.back()["self"] = subject;
|
||||
for (size_t i = 0; i < func.arg_names.size(); ++i) {
|
||||
data::scopes.back()[func.arg_names[i]] = evaluate(func_args[i]);
|
||||
data::scopes.back()[func.arg_names[i]] = func_args[i];
|
||||
}
|
||||
Value return_val;
|
||||
for (const auto& body_inst : func.body) {
|
||||
|
||||
Reference in New Issue
Block a user