Selaa lähdekoodia

"mutable" keyword added right before a function to allow for functions
that can be written to after compilation

Yentl Van Tendeloo 8 vuotta sitten
vanhempi
commit
d3f2abd615

+ 1 - 1
bootstrap/initial_code_user.alb

@@ -1,7 +1,7 @@
 include "bootstrap/primitives.alc"
 include "user_interface.alh"
 
-Void function __main():
+Void mutable function __main():
 	Element root
 	root = read_root()
 	root = root["__hierarchy"]["objects"]

+ 1 - 1
bootstrap/user_interface.alc

@@ -5,7 +5,7 @@ include "compilation_manager.alh"
 include "constructors.alh"
 include "modelling.alh"
 
-Void function new_user():
+Void mutable function new_user():
 	Integer interface
 	while (True):
 		interface = input()

+ 2 - 1
interface/HUTN/grammars/actionlanguage.g

@@ -106,7 +106,7 @@ grammar{
 
     func_body: block;
 
-    funcdecl: func_type FUNCTION func_name LPAREN (parameter (COMMA parameter)*)? RPAREN ((COLON newline func_body) | (ASSIGN QUESTIONMARK ANYTHING newline))?;
+    funcdecl: func_type MUTABLE? FUNCTION func_name LPAREN (parameter (COMMA parameter)*)? RPAREN ((COLON newline func_body) | (ASSIGN QUESTIONMARK ANYTHING newline))?;
 
     func_type: type_specifier | void;
 
@@ -206,5 +206,6 @@ grammar{
         COMM: '[\t]*//[^\n]*';
         ID: '[a-zA-Z_][a-zA-Z_0-9.]*';
         ANYTHING: '[a-zA-Z_0-9/.]+';
+        MUTABLE : 'mutable';
     }
 }

+ 5 - 1
interface/HUTN/hutn_compiler/constructors_visitor.py

@@ -225,7 +225,11 @@ class ConstructorsVisitor(Visitor):
         if func_body:
             if symbol.name in ["input", "output"]:
                 return False
-            self.add_constructors("funcdef", symbol.node,
+            if tree.get_children("MUTABLE"):
+                self.add_constructors("mutable_funcdef")
+            else:
+                self.add_constructors("funcdef")
+            self.add_constructors(symbol.node,
                                   len(symbol.params))
             for p in tree.get_children("parameter"):
                 self.visit(p)

+ 2 - 0
interface/HUTN/hutn_compiler/primitives_visitor.py

@@ -378,6 +378,8 @@ class PrimitivesVisitor(Visitor):
                     # Add the name in case we want to pre-compile in the MvK
                     self.dict(n, "name", self.value(string.ascii_lowercase[i]))
             b = self.get_primitive(func_body)
+            if tree.get_children("MUTABLE"):
+                self.dict(vf, "mutable", self.node())
             self.dict(vf, "body", b)
         else:
             # TODO: fix funcdecl special case: "X function f(...) = ..."