summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2020-09-08 11:31:46 +0200
committernsensfel <SpamShield0@noot-noot.org>2020-09-08 11:31:46 +0200
commit51cd83bf0dcf2e147d7b14e755a96133eaa9c767 (patch)
tree5aa289eac55455e7aff66b2f5f14212925df81b7
parente7e5ec29417559a155c6f79e1bbeed77a9fe1ff3 (diff)
It compiles, but doesn't work properly.
Structure initialization can't work with this: if it was initialized as an int then used later as a struct, none of the struct's fields are there, so writting to them is not doable. There might be a way, using `remove` and `initialize` to refresh the register at every use. This would kill the side-channel attack used to pass parameters, and so special care would have to be taken for them.
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/Compiler.java2
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/util/registers/RegisterContext.java35
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/util/registers/RegisterManager.java4
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/util/registers/StackableRegisterContext.java16
-rw-r--r--src/core/src/tonkadur/wyrd/v1/lang/Register.java67
5 files changed, 60 insertions, 64 deletions
diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/Compiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/Compiler.java
index 3b57ff3..4dc56d6 100644
--- a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/Compiler.java
+++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/Compiler.java
@@ -107,8 +107,6 @@ public class Compiler
t = TypeCompiler.compile(this, variable.get_type());
r = registers.register(t, variable.get_name());
-
- r.set_is_in_use(true);
}
this.assembler().handle_adding_instruction
diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/registers/RegisterContext.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/registers/RegisterContext.java
index c0d70a3..24ec2eb 100644
--- a/src/core/src/tonkadur/wyrd/v1/compiler/util/registers/RegisterContext.java
+++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/registers/RegisterContext.java
@@ -23,7 +23,7 @@ class RegisterContext
protected final Map<String, Register> register_by_name;
protected final Map<String, Register> aliased_registers;
protected final Deque<Collection<String>> hierarchical_aliases;
- protected final Map<Type, List<Register>> anonymous_register_by_type;
+ protected final List<Register> anonymous_registers;
protected final String name_prefix;
protected int generated_registers;
@@ -34,7 +34,7 @@ class RegisterContext
register_by_name = new HashMap<String, Register>();
aliased_registers = new HashMap<String, Register>();
hierarchical_aliases = new ArrayDeque<Collection<String>>();
- anonymous_register_by_type = new HashMap<Type, List<Register>>();
+ anonymous_registers = new ArrayList<Register>();
name_prefix = default_name_prefix;
generated_registers = 0;
@@ -46,7 +46,7 @@ class RegisterContext
register_by_name = new HashMap<String, Register>();
aliased_registers = new HashMap<String, Register>();
- anonymous_register_by_type = new HashMap<Type, List<Register>>();
+ anonymous_registers = new ArrayList<Register>();
hierarchical_aliases = new ArrayDeque<Collection<String>>();
this.name_prefix = name_prefix;
@@ -71,22 +71,12 @@ class RegisterContext
{
final String name;
final Register result;
- List<Register> list;
- list = anonymous_register_by_type.get(t);
-
- if (list == null)
- {
- list = new ArrayList<Register>();
-
- anonymous_register_by_type.put(t, list);
- }
-
- for (final Register r: list)
+ for (final Register r: anonymous_registers)
{
- if (!r.get_is_in_use())
+ if (!r.is_active())
{
- r.set_is_in_use(true);
+ r.activate(t);
return r;
}
@@ -96,9 +86,7 @@ class RegisterContext
result = create_register(t, name, initialize_holder);
- result.set_is_in_use(true);
-
- list.add(result);
+ anonymous_registers.add(result);
register_by_name.put(name, result);
@@ -128,8 +116,6 @@ class RegisterContext
register_by_name.put(name, result);
- result.set_is_in_use(true);
-
return result;
}
@@ -158,7 +144,9 @@ class RegisterContext
public void unbind (final String name)
{
release(aliased_registers.get(name));
+
aliased_registers.remove(name);
+
if (!hierarchical_aliases.isEmpty())
{
hierarchical_aliases.peekFirst().remove(name);
@@ -199,7 +187,7 @@ class RegisterContext
public void release (final Register r)
{
- r.set_is_in_use(false);
+ r.deactivate();
}
protected Register create_register
@@ -211,7 +199,8 @@ class RegisterContext
{
final Register result;
- result = new Register(t, name);
+ result = new Register(name);
+ result.activate(t);
initialize_holder.add(new Initialize(result.get_address(), t));
diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/registers/RegisterManager.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/registers/RegisterManager.java
index 07ea1ac..da5b063 100644
--- a/src/core/src/tonkadur/wyrd/v1/compiler/util/registers/RegisterManager.java
+++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/registers/RegisterManager.java
@@ -335,7 +335,7 @@ public class RegisterManager
for (final Register r: used_registers)
{
/* Side-channel attack to pass parameters, because it's convenient. */
- r.set_is_in_use(false);
+ r.deactivate();
}
return result;
@@ -363,7 +363,7 @@ public class RegisterManager
for (final Register r: used_registers)
{
/* Side-channel attack to pass parameters, because it's convenient. */
- r.set_is_in_use(false);
+ r.deactivate();
}
return result;
diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/registers/StackableRegisterContext.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/registers/StackableRegisterContext.java
index 8731d8c..5f38107 100644
--- a/src/core/src/tonkadur/wyrd/v1/compiler/util/registers/StackableRegisterContext.java
+++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/registers/StackableRegisterContext.java
@@ -102,20 +102,10 @@ class StackableRegisterContext extends RegisterContext
);
}
- context_structure.get_fields().put(name, t);
+ context_structure.get_fields().put(name, Type.INT);
- result =
- new Register
- (
- new RelativeAddress
- (
- current_context_address,
- new Constant(Type.STRING, name),
- t
- ),
- t,
- name
- );
+ result = new Register(current_context_address, name);
+ result.activate(t);
/* No need for this: it's part of the type. */
//initialize_holder.add(new Initialize(result.get_address(), t));
diff --git a/src/core/src/tonkadur/wyrd/v1/lang/Register.java b/src/core/src/tonkadur/wyrd/v1/lang/Register.java
index cefe711..7d87c21 100644
--- a/src/core/src/tonkadur/wyrd/v1/lang/Register.java
+++ b/src/core/src/tonkadur/wyrd/v1/lang/Register.java
@@ -4,46 +4,42 @@ import tonkadur.wyrd.v1.lang.type.Type;
import tonkadur.wyrd.v1.lang.computation.Constant;
import tonkadur.wyrd.v1.lang.computation.Address;
+import tonkadur.wyrd.v1.lang.computation.RelativeAddress;
import tonkadur.wyrd.v1.lang.computation.ValueOf;
import tonkadur.wyrd.v1.lang.meta.Computation;
public class Register
{
- protected final Type type;
protected final String name;
- protected final Address address;
- protected final Computation value;
- protected boolean is_in_use;
+ protected final Address address_prefix;
+ protected Address address;
+ protected Computation value;
+ protected Type current_type;
- public Register (final Type type, final String name)
+ public Register (final String name)
{
this.name = name;
- this.type = type;
- address = new Address(new Constant(Type.STRING, name), type);
- value = new ValueOf(address);
- is_in_use = false;
+ address_prefix = null;
+ address = null;
+ value = null;
+ current_type = Type.INT;
}
- public Register
- (
- final Address address,
- final Type type,
- final String name
- )
+ public Register (final Address address_prefix, final String name)
{
- this.address = address;
+ this.address_prefix = address_prefix;
this.name = name;
- this.type = type;
- value = new ValueOf(address);
- is_in_use = false;
+ address = null;
+ value = null;
+ current_type = Type.INT;
}
public Type get_type ()
{
- return type;
+ return current_type;
}
public String get_name ()
@@ -61,13 +57,36 @@ public class Register
return value;
}
- public boolean get_is_in_use ()
+ public boolean is_active ()
+ {
+ return (address != null);
+ }
+
+ public void activate (final Type type)
{
- return is_in_use;
+ this.current_type = type;
+
+ if (address_prefix == null)
+ {
+ address = new Address(new Constant(Type.STRING, name), type);
+ }
+ else
+ {
+ address =
+ new RelativeAddress
+ (
+ address_prefix,
+ new Constant(Type.STRING, name),
+ type
+ );
+ }
+
+ value = new ValueOf(address);
}
- public void set_is_in_use (final boolean val)
+ public void deactivate ()
{
- is_in_use = val;
+ address = null;
+ value = null;
}
}