feat(furas): add slice type and instruction
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
type arr = array $s8 10
|
type arr = array $s8 10
|
||||||
|
type arrSlice = slice $s8
|
||||||
|
|
||||||
func println ref $arr = native println
|
func println $arrSlice = native println
|
||||||
|
|
||||||
public func main = #main
|
public func main = #main
|
||||||
main:
|
main:
|
||||||
@@ -30,5 +31,8 @@ body:
|
|||||||
end:
|
end:
|
||||||
drop
|
drop
|
||||||
load %0
|
load %0
|
||||||
call ref $arr println
|
push $u32 0
|
||||||
|
load %1
|
||||||
|
slice
|
||||||
|
call $arrSlice println
|
||||||
ret
|
ret
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ struct token {
|
|||||||
// Instructions
|
// Instructions
|
||||||
Push,
|
Push,
|
||||||
Array,
|
Array,
|
||||||
|
Slice,
|
||||||
Get,
|
Get,
|
||||||
Set,
|
Set,
|
||||||
Drop,
|
Drop,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "furvm/function.hpp"
|
#include "furvm/function.hpp"
|
||||||
#include "furvm/fwd.hpp"
|
#include "furvm/fwd.hpp"
|
||||||
#include "furvm/instruction.hpp"
|
#include "furvm/instruction.hpp"
|
||||||
|
#include "furvm/module.hpp"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@@ -24,6 +25,7 @@ namespace {
|
|||||||
// NOLINTBEGIN
|
// NOLINTBEGIN
|
||||||
std::unordered_map<enum token::type, furvm::instruction_t> instructions = {
|
std::unordered_map<enum token::type, furvm::instruction_t> instructions = {
|
||||||
{ token::Array, furvm::instruction_t::Array },
|
{ token::Array, furvm::instruction_t::Array },
|
||||||
|
{ token::Slice, furvm::instruction_t::Slice },
|
||||||
{ token::Get, furvm::instruction_t::Get },
|
{ token::Get, furvm::instruction_t::Get },
|
||||||
{ token::Set, furvm::instruction_t::Set },
|
{ token::Set, furvm::instruction_t::Set },
|
||||||
{ token::Drop, furvm::instruction_t::Drop },
|
{ token::Drop, furvm::instruction_t::Drop },
|
||||||
@@ -77,6 +79,7 @@ const char* token_type(enum token::type type) {
|
|||||||
case token::Allocate: return "allocate";
|
case token::Allocate: return "allocate";
|
||||||
case token::Push: return "push";
|
case token::Push: return "push";
|
||||||
case token::Array: return "array";
|
case token::Array: return "array";
|
||||||
|
case token::Slice: return "slice";
|
||||||
case token::Get: return "get";
|
case token::Get: return "get";
|
||||||
case token::Set: return "set";
|
case token::Set: return "set";
|
||||||
case token::Drop: return "drop";
|
case token::Drop: return "drop";
|
||||||
@@ -160,6 +163,8 @@ struct mod_context {
|
|||||||
case furvm::mod_type::Array:
|
case furvm::mod_type::Array:
|
||||||
return lhs->value.array.size == rhs->value.array.size &&
|
return lhs->value.array.size == rhs->value.array.size &&
|
||||||
compare_types(mod.type_at(lhs->value.array.typeId), mod.type_at(rhs->value.array.typeId));
|
compare_types(mod.type_at(lhs->value.array.typeId), mod.type_at(rhs->value.array.typeId));
|
||||||
|
case furvm::mod_type::Slice:
|
||||||
|
return compare_types(mod.type_at(lhs->value.slice.typeId), mod.type_at(rhs->value.slice.typeId));
|
||||||
case furvm::mod_type::Import:
|
case furvm::mod_type::Import:
|
||||||
return lhs->value.imprt.modId == rhs->value.imprt.modId &&
|
return lhs->value.imprt.modId == rhs->value.imprt.modId &&
|
||||||
lhs->value.imprt.typeId == rhs->value.imprt.typeId;
|
lhs->value.imprt.typeId == rhs->value.imprt.typeId;
|
||||||
@@ -252,6 +257,15 @@ struct mod_context {
|
|||||||
|
|
||||||
return mod.emplace_type(inner.id(), size->value.uint);
|
return mod.emplace_type(inner.id(), size->value.uint);
|
||||||
}
|
}
|
||||||
|
case token::Slice: {
|
||||||
|
auto result = next_token(lexer);
|
||||||
|
|
||||||
|
if (!result) throw std::runtime_error("error");
|
||||||
|
|
||||||
|
auto inner = eat_type(lexer, result.value);
|
||||||
|
|
||||||
|
return mod.emplace_type(furvm::mod_type::Slice, inner.id());
|
||||||
|
}
|
||||||
default: throw std::runtime_error("error");
|
default: throw std::runtime_error("error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -463,6 +477,7 @@ struct mod_context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case token::Array:
|
case token::Array:
|
||||||
|
case token::Slice:
|
||||||
case token::Get:
|
case token::Get:
|
||||||
case token::Set:
|
case token::Set:
|
||||||
case token::Drop:
|
case token::Drop:
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ token_r lexer::next_token() {
|
|||||||
|
|
||||||
{ "push", token::Push },
|
{ "push", token::Push },
|
||||||
{ "array", token::Array },
|
{ "array", token::Array },
|
||||||
|
{ "slice", token::Slice },
|
||||||
{ "get", token::Get },
|
{ "get", token::Get },
|
||||||
{ "set", token::Set },
|
{ "set", token::Set },
|
||||||
{ "drop", token::Drop },
|
{ "drop", token::Drop },
|
||||||
|
|||||||
Reference in New Issue
Block a user