فهرست منبع

Merge remote-tracking branch 'yentl/yentl' into jit

jonathanvdc 8 سال پیش
والد
کامیت
8c295d6732

BIN
bootstrap/bootstrap.m.gz


+ 14 - 4
bootstrap/constructors.alc

@@ -14,7 +14,9 @@ Action function construct_top():
 		if (command == "global"):
 			return construct_global()!
 		elif (command == "funcdef"):
-			return construct_top_funcdef()!
+			return construct_top_funcdef(False)!
+		elif (command == "mutable_funcdef"):
+			return construct_top_funcdef(True)!
 		else:
 			log("ERROR: did not understand command " + cast_e2s(command))
 
@@ -58,7 +60,7 @@ Action function construct_global():
 		dict_add(assign, "next", construct_top())
 	return this_element!
 
-Action function construct_top_funcdef():
+Action function construct_top_funcdef(mutable : Boolean):
 	Action assign
 	Action resolve
 	Action constant
@@ -87,6 +89,9 @@ Action function construct_top_funcdef():
 	dict_add(constant, "node", func)
 	dict_add(func, "params", params)
 
+	if (mutable):
+		dict_add(func, "mutable", create_node())
+
 	Integer nrParams
 	nrParams = input()
 	Integer counter
@@ -308,12 +313,14 @@ Action function construct_function():
 	Element param
 	Element params
 	String arg_names_decl
+	String inp
 
 	variable_map = create_node()
 
-	while (value_neq(input(), "funcdef")):
+	inp = input()
+	while (bool_and(inp != "funcdef", inp != "mutable_funcdef")):
 		// We skip over everything that is not a funcdef, as these are all just definitions of global stuff
-		log("Skip over input!")
+		inp = input()
 
 	// Consume the name
 	input()
@@ -325,6 +332,9 @@ Action function construct_function():
 	arg_names_decl = "abcdefghijklmnopqrstuvwxyz"
 	dict_add(func, "params", params)
 
+	if (inp == "mutable_funcdef"):
+		dict_add(func, "mutable", create_node())
+
 	while (counter < nrParams):
 		param = create_node()
 		dict_add(params, string_get(arg_names_decl, counter), param)

+ 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 - 2
interface/HUTN/hutn_compiler/declare_functions_visitor.py

@@ -13,7 +13,7 @@ class DeclareFunctionsVisitor(Visitor):
     def compute_parameter_types(self, tree):
         parameter_types = []
         for parameter in tree.get_children('parameter'):
-            type_specifier = parameter.get_tail()[2].get_text()
+            type_specifier = parameter.get_children("type_specifier")[0].get_text()
             parameter_types.append(types_mv.string_to_type(type_specifier))
         return parameter_types
 
@@ -23,7 +23,7 @@ class DeclareFunctionsVisitor(Visitor):
         return func_type
 
     def visit_funcdecl(self, tree):
-        func_name = tree.get_tail()[2].get_text()
+        func_name = tree.get_children("func_name")[0].get_text()
         func_type = self.compute_func_type(tree)
         parameter_types = self.compute_parameter_types(tree)
         self.set_type(tree, func_type)

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

@@ -378,6 +378,10 @@ 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(...) = ..."

+ 1 - 0
scripts/compile.py

@@ -3,6 +3,7 @@ import os
 import urllib2
 import urllib
 import subprocess
+import time
 
 def do_compile(address, filename, username, modulename, mode, optionals=['--debug'], grammar=""):
     filename = os.path.realpath(filename)