Skip to content

Commit

Permalink
Compile everything with mk + plan9port rc
Browse files Browse the repository at this point in the history
test plan:
install plan9port so rc is in your PATH

then
export MKSHELL=/usr/lib/plan9/bin/rc
EXPORT PATH=~/xix/bin:$PATH
mk
  • Loading branch information
aryx committed Apr 22, 2024
1 parent e3bd833 commit 6e5ecaf
Show file tree
Hide file tree
Showing 88 changed files with 261 additions and 172 deletions.
1 change: 1 addition & 0 deletions assembler/main.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(* Copyright 2015, 2016 Yoann Padioleau, see copyright.txt *)
open Stdcompat (* for |> *)
open Common

(*****************************************************************************)
Expand Down
1 change: 1 addition & 0 deletions assembler/parse_asm5.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(* Copyright 2015, 2016 Yoann Padioleau, see copyright.txt *)
open Stdcompat (* for |> *)
open Common

module L = Location_cpp
Expand Down
1 change: 1 addition & 0 deletions assembler/resolve_labels5.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(* Copyright 2015, 2016 Yoann Padioleau, see copyright.txt *)
open Stdcompat (* for |> *)
open Common

open Ast_asm5
Expand Down
13 changes: 4 additions & 9 deletions bootstrap-mk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
# Script to compile 'mk' (and 'rc') without using 'mk' (nor 'rc') and generate
# a bin/mk (and bin/rc) so that we don't need a BOOTSTRAP/Linux/386/bin/mk
# like in kencc. Note that kencc has no BOOTSTRAP/Linux/386/bin/rc because
# it assumes the presence of a shell and can work both with 'rc' and 'sh'.
# it assumes the presence of a shell and can work with both 'rc' and 'sh'.
#
# Note that right now to boostrap Xix we still need:
# - OCaml (which itself requires to bootstrap ocamllex, ocamlyacc and C)
# - the ocamlfind tool and stdcompat library
# - a C compiler
# - /bin/sh
# - probably many other things
#
# Maybe at some point the assembler/linker/compiler in this repo will
# be able to bootstrap itself and we will just need an ocamlrun bytecode
Expand All @@ -24,16 +25,10 @@ set -x
# Limit to just stdcompat! This is Xix!
EXTERNAL_LIB=`ocamlfind query stdcompat`

#TODO? -bin-annot -absname -dtypes
# -g so we can get good backtrace
#coupling: mkconfig COMPFLAGS
OCAMLCFLAGS="-I $EXTERNAL_LIB -g"

# We need -g for good backtrace.
# We need -custom because of dllstdcompat__stubs, otherwise
# we would need to set CAML_LD_LIBRARY_PATH before running the programs.
# LATER: would be good to remove if one day we want to store
# a BOOTSTRAP/mk and we want a really portable bytecode across platforms.
# TODO? for windows under cygwin might need -custom too?
#coupling: mkconfig LINKFLAGS
EXTRALINKFLAGS="-I $EXTERNAL_LIB stdcompat.cma -custom -g"

TOP=`pwd`
Expand Down
1 change: 1 addition & 0 deletions compiler/type.ml → compiler/Type_.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(* Copyright 2016 Yoann Padioleau, see copyright.txt *)
(* renamed to Type_.ml because conflict with OCaml5 module name *)

type blockid = int
type fullname = string * blockid
Expand Down
4 changes: 2 additions & 2 deletions compiler/arch.ml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
(* Copyright 2016 Yoann Padioleau, see copyright.txt *)

type env = {
structs: (Ast.fullname, Type.struct_kind * Type.structdef) Hashtbl.t;
structs: (Ast.fullname, Type_.struct_kind * Type_.structdef) Hashtbl.t;
}

type arch = {
width_of_type: env -> Type.t -> int;
width_of_type: env -> Type_.t -> int;
}

(* todo? have a portable asm? ast_asm_common.ml?
Expand Down
3 changes: 2 additions & 1 deletion compiler/arch5.ml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
(* Copyright 2016 Yoann Padioleau, see copyright.txt *)
open Stdcompat (* for |> *)
open Common

open Arch
module T = Type
module T = Type_

let rec width_of_type env t =
match t with
Expand Down
26 changes: 13 additions & 13 deletions compiler/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type loc = Location_cpp.loc
type name = string

(* for scope *)
type blockid = int (* same than Type.blockid, repeated here for clarity *)
type blockid = int (* same than Type_.blockid, repeated here for clarity *)

(* A fully resolved and scoped name.
* 5c uses a reference to a symbol in a symbol table to fully qualify a name.
Expand All @@ -57,7 +57,7 @@ type blockid = int (* same than Type.blockid, repeated here for clarity *)
*
* 'name' below can be a gensym'ed name for anonymous struct/union/enum.
*)
type fullname = name * blockid (* same than Type.fullname *)
type fullname = name * blockid (* same than Type_.fullname *)

(* Used in globals.ml/lexer.mll/parser.mly to recognize typedef identifiers.
* Could be moved in a separate naming.ml, but not worth it for just two types.
Expand All @@ -76,7 +76,7 @@ type tagkind =
(* ------------------------------------------------------------------------- *)
(* Types *)
(* ------------------------------------------------------------------------- *)
(* What are the differences between type_ below and Type.t?
(* What are the differences between type_ below and Type_.t?
* - typedef expansion is not done here
* - constant expressions are not resolved yet
* (those expressions can involve enum constants which will be resolved later).
Expand All @@ -90,12 +90,12 @@ type type_ = {
t_loc: loc;
}
and type_bis =
| TBase of Type.t (* only the Basic stuff *)
| TBase of Type_.t (* only the Basic stuff *)
| TPointer of type_
| TArray of const_expr option * type_
| TFunction of function_type

| TStructName of Type.struct_kind * fullname
| TStructName of Type_.struct_kind * fullname
(* In C an enum is really like an int. However, we could do
* extended checks at some point to do more strict type checking!
*)
Expand Down Expand Up @@ -126,14 +126,14 @@ and expr = {
e: expr_bis;
e_loc: loc;
(* properly set during typechecking in typecheck.ml *)
e_type: Type.t;
e_type: Type_.t;
}
and expr_bis =
(* Note that characters are transformed in Int at parsing time; no need Char*)
| Int of string * Type.integer_type
| Float of string * Type.float_type
| Int of string * Type_.integer_type
| Float of string * Type_.float_type
(* codegen: converted to Id after typechecking *)
| String of string * Type.t (* always array of chars for now, no unicode *)
| String of string * Type_.t (* always array of chars for now, no unicode *)

(* Global, local, parameter, enum constant (can be scoped), function.
* Not that the storage, type, usage of ids is computed later and stored
Expand Down Expand Up @@ -288,7 +288,7 @@ type func_def = {
type struct_def = {
su_name: fullname;
su_loc: loc;
su_kind: Type.struct_kind;
su_kind: Type_.struct_kind;
(* todo: bitfield annotation *)
su_flds: field_def list;
}
Expand Down Expand Up @@ -351,16 +351,16 @@ type any =
| Type of type_
| Toplevel of toplevel
| Program of program
| FinalType of Type.t
| FinalType of Type_.t

(* with tarzan *)

(*****************************************************************************)
(* Helpers *)
(*****************************************************************************)
let tagkind_of_su = function
| Type.Struct -> TagStruct
| Type.Union -> TagUnion
| Type_.Struct -> TagStruct
| Type_.Union -> TagUnion

let unwrap (name, _) = name

Expand Down
1 change: 1 addition & 0 deletions compiler/check.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(* Copyright 2016 Yoann Padioleau, see copyright.txt *)
open Stdcompat (* for |> *)
open Common

open Ast
Expand Down
9 changes: 5 additions & 4 deletions compiler/codegen5.ml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
(* Copyright 2016, 2017 Yoann Padioleau, see copyright.txt *)
open Stdcompat (* for |> *)
open Common

open Ast
module C = Ast
module A = Ast_asm5

module T = Type
module T = Type_
module S = Storage
module TC = Typecheck
module E = Check
Expand Down Expand Up @@ -36,7 +37,7 @@ type env = {
(* computed by previous typechecking phase *)

ids: (Ast.fullname, TC.idinfo) Hashtbl.t;
structs: (Ast.fullname, Type.struct_kind * Type.structdef) Hashtbl.t;
structs: (Ast.fullname, Type_.struct_kind * Type_.structdef) Hashtbl.t;

(* less: compute offset for each field?
* fields: (Ast.fullname * string, A.offset) Hashtbl.t
Expand Down Expand Up @@ -87,7 +88,7 @@ let rEXT1 = A.R 10
let rEXT2 = A.R 9

let regs_initial =
let arr = Array.create A.nb_registers 0 in
let arr = Array.make A.nb_registers 0 in
[A.rLINK; A.rPC; (* hardware reseved *)
A.rTMP; A.rSB; A.rSP; (* linker reserved *)
rEXT1; rEXT2; (* compiler reserved *)
Expand All @@ -103,7 +104,7 @@ type integer = int
(* some form of instruction selection *)
type operand_able =
{ opd: operand_able_kind;
typ: Type.t;
typ: Type_.t;
loc: Ast.loc;
}
and operand_able_kind =
Expand Down
2 changes: 1 addition & 1 deletion compiler/codegen5.mli
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exception Error of error
(* can raise Error *)
val codegen:
(Ast.fullname, Typecheck.idinfo) Hashtbl.t *
(Ast.fullname, Type.struct_kind * Type.structdef) Hashtbl.t *
(Ast.fullname, Type_.struct_kind * Type_.structdef) Hashtbl.t *
Ast.func_def list
->
Ast_asm5.program
2 changes: 1 addition & 1 deletion compiler/eval_const.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module E = Check
type integer = int

(* less: could do that in rewrite.ml so no need to pass is to eval *)
type env = (Ast.fullname, integer * Type.integer_type) Hashtbl.t
type env = (Ast.fullname, integer * Type_.integer_type) Hashtbl.t

exception NotAConstant

Expand Down
2 changes: 1 addition & 1 deletion compiler/eval_const.mli
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type error = Check.error
exception Error of error

type integer = int
type env = (Ast.fullname, integer * Type.integer_type) Hashtbl.t
type env = (Ast.fullname, integer * Type_.integer_type) Hashtbl.t

(* may raise NotAConstant or Error *)
val eval: env -> Ast.expr -> integer
9 changes: 5 additions & 4 deletions compiler/lexer.mll
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
open Stdcompat
(* Copyright 2016 Yoann Padioleau, see copyright.txt *)
open Common

open Parser
module A = Ast
module L = Location_cpp
module T = Type
module T = Type_

(*****************************************************************************)
(* Prelude *)
Expand Down Expand Up @@ -34,19 +35,19 @@ let loc () = !L.line

let inttype_of_suffix sign size =
let sign =
match String.lowercase sign with
match String.lowercase_ascii sign with
| "" -> T.Signed
| "u" -> T.Unsigned
| s -> error (spf "Impossible: wrong sign suffix: %s" s)
in
match String.lowercase size with
match String.lowercase_ascii size with
| "" -> T.Int, sign
| "l" -> T.Long, sign
| "ll" -> T.VLong, sign
| s -> error (spf "Impossible: wrong int size suffix: %s" s)

let floattype_of_suffix s =
match String.lowercase s with
match String.lowercase_ascii s with
| "" -> T.Double
| "f" -> T.Float
| s -> error (spf "Impossible: wrong float size suffix: %s" s)
Expand Down
1 change: 1 addition & 0 deletions compiler/main.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(* Copyright 2016 Yoann Padioleau, see copyright.txt *)
open Stdcompat (* for |> *)
open Common

(*****************************************************************************)
Expand Down
2 changes: 1 addition & 1 deletion compiler/meta_type.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(* generated by ocamltarzan with: camlp4o -o /tmp/yyy.ml -I pa/ pa_type_conv.cmo pa_vof.cmo pr_o.cmo /tmp/xxx.ml *)

open Type
open Type_

let vof_blockid v = Ocaml.vof_int v

Expand Down
2 changes: 1 addition & 1 deletion compiler/mkfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ INCLUDES=-I $TOP/lib_core/commons -I $TOP/lib_core/collections \
-I $TOP/formats/objects

SRC= flags.ml \
type.ml meta_type.ml storage.ml meta_storage.ml \
Type_.ml meta_type.ml storage.ml meta_storage.ml \
ast.ml meta_ast.ml \
dumper.ml \
globals.ml \
Expand Down
1 change: 1 addition & 0 deletions compiler/parse.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(* Copyright 2016 Yoann Padioleau, see copyright.txt *)
open Stdcompat (* for |> *)
open Common

module L = Location_cpp
Expand Down
9 changes: 5 additions & 4 deletions compiler/parser.mly
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
%{
(* Copyright 2016 Yoann Padioleau, see copyright.txt *)
open Stdcompat (* for |> *)
open Common

open Ast
module T = Type
module T = Type_
module L = Location_cpp

(*****************************************************************************)
Expand Down Expand Up @@ -153,9 +154,9 @@ let pop_scope env =
/*(*************************************************************************)*/

%token <Ast.loc * string> TName TTypeName
%token <Ast.loc * string * Type.integer_type> TIConst
%token <Ast.loc * string * Type.float_type> TFConst
%token <Ast.loc * string * Type.t> TString
%token <Ast.loc * string * Type_.integer_type> TIConst
%token <Ast.loc * string * Type_.float_type> TFConst
%token <Ast.loc * string * Type_.t> TString

/*(*-----------------------------------------*)*/
/*(*2 Keywords *)*/
Expand Down
19 changes: 10 additions & 9 deletions compiler/typecheck.ml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
(* Copyright 2016, 2017 Yoann Padioleau, see copyright.txt *)
open Stdcompat (* for |> *)
open Common

open Ast
module T = Type
module T = Type_
module S = Storage
module E = Check

Expand Down Expand Up @@ -50,22 +51,22 @@ type integer = int
type env = {
(* those 2 fields will be returned ultimately by check_and_annotate_program *)
ids: (Ast.fullname, idinfo) Hashtbl.t;
structs: (Ast.fullname, Type.struct_kind * Type.structdef) Hashtbl.t;
structs: (Ast.fullname, Type_.struct_kind * Type_.structdef) Hashtbl.t;

(* internal *)
typedefs: (Ast.fullname, Type.t) Hashtbl.t;
typedefs: (Ast.fullname, Type_.t) Hashtbl.t;
(* stricter: no float enum *)
enums: (fullname, Type.integer_type) Hashtbl.t;
enums: (fullname, Type_.integer_type) Hashtbl.t;
(* stricter: no support for float enum constants either *)
constants: (Ast.fullname, integer * Type.integer_type) Hashtbl.t;
constants: (Ast.fullname, integer * Type_.integer_type) Hashtbl.t;

(* return type of function; used to typecheck Return *)
return_type: Type.t;
return_type: Type_.t;
(* used to add some implicit GetRef for arrays and functions *)
expr_context: expr_context;
}
and idinfo = {
typ: Type.t;
typ: Type_.t;
sto: Storage.t;
loc: Location_cpp.loc;
(* typed initialisers (fake expression for function definitions) *)
Expand Down Expand Up @@ -981,7 +982,7 @@ let check_and_annotate_program ast =
* be able to store those definitions in env.ids. That way
* we can detect function redefinitions, useless redeclarations, etc.
*)
let ini = Some { e = Id fullname; e_loc = loc; e_type = Type.Void } in
let ini = Some { e = Id fullname; e_loc = loc; e_type = Type_.Void } in

(try
(* check for weird redeclarations *)
Expand Down Expand Up @@ -1057,7 +1058,7 @@ let check_and_annotate_program ast =
enums = Hashtbl.create 101;
constants = Hashtbl.create 101;

return_type = Type.Void;
return_type = Type_.Void;
expr_context = CtxWantValue;
}
in
Expand Down
Loading

0 comments on commit 6e5ecaf

Please sign in to comment.