package org.metaborg.meta.lang.dynsem.interpreter.nabl2.f.nodes;

import org.metaborg.meta.lang.dynsem.interpreter.nabl2.f.Addr;
import org.metaborg.meta.lang.dynsem.interpreter.nodes.building.NativeOpBuild;
import org.metaborg.meta.lang.dynsem.interpreter.nodes.building.TermBuild;
import org.metaborg.meta.lang.dynsem.interpreter.terms.shared.ValSort;

import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.NodeChildren;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.source.SourceSection;

@NodeChildren({ @NodeChild(value = "addr", type = TermBuild.class), @NodeChild(value = "val", type = TermBuild.class) })
public abstract class SetAtAddr extends NativeOpBuild {

	public SetAtAddr(SourceSection source) {
		super(source);
	}

	// TODO: 2 cases: arrayaddr and frameaddr

	@Specialization
	public ValSort executeGet(Addr addr, ValSort val) {
		throw new IllegalStateException("Set not implemented");
	}

	public static SetAtAddr create(SourceSection source, TermBuild addr, TermBuild val) {
		return SetAtAddrNodeGen.create(source, addr, val);
	}
}

@@ -116,16 +116,96 @@
 nabl2.f.
+FrameAddr;%0Aimport org.metaborg.meta.lang.dynsem.interpreter.nabl2.f.arrays.Array
 Addr;%0Aim
@@ -359,79 +359,8 @@
 ild;
-%0Aimport org.metaborg.meta.lang.dynsem.interpreter.terms.shared.ValSort;
 %0A%0Aim
@@ -500,16 +500,145 @@
 zation;%0A
+import com.oracle.truffle.api.object.FinalLocationException;%0Aimport com.oracle.truffle.api.object.IncompatibleLocationException;%0A
 import c
@@ -926,53 +926,8 @@
 %0A%09%7D%0A
-%0A%09// TODO: 2 cases: arrayaddr and frameaddr%0A%0A
 %09@Sp
@@ -947,22 +947,21 @@
 %09public 
-ValSor
+Objec
 t execut
@@ -965,38 +965,170 @@
 cute
-Get(Addr addr, ValSort val
+FrameSet(FrameAddr addr, Object val) %7B%0A%09%09try %7B%0A%09%09%09addr.location().set(addr.frame(), val);%0A%09%09%7D catch (IncompatibleLocationException %7C FinalLocationException e
 ) %7B%0A
+%09
 %09%09th
@@ -1161,30 +1161,159 @@
 ion(
-%22Set not implemented%22)
+e);%0A%09%09%7D%0A%09%09return val;%0A%09%7D%0A%0A%09@Specialization%0A%09public Object executeArraySet(ArrayAddr addr, Object val) %7B%0A%09%09addr.arr().set(addr.idx(), val);%0A%09%09return val
 ;%0A%09%7D

Implement setting value at address for frames and arrays