Skip to content

Commit

Permalink
Merge pull request ValeLang#610 from Verdagon/regionsmerge8
Browse files Browse the repository at this point in the history
Merging in regions branch's instantiator stage
  • Loading branch information
Verdagon authored Jul 11, 2023
2 parents 86e5337 + dce4494 commit 3bb8080
Show file tree
Hide file tree
Showing 167 changed files with 9,013 additions and 2,721 deletions.
6 changes: 6 additions & 0 deletions Frontend/Builtins/src/dev/vale/Builtins.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ object Builtins {
"drop" -> "drop.vale",
"clone" -> "clone.vale",
"arrays" -> "arrays.vale",
"runtime_sized_array_mut_new" -> "runtime_sized_array_mut_new.vale",
"runtime_sized_array_push" -> "runtime_sized_array_push.vale",
"runtime_sized_array_pop" -> "runtime_sized_array_pop.vale",
"runtime_sized_array_len" -> "runtime_sized_array_len.vale",
"mainargs" -> "mainargs.vale",
"as" -> "as.vale",
"print" -> "print.vale",
"tup" -> "tup.vale",
"streq" -> "streq.vale",
"panic" -> "panic.vale",
"panicutils" -> "panicutils.vale",
"opt" -> "opt.vale",
"result" -> "result.vale",
"sameinstance" -> "sameinstance.vale",
Expand Down
3 changes: 3 additions & 0 deletions Frontend/Builtins/src/dev/vale/resources/arith.vale
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ extern func castFloatI32(x float) int;

extern func TruncateI64ToI32(x i64) int;

func i64(x int) i64 { __vbi_ExtendI32ToI64(x) }
extern func __vbi_ExtendI32ToI64(x int) i64;

func -(x int) int { return __vbi_negateI32(x); }
extern func __vbi_negateI32(x int) int;

Expand Down
18 changes: 4 additions & 14 deletions Frontend/Builtins/src/dev/vale/resources/arrays.vale
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import v.builtins.arith.*;
import v.builtins.drop.*;
import v.builtins.panic.*;
import v.builtins.runtime_sized_array_mut_new.*;
import v.builtins.runtime_sized_array_push.*;
import v.builtins.runtime_sized_array_pop.*;
import v.builtins.runtime_sized_array_len.*;

func drop_into<V Variability, S Int, E, F>(arr [#S]<imm, V>E, consumer &F) void
where func(&F, E)void
Expand Down Expand Up @@ -47,23 +51,9 @@ where func drop(E)void {
extern("vale_static_sized_array_len")
func len<M Mutability, V Variability, S Int, E>(arr &[#S]<M Mutability, V>E) int;

extern("vale_runtime_sized_array_len")
func len<M Mutability, E>(arr &[]<M>E) int;


extern("vale_runtime_sized_array_capacity")
func capacity<E>(arr &[]<mut>E) int;

extern("vale_runtime_sized_array_push")
func push<E>(arr &[]<mut>E, newElement E) void;

extern("vale_runtime_sized_array_pop")
func pop<E>(arr &[]<mut>E) E;

extern("vale_runtime_sized_array_mut_new")
func Array<M Mutability, E Ref>(size int) []<M>E
where M = mut;

func Array<M Mutability, E, G>(n int, generator G) []<M>E
where
M Mutability = mut,
Expand Down
2 changes: 1 addition & 1 deletion Frontend/Builtins/src/dev/vale/resources/opt.vale
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import v.builtins.panic.*;
import v.builtins.panicutils.*;
import v.builtins.drop.*;

#!DeriveInterfaceDrop
Expand Down
13 changes: 0 additions & 13 deletions Frontend/Builtins/src/dev/vale/resources/panic.vale
Original file line number Diff line number Diff line change
@@ -1,14 +1 @@
import v.builtins.print.*;
import v.builtins.str.*;

func panic() __Never {
return __vbi_panic();
}

func panic(msg str) __Never {
print(msg);
print("\n");
return __vbi_panic();
}

extern func __vbi_panic() __Never;
13 changes: 13 additions & 0 deletions Frontend/Builtins/src/dev/vale/resources/panicutils.vale
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import v.builtins.print.*;
import v.builtins.str.*;
import v.builtins.panic.*;

func panic() __Never {
return __vbi_panic();
}

func panic(msg str) __Never {
print(msg);
print("\n");
return __vbi_panic();
}
2 changes: 1 addition & 1 deletion Frontend/Builtins/src/dev/vale/resources/result.vale
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import v.builtins.panic.*;
import v.builtins.panicutils.*;
import v.builtins.logic.*;

#!DeriveInterfaceDrop
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extern("vale_runtime_sized_array_len")
func len<M Mutability, E>(arr &[]<M>E) int;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extern("vale_runtime_sized_array_mut_new")
func Array<M Mutability, E Ref>(size int) []<M>E
where M = mut;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extern("vale_runtime_sized_array_pop")
func pop<E>(arr &[]<mut>E) E;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extern("vale_runtime_sized_array_push")
func push<E>(arr &[]<mut>E, newElement E) void;
9 changes: 0 additions & 9 deletions Frontend/Builtins/src/dev/vale/resources/str.vale
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ extern func substring(
end int)
str;

extern func streq(
aContainerStr str,
aBegin int,
aEnd int,
bContainerStr str,
bBegin int,
bEnd int)
bool;

extern func strcmp(
aContainerStr str,
aBegin int,
Expand Down
9 changes: 9 additions & 0 deletions Frontend/Builtins/src/dev/vale/resources/streq.vale
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

extern func streq(
aContainerStr str,
aBegin int,
aEnd int,
bContainerStr str,
bBegin int,
bEnd int)
bool;
37 changes: 0 additions & 37 deletions Frontend/FinalAST/src/dev/vale/finalast/MetalPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,3 @@ package dev.vale.finalast

import dev.vale.von.{IVonData, VonPrinter, VonSyntax}

//object MetalPrinter {
// def print(data: IVonData): String = {
// val nameMap =
// Map(
// "Str" -> "s",
// "Int" -> "i",
// "Float" -> "f",
//// "Void" -> "v",
// "Bool" -> "b",
// "Function" -> "F",
// "Ref" -> "R",
// "Share" -> "@",
// "Pointer" -> "*",
// "Weak" -> "&&",
// "Own" -> "^",
// "Readonly" -> "#",
// "Readwrite" -> "!",
// "Inline" -> "<",
// "Yonder" -> ">",
// "CoordTemplata" -> "TR",
// "KindTemplata" -> "TK",
// "CitizenName" -> "C",
// "CoordListTemplata" -> "TRL",
// "CitizenTemplateName" -> "CT",
// "InterfaceTemplateName" -> "CT",
// "StructTemplateName" -> "CT",
// "Immutable" -> "imm",
// "MutabilityTemplata" -> "TM",
// "StructId" -> "SId",
// "InterfaceId" -> "IId",
// "AnonymousSubstructName" -> "AS",
// "LambdaCitizenName" -> "LC",
// )
// val printer = new VonPrinter(VonSyntax(false, true, false, false), Int.MaxValue, nameMap, false);
// printer.print(data)
// }
//}
41 changes: 22 additions & 19 deletions Frontend/FinalAST/src/dev/vale/finalast/ast.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ object ProgramH {
val externRegionName = "host"
}

case class RegionH(
name: String,
kinds: Vector[KindHT]) { val hash = runtime.ScalaRunTime._hashCode(this); override def hashCode(): Int = hash; override def equals(obj: Any): Boolean = vcurious(); }
case class RegionH() { val hash = runtime.ScalaRunTime._hashCode(this); override def hashCode(): Int = hash; override def equals(obj: Any): Boolean = vcurious(); }

case class Export(
nameH: IdH,
Expand Down Expand Up @@ -64,7 +62,7 @@ case class PackageH(
val matches =
(Vector.empty ++
exportNameToFunction.find(_._1.str == readableName).map(_._2).toVector ++
functions.filter(_.prototype.fullName.localName == readableName).map(_.prototype))
functions.filter(_.prototype.id.localName == readableName).map(_.prototype))
.distinct
vassert(matches.nonEmpty)
vassert(matches.size <= 1)
Expand All @@ -74,15 +72,15 @@ case class PackageH(
// Convenience function for the tests to look up a struct.
// Struct must be at the top level of the program.
def lookupStruct(humanName: String) = {
val matches = structs.filter(_.fullName.localName == humanName)
val matches = structs.filter(_.id.localName == humanName)
vassert(matches.size == 1)
matches.head
}

// Convenience function for the tests to look up an interface.
// Interface must be at the top level of the program.
def lookupInterface(humanName: String) = {
val matches = interfaces.filter(_.fullName.shortenedName == humanName)
val matches = interfaces.filter(_.id.shortenedName == humanName)
vassert(matches.size == 1)
matches.head
}
Expand All @@ -97,22 +95,22 @@ case class ProgramH(
vassertSome(packages.get(packageCoordinate))
}
def lookupFunction(prototype: PrototypeH): FunctionH = {
val paackage = lookupPackage(prototype.fullName.packageCoordinate)
val result = vassertSome(paackage.functions.find(_.fullName == prototype.fullName))
val paackage = lookupPackage(prototype.id.packageCoordinate)
val result = vassertSome(paackage.functions.find(_.fullName == prototype.id))
vassert(prototype == result.prototype)
result
}
def lookupStruct(structRefH: StructHT): StructDefinitionH = {
val paackage = lookupPackage(structRefH.fullName.packageCoordinate)
val paackage = lookupPackage(structRefH.id.packageCoordinate)
vassertSome(paackage.structs.find(_.getRef == structRefH))
}
def lookupInterface(interfaceRefH: InterfaceHT): InterfaceDefinitionH = {
val paackage = lookupPackage(interfaceRefH.fullName.packageCoordinate)
val paackage = lookupPackage(interfaceRefH.id.packageCoordinate)
vassertSome(paackage.interfaces.find(_.getRef == interfaceRefH))
}
def lookupStaticSizedArray(ssaTH: StaticSizedArrayHT): StaticSizedArrayDefinitionHT = {
val paackage = lookupPackage(ssaTH.name.packageCoordinate)
vassertSome(paackage.staticSizedArrays.find(_.name == ssaTH.name))
val paackage = lookupPackage(ssaTH.id.packageCoordinate)
vassertSome(paackage.staticSizedArrays.find(_.name == ssaTH.id))
}
def lookupRuntimeSizedArray(rsaTH: RuntimeSizedArrayHT): RuntimeSizedArrayDefinitionHT = {
val paackage = lookupPackage(rsaTH.name.packageCoordinate)
Expand All @@ -124,7 +122,7 @@ case class ProgramH(
// There is only one of these per type of struct in the program.
case class StructDefinitionH(
// Name of the struct. Guaranteed to be unique in the entire program.
fullName: IdH,
id: IdH,
// Whether we can take weak references to this object.
// On native, this means an extra "weak ref count" will be included for the object.
// On JVM/CLR/JS, this means the object will have an extra tiny object pointing
Expand All @@ -143,7 +141,7 @@ case class StructDefinitionH(
// The members of the struct, in order.
members: Vector[StructMemberH]) {
val hash = runtime.ScalaRunTime._hashCode(this); override def hashCode(): Int = hash; override def equals(obj: Any): Boolean = vcurious();
def getRef: StructHT = StructHT(fullName)
def getRef: StructHT = StructHT(id)
}

// A member of a struct.
Expand All @@ -164,7 +162,7 @@ case class StructMemberH(

// An interface definition containing name, methods, etc.
case class InterfaceDefinitionH(
fullName: IdH,
id: IdH,
// Whether we can take weak references to this interface.
// On native, this means an extra "weak ref count" will be included for the object.
// On JVM/CLR/JS, this means the object should extend the IWeakable interface,
Expand All @@ -182,7 +180,7 @@ case class InterfaceDefinitionH(
// All the methods that we can call on this interface.
methods: Vector[InterfaceMethodH]) {
val hash = runtime.ScalaRunTime._hashCode(this); override def hashCode(): Int = hash; override def equals(obj: Any): Boolean = vcurious();
def getRef = InterfaceHT(fullName)
def getRef = InterfaceHT(id)
}

// A method in an interface.
Expand Down Expand Up @@ -218,22 +216,25 @@ case class FunctionH(

// Whether this has a body. If true, the body will simply contain an InterfaceCallH instruction.
isAbstract: Boolean,
// Whether this has a body. If true, the body will simply contain an ExternCallH instruction to the same
// Whether this is an extern. If true, the body will simply contain an ExternCallH instruction to the same
// prototype describing this function.
isExtern: Boolean,

attributes: Vector[IFunctionAttributeH],

// The body of the function that contains the actual instructions.
body: ExpressionH[KindHT]) {

vpass()

val hash = runtime.ScalaRunTime._hashCode(this); override def hashCode(): Int = hash; override def equals(obj: Any): Boolean = vcurious();
def fullName = prototype.fullName
def fullName = prototype.id
def isUserFunction = attributes.contains(UserFunctionH)
}

// A wrapper around a function's name, which also has its params and return type.
case class PrototypeH(
fullName: IdH,
id: IdH,
params: Vector[CoordH[KindHT]],
returnType: CoordH[KindHT]
) { val hash = runtime.ScalaRunTime._hashCode(this); override def hashCode(): Int = hash; }
Expand All @@ -247,6 +248,8 @@ case class IdH(
shortenedName: String,
// Most precise name, without shortening.
fullyQualifiedName: String) {
vpass()

val hash = runtime.ScalaRunTime._hashCode(this); override def hashCode(): Int = hash;

override def equals(obj: Any): Boolean = {
Expand Down
Loading

0 comments on commit 3bb8080

Please sign in to comment.