[Fix] 修复struct内部函数无法访问内部成员的问题

[Feat] 拓展构建
This commit is contained in:
2025-12-23 01:37:46 +08:00
parent 6226059adc
commit 660cca2579
6 changed files with 83 additions and 71 deletions

46
fig-vscode/LICENSE Normal file
View File

@@ -0,0 +1,46 @@
MIT License (Fig)
Copyright (c) 2025 PuqiAR <im@puqiar.top>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
1. The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
2. This project includes code from the following projects with their respective licenses:
- argparse (MIT License)
Copyright (c) 2018 Pranav Srinivas Kumar <pranav.srinivas.kumar@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- magic_enum (MIT License)
Copyright (c) 2019 - 2024 Daniil Goncharov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,71 +1,3 @@
# fig-vscode README
This is the README for your extension "fig-vscode". After writing up a brief description, we recommend including the following sections.
## Features
Describe specific features of your extension including screenshots of your extension in action. Image paths are relative to this README file.
For example if there is an image subfolder under your extension project workspace:
\!\[feature X\]\(images/feature-x.png\)
> Tip: Many popular extensions utilize animations. This is an excellent way to show off your extension! We recommend short, focused animations that are easy to follow.
## Requirements
If you have any requirements or dependencies, add a section describing those and how to install and configure them.
## Extension Settings
Include if your extension adds any VS Code settings through the `contributes.configuration` extension point.
For example:
This extension contributes the following settings:
* `myExtension.enable`: Enable/disable this extension.
* `myExtension.thing`: Set to `blah` to do something.
## Known Issues
Calling out known issues can help limit users opening duplicate issues against your extension.
## Release Notes
Users appreciate release notes as you update your extension.
### 1.0.0
Initial release of ...
### 1.0.1
Fixed issue #.
### 1.1.0
Added features X, Y, and Z.
---
## Following extension guidelines
Ensure that you've read through the extensions guidelines and follow the best practices for creating your extension.
* [Extension Guidelines](https://code.visualstudio.com/api/references/extension-guidelines)
## Working with Markdown
You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts:
* Split the editor (`Cmd+\` on macOS or `Ctrl+\` on Windows and Linux).
* Toggle preview (`Shift+Cmd+V` on macOS or `Shift+Ctrl+V` on Windows and Linux).
* Press `Ctrl+Space` (Windows, Linux, macOS) to see a list of Markdown snippets.
## For more information
* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown)
* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/)
**Enjoy!**
Fuck.

View File

@@ -3,12 +3,16 @@
"displayName": "Fig Language",
"description": "VSCode extension for Fig language with syntax highlighting",
"version": "0.0.1",
"publisher": "PuqiAR",
"engines": {
"vscode": "^1.90.0"
},
"categories": [
"Programming Languages"
],
"repository": {
"url":"https://github.com/PuqiAR/Fig"
},
"activationEvents": [],
"main": "./out/extension.js",
"contributes": {

View File

@@ -56,6 +56,11 @@ namespace Fig
structTypeNames.insert(c.structTypeNames.begin(), c.structTypeNames.end());
}
std::unordered_map<size_t, Function> getFunctions() const
{
return functions;
}
std::optional<ObjectPtr> get(const FString &name)
{
auto it = variables.find(name);
@@ -125,6 +130,21 @@ namespace Fig
throw RuntimeError(FStringView(std::format("Variable '{}' not defined", name.toBasicString())));
}
}
void _update(const FString &name, const Object &value)
{
if (variables.contains(name))
{
variables[name] = std::make_shared<Object>(value);
}
else if (parent != nullptr)
{
parent->set(name, value);
}
else
{
throw RuntimeError(FStringView(std::format("Variable '{}' not defined", name.toBasicString())));
}
}
void def(const FString &name, const TypeInfo &ti, AccessModifier am, const ObjectPtr &value = Object::getNullInstance())
{
if (containsInThisScope(name))

View File

@@ -456,6 +456,12 @@ namespace Fig
}
}
instanceCtx->merge(*structT.defContext);
for (auto &[id, fn] : instanceCtx->getFunctions())
{
instanceCtx->_update(*instanceCtx->getFunctionName(id), Object(
Function(fn.paras, fn.retType, fn.body, instanceCtx) // change its closureContext to struct instance's context
));
}
return std::make_shared<Object>(StructInstance(structT.id, instanceCtx));
}
default:
@@ -542,7 +548,7 @@ namespace Fig
};
case AstType::FunctionDefSt: {
auto fnDef = std::dynamic_pointer_cast<Ast::FunctionDefSt>(stmt);
if (currentContext->contains(fnDef->name))
if (currentContext->containsInThisScope(fnDef->name))
{
static constexpr char RedeclarationErrorName[] = "RedeclarationError";
throw EvaluatorError<RedeclarationErrorName>(FStringView(std::format("Function '{}' already defined in this scope", fnDef->name.toBasicString())), currentAddressInfo);

View File

@@ -1,10 +1,14 @@
struct test
{
bar:String = "1233";
func foo()
{
__fstdout_println("666");
__fstdout_println(bar);
}
}
var x := test{};
x.foo();
x.bar = "555";
x.foo();