Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cumulative updates from flat_alloc branch #382

Merged
merged 14 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Obsidian_Runtime/src/main/yul_templates/object.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ object "{{creationObject}}" {
if iszero(lt(calldatasize(), 4)) {
{{#dispatch}}
{{! TODO 224 is a magic number offset to shift to follow the spec above; check that it's right }}
let this := address()
let selector := shr(224, calldataload(0))
{{dispatchCase}}
{{/dispatch}}
Expand All @@ -63,14 +64,14 @@ object "{{creationObject}}" {
}

function allocate_unbounded() -> memPtr {
memPtr := mload(64)
memPtr := mload(0x40)
}

function finalize_allocation(memPtr, size) {
let newFreePtr := add(memPtr, round_up_to_mul_of_32(size))
// protect against overflow
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
mstore(64, newFreePtr)
mstore(0x40, newFreePtr)
}

function panic_error_0x41() {
Expand Down
2 changes: 1 addition & 1 deletion bin/run_any_yul.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ TOP=$(echo "$output" | grep -n "Pretty printed source:" | cut -f1 -d:)
BOT=$(echo "$output" | grep -n "Binary representation:" | cut -f1 -d:)
TOP=$((TOP+1)) # drop the line with the name
BOT=$((BOT-2)) # drop the empty line after the binary
echo -ne "$output" | sed -n $TOP','$BOT'p' | bat -l javascript --style=plain
echo -ne "$output" | sed -n $TOP','$BOT'p' | bat -l javascript --style=plain -P

TOP=$(echo "$output" | grep -n "Binary representation" | cut -f1 -d:)
BOT=$(echo "$output" | grep -n "Text representation" | cut -f1 -d:)
Expand Down
110 changes: 110 additions & 0 deletions resources/tests/GanacheTests/LinkedList.obs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
asset contract NodeMaybe {
state NodeNone {}
state NodeSome {
IntNode@Shared node;
}

NodeMaybe@NodeSome(IntNode@Shared node) {
->NodeSome(node = node);
}

NodeMaybe@NodeNone() {
->NodeNone;
}


transaction getNode(NodeMaybe@NodeSome this) returns IntNode@Unowned
{
return node;
}

transaction getValue(NodeMaybe@NodeSome this) returns int {
return node.getValue();
}
}


asset contract IntNode {
int elem;
NodeMaybe@Owned next;

IntNode@Owned(int elem, NodeMaybe@Owned next) {
this.elem = elem;
this.next = next;
}

transaction length(IntNode@Unowned this) returns int {
int i = 1;
switch next {
case NodeSome {
i = i + next.getNode().length();
}
}
return i;
}

transaction append(int new_elem) {
switch next {
case NodeSome {
next.getNode().append(new_elem);
}

case NodeNone {
next = new NodeMaybe(new IntNode(new_elem, new NodeMaybe()));
}
}
}
}

asset contract IntList {

NodeMaybe first;

IntList() {
first = new NodeMaybe();
}

transaction length() returns int {
int i = 0;
switch first {
case NodeSome {
i = first.getNode().length();
}
}
return i;
}

transaction append(int elem) {
switch first {
case NodeSome {
first.getNode().append(elem);
}
case NodeNone {
first = new NodeMaybe(new IntNode(elem, new NodeMaybe()));
}
}
}


/* assume that elements appear at most once */
transaction delete(int target) {
return; // TODO
}
}


main contract UsesLinkedList {

IntList ll;

transaction main() returns int {
ll = new IntList();
ll.append(1);
ll.append(2);
ll.append(3);
ll.append(4);
ll.append(5);
ll.delete(3);
return(ll.length());
}
}
3 changes: 1 addition & 2 deletions src/main/scala/edu/cmu/cs/obsidian/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package edu.cmu.cs.obsidian
import java.io.{File, FileInputStream}
import java.nio.file.{Files, Path, Paths, StandardCopyOption}
import java.util.Scanner

import org.apache.commons.io.FileUtils

import scala.collection.mutable.HashSet
Expand Down Expand Up @@ -252,7 +251,7 @@ object Main {

val checker = new Checker(transformedTable, options.typeCheckerDebug)
val (typecheckingErrors, checkedTable) = checker.checkProgram()

val allSortedErrors = (duplicateErrors ++ importErrors ++ transformErrors ++ typecheckingErrors).sorted

if (!allSortedErrors.isEmpty) {
Expand Down
Loading